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
This commit is contained in:
Chris Allegretta 2001-01-14 05:18:27 +00:00
parent 201d9bf467
commit e61e830010
3 changed files with 47 additions and 6 deletions

View File

@ -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.

33
nano.c
View File

@ -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);

12
nano.h
View File

@ -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 */