Removed intl/ entirely, and a few more tweaks by gettextize.
- i18nized a few strings used in DEBUG mode. (DLR)
- Some chars being assigned 0 are now assigned '\0'. (DLR)
- - Put header files in a more consistent order. (DLR)
+ - Put header file #includes in a more consistent order. (DLR)
- Remove some unneeded blank lines and spaces, and make some
spacing more consistent. (DLR)
- When possible, use iscntrl() to determine whether a character
is a control character or not. (DLR)
- Miscellaneous typo fixes. (DLR)
+ - Many fixes to the help browser and shortcut lists: efficiency
+ updates, consistency fixes, help text fixes and improvements,
+ and spacing improvements. (David Benbennick)
+ - Make more functions use const variables when possible. (David
+ Benbennick)
- files.c:
read_file(), read_line():
- Rework to properly handle nulls in the input file, fix
with it, instead of calling clear_filename() in two places.
Make startline an int instead of a long, since it's supposed to
hold a line number. (DLR)
+ - Properly handle multiple -r settings on the command line. (Carl
+ Drinkwater)
- search.c:
findnextstr():
- Update the current line at current_x if we don't find a match.
- (DLR)
+ Also, pass current_x_find to strstrwrapper() so we know whether
+ we're at the beginning of a string or not (see changes to
+ strstrwrapper() below), and reset it between lines. (DLR)
+ do_gotoline():
+ - Make sure placewewant is zero after we go to a line. (David
+ Benbennick)
do_gotopos():
- Simplify the sanity check to only put x within the range of the
current line; don't call actual_x() anymore. (DLR)
other than the terminating null in strings to newlines and
back; they're used to handle null characters in files properly.
(DLR)
+ strstrwrapper(): Set REG_NOTBOL when we're not at the beginning of a
+ string, to avoid false positives when searching for regular
+ expressions prefixed with ^. Make it take a new parameter,
+ line_pos, to determine where we are in the string. (DLR)
- winio.c:
actual_x_from_start():
- Overhaul to make cursor placement more like that of Pico: add
- After the user presses Enter at the prompt, refresh the edit
window in case there's a list of possible filename matches
(left over from attempted tab completion) on it. (DLR)
+ titlebar():
+ - Tweak text spacing and printing so that the titlebar text looks
+ better on smaller terminals. (Carl Drinkwater)
update_line():
- When marking control characters, make sure the mark moves
forward by two characters inctead of one. Rework control
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");
_("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");
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);
+#ifndef NANO_SMALL
+ sc_init_one(&main_list, NANO_NEXTWORD_KEY, _("Next Word"),
+ IFHELP(_("Move forward one word"), 0),
+ 0, 0, VIEW, do_next_word_void);
+
+ sc_init_one(&main_list, -9, _("Prev Word"),
+ IFHELP(_("Move backward one word"), NANO_PREVWORD_KEY), 0, 0,
+ VIEW, do_prev_word_void);
+#endif
+
#if (!defined NANO_SMALL) && (defined HAVE_REGEX_H)
sc_init_one(&main_list, -9, _("Find Other Bracket"),
IFHELP(nano_bracket_msg, NANO_BRACKET_KEY),
0, 0, VIEW, open_nextfile_void);
#endif
-#ifndef NANO_SMALL
- sc_init_one(&main_list, NANO_NEXTWORD_KEY, _("Next Word"),
- IFHELP(_("Move forward one word"), 0),
- 0, 0, VIEW, do_next_word_void);
- sc_init_one(&main_list, -9, _("Prev Word"),
- IFHELP(_("Move backward one word"), NANO_PREVWORD_KEY), 0, 0,
- VIEW, do_prev_word_void);
-#endif
-
free_shortcutage(&whereis_list);
sc_init_one(&whereis_list, NANO_HELP_KEY, _("Get Help"),
sc_init_one(&whereis_list, NANO_OTHERSEARCH_KEY, _("Replace"),
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);
#ifndef NANO_SMALL
sc_init_one(&replace_list, NANO_OTHERSEARCH_KEY, _("No Replace"),
IFHELP(nano_whereis_msg, 0), 0, 0, VIEW, do_search);
- sc_init_one(&replace_list, NANO_FROMSEARCHTOGOTO_KEY, _("Goto Line"),
+ sc_init_one(&replace_list, NANO_FROMSEARCHTOGOTO_KEY, _("Go To Line"),
IFHELP(nano_goto_msg, 0), 0, 0, VIEW, do_gotoline_void);
#ifndef NANO_SMALL
sc_init_one(&browser_list, NANO_HELP_KEY, _("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), NANO_EXIT_FKEY, 0, VIEW, 0);
sc_init_one(&browser_list, NANO_PREVPAGE_KEY, _("Prev Page"),
IFHELP(nano_prevpage_msg, 0), NANO_PREVPAGE_FKEY,
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);
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? */
}
-#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. */
+/* Make a copy of a node to a pointer (space will be malloc()ed). */
filestruct *copy_node(filestruct * src)
{
filestruct *dst;
}
#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
"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 "
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 "
- "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 "
- "mode.\n\n The following function keys are available in "
- "Write File mode:\n\n");
+ "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 mode.\n\n The following function keys "
+ "are available in Write File mode:\n\n");
#ifndef DISABLE_BROWSER
else if (currshortcut == browser_list)
ptr = _("File Browser Help Text\n\n "
"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 "
"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);
-
- 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';
- help_text[sofar++] = '\t';
+ else if (s->val >= 'a') {
+ meta_shortcut = 1;
+ ptr += sprintf(ptr, "M-%c", s->val - 32);
}
- if (s->help != NULL)
- sofar += sprintf(help_text + sofar, "%s", s->help);
+ *(ptr++) = '\t';
+
+ if (s->misc1 > KEY_F0 && s->misc1 <= KEY_F(64))
+ ptr += sprintf(ptr, "(F%d)", s->misc1 - KEY_F0);
- help_text[sofar++] = '\n';
+ *(ptr++) = '\t';
- s = s->next;
+ if (!meta_shortcut && s->altval > 0)
+ ptr += sprintf(ptr, "(M-%c)", s->altval -
+ (('A' <= s->altval && s->altval <= 'Z') || 'a' <= s->altval
+ ? 32 : 0));
+
+ *(ptr++) = '\t';
+
+ 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
fill = atoi(optarg);
if (fill < 0)
wrap_at = fill;
+ else if (fill > 0)
+ wrap_at = 0;
else if (fill == 0) {
usage(); /* To stop bogus data (like a string) */
finish(1);
/* Set up some global variables */
global_init(0);
shortcut_init(0);
-#ifndef DISABLE_HELP
- init_help_msg();
- help_init();
-#endif
signal_init();
#ifdef DEBUG
char *revstrstr(char *haystack, char *needle, char *rev_start);
char *stristr(char *haystack, char *needle);
char *revstristr(char *haystack, char *needle, char *rev_start);
-char *strstrwrapper(char *haystack, char *needle, char *rev_start);
+char *strstrwrapper(char *haystack, char *needle, char *rev_start, int line_pos);
int search_init(int replacing);
int renumber(filestruct * fileptr);
int free_filestruct(filestruct * src);
searchstr = &fileptr->data[current_x_find];
/* Look for needle in searchstr */
- while ((found = strstrwrapper(searchstr, needle, rev_start)) == NULL) {
+ while ((found = strstrwrapper(searchstr, needle, rev_start, current_x_find)) == NULL) {
/* finished processing file, get out */
if (search_last_line) {
}
update_line(fileptr, 0);
+
+ /* reset current_x_find between lines */
+ current_x_find = 0;
+
fileptr = fileptr->next;
if (fileptr == editbot)
/* EOF reached ?, wrap around once */
if (fileptr == NULL) {
- if (bracket_mode) /* don't wrap if looking for bracket match */
+ /* don't wrap if looking for bracket match */
+ if (bracket_mode)
return NULL;
fileptr = fileage;
past_editbuff = 1;
searchstr = fileptr->data;
/* Look for needle in searchstr */
- while ((found = strstrwrapper(searchstr, needle, rev_start)) == NULL) {
+ while ((found = strstrwrapper(searchstr, needle, rev_start, current_x_find)) == NULL) {
/* finished processing file, get out */
if (search_last_line) {
}
update_line(fileptr, 0);
+
+ /* reset current_x_find between lines */
+ current_x_find = 0;
+
fileptr = fileptr->prev;
if (fileptr == edittop->prev)
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;
}
}
- for (current = fileage; ((current->next != NULL) && (i < line)); i++)
+ for (current = fileage; current->next != NULL && line > 1; line--)
current = current->next;
current_x = 0;
else
edit_update(current, CENTER);
- placewewant = xplustabs();
+ placewewant = 0;
goto_abort();
return 1;
}
return NULL;
}
-char *strstrwrapper(char *haystack, char *needle, char *rev_start)
+char *strstrwrapper(char *haystack, char *needle, char *rev_start, int line_pos)
{
#ifdef HAVE_REGEX_H
- int result;
+ int result;
if (ISSET(USE_REGEXP)) {
if (!ISSET(REVERSE_SEARCH)) {
- result = regexec(&search_regexp, haystack, 10, regmatches, 0);
+ result = regexec(&search_regexp, haystack, 10, regmatches, (line_pos > 0) ? REG_NOTBOL : 0);
if (!result)
return haystack + regmatches[0].rm_so;
#ifndef NANO_SMALL
/* do a quick search forward first */
if (!(regexec(&search_regexp, haystack, 10, regmatches, 0))) {
/* there's a match somewhere in the line - now search for it backwards, much slower */
- for(i = rev_start ; i >= haystack ; --i)
- if (!(result = regexec(&search_regexp, i, 10, regmatches, 0))) {
+ for (i = rev_start; i >= haystack; --i) {
+ if (!(result = regexec(&search_regexp, i, 10, regmatches, (i > haystack) ? REG_NOTBOL : 0))) {
j = i + regmatches[0].rm_so;
if (j <= rev_start)
return j;
}
+ }
}
#endif
}
if (ISSET(REVERSE_SEARCH))
return revstrstr(haystack, needle, rev_start);
else
- return strstr(haystack,needle);
+ return strstr(haystack, needle);
} else {
if (ISSET(REVERSE_SEARCH))
}
/* 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;
wattron(topwin, A_REVERSE);
#endif
-
- mvwaddstr(topwin, 0, 3, VERMSG);
+ mvwaddnstr(topwin, 0, 2, VERMSG, COLS - 3);
space = COLS - strlen(VERMSG) - strlen(VERSION) - 21;
namelen = strlen(what);
- if (what[0] == '\0')
- mvwaddstr(topwin, 0, COLS / 2 - 6, _("New Buffer"));
- else {
- if (namelen > space) {
- if (path == NULL)
- waddstr(topwin, _(" File: ..."));
- else
- waddstr(topwin, _(" DIR: ..."));
- waddstr(topwin, &what[namelen - space]);
- } else {
- if (path == NULL)
- mvwaddstr(topwin, 0, COLS / 2 - (namelen / 2 + 1),
- _("File: "));
- else
- mvwaddstr(topwin, 0, COLS / 2 - (namelen / 2 + 1),
- _(" DIR: "));
- waddstr(topwin, what);
+ if (space > 0) {
+ if (what[0] == '\0')
+ mvwaddstr(topwin, 0, COLS / 2 - 6, _("New Buffer"));
+ else {
+ if (namelen > space) {
+ if (path == NULL)
+ waddstr(topwin, _(" File: ..."));
+ else
+ waddstr(topwin, _(" DIR: ..."));
+ waddstr(topwin, &what[namelen - space]);
+ } else {
+ if (path == NULL)
+ mvwaddstr(topwin, 0, COLS / 2 - (namelen / 2 + 1),
+ _("File: "));
+ else
+ mvwaddstr(topwin, 0, COLS / 2 - (namelen / 2 + 1),
+ _(" DIR: "));
+ waddstr(topwin, what);
+ }
}
- }
+ } /* If we don't have space, we shouldn't bother */
if (ISSET(MODIFIED))
- mvwaddstr(topwin, 0, COLS - 10, _("Modified"));
+ mvwaddstr(topwin, 0, COLS - 11, _(" Modified "));
else if (ISSET(VIEW_MODE))
- mvwaddstr(topwin, 0, COLS - 10, _("View"));
+ mvwaddstr(topwin, 0, COLS - 11, _(" View "));
#ifdef ENABLE_COLOR
color_off(topwin, COLOR_TITLEBAR);
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;
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;
bottombars(help_list);
do {
- ptr = help_text;
+ const char *ptr = help_text;
+
switch (kbinput) {
#ifndef DISABLE_MOUSE
#ifdef NCURSES_MOUSE_VERSION
}
}
- 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++;
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;
}