From: David Lawrence Ramsey Date: Wed, 19 Jan 2005 19:52:42 +0000 (+0000) Subject: add DB's (slightly tweaked) changes to make resizing more flexible, and X-Git-Tag: v1.3.6~113 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=5040666fbb489f2641db56f860b7afcf629e08da;p=nano.git add DB's (slightly tweaked) changes to make resizing more flexible, and also add his replacement of RETSIGTYPE with void, which avoids some potential problems git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2289 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index fc42e5c0..b9d2ab67 100644 --- a/ChangeLog +++ b/ChangeLog @@ -128,6 +128,18 @@ CVS code - statusbar prompt. New functions do_statusbar_next_word() and do_statusbar_prev_word(); changes to do_statusbar_input(). (DLR) + - Make resizing more flexible. We now can work with as few as + one row, and with no limit on the number of columns (except of + course the curses-imposed limit that it be greater than zero). + New function resize_variables(); changes to die_too_small() + (renamed check_die_too_small()), global_init(), window_init(), + and handle_sigwinch(). (David Benbennick) DLR: Tweak the + coordinate formula in window_init() so that the statusbar + prompt is always visible. + - Use void instead of RETSIGTYPE, as signal handlers are + supposed to return void anyway. Also, the value of RETSIGTYPE + is sometimes misdetected as int, leading to compilation + warnings or errors. (David Benbennick) - cut.c: do_cut_text() - If keep_cutbuffer is FALSE, only blow away the text in the @@ -186,6 +198,7 @@ CVS code - - nano.h: - Remove now-unneeded #defines for functions that now have multibyte equivalents. (DLR) + - Remove now-unneeded MIN_EDITOR_COLS. (David Benbennick) - utils.c: regexec_safe() - Remove redundant regexec #define, and move the regexec #undef diff --git a/src/nano.c b/src/nano.c index 9e072ade..342e3af8 100644 --- a/src/nano.c +++ b/src/nano.c @@ -79,6 +79,11 @@ static filestruct *jusbottom = NULL; /* Pointer to end of justify buffer. */ #endif +void print_view_warning(void) +{ + statusbar(_("Key illegal in VIEW mode")); +} + /* What we do when we're all set to exit. */ void finish(void) { @@ -178,54 +183,52 @@ void die_save_file(const char *die_filename) /* Die with an error message that the screen was too small if, well, the * screen is too small. */ -void die_too_small(void) +void check_die_too_small(void) { - die(_("Window size is too small for nano...\n")); + editwinrows = LINES - 5 + no_more_space() + no_help(); + if (editwinrows < MIN_EDITOR_ROWS) + die(_("Window size is too small for nano...\n")); } -void print_view_warning(void) +/* Reassign variables that depend on the window size. That is, fill and + * hblank. */ +void resize_variables(void) { - statusbar(_("Key illegal in VIEW mode")); +#ifndef DISABLE_WRAPJUSTIFY + fill = wrap_at; + if (fill <= 0) + fill += COLS; + if (fill < 0) + fill = 0; +#endif + + hblank = charealloc(hblank, COLS + 1); + memset(hblank, ' ', COLS); + hblank[COLS] = '\0'; } /* Initialize global variables -- no better way for now. If * save_cutbuffer is TRUE, don't set cutbuffer to NULL. */ void global_init(bool save_cutbuffer) { - current_x = 0; - current_y = 0; - - editwinrows = LINES - 5 + no_more_space() + no_help(); - if (editwinrows < MIN_EDITOR_ROWS || COLS < MIN_EDITOR_COLS) - die_too_small(); + check_die_too_small(); + resize_variables(); fileage = NULL; + edittop = NULL; + current = NULL; if (!save_cutbuffer) cutbuffer = NULL; - current = NULL; - edittop = NULL; + current_x = 0; + placewewant = 0; + current_y = 0; totlines = 0; totsize = 0; - placewewant = 0; - -#ifndef DISABLE_WRAPJUSTIFY - fill = wrap_at; - if (fill <= 0) - fill += COLS; - if (fill < 0) - fill = 0; -#endif - - hblank = charalloc(COLS + 1); - memset(hblank, ' ', COLS); - hblank[COLS] = '\0'; } void window_init(void) { - editwinrows = LINES - 5 + no_more_space() + no_help(); - if (editwinrows < MIN_EDITOR_ROWS) - die_too_small(); + check_die_too_small(); if (topwin != NULL) delwin(topwin); @@ -237,7 +240,7 @@ void window_init(void) /* Set up the windows. */ topwin = newwin(2 - no_more_space(), COLS, 0, 0); edit = newwin(editwinrows, COLS, 2 - no_more_space(), 0); - bottomwin = newwin(3 - no_help(), COLS, LINES - 3 + no_help(), 0); + bottomwin = newwin(3 - no_help(), COLS, editwinrows + 1, 0); /* Turn the keypad back on. */ keypad(edit, TRUE); @@ -1054,7 +1057,7 @@ void nano_disabled_msg(void) } #ifndef NANO_SMALL -RETSIGTYPE cancel_fork(int signal) +void cancel_fork(int signal) { if (kill(pid, SIGKILL) == -1) nperror("kill"); @@ -3259,13 +3262,13 @@ void signal_init(void) } /* Handler for SIGHUP (hangup) and SIGTERM (terminate). */ -RETSIGTYPE handle_hupterm(int signal) +void handle_hupterm(int signal) { die(_("Received SIGHUP or SIGTERM\n")); } /* Handler for SIGTSTP (suspend). */ -RETSIGTYPE do_suspend(int signal) +void do_suspend(int signal) { endwin(); printf("\n\n\n\n\n%s\n", _("Use \"fg\" to return to nano")); @@ -3285,7 +3288,7 @@ RETSIGTYPE do_suspend(int signal) } /* Handler for SIGCONT (continue after suspend). */ -RETSIGTYPE do_cont(int signal) +void do_cont(int signal) { #ifndef NANO_SMALL /* Perhaps the user resized the window while we slept. Handle it @@ -3321,21 +3324,9 @@ void handle_sigwinch(int s) * But not in all cases, argh. */ COLS = win.ws_col; LINES = win.ws_row; - editwinrows = LINES - 5 + no_more_space() + no_help(); - if (editwinrows < MIN_EDITOR_ROWS || COLS < MIN_EDITOR_COLS) - die_too_small(); - -#ifndef DISABLE_WRAPJUSTIFY - fill = wrap_at; - if (fill <= 0) - fill += COLS; - if (fill < 0) - fill = 0; -#endif - hblank = charealloc(hblank, COLS + 1); - memset(hblank, ' ', COLS); - hblank[COLS] = '\0'; + check_die_too_small(); + resize_variables(); /* If we've partitioned the filestruct, unpartition it now. */ if (filepart != NULL) diff --git a/src/nano.h b/src/nano.h index 31a50866..b8814d5a 100644 --- a/src/nano.h +++ b/src/nano.h @@ -501,10 +501,7 @@ typedef struct historyheadtype { #define NOVIEW FALSE /* Minimum editor window rows required for nano to work correctly. */ -#define MIN_EDITOR_ROWS 3 - -/* Minimum editor window cols required for nano to work correctly. */ -#define MIN_EDITOR_COLS 10 +#define MIN_EDITOR_ROWS 1 /* Default number of characters from end-of-line where text wrapping * occurs. */ diff --git a/src/proto.h b/src/proto.h index 9413b164..0b1581e9 100644 --- a/src/proto.h +++ b/src/proto.h @@ -343,11 +343,12 @@ void do_right(bool allow_update); void do_right_void(void); /* Public functions in nano.c. */ +void print_view_warning(void); void finish(void); void die(const char *msg, ...); void die_save_file(const char *die_filename); -void die_too_small(void); -void print_view_warning(void); +void check_die_too_small(void); +void resize_variables(void); void global_init(bool save_cutbuffer); void window_init(void); #ifndef DISABLE_MOUSE @@ -380,7 +381,7 @@ int no_more_space(void); int no_help(void); void nano_disabled_msg(void); #ifndef NANO_SMALL -RETSIGTYPE cancel_fork(int signal); +void cancel_fork(int signal); bool open_pipe(const char *command); #endif void do_verbatim_input(void); @@ -428,9 +429,9 @@ void do_full_justify(void); #endif /* !DISABLE_JUSTIFY */ void do_exit(void); void signal_init(void); -RETSIGTYPE handle_hupterm(int signal); -RETSIGTYPE do_suspend(int signal); -RETSIGTYPE do_cont(int signal); +void handle_hupterm(int signal); +void do_suspend(int signal); +void do_cont(int signal); #ifndef NANO_SMALL void handle_sigwinch(int s); void allow_pending_sigwinch(bool allow);