linenoise REFACTOR do not shadow variables
diff --git a/tools/lint/linenoise/linenoise.c b/tools/lint/linenoise/linenoise.c
index e50bd8e..fed3d26 100644
--- a/tools/lint/linenoise/linenoise.c
+++ b/tools/lint/linenoise/linenoise.c
@@ -137,28 +137,28 @@
/* The linenoiseState structure represents the state during line editing.
* We pass this state to functions implementing specific editing
* functionalities. */
-struct linenoiseState ls;
+struct linenoiseState lss;
enum KEY_ACTION{
- KEY_NULL = 0, /* NULL */
- CTRL_A = 1, /* Ctrl+a */
- CTRL_B = 2, /* Ctrl-b */
- CTRL_C = 3, /* Ctrl-c */
- CTRL_D = 4, /* Ctrl-d */
- CTRL_E = 5, /* Ctrl-e */
- CTRL_F = 6, /* Ctrl-f */
- CTRL_H = 8, /* Ctrl-h */
- TAB = 9, /* Tab */
- CTRL_K = 11, /* Ctrl+k */
- CTRL_L = 12, /* Ctrl+l */
- ENTER = 13, /* Enter */
- CTRL_N = 14, /* Ctrl-n */
- CTRL_P = 16, /* Ctrl-p */
- CTRL_T = 20, /* Ctrl-t */
- CTRL_U = 21, /* Ctrl+u */
- CTRL_W = 23, /* Ctrl+w */
- ESC = 27, /* Escape */
- BACKSPACE = 127 /* Backspace */
+ KEY_NULL = 0, /* NULL */
+ CTRL_A = 1, /* Ctrl+a */
+ CTRL_B = 2, /* Ctrl-b */
+ CTRL_C = 3, /* Ctrl-c */
+ CTRL_D = 4, /* Ctrl-d */
+ CTRL_E = 5, /* Ctrl-e */
+ CTRL_F = 6, /* Ctrl-f */
+ CTRL_H = 8, /* Ctrl-h */
+ TAB = 9, /* Tab */
+ CTRL_K = 11, /* Ctrl+k */
+ CTRL_L = 12, /* Ctrl+l */
+ ENTER = 13, /* Enter */
+ CTRL_N = 14, /* Ctrl-n */
+ CTRL_P = 16, /* Ctrl-p */
+ CTRL_T = 20, /* Ctrl-t */
+ CTRL_U = 21, /* Ctrl+u */
+ CTRL_W = 23, /* Ctrl+w */
+ ESC = 27, /* Escape */
+ BACKSPACE = 127 /* Backspace */
};
static void linenoiseAtExit(void);
@@ -230,7 +230,7 @@
/* put terminal in raw mode after flushing */
if (tcsetattr(fd,TCSAFLUSH,&raw) < 0) goto fatal;
- ls.rawmode = 1;
+ lss.rawmode = 1;
return 0;
fatal:
@@ -240,8 +240,8 @@
void linenoiseDisableRawMode(int fd) {
/* Don't even check the return value as it's too late. */
- if (ls.rawmode && tcsetattr(fd,TCSAFLUSH,&orig_termios) != -1)
- ls.rawmode = 0;
+ if (lss.rawmode && tcsetattr(fd,TCSAFLUSH,&orig_termios) != -1)
+ lss.rawmode = 0;
}
/* Use the ESC [6n escape sequence to query the horizontal cursor position
@@ -698,12 +698,12 @@
* refreshMultiLine() according to the selected mode. */
void linenoiseRefreshLine(void) {
/* Update columns in case the terminal was resized */
- ls.cols = getColumns(STDIN_FILENO, STDOUT_FILENO);
+ lss.cols = getColumns(STDIN_FILENO, STDOUT_FILENO);
if (mlmode)
- refreshMultiLine(&ls);
+ refreshMultiLine(&lss);
else
- refreshSingleLine(&ls);
+ refreshSingleLine(&lss);
}
/* Insert the character 'c' at cursor current position.
@@ -843,42 +843,42 @@
{
/* Populate the linenoise state that we pass to functions implementing
* specific editing functionalities. */
- ls.ifd = stdin_fd;
- ls.ofd = stdout_fd;
- ls.buf = buf;
- ls.buflen = buflen;
- ls.prompt = prompt;
- ls.plen = strlen(prompt);
- ls.oldpos = ls.pos = 0;
- ls.len = 0;
- ls.cols = getColumns(stdin_fd, stdout_fd);
- ls.maxrows = 0;
- ls.history_index = 0;
+ lss.ifd = stdin_fd;
+ lss.ofd = stdout_fd;
+ lss.buf = buf;
+ lss.buflen = buflen;
+ lss.prompt = prompt;
+ lss.plen = strlen(prompt);
+ lss.oldpos = lss.pos = 0;
+ lss.len = 0;
+ lss.cols = getColumns(stdin_fd, stdout_fd);
+ lss.maxrows = 0;
+ lss.history_index = 0;
/* Buffer starts empty. */
- ls.buf[0] = '\0';
- ls.buflen--; /* Make sure there is always space for the nulterm */
+ lss.buf[0] = '\0';
+ lss.buflen--; /* Make sure there is always space for the nulterm */
/* The latest history entry is always our current buffer, that
* initially is just an empty string. */
linenoiseHistoryAdd("");
- if (write(ls.ofd,prompt,ls.plen) == -1) return -1;
+ if (write(lss.ofd,prompt,lss.plen) == -1) return -1;
while(1) {
char c = 0;
int nread;
char seq[3];
- nread = read(ls.ifd,&c,sizeof c);
- if (nread <= 0) return ls.len;
+ nread = read(lss.ifd,&c,sizeof c);
+ if (nread <= 0) return lss.len;
/* Only autocomplete when the callback is set. It returns < 0 when
* there was an error reading from fd. Otherwise it will return the
* character that should be handled next. */
if (c == 9 && completionCallback != NULL) {
- c = completeLine(&ls);
+ c = completeLine(&lss);
/* Return on errors */
- if (c < 0) return ls.len;
+ if (c < 0) return lss.len;
/* Read next character when 0 */
if (c == 0) continue;
}
@@ -887,19 +887,19 @@
case ENTER: /* enter */
history_len--;
free(history[history_len]);
- if (mlmode) linenoiseEditMoveEnd(&ls);
- return (int)ls.len;
+ if (mlmode) linenoiseEditMoveEnd(&lss);
+ return (int)lss.len;
case CTRL_C: /* ctrl-c */
errno = EAGAIN;
return -1;
case BACKSPACE: /* backspace */
case 8: /* ctrl-h */
- linenoiseEditBackspace(&ls);
+ linenoiseEditBackspace(&lss);
break;
case CTRL_D: /* ctrl-d, remove char at right of cursor, or if the
line is empty, act as end-of-file. */
- if (ls.len > 0) {
- linenoiseEditDelete(&ls);
+ if (lss.len > 0) {
+ linenoiseEditDelete(&lss);
} else {
history_len--;
free(history[history_len]);
@@ -907,64 +907,61 @@
}
break;
case CTRL_T: /* ctrl-t, swaps current character with previous. */
- if (ls.pos > 0 && ls.pos < ls.len) {
- int aux = buf[ls.pos-1];
- buf[ls.pos-1] = buf[ls.pos];
- buf[ls.pos] = aux;
- if (ls.pos != ls.len-1) ls.pos++;
+ if (lss.pos > 0 && lss.pos < lss.len) {
+ int aux = buf[lss.pos-1];
+ buf[lss.pos-1] = buf[lss.pos];
+ buf[lss.pos] = aux;
+ if (lss.pos != lss.len-1) lss.pos++;
linenoiseRefreshLine();
}
break;
case CTRL_B: /* ctrl-b */
- linenoiseEditMoveLeft(&ls);
+ linenoiseEditMoveLeft(&lss);
break;
case CTRL_F: /* ctrl-f */
- linenoiseEditMoveRight(&ls);
+ linenoiseEditMoveRight(&lss);
break;
case CTRL_P: /* ctrl-p */
- linenoiseEditHistoryNext(&ls, LINENOISE_HISTORY_PREV);
+ linenoiseEditHistoryNext(&lss, LINENOISE_HISTORY_PREV);
break;
case CTRL_N: /* ctrl-n */
- linenoiseEditHistoryNext(&ls, LINENOISE_HISTORY_NEXT);
+ linenoiseEditHistoryNext(&lss, LINENOISE_HISTORY_NEXT);
break;
case ESC: /* escape sequence */
/* Read the next two bytes representing the escape sequence.
* Use two calls to handle slow terminals returning the two
* chars at different times. */
- if (read(ls.ifd,seq,1) == -1) break;
- if (read(ls.ifd,seq+1,1) == -1) break;
+ if (read(lss.ifd,seq,1) == -1) break;
+ if (read(lss.ifd,seq+1,1) == -1) break;
/* ESC [ sequences. */
if (seq[0] == '[') {
if (seq[1] >= '0' && seq[1] <= '9') {
/* Extended escape, read additional byte. */
- if (read(ls.ifd,seq+2,1) == -1) break;
- if (seq[2] == '~') {
- switch(seq[1]) {
- case '3': /* Delete key. */
- linenoiseEditDelete(&ls);
- break;
- }
+ if (read(lss.ifd, seq + 2, 1) == -1) break;
+ if ((seq[1] == '3') && (seq[2] == '~')) {
+ /* Delete key. */
+ linenoiseEditDelete(&lss);
}
} else {
switch(seq[1]) {
case 'A': /* Up */
- linenoiseEditHistoryNext(&ls, LINENOISE_HISTORY_PREV);
+ linenoiseEditHistoryNext(&lss, LINENOISE_HISTORY_PREV);
break;
case 'B': /* Down */
- linenoiseEditHistoryNext(&ls, LINENOISE_HISTORY_NEXT);
+ linenoiseEditHistoryNext(&lss, LINENOISE_HISTORY_NEXT);
break;
case 'C': /* Right */
- linenoiseEditMoveRight(&ls);
+ linenoiseEditMoveRight(&lss);
break;
case 'D': /* Left */
- linenoiseEditMoveLeft(&ls);
+ linenoiseEditMoveLeft(&lss);
break;
case 'H': /* Home */
- linenoiseEditMoveHome(&ls);
+ linenoiseEditMoveHome(&lss);
break;
case 'F': /* End*/
- linenoiseEditMoveEnd(&ls);
+ linenoiseEditMoveEnd(&lss);
break;
}
}
@@ -974,43 +971,43 @@
else if (seq[0] == 'O') {
switch(seq[1]) {
case 'H': /* Home */
- linenoiseEditMoveHome(&ls);
+ linenoiseEditMoveHome(&lss);
break;
case 'F': /* End*/
- linenoiseEditMoveEnd(&ls);
+ linenoiseEditMoveEnd(&lss);
break;
}
}
break;
default:
- if (linenoiseEditInsert(&ls,c)) return -1;
+ if (linenoiseEditInsert(&lss,c)) return -1;
break;
case CTRL_U: /* Ctrl+u, delete the whole line. */
buf[0] = '\0';
- ls.pos = ls.len = 0;
+ lss.pos = lss.len = 0;
linenoiseRefreshLine();
break;
case CTRL_K: /* Ctrl+k, delete from current to end of line. */
- buf[ls.pos] = '\0';
- ls.len = ls.pos;
+ buf[lss.pos] = '\0';
+ lss.len = lss.pos;
linenoiseRefreshLine();
break;
case CTRL_A: /* Ctrl+a, go to the start of the line */
- linenoiseEditMoveHome(&ls);
+ linenoiseEditMoveHome(&lss);
break;
case CTRL_E: /* ctrl+e, go to the end of the line */
- linenoiseEditMoveEnd(&ls);
+ linenoiseEditMoveEnd(&lss);
break;
case CTRL_L: /* ctrl+l, clear screen */
linenoiseClearScreen();
linenoiseRefreshLine();
break;
case CTRL_W: /* ctrl+w, delete previous word */
- linenoiseEditDeletePrevWord(&ls);
+ linenoiseEditDeletePrevWord(&lss);
break;
}
}
- return ls.len;
+ return lss.len;
}
/* This special mode is used by linenoise in order to print scan codes
diff --git a/tools/lint/linenoise/linenoise.h b/tools/lint/linenoise/linenoise.h
index 2bebcf3..8362b1f 100644
--- a/tools/lint/linenoise/linenoise.h
+++ b/tools/lint/linenoise/linenoise.h
@@ -61,7 +61,7 @@
int history_index; /* The history index we are currently editing. */
};
-extern struct linenoiseState ls;
+extern struct linenoiseState lss;
typedef struct linenoiseCompletions {
int path;