From e61e830010b35ba0616e200849f721cf95610c3d Mon Sep 17 00:00:00 2001 From: Chris Allegretta Date: Sun, 14 Jan 2001 05:18:27 +0000 Subject: [PATCH] Rocco's source code cleanups and #defines for magic values in global_init(). Added die_too_small() function git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@476 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 8 ++++++++ nano.c | 33 ++++++++++++++++++++++++++++----- nano.h | 12 +++++++++++- 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6b269db4..f50531f8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,6 +9,8 @@ General - Added message for when keypad goes awry. Added code in main and function print_numlock_warning() to notify user, and added an apropriate section in the faq to refer to this brokenness. + - Added macros in nano.h for magic values that might be unclear in + nano.c:global_init(). - configure.in: - Fix for _use_keypad check breaking slang support (Christian Weisgerber). @@ -43,6 +45,12 @@ General usage() - Alternate speller option no longer valid if DISABLE_SPELLER is active. (Rocco) + window_init(), handle_sigwinch() + - Added check for not having enough LINES to do anything useful, + if so die with an error. (Rocco) + die_too_small() + - Function to print the window too small error message, avoids + repeated string defs and globals. - fi.po: - Update by Pauli Virtanen. diff --git a/nano.c b/nano.c index d859148e..43468ebd 100644 --- a/nano.c +++ b/nano.c @@ -141,6 +141,16 @@ void die(char *msg, ...) exit(1); /* We have a problem: exit w/ errorlevel(1) */ } +/* Die with an error message that the screen was too small if, well, the + screen is too small */ +void die_too_small(void) +{ + char *too_small_msg = _("Window size is too small for Nano..."); + + die(too_small_msg); + +} + void print_view_warning(void) { statusbar(_("Key illegal in VIEW mode")); @@ -163,7 +173,10 @@ void global_init(void) center_y = LINES / 2; current_x = 0; current_y = 0; - editwinrows = LINES - 5 + no_help(); + + if ((editwinrows = LINES - 5 + no_help()) < MIN_EDITOR_ROWS) + die_too_small(); + fileage = NULL; cutbuffer = NULL; current = NULL; @@ -171,8 +184,13 @@ void global_init(void) editbot = NULL; totlines = 0; placewewant = 0; + if (!fill) - fill = COLS - 8; + fill = COLS - CHARS_FROM_EOL; + + if (fill < MIN_FILL_LENGTH) + die_too_small(); + hblank = nmalloc(COLS + 1); /* Thanks BG for this bit... */ @@ -1555,8 +1573,12 @@ void handle_sigwinch(int s) center_x = COLS / 2; center_y = LINES / 2; - editwinrows = LINES - 5 + no_help(); - fill = COLS - 8; + + if ((editwinrows = LINES - 5 + no_help()) < MIN_EDITOR_ROWS) + die_too_small(); + + if ((fill = COLS - CHARS_FROM_EOL) < MIN_FILL_LENGTH) + die_too_small(); free(hblank); hblank = nmalloc(COLS + 1); @@ -1629,7 +1651,8 @@ void signal_init(void) void window_init(void) { - editwinrows = LINES - 5 + no_help(); + if ((editwinrows = LINES - 5 + no_help()) < MIN_EDITOR_ROWS) + die_too_small(); /* Setup up the main text window */ edit = newwin(editwinrows, COLS, 2, 0); diff --git a/nano.h b/nano.h index 6bc4b6d8..0168ae41 100644 --- a/nano.h +++ b/nano.h @@ -266,4 +266,14 @@ know what you're doing */ #define TOP 2 #define CENTER 1 #define BOTTOM 0 -#endif + +/* Minimum editor window rows required for Nano to work correctly */ +#define MIN_EDITOR_ROWS 3 + +/* Default number of characters from end-of-line where text wrapping occurs */ +#define CHARS_FROM_EOL 8 + +/* Minimum fill length (space available for text before wrapping occurs) */ +#define MIN_FILL_LENGTH 10 + +#endif /* ifndef NANO_H */ -- 2.39.5