diff -u nano/global.c nano-working/global.c --- nano/global.c Sun May 12 15:52:15 2002 +++ nano-working/global.c Wed May 15 03:58:50 2002 @@ -338,7 +338,7 @@ nano_exit_msg = _("Exit from nano"); #endif - nano_goto_msg = _("Goto a specific line number"); + nano_goto_msg = _("Go to a specific line number"); nano_justify_msg = _("Justify the current paragraph"); nano_unjustify_msg = _("Unjustify after a justify"); nano_replace_msg = _("Replace text within the editor"); @@ -369,7 +369,7 @@ _("Make the current search or replace case (in)sensitive"); nano_tofiles_msg = _("Go to file browser"); nano_execute_msg = _("Execute external command"); - nano_gotodir_msg = _("Goto Directory"); + nano_gotodir_msg = _("Go to directory"); nano_cancel_msg = _("Cancel the current function"); nano_append_msg = _("Append to the current file"); nano_prepend_msg = _("Prepend to the current file"); @@ -542,7 +542,7 @@ IFHELP(nano_enter_msg,) 0, KEY_ENTER, NANO_CONTROL_M, NOVIEW, do_enter_void); - sc_init_one(&main_list, NANO_GOTO_KEY, _("Goto Line"), + sc_init_one(&main_list, NANO_GOTO_KEY, _("Go To Line"), IFHELP(nano_goto_msg,) NANO_ALT_GOTO_KEY, NANO_GOTO_FKEY, 0, VIEW, do_gotoline_void); @@ -592,7 +592,7 @@ IFHELP(nano_replace_msg,) 0, 0, 0, VIEW, do_replace); - sc_init_one(&whereis_list, NANO_FROMSEARCHTOGOTO_KEY, _("Goto Line"), + sc_init_one(&whereis_list, NANO_FROMSEARCHTOGOTO_KEY, _("Go To Line"), IFHELP(nano_goto_msg,) 0, 0, 0, VIEW, do_gotoline_void); @@ -635,7 +635,7 @@ 0, 0, 0, VIEW, do_search); sc_init_one(&replace_list, NANO_FROMSEARCHTOGOTO_KEY, - _("Goto Line"), IFHELP(nano_goto_msg,) + _("Go To Line"), IFHELP(nano_goto_msg,) 0, 0, 0, VIEW, do_gotoline_void); #ifndef NANO_SMALL @@ -791,9 +791,9 @@ _("Get Help"), IFHELP(nano_help_msg,) 0, 0, 0, VIEW, do_help); - sc_init_one(&browser_list, NANO_EXIT_KEY, _("Exit"), - IFHELP(nano_exit_msg,) - 0, NANO_EXIT_FKEY, 0, VIEW, 0); + sc_init_one(&browser_list, NANO_CANCEL_KEY, _("Cancel"), + IFHELP(nano_cancel_msg,) + 0, 0, 0, VIEW, 0); sc_init_one(&browser_list, NANO_PREVPAGE_KEY, _("Prev Page"), IFHELP(nano_prevpage_msg,) @@ -803,7 +803,7 @@ IFHELP(nano_nextpage_msg,) 0, NANO_NEXTPAGE_FKEY, KEY_NPAGE, VIEW, 0); - sc_init_one(&browser_list, NANO_GOTO_KEY, _("Goto"), + sc_init_one(&browser_list, NANO_GOTO_KEY, _("Go To Dir"), IFHELP(nano_gotodir_msg,) NANO_ALT_GOTO_KEY, NANO_GOTO_FKEY, 0, VIEW, 0); diff -u nano/nano.c nano-working/nano.c --- nano/nano.c Sun May 12 15:52:15 2002 +++ nano-working/nano.c Wed May 15 04:10:21 2002 @@ -71,10 +71,6 @@ struct termios oldterm; /* The user's original term settings */ static struct sigaction act; /* For all our fun signal handlers */ -#ifndef DISABLE_HELP -static char *help_text_init = ""; /* Initial message, not including shortcuts */ -#endif - char *last_search = NULL; /* Last string we searched for */ char *last_replace = NULL; /* Last replacement string */ int search_last_line; /* Is this the last search line? */ @@ -257,31 +253,6 @@ } -#ifndef DISABLE_HELP -void init_help_msg(void) -{ - - help_text_init = - _(" nano help text\n\n " - "The nano editor is designed to emulate the functionality and " - "ease-of-use of the UW Pico text editor. There are four main " - "sections of the editor: The top line shows the program " - "version, the current filename being edited, and whether " - "or not the file has been modified. Next is the main editor " - "window showing the file being edited. The status line is " - "the third line from the bottom and shows important messages. " - "The bottom two lines show the most commonly used shortcuts " - "in the editor.\n\n " - "The notation for shortcuts is as follows: Control-key " - "sequences are notated with a caret (^) symbol and are entered " - "with the Control (Ctrl) key. Escape-key sequences are notated " - "with the Meta (M) symbol and can be entered using either the " - "Esc, Alt or Meta key depending on your keyboard setup. The " - "following keystrokes are available in the main editor window. " - "Optional keys are shown in parentheses:\n\n"); -} -#endif - /* Make a copy of a node to a pointer (space will be malloc()ed). This does NOT copy the data members used only by open_files. */ filestruct *copy_node(filestruct * src) @@ -2487,17 +2458,16 @@ } #ifndef DISABLE_HELP +/* This function allocates help_text, and stores the help string in it. + * help_text should be NULL initially. */ void help_init(void) { - int i, sofar = 0, helplen; - long allocsize = 1; /* How much space we're gonna need for the help text */ + size_t allocsize = 1; /* space needed for help_text */ char *ptr = NULL; #ifndef NANO_SMALL - toggle *t; + const toggle *t; #endif - shortcut *s; - - helplen = length_of_list(currshortcut); + const shortcut *s; /* First set up the initial help text for the current function */ if (currshortcut == whereis_list || currshortcut == replace_list @@ -2507,29 +2477,29 @@ "for, then hit enter. If there is a match for the text you " "entered, the screen will be updated to the location of the " "nearest match for the search string.\n\n " - "If using Pico Mode via the -p or --pico flags, using the " - "Meta-P toggle or using a nanorc file, the previous search " + "If using Pico Mode via the -p or --pico flags, the " + "Meta-P toggle, or a nanorc file, the previous search " "string will be shown in brackets after the Search: prompt. " - "Hitting enter without entering any text will perform the " - "previous search. Otherwise, the previous string will be " - "placed in front of the cursor, and can be edited or deleted " - "before hitting enter.\n\n The following functions keys are " + "Hitting Enter without entering any text will perform the " + "previous search. Otherwise, the previous string will be " + "placed before the cursor, and can be edited or deleted " + "before hitting enter.\n\n The following function keys are " "available in Search mode:\n\n"); else if (currshortcut == goto_list) - ptr = _("Goto Line Help Text\n\n " + ptr = _("Go To Line Help Text\n\n " "Enter the line number that you wish to go to and hit " "Enter. If there are fewer lines of text than the " "number you entered, you will be brought to the last line " - "of the file.\n\n The following functions keys are " - "available in Goto Line mode:\n\n"); + "of the file.\n\n The following function keys are " + "available in Go To Line mode:\n\n"); else if (currshortcut == insertfile_list) ptr = _("Insert File Help Text\n\n " "Type in the name of a file to be inserted into the current " "file buffer at the current cursor location.\n\n " "If you have compiled nano with multiple file buffer " "support, and enable multiple buffers with the -F " - "or --multibuffer command line flags, the Meta-F toggle or " - "using a nanorc file, inserting a file will cause it to be " + "or --multibuffer command line flags, the Meta-F toggle, or " + "a nanorc file, inserting a file will cause it to be " "loaded into a separate buffer (use Meta-< and > to switch " "between file buffers).\n\n If you need another blank " "buffer, do not enter any filename, or type in a " @@ -2539,9 +2509,9 @@ else if (currshortcut == writefile_list) ptr = _("Write File Help Text\n\n " "Type the name that you wish to save the current file " - "as and hit enter to save the file.\n\n " - "If you are using the marker code with Ctrl-^ and have " - "selected text, you will be prompted to save only the " + "as and hit Enter to save the file.\n\n " + "If you have selected text with Ctrl-^, you will be " + "prompted to save only the " "selected portion to a separate file. To reduce the " "chance of overwriting the current file with just a portion " "of it, the current filename is not the default in this " @@ -2555,17 +2525,17 @@ "or writing. You may use the arrow keys or Page Up/" "Down to browse through the files, and S or Enter to " "choose the selected file or enter the selected " - "directory. To move up one level, select the directory " + "directory. To move up one level, select the directory " "called \"..\" at the top of the file list.\n\n The " - "following functions keys are available in the file " + "following function keys are available in the file " "browser:\n\n"); else if (currshortcut == gotodir_list) - ptr = _("Browser Goto Directory Help Text\n\n " + ptr = _("Browser Go To Directory Help Text\n\n " "Enter the name of the directory you would like to " "browse to.\n\n If tab completion has not been disabled, " "you can use the TAB key to (attempt to) automatically " - "complete the directory name.\n\n The following function " - "keys are available in Browser GotoDir mode:\n\n"); + "complete the directory name.\n\n The following function " + "keys are available in Browser Go To Directory mode:\n\n"); #endif else if (currshortcut == spell_list) ptr = _("Spell Check Help Text\n\n " @@ -2585,107 +2555,117 @@ "available in this mode:\n\n"); #endif else /* Default to the main help list */ - ptr = help_text_init; + ptr = _(" nano help text\n\n " + "The nano editor is designed to emulate the functionality and " + "ease-of-use of the UW Pico text editor. There are four main " + "sections of the editor: The top line shows the program " + "version, the current filename being edited, and whether " + "or not the file has been modified. Next is the main editor " + "window showing the file being edited. The status line is " + "the third line from the bottom and shows important messages. " + "The bottom two lines show the most commonly used shortcuts " + "in the editor.\n\n " + "The notation for shortcuts is as follows: Control-key " + "sequences are notated with a caret (^) symbol and are entered " + "with the Control (Ctrl) key. Escape-key sequences are notated " + "with the Meta (M) symbol and can be entered using either the " + "Esc, Alt or Meta key depending on your keyboard setup. The " + "following keystrokes are available in the main editor window. " + "Alternative keys are shown in parentheses:\n\n"); - /* Compute the space needed for the shortcut lists - we add 15 to - have room for the shortcut abbrev and its possible alternate keys */ - s = currshortcut; - for (i = 0; i <= helplen - 1; i++) { - if (s->help != NULL) - allocsize += strlen(s->help) + 15; - s = s->next; + assert(currshortcut != NULL); + /* Compute the space needed for the shortcut lists */ + for (s = currshortcut; s != NULL; s = s->next) { + assert(s->help != NULL); + /* Each shortcut has at most 24 chars for the shortcut keys, plus + * the help description, plus 1 for \n. */ + allocsize += strlen(s->help) + 25; } #ifndef NANO_SMALL - /* If we're on the main list, we also allocate space for toggle help text. */ + /* If we're on the main list, we also count the toggle help text. */ if (currshortcut == main_list) { - for (t = toggles; t != NULL; t = t->next) - if (t->desc != NULL) - allocsize += strlen(t->desc) + 30; + for (t = toggles; t != NULL; t = t->next) { + size_t len; + + assert(t->desc != NULL); + len = strlen(t->desc); + + /* 6 for "M-%c\t\t\t", which fills 24 columns. */ + allocsize += 6 + (len < COLS-24 ? len : COLS-24); + } } #endif /* !NANO_SMALL */ allocsize += strlen(ptr); - if (help_text != NULL) - free(help_text); + /* Other routines should have set help_text to NULL before */ + assert(help_text == NULL); /* Allocate space for the help text */ help_text = charalloc(allocsize); /* Now add the text we want */ strcpy(help_text, ptr); - sofar = strlen(help_text); + ptr = help_text + strlen(help_text); /* Now add our shortcut info */ - s = currshortcut; - for (i = 0; i <= helplen - 1; i++) { + for (s = currshortcut; s != NULL; s = s->next) { + /* true if the character in s->altval is shown in first column */ int meta_shortcut = 0; if (s->val > 0 && s->val < 32) - sofar += sprintf(help_text + sofar, "^%c\t", s->val + 64); + ptr += sprintf(ptr, "^%c", s->val + 64); #ifndef NANO_SMALL else if (s->val == NANO_CONTROL_SPACE) - sofar += sprintf(help_text + sofar, "^%s\t", _("Space")); -#endif - else if (s->altval > 0) + ptr += snprintf(ptr, 8, "^%s", _("Space")); + else if (s->altval == NANO_ALT_SPACE) { meta_shortcut = 1; - else - help_text[sofar++] = '\t'; - - if (!meta_shortcut) { - if (s->misc1 > KEY_F0 && s->misc1 <= KEY_F(64)) - sofar += sprintf(help_text + sofar, "(F%d)", - s->misc1 - KEY_F0); - help_text[sofar++] = '\t'; + ptr += snprintf(ptr, 8, "M-%s", _("Space")); } - -#ifndef NANO_SMALL - if (s->altval == NANO_ALT_SPACE) - sofar += sprintf(help_text + sofar, "M-%s", _("Space")); - else #endif - if (s->altval > 0) - sofar += sprintf(help_text + sofar, - (meta_shortcut ? "M-%c" : "(M-%c)"), s->altval - - (('A' <= s->altval && s->altval <= 'Z') || 'a' <= s->altval - ? 32 : 0)); + else if (s->altval > 0) { + meta_shortcut = 1; + ptr += sprintf(ptr, "M-%c", s->altval - + (('A' <= s->altval && s->altval <= 'Z') || + 'a' <= s->altval ? 32 : 0)); + } /* Hack */ - else if (s->val >= 'a') - sofar += sprintf(help_text + sofar, - (meta_shortcut ? "(M-%c)\t" : "M-%c\t"), s->val - 32); + else if (s->val >= 'a') { + meta_shortcut = 1; + ptr += sprintf(ptr, "M-%c", s->val - 32); + } - help_text[sofar++] = '\t'; + *(ptr++) = '\t'; - if (meta_shortcut) { - if (s->misc1 > KEY_F0 && s->misc1 <= KEY_F(64)) - sofar += sprintf(help_text + sofar, - "(F%d)", s->misc1 - KEY_F0); - help_text[sofar++] = '\t'; - help_text[sofar++] = '\t'; - } + if (s->misc1 > KEY_F0 && s->misc1 <= KEY_F(64)) + ptr += sprintf(ptr, "(F%d)", s->misc1 - KEY_F0); + + *(ptr++) = '\t'; - if (s->help != NULL) - sofar += sprintf(help_text + sofar, "%s", s->help); + if (!meta_shortcut && s->altval > 0) + ptr += sprintf(ptr, "(M-%c)", s->altval - + (('A' <= s->altval && s->altval <= 'Z') || 'a' <= s->altval + ? 32 : 0)); - help_text[sofar++] = '\n'; + *(ptr++) = '\t'; - s = s->next; + ptr += sprintf(ptr, "%s\n", s->help); } #ifndef NANO_SMALL /* And the toggles... */ if (currshortcut == main_list) for (t = toggles; t != NULL; t = t->next) { - sofar += sprintf(help_text + sofar, "M-%c\t\t\t", - t->val - 32); - if (t->desc != NULL) { - sofar += sprintf(help_text + sofar, - _("%s enable/disable"), t->desc); - } - help_text[sofar++] = '\n'; + ptr += sprintf(ptr, "M-%c\t\t\t", t->val - 32); + ptr += snprintf(ptr, COLS-24, _("%s enable/disable\n"), + t->desc); } #endif /* !NANO_SMALL */ + + /* If all went well, we didn't overwrite the allocated space for + * help_text. */ + assert(strlen(help_text) < allocsize); } #endif @@ -3067,10 +3047,6 @@ /* Set up some global variables */ global_init(0); shortcut_init(0); -#ifndef DISABLE_HELP - init_help_msg(); - help_init(); -#endif signal_init(); #ifdef DEBUG diff -u nano/search.c nano-working/search.c --- nano/search.c Sun May 12 15:52:15 2002 +++ nano-working/search.c Wed May 15 03:55:18 2002 @@ -810,14 +810,8 @@ int do_gotoline(int line, int save_pos) { - int i = 1; - if (line <= 0) { /* Ask for it */ - - int j = 0; - - j = statusq(0, goto_list, "", _("Enter line number")); - if (j != 0) { + if (statusq(0, goto_list, "", _("Enter line number"))) { statusbar(_("Aborted")); goto_abort(); return 0; @@ -833,7 +827,7 @@ } } - for (current = fileage; ((current->next != NULL) && (i < line)); i++) + for (current = fileage; current->next != NULL && line > 0; line--) current = current->next; current_x = 0; @@ -845,7 +839,7 @@ else edit_update(current, CENTER); - placewewant = xplustabs(); + placewewant = 0; goto_abort(); return 1; } diff -u nano/winio.c nano-working/winio.c --- nano/winio.c Sun May 12 16:43:49 2002 +++ nano-working/winio.c Wed May 15 03:55:18 2002 @@ -68,7 +68,7 @@ } /* Like xplustabs, but for a specific index of a specific filestruct */ -int xpt(filestruct * fileptr, int index) +int xpt(const filestruct *fileptr, int index) { int i, tabs = 0; @@ -1694,12 +1694,11 @@ return do_cursorpos(0); } -/* Our broken, non-shortcut list compliant help function. - But, hey, it's better than nothing, and it's dynamic! */ +/* Our shortcut-list-compliant help function, which is + * better than nothing, and dynamic! */ int do_help(void) { #ifndef DISABLE_HELP - char *ptr, *end; int i, j, row = 0, page = 1, kbinput = 0, no_more = 0, kp, kp2; int no_help_flag = 0; shortcut *oldshortcut; @@ -1709,8 +1708,9 @@ wattroff(bottomwin, A_REVERSE); blank_statusbar(); + /* set help_text as the string to display */ help_init(); - ptr = help_text; + assert(help_text != NULL); oldshortcut = currshortcut; @@ -1732,7 +1732,8 @@ bottombars(help_list); do { - ptr = help_text; + const char *ptr = help_text; + switch (kbinput) { #ifndef DISABLE_MOUSE #ifdef NCURSES_MOUSE_VERSION @@ -1775,14 +1776,10 @@ } } - if (i > 1) { - - } - i = 0; j = 0; while (i < editwinrows && *ptr != '\0') { - end = ptr; + const char *end = ptr; while (*end != '\n' && *end != '\0' && j != COLS - 5) { end++; j++; @@ -1827,6 +1824,11 @@ #elif defined(DISABLE_HELP) nano_disabled_msg(); #endif + + /* The help_init() at the beginning allocated help_text, which has + * now been written to screen. */ + free(help_text); + help_text = NULL; return 1; }