}
-
int read_byte(int fd, char *filename, char *input)
{
static char buf[BUFSIZ];
strcpy(fileptr->data, buf);
#ifndef NANO_SMALL
- /* If it's a DOS file (CRLF), strip out the CR part*/
- if (buf[strlen(buf) - 1] == '\r') {
+ /* If it's a DOS file (CRLF), and file conversion isn't disabled,
+ strip out the CR part */
+ if (!ISSET(NO_CONVERT) && buf[strlen(buf) - 1] == '\r') {
fileptr->data[strlen(buf) - 1] = 0;
totsize--;
return fileptr;
}
-
int read_file(int fd, char *filename, int quiet)
{
long size;
buf[0] = 0;
i = 0;
#ifndef NANO_SMALL
- /* If it's a Mac file (no LF just a CR), handle it! */
- } else if (i > 0 && buf[i-1] == '\r') {
+ } else if (!ISSET(NO_CONVERT) && input[0] < 32
+ && 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;
fileptr = read_line(buf, fileptr, &line1ins);
num_lines++;
#if !defined(DISABLE_BROWSER) || !defined(DISABLE_MOUSE)
currshortcut = insertfile_list;
- currslen = INSERTFILE_LIST_LEN;
#endif
- i = statusq(1, insertfile_list, INSERTFILE_LIST_LEN, "",
- _("File to insert [from ./] "));
+ i = statusq(1, insertfile_list, "", _("File to insert [from ./] "));
if (i != -1) {
#ifdef DEBUG
char *tmp = do_browse_from(realname);
#if !defined(DISABLE_HELP) || !defined(DISABLE_MOUSE)
currshortcut = insertfile_list;
- currslen = INSERTFILE_LIST_LEN;
#endif
#ifdef DISABLE_TABCOMP
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
* zero, update the current entry before switching from it. Otherwise, we
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
* entry, the next or previous entry is opened, whichever is found first.
display_main_list();
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
* origpath, return "[full path]" or "[full path][filename]" on success,
* yet on disk); it is not done if the relative path doesn't exist (since
* 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;
int path_only, last_slash_index;
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
/*
int do_writeout(char *path, int exiting, int append)
{
int i = 0;
+ char *formatstr;
#ifdef NANO_EXTRA
static int did_cred = 0;
#if !defined(DISABLE_BROWSER) || !defined(DISABLE_MOUSE)
currshortcut = writefile_list;
- currslen = WRITEFILE_LIST_LEN;
#endif
answer = mallocstrcpy(answer, path);
while (1) {
- /* Be nice to the translation folks */
#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 (append)
- i = statusq(1, writefile_list, WRITEFILE_LIST_LEN, "",
- _("Append Selection to File"));
+ i = statusq(1, writefile_list, "",
+ "%s%s", _("Append Selection to File"), formatstr);
else
- i = statusq(1, writefile_list, WRITEFILE_LIST_LEN, "",
- _("Write Selection to File"));
+ i = statusq(1, writefile_list, "",
+ "%s%s", _("Write Selection to File"), formatstr);
} else
#endif
{
if (append)
- i = statusq(1, writefile_list, WRITEFILE_LIST_LEN, answer,
- _("File Name to Append"));
+ i = statusq(1, writefile_list, answer,
+ "%s%s", _("File Name to Append"), formatstr);
else
- i = statusq(1, writefile_list, WRITEFILE_LIST_LEN, answer,
- _("File Name to Write"));
+ i = statusq(1, writefile_list, answer,
+ "%s%s", _("File Name to Write"), formatstr);
}
#if !defined(DISABLE_BROWSER) || !defined(DISABLE_MOUSE)
currshortcut = writefile_list;
- currslen = WRITEFILE_LIST_LEN;
#endif
if (tmp != NULL) {
return do_writeout(answer, exiting, append);
} else
#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));
#ifdef DEBUG
kb = keypad_on(edit, 1);
titlebar(path);
- bottombars(browser_list, BROWSER_LIST_LEN);
+ bottombars(browser_list);
curs_set(0);
wmove(edit, 0, 0);
i = 0;
#if !defined DISABLE_HELP || !defined(DISABLE_MOUSE)
currshortcut = browser_list;
- currslen = BROWSER_LIST_LEN;
#endif
editline = 0;
case NANO_GOTO_KEY:
curs_set(1);
- j = statusq(0, gotodir_list, GOTODIR_LIST_LEN, "", _("Goto Directory"));
- bottombars(browser_list, BROWSER_LIST_LEN);
+ j = statusq(0, gotodir_list, "", _("Goto Directory"));
+ bottombars(browser_list);
curs_set(0);
#ifndef DISABLE_OPERATINGDIR
char *alt_speller; /* Alternative spell command */
#endif
-shortcut main_list[MAIN_LIST_LEN];
-shortcut whereis_list[WHEREIS_LIST_LEN];
-shortcut replace_list[REPLACE_LIST_LEN];
-shortcut replace_list_2[REPLACE_LIST_LEN]; /* 2nd half of replace dialog */
-shortcut goto_list[GOTO_LIST_LEN];
-shortcut gotodir_list[GOTODIR_LIST_LEN];
-shortcut writefile_list[WRITEFILE_LIST_LEN];
-shortcut insertfile_list[INSERTFILE_LIST_LEN];
-shortcut help_list[HELP_LIST_LEN];
-shortcut spell_list[SPELL_LIST_LEN];
+shortcut *main_list = NULL;
+shortcut *whereis_list = NULL;
+shortcut *replace_list = NULL;
+shortcut *replace_list_2; /* 2nd half of replace dialog */
+shortcut *goto_list = NULL;
+shortcut *gotodir_list = NULL;
+shortcut *writefile_list = NULL;
+shortcut *insertfile_list = NULL;
+shortcut *help_list = NULL;
+shortcut *spell_list = NULL;
#ifndef DISABLE_BROWSER
-shortcut browser_list[BROWSER_LIST_LEN];
+shortcut *browser_list = NULL;
#endif
#ifdef ENABLE_COLOR
#endif
#if !defined(DISABLE_BROWSER) || !defined(DISABLE_MOUSE) || !defined (DISABLE_HELP)
-shortcut *currshortcut = main_list; /* Current shortcut list we're using */
-int currslen = MAIN_VISIBLE; /* Length of current shortcut list */
+shortcut *currshortcut; /* Current shortcut list we're using */
#endif
#ifndef NANO_SMALL
-toggle toggles[TOGGLE_LEN];
+toggle *toggles = NULL;
#endif
/* Regular expressions */
subexpressions, max of 10 */
#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 =( */
-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))
{
+ 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->desc = desc;
s->help = help;
s->misc2 = misc2;
s->viewok = view;
s->func = func;
+ s->next = NULL;
}
#ifndef NANO_SMALL
/* Initialize the toggles in the same manner */
-void toggle_init_one(toggle * t, int val, char *desc, int flag,
- char override_ch)
+void toggle_init_one(int val, char *desc, int flag)
{
- t->val = val;
- t->desc = desc;
- t->flag = flag;
- t->override_ch = override_ch;
+ toggle *u;
+
+ if (toggles == NULL) {
+ 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
char *toggle_const_msg, *toggle_autoindent_msg, *toggle_suspend_msg,
*toggle_nohelp_msg, *toggle_picomode_msg, *toggle_mouse_msg,
*toggle_cuttoend_msg, *toggle_wrap_msg, *toggle_case_msg,
- *toggle_backwards_msg, *toggle_dos_msg, *toggle_mac_msg,
- *toggle_smooth_msg;
-
-#ifdef ENABLE_MULTIBUFFER
- char *toggle_load_msg, *nano_openprev_msg, *nano_opennext_msg;
-#endif
+ *toggle_backwards_msg, *toggle_noconvert_msg, *toggle_dos_msg,
+ *toggle_mac_msg, *toggle_smooth_msg;
#ifdef HAVE_REGEX_H
char *toggle_regexp_msg;
#endif
+#ifdef ENABLE_MULTIBUFFER
+ char *toggle_load_msg;
+#endif
toggle_const_msg = _("Constant cursor position");
toggle_autoindent_msg = _("Auto indent");
toggle_cuttoend_msg = _("Cut to end");
toggle_backwards_msg = _("Backwards search");
toggle_case_msg = _("Case sensitive search");
- toggle_dos_msg = _("Writing file in DOS format");
- toggle_mac_msg = _("Writing file in Mac format");
- toggle_smooth_msg = _("Smooth scrolling");
#ifdef HAVE_REGEX_H
- toggle_regexp_msg = _("Regular expressions");
+ 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_mac_msg = _("Writing file in Mac format");
+ toggle_smooth_msg = _("Smooth scrolling");
toggle_wrap_msg = _("Auto wrap");
#ifdef ENABLE_MULTIBUFFER
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
+ 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
- toggle_init_one(&toggles[TOGGLE_LEN - 1], TOGGLE_REGEXP_KEY,
- toggle_regexp_msg, USE_REGEXP, 0);
+ toggle_init_one(TOGGLE_REGEXP_KEY, toggle_regexp_msg, USE_REGEXP);
#endif
+#ifdef ENABLE_MULTIBUFFER
+ toggle_init_one(TOGGLE_LOAD_KEY, toggle_load_msg, MULTIBUFFER);
#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)
"", *nano_mark_msg = "", *nano_delete_msg =
"", *nano_backspace_msg = "", *nano_tab_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
char *nano_tofiles_msg = "", *nano_gotodir_msg = "", *nano_case_msg =
#ifdef HAVE_REGEX_H
char *nano_regexp_msg = "", *nano_bracket_msg = "";
#endif
+#ifdef ENABLE_MULTIBUFFER
+ char *nano_openprev_msg = "", *nano_opennext_msg = "";
+#endif
nano_help_msg = _("Invoke the help menu");
nano_writeout_msg = _("Write the current file to disk");
nano_cancel_msg = _("Cancel the current function");
nano_append_msg = _("Append to the current file");
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
nano_regexp_msg = _("Use Regular expressions");
nano_bracket_msg = _("Find other bracket");
#endif
+#ifdef ENABLE_MULTIBUFFER
+ nano_openprev_msg = _("Open previously loaded file");
+ nano_opennext_msg = _("Open next loaded file");
#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);
#ifdef ENABLE_MULTIBUFFER
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);
else
#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);
- sc_init_one(&main_list[2], NANO_WRITEOUT_KEY, _("WriteOut"),
+ sc_init_one(&main_list, NANO_WRITEOUT_KEY, _("WriteOut"),
nano_writeout_msg,
0, NANO_WRITEOUT_FKEY, 0, NOVIEW, do_writeout_void);
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,
NOVIEW, do_justify);
else
#ifdef ENABLE_MULTIBUFFER
/* 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,
0, NANO_INSERTFILE_FKEY, 0, VIEW, do_insertfile_void);
#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,
0, NANO_INSERTFILE_FKEY, 0, NOVIEW, do_insertfile_void);
#endif
#ifdef ENABLE_MULTIBUFFER
/* 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,
0, NANO_INSERTFILE_FKEY, 0, VIEW, do_insertfile_void);
#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,
0, NANO_INSERTFILE_FKEY, 0, NOVIEW, do_insertfile_void);
#endif
else
- sc_init_one(&main_list[4], NANO_REPLACE_KEY, _("Replace"),
+ sc_init_one(&main_list, NANO_REPLACE_KEY, _("Replace"),
nano_replace_msg,
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,
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,
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,
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);
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);
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,
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,
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);
- 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);
- 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);
- 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);
- 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);
- 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);
- 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);
- 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);
- 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);
- 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_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,
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);
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_ALT_REPLACE_KEY, NANO_REPLACE_FKEY, 0, NOVIEW, do_replace);
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,
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,
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_ALT_GOTO_KEY, NANO_GOTO_FKEY, 0, VIEW, do_gotoline_void);
#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_KEY, 0, 0, VIEW, do_find_bracket);
#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);
- 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);
- 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);
- 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);
- 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);
- 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,
do_gotoline_void);
#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);
- 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);
#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);
#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);
- 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);
- 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);
- 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);
- 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);
- 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,
do_gotoline_void);
#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);
- 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);
#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);
#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);
- 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);
- 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);
- 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);
- 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);
- 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);
- 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);
- 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);
- sc_init_one(&help_list[0], NANO_PREVPAGE_KEY, _("Prev Page"),
+ sc_init_one(&help_list, NANO_PREVPAGE_KEY, _("Prev Page"),
nano_prevpage_msg,
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,
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);
- 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);
- sc_init_one(&writefile_list[1], NANO_CANCEL_KEY, _("Cancel"),
- nano_cancel_msg, 0, 0, 0, VIEW, 0);
-
#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);
#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);
- 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);
- 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);
#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);
#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);
- 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);
#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);
- 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);
- sc_init_one(&browser_list[2], NANO_PREVPAGE_KEY, _("Prev Page"),
+ sc_init_one(&browser_list, NANO_PREVPAGE_KEY, _("Prev Page"),
nano_prevpage_msg,
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,
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,
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);
- 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);
#endif
+#if !defined(DISABLE_BROWSER) || !defined(DISABLE_MOUSE) || !defined (DISABLE_HELP)
+ currshortcut = main_list;
+#endif
+
toggle_init();
}
#ifndef DISABLE_WRAPJUSTIFY
/* Former globals, now static */
-int fill = 0; /* Fill - where to wrap lines, basically */
-int wrap_at = 0; /* Right justified fill value, allows resize */
+int fill = 0;/* Fill - where to wrap lines, basically */
+int wrap_at = 0; /* Right justified fill value, allows resize */
#endif
struct termios oldterm; /* The user's original term settings */
printf
(_
(" -M --mac Write file in Mac format\n"));
-#endif
-#ifdef HAVE_REGEX_H
- printf(_
- (" -R --regexp Use regular expressions for search\n"));
+ printf
+ (_
+ (" -N --noconvert Don't convert files from DOS/Mac format\n"));
#endif
#ifndef NANO_SMALL
printf(_
do_replace_highlight(TRUE, prevanswer);
/* allow replace word to be corrected */
- i = statusq(0, spell_list, SPELL_LIST_LEN, last_replace,
- _("Edit a replacement"));
+ i = statusq(0, spell_list, last_replace, _("Edit a replacement"));
do_replace_highlight(FALSE, prevanswer);
char *temp;
int spell_res;
- if ((temp = tempnam(0, "nano.")) == NULL) {
+ if ((temp = safe_tempnam(0, "nano.")) == NULL) {
statusbar(_("Could not create a temporary filename: %s"),
strerror(errno));
return 0;
{
MEVENT mevent;
int foo = 0, tab_found = 0;
+ int currslen;
if (getmouse(&mevent) == ERR)
return;
int k, val = 0;
+ if (currshortcut == main_list)
+ currslen = MAIN_VISIBLE;
+ else
+ currslen = length_of_list(currshortcut);
+
if (currslen < 2)
k = COLS / 6;
else
#ifndef DISABLE_HELP
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 */
char buf[BUFSIZ] = "", *ptr = NULL;
+ toggle *t;
+ shortcut *s;
- if (currslen == MAIN_VISIBLE)
- helplen = MAIN_LIST_LEN;
- else
- helplen = currslen;
+/*
+ if (currshortcut = main_list)
+ helplen = MAIN_VISIBLE;
+ else */
+ helplen = length_of_list(currshortcut);
/* First set up the initial help text for the current function */
if (currshortcut == whereis_list || currshortcut == replace_list
"or --multibuffer command line flags, the Meta-F toggle or "
"using 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 The following function keys are "
- "available in Insert File mode:\n\n");
+ "between file buffers).\n\n In multiple buffer mode, the "
+ "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)
ptr = _("Write File Help Text\n\n "
"Type the name that you wish to save the current file "
/* Compute the space needed for the shortcut lists - we add 15 to
have room for the shortcut abbrev and its possible alternate keys */
- for (i = 0; i <= helplen - 1; i++)
- if (currshortcut[i].help != NULL)
- allocsize += strlen(currshortcut[i].help) + 15;
+ s = currshortcut;
+ for (i = 0; i <= helplen - 1; i++) {
+ 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 (currshortcut == main_list) {
- for (i = 0; i <= TOGGLE_LEN - 1; i++)
- if (toggles[i].desc != NULL)
- allocsize += strlen(toggles[i].desc) + 30;
-
+ for (t = toggles; t != NULL; t = t->next)
+ if (t->desc != NULL)
+ allocsize += strlen(t->desc) + 30;
}
allocsize += strlen(ptr);
-
if (help_text != NULL)
free(help_text);
strcpy(help_text, ptr);
/* Now add our shortcut info */
+ s = currshortcut;
for (i = 0; i <= helplen - 1; i++) {
- if (currshortcut[i].val > 0 && currshortcut[i].val < 'a')
- sofar = snprintf(buf, BUFSIZ, "^%c ", currshortcut[i].val + 64);
- else
- sofar = snprintf(buf, BUFSIZ, " ");
+ if (s->val > 0 && s->val < 'a')
+ sofar = snprintf(buf, BUFSIZ, "^%c ", s->val + 64);
+ else {
+ 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))
- sofar += snprintf(&buf[sofar], BUFSIZ - sofar, "(F%d) ",
- currshortcut[i].misc1 - KEY_F0);
- else
- 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].altval > 0 && currshortcut[i].altval < 91)
- sofar += snprintf(&buf[sofar], BUFSIZ - sofar, "(M-%c) ",
- currshortcut[i].altval - 32);
- else if (currshortcut[i].altval > 0)
- sofar += snprintf(&buf[sofar], BUFSIZ - sofar, "(M-%c) ",
- currshortcut[i].altval);
+ if (s->altval > 0 && s->altval < 91
+ && (s->altval - 32) > 32)
+ sofar += snprintf(&buf[sofar], BUFSIZ - sofar,
+ (meta_shortcut ? "M-%c " : "(M-%c) "),
+ s->altval - 32);
+ else if (s->altval > 0)
+ sofar += snprintf(&buf[sofar], BUFSIZ - sofar,
+ (meta_shortcut ? "M-%c " : "(M-%c) "),
+ s->altval);
/* Hack */
- else if (currshortcut[i].val >= 'a')
- sofar += snprintf(&buf[sofar], BUFSIZ - sofar, "(M-%c) ",
- currshortcut[i].val - 32);
+ else if (s->val >= 'a')
+ sofar += snprintf(&buf[sofar], BUFSIZ - sofar,
+ (meta_shortcut ? "(M-%c) " : "M-%c "),
+ s->val - 32);
else
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)
- snprintf(&buf[sofar], BUFSIZ - sofar, "%s", currshortcut[i].help);
-
+ if (s->help != NULL)
+ snprintf(&buf[sofar], BUFSIZ - sofar, "%s", s->help);
strcat(help_text, buf);
strcat(help_text, "\n");
+
+ s = s->next;
}
/* And the toggles... */
if (currshortcut == main_list)
- for (i = 0; i <= TOGGLE_LEN - 1; i++) {
- if (toggles[i].override_ch != 0)
- sofar = snprintf(buf, BUFSIZ,
- "M-%c ", toggles[i].override_ch);
- else
+ for (t = toggles; t != NULL; t = t->next) {
sofar = snprintf(buf, BUFSIZ,
- "M-%c ", toggles[i].val - 32);
-
- if (toggles[i].desc != NULL) {
- if (toggles[i].flag != 0)
+ "M-%c ", t->val - 32);
+ if (t->desc != NULL) {
snprintf(&buf[sofar], BUFSIZ - sofar, _("%s enable/disable"),
- toggles[i].desc);
- else
- snprintf(&buf[sofar], BUFSIZ - sofar, "%s",
- toggles[i].desc);
+ t->desc);
}
-
strcat(help_text, buf);
strcat(help_text, "\n");
}
}
#endif
-void do_toggle(int which)
+void do_toggle(toggle *which)
{
#ifdef NANO_SMALL
nano_disabled_msg();
char *enabled = _("enabled");
char *disabled = _("disabled");
- switch (toggles[which].val) {
+ switch (which->val) {
case TOGGLE_BACKWARDS_KEY:
case TOGGLE_CASE_KEY:
case TOGGLE_REGEXP_KEY:
}
/* Even easier! */
- TOGGLE(toggles[which].flag);
+ TOGGLE(which->flag);
- switch (toggles[which].val) {
+ switch (which->val) {
case TOGGLE_PICOMODE_KEY:
shortcut_init(0);
SET(CLEAR_BACKUPSTRING);
break;
}
- if (!ISSET(toggles[which].flag)) {
- if (toggles[which].val == TOGGLE_NOHELP_KEY ||
- toggles[which].val == TOGGLE_WRAP_KEY)
- statusbar("%s %s", toggles[which].desc, enabled);
+ if (!ISSET(which->flag)) {
+ if (which->val == TOGGLE_NOHELP_KEY ||
+ which->val == TOGGLE_WRAP_KEY)
+ statusbar("%s %s", which->desc, enabled);
else
- statusbar("%s %s", toggles[which].desc, disabled);
+ statusbar("%s %s", which->desc, disabled);
} else {
- if (toggles[which].val == TOGGLE_NOHELP_KEY ||
- toggles[which].val == TOGGLE_WRAP_KEY)
- statusbar("%s %s", toggles[which].desc, disabled);
+ if (which->val == TOGGLE_NOHELP_KEY ||
+ which->val == TOGGLE_WRAP_KEY)
+ statusbar("%s %s", which->desc, disabled);
else
- statusbar("%s %s", toggles[which].desc, enabled);
+ statusbar("%s %s", which->desc, enabled);
}
#endif
int keyhandled; /* Have we handled the keystroke yet? */
int i, modify_control_seq;
char *argv0;
+ shortcut *s;
+ toggle *t;
#ifdef _POSIX_VDISABLE
struct termios term;
{"cut", 0, 0, 'k'},
{"dos", 0, 0, 'D'},
{"mac", 0, 0, 'M'},
+ {"noconvert", 0, 0, 'N'},
{"autoindent", 0, 0, 'i'},
#endif
{"tempfile", 0, 0, 't'},
#endif /* ENABLE_NANORC */
#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) {
#else
while ((optchr =
- getopt(argc, argv, "h?DFKMRST:Vabcefgijklmo:pr:s:tvwxz")) != EOF) {
+ getopt(argc, argv, "h?DFKMNRST:Vabcefgijklmo:pr:s:tvwxz")) != EOF) {
#endif
switch (optchr) {
case 'M':
SET(MAC_FILE);
break;
-#endif
- case 'T':
- tabsize = atoi(optarg);
- if (tabsize <= 0) {
- usage(); /* To stop bogus data for tab width */
- finish(1);
- }
+ case 'N':
+ SET(NO_CONVERT);
break;
+#endif
#ifdef HAVE_REGEX_H
case 'R':
SET(USE_REGEXP);
SET(SMOOTHSCROLL);
break;
#endif
+ case 'T':
+ tabsize = atoi(optarg);
+ if (tabsize <= 0) {
+ usage(); /* To stop bogus data for tab width */
+ finish(1);
+ }
+ break;
case 'V':
version();
exit(0);
#ifndef DISABLE_MOUSE
currshortcut = main_list;
- currslen = MAIN_VISIBLE;
#endif
#ifndef _POSIX_VDISABLE
break;
}
break;
+
#ifdef ENABLE_MULTIBUFFER
case NANO_OPENPREV_KEY:
case NANO_OPENPREV_ALTKEY:
keyhandled = 1;
break;
#endif
+
+#if !defined (NANO_SMALL) && defined (HAVE_REGEX_H)
+ case NANO_BRACKET_KEY:
+ do_find_bracket();
+ keyhandled = 1;
+ break;
+#endif
+
default:
/* Check for the altkey defs.... */
- for (i = 0; i <= MAIN_LIST_LEN - 1; i++)
- if (kbinput == main_list[i].altval ||
- kbinput == main_list[i].altval - 32) {
- kbinput = main_list[i].val;
+ for (s = main_list; s != NULL; s = s->next)
+ if (kbinput == s->altval ||
+ kbinput == s->altval - 32) {
+ kbinput = s->val;
break;
}
#ifndef NANO_SMALL
/* And for toggle switches */
- for (i = 0; i <= TOGGLE_LEN - 1 && !keyhandled; i++)
- if (kbinput == toggles[i].val ||
- (toggles[i].val > 'a' &&
- kbinput == toggles[i].val - 32)) {
- do_toggle(i);
+ for (t = toggles; t != NULL && !keyhandled; t = t->next)
+ if (kbinput == t->val ||
+ (t->val > 'a' &&
+ kbinput == t->val - 32)) {
+ do_toggle(t);
keyhandled = 1;
break;
}
/* Look through the main shortcut list to see if we've hit a
shortcut key */
- for (i = 0; i < MAIN_LIST_LEN && !keyhandled; i++) {
- if (kbinput == main_list[i].val ||
- (main_list[i].misc1 && kbinput == main_list[i].misc1) ||
- (main_list[i].misc2 && kbinput == main_list[i].misc2)) {
- if (ISSET(VIEW_MODE) && !main_list[i].viewok)
+
+ for (s = currshortcut; s != NULL && !keyhandled; s = s->next) {
+ if (kbinput == s->val ||
+ (s->misc1 && kbinput == s->misc1) ||
+ (s->misc2 && kbinput == s->misc2)) {
+ if (ISSET(VIEW_MODE) && !s->viewok)
print_view_warning();
else
- main_list[i].func();
+ s->func();
keyhandled = 1;
}
}
}
/* 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 kbinput = 0, j = 0, x = 0, xend;
+ int kbinput = 0, j = 0, x = 0, xend, slen;
int x_left = 0, inputlen, tabbed = 0;
char *inputbuf;
+ shortcut *t;
#ifndef DISABLE_TABCOMP
int shift = 0;
#endif
+ slen = length_of_list(s);
inputbuf = charalloc(strlen(def) + 1);
inputbuf[0] = 0;
#if !defined(DISABLE_HELP) || !defined(DISABLE_MOUSE)
currshortcut = s;
- currslen = slen;
#endif
/* Get the input! */
wrefresh(edit);
while ((kbinput = wgetch(bottomwin)) != 13) {
- for (j = 0; j <= slen - 1; j++) {
+ for (t = s; t != NULL; t = t->next) {
#ifdef DEBUG
fprintf(stderr, _("Aha! \'%c\' (%d)\n"), kbinput, kbinput);
#endif
- if (kbinput == s[j].val && kbinput < 32) {
+ if (kbinput == t->val && kbinput < 32) {
#ifndef DISABLE_HELP
/* Have to do this here, it would be too late to do it in statusq */
we hit a keystroke, GEEZ! */
answer = mallocstrcpy(answer, inputbuf);
free(inputbuf);
- return s[j].val;
+ return t->val;
}
}
xend = strlen(buf) + strlen(inputbuf);
}
default:
- for (j = 0; j <= slen - 1; j++) {
+ for (t = s; t != NULL; t = t->next) {
#ifdef DEBUG
fprintf(stderr, _("Aha! \'%c\' (%d)\n"), kbinput,
kbinput);
#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
just ungetch the letter and let it get caught
above cause that screws the keypad... */
answer = mallocstrcpy(answer, inputbuf);
free(inputbuf);
- return s[j].val;
+ return t->val;
}
}
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);
waddstr(bottomwin, keystroke);
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)
mvwaddstr(bottomwin, 2, 0, hblank);
}
-void bottombars(shortcut s[], int slen)
+void bottombars(shortcut *s)
{
int i, j, k;
char keystr[10];
+ shortcut *t;
+ int slen;
+
+ if (s == main_list)
+ slen = MAIN_VISIBLE;
+ else
+ slen = length_of_list(s);
if (ISSET(NO_HELP))
return;
/* Determine how many extra spaces are needed to fill the bottom of the screen */
if (slen < 2)
- k = COLS / 6 - 13;
+ k = COLS / 6;
else
- k = COLS / ((slen + (slen % 2)) / 2) - 13;
+ k = COLS / ((slen + (slen % 2)) / 2);
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)
- snprintf(keystr, 10, "^%c", s[i].val + 64);
+ wmove(bottomwin, 1, i * k);
+
+ if (t->val < 97)
+ snprintf(keystr, 10, "^%c", t->val + 64);
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++)
- waddch(bottomwin, ' ');
- }
+ if (t->next == NULL)
+ break;
+ t = t->next;
- wmove(bottomwin, 2, 0);
- for (i = 1; i <= slen - 1; i += 2) {
+ wmove(bottomwin, 2, i * k);
- if (s[i].val < 97)
- snprintf(keystr, 10, "^%c", s[i].val + 64);
+ if (t->val < 97)
+ snprintf(keystr, 10, "^%c", t->val + 64);
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++)
- waddch(bottomwin, ' ');
+ if (t->next == NULL)
+ break;
+ t = t->next;
+
}
#ifdef ENABLE_COLOR
*
* 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;
char foo[133];
- int ret;
+ int ret, slen;
#ifndef DISABLE_TABCOMP
int list = 0;
#endif
- bottombars(s, slen);
+ bottombars(s);
va_start(ap, msg);
vsnprintf(foo, 132, msg, ap);
#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
/* 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 */
- ret = nanogetstr(tabs, foo, def, s, slen, (strlen(foo) + 3), 0);
+ ret = nanogetstr(tabs, foo, def, s, (strlen(foo) + 3), 0);
#endif
#ifdef ENABLE_COLOR
wmove(bottomwin, 1, 0);
snprintf(shortstr, 3, " %c", yesstr[0]);
- onekey(shortstr, _("Yes"));
+ onekey(shortstr, _("Yes"), 16);
if (all) {
snprintf(shortstr, 3, " %c", allstr[0]);
- onekey(shortstr, _("All"));
+ onekey(shortstr, _("All"), 16);
}
wmove(bottomwin, 2, 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);
vsnprintf(foo, 132, msg, ap);
void display_main_list(void)
{
- bottombars(main_list, MAIN_VISIBLE);
+ bottombars(main_list);
}
int total_refresh(void)
ptr = help_text;
oldshortcut = currshortcut;
- oldslen = currslen;
currshortcut = help_list;
- currslen = HELP_LIST_LEN;
kp = keypad_on(edit, 1);
kp2 = keypad_on(bottomwin, 1);
no_help_flag = 1;
UNSET(NO_HELP);
window_init();
- bottombars(help_list, HELP_LIST_LEN);
+ bottombars(help_list);
} else
- bottombars(help_list, HELP_LIST_LEN);
+ bottombars(help_list);
do {
ptr = help_text;
kbinput != NANO_EXIT_FKEY);
currshortcut = oldshortcut;
- currslen = oldslen;
if (no_help_flag) {
blank_bottombars();
SET(NO_HELP);
window_init();
} else
- bottombars(currshortcut, currslen);
+ bottombars(currshortcut);
curs_set(1);
edit_refresh();
"Adam Rogoyski",
"Rob Siemborski",
"Rocco Corsi",
+ "David Lawrence Ramsey",
"Ken Tyler",
"Sven Guckes",
"Florian König",
"Joshua Jensen",
"Ryan Krebs",
"Albert Chin",
- "David Lawrence Ramsey",
"",
specialthx,
"Plattsburgh State University",