]> git.draconx.ca Git - cdecl99.git/blobdiff - src/cdecl99.c
Add basic readline history support.
[cdecl99.git] / src / cdecl99.c
index d58433ba15e68774eadfb3549d8f73583102fc5a..99b5d63eaed47bcc2c197117ae95beb7cd89d1ef 100644 (file)
@@ -1,31 +1,33 @@
 /*
- *  Command line utility for making sense of C declarations.
- *  Copyright © 2011 Nick Bowler
+ * Command line utility for making sense of C declarations.
+ * Copyright © 2011-2012 Nick Bowler
  *
- *  This program is free software: you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation, either version 3 of the License, or
- *  (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
  *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- *  You should have received a copy of the GNU General Public License
- *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 #include <config.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdbool.h>
 #include <string.h>
+#include <ctype.h>
 #include <errno.h>
 #include <locale.h>
 #include <getopt.h>
 #include <gettext.h>
 #include <assert.h>
 #include "readline.h"
+#include "history.h"
 #include "cdecl.h"
 
 #define _(x) gettext(x)
@@ -398,11 +400,24 @@ static int run_command(const char *line)
        return -1;
 }
 
+static bool is_blank_line(const char *line)
+{
+       for (size_t i = 0; line[i]; i++) {
+               if (!isblank((unsigned char)line[i]))
+                       return false;
+       }
+
+       return true;
+}
+
 static int repl(void)
 {
        char *line;
 
        for (; (line = readline("> ")); free(line)) {
+               if (!is_blank_line(line))
+                       cdecl_add_history(line);
+
                if (!run_command(line))
                        break;
        }