libcubescript/docs/patch-linenoise.c.diff

150 lines
4.9 KiB
Diff

--- linenoise.c 2016-09-01 13:45:57.027318000 +0100
+++ linenoise.cc 2016-09-01 17:42:43.681873000 +0100
@@ -115,11 +115,11 @@
#include <sys/types.h>
#include <sys/ioctl.h>
#include <unistd.h>
-#include "linenoise.h"
+#include "linenoise.hh"
#define LINENOISE_DEFAULT_HISTORY_MAX_LEN 100
#define LINENOISE_MAX_LINE 4096
-static char *unsupported_term[] = {"dumb","cons25","emacs",NULL};
+static const char *unsupported_term[] = {"dumb","cons25","emacs",NULL};
static linenoiseCompletionCallback *completionCallback = NULL;
static linenoiseHintsCallback *hintsCallback = NULL;
static linenoiseFreeHintsCallback *freeHintsCallback = NULL;
@@ -430,10 +430,10 @@
size_t len = strlen(str);
char *copy, **cvec;
- copy = malloc(len+1);
+ copy = static_cast<char *>(malloc(len+1));
if (copy == NULL) return;
memcpy(copy,str,len+1);
- cvec = realloc(lc->cvec,sizeof(char*)*(lc->len+1));
+ cvec = static_cast<char **>(realloc(lc->cvec,sizeof(char*)*(lc->len+1)));
if (cvec == NULL) {
free(copy);
return;
@@ -459,11 +459,11 @@
}
static void abAppend(struct abuf *ab, const char *s, int len) {
- char *new = realloc(ab->b,ab->len+len);
+ char *newb = static_cast<char *>(realloc(ab->b,ab->len+len));
- if (new == NULL) return;
- memcpy(new+ab->len,s,len);
- ab->b = new;
+ if (newb == NULL) return;
+ memcpy(newb+ab->len,s,len);
+ ab->b = newb;
ab->len += len;
}
@@ -530,7 +530,7 @@
snprintf(seq,64,"\x1b[0K");
abAppend(&ab,seq,strlen(seq));
/* Move cursor to original position. */
- snprintf(seq,64,"\r\x1b[%dC", (int)(pos+plen));
+ snprintf(seq,64,"\r\x1b[%dC", int(pos+plen));
abAppend(&ab,seq,strlen(seq));
if (write(fd,ab.b,ab.len) == -1) {} /* Can't recover from write error. */
abFree(&ab);
@@ -552,7 +552,7 @@
struct abuf ab;
/* Update maxrows if needed. */
- if (rows > (int)l->maxrows) l->maxrows = rows;
+ if (rows > int(l->maxrows)) l->maxrows = rows;
/* First step: clear all the lines used before. To do so start by
* going to the last row. */
@@ -593,7 +593,7 @@
snprintf(seq,64,"\r");
abAppend(&ab,seq,strlen(seq));
rows++;
- if (rows > (int)l->maxrows) l->maxrows = rows;
+ if (rows > int(l->maxrows)) l->maxrows = rows;
}
/* Move cursor to right position. */
@@ -608,7 +608,7 @@
}
/* Set column. */
- col = (plen+(int)l->pos) % (int)l->cols;
+ col = (plen+int(l->pos)) % int(l->cols);
lndebug("set col %d", 1+col);
if (col)
snprintf(seq,64,"\r\x1b[%dC", col);
@@ -824,7 +824,7 @@
refreshLine(&l);
hintsCallback = hc;
}
- return (int)l.len;
+ return int(l.len);
case CTRL_C: /* ctrl-c */
errno = EAGAIN;
return -1;
@@ -970,7 +970,7 @@
if (memcmp(quit,"quit",sizeof(quit)) == 0) break;
printf("'%c' %02x (%d) (type quit to exit)\n",
- isprint(c) ? c : '?', (int)c, (int)c);
+ isprint(c) ? c : '?', int(c), int(c));
printf("\r"); /* Go left edge manually, we are in raw mode. */
fflush(stdout);
}
@@ -1008,7 +1008,7 @@
if (maxlen == 0) maxlen = 16;
maxlen *= 2;
char *oldval = line;
- line = realloc(line,maxlen);
+ line = static_cast<char *>(realloc(line,maxlen));
if (line == NULL) {
if (oldval) free(oldval);
return NULL;
@@ -1104,7 +1104,7 @@
/* Initialization on first call. */
if (history == NULL) {
- history = malloc(sizeof(char*)*history_max_len);
+ history = static_cast<char **>(malloc(sizeof(char*)*history_max_len));
if (history == NULL) return 0;
memset(history,0,(sizeof(char*)*history_max_len));
}
@@ -1131,14 +1131,14 @@
* just the latest 'len' elements if the new history length value is smaller
* than the amount of items already inside the history. */
int linenoiseHistorySetMaxLen(int len) {
- char **new;
+ char **newb;
if (len < 1) return 0;
if (history) {
int tocopy = history_len;
- new = malloc(sizeof(char*)*len);
- if (new == NULL) return 0;
+ newb = static_cast<char **>(malloc(sizeof(char*)*len));
+ if (newb == NULL) return 0;
/* If we can't copy everything, free the elements we'll not use. */
if (len < tocopy) {
@@ -1147,10 +1147,10 @@
for (j = 0; j < tocopy-len; j++) free(history[j]);
tocopy = len;
}
- memset(new,0,sizeof(char*)*len);
- memcpy(new,history+(history_len-tocopy), sizeof(char*)*tocopy);
+ memset(newb,0,sizeof(char*)*len);
+ memcpy(newb,history+(history_len-tocopy), sizeof(char*)*tocopy);
free(history);
- history = new;
+ history = newb;
}
history_max_len = len;
if (history_len > history_max_len)