From f497f7eb5c94b7828ec3bc50a4d95016869da09e Mon Sep 17 00:00:00 2001 From: Stefan 'psYchotic' Zwanenburg Date: Tue, 26 Jan 2010 14:30:47 +0100 Subject: [PATCH] SimpleShell now uses the readline history. MIT license added. --- ss.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/ss.c b/ss.c index d27df09..ded424d 100644 --- a/ss.c +++ b/ss.c @@ -1,3 +1,27 @@ +/****************************************************************************** + * The MIT License + * + * Copyright (c) 2010 Stefan 'psYchotic' Zwanenburg + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + *****************************************************************************/ + #define _GNU_SOURCE #include #include @@ -151,6 +175,9 @@ int handle_input(char *input) { /* do nothing */ } else { argv = split_input(input); + if (history_length == 0 || history_search_pos(input, 1, 0) == -1) { + add_history(input); + } free(input); if (!strcmp(argv[0], "exit")) { return_value = exit_cmd(&argv[1]); @@ -267,6 +294,8 @@ int main(int argc, char **argv) { } } + using_history(); + do { input = get_input(prompt); } while (!handle_input(input)); -- 2.11.4.GIT