diff options
Diffstat (limited to 'cpukit/libmisc/shell/main_edit.c')
-rw-r--r-- | cpukit/libmisc/shell/main_edit.c | 56 |
1 files changed, 34 insertions, 22 deletions
diff --git a/cpukit/libmisc/shell/main_edit.c b/cpukit/libmisc/shell/main_edit.c index 8ac7eeea5b..8317452b7b 100644 --- a/cpukit/libmisc/shell/main_edit.c +++ b/cpukit/libmisc/shell/main_edit.c @@ -55,7 +55,9 @@ #if defined(__linux__) || defined(__rtems__) #include <sys/ioctl.h> #include <termios.h> +#ifndef O_BINARY #define O_BINARY 0 +#endif static int linux_console; #endif @@ -410,6 +412,9 @@ static void move_gap(struct editor *ed, int pos, int minsize) { if (gapsize + MINEXTEND > minsize) minsize = gapsize + MINEXTEND; newsize = (ed->end - ed->start) - gapsize + minsize; start = (unsigned char *) malloc(newsize); // TODO check for out of memory + if (start == NULL) { + return; + } gap = start + pos; rest = gap + minsize; end = start + newsize; @@ -684,7 +689,7 @@ static void moveto(struct editor *ed, int pos, int center) { // Text selection // -static int get_selection(struct editor *ed, int *start, int *end) { +static int get_selection(struct editor *ed, size_t *start, size_t *end) { if (ed->anchor == -1) { *start = *end = -1; return 0; @@ -705,7 +710,7 @@ static int get_selection(struct editor *ed, int *start, int *end) { } static int get_selected_text(struct editor *ed, char *buffer, int size) { - int selstart, selend, len; + size_t selstart, selend, len; if (!get_selection(ed, &selstart, &selend)) return 0; len = selend - selstart; @@ -726,7 +731,7 @@ static void update_selection(struct editor *ed, int select) { } static int erase_selection(struct editor *ed) { - int selstart, selend; + size_t selstart, selend; if (!get_selection(ed, &selstart, &selend)) return 0; moveto(ed, selstart, 0); @@ -753,8 +758,23 @@ static void get_console_size(struct env *env) { env->cols = ws.ws_col; env->lines = ws.ws_row - 1; #elif defined(__rtems__) - env->cols = 80; + char* e; env->lines = 25; + env->cols = 80; + e = getenv("LINES"); + if (e != NULL) { + int lines = strtol(e, 0, 10); + if (lines > 0) { + env->lines = lines - 1; + } + } + e = getenv("COLUMNS"); + if (e != NULL) { + int cols = strtol(e, 0, 10); + if (cols > 0) { + env->cols = cols; + } + } #else struct term *term = gettib()->proc->term; env->cols = term->cols; @@ -1086,7 +1106,7 @@ static void display_line(struct editor *ed, int pos, int fullline) { int maxcol = ed->env->cols + margin; unsigned char *bufptr = ed->env->linebuf; unsigned char *p = text_ptr(ed, pos); - int selstart, selend, ch; + size_t selstart, selend, ch; char *s; (void) get_selection(ed, &selstart, &selend); @@ -1545,9 +1565,9 @@ static void del(struct editor *ed) { } static void indent(struct editor *ed, unsigned char *indentation) { - int start, end, i, lines, toplines, newline, ch; + size_t start, end, i, lines, toplines, newline, ch; unsigned char *buffer, *p; - int buflen; + size_t buflen; int width = strlen((const char*) indentation); int pos = ed->linepos + ed->col; @@ -1602,7 +1622,7 @@ static void indent(struct editor *ed, unsigned char *indentation) { } static void unindent(struct editor *ed, unsigned char *indentation) { - int start, end, i, newline, ch, shrinkage, topofs; + size_t start, end, i, newline, ch, shrinkage, topofs; unsigned char *buffer, *p; int width = strlen((const char*) indentation); int pos = ed->linepos + ed->col; @@ -1686,14 +1706,13 @@ static void redo(struct editor *ed) { // static void copy_selection(struct editor *ed) { - int selstart, selend; + size_t selstart, selend; if (!get_selection(ed, &selstart, &selend)) return; ed->env->clipsize = selend - selstart; ed->env->clipboard = (unsigned char *) realloc(ed->env->clipboard, ed->env->clipsize); if (!ed->env->clipboard) return; copy(ed, ed->env->clipboard, selstart, ed->env->clipsize); - select_toggle(ed); } static void cut_selection(struct editor *ed) { @@ -1792,14 +1811,14 @@ static void save_editor(struct editor *ed) { ed->refresh = 1; } -static void close_editor(struct editor *ed) { +static struct editor* close_editor(struct editor *ed) { struct env *env = ed->env; if (ed->dirty) { display_message(ed, "Close %s without saving changes (y/n)? ", ed->filename); if (!ask()) { ed->refresh = 1; - return; + return ed; } } @@ -1811,6 +1830,7 @@ static void close_editor(struct editor *ed) { new_file(ed, ""); } ed->refresh = 1; + return ed; } static void pipe_command(struct editor *ed) { @@ -2111,7 +2131,7 @@ static void edit(struct editor *ed) { case ctrl('e'): select_toggle(ed); break; case ctrl('a'): select_all(ed); break; - case ctrl('c'): copy_selection(ed); break; + case ctrl('c'): copy_selection(ed);select_toggle(ed); break; case ctrl('f'): find_text(ed, 0); break; case ctrl('l'): goto_line(ed); break; case ctrl('g'): find_text(ed, 1); break; @@ -2134,15 +2154,7 @@ static void edit(struct editor *ed) { case ctrl('s'): save_editor(ed); break; case ctrl('p'): pipe_command(ed); break; #endif -#if defined(__rtems__) - /* - * Coverity spotted this as using ed after free() so changing - * the order of the statements. - */ - case ctrl('w'): ed = ed->env->current; close_editor(ed); break; -#else - case ctrl('w'): close_editor(ed); ed = ed->env->current; break; -#endif + case ctrl('w'): ed = close_editor(ed); break; } } } |