DLR's patch merged, Static toggles and shortcut gone, lots of stuff changed

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1073 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Chris Allegretta 2002-02-15 19:17:02 +00:00
parent 025a42c67f
commit a8c225787b
11 changed files with 643 additions and 417 deletions

View File

@ -1,15 +1,39 @@
CVS code - CVS code -
- General
- malloc->calloc, etc cleanups (DLR).
- New option, noconvert (-N, --noconvert) to completely stop
the translation of files from DOS or Mac format (DLR).
- New functions wheck_writable_directory() and safe_tempnam()
to get around the tempnam warning. (DLR) Needs testing
- Added DOS and Mac format options to write file routine.
Changes to shortcut_init() and do_writeout().
- Removed stupid static definitions of toggles and shortcut
lists. Many changes to shortcut_init(), toggle_init(),
statusq(), nanogetstr(), main(), and many other places.
FIXME: Mouse support broken by this change.
- Makefile.am: - Makefile.am:
- Add SYSCONFDIR to DEFS, so we can have an /etc/nanorc. - Add SYSCONFDIR to DEFS, so we can have an /etc/nanorc.
- Change localedir line to 1.0's version. - Change localedir line to 1.0's version.
- files.c:
read_byte()
- Added check for conrol characters (indicative of a binary
file), set NO_CONVERT if found.
- global.c:
- Move openprev and opennext functions to shortcuts, they really
aren't toggles (DLR).
- rcfile.c: - rcfile.c:
parse_next_rege() parse_next_regex()
- Allow " symbol to be in regex without leading \ by checking - Allow " symbol to be in regex without leading \ by checking
for *ptr+1 is not the end of the regex. for *ptr+1 is not the end of the regex.
- nano.c:
help_init()
- Added message re: having multiple blank buffers (DLR).
- winio.c: - winio.c:
do_cursorpos() do_cursorpos()
- Rewritten to show col place as well as charcter place, without - Rewritten to show col place as well as charcter place, without
needing an entirely separate flag. needing an entirely separate flag.
bottombars(), onekey()
- Make bottom list dynamic with screen size (Guus Sliepen & Chris).
- utils.c: - utils.c:
strstrwrapper() strstrwrapper()
- NANO_SMALL test was backwards (Ken Tyler). - NANO_SMALL test was backwards (Ken Tyler).

2
cut.c
View File

@ -232,7 +232,7 @@ int do_cut_text(void)
junk = NULL; junk = NULL;
junk = make_new_node(current); junk = make_new_node(current);
junk->data = nmalloc(1 * sizeof (char)); junk->data = charalloc(1);
junk->data[0] = 0; junk->data[0] = 0;
add_to_cutbuffer(junk); add_to_cutbuffer(junk);

211
files.c
View File

@ -108,7 +108,6 @@ void new_file(void)
} }
int read_byte(int fd, char *filename, char *input) int read_byte(int fd, char *filename, char *input)
{ {
static char buf[BUFSIZ]; static char buf[BUFSIZ];
@ -141,8 +140,9 @@ filestruct *read_line(char *buf, filestruct * prev, int *line1ins)
strcpy(fileptr->data, buf); strcpy(fileptr->data, buf);
#ifndef NANO_SMALL #ifndef NANO_SMALL
/* If it's a DOS file (CRLF), strip out the CR part*/ /* If it's a DOS file (CRLF), and file conversion isn't disabled,
if (buf[strlen(buf) - 1] == '\r') { strip out the CR part */
if (!ISSET(NO_CONVERT) && buf[strlen(buf) - 1] == '\r') {
fileptr->data[strlen(buf) - 1] = 0; fileptr->data[strlen(buf) - 1] = 0;
totsize--; totsize--;
@ -179,7 +179,6 @@ filestruct *read_line(char *buf, filestruct * prev, int *line1ins)
return fileptr; return fileptr;
} }
int read_file(int fd, char *filename, int quiet) int read_file(int fd, char *filename, int quiet)
{ {
long size; long size;
@ -211,8 +210,15 @@ int read_file(int fd, char *filename, int quiet)
buf[0] = 0; buf[0] = 0;
i = 0; i = 0;
#ifndef NANO_SMALL #ifndef NANO_SMALL
/* If it's a Mac file (no LF just a CR), handle it! */ } else if (!ISSET(NO_CONVERT) && input[0] < 32
} else if (i > 0 && buf[i-1] == '\r') { && input[0] != '\r' && input[0] != '\n')
/* If the file has binary chars in it, don't stupidly
assume it's a DOS or Mac formatted file! */
SET(NO_CONVERT);
/* If it's a Mac file (no LF just a CR), and file conversion
isn't disabled, handle it! */
else if (!ISSET(NO_CONVERT) && i > 0 && buf[i-1] == '\r') {
fileformat = 2; fileformat = 2;
fileptr = read_line(buf, fileptr, &line1ins); fileptr = read_line(buf, fileptr, &line1ins);
num_lines++; num_lines++;
@ -335,11 +341,9 @@ int do_insertfile(int loading_file)
#if !defined(DISABLE_BROWSER) || !defined(DISABLE_MOUSE) #if !defined(DISABLE_BROWSER) || !defined(DISABLE_MOUSE)
currshortcut = insertfile_list; currshortcut = insertfile_list;
currslen = INSERTFILE_LIST_LEN;
#endif #endif
i = statusq(1, insertfile_list, INSERTFILE_LIST_LEN, "", i = statusq(1, insertfile_list, "", _("File to insert [from ./] "));
_("File to insert [from ./] "));
if (i != -1) { if (i != -1) {
#ifdef DEBUG #ifdef DEBUG
@ -358,7 +362,6 @@ int do_insertfile(int loading_file)
char *tmp = do_browse_from(realname); char *tmp = do_browse_from(realname);
#if !defined(DISABLE_HELP) || !defined(DISABLE_MOUSE) #if !defined(DISABLE_HELP) || !defined(DISABLE_MOUSE)
currshortcut = insertfile_list; currshortcut = insertfile_list;
currslen = INSERTFILE_LIST_LEN;
#endif #endif
#ifdef DISABLE_TABCOMP #ifdef DISABLE_TABCOMP
@ -770,6 +773,13 @@ int open_prevfile(int closing_file)
return 0; return 0;
} }
/* This function is used by the shortcut list. */
int open_prevfile_void(void)
{
open_prevfile(0);
return 0;
}
/* /*
* Open the next entry in the open_files structure. If closing_file is * Open the next entry in the open_files structure. If closing_file is
* zero, update the current entry before switching from it. Otherwise, we * zero, update the current entry before switching from it. Otherwise, we
@ -825,6 +835,13 @@ int open_nextfile(int closing_file)
return 0; return 0;
} }
/* This function is used by the shortcut list. */
int open_nextfile_void(void)
{
open_nextfile(0);
return 0;
}
/* /*
* Delete an entry from the open_files filestruct. After deletion of an * Delete an entry from the open_files filestruct. After deletion of an
* entry, the next or previous entry is opened, whichever is found first. * entry, the next or previous entry is opened, whichever is found first.
@ -852,9 +869,9 @@ int close_open_file(void)
display_main_list(); display_main_list();
return 0; return 0;
} }
#endif #endif /* MULTIBUFFER */
#if defined (ENABLE_MULTIBUFFER) || !defined (DISABLE_OPERATINGDIR) #if defined (ENABLE_MULTIBUFFER) || !defined (DISABLE_SPELLER) || !defined (DISABLE_OPERATINGDIR)
/* /*
* When passed "[relative path]" or "[relative path][filename]" in * When passed "[relative path]" or "[relative path][filename]" in
* origpath, return "[full path]" or "[full path][filename]" on success, * origpath, return "[full path]" or "[full path][filename]" on success,
@ -863,7 +880,7 @@ int close_open_file(void)
* yet on disk); it is not done if the relative path doesn't exist (since * yet on disk); it is not done if the relative path doesn't exist (since
* the first call to chdir() will fail then). * the first call to chdir() will fail then).
*/ */
char *get_full_path(char *origpath) char *get_full_path(const char *origpath)
{ {
char *newpath = NULL, *last_slash, *d_here, *d_there, *d_there_file, tmp; char *newpath = NULL, *last_slash, *d_here, *d_there, *d_there_file, tmp;
int path_only, last_slash_index; int path_only, last_slash_index;
@ -1003,7 +1020,127 @@ char *get_full_path(char *origpath)
return newpath; return newpath;
} }
#endif /* ENABLE_MULTIBUFFER || !DISABLE_OPERATINGDIR */ #endif /* ENABLE_MULTIBUFFER || !DISABLE_SPELLER || !DISABLE_OPERATINGDIR */
#ifndef DISABLE_SPELLER
/*
* This function accepts a path and a pointer to an integer, and returns
* the full path (via get_full_path()). It also sets the integer
* pointer's referenced value to 1 if the full path is writable, and 0
* otherwise. On error, it returns NULL, and sets the pointer's
* referenced value to 0.
*/
char *check_writable_directory(const char *path, int *writable) {
char *full_path = get_full_path(path);
struct stat fileinfo;
/* if get_full_path() failed, set *writable to 0 and return NULL */
if (!full_path) {
*writable = 0;
return NULL;
}
else {
/* otherwise, stat() the full path to see if it's writable by the
user; set *writable to 1 if it is, or 0 if it isn't */
stat(path, &fileinfo);
if (fileinfo.st_mode & S_IWUSR)
*writable = 1;
else
*writable = 0;
}
/* if the full path doesn't end in a slash (meaning get_full_path()
found that it isn't a directory) or isn't writable, return NULL */
if (full_path[strlen(full_path) - 1] != '/' || *writable == 0)
return NULL;
/* otherwise, return the full path */
return full_path;
}
/*
* This function accepts a directory name and filename prefix the same
* way that tempnam() does, determines the location for its temporary
* file the same way that tempnam() does, safely creates the temporary
* file there via mkstemp(), and returns the name of the temporary file
* the same way that tempnam() does.
*/
char *safe_tempnam(const char *dirname, const char *filename_prefix) {
char *buf, *tempdir = NULL, *full_tempdir = NULL;
int writable = 0, filedesc;
/* if $TMPDIR is set and non-empty, set tempdir to it, run it through
get_full_path(), and save the result in full_tempdir; otherwise,
leave full_tempdir set to to NULL */
if (getenv("TMPDIR") && strcmp(getenv("TMPDIR"),"")) {
/* store the value of $TMPDIR in tempdir, run its value through
get_full_path(), and save the result in full_tempdir */
tempdir = charalloc(strlen(getenv("TMPDIR")) + 1);
sprintf(tempdir, "%s", getenv("TMPDIR"));
full_tempdir = check_writable_directory(tempdir, &writable);
/* we don't need the value of tempdir anymore */
free(tempdir);
}
if (!full_tempdir) {
/* if $TMPDIR is blank or isn't set, or isn't a writable
directory, and dirname isn't NULL, try it; otherwise, leave
full_tempdir set to NULL */
if (dirname) {
tempdir = charalloc(strlen(dirname) + 1);
strcpy(tempdir, dirname);
full_tempdir = check_writable_directory(tempdir, &writable);
/* we don't need the value of tempdir anymore */
free(tempdir);
}
}
/* if $TMPDIR is blank or isn't set, or if it isn't a writable
directory, and dirname is NULL, try P_tmpdir instead */
if (!full_tempdir) {
tempdir = charalloc(strlen(P_tmpdir) + 1);
strcpy(tempdir, P_tmpdir);
full_tempdir = check_writable_directory(tempdir, &writable);
/* we don't need the value of tempdir anymore */
free(tempdir);
}
/* if P_tmpdir didn't work, use /tmp instead */
if (!full_tempdir) {
full_tempdir = charalloc(6);
strcpy(full_tempdir, "/tmp/");
}
buf = charalloc(strlen(full_tempdir) + 12);
sprintf(buf, "%s", full_tempdir);
/* like tempnam(), use only the first 5 characters of the prefix */
strncat(buf, filename_prefix, 5);
strcat(buf, "XXXXXX");
filedesc = mkstemp(buf);
/* if mkstemp() failed, get out */
if (filedesc == -1)
return NULL;
/* otherwise, close the resulting file; afterwards, it'll be 0 bytes
long, so delete it; finally, return the filename (all that's left
of it) */
else {
close(filedesc);
unlink(buf);
return buf;
}
}
#endif /* !DISABLE_SPELLER */
#ifndef DISABLE_OPERATINGDIR #ifndef DISABLE_OPERATINGDIR
/* /*
@ -1308,6 +1445,7 @@ int write_file(char *name, int tmp, int append, int nonamechange)
int do_writeout(char *path, int exiting, int append) int do_writeout(char *path, int exiting, int append)
{ {
int i = 0; int i = 0;
char *formatstr;
#ifdef NANO_EXTRA #ifdef NANO_EXTRA
static int did_cred = 0; static int did_cred = 0;
@ -1315,7 +1453,6 @@ int do_writeout(char *path, int exiting, int append)
#if !defined(DISABLE_BROWSER) || !defined(DISABLE_MOUSE) #if !defined(DISABLE_BROWSER) || !defined(DISABLE_MOUSE)
currshortcut = writefile_list; currshortcut = writefile_list;
currslen = WRITEFILE_LIST_LEN;
#endif #endif
answer = mallocstrcpy(answer, path); answer = mallocstrcpy(answer, path);
@ -1336,24 +1473,32 @@ int do_writeout(char *path, int exiting, int append)
while (1) { while (1) {
/* Be nice to the translation folks */
#ifndef NANO_SMALL #ifndef NANO_SMALL
if (ISSET(MAC_FILE))
formatstr = _(" [Mac Format]");
else if (ISSET(DOS_FILE))
formatstr = _(" [DOS Format]");
else
formatstr = "";
/* Be nice to the translation folks */
if (ISSET(MARK_ISSET) && !exiting) { if (ISSET(MARK_ISSET) && !exiting) {
if (append) if (append)
i = statusq(1, writefile_list, WRITEFILE_LIST_LEN, "", i = statusq(1, writefile_list, "",
_("Append Selection to File")); "%s%s", _("Append Selection to File"), formatstr);
else else
i = statusq(1, writefile_list, WRITEFILE_LIST_LEN, "", i = statusq(1, writefile_list, "",
_("Write Selection to File")); "%s%s", _("Write Selection to File"), formatstr);
} else } else
#endif #endif
{ {
if (append) if (append)
i = statusq(1, writefile_list, WRITEFILE_LIST_LEN, answer, i = statusq(1, writefile_list, answer,
_("File Name to Append")); "%s%s", _("File Name to Append"), formatstr);
else else
i = statusq(1, writefile_list, WRITEFILE_LIST_LEN, answer, i = statusq(1, writefile_list, answer,
_("File Name to Write")); "%s%s", _("File Name to Write"), formatstr);
} }
@ -1366,7 +1511,6 @@ int do_writeout(char *path, int exiting, int append)
#if !defined(DISABLE_BROWSER) || !defined(DISABLE_MOUSE) #if !defined(DISABLE_BROWSER) || !defined(DISABLE_MOUSE)
currshortcut = writefile_list; currshortcut = writefile_list;
currslen = WRITEFILE_LIST_LEN;
#endif #endif
if (tmp != NULL) { if (tmp != NULL) {
@ -1375,7 +1519,15 @@ int do_writeout(char *path, int exiting, int append)
return do_writeout(answer, exiting, append); return do_writeout(answer, exiting, append);
} else } else
#endif #endif
if (i == NANO_APPEND_KEY) if (i == TOGGLE_DOS_KEY) {
UNSET(MAC_FILE);
TOGGLE(DOS_FILE);
return(do_writeout(answer, exiting, append));
} else if (i == TOGGLE_MAC_KEY) {
UNSET(DOS_FILE);
TOGGLE(MAC_FILE);
return(do_writeout(answer, exiting, append));
} else if (i == NANO_APPEND_KEY)
return(do_writeout(answer, exiting, 1 - append)); return(do_writeout(answer, exiting, 1 - append));
#ifdef DEBUG #ifdef DEBUG
@ -2101,7 +2253,7 @@ char *do_browser(char *inpath)
kb = keypad_on(edit, 1); kb = keypad_on(edit, 1);
titlebar(path); titlebar(path);
bottombars(browser_list, BROWSER_LIST_LEN); bottombars(browser_list);
curs_set(0); curs_set(0);
wmove(edit, 0, 0); wmove(edit, 0, 0);
i = 0; i = 0;
@ -2116,7 +2268,6 @@ char *do_browser(char *inpath)
#if !defined DISABLE_HELP || !defined(DISABLE_MOUSE) #if !defined DISABLE_HELP || !defined(DISABLE_MOUSE)
currshortcut = browser_list; currshortcut = browser_list;
currslen = BROWSER_LIST_LEN;
#endif #endif
editline = 0; editline = 0;
@ -2287,8 +2438,8 @@ char *do_browser(char *inpath)
case NANO_GOTO_KEY: case NANO_GOTO_KEY:
curs_set(1); curs_set(1);
j = statusq(0, gotodir_list, GOTODIR_LIST_LEN, "", _("Goto Directory")); j = statusq(0, gotodir_list, "", _("Goto Directory"));
bottombars(browser_list, BROWSER_LIST_LEN); bottombars(browser_list);
curs_set(0); curs_set(0);
#ifndef DISABLE_OPERATINGDIR #ifndef DISABLE_OPERATINGDIR

355
global.c
View File

@ -84,18 +84,18 @@ char *operating_dir = NULL; /* Operating directory, which we can't go
char *alt_speller; /* Alternative spell command */ char *alt_speller; /* Alternative spell command */
#endif #endif
shortcut main_list[MAIN_LIST_LEN]; shortcut *main_list = NULL;
shortcut whereis_list[WHEREIS_LIST_LEN]; shortcut *whereis_list = NULL;
shortcut replace_list[REPLACE_LIST_LEN]; shortcut *replace_list = NULL;
shortcut replace_list_2[REPLACE_LIST_LEN]; /* 2nd half of replace dialog */ shortcut *replace_list_2; /* 2nd half of replace dialog */
shortcut goto_list[GOTO_LIST_LEN]; shortcut *goto_list = NULL;
shortcut gotodir_list[GOTODIR_LIST_LEN]; shortcut *gotodir_list = NULL;
shortcut writefile_list[WRITEFILE_LIST_LEN]; shortcut *writefile_list = NULL;
shortcut insertfile_list[INSERTFILE_LIST_LEN]; shortcut *insertfile_list = NULL;
shortcut help_list[HELP_LIST_LEN]; shortcut *help_list = NULL;
shortcut spell_list[SPELL_LIST_LEN]; shortcut *spell_list = NULL;
#ifndef DISABLE_BROWSER #ifndef DISABLE_BROWSER
shortcut browser_list[BROWSER_LIST_LEN]; shortcut *browser_list = NULL;
#endif #endif
#ifdef ENABLE_COLOR #ifdef ENABLE_COLOR
@ -104,12 +104,11 @@ shortcut browser_list[BROWSER_LIST_LEN];
#endif #endif
#if !defined(DISABLE_BROWSER) || !defined(DISABLE_MOUSE) || !defined (DISABLE_HELP) #if !defined(DISABLE_BROWSER) || !defined(DISABLE_MOUSE) || !defined (DISABLE_HELP)
shortcut *currshortcut = main_list; /* Current shortcut list we're using */ shortcut *currshortcut; /* Current shortcut list we're using */
int currslen = MAIN_VISIBLE; /* Length of current shortcut list */
#endif #endif
#ifndef NANO_SMALL #ifndef NANO_SMALL
toggle toggles[TOGGLE_LEN]; toggle *toggles = NULL;
#endif #endif
/* Regular expressions */ /* Regular expressions */
@ -120,10 +119,33 @@ regmatch_t regmatches[10]; /* Match positions for parenthetical
subexpressions, max of 10 */ subexpressions, max of 10 */
#endif #endif
int length_of_list(shortcut *s)
{
int i = 0;
shortcut *t;
for (t = s; t != NULL; t = t->next)
i++;
return i;
}
/* Initialize a struct *without* our lovely braces =( */ /* Initialize a struct *without* our lovely braces =( */
void sc_init_one(shortcut * s, int key, char *desc, char *help, int alt, void sc_init_one(shortcut **shortcutage, int key, char *desc, char *help, int alt,
int misc1, int misc2, int view, int (*func) (void)) int misc1, int misc2, int view, int (*func) (void))
{ {
shortcut *s;
if (*shortcutage == NULL) {
*shortcutage = nmalloc(sizeof(shortcut));
s = *shortcutage;
} else {
for (s = *shortcutage; s->next != NULL; s = s->next)
;
s->next = nmalloc(sizeof(shortcut));
s = s->next;
}
s->val = key; s->val = key;
s->desc = desc; s->desc = desc;
s->help = help; s->help = help;
@ -132,17 +154,29 @@ void sc_init_one(shortcut * s, int key, char *desc, char *help, int alt,
s->misc2 = misc2; s->misc2 = misc2;
s->viewok = view; s->viewok = view;
s->func = func; s->func = func;
s->next = NULL;
} }
#ifndef NANO_SMALL #ifndef NANO_SMALL
/* Initialize the toggles in the same manner */ /* Initialize the toggles in the same manner */
void toggle_init_one(toggle * t, int val, char *desc, int flag, void toggle_init_one(int val, char *desc, int flag)
char override_ch)
{ {
t->val = val; toggle *u;
t->desc = desc;
t->flag = flag; if (toggles == NULL) {
t->override_ch = override_ch; toggles = nmalloc(sizeof(toggle));
u = toggles;
} else {
for (u = toggles; u->next != NULL; u = u->next)
;
u->next = nmalloc(sizeof(toggle));
u = u->next;
}
u->val = val;
u->desc = desc;
u->flag = flag;
u->next = NULL;
} }
#endif #endif
@ -152,17 +186,16 @@ void toggle_init(void)
char *toggle_const_msg, *toggle_autoindent_msg, *toggle_suspend_msg, char *toggle_const_msg, *toggle_autoindent_msg, *toggle_suspend_msg,
*toggle_nohelp_msg, *toggle_picomode_msg, *toggle_mouse_msg, *toggle_nohelp_msg, *toggle_picomode_msg, *toggle_mouse_msg,
*toggle_cuttoend_msg, *toggle_wrap_msg, *toggle_case_msg, *toggle_cuttoend_msg, *toggle_wrap_msg, *toggle_case_msg,
*toggle_backwards_msg, *toggle_dos_msg, *toggle_mac_msg, *toggle_backwards_msg, *toggle_noconvert_msg, *toggle_dos_msg,
*toggle_smooth_msg; *toggle_mac_msg, *toggle_smooth_msg;
#ifdef ENABLE_MULTIBUFFER
char *toggle_load_msg, *nano_openprev_msg, *nano_opennext_msg;
#endif
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
char *toggle_regexp_msg; char *toggle_regexp_msg;
#endif #endif
#ifdef ENABLE_MULTIBUFFER
char *toggle_load_msg;
#endif
toggle_const_msg = _("Constant cursor position"); toggle_const_msg = _("Constant cursor position");
toggle_autoindent_msg = _("Auto indent"); toggle_autoindent_msg = _("Auto indent");
@ -173,62 +206,42 @@ void toggle_init(void)
toggle_cuttoend_msg = _("Cut to end"); toggle_cuttoend_msg = _("Cut to end");
toggle_backwards_msg = _("Backwards search"); toggle_backwards_msg = _("Backwards search");
toggle_case_msg = _("Case sensitive search"); toggle_case_msg = _("Case sensitive search");
#ifdef HAVE_REGEX_H
toggle_regexp_msg = _("Regular expression search");
#endif
toggle_noconvert_msg = _("No conversion from DOS/Mac format");
toggle_dos_msg = _("Writing file in DOS format"); toggle_dos_msg = _("Writing file in DOS format");
toggle_mac_msg = _("Writing file in Mac format"); toggle_mac_msg = _("Writing file in Mac format");
toggle_smooth_msg = _("Smooth scrolling"); toggle_smooth_msg = _("Smooth scrolling");
#ifdef HAVE_REGEX_H
toggle_regexp_msg = _("Regular expressions");
#endif
toggle_wrap_msg = _("Auto wrap"); toggle_wrap_msg = _("Auto wrap");
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER
toggle_load_msg = _("Multiple file buffers"); toggle_load_msg = _("Multiple file buffers");
nano_openprev_msg = _("Open previously loaded file");
nano_opennext_msg = _("Open next loaded file");
#endif
toggle_init_one(&toggles[0], TOGGLE_CONST_KEY, toggle_const_msg,
CONSTUPDATE, 0);
toggle_init_one(&toggles[1], TOGGLE_AUTOINDENT_KEY,
toggle_autoindent_msg, AUTOINDENT, 0);
toggle_init_one(&toggles[2], TOGGLE_SUSPEND_KEY, toggle_suspend_msg,
SUSPEND, 0);
toggle_init_one(&toggles[3], TOGGLE_NOHELP_KEY, toggle_nohelp_msg,
NO_HELP, 0);
toggle_init_one(&toggles[4], TOGGLE_PICOMODE_KEY, toggle_picomode_msg,
PICO_MODE, 0);
toggle_init_one(&toggles[5], TOGGLE_WRAP_KEY, toggle_wrap_msg,
NO_WRAP, 0);
toggle_init_one(&toggles[6], TOGGLE_MOUSE_KEY, toggle_mouse_msg,
USE_MOUSE, 0);
toggle_init_one(&toggles[7], TOGGLE_CUTTOEND_KEY, toggle_cuttoend_msg,
CUT_TO_END, 0);
toggle_init_one(&toggles[8], TOGGLE_BACKWARDS_KEY, toggle_backwards_msg,
REVERSE_SEARCH, 0);
toggle_init_one(&toggles[9], TOGGLE_CASE_KEY, toggle_case_msg,
CASE_SENSITIVE, 0);
toggle_init_one(&toggles[10], TOGGLE_DOS_KEY, toggle_dos_msg,
DOS_FILE, 0);
toggle_init_one(&toggles[11], TOGGLE_MAC_KEY, toggle_mac_msg,
MAC_FILE, 0);
toggle_init_one(&toggles[12], TOGGLE_SMOOTH_KEY, toggle_smooth_msg,
SMOOTHSCROLL, 0);
#ifdef ENABLE_MULTIBUFFER
toggle_init_one(&toggles[13], TOGGLE_LOAD_KEY, toggle_load_msg,
MULTIBUFFER, 0);
toggle_init_one(&toggles[14], NANO_OPENPREV_KEY, nano_openprev_msg,
0, '<');
toggle_init_one(&toggles[15], NANO_OPENNEXT_KEY, nano_opennext_msg,
0, '>');
#endif #endif
toggle_init_one(TOGGLE_CONST_KEY, toggle_const_msg, CONSTUPDATE);
toggle_init_one(TOGGLE_AUTOINDENT_KEY, toggle_autoindent_msg, AUTOINDENT);
toggle_init_one(TOGGLE_SUSPEND_KEY, toggle_suspend_msg, SUSPEND);
toggle_init_one(TOGGLE_NOHELP_KEY, toggle_nohelp_msg, NO_HELP);
toggle_init_one(TOGGLE_PICOMODE_KEY, toggle_picomode_msg, PICO_MODE);
toggle_init_one(TOGGLE_WRAP_KEY, toggle_wrap_msg, NO_WRAP);
toggle_init_one(TOGGLE_MOUSE_KEY, toggle_mouse_msg, USE_MOUSE);
toggle_init_one(TOGGLE_CUTTOEND_KEY, toggle_cuttoend_msg, CUT_TO_END);
toggle_init_one(TOGGLE_BACKWARDS_KEY, toggle_backwards_msg, REVERSE_SEARCH);
toggle_init_one(TOGGLE_CASE_KEY, toggle_case_msg, CASE_SENSITIVE);
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
toggle_init_one(&toggles[TOGGLE_LEN - 1], TOGGLE_REGEXP_KEY, toggle_init_one(TOGGLE_REGEXP_KEY, toggle_regexp_msg, USE_REGEXP);
toggle_regexp_msg, USE_REGEXP, 0);
#endif #endif
#ifdef ENABLE_MULTIBUFFER
toggle_init_one(TOGGLE_LOAD_KEY, toggle_load_msg, MULTIBUFFER);
#endif #endif
toggle_init_one(TOGGLE_NOCONVERT_KEY, toggle_noconvert_msg, NO_CONVERT);
toggle_init_one(TOGGLE_DOS_KEY, toggle_dos_msg, DOS_FILE);
toggle_init_one(TOGGLE_MAC_KEY, toggle_mac_msg, MAC_FILE);
toggle_init_one(TOGGLE_SMOOTH_KEY, toggle_smooth_msg, SMOOTHSCROLL);
#endif /* !NANO_SMALL */
} }
void shortcut_init(int unjustify) void shortcut_init(int unjustify)
@ -245,7 +258,8 @@ void shortcut_init(int unjustify)
"", *nano_mark_msg = "", *nano_delete_msg = "", *nano_mark_msg = "", *nano_delete_msg =
"", *nano_backspace_msg = "", *nano_tab_msg = "", *nano_backspace_msg = "", *nano_tab_msg =
"", *nano_enter_msg = "", *nano_cancel_msg = "", *nano_enter_msg = "", *nano_cancel_msg =
"", *nano_unjustify_msg = "", *nano_append_msg = ""; "", *nano_unjustify_msg = "", *nano_append_msg =
"", *nano_dos_msg = "", *nano_mac_msg = "";
#ifndef NANO_SMALL #ifndef NANO_SMALL
char *nano_tofiles_msg = "", *nano_gotodir_msg = "", *nano_case_msg = char *nano_tofiles_msg = "", *nano_gotodir_msg = "", *nano_case_msg =
@ -253,6 +267,9 @@ void shortcut_init(int unjustify)
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
char *nano_regexp_msg = "", *nano_bracket_msg = ""; char *nano_regexp_msg = "", *nano_bracket_msg = "";
#endif #endif
#ifdef ENABLE_MULTIBUFFER
char *nano_openprev_msg = "", *nano_opennext_msg = "";
#endif
nano_help_msg = _("Invoke the help menu"); nano_help_msg = _("Invoke the help menu");
nano_writeout_msg = _("Write the current file to disk"); nano_writeout_msg = _("Write the current file to disk");
@ -297,41 +314,47 @@ void shortcut_init(int unjustify)
nano_cancel_msg = _("Cancel the current function"); nano_cancel_msg = _("Cancel the current function");
nano_append_msg = _("Append to the current file"); nano_append_msg = _("Append to the current file");
nano_reverse_msg = _("Search backwards"); nano_reverse_msg = _("Search backwards");
nano_dos_msg = _("Write file out in DOS format");
nano_mac_msg = _("Write file out in Mac format");
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
nano_regexp_msg = _("Use Regular expressions"); nano_regexp_msg = _("Use Regular expressions");
nano_bracket_msg = _("Find other bracket"); nano_bracket_msg = _("Find other bracket");
#endif #endif
#ifdef ENABLE_MULTIBUFFER
nano_openprev_msg = _("Open previously loaded file");
nano_opennext_msg = _("Open next loaded file");
#endif #endif
#endif /* !NANO_SMALL */
sc_init_one(&main_list[0], NANO_HELP_KEY, _("Get Help"), sc_init_one(&main_list, NANO_HELP_KEY, _("Get Help"),
nano_help_msg, 0, NANO_HELP_FKEY, 0, VIEW, do_help); nano_help_msg, 0, NANO_HELP_FKEY, 0, VIEW, do_help);
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER
if (open_files != NULL && (open_files->prev || open_files->next)) if (open_files != NULL && (open_files->prev || open_files->next))
sc_init_one(&main_list[1], NANO_EXIT_KEY, _("Close"), sc_init_one(&main_list, NANO_EXIT_KEY, _("Close"),
nano_exit_msg, 0, NANO_EXIT_FKEY, 0, VIEW, do_exit); nano_exit_msg, 0, NANO_EXIT_FKEY, 0, VIEW, do_exit);
else else
#endif #endif
sc_init_one(&main_list[1], NANO_EXIT_KEY, _("Exit"), sc_init_one(&main_list, NANO_EXIT_KEY, _("Exit"),
nano_exit_msg, 0, NANO_EXIT_FKEY, 0, VIEW, do_exit); nano_exit_msg, 0, NANO_EXIT_FKEY, 0, VIEW, do_exit);
sc_init_one(&main_list[2], NANO_WRITEOUT_KEY, _("WriteOut"), sc_init_one(&main_list, NANO_WRITEOUT_KEY, _("WriteOut"),
nano_writeout_msg, nano_writeout_msg,
0, NANO_WRITEOUT_FKEY, 0, NOVIEW, do_writeout_void); 0, NANO_WRITEOUT_FKEY, 0, NOVIEW, do_writeout_void);
if (ISSET(PICO_MODE)) if (ISSET(PICO_MODE))
sc_init_one(&main_list[3], NANO_JUSTIFY_KEY, _("Justify"), sc_init_one(&main_list, NANO_JUSTIFY_KEY, _("Justify"),
nano_justify_msg, 0, NANO_JUSTIFY_FKEY, 0, nano_justify_msg, 0, NANO_JUSTIFY_FKEY, 0,
NOVIEW, do_justify); NOVIEW, do_justify);
else else
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER
/* this is so we can view multiple files */ /* this is so we can view multiple files */
sc_init_one(&main_list[3], NANO_INSERTFILE_KEY, _("Read File"), sc_init_one(&main_list, NANO_INSERTFILE_KEY, _("Read File"),
nano_insert_msg, nano_insert_msg,
0, NANO_INSERTFILE_FKEY, 0, VIEW, do_insertfile_void); 0, NANO_INSERTFILE_FKEY, 0, VIEW, do_insertfile_void);
#else #else
sc_init_one(&main_list[3], NANO_INSERTFILE_KEY, _("Read File"), sc_init_one(&main_list, NANO_INSERTFILE_KEY, _("Read File"),
nano_insert_msg, nano_insert_msg,
0, NANO_INSERTFILE_FKEY, 0, NOVIEW, do_insertfile_void); 0, NANO_INSERTFILE_FKEY, 0, NOVIEW, do_insertfile_void);
#endif #endif
@ -340,273 +363,295 @@ void shortcut_init(int unjustify)
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER
/* this is so we can view multiple files */ /* this is so we can view multiple files */
sc_init_one(&main_list[4], NANO_INSERTFILE_KEY, _("Read File"), sc_init_one(&main_list, NANO_INSERTFILE_KEY, _("Read File"),
nano_insert_msg, nano_insert_msg,
0, NANO_INSERTFILE_FKEY, 0, VIEW, do_insertfile_void); 0, NANO_INSERTFILE_FKEY, 0, VIEW, do_insertfile_void);
#else #else
sc_init_one(&main_list[4], NANO_INSERTFILE_KEY, _("Read File"), sc_init_one(&main_list, NANO_INSERTFILE_KEY, _("Read File"),
nano_insert_msg, nano_insert_msg,
0, NANO_INSERTFILE_FKEY, 0, NOVIEW, do_insertfile_void); 0, NANO_INSERTFILE_FKEY, 0, NOVIEW, do_insertfile_void);
#endif #endif
else else
sc_init_one(&main_list[4], NANO_REPLACE_KEY, _("Replace"), sc_init_one(&main_list, NANO_REPLACE_KEY, _("Replace"),
nano_replace_msg, nano_replace_msg,
NANO_ALT_REPLACE_KEY, NANO_REPLACE_FKEY, 0, NOVIEW, do_replace); NANO_ALT_REPLACE_KEY, NANO_REPLACE_FKEY, 0, NOVIEW, do_replace);
sc_init_one(&main_list[5], NANO_WHEREIS_KEY, _("Where Is"), sc_init_one(&main_list, NANO_WHEREIS_KEY, _("Where Is"),
nano_whereis_msg, nano_whereis_msg,
0, NANO_WHEREIS_FKEY, 0, VIEW, do_search); 0, NANO_WHEREIS_FKEY, 0, VIEW, do_search);
sc_init_one(&main_list[6], NANO_PREVPAGE_KEY, _("Prev Page"), sc_init_one(&main_list, NANO_PREVPAGE_KEY, _("Prev Page"),
nano_prevpage_msg, nano_prevpage_msg,
0, NANO_PREVPAGE_FKEY, KEY_PPAGE, VIEW, do_page_up); 0, NANO_PREVPAGE_FKEY, KEY_PPAGE, VIEW, do_page_up);
sc_init_one(&main_list[7], NANO_NEXTPAGE_KEY, _("Next Page"), sc_init_one(&main_list, NANO_NEXTPAGE_KEY, _("Next Page"),
nano_nextpage_msg, nano_nextpage_msg,
0, NANO_NEXTPAGE_FKEY, KEY_NPAGE, VIEW, do_page_down); 0, NANO_NEXTPAGE_FKEY, KEY_NPAGE, VIEW, do_page_down);
sc_init_one(&main_list[8], NANO_CUT_KEY, _("Cut Text"), sc_init_one(&main_list, NANO_CUT_KEY, _("Cut Text"),
nano_cut_msg, 0, NANO_CUT_FKEY, 0, NOVIEW, do_cut_text); nano_cut_msg, 0, NANO_CUT_FKEY, 0, NOVIEW, do_cut_text);
if (unjustify) if (unjustify)
sc_init_one(&main_list[9], NANO_UNJUSTIFY_KEY, _("UnJustify"), sc_init_one(&main_list, NANO_UNJUSTIFY_KEY, _("UnJustify"),
nano_unjustify_msg, 0, 0, 0, NOVIEW, do_uncut_text); nano_unjustify_msg, 0, 0, 0, NOVIEW, do_uncut_text);
else else
sc_init_one(&main_list[9], NANO_UNCUT_KEY, _("UnCut Txt"), sc_init_one(&main_list, NANO_UNCUT_KEY, _("UnCut Txt"),
nano_uncut_msg, nano_uncut_msg,
0, NANO_UNCUT_FKEY, 0, NOVIEW, do_uncut_text); 0, NANO_UNCUT_FKEY, 0, NOVIEW, do_uncut_text);
sc_init_one(&main_list[10], NANO_CURSORPOS_KEY, _("Cur Pos"), sc_init_one(&main_list, NANO_CURSORPOS_KEY, _("Cur Pos"),
nano_cursorpos_msg, nano_cursorpos_msg,
0, NANO_CURSORPOS_FKEY, 0, VIEW, do_cursorpos_void); 0, NANO_CURSORPOS_FKEY, 0, VIEW, do_cursorpos_void);
sc_init_one(&main_list[11], NANO_SPELL_KEY, _("To Spell"), sc_init_one(&main_list, NANO_SPELL_KEY, _("To Spell"),
nano_spell_msg, 0, NANO_SPELL_FKEY, 0, NOVIEW, do_spell); nano_spell_msg, 0, NANO_SPELL_FKEY, 0, NOVIEW, do_spell);
sc_init_one(&main_list[12], NANO_UP_KEY, _("Up"), sc_init_one(&main_list, NANO_UP_KEY, _("Up"),
nano_up_msg, 0, KEY_UP, 0, VIEW, do_up); nano_up_msg, 0, KEY_UP, 0, VIEW, do_up);
sc_init_one(&main_list[13], NANO_DOWN_KEY, _("Down"), sc_init_one(&main_list, NANO_DOWN_KEY, _("Down"),
nano_down_msg, 0, KEY_DOWN, 0, VIEW, do_down); nano_down_msg, 0, KEY_DOWN, 0, VIEW, do_down);
sc_init_one(&main_list[14], NANO_FORWARD_KEY, _("Forward"), sc_init_one(&main_list, NANO_FORWARD_KEY, _("Forward"),
nano_forward_msg, 0, KEY_RIGHT, 0, VIEW, do_right); nano_forward_msg, 0, KEY_RIGHT, 0, VIEW, do_right);
sc_init_one(&main_list[15], NANO_BACK_KEY, _("Back"), sc_init_one(&main_list, NANO_BACK_KEY, _("Back"),
nano_back_msg, 0, KEY_LEFT, 0, VIEW, do_left); nano_back_msg, 0, KEY_LEFT, 0, VIEW, do_left);
sc_init_one(&main_list[16], NANO_HOME_KEY, _("Home"), sc_init_one(&main_list, NANO_HOME_KEY, _("Home"),
nano_home_msg, 0, KEY_HOME, 362, VIEW, do_home); nano_home_msg, 0, KEY_HOME, 362, VIEW, do_home);
sc_init_one(&main_list[17], NANO_END_KEY, _("End"), sc_init_one(&main_list, NANO_END_KEY, _("End"),
nano_end_msg, 0, KEY_END, 385, VIEW, do_end); nano_end_msg, 0, KEY_END, 385, VIEW, do_end);
sc_init_one(&main_list[18], NANO_REFRESH_KEY, _("Refresh"), sc_init_one(&main_list, NANO_REFRESH_KEY, _("Refresh"),
nano_refresh_msg, 0, 0, 0, VIEW, total_refresh); nano_refresh_msg, 0, 0, 0, VIEW, total_refresh);
sc_init_one(&main_list[19], NANO_MARK_KEY, _("Mark Text"), sc_init_one(&main_list, NANO_MARK_KEY, _("Mark Text"),
nano_mark_msg, NANO_ALT_MARK_KEY, 0, 0, NOVIEW, do_mark); nano_mark_msg, NANO_ALT_MARK_KEY, 0, 0, NOVIEW, do_mark);
sc_init_one(&main_list[20], NANO_DELETE_KEY, _("Delete"), sc_init_one(&main_list, NANO_DELETE_KEY, _("Delete"),
nano_delete_msg, 0, KEY_DC, nano_delete_msg, 0, KEY_DC,
NANO_CONTROL_D, NOVIEW, do_delete); NANO_CONTROL_D, NOVIEW, do_delete);
sc_init_one(&main_list[21], NANO_BACKSPACE_KEY, _("Backspace"), sc_init_one(&main_list, NANO_BACKSPACE_KEY, _("Backspace"),
nano_backspace_msg, 0, nano_backspace_msg, 0,
KEY_BACKSPACE, 127, NOVIEW, do_backspace); KEY_BACKSPACE, 127, NOVIEW, do_backspace);
sc_init_one(&main_list[22], NANO_TAB_KEY, _("Tab"), sc_init_one(&main_list, NANO_TAB_KEY, _("Tab"),
nano_tab_msg, 0, 0, 0, NOVIEW, do_tab); nano_tab_msg, 0, 0, 0, NOVIEW, do_tab);
if (ISSET(PICO_MODE)) if (ISSET(PICO_MODE))
sc_init_one(&main_list[23], NANO_REPLACE_KEY, _("Replace"), sc_init_one(&main_list, NANO_REPLACE_KEY, _("Replace"),
nano_replace_msg, nano_replace_msg,
NANO_ALT_REPLACE_KEY, NANO_REPLACE_FKEY, 0, NOVIEW, do_replace); NANO_ALT_REPLACE_KEY, NANO_REPLACE_FKEY, 0, NOVIEW, do_replace);
else else
sc_init_one(&main_list[23], NANO_JUSTIFY_KEY, _("Justify"), sc_init_one(&main_list, NANO_JUSTIFY_KEY, _("Justify"),
nano_justify_msg, 0, NANO_JUSTIFY_FKEY, 0, nano_justify_msg, 0, NANO_JUSTIFY_FKEY, 0,
NOVIEW, do_justify); NOVIEW, do_justify);
sc_init_one(&main_list[24], NANO_ENTER_KEY, _("Enter"), sc_init_one(&main_list, NANO_ENTER_KEY, _("Enter"),
nano_enter_msg, nano_enter_msg,
0, KEY_ENTER, NANO_CONTROL_M, NOVIEW, do_enter_void); 0, KEY_ENTER, NANO_CONTROL_M, NOVIEW, do_enter_void);
sc_init_one(&main_list[25], NANO_GOTO_KEY, _("Goto Line"), sc_init_one(&main_list, NANO_GOTO_KEY, _("Goto Line"),
nano_goto_msg, nano_goto_msg,
NANO_ALT_GOTO_KEY, NANO_GOTO_FKEY, 0, VIEW, do_gotoline_void); NANO_ALT_GOTO_KEY, NANO_GOTO_FKEY, 0, VIEW, do_gotoline_void);
#if (!defined NANO_SMALL) && (defined HAVE_REGEX_H) #if (!defined NANO_SMALL) && (defined HAVE_REGEX_H)
sc_init_one(&main_list[26], -9, _("Find Other Bracket"), sc_init_one(&main_list, -9, _("Find Other Bracket"),
nano_bracket_msg, nano_bracket_msg,
NANO_BRACKET_KEY, 0, 0, VIEW, do_find_bracket); NANO_BRACKET_KEY, 0, 0, VIEW, do_find_bracket);
#endif #endif
#ifdef ENABLE_MULTIBUFFER
sc_init_one(&main_list, -9, _("Previous File"),
nano_openprev_msg,
NANO_OPENPREV_KEY, 0, 0, VIEW, open_prevfile_void);
sc_init_one(&main_list, -9, _("Next File"),
nano_opennext_msg,
NANO_OPENNEXT_KEY, 0, 0, VIEW, open_nextfile_void);
#endif
sc_init_one(&whereis_list[0], NANO_HELP_KEY, sc_init_one(&whereis_list, NANO_HELP_KEY,
_("Get Help"), nano_help_msg, 0, 0, 0, VIEW, do_help); _("Get Help"), nano_help_msg, 0, 0, 0, VIEW, do_help);
sc_init_one(&whereis_list[1], NANO_CANCEL_KEY, sc_init_one(&whereis_list, NANO_CANCEL_KEY,
_("Cancel"), nano_cancel_msg, 0, 0, 0, VIEW, 0); _("Cancel"), nano_cancel_msg, 0, 0, 0, VIEW, 0);
sc_init_one(&whereis_list[2], NANO_FIRSTLINE_KEY, _("First Line"), sc_init_one(&whereis_list, NANO_FIRSTLINE_KEY, _("First Line"),
nano_firstline_msg, 0, 0, 0, VIEW, do_first_line); nano_firstline_msg, 0, 0, 0, VIEW, do_first_line);
sc_init_one(&whereis_list[3], NANO_LASTLINE_KEY, _("Last Line"), sc_init_one(&whereis_list, NANO_LASTLINE_KEY, _("Last Line"),
nano_lastline_msg, 0, 0, 0, VIEW, do_last_line); nano_lastline_msg, 0, 0, 0, VIEW, do_last_line);
sc_init_one(&whereis_list[4], NANO_OTHERSEARCH_KEY, _("Replace"), sc_init_one(&whereis_list, NANO_OTHERSEARCH_KEY, _("Replace"),
nano_replace_msg, 0, 0, 0, VIEW, do_replace); nano_replace_msg, 0, 0, 0, VIEW, do_replace);
sc_init_one(&whereis_list[5], NANO_FROMSEARCHTOGOTO_KEY, sc_init_one(&whereis_list, NANO_FROMSEARCHTOGOTO_KEY,
_("Goto Line"), nano_goto_msg, 0, 0, 0, VIEW, _("Goto Line"), nano_goto_msg, 0, 0, 0, VIEW,
do_gotoline_void); do_gotoline_void);
#ifndef NANO_SMALL #ifndef NANO_SMALL
sc_init_one(&whereis_list[6], TOGGLE_CASE_KEY, _("Case Sens"), sc_init_one(&whereis_list, TOGGLE_CASE_KEY, _("Case Sens"),
nano_case_msg, 0, 0, 0, VIEW, 0); nano_case_msg, 0, 0, 0, VIEW, 0);
sc_init_one(&whereis_list[7], TOGGLE_BACKWARDS_KEY, _("Direction"), sc_init_one(&whereis_list, TOGGLE_BACKWARDS_KEY, _("Direction"),
nano_reverse_msg, 0, 0, 0, VIEW, 0); nano_reverse_msg, 0, 0, 0, VIEW, 0);
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
sc_init_one(&whereis_list[REPLACE_LIST_LEN - 1], TOGGLE_REGEXP_KEY, sc_init_one(&whereis_list, TOGGLE_REGEXP_KEY,
_("Regexp"), nano_regexp_msg, 0, 0, 0, VIEW, 0); _("Regexp"), nano_regexp_msg, 0, 0, 0, VIEW, 0);
#endif #endif
#endif /* NANO_SMALL */ #endif /* !NANO_SMALL */
sc_init_one(&replace_list[0], NANO_HELP_KEY, sc_init_one(&replace_list, NANO_HELP_KEY,
_("Get Help"), nano_help_msg, 0, 0, 0, VIEW, do_help); _("Get Help"), nano_help_msg, 0, 0, 0, VIEW, do_help);
sc_init_one(&replace_list[1], NANO_CANCEL_KEY, sc_init_one(&replace_list, NANO_CANCEL_KEY,
_("Cancel"), nano_cancel_msg, 0, 0, 0, VIEW, 0); _("Cancel"), nano_cancel_msg, 0, 0, 0, VIEW, 0);
sc_init_one(&replace_list[2], NANO_FIRSTLINE_KEY, _("First Line"), sc_init_one(&replace_list, NANO_FIRSTLINE_KEY, _("First Line"),
nano_firstline_msg, 0, 0, 0, VIEW, do_first_line); nano_firstline_msg, 0, 0, 0, VIEW, do_first_line);
sc_init_one(&replace_list[3], NANO_LASTLINE_KEY, _("Last Line"), sc_init_one(&replace_list, NANO_LASTLINE_KEY, _("Last Line"),
nano_lastline_msg, 0, 0, 0, VIEW, do_last_line); nano_lastline_msg, 0, 0, 0, VIEW, do_last_line);
sc_init_one(&replace_list[4], NANO_OTHERSEARCH_KEY, _("No Replace"), sc_init_one(&replace_list, NANO_OTHERSEARCH_KEY, _("No Replace"),
nano_whereis_msg, 0, 0, 0, VIEW, do_search); nano_whereis_msg, 0, 0, 0, VIEW, do_search);
sc_init_one(&replace_list[5], NANO_FROMSEARCHTOGOTO_KEY, sc_init_one(&replace_list, NANO_FROMSEARCHTOGOTO_KEY,
_("Goto Line"), nano_goto_msg, 0, 0, 0, VIEW, _("Goto Line"), nano_goto_msg, 0, 0, 0, VIEW,
do_gotoline_void); do_gotoline_void);
#ifndef NANO_SMALL #ifndef NANO_SMALL
sc_init_one(&replace_list[6], TOGGLE_CASE_KEY, _("Case Sens"), sc_init_one(&replace_list, TOGGLE_CASE_KEY, _("Case Sens"),
nano_case_msg, 0, 0, 0, VIEW, 0); nano_case_msg, 0, 0, 0, VIEW, 0);
sc_init_one(&replace_list[7], TOGGLE_BACKWARDS_KEY, _("Direction"), sc_init_one(&replace_list, TOGGLE_BACKWARDS_KEY, _("Direction"),
nano_reverse_msg, 0, 0, 0, VIEW, 0); nano_reverse_msg, 0, 0, 0, VIEW, 0);
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
sc_init_one(&replace_list[REPLACE_LIST_LEN - 1], TOGGLE_REGEXP_KEY, sc_init_one(&replace_list, TOGGLE_REGEXP_KEY,
_("Regexp"), nano_regexp_msg, 0, 0, 0, VIEW, 0); _("Regexp"), nano_regexp_msg, 0, 0, 0, VIEW, 0);
#endif #endif
#endif /* NANO_SMALL */ #endif /* !NANO_SMALL */
sc_init_one(&replace_list_2[0], NANO_HELP_KEY, sc_init_one(&replace_list_2, NANO_HELP_KEY,
_("Get Help"), nano_help_msg, 0, 0, 0, VIEW, do_help); _("Get Help"), nano_help_msg, 0, 0, 0, VIEW, do_help);
sc_init_one(&replace_list_2[1], NANO_CANCEL_KEY, sc_init_one(&replace_list_2, NANO_CANCEL_KEY,
_("Cancel"), nano_cancel_msg, 0, 0, 0, VIEW, 0); _("Cancel"), nano_cancel_msg, 0, 0, 0, VIEW, 0);
sc_init_one(&replace_list_2[2], NANO_FIRSTLINE_KEY, _("First Line"), sc_init_one(&replace_list_2, NANO_FIRSTLINE_KEY, _("First Line"),
nano_firstline_msg, 0, 0, 0, VIEW, do_first_line); nano_firstline_msg, 0, 0, 0, VIEW, do_first_line);
sc_init_one(&replace_list_2[3], NANO_LASTLINE_KEY, _("Last Line"), sc_init_one(&replace_list_2, NANO_LASTLINE_KEY, _("Last Line"),
nano_lastline_msg, 0, 0, 0, VIEW, do_last_line); nano_lastline_msg, 0, 0, 0, VIEW, do_last_line);
sc_init_one(&goto_list[0], NANO_HELP_KEY, sc_init_one(&goto_list, NANO_HELP_KEY,
_("Get Help"), nano_help_msg, 0, 0, 0, VIEW, do_help); _("Get Help"), nano_help_msg, 0, 0, 0, VIEW, do_help);
sc_init_one(&goto_list[1], NANO_CANCEL_KEY, _("Cancel"), sc_init_one(&goto_list, NANO_CANCEL_KEY, _("Cancel"),
nano_cancel_msg, 0, 0, 0, VIEW, 0); nano_cancel_msg, 0, 0, 0, VIEW, 0);
sc_init_one(&goto_list[2], NANO_FIRSTLINE_KEY, _("First Line"), sc_init_one(&goto_list, NANO_FIRSTLINE_KEY, _("First Line"),
nano_firstline_msg, 0, 0, 0, VIEW, &do_first_line); nano_firstline_msg, 0, 0, 0, VIEW, &do_first_line);
sc_init_one(&goto_list[3], NANO_LASTLINE_KEY, _("Last Line"), sc_init_one(&goto_list, NANO_LASTLINE_KEY, _("Last Line"),
nano_lastline_msg, 0, 0, 0, VIEW, &do_last_line); nano_lastline_msg, 0, 0, 0, VIEW, &do_last_line);
sc_init_one(&help_list[0], NANO_PREVPAGE_KEY, _("Prev Page"), sc_init_one(&help_list, NANO_PREVPAGE_KEY, _("Prev Page"),
nano_prevpage_msg, nano_prevpage_msg,
0, NANO_PREVPAGE_FKEY, KEY_PPAGE, VIEW, do_page_up); 0, NANO_PREVPAGE_FKEY, KEY_PPAGE, VIEW, do_page_up);
sc_init_one(&help_list[1], NANO_NEXTPAGE_KEY, _("Next Page"), sc_init_one(&help_list, NANO_NEXTPAGE_KEY, _("Next Page"),
nano_nextpage_msg, nano_nextpage_msg,
0, NANO_NEXTPAGE_FKEY, KEY_NPAGE, VIEW, do_page_down); 0, NANO_NEXTPAGE_FKEY, KEY_NPAGE, VIEW, do_page_down);
sc_init_one(&help_list[2], NANO_EXIT_KEY, _("Exit"), sc_init_one(&help_list, NANO_EXIT_KEY, _("Exit"),
nano_exit_msg, 0, NANO_EXIT_FKEY, 0, VIEW, do_exit); nano_exit_msg, 0, NANO_EXIT_FKEY, 0, VIEW, do_exit);
sc_init_one(&writefile_list[0], NANO_HELP_KEY, sc_init_one(&writefile_list, NANO_HELP_KEY,
_("Get Help"), nano_help_msg, 0, 0, 0, VIEW, do_help); _("Get Help"), nano_help_msg, 0, 0, 0, VIEW, do_help);
sc_init_one(&writefile_list[1], NANO_CANCEL_KEY, _("Cancel"),
nano_cancel_msg, 0, 0, 0, VIEW, 0);
#ifndef DISABLE_BROWSER #ifndef DISABLE_BROWSER
sc_init_one(&writefile_list[2], NANO_TOFILES_KEY, _("To Files"), sc_init_one(&writefile_list, NANO_TOFILES_KEY, _("To Files"),
nano_tofiles_msg, 0, 0, 0, NOVIEW, 0); nano_tofiles_msg, 0, 0, 0, NOVIEW, 0);
#endif #endif
sc_init_one(&writefile_list[WRITEFILE_LIST_LEN - 1], NANO_APPEND_KEY, _("Append"), #ifndef NANO_SMALL
sc_init_one(&writefile_list, TOGGLE_DOS_KEY,
_("DOS Format"), nano_dos_msg, 0, 0, 0, NOVIEW, 0);
sc_init_one(&writefile_list, TOGGLE_MAC_KEY,
_("Mac Format"), nano_mac_msg, 0, 0, 0, NOVIEW, 0);
#endif
sc_init_one(&writefile_list,
NANO_APPEND_KEY, _("Append"),
nano_append_msg, 0, 0, 0, NOVIEW, 0); nano_append_msg, 0, 0, 0, NOVIEW, 0);
sc_init_one(&insertfile_list[0], NANO_HELP_KEY, sc_init_one(&writefile_list, NANO_CANCEL_KEY,
_("Cancel"), nano_cancel_msg, 0, 0, 0, VIEW, 0);
sc_init_one(&insertfile_list, NANO_HELP_KEY,
_("Get Help"), nano_help_msg, 0, 0, 0, VIEW, do_help); _("Get Help"), nano_help_msg, 0, 0, 0, VIEW, do_help);
sc_init_one(&insertfile_list[1], NANO_CANCEL_KEY, _("Cancel"), sc_init_one(&insertfile_list, NANO_CANCEL_KEY, _("Cancel"),
nano_cancel_msg, 0, 0, 0, VIEW, 0); nano_cancel_msg, 0, 0, 0, VIEW, 0);
#ifndef DISABLE_BROWSER #ifndef DISABLE_BROWSER
sc_init_one(&insertfile_list[2], NANO_TOFILES_KEY, _("To Files"), sc_init_one(&insertfile_list, NANO_TOFILES_KEY, _("To Files"),
nano_tofiles_msg, 0, 0, 0, NOVIEW, 0); nano_tofiles_msg, 0, 0, 0, NOVIEW, 0);
#endif #endif
sc_init_one(&spell_list[0], NANO_HELP_KEY, sc_init_one(&spell_list, NANO_HELP_KEY,
_("Get Help"), nano_help_msg, 0, 0, 0, VIEW, do_help); _("Get Help"), nano_help_msg, 0, 0, 0, VIEW, do_help);
sc_init_one(&spell_list[1], NANO_CANCEL_KEY, _("Cancel"), sc_init_one(&spell_list, NANO_CANCEL_KEY, _("Cancel"),
nano_cancel_msg, 0, 0, 0, VIEW, 0); nano_cancel_msg, 0, 0, 0, VIEW, 0);
#ifndef DISABLE_BROWSER #ifndef DISABLE_BROWSER
sc_init_one(&browser_list[0], NANO_HELP_KEY, sc_init_one(&browser_list, NANO_HELP_KEY,
_("Get Help"), nano_help_msg, 0, 0, 0, VIEW, do_help); _("Get Help"), nano_help_msg, 0, 0, 0, VIEW, do_help);
sc_init_one(&browser_list[1], NANO_EXIT_KEY, _("Exit"), sc_init_one(&browser_list, NANO_EXIT_KEY, _("Exit"),
nano_exit_msg, 0, NANO_EXIT_FKEY, 0, VIEW, 0); nano_exit_msg, 0, NANO_EXIT_FKEY, 0, VIEW, 0);
sc_init_one(&browser_list[2], NANO_PREVPAGE_KEY, _("Prev Page"), sc_init_one(&browser_list, NANO_PREVPAGE_KEY, _("Prev Page"),
nano_prevpage_msg, nano_prevpage_msg,
0, NANO_PREVPAGE_FKEY, KEY_PPAGE, VIEW, 0); 0, NANO_PREVPAGE_FKEY, KEY_PPAGE, VIEW, 0);
sc_init_one(&browser_list[3], NANO_NEXTPAGE_KEY, _("Next Page"), sc_init_one(&browser_list, NANO_NEXTPAGE_KEY, _("Next Page"),
nano_nextpage_msg, nano_nextpage_msg,
0, NANO_NEXTPAGE_FKEY, KEY_NPAGE, VIEW, 0); 0, NANO_NEXTPAGE_FKEY, KEY_NPAGE, VIEW, 0);
sc_init_one(&browser_list[4], NANO_GOTO_KEY, _("Goto"), sc_init_one(&browser_list, NANO_GOTO_KEY, _("Goto"),
nano_gotodir_msg, NANO_ALT_GOTO_KEY, NANO_GOTO_FKEY, 0, nano_gotodir_msg, NANO_ALT_GOTO_KEY, NANO_GOTO_FKEY, 0,
VIEW, 0); VIEW, 0);
sc_init_one(&gotodir_list[0], NANO_HELP_KEY, sc_init_one(&gotodir_list, NANO_HELP_KEY,
_("Get Help"), nano_help_msg, 0, 0, 0, VIEW, do_help); _("Get Help"), nano_help_msg, 0, 0, 0, VIEW, do_help);
sc_init_one(&gotodir_list[1], NANO_CANCEL_KEY, _("Cancel"), sc_init_one(&gotodir_list, NANO_CANCEL_KEY, _("Cancel"),
nano_cancel_msg, 0, 0, 0, VIEW, 0); nano_cancel_msg, 0, 0, 0, VIEW, 0);
#endif #endif
#if !defined(DISABLE_BROWSER) || !defined(DISABLE_MOUSE) || !defined (DISABLE_HELP)
currshortcut = main_list;
#endif
toggle_init(); toggle_init();
} }

233
nano.c
View File

@ -64,8 +64,8 @@
#ifndef DISABLE_WRAPJUSTIFY #ifndef DISABLE_WRAPJUSTIFY
/* Former globals, now static */ /* Former globals, now static */
int fill = 0; /* Fill - where to wrap lines, basically */ int fill = 0;/* Fill - where to wrap lines, basically */
int wrap_at = 0; /* Right justified fill value, allows resize */ int wrap_at = 0; /* Right justified fill value, allows resize */
#endif #endif
struct termios oldterm; /* The user's original term settings */ struct termios oldterm; /* The user's original term settings */
@ -425,10 +425,9 @@ void usage(void)
printf printf
(_ (_
(" -M --mac Write file in Mac format\n")); (" -M --mac Write file in Mac format\n"));
#endif printf
#ifdef HAVE_REGEX_H (_
printf(_ (" -N --noconvert Don't convert files from DOS/Mac format\n"));
(" -R --regexp Use regular expressions for search\n"));
#endif #endif
#ifndef NANO_SMALL #ifndef NANO_SMALL
printf(_ printf(_
@ -1488,8 +1487,7 @@ int do_int_spell_fix(char *word)
do_replace_highlight(TRUE, prevanswer); do_replace_highlight(TRUE, prevanswer);
/* allow replace word to be corrected */ /* allow replace word to be corrected */
i = statusq(0, spell_list, SPELL_LIST_LEN, last_replace, i = statusq(0, spell_list, last_replace, _("Edit a replacement"));
_("Edit a replacement"));
do_replace_highlight(FALSE, prevanswer); do_replace_highlight(FALSE, prevanswer);
@ -1732,7 +1730,7 @@ int do_spell(void)
char *temp; char *temp;
int spell_res; int spell_res;
if ((temp = tempnam(0, "nano.")) == NULL) { if ((temp = safe_tempnam(0, "nano.")) == NULL) {
statusbar(_("Could not create a temporary filename: %s"), statusbar(_("Could not create a temporary filename: %s"),
strerror(errno)); strerror(errno));
return 0; return 0;
@ -1834,6 +1832,7 @@ void do_mouse(void)
{ {
MEVENT mevent; MEVENT mevent;
int foo = 0, tab_found = 0; int foo = 0, tab_found = 0;
int currslen;
if (getmouse(&mevent) == ERR) if (getmouse(&mevent) == ERR)
return; return;
@ -1905,6 +1904,11 @@ void do_mouse(void)
int k, val = 0; int k, val = 0;
if (currshortcut == main_list)
currslen = MAIN_VISIBLE;
else
currslen = length_of_list(currshortcut);
if (currslen < 2) if (currslen < 2)
k = COLS / 6; k = COLS / 6;
else else
@ -2410,14 +2414,17 @@ int do_justify(void)
#ifndef DISABLE_HELP #ifndef DISABLE_HELP
void help_init(void) void help_init(void)
{ {
int i, sofar = 0, helplen; int i, sofar = 0, meta_shortcut = 0, helplen;
long allocsize = 1; /* How much space we're gonna need for the help text */ long allocsize = 1; /* How much space we're gonna need for the help text */
char buf[BUFSIZ] = "", *ptr = NULL; char buf[BUFSIZ] = "", *ptr = NULL;
toggle *t;
shortcut *s;
if (currslen == MAIN_VISIBLE) /*
helplen = MAIN_LIST_LEN; if (currshortcut = main_list)
else helplen = MAIN_VISIBLE;
helplen = currslen; else */
helplen = length_of_list(currshortcut);
/* First set up the initial help text for the current function */ /* First set up the initial help text for the current function */
if (currshortcut == whereis_list || currshortcut == replace_list if (currshortcut == whereis_list || currshortcut == replace_list
@ -2451,8 +2458,12 @@ void help_init(void)
"or --multibuffer command line flags, the Meta-F toggle or " "or --multibuffer command line flags, the Meta-F toggle or "
"using a nanorc file, inserting a file will cause it to be " "using a nanorc file, inserting a file will cause it to be "
"loaded into a separate buffer (use Meta-< and > to switch " "loaded into a separate buffer (use Meta-< and > to switch "
"between file buffers).\n\n The following function keys are " "between file buffers).\n\n In multiple buffer mode, the "
"available in Insert File mode:\n\n"); "same file cannot be loaded twice, not even a \"New "
"Buffer.\" A workaround to load another blank buffer is to "
"load a nonexistent filename into a separate buffer.\n\n "
"The following function keys are available in Insert File "
"mode:\n\n");
else if (currshortcut == writefile_list) else if (currshortcut == writefile_list)
ptr = _("Write File Help Text\n\n " ptr = _("Write File Help Text\n\n "
"Type the name that you wish to save the current file " "Type the name that you wish to save the current file "
@ -2498,21 +2509,22 @@ void help_init(void)
/* Compute the space needed for the shortcut lists - we add 15 to /* Compute the space needed for the shortcut lists - we add 15 to
have room for the shortcut abbrev and its possible alternate keys */ have room for the shortcut abbrev and its possible alternate keys */
for (i = 0; i <= helplen - 1; i++) s = currshortcut;
if (currshortcut[i].help != NULL) for (i = 0; i <= helplen - 1; i++) {
allocsize += strlen(currshortcut[i].help) + 15; if (s->help != NULL)
allocsize += strlen(s->help) + 15;
s = s->next;
}
/* If we're on the main list, we also allocate space for toggle help text. */ /* If we're on the main list, we also allocate space for toggle help text. */
if (currshortcut == main_list) { if (currshortcut == main_list) {
for (i = 0; i <= TOGGLE_LEN - 1; i++) for (t = toggles; t != NULL; t = t->next)
if (toggles[i].desc != NULL) if (t->desc != NULL)
allocsize += strlen(toggles[i].desc) + 30; allocsize += strlen(t->desc) + 30;
} }
allocsize += strlen(ptr); allocsize += strlen(ptr);
if (help_text != NULL) if (help_text != NULL)
free(help_text); free(help_text);
@ -2523,59 +2535,71 @@ void help_init(void)
strcpy(help_text, ptr); strcpy(help_text, ptr);
/* Now add our shortcut info */ /* Now add our shortcut info */
s = currshortcut;
for (i = 0; i <= helplen - 1; i++) { for (i = 0; i <= helplen - 1; i++) {
if (currshortcut[i].val > 0 && currshortcut[i].val < 'a') if (s->val > 0 && s->val < 'a')
sofar = snprintf(buf, BUFSIZ, "^%c ", currshortcut[i].val + 64); sofar = snprintf(buf, BUFSIZ, "^%c ", s->val + 64);
else else {
sofar = snprintf(buf, BUFSIZ, " "); if (s->altval > 0) {
sofar = 0;
meta_shortcut = 1;
}
else
sofar = snprintf(buf, BUFSIZ, " ");
}
if (currshortcut[i].misc1 > KEY_F0 && currshortcut[i].misc1 <= KEY_F(64)) if (!meta_shortcut) {
sofar += snprintf(&buf[sofar], BUFSIZ - sofar, "(F%d) ", if (s->misc1 > KEY_F0 && s->misc1 <= KEY_F(64))
currshortcut[i].misc1 - KEY_F0); sofar += snprintf(&buf[sofar], BUFSIZ - sofar, "(F%d) ",
else s->misc1 - KEY_F0);
sofar += snprintf(&buf[sofar], BUFSIZ - sofar, " "); else
sofar += snprintf(&buf[sofar], BUFSIZ - sofar, " ");
}
if (currshortcut[i].altval > 0 && currshortcut[i].altval < 91) if (s->altval > 0 && s->altval < 91
sofar += snprintf(&buf[sofar], BUFSIZ - sofar, "(M-%c) ", && (s->altval - 32) > 32)
currshortcut[i].altval - 32); sofar += snprintf(&buf[sofar], BUFSIZ - sofar,
else if (currshortcut[i].altval > 0) (meta_shortcut ? "M-%c " : "(M-%c) "),
sofar += snprintf(&buf[sofar], BUFSIZ - sofar, "(M-%c) ", s->altval - 32);
currshortcut[i].altval); else if (s->altval > 0)
sofar += snprintf(&buf[sofar], BUFSIZ - sofar,
(meta_shortcut ? "M-%c " : "(M-%c) "),
s->altval);
/* Hack */ /* Hack */
else if (currshortcut[i].val >= 'a') else if (s->val >= 'a')
sofar += snprintf(&buf[sofar], BUFSIZ - sofar, "(M-%c) ", sofar += snprintf(&buf[sofar], BUFSIZ - sofar,
currshortcut[i].val - 32); (meta_shortcut ? "(M-%c) " : "M-%c "),
s->val - 32);
else else
sofar += snprintf(&buf[sofar], BUFSIZ - sofar, " "); sofar += snprintf(&buf[sofar], BUFSIZ - sofar, " ");
if (meta_shortcut) {
if (s->misc1 > KEY_F0 && s->misc1 <= KEY_F(64))
sofar += snprintf(&buf[sofar], BUFSIZ - sofar,
"(F%d) ", s->misc1 - KEY_F0);
else
sofar += snprintf(&buf[sofar], BUFSIZ - sofar,
" ");
}
if (currshortcut[i].help != NULL) if (s->help != NULL)
snprintf(&buf[sofar], BUFSIZ - sofar, "%s", currshortcut[i].help); snprintf(&buf[sofar], BUFSIZ - sofar, "%s", s->help);
strcat(help_text, buf); strcat(help_text, buf);
strcat(help_text, "\n"); strcat(help_text, "\n");
s = s->next;
} }
/* And the toggles... */ /* And the toggles... */
if (currshortcut == main_list) if (currshortcut == main_list)
for (i = 0; i <= TOGGLE_LEN - 1; i++) { for (t = toggles; t != NULL; t = t->next) {
if (toggles[i].override_ch != 0)
sofar = snprintf(buf, BUFSIZ, sofar = snprintf(buf, BUFSIZ,
"M-%c ", toggles[i].override_ch); "M-%c ", t->val - 32);
else if (t->desc != NULL) {
sofar = snprintf(buf, BUFSIZ,
"M-%c ", toggles[i].val - 32);
if (toggles[i].desc != NULL) {
if (toggles[i].flag != 0)
snprintf(&buf[sofar], BUFSIZ - sofar, _("%s enable/disable"), snprintf(&buf[sofar], BUFSIZ - sofar, _("%s enable/disable"),
toggles[i].desc); t->desc);
else
snprintf(&buf[sofar], BUFSIZ - sofar, "%s",
toggles[i].desc);
} }
strcat(help_text, buf); strcat(help_text, buf);
strcat(help_text, "\n"); strcat(help_text, "\n");
} }
@ -2583,7 +2607,7 @@ void help_init(void)
} }
#endif #endif
void do_toggle(int which) void do_toggle(toggle *which)
{ {
#ifdef NANO_SMALL #ifdef NANO_SMALL
nano_disabled_msg(); nano_disabled_msg();
@ -2591,7 +2615,7 @@ void do_toggle(int which)
char *enabled = _("enabled"); char *enabled = _("enabled");
char *disabled = _("disabled"); char *disabled = _("disabled");
switch (toggles[which].val) { switch (which->val) {
case TOGGLE_BACKWARDS_KEY: case TOGGLE_BACKWARDS_KEY:
case TOGGLE_CASE_KEY: case TOGGLE_CASE_KEY:
case TOGGLE_REGEXP_KEY: case TOGGLE_REGEXP_KEY:
@ -2599,9 +2623,9 @@ void do_toggle(int which)
} }
/* Even easier! */ /* Even easier! */
TOGGLE(toggles[which].flag); TOGGLE(which->flag);
switch (toggles[which].val) { switch (which->val) {
case TOGGLE_PICOMODE_KEY: case TOGGLE_PICOMODE_KEY:
shortcut_init(0); shortcut_init(0);
SET(CLEAR_BACKUPSTRING); SET(CLEAR_BACKUPSTRING);
@ -2629,18 +2653,18 @@ void do_toggle(int which)
break; break;
} }
if (!ISSET(toggles[which].flag)) { if (!ISSET(which->flag)) {
if (toggles[which].val == TOGGLE_NOHELP_KEY || if (which->val == TOGGLE_NOHELP_KEY ||
toggles[which].val == TOGGLE_WRAP_KEY) which->val == TOGGLE_WRAP_KEY)
statusbar("%s %s", toggles[which].desc, enabled); statusbar("%s %s", which->desc, enabled);
else else
statusbar("%s %s", toggles[which].desc, disabled); statusbar("%s %s", which->desc, disabled);
} else { } else {
if (toggles[which].val == TOGGLE_NOHELP_KEY || if (which->val == TOGGLE_NOHELP_KEY ||
toggles[which].val == TOGGLE_WRAP_KEY) which->val == TOGGLE_WRAP_KEY)
statusbar("%s %s", toggles[which].desc, disabled); statusbar("%s %s", which->desc, disabled);
else else
statusbar("%s %s", toggles[which].desc, enabled); statusbar("%s %s", which->desc, enabled);
} }
#endif #endif
@ -2689,6 +2713,8 @@ int main(int argc, char *argv[])
int keyhandled; /* Have we handled the keystroke yet? */ int keyhandled; /* Have we handled the keystroke yet? */
int i, modify_control_seq; int i, modify_control_seq;
char *argv0; char *argv0;
shortcut *s;
toggle *t;
#ifdef _POSIX_VDISABLE #ifdef _POSIX_VDISABLE
struct termios term; struct termios term;
@ -2711,6 +2737,7 @@ int main(int argc, char *argv[])
{"cut", 0, 0, 'k'}, {"cut", 0, 0, 'k'},
{"dos", 0, 0, 'D'}, {"dos", 0, 0, 'D'},
{"mac", 0, 0, 'M'}, {"mac", 0, 0, 'M'},
{"noconvert", 0, 0, 'N'},
{"autoindent", 0, 0, 'i'}, {"autoindent", 0, 0, 'i'},
#endif #endif
{"tempfile", 0, 0, 't'}, {"tempfile", 0, 0, 't'},
@ -2756,11 +2783,11 @@ int main(int argc, char *argv[])
#endif /* ENABLE_NANORC */ #endif /* ENABLE_NANORC */
#ifdef HAVE_GETOPT_LONG #ifdef HAVE_GETOPT_LONG
while ((optchr = getopt_long(argc, argv, "h?DFKMRST:Vabcefgijklmo:pr:s:tvwxz", while ((optchr = getopt_long(argc, argv, "h?DFKMNRST:Vabcefgijklmo:pr:s:tvwxz",
long_options, &option_index)) != EOF) { long_options, &option_index)) != EOF) {
#else #else
while ((optchr = while ((optchr =
getopt(argc, argv, "h?DFKMRST:Vabcefgijklmo:pr:s:tvwxz")) != EOF) { getopt(argc, argv, "h?DFKMNRST:Vabcefgijklmo:pr:s:tvwxz")) != EOF) {
#endif #endif
switch (optchr) { switch (optchr) {
@ -2782,14 +2809,10 @@ int main(int argc, char *argv[])
case 'M': case 'M':
SET(MAC_FILE); SET(MAC_FILE);
break; break;
#endif case 'N':
case 'T': SET(NO_CONVERT);
tabsize = atoi(optarg);
if (tabsize <= 0) {
usage(); /* To stop bogus data for tab width */
finish(1);
}
break; break;
#endif
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
case 'R': case 'R':
SET(USE_REGEXP); SET(USE_REGEXP);
@ -2800,6 +2823,13 @@ int main(int argc, char *argv[])
SET(SMOOTHSCROLL); SET(SMOOTHSCROLL);
break; break;
#endif #endif
case 'T':
tabsize = atoi(optarg);
if (tabsize <= 0) {
usage(); /* To stop bogus data for tab width */
finish(1);
}
break;
case 'V': case 'V':
version(); version();
exit(0); exit(0);
@ -3004,7 +3034,6 @@ int main(int argc, char *argv[])
#ifndef DISABLE_MOUSE #ifndef DISABLE_MOUSE
currshortcut = main_list; currshortcut = main_list;
currslen = MAIN_VISIBLE;
#endif #endif
#ifndef _POSIX_VDISABLE #ifndef _POSIX_VDISABLE
@ -3170,6 +3199,7 @@ int main(int argc, char *argv[])
break; break;
} }
break; break;
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER
case NANO_OPENPREV_KEY: case NANO_OPENPREV_KEY:
case NANO_OPENPREV_ALTKEY: case NANO_OPENPREV_ALTKEY:
@ -3182,21 +3212,29 @@ int main(int argc, char *argv[])
keyhandled = 1; keyhandled = 1;
break; break;
#endif #endif
#if !defined (NANO_SMALL) && defined (HAVE_REGEX_H)
case NANO_BRACKET_KEY:
do_find_bracket();
keyhandled = 1;
break;
#endif
default: default:
/* Check for the altkey defs.... */ /* Check for the altkey defs.... */
for (i = 0; i <= MAIN_LIST_LEN - 1; i++) for (s = main_list; s != NULL; s = s->next)
if (kbinput == main_list[i].altval || if (kbinput == s->altval ||
kbinput == main_list[i].altval - 32) { kbinput == s->altval - 32) {
kbinput = main_list[i].val; kbinput = s->val;
break; break;
} }
#ifndef NANO_SMALL #ifndef NANO_SMALL
/* And for toggle switches */ /* And for toggle switches */
for (i = 0; i <= TOGGLE_LEN - 1 && !keyhandled; i++) for (t = toggles; t != NULL && !keyhandled; t = t->next)
if (kbinput == toggles[i].val || if (kbinput == t->val ||
(toggles[i].val > 'a' && (t->val > 'a' &&
kbinput == toggles[i].val - 32)) { kbinput == t->val - 32)) {
do_toggle(i); do_toggle(t);
keyhandled = 1; keyhandled = 1;
break; break;
} }
@ -3222,14 +3260,15 @@ int main(int argc, char *argv[])
/* Look through the main shortcut list to see if we've hit a /* Look through the main shortcut list to see if we've hit a
shortcut key */ shortcut key */
for (i = 0; i < MAIN_LIST_LEN && !keyhandled; i++) {
if (kbinput == main_list[i].val || for (s = currshortcut; s != NULL && !keyhandled; s = s->next) {
(main_list[i].misc1 && kbinput == main_list[i].misc1) || if (kbinput == s->val ||
(main_list[i].misc2 && kbinput == main_list[i].misc2)) { (s->misc1 && kbinput == s->misc1) ||
if (ISSET(VIEW_MODE) && !main_list[i].viewok) (s->misc2 && kbinput == s->misc2)) {
if (ISSET(VIEW_MODE) && !s->viewok)
print_view_warning(); print_view_warning();
else else
main_list[i].func(); s->func();
keyhandled = 1; keyhandled = 1;
} }
} }

55
nano.h
View File

@ -97,6 +97,7 @@ typedef struct shortcut {
int (*func) (void); /* Function to call when we catch this key */ int (*func) (void); /* Function to call when we catch this key */
char *desc; /* Description, e.g. "Page Up" */ char *desc; /* Description, e.g. "Page Up" */
char *help; /* Help file entry text */ char *help; /* Help file entry text */
struct shortcut *next;
} shortcut; } shortcut;
typedef struct toggle { typedef struct toggle {
@ -105,8 +106,7 @@ typedef struct toggle {
e.g. "Pico Messages"; we'll append Enabled or e.g. "Pico Messages"; we'll append Enabled or
Disabled */ Disabled */
int flag; /* What flag actually gets toggled */ int flag; /* What flag actually gets toggled */
char override_ch; /* The character to display on the help screen, struct toggle *next;
if it isn't NULL */
} toggle; } toggle;
#ifdef ENABLE_NANORC #ifdef ENABLE_NANORC
@ -162,6 +162,7 @@ typedef struct colortype {
#define SMOOTHSCROLL (1<<23) #define SMOOTHSCROLL (1<<23)
#define DISABLE_CURPOS (1<<24) /* Damn, we still need it */ #define DISABLE_CURPOS (1<<24) /* Damn, we still need it */
#define ALT_KEYPAD (1<<25) #define ALT_KEYPAD (1<<25)
#define NO_CONVERT (1<<26)
/* Control key sequences, changing these would be very very bad */ /* Control key sequences, changing these would be very very bad */
@ -305,57 +306,9 @@ know what you're doing */
#define TOGGLE_DOS_KEY NANO_ALT_D #define TOGGLE_DOS_KEY NANO_ALT_D
#define TOGGLE_MAC_KEY NANO_ALT_O #define TOGGLE_MAC_KEY NANO_ALT_O
#define TOGGLE_SMOOTH_KEY NANO_ALT_S #define TOGGLE_SMOOTH_KEY NANO_ALT_S
#define TOGGLE_NOCONVERT_KEY NANO_ALT_N
/* Toggle stuff, these static lengths need to go away RSN */
#ifndef HAVE_REGEX_H
#define NO_REGEX 1
#define SMALL_TOO 0
#else
#define NO_REGEX 0
#ifdef NANO_SMALL
#define SMALL_TOO 1
#else
#define SMALL_TOO 0
#endif /* NANO_SMALL */
#endif /* HAVE_REGEX_H */
#ifdef DISABLE_BROWSER
#define NO_BROWSER 1
#else
#define NO_BROWSER 0
#endif
#ifdef NANO_SMALL
#ifdef HAVE_REGEX_H
#define NO_TOGGLES 3
#else
#define NO_TOGGLES 2
#endif /* HAVE_REGEX_H */
#else
#define NO_TOGGLES 0
#endif /* NANO_SMALL */
#ifdef ENABLE_MULTIBUFFER
#define MULTI_TOGGLES 3
#else
#define MULTI_TOGGLES 0
#endif
#define WHEREIS_LIST_LEN (9 - NO_REGEX - NO_TOGGLES)
#define REPLACE_LIST_LEN (9 - NO_REGEX - NO_TOGGLES)
#define TOGGLE_LEN (14 - NO_REGEX + MULTI_TOGGLES)
#define WRITEFILE_LIST_LEN (4 - NO_BROWSER)
#define INSERTFILE_LIST_LEN (3 - NO_BROWSER)
#define BROWSER_LIST_LEN 5
#define MAIN_LIST_LEN (27 - NO_REGEX - SMALL_TOO)
#define MAIN_VISIBLE 12 #define MAIN_VISIBLE 12
#define REPLACE_LIST_2_LEN 4
#define GOTO_LIST_LEN 4
#define GOTODIR_LIST_LEN 2
#define HELP_LIST_LEN 3
#define SPELL_LIST_LEN 2
#define VIEW 1 #define VIEW 1
#define NOVIEW 0 #define NOVIEW 0

View File

@ -55,6 +55,12 @@
# Use smooth scrolling as the default # Use smooth scrolling as the default
# set smooth # set smooth
# Use alternate keypad routines
# set keypad
# Don't convert files from DOS/Mac format
# set noconvert
# Allow multiple file buffers (using ^R inserts into separate buffer) # Allow multiple file buffers (using ^R inserts into separate buffer)
# You must have configured with --enable-multibuffer or --enable-extra for # You must have configured with --enable-multibuffer or --enable-extra for
# this to work # this to work

30
proto.h
View File

@ -64,13 +64,13 @@ colortype *colorstrings;
#endif #endif
extern shortcut *shortcut_list; extern shortcut *shortcut_list;
extern shortcut main_list[MAIN_LIST_LEN], whereis_list[WHEREIS_LIST_LEN]; extern shortcut *main_list, *whereis_list;
extern shortcut replace_list[REPLACE_LIST_LEN], goto_list[GOTO_LIST_LEN]; extern shortcut *replace_list, *goto_list;
extern shortcut writefile_list[WRITEFILE_LIST_LEN], insertfile_list[INSERTFILE_LIST_LEN]; extern shortcut *writefile_list, *insertfile_list;
extern shortcut spell_list[SPELL_LIST_LEN], replace_list_2[REPLACE_LIST_LEN]; extern shortcut *spell_list, *replace_list_2;
extern shortcut help_list[HELP_LIST_LEN]; extern shortcut *help_list;
#ifndef DISABLE_BROWSER #ifndef DISABLE_BROWSER
extern shortcut browser_list[BROWSER_LIST_LEN], gotodir_list[GOTODIR_LIST_LEN]; extern shortcut *browser_list, *gotodir_list;
#endif #endif
extern shortcut *currshortcut; extern shortcut *currshortcut;
@ -80,7 +80,7 @@ extern regex_t search_regexp;
extern regmatch_t regmatches[10]; extern regmatch_t regmatches[10];
#endif #endif
extern toggle toggles[TOGGLE_LEN]; extern toggle *toggles;
/* Programs we want available */ /* Programs we want available */
@ -95,7 +95,7 @@ int xplustabs(void);
int do_yesno(int all, int leavecursor, char *msg, ...); int do_yesno(int all, int leavecursor, char *msg, ...);
int actual_x(filestruct * fileptr, int xplus); int actual_x(filestruct * fileptr, int xplus);
int strlenpt(char *buf); int strlenpt(char *buf);
int statusq(int allowtabs, shortcut s[], int slen, char *def, char *msg, ...); int statusq(int allowtabs, shortcut s[], char *def, char *msg, ...);
int write_file(char *name, int tmpfile, int append, int nonamechange); int write_file(char *name, int tmpfile, int append, int nonamechange);
int do_cut_text(void); int do_cut_text(void);
int do_uncut_text(void); int do_uncut_text(void);
@ -103,6 +103,7 @@ int no_help(void);
int renumber_all(void); int renumber_all(void);
int open_file(char *filename, int insert, int quiet); int open_file(char *filename, int insert, int quiet);
int do_insertfile(int loading_file); int do_insertfile(int loading_file);
int length_of_list(shortcut *s);
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER
int add_open_file(int update, int dup_fix); int add_open_file(int update, int dup_fix);
@ -155,7 +156,7 @@ void blank_statusbar(void);
void titlebar(char *path); void titlebar(char *path);
void previous_line(void); void previous_line(void);
void center_cursor(void); void center_cursor(void);
void bottombars(shortcut s[], int slen); void bottombars(shortcut *s);
void blank_statusbar_refresh(void); void blank_statusbar_refresh(void);
void *nmalloc (size_t howmuch); void *nmalloc (size_t howmuch);
void *mallocstrcpy(char *dest, char *src); void *mallocstrcpy(char *dest, char *src);
@ -194,7 +195,6 @@ void do_rcfile(void);
void do_credits(void); void do_credits(void);
#endif #endif
int do_writeout_void(void), do_exit(void), do_gotoline_void(void); int do_writeout_void(void), do_exit(void), do_gotoline_void(void);
int do_insertfile_void(void), do_search(void); int do_insertfile_void(void), do_search(void);
@ -214,12 +214,18 @@ int keypad_on(WINDOW * win, int newval);
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER
int open_file_dup_fix(int update); int open_file_dup_fix(int update);
int open_prevfile(int closing_file), open_nextfile(int closing_file); int open_prevfile(int closing_file), open_nextfile(int closing_file);
int open_prevfile_void(void), open_nextfile_void(void);
#endif #endif
char *charalloc (size_t howmuch); char *charalloc (size_t howmuch);
#if defined (ENABLE_MULTIBUFFER) || !defined (ENABLE_OPERATINGDIR) #if defined (ENABLE_MULTIBUFFER) || !defined (DISABLE_SPELLER) || !defined (DISABLE_OPERATINGDIR)
char *get_full_path(char *origpath); char *get_full_path(const char *origpath);
#endif
#ifndef DISABLE_SPELLER
char *check_writable_directory(const char *path, int *writable);
char *safe_tempnam(const char *dirname, const char *filename_prefix);
#endif #endif
#ifndef DISABLE_BROWSER #ifndef DISABLE_BROWSER

View File

@ -40,11 +40,7 @@
#define _(string) (string) #define _(string) (string)
#endif #endif
#ifndef DISABLE_WRAPJUSTIFY #define NUM_RCOPTS 21
#define NUM_RCOPTS 20
#else
#define NUM_RCOPTS 19
#endif
/* Static stuff for the nanorc file */ /* Static stuff for the nanorc file */
rcoption rcopts[NUM_RCOPTS] = { rcoption rcopts[NUM_RCOPTS] = {
@ -57,11 +53,7 @@ rcoption rcopts[NUM_RCOPTS] = {
{"operatingdir", 0}, {"operatingdir", 0},
{"pico", PICO_MODE}, {"pico", PICO_MODE},
{"tabsize", 0}, {"tabsize", 0},
#ifndef DISABLE_WRAPJUSTIFY
{"fill", 0}, {"fill", 0},
#endif
{"speller", 0}, {"speller", 0},
{"tempfile", TEMP_OPT}, {"tempfile", TEMP_OPT},
{"view", VIEW_MODE}, {"view", VIEW_MODE},
@ -71,7 +63,8 @@ rcoption rcopts[NUM_RCOPTS] = {
{"multibuffer", MULTIBUFFER}, {"multibuffer", MULTIBUFFER},
{"smooth", SMOOTHSCROLL}, {"smooth", SMOOTHSCROLL},
{"keypad", ALT_KEYPAD}, {"keypad", ALT_KEYPAD},
{"relative", RELATIVECHARS} {"relative", RELATIVECHARS},
{"noconvert", NO_CONVERT}
}; };
static int errors = 0; static int errors = 0;

View File

@ -76,7 +76,7 @@ int search_init(int replacing)
char *buf; char *buf;
static char *backupstring = NULL; static char *backupstring = NULL;
#ifndef NANO_SMALL #ifndef NANO_SMALL
int j; toggle *t;
#endif #endif
search_init_globals(); search_init_globals();
@ -126,8 +126,7 @@ int search_init(int replacing)
strcpy(buf, ""); strcpy(buf, "");
/* This is now one simple call. It just does a lot */ /* This is now one simple call. It just does a lot */
i = statusq(0, replacing ? replace_list : whereis_list, i = statusq(0, replacing ? replace_list : whereis_list, backupstring,
replacing ? REPLACE_LIST_LEN : WHEREIS_LIST_LEN, backupstring,
"%s%s%s%s%s%s", "%s%s%s%s%s%s",
_("Search"), _("Search"),
@ -187,9 +186,9 @@ int search_init(int replacing)
backupstring = mallocstrcpy(backupstring, answer); backupstring = mallocstrcpy(backupstring, answer);
#ifndef NANO_SMALL #ifndef NANO_SMALL
for (j = 0; j <= TOGGLE_LEN - 1; j++) for (t = toggles; t != NULL; t = t->next)
if (i == toggles[j].val) if (i == t->val)
TOGGLE(toggles[j].flag); TOGGLE(t->flag);
#endif #endif
return 1; return 1;
@ -743,15 +742,15 @@ int do_replace(void)
} else } else
sprintf(buf, "%s", last_replace); sprintf(buf, "%s", last_replace);
i = statusq(0, replace_list_2, REPLACE_LIST_2_LEN, "", i = statusq(0, replace_list_2, "",
_("Replace with [%s]"), buf); _("Replace with [%s]"), buf);
} }
else else
i = statusq(0, replace_list_2, REPLACE_LIST_2_LEN, "", i = statusq(0, replace_list_2, "",
_("Replace with")); _("Replace with"));
} }
else else
i = statusq(0, replace_list_2, REPLACE_LIST_2_LEN, last_replace, i = statusq(0, replace_list_2, last_replace,
_("Replace with")); _("Replace with"));
/* save where we are */ /* save where we are */
@ -786,7 +785,7 @@ int do_gotoline(int line, int save_pos)
int j = 0; int j = 0;
j = statusq(0, goto_list, GOTO_LIST_LEN, "", _("Enter line number")); j = statusq(0, goto_list, "", _("Enter line number"));
if (j != 0) { if (j != 0) {
statusbar(_("Aborted")); statusbar(_("Aborted"));
goto_abort(); goto_abort();

110
winio.c
View File

@ -258,16 +258,18 @@ void nanoget_repaint(char *buf, char *inputbuf, int x)
} }
/* Get the input from the kb; this should only be called from statusq */ /* Get the input from the kb; this should only be called from statusq */
int nanogetstr(int allowtabs, char *buf, char *def, shortcut s[], int slen, int nanogetstr(int allowtabs, char *buf, char *def, shortcut *s,
int start_x, int list) int start_x, int list)
{ {
int kbinput = 0, j = 0, x = 0, xend; int kbinput = 0, j = 0, x = 0, xend, slen;
int x_left = 0, inputlen, tabbed = 0; int x_left = 0, inputlen, tabbed = 0;
char *inputbuf; char *inputbuf;
shortcut *t;
#ifndef DISABLE_TABCOMP #ifndef DISABLE_TABCOMP
int shift = 0; int shift = 0;
#endif #endif
slen = length_of_list(s);
inputbuf = charalloc(strlen(def) + 1); inputbuf = charalloc(strlen(def) + 1);
inputbuf[0] = 0; inputbuf[0] = 0;
@ -276,7 +278,6 @@ int nanogetstr(int allowtabs, char *buf, char *def, shortcut s[], int slen,
#if !defined(DISABLE_HELP) || !defined(DISABLE_MOUSE) #if !defined(DISABLE_HELP) || !defined(DISABLE_MOUSE)
currshortcut = s; currshortcut = s;
currslen = slen;
#endif #endif
/* Get the input! */ /* Get the input! */
@ -289,12 +290,12 @@ int nanogetstr(int allowtabs, char *buf, char *def, shortcut s[], int slen,
wrefresh(edit); wrefresh(edit);
while ((kbinput = wgetch(bottomwin)) != 13) { while ((kbinput = wgetch(bottomwin)) != 13) {
for (j = 0; j <= slen - 1; j++) { for (t = s; t != NULL; t = t->next) {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, _("Aha! \'%c\' (%d)\n"), kbinput, kbinput); fprintf(stderr, _("Aha! \'%c\' (%d)\n"), kbinput, kbinput);
#endif #endif
if (kbinput == s[j].val && kbinput < 32) { if (kbinput == t->val && kbinput < 32) {
#ifndef DISABLE_HELP #ifndef DISABLE_HELP
/* Have to do this here, it would be too late to do it in statusq */ /* Have to do this here, it would be too late to do it in statusq */
@ -308,7 +309,7 @@ int nanogetstr(int allowtabs, char *buf, char *def, shortcut s[], int slen,
we hit a keystroke, GEEZ! */ we hit a keystroke, GEEZ! */
answer = mallocstrcpy(answer, inputbuf); answer = mallocstrcpy(answer, inputbuf);
free(inputbuf); free(inputbuf);
return s[j].val; return t->val;
} }
} }
xend = strlen(buf) + strlen(inputbuf); xend = strlen(buf) + strlen(inputbuf);
@ -459,19 +460,19 @@ int nanogetstr(int allowtabs, char *buf, char *def, shortcut s[], int slen,
} }
default: default:
for (j = 0; j <= slen - 1; j++) { for (t = s; t != NULL; t = t->next) {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, _("Aha! \'%c\' (%d)\n"), kbinput, fprintf(stderr, _("Aha! \'%c\' (%d)\n"), kbinput,
kbinput); kbinput);
#endif #endif
if (kbinput == s[j].val || kbinput == s[j].val - 32) { if (kbinput == t->val || kbinput == t->val - 32) {
/* We hit an Alt key. Do like above. We don't /* We hit an Alt key. Do like above. We don't
just ungetch the letter and let it get caught just ungetch the letter and let it get caught
above cause that screws the keypad... */ above cause that screws the keypad... */
answer = mallocstrcpy(answer, inputbuf); answer = mallocstrcpy(answer, inputbuf);
free(inputbuf); free(inputbuf);
return s[j].val; return t->val;
} }
} }
@ -573,15 +574,17 @@ void titlebar(char *path)
reset_cursor(); reset_cursor();
} }
void onekey(char *keystroke, char *desc) void onekey(char *keystroke, char *desc, int len)
{ {
char description[80]; int i;
snprintf(description, 12 - (strlen(keystroke) - 2), " %-10s", desc);
wattron(bottomwin, A_REVERSE); wattron(bottomwin, A_REVERSE);
waddstr(bottomwin, keystroke); waddstr(bottomwin, keystroke);
wattroff(bottomwin, A_REVERSE); wattroff(bottomwin, A_REVERSE);
waddstr(bottomwin, description); waddch(bottomwin, ' ');
waddnstr(bottomwin, desc, len - 3);
for (i = strlen(desc); i < len - 3; i++)
waddch(bottomwin, ' ');
} }
void clear_bottomwin(void) void clear_bottomwin(void)
@ -593,10 +596,17 @@ void clear_bottomwin(void)
mvwaddstr(bottomwin, 2, 0, hblank); mvwaddstr(bottomwin, 2, 0, hblank);
} }
void bottombars(shortcut s[], int slen) void bottombars(shortcut *s)
{ {
int i, j, k; int i, j, k;
char keystr[10]; char keystr[10];
shortcut *t;
int slen;
if (s == main_list)
slen = MAIN_VISIBLE;
else
slen = length_of_list(s);
if (ISSET(NO_HELP)) if (ISSET(NO_HELP))
return; return;
@ -610,39 +620,42 @@ void bottombars(shortcut s[], int slen)
/* Determine how many extra spaces are needed to fill the bottom of the screen */ /* Determine how many extra spaces are needed to fill the bottom of the screen */
if (slen < 2) if (slen < 2)
k = COLS / 6 - 13; k = COLS / 6;
else else
k = COLS / ((slen + (slen % 2)) / 2) - 13; k = COLS / ((slen + (slen % 2)) / 2);
clear_bottomwin(); clear_bottomwin();
wmove(bottomwin, 1, 0);
for (i = 0; i <= slen - 1; i += 2) { t = s;
for (i = 0; i < slen / 2; i++) {
if (s[i].val < 97) wmove(bottomwin, 1, i * k);
snprintf(keystr, 10, "^%c", s[i].val + 64);
if (t->val < 97)
snprintf(keystr, 10, "^%c", t->val + 64);
else else
snprintf(keystr, 10, "M-%c", s[i].val - 32); snprintf(keystr, 10, "M-%c", t->val - 32);
onekey(keystr, s[i].desc); onekey(keystr, t->desc, k);
for (j = 0; j < k; j++) if (t->next == NULL)
waddch(bottomwin, ' '); break;
} t = t->next;
wmove(bottomwin, 2, 0); wmove(bottomwin, 2, i * k);
for (i = 1; i <= slen - 1; i += 2) {
if (s[i].val < 97) if (t->val < 97)
snprintf(keystr, 10, "^%c", s[i].val + 64); snprintf(keystr, 10, "^%c", t->val + 64);
else else
snprintf(keystr, 10, "M-%c", s[i].val - 32); snprintf(keystr, 10, "M-%c", t->val - 32);
onekey(keystr, s[i].desc); onekey(keystr, t->desc, k);
for (j = 0; j < k; j++) if (t->next == NULL)
waddch(bottomwin, ' '); break;
t = t->next;
} }
#ifdef ENABLE_COLOR #ifdef ENABLE_COLOR
@ -1293,17 +1306,17 @@ void update_cursor(void)
* *
* New arg tabs tells whether or not to allow tab completion. * New arg tabs tells whether or not to allow tab completion.
*/ */
int statusq(int tabs, shortcut s[], int slen, char *def, char *msg, ...) int statusq(int tabs, shortcut *s, char *def, char *msg, ...)
{ {
va_list ap; va_list ap;
char foo[133]; char foo[133];
int ret; int ret, slen;
#ifndef DISABLE_TABCOMP #ifndef DISABLE_TABCOMP
int list = 0; int list = 0;
#endif #endif
bottombars(s, slen); bottombars(s);
va_start(ap, msg); va_start(ap, msg);
vsnprintf(foo, 132, msg, ap); vsnprintf(foo, 132, msg, ap);
@ -1318,11 +1331,11 @@ int statusq(int tabs, shortcut s[], int slen, char *def, char *msg, ...)
#ifndef DISABLE_TABCOMP #ifndef DISABLE_TABCOMP
ret = nanogetstr(tabs, foo, def, s, slen, (strlen(foo) + 3), list); ret = nanogetstr(tabs, foo, def, s, (strlen(foo) + 3), list);
#else #else
/* if we've disabled tab completion, the value of list won't be /* if we've disabled tab completion, the value of list won't be
used at all, so it's safe to use 0 (NULL) as a placeholder */ used at all, so it's safe to use 0 (NULL) as a placeholder */
ret = nanogetstr(tabs, foo, def, s, slen, (strlen(foo) + 3), 0); ret = nanogetstr(tabs, foo, def, s, (strlen(foo) + 3), 0);
#endif #endif
#ifdef ENABLE_COLOR #ifdef ENABLE_COLOR
@ -1399,18 +1412,18 @@ int do_yesno(int all, int leavecursor, char *msg, ...)
wmove(bottomwin, 1, 0); wmove(bottomwin, 1, 0);
snprintf(shortstr, 3, " %c", yesstr[0]); snprintf(shortstr, 3, " %c", yesstr[0]);
onekey(shortstr, _("Yes")); onekey(shortstr, _("Yes"), 16);
if (all) { if (all) {
snprintf(shortstr, 3, " %c", allstr[0]); snprintf(shortstr, 3, " %c", allstr[0]);
onekey(shortstr, _("All")); onekey(shortstr, _("All"), 16);
} }
wmove(bottomwin, 2, 0); wmove(bottomwin, 2, 0);
snprintf(shortstr, 3, " %c", nostr[0]); snprintf(shortstr, 3, " %c", nostr[0]);
onekey(shortstr, _("No")); onekey(shortstr, _("No"), 16);
onekey("^C", _("Cancel")); onekey("^C", _("Cancel"), 16);
} }
va_start(ap, msg); va_start(ap, msg);
vsnprintf(foo, 132, msg, ap); vsnprintf(foo, 132, msg, ap);
@ -1556,7 +1569,7 @@ void statusbar(char *msg, ...)
void display_main_list(void) void display_main_list(void)
{ {
bottombars(main_list, MAIN_VISIBLE); bottombars(main_list);
} }
int total_refresh(void) int total_refresh(void)
@ -1667,10 +1680,8 @@ int do_help(void)
ptr = help_text; ptr = help_text;
oldshortcut = currshortcut; oldshortcut = currshortcut;
oldslen = currslen;
currshortcut = help_list; currshortcut = help_list;
currslen = HELP_LIST_LEN;
kp = keypad_on(edit, 1); kp = keypad_on(edit, 1);
kp2 = keypad_on(bottomwin, 1); kp2 = keypad_on(bottomwin, 1);
@ -1682,10 +1693,10 @@ int do_help(void)
no_help_flag = 1; no_help_flag = 1;
UNSET(NO_HELP); UNSET(NO_HELP);
window_init(); window_init();
bottombars(help_list, HELP_LIST_LEN); bottombars(help_list);
} else } else
bottombars(help_list, HELP_LIST_LEN); bottombars(help_list);
do { do {
ptr = help_text; ptr = help_text;
@ -1766,7 +1777,6 @@ int do_help(void)
kbinput != NANO_EXIT_FKEY); kbinput != NANO_EXIT_FKEY);
currshortcut = oldshortcut; currshortcut = oldshortcut;
currslen = oldslen;
if (no_help_flag) { if (no_help_flag) {
blank_bottombars(); blank_bottombars();
@ -1774,7 +1784,7 @@ int do_help(void)
SET(NO_HELP); SET(NO_HELP);
window_init(); window_init();
} else } else
bottombars(currshortcut, currslen); bottombars(currshortcut);
curs_set(1); curs_set(1);
edit_refresh(); edit_refresh();
@ -1895,6 +1905,7 @@ void do_credits(void)
"Adam Rogoyski", "Adam Rogoyski",
"Rob Siemborski", "Rob Siemborski",
"Rocco Corsi", "Rocco Corsi",
"David Lawrence Ramsey",
"Ken Tyler", "Ken Tyler",
"Sven Guckes", "Sven Guckes",
"Florian König", "Florian König",
@ -1909,7 +1920,6 @@ void do_credits(void)
"Joshua Jensen", "Joshua Jensen",
"Ryan Krebs", "Ryan Krebs",
"Albert Chin", "Albert Chin",
"David Lawrence Ramsey",
"", "",
specialthx, specialthx,
"Plattsburgh State University", "Plattsburgh State University",