]> git.lizzy.rs Git - linenoise.git/commitdiff
Added some casts to make it easier to include in a c++ project
authorEliot Horowitz <eliot@10gen.com>
Fri, 18 Mar 2011 07:47:51 +0000 (03:47 -0400)
committerSteve Bennett <steveb@workware.net.au>
Tue, 12 Apr 2011 23:35:50 +0000 (09:35 +1000)
Makefile
linenoise.c

index 7e50716eb3f98c4939b30c4423a1e46c36343b29..4c218d427cb32892802c27a118720ac6588bd5e6 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -6,5 +6,8 @@ linenoise_example: linenoise.h linenoise.c example.c
 linenoise_utf8_example: linenoise.c utf8.c example.c
        $(CC) -DNO_COMPLETION -DUSE_UTF8 -Wall -W -Os -g -o $@ linenoise.c utf8.c example.c
 
+test_cpp_compile: linenoise.h linenoise.c
+       g++ -Wall -W -Os -g -c -o linenoise.o linenoise.c 
+
 clean:
        rm -f linenoise_example linenoise_utf8_example
index 63a75123355cb429bc306a976f79491fbc202998..b4fb56f1c0f3c859e965a27b75e7b92a83d43565 100644 (file)
 
 #define LINENOISE_DEFAULT_HISTORY_MAX_LEN 100
 #define LINENOISE_MAX_LINE 4096
-static char *unsupported_term[] = {"dumb","cons25",NULL};
+static const char *unsupported_term[] = {"dumb","cons25",NULL};
 
 static struct termios orig_termios; /* in order to restore at exit */
 static int rawmode = 0; /* for atexit() function to check if restore is needed*/
@@ -208,7 +208,7 @@ struct current {
 };
 
 /* gcc/glibc insists that we care about the return code of write! */
-#define IGNORE_RC(EXPR) ((EXPR) < 0 ? -1 : 0)
+#define IGNORE_RC(EXPR) if (EXPR) {}
 
 /* This is fd_printf() on some systems, but use a different
  * name to avoid conflicts
@@ -504,7 +504,7 @@ void linenoiseSetCompletionCallback(linenoiseCompletionCallback *fn) {
 }
 
 void linenoiseAddCompletion(linenoiseCompletions *lc, const char *str) {
-    lc->cvec = realloc(lc->cvec,sizeof(char*)*(lc->len+1));
+    lc->cvec = (char **)realloc(lc->cvec,sizeof(char*)*(lc->len+1));
     lc->cvec[lc->len++] = strdup(str);
 }
 
@@ -1046,7 +1046,7 @@ int linenoiseHistoryAdd(const char *line) {
 
     if (history_max_len == 0) return 0;
     if (history == NULL) {
-        history = malloc(sizeof(char*)*history_max_len);
+        history = (char**)malloc(sizeof(char*)*history_max_len);
         if (history == NULL) return 0;
         memset(history,0,(sizeof(char*)*history_max_len));
     }
@@ -1063,18 +1063,18 @@ int linenoiseHistoryAdd(const char *line) {
 }
 
 int linenoiseHistorySetMaxLen(int len) {
-    char **new;
+    char **newHistory;
 
     if (len < 1) return 0;
     if (history) {
         int tocopy = history_len;
 
-        new = malloc(sizeof(char*)*len);
-        if (new == NULL) return 0;
+        newHistory = (char**)malloc(sizeof(char*)*len);
+        if (newHistory == NULL) return 0;
         if (len < tocopy) tocopy = len;
-        memcpy(new,history+(history_max_len-tocopy), sizeof(char*)*tocopy);
+        memcpy(newHistory,history+(history_max_len-tocopy), sizeof(char*)*tocopy);
         free(history);
-        history = new;
+        history = newHistory;
     }
     history_max_len = len;
     if (history_len > history_max_len)