From: David Lawrence Ramsey Date: Sun, 10 Jul 2005 02:37:38 +0000 (+0000) Subject: use blank_line() instead of hblank/mvwhline(), and fix more breakage X-Git-Tag: v1.3.9~202 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=b386a905e6383fa58db4f0b372d9cc2573ce2d8a;p=nano.git use blank_line() instead of hblank/mvwhline(), and fix more breakage git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2844 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index a2226505..02a04b55 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,21 +13,20 @@ CVS code - openfilestruct, and so that the values in it are used directly instead of being periodically synced up with the globals. Accordingly, remove the globals. Changes to pretty much - every function. Rename global_init() resize_init(), rename - add_open_file() make_new_buffer(), rename load_buffer() + every function. Rename global_init() window_size_init(), + rename add_open_file() make_new_buffer(), rename load_buffer() open_buffer(), rename load_open_file() load_buffer(), rename open_prevnext_file() switch_to_prevnext_buffer(), rename open_prevfile_void() switch_to_prev_buffer(), rename open_nextfile_void() switch_to_next_buffer(), remove load_file(), rename cancel_fork() cancel_command(), - rename open_pipe() execute_command(), and remove - execute_command(). (DLR) - - Replace almost all mvwaddstr(hblank) calls with mvwhline(' ', - COLS) calls, which do the same thing. New function - nmvwhline() (since slang doesn't define mvwhline()); changes - to do_browser(), blank_titlebar(), blank_topbar(), - blank_edit(), blank_statusbar(), blank_bottombars(), - update_line(), and edit_refresh(). (DLR) + rename open_pipe() execute_command(), remove + execute_command(), and remove resize_variables(). (DLR) + - Replace all mvwaddstr(hblank) calls with a new function that + does the same thing without the need for hblank. New function + blank_line(); changes to do_browser(), blank_titlebar(), + blank_topbar(), blank_edit(), blank_statusbar(), + blank_bottombars(), update_line(), and edit_refresh(). (DLR) - files.c: open_file() - Assert that filename isn't NULL, and don't do anything special @@ -83,8 +82,11 @@ CVS code - display_string() - Display invalid multibyte sequences as Unicode 0xFFFD (Replacement Character). (DLR) - total_redraw() - - Rework to use functions that slang actually defines. (DLR) + titlebar() + - Rework to display only one space after the version number, so + that there's more room for other things, and to not display + the status when we're in the file browser, since Pico doesn't. + (DLR) - configure.ac: - Since we only use vsnprintf() now, remove the tests for snprintf(). (DLR) diff --git a/src/files.c b/src/files.c index d8cb28eb..2944cfd2 100644 --- a/src/files.c +++ b/src/files.c @@ -111,6 +111,15 @@ void make_new_buffer(void) openfile = openfile->next; } + /* Initialize the new buffer. */ + initialize_buffer(); +} + +/* Initialize the current entry of the openfile openfilestruct. */ +void initialize_buffer(void) +{ + assert(openfile != NULL); + openfile->filename = mallocstrcpy(NULL, ""); openfile->fileage = make_new_node(NULL); @@ -142,6 +151,20 @@ void make_new_buffer(void) #endif } +#ifndef DISABLE_SPELLER +/* Reinitialize the current entry of the openfile openfilestruct. */ +void reinitialize_buffer(void) +{ + assert(openfile != NULL); + + free(openfile->filename); + + free_filestruct(openfile->fileage); + + initialize_buffer(); +} +#endif + /* filename is a file to open. We make a new buffer, if necessary, and * then open and read the file. */ void open_buffer(const char *filename) @@ -255,7 +278,7 @@ void switch_to_next_buffer_void(void) switch_to_prevnext_buffer(TRUE); } -/* Delete an entry from the openfile filestruct, and open the one +/* Delete an entry from the openfile filestruct, and switch to the one * after it. Return TRUE on success, or FALSE if there are no more open * file buffers. */ bool close_buffer(void) @@ -2581,7 +2604,7 @@ char *do_browser(char *path, DIR *dir) if (j == selected) wattron(edit, A_REVERSE); - mvwhline(edit, editline, col, ' ', longest); + blank_line(edit, editline, col, longest); mvwaddstr(edit, editline, col, disp); free(disp); diff --git a/src/global.c b/src/global.c index 9c0dd5d4..12ec5dd3 100644 --- a/src/global.c +++ b/src/global.c @@ -89,7 +89,6 @@ char *answer = NULL; /* Answer str to many questions */ ssize_t tabsize = -1; /* Our internal tabsize variable. The default value is set in main(). */ -char *hblank = NULL; /* A horizontal blank line */ #ifndef DISABLE_HELP char *help_text; /* The text in the help window */ #endif @@ -1162,8 +1161,6 @@ void thanks_for_all_the_fish(void) free(last_search); if (last_replace != NULL) free(last_replace); - if (hblank != NULL) - free(hblank); #ifndef DISABLE_SPELLER if (alt_speller != NULL) free(alt_speller); diff --git a/src/nano.c b/src/nano.c index 3527d179..266dd74c 100644 --- a/src/nano.c +++ b/src/nano.c @@ -575,10 +575,12 @@ void check_die_too_small(void) die(_("Window size is too small for nano...\n")); } -/* Reinitialize the variables that depend on the window size. That is, - * fill and hblank. */ -void resize_variables(void) +/* Make sure the window size isn't too small, and reinitialize the fill + * variable, since it depends on the window size. */ +void window_size_init(void) { + check_die_too_small(); + #ifndef DISABLE_WRAPJUSTIFY fill = wrap_at; if (fill <= 0) @@ -586,17 +588,6 @@ void resize_variables(void) if (fill < 0) fill = 0; #endif - - hblank = charealloc(hblank, COLS + 1); - charset(hblank, ' ', COLS); - hblank[COLS] = '\0'; -} - -/* Initialize the resize variables. */ -void resize_init(void) -{ - check_die_too_small(); - resize_variables(); } void window_init(void) @@ -2341,6 +2332,7 @@ const char *do_int_speller(const char *tempfile_name) const char *do_alt_speller(char *tempfile_name) { int alt_spell_status; + char *filename_save; size_t current_x_save = openfile->current_x; size_t pww_save = openfile->placewewant; ssize_t current_y_save = openfile->current_y; @@ -2455,15 +2447,20 @@ const char *do_alt_speller(char *tempfile_name) } #endif - /* Reinitialize the filestruct. */ - free_filestruct(openfile->fileage); + /* Set up the window size. */ + window_size_init(); + + /* Save the current filename. */ + filename_save = mallocstrcpy(NULL, openfile->filename); + + /* Reinitialize the current buffer. */ + reinitialize_buffer(); - /* Reinitialize the resize variables. */ - resize_init(); + /* Restore the current filename. */ + openfile->filename = filename_save; - /* Reload the temp file. Do what open_buffer() would do, except for - * making a new buffer for the temp file if multibuffer support is - * available. */ + /* Reload the temp file. Open it, read it into the current buffer, + * and move back to the first line of the buffer. */ open_file(tempfile_name, FALSE, &f); read_file(f, tempfile_name); openfile->current = openfile->fileage; @@ -3675,7 +3672,8 @@ void handle_sigwinch(int s) COLS = win.ws_col; LINES = win.ws_row; - resize_init(); + /* Reinitialize the window size variables. */ + window_size_init(); /* If we've partitioned the filestruct, unpartition it now. */ if (filepart != NULL) @@ -4618,16 +4616,19 @@ int main(int argc, char **argv) /* Back up the old terminal settings so that they can be restored. */ tcgetattr(0, &oldterm); - /* Curses initialization stuff: Start curses and set up the - * terminal state. */ + /* Initialize curses mode. */ initscr(); + + /* Set up the terminal state. */ terminal_init(); /* Turn the cursor on for sure. */ curs_set(1); - /* Set up the resize variables and the shortcuts. */ - resize_init(); + /* Initialize the window size variables. */ + window_size_init(); + + /* Set up the shortcuts. */ shortcut_init(FALSE); /* Set up the signal handlers. */ diff --git a/src/nano.h b/src/nano.h index b418ac8e..b9ac25f1 100644 --- a/src/nano.h +++ b/src/nano.h @@ -127,12 +127,6 @@ #define getline ngetline #endif -/* Slang curses emulation brain damage, part 3: Slang doesn't define - * mvwhline(), so use the version we have. */ -#ifdef USE_SLANG -#define mvwhline nmvwhline -#endif - #define VERMSG "GNU nano " VERSION /* If we aren't using ncurses, turn the mouse support off, as it's diff --git a/src/proto.h b/src/proto.h index 196d9151..1420fef5 100644 --- a/src/proto.h +++ b/src/proto.h @@ -65,7 +65,6 @@ extern char *backup_dir; extern WINDOW *topwin, *edit, *bottomwin; extern char *answer; -extern char *hblank; #ifndef DISABLE_HELP extern char *help_text; #endif @@ -239,6 +238,10 @@ void delete_opennode(openfilestruct *fileptr); void free_openfilestruct(openfilestruct *src); #endif void make_new_buffer(void); +void initialize_buffer(void); +#ifndef DISABLE_SPELLER +void reinitialize_buffer(void); +#endif void open_buffer(const char *filename); void load_buffer(void); #ifdef ENABLE_MULTIBUFFER @@ -358,8 +361,7 @@ void finish(void); void die(const char *msg, ...); void die_save_file(const char *die_filename); void check_die_too_small(void); -void resize_variables(void); -void resize_init(void); +void window_size_init(void); void window_init(void); #ifndef DISABLE_MOUSE void mouse_init(void); @@ -567,9 +569,6 @@ void get_totals(const filestruct *begin, const filestruct *end, size_t *lines, size_t *size); /* Public functions in winio.c. */ -#ifdef USE_SLANG -int nmvwhline(WINDOW *win, int y, int x, char ch, int n); -#endif #ifndef NANO_SMALL void reset_kbinput(void); #endif @@ -632,6 +631,7 @@ size_t xplustabs(void); size_t actual_x(const char *str, size_t xplus); size_t strnlenpt(const char *buf, size_t size); size_t strlenpt(const char *buf); +void blank_line(WINDOW *win, int y, int x, int n); void blank_titlebar(void); void blank_topbar(void); void blank_edit(void); diff --git a/src/winio.c b/src/winio.c index 3ddb0457..d9e8b8e1 100644 --- a/src/winio.c +++ b/src/winio.c @@ -52,19 +52,6 @@ static bool resetstatuspos = FALSE; /* Should we reset the cursor position * at the statusbar prompt? */ -#ifdef USE_SLANG -/* Slang curses emulation brain damage, part 4: Slang doesn't define - * mvwhline(). */ -int nmvwhline(WINDOW *win, int y, int x, char ch, int n) -{ - wmove(win, y, x); - for (; n > 0; n--) - waddch(win, ch); - - return 0; -} -#endif - /* Control character compatibility: * * - NANO_BACKSPACE_KEY is Ctrl-H, which is Backspace under ASCII, ANSI, @@ -2223,34 +2210,43 @@ size_t strlenpt(const char *buf) return strnlenpt(buf, (size_t)-1); } +/* Move to (x, y) in win, and display a line of n spaces with the + * current attributes. */ +void blank_line(WINDOW *win, int y, int x, int n) +{ + wmove(win, y, x); + for (; n > 0; n--) + waddch(win, ' '); +} + void blank_titlebar(void) { - mvwhline(topwin, 0, 0, ' ', COLS); + blank_line(topwin, 0, 0, COLS); } void blank_topbar(void) { if (!ISSET(MORE_SPACE)) - mvwhline(topwin, 1, 0, ' ', COLS); + blank_line(topwin, 1, 0, COLS); } void blank_edit(void) { int i; for (i = 0; i < editwinrows; i++) - mvwhline(edit, i, 0, ' ', COLS); + blank_line(edit, i, 0, COLS); } void blank_statusbar(void) { - mvwhline(bottomwin, 0, 0, ' ', COLS); + blank_line(bottomwin, 0, 0, COLS); } void blank_bottombars(void) { if (!ISSET(NO_HELP)) { - mvwhline(bottomwin, 1, 0, ' ', COLS); - mvwhline(bottomwin, 2, 0, ' ', COLS); + blank_line(bottomwin, 1, 0, COLS); + blank_line(bottomwin, 2, 0, COLS); } } @@ -2747,17 +2743,18 @@ void titlebar(const char *path) { int space; /* The space we have available for display. */ - size_t verlen = strlenpt(VERMSG) + 1; + size_t verlen = strlenpt(VERMSG); /* The length of the version message in columns. */ const char *prefix; - /* "File:", "Dir:", or "New Buffer". Goes before filename. */ + /* "DIR:", "File:", or "New Buffer". Goes before filename. */ size_t prefixlen; - /* The length of the prefix in columns, plus one. */ + /* The length of the prefix in columns. */ const char *state; - /* "Modified", "View", or spaces the length of "Modified". - * Tells the state of this buffer. */ + /* "Modified", "View", or "". Shows the state of this + * buffer. */ size_t statelen = 0; - /* The length of the state in columns, plus one. */ + /* The length of the state in columns, or the length of + * "Modified" if the state is blank. */ char *exppath = NULL; /* The file name, expanded for display. */ bool newfie = FALSE; @@ -2771,34 +2768,34 @@ void titlebar(const char *path) wattron(topwin, A_REVERSE); blank_titlebar(); - if (COLS <= 5 || COLS - 5 < verlen) + if (COLS <= 4 || COLS - 4 < verlen) space = 0; else { - space = COLS - 5 - verlen; - /* Reserve 2/3 of the screen plus one column for after the + space = COLS - 4 - verlen; + /* Reserve 2/3 of the screen plus two columns for after the * version message. */ - if (space < COLS - (COLS / 3) + 1) - space = COLS - (COLS / 3) + 1; + if (space < COLS - (COLS / 3) + 2) + space = COLS - (COLS / 3) + 2; } - if (COLS > 4) { - /* The version message should only take up 1/3 of the screen - * minus one column. */ + if (COLS > 3) { + /* The version message, counting the two spaces before it, + * should only take up 1/3 of the screen minus two columns. */ mvwaddnstr(topwin, 0, 2, VERMSG, actual_x(VERMSG, - (COLS / 3) - 3)); - waddstr(topwin, " "); + (COLS / 3) - 4)); + waddch(topwin, ' '); } - if (openfile->modified) - state = _("Modified"); - else if (ISSET(VIEW_MODE)) - state = _("View"); - else { - if (space > 0) - statelen = strnlenpt(_("Modified"), space - 1) + 1; - state = &hblank[COLS - statelen]; - } - statelen = strnlenpt(state, COLS); +#ifndef DISABLE_BROWSER + /* Don't display the state if we're in the file browser. */ + if (path != NULL) + state = ""; + else +#endif + state = openfile->modified ? _("Modified") : ISSET(VIEW_MODE) ? + _("View") : ""; + + statelen = strlenpt((state[0] != '\0') ? state : _("Modified")); /* We need a space before state. */ if ((openfile->modified || ISSET(VIEW_MODE)) && statelen < COLS) @@ -2810,6 +2807,7 @@ void titlebar(const char *path) goto the_end; #ifndef DISABLE_BROWSER + /* path should be a directory if we're in the file browser. */ if (path != NULL) prefix = _("DIR:"); else @@ -2828,8 +2826,11 @@ void titlebar(const char *path) if (!newfie && prefixlen + statelen < space) prefixlen++; + /* If we're not in the file browser, path should be the current + * filename. */ if (path == NULL) path = openfile->filename; + if (space >= prefixlen + statelen) space -= prefixlen + statelen; else @@ -2837,9 +2838,9 @@ void titlebar(const char *path) /* space is now the room we have for the file name. */ if (!newfie) { - size_t lenpt = strlenpt(path), start_col; + size_t lenpt = strlenpt(path) + 1, start_col; - dots = (lenpt > space); + dots = (lenpt >= space); if (dots) { start_col = lenpt - space + 3; @@ -2855,8 +2856,8 @@ void titlebar(const char *path) /* The length of the expanded filename. */ /* There is room for the whole filename, so we center it. */ - waddnstr(topwin, hblank, (space - exppathlen) / 3); - waddnstr(topwin, prefix, actual_x(prefix, prefixlen)); + mvwaddnstr(topwin, 0, ((COLS / 3) - 4) + ((space - exppathlen) / + 3), prefix, actual_x(prefix, prefixlen)); if (!newfie) { assert(strlenpt(prefix) + 1 == prefixlen); @@ -2878,14 +2879,16 @@ void titlebar(const char *path) the_end: free(exppath); - if (COLS <= 1 || statelen >= COLS - 1) - mvwaddnstr(topwin, 0, 0, state, actual_x(state, COLS)); - else { - assert(COLS - statelen - 2 >= 0); + if (state[0] != '\0') { + if (COLS <= 1 || statelen >= COLS - 1) + mvwaddnstr(topwin, 0, 0, state, actual_x(state, COLS)); + else { + assert(COLS - statelen - 2 >= 0); - mvwaddch(topwin, 0, COLS - statelen - 2, ' '); - mvwaddnstr(topwin, 0, COLS - statelen - 1, state, + mvwaddch(topwin, 0, COLS - statelen - 2, ' '); + mvwaddnstr(topwin, 0, COLS - statelen - 1, state, actual_x(state, statelen)); + } } wattroff(topwin, A_REVERSE); @@ -3448,7 +3451,7 @@ void update_line(const filestruct *fileptr, size_t index) return; /* First, blank out the line. */ - mvwhline(edit, line, 0, ' ', COLS); + blank_line(edit, line, 0, COLS); /* Next, convert variables that index the line to their equivalent * positions in the expanded line. */ @@ -3632,7 +3635,7 @@ void edit_refresh(void) foo = foo->next; } while (nlines < editwinrows) { - mvwhline(edit, nlines, 0, ' ', COLS); + blank_line(edit, nlines, 0, COLS); nlines++; } reset_cursor(); @@ -3789,8 +3792,14 @@ int do_yesno(bool all, const char *msg) void total_redraw(void) { - touchwin(stdscr); - wrefresh(stdscr); +#ifdef USE_SLANG + /* Slang curses emulation brain damage, part 3: Slang doesn't define + * curscr. */ + SLsmg_touch_screen(); + SLsmg_refresh(); +#else + wrefresh(curscr); +#endif } void total_refresh(void)