1/* $Id: global.c,v 1.223.2.1 2007/04/19 03:15:04 dolorous Exp $ */
2/**************************************************************************
3 *   global.c                                                             *
4 *                                                                        *
5 *   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 Chris Allegretta    *
6 *   Copyright (C) 2005, 2006, 2007 David Lawrence Ramsey                 *
7 *   This program is free software; you can redistribute it and/or modify *
8 *   it under the terms of the GNU General Public License as published by *
9 *   the Free Software Foundation; either version 2, or (at your option)  *
10 *   any later version.                                                   *
11 *                                                                        *
12 *   This program is distributed in the hope that it will be useful, but  *
13 *   WITHOUT ANY WARRANTY; without even the implied warranty of           *
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    *
15 *   General Public License for more details.                             *
16 *                                                                        *
17 *   You should have received a copy of the GNU General Public License    *
18 *   along with this program; if not, write to the Free Software          *
19 *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA            *
20 *   02110-1301, USA.                                                     *
21 *                                                                        *
22 **************************************************************************/
23
24#include "proto.h"
25
26/* Global variables. */
27#ifndef NANO_TINY
28sigjmp_buf jump_buf;
29	/* Used to return to either main() or the unjustify routine in
30	 * do_justify() after a SIGWINCH. */
31bool jump_buf_main = FALSE;
32	/* Have we set jump_buf so that we return to main() after a
33	 * SIGWINCH? */
34#endif
35
36#ifndef DISABLE_WRAPJUSTIFY
37ssize_t fill = 0;
38	/* The column where we will wrap lines. */
39ssize_t wrap_at = -CHARS_FROM_EOL;
40	/* The position where we will wrap lines.  fill is equal to this
41	 * if it's greater than zero, and equal to (COLS + this) if it
42	 * isn't. */
43#endif
44
45char *last_search = NULL;
46	/* The last string we searched for. */
47char *last_replace = NULL;
48	/* The last replacement string we searched for. */
49
50long flags = 0;
51	/* Our flag containing the states of all global options. */
52WINDOW *topwin;
53	/* The top portion of the window, where we display the version
54	 * number of nano, the name of the current file, and whether the
55	 * current file has been modified. */
56WINDOW *edit;
57	/* The middle portion of the window, i.e. the edit window, where
58	 * we display the current file we're editing. */
59WINDOW *bottomwin;
60	/* The bottom portion of the window, where we display statusbar
61	 * messages, the statusbar prompt, and a list of shortcuts. */
62int editwinrows = 0;
63	/* How many rows does the edit window take up? */
64
65filestruct *cutbuffer = NULL;
66	/* The buffer where we store cut text. */
67#ifndef DISABLE_JUSTIFY
68filestruct *jusbuffer = NULL;
69	/* The buffer where we store unjustified text. */
70#endif
71partition *filepart = NULL;
72	/* The partition where we store a portion of the current
73	 * file. */
74openfilestruct *openfile = NULL;
75	/* The list of all open file buffers. */
76
77#ifndef NANO_TINY
78char *matchbrackets = NULL;
79	/* The opening and closing brackets that can be found by bracket
80	 * searches. */
81#endif
82
83#if !defined(NANO_TINY) && defined(ENABLE_NANORC)
84char *whitespace = NULL;
85	/* The characters used when displaying the first characters of
86	 * tabs and spaces. */
87int whitespace_len[2];
88	/* The length of these characters. */
89#endif
90
91#ifndef DISABLE_JUSTIFY
92char *punct = NULL;
93	/* The closing punctuation that can end sentences. */
94char *brackets = NULL;
95	/* The closing brackets that can follow closing punctuation and
96	 * can end sentences. */
97char *quotestr = NULL;
98	/* The quoting string.  The default value is set in main(). */
99#ifdef HAVE_REGEX_H
100regex_t quotereg;
101	/* The compiled regular expression from the quoting string. */
102int quoterc;
103	/* Whether it was compiled successfully. */
104char *quoteerr = NULL;
105	/* The error message, if it didn't. */
106#else
107size_t quotelen;
108	/* The length of the quoting string in bytes. */
109#endif
110#endif
111
112char *answer = NULL;
113	/* The answer string used by the statusbar prompt. */
114
115ssize_t tabsize = -1;
116	/* The width of a tab in spaces.  The default value is set in
117	 * main(). */
118
119#ifndef NANO_TINY
120char *backup_dir = NULL;
121	/* The directory where we store backup files. */
122#endif
123#ifndef DISABLE_OPERATINGDIR
124char *operating_dir = NULL;
125	/* The relative path to the operating directory, which we can't
126	 * move outside of. */
127char *full_operating_dir = NULL;
128	/* The full path to it. */
129#endif
130
131#ifndef DISABLE_SPELLER
132char *alt_speller = NULL;
133	/* The command to use for the alternate spell checker. */
134#endif
135
136shortcut *main_list = NULL;
137	/* The main shortcut list. */
138shortcut *whereis_list = NULL;
139	/* The "Search" shortcut list. */
140shortcut *replace_list = NULL;
141	/* The "Search (to replace)" shortcut list. */
142shortcut *replace_list_2 = NULL;
143	/* The "Replace with" shortcut list. */
144shortcut *gotoline_list = NULL;
145	/* The "Enter line number, column number" shortcut list. */
146shortcut *writefile_list = NULL;
147	/* The "File Name to Write" shortcut list. */
148shortcut *insertfile_list = NULL;
149	/* The "File to insert" shortcut list. */
150#ifndef NANO_TINY
151shortcut *extcmd_list = NULL;
152	/* The "Command to execute" shortcut list. */
153#endif
154#ifndef DISABLE_HELP
155shortcut *help_list = NULL;
156	/* The help text shortcut list. */
157#endif
158#ifndef DISABLE_SPELLER
159shortcut *spell_list = NULL;
160	/* The internal spell checker shortcut list. */
161#endif
162#ifndef DISABLE_BROWSER
163shortcut *browser_list = NULL;
164	/* The file browser shortcut list. */
165shortcut *whereis_file_list = NULL;
166	/* The file browser "Search" shortcut list. */
167shortcut *gotodir_list = NULL;
168	/* The "Go To Directory" shortcut list. */
169#endif
170
171#ifdef ENABLE_COLOR
172syntaxtype *syntaxes = NULL;
173	/* The global list of color syntaxes. */
174char *syntaxstr = NULL;
175	/* The color syntax name specified on the command line. */
176#endif
177
178const shortcut *currshortcut;
179	/* The current shortcut list we're using. */
180#ifndef NANO_TINY
181toggle *toggles = NULL;
182	/* The global toggle list. */
183#endif
184
185#ifndef NANO_TINY
186filestruct *search_history = NULL;
187	/* The search string history list. */
188filestruct *searchage = NULL;
189	/* The top of the search string history list. */
190filestruct *searchbot = NULL;
191	/* The bottom of the search string history list. */
192filestruct *replace_history = NULL;
193	/* The replace string history list. */
194filestruct *replaceage = NULL;
195	/* The top of the replace string history list. */
196filestruct *replacebot = NULL;
197	/* The bottom of the replace string history list. */
198#endif
199
200/* Regular expressions. */
201#ifdef HAVE_REGEX_H
202regex_t search_regexp;
203	/* The compiled regular expression to use in searches. */
204regmatch_t regmatches[10];
205	/* The match positions for parenthetical subexpressions, 10
206	 * maximum, used in regular expression searches. */
207#endif
208
209int reverse_attr = A_REVERSE;
210	/* The curses attribute we use for reverse video. */
211
212char *homedir = NULL;
213	/* The user's home directory, from $HOME or /etc/passwd. */
214
215/* Return the number of entries in the shortcut list s. */
216size_t length_of_list(const shortcut *s)
217{
218    size_t i = 0;
219
220    for (; s != NULL; s = s->next)
221	i++;
222    return i;
223}
224
225/* Add a new shortcut to the end of the shortcut list. */
226void sc_init_one(shortcut **shortcutage, int ctrlval, const char *desc
227#ifndef DISABLE_HELP
228	, const char *help, bool blank_after
229#endif
230	, int metaval, int funcval, int miscval, bool view,
231	void (*func)(void))
232{
233    shortcut *s;
234
235    if (*shortcutage == NULL) {
236	*shortcutage = (shortcut *)nmalloc(sizeof(shortcut));
237	s = *shortcutage;
238    } else {
239	for (s = *shortcutage; s->next != NULL; s = s->next)
240	    ;
241	s->next = (shortcut *)nmalloc(sizeof(shortcut));
242	s = s->next;
243    }
244
245    s->ctrlval = ctrlval;
246    s->desc = (desc == NULL) ? "" : _(desc);
247#ifndef DISABLE_HELP
248    s->help = (help == NULL) ? "" : _(help);
249    s->blank_after = blank_after;
250#endif
251    s->metaval = metaval;
252    s->funcval = funcval;
253    s->miscval = miscval;
254    s->viewok = view;
255    s->func = func;
256    s->next = NULL;
257}
258
259/* Initialize all shortcut lists.  If unjustify is TRUE, replace the
260 * Uncut shortcut in the main shortcut list with UnJustify. */
261void shortcut_init(bool unjustify)
262{
263    /* TRANSLATORS: Try to keep this and following strings at most 10
264     * characters. */
265    const char *cancel_msg = N_("Cancel");
266    const char *get_help_msg = N_("Get Help");
267    const char *exit_msg = N_("Exit");
268    const char *whereis_msg = N_("Where Is");
269    const char *prev_page_msg = N_("Prev Page");
270    const char *next_page_msg = N_("Next Page");
271    const char *go_to_line_msg = N_("Go To Line");
272    /* TRANSLATORS: Try to keep this and previous strings at most 10
273     * characters. */
274    const char *replace_msg = N_("Replace");
275#ifndef NANO_TINY
276    /* TRANSLATORS: Try to keep this at most 12 characters. */
277    const char *whereis_next_msg = N_("WhereIs Next");
278#endif
279    /* TRANSLATORS: Try to keep this and following strings at most 10
280     * characters. */
281    const char *first_line_msg = N_("First Line");
282    const char *last_line_msg = N_("Last Line");
283#ifndef DISABLE_JUSTIFY
284    const char *beg_of_par_msg = N_("Beg of Par");
285    const char *end_of_par_msg = N_("End of Par");
286    const char *fulljstify_msg = N_("FullJstify");
287#endif
288    const char *refresh_msg = N_("Refresh");
289#ifndef NANO_TINY
290    const char *case_sens_msg = N_("Case Sens");
291    const char *backwards_msg = N_("Backwards");
292#endif
293#ifdef HAVE_REGEX_H
294    const char *regexp_msg = N_("Regexp");
295#endif
296#ifndef NANO_TINY
297    const char *prev_history_msg = N_("PrevHstory");
298    /* TRANSLATORS: Try to keep this and previous strings at most 10
299     * characters. */
300    const char *next_history_msg = N_("NextHstory");
301#ifdef ENABLE_MULTIBUFFER
302    /* TRANSLATORS: Try to keep this at most 16 characters. */
303    const char *new_buffer_msg = N_("New Buffer");
304#endif
305#endif
306#ifndef DISABLE_BROWSER
307    /* TRANSLATORS: Try to keep this at most 16 characters. */
308    const char *to_files_msg = N_("To Files");
309    /* TRANSLATORS: Try to keep this at most 12 characters. */
310    const char *first_file_msg = N_("First File");
311    /* TRANSLATORS: Try to keep this at most 12 characters. */
312    const char *last_file_msg = N_("Last File");
313#endif
314#ifndef DISABLE_HELP
315    const char *nano_cancel_msg = N_("Cancel the current function");
316    const char *nano_help_msg = N_("Display this help text");
317    const char *nano_exit_msg =
318#ifdef ENABLE_MULTIBUFFER
319	N_("Close the current file buffer / Exit from nano")
320#else
321   	N_("Exit from nano")
322#endif
323	;
324    const char *nano_writeout_msg =
325	N_("Write the current file to disk");
326    const char *nano_justify_msg = N_("Justify the current paragraph");
327    const char *nano_insert_msg =
328	N_("Insert another file into the current one");
329    const char *nano_whereis_msg =
330	N_("Search for a string or a regular expression");
331    const char *nano_prevpage_msg = N_("Move to the previous screen");
332    const char *nano_nextpage_msg = N_("Move to the next screen");
333    const char *nano_cut_msg =
334	N_("Cut the current line and store it in the cutbuffer");
335    const char *nano_uncut_msg =
336	N_("Uncut from the cutbuffer into the current line");
337    const char *nano_cursorpos_msg =
338	N_("Display the position of the cursor");
339    const char *nano_spell_msg =
340	N_("Invoke the spell checker, if available");
341    const char *nano_gotoline_msg = N_("Go to line and column number");
342    const char *nano_replace_msg =
343	N_("Replace a string or a regular expression");
344#ifndef NANO_TINY
345    const char *nano_mark_msg = N_("Mark text at the cursor position");
346    const char *nano_whereis_next_msg = N_("Repeat last search");
347    const char *nano_copy_msg =
348	N_("Copy the current line and store it in the cutbuffer");
349    const char *nano_indent_msg = N_("Indent the current line");
350    const char *nano_unindent_msg = N_("Unindent the current line");
351#endif
352    const char *nano_forward_msg = N_("Move forward one character");
353    const char *nano_back_msg = N_("Move back one character");
354#ifndef NANO_TINY
355    const char *nano_nextword_msg = N_("Move forward one word");
356    const char *nano_prevword_msg = N_("Move back one word");
357#endif
358    const char *nano_prevline_msg = N_("Move to the previous line");
359    const char *nano_nextline_msg = N_("Move to the next line");
360    const char *nano_home_msg =
361	N_("Move to the beginning of the current line");
362    const char *nano_end_msg =
363	N_("Move to the end of the current line");
364#ifndef DISABLE_JUSTIFY
365    const char *nano_parabegin_msg =
366	N_("Move to the beginning of the current paragraph");
367    const char *nano_paraend_msg =
368	N_("Move to the end of the current paragraph");
369#endif
370    const char *nano_firstline_msg =
371	N_("Move to the first line of the file");
372    const char *nano_lastline_msg =
373	N_("Move to the last line of the file");
374#ifndef NANO_TINY
375    const char *nano_bracket_msg = N_("Move to the matching bracket");
376    const char *nano_scrollup_msg =
377	N_("Scroll up one line without scrolling the cursor");
378    const char *nano_scrolldown_msg =
379	N_("Scroll down one line without scrolling the cursor");
380#endif
381#ifdef ENABLE_MULTIBUFFER
382    const char *nano_prevfile_msg =
383	N_("Switch to the previous file buffer");
384    const char *nano_nextfile_msg =
385	N_("Switch to the next file buffer");
386#endif
387    const char *nano_verbatim_msg =
388	N_("Insert the next keystroke verbatim");
389    const char *nano_tab_msg =
390	N_("Insert a tab at the cursor position");
391    const char *nano_enter_msg =
392	N_("Insert a newline at the cursor position");
393    const char *nano_delete_msg =
394	N_("Delete the character under the cursor");
395    const char *nano_backspace_msg =
396	N_("Delete the character to the left of the cursor");
397#ifndef NANO_TINY
398    const char *nano_cut_till_end_msg =
399	N_("Cut from the cursor position to the end of the file");
400#endif
401#ifndef DISABLE_JUSTIFY
402    const char *nano_fulljustify_msg = N_("Justify the entire file");
403#endif
404#ifndef NANO_TINY
405    const char *nano_wordcount_msg =
406	N_("Count the number of words, lines, and characters");
407#endif
408    const char *nano_refresh_msg =
409	N_("Refresh (redraw) the current screen");
410#ifndef NANO_TINY
411    const char *nano_case_msg =
412	N_("Toggle the case sensitivity of the search");
413    const char *nano_reverse_msg =
414	N_("Reverse the direction of the search");
415#endif
416#ifdef HAVE_REGEX_H
417    const char *nano_regexp_msg =
418	N_("Toggle the use of regular expressions");
419#endif
420#ifndef NANO_TINY
421    const char *nano_prev_history_msg =
422	N_("Recall the previous search/replace string");
423    const char *nano_next_history_msg =
424	N_("Recall the next search/replace string");
425#endif
426#ifndef DISABLE_BROWSER
427    const char *nano_tofiles_msg = N_("Go to file browser");
428#endif
429#ifndef NANO_TINY
430    const char *nano_dos_msg = N_("Toggle the use of DOS format");
431    const char *nano_mac_msg = N_("Toggle the use of Mac format");
432#endif
433    const char *nano_append_msg = N_("Toggle appending");
434    const char *nano_prepend_msg = N_("Toggle prepending");
435#ifndef NANO_TINY
436    const char *nano_backup_msg =
437	N_("Toggle backing up of the original file");
438    const char *nano_execute_msg = N_("Execute external command");
439#endif
440#if !defined(NANO_TINY) && defined(ENABLE_MULTIBUFFER)
441    const char *nano_multibuffer_msg =
442	N_("Toggle the use of a new buffer");
443#endif
444#ifndef DISABLE_BROWSER
445    const char *nano_exitbrowser_msg = N_("Exit from the file browser");
446    const char *nano_firstfile_msg =
447	N_("Go to the first file in the list");
448    const char *nano_lastfile_msg =
449	N_("Go to the last file in the list");
450    const char *nano_gotodir_msg = N_("Go to directory");
451#endif
452#endif /* !DISABLE_HELP */
453
454/* The following macro is to be used in calling sc_init_one().  The
455 * point is that sc_init_one() takes 10 arguments, unless DISABLE_HELP
456 * is defined, when the 4th and 5th ones should not be there. */
457#ifndef DISABLE_HELP
458#define IFSCHELP(help, blank, nextvar) help, blank, nextvar
459#else
460#define IFSCHELP(help, blank, nextvar) nextvar
461#endif
462
463    free_shortcutage(&main_list);
464
465    sc_init_one(&main_list, NANO_HELP_KEY, get_help_msg,
466	IFSCHELP(nano_help_msg, FALSE, NANO_NO_KEY), NANO_HELP_FKEY,
467	NANO_NO_KEY, VIEW,
468#ifndef DISABLE_HELP
469	do_help_void
470#else
471	nano_disabled_msg
472#endif
473	);
474
475    sc_init_one(&main_list, NANO_EXIT_KEY,
476#ifdef ENABLE_MULTIBUFFER
477	/* TRANSLATORS: Try to keep this at most 10 characters. */
478	openfile != NULL && openfile != openfile->next ? N_("Close") :
479#endif
480	exit_msg, IFSCHELP(nano_exit_msg, FALSE, NANO_NO_KEY),
481	NANO_EXIT_FKEY, NANO_NO_KEY, VIEW, do_exit);
482
483    /* TRANSLATORS: Try to keep this at most 10 characters. */
484    sc_init_one(&main_list, NANO_WRITEOUT_KEY, N_("WriteOut"),
485	IFSCHELP(nano_writeout_msg, FALSE, NANO_NO_KEY),
486	NANO_WRITEOUT_FKEY, NANO_NO_KEY, NOVIEW, do_writeout_void);
487
488    /* TRANSLATORS: Try to keep this at most 10 characters. */
489    sc_init_one(&main_list, NANO_JUSTIFY_KEY, N_("Justify"),
490	IFSCHELP(nano_justify_msg, TRUE, NANO_NO_KEY),
491	NANO_JUSTIFY_FKEY, NANO_NO_KEY, NOVIEW,
492#ifndef DISABLE_JUSTIFY
493	do_justify_void
494#else
495	nano_disabled_msg
496#endif
497	);
498
499    /* We allow inserting files in view mode if multibuffers are
500     * available, so that we can view multiple files.  If we're using
501     * restricted mode, inserting files is disabled, since it allows
502     * reading from or writing to files not specified on the command
503     * line. */
504    /* TRANSLATORS: Try to keep this at most 10 characters. */
505    sc_init_one(&main_list, NANO_INSERTFILE_KEY, N_("Read File"),
506	IFSCHELP(nano_insert_msg, FALSE, NANO_NO_KEY),
507	NANO_INSERTFILE_FKEY, NANO_NO_KEY,
508#ifdef ENABLE_MULTIBUFFER
509	VIEW
510#else
511	NOVIEW
512#endif
513	, !ISSET(RESTRICTED) ? do_insertfile_void : nano_disabled_msg);
514
515    sc_init_one(&main_list, NANO_WHEREIS_KEY, whereis_msg,
516	IFSCHELP(nano_whereis_msg, FALSE, NANO_NO_KEY),
517	NANO_WHEREIS_FKEY, NANO_NO_KEY, VIEW, do_search);
518
519    sc_init_one(&main_list, NANO_PREVPAGE_KEY, prev_page_msg,
520	IFSCHELP(nano_prevpage_msg, FALSE, NANO_NO_KEY),
521	NANO_PREVPAGE_FKEY, NANO_NO_KEY, VIEW, do_page_up);
522
523    sc_init_one(&main_list, NANO_NEXTPAGE_KEY, next_page_msg,
524	IFSCHELP(nano_nextpage_msg, TRUE, NANO_NO_KEY),
525	NANO_NEXTPAGE_FKEY, NANO_NO_KEY, VIEW, do_page_down);
526
527    /* TRANSLATORS: Try to keep this at most 10 characters. */
528    sc_init_one(&main_list, NANO_CUT_KEY, N_("Cut Text"),
529	IFSCHELP(nano_cut_msg, FALSE, NANO_NO_KEY), NANO_CUT_FKEY,
530	NANO_NO_KEY, NOVIEW, do_cut_text_void);
531
532    if (unjustify)
533	/* TRANSLATORS: Try to keep this at most 10 characters. */
534	sc_init_one(&main_list, NANO_UNJUSTIFY_KEY, N_("UnJustify"),
535		IFSCHELP(NULL, FALSE, NANO_NO_KEY), NANO_UNJUSTIFY_FKEY,
536		NANO_NO_KEY, NOVIEW, NULL);
537    else
538	/* TRANSLATORS: Try to keep this at most 10 characters. */
539	sc_init_one(&main_list, NANO_UNCUT_KEY, N_("UnCut Text"),
540		IFSCHELP(nano_uncut_msg, FALSE, NANO_NO_KEY),
541		NANO_UNCUT_FKEY, NANO_NO_KEY, NOVIEW, do_uncut_text);
542
543    /* TRANSLATORS: Try to keep this at most 10 characters. */
544    sc_init_one(&main_list, NANO_CURSORPOS_KEY, N_("Cur Pos"),
545	IFSCHELP(nano_cursorpos_msg, FALSE, NANO_NO_KEY),
546	NANO_CURSORPOS_FKEY, NANO_NO_KEY, VIEW, do_cursorpos_void);
547
548    /* If we're using restricted mode, spell checking is disabled
549     * because it allows reading from or writing to files not specified
550     * on the command line. */
551    /* TRANSLATORS: Try to keep this at most 10 characters. */
552    sc_init_one(&main_list, NANO_SPELL_KEY, N_("To Spell"),
553	IFSCHELP(nano_spell_msg, TRUE, NANO_NO_KEY), NANO_SPELL_FKEY,
554	NANO_NO_KEY, NOVIEW,
555#ifndef DISABLE_SPELLER
556	!ISSET(RESTRICTED) ? do_spell :
557#endif
558	nano_disabled_msg);
559
560    sc_init_one(&main_list, NANO_GOTOLINE_KEY, go_to_line_msg,
561	IFSCHELP(nano_gotoline_msg, FALSE, NANO_GOTOLINE_METAKEY),
562	NANO_GOTOLINE_FKEY, NANO_NO_KEY, VIEW,
563	do_gotolinecolumn_void);
564
565    sc_init_one(&main_list, NANO_REPLACE_KEY, replace_msg
566#ifndef NANO_TINY
567	, IFSCHELP(nano_replace_msg, FALSE, NANO_REPLACE_METAKEY)
568#else
569	, IFSCHELP(nano_replace_msg, TRUE, NANO_REPLACE_METAKEY)
570#endif
571	, NANO_REPLACE_FKEY, NANO_NO_KEY, NOVIEW, do_replace);
572
573#ifndef NANO_TINY
574    sc_init_one(&main_list, NANO_MARK_KEY, N_("Mark Text"),
575	IFSCHELP(nano_mark_msg, FALSE, NANO_MARK_METAKEY),
576	NANO_MARK_FKEY, NANO_NO_KEY, VIEW, do_mark);
577
578    sc_init_one(&main_list, NANO_NO_KEY, whereis_next_msg,
579	IFSCHELP(nano_whereis_next_msg, TRUE, NANO_WHEREIS_NEXT_KEY),
580	NANO_WHEREIS_NEXT_FKEY, NANO_NO_KEY, VIEW, do_research);
581
582    sc_init_one(&main_list, NANO_NO_KEY, N_("Copy Text"),
583	IFSCHELP(nano_copy_msg, FALSE, NANO_COPY_KEY), NANO_NO_KEY,
584	NANO_COPY_METAKEY, NOVIEW, do_copy_text);
585
586    sc_init_one(&main_list, NANO_NO_KEY, N_("Indent Text"),
587	IFSCHELP(nano_indent_msg, FALSE, NANO_INDENT_KEY), NANO_NO_KEY,
588	NANO_NO_KEY, NOVIEW, do_indent_void);
589
590    sc_init_one(&main_list, NANO_NO_KEY, N_("Unindent Text"),
591	IFSCHELP(nano_unindent_msg, TRUE, NANO_UNINDENT_KEY),
592	NANO_NO_KEY, NANO_NO_KEY, NOVIEW, do_unindent);
593#endif
594
595    sc_init_one(&main_list, NANO_FORWARD_KEY, N_("Forward"),
596	IFSCHELP(nano_forward_msg, FALSE, NANO_NO_KEY), NANO_NO_KEY,
597	NANO_NO_KEY, VIEW, do_right);
598
599    sc_init_one(&main_list, NANO_BACK_KEY, N_("Back"),
600	IFSCHELP(nano_back_msg, FALSE, NANO_NO_KEY), NANO_NO_KEY,
601	NANO_NO_KEY, VIEW, do_left);
602
603#ifndef NANO_TINY
604    sc_init_one(&main_list, NANO_NEXTWORD_KEY, N_("Next Word"),
605	IFSCHELP(nano_nextword_msg, FALSE, NANO_NO_KEY), NANO_NO_KEY,
606	NANO_NO_KEY, VIEW, do_next_word_void);
607
608    sc_init_one(&main_list, NANO_NO_KEY, N_("Prev Word"),
609	IFSCHELP(nano_prevword_msg, FALSE, NANO_PREVWORD_KEY),
610	NANO_NO_KEY, NANO_NO_KEY, VIEW, do_prev_word_void);
611#endif
612
613    sc_init_one(&main_list, NANO_PREVLINE_KEY, N_("Prev Line"),
614	IFSCHELP(nano_prevline_msg, FALSE, NANO_NO_KEY), NANO_NO_KEY,
615	NANO_NO_KEY, VIEW, do_up_void);
616
617    sc_init_one(&main_list, NANO_NEXTLINE_KEY, N_("Next Line"),
618	IFSCHELP(nano_nextline_msg, TRUE, NANO_NO_KEY), NANO_NO_KEY,
619	NANO_NO_KEY, VIEW, do_down_void);
620
621    sc_init_one(&main_list, NANO_HOME_KEY, N_("Home"),
622	IFSCHELP(nano_home_msg, FALSE, NANO_NO_KEY), NANO_NO_KEY,
623	NANO_NO_KEY, VIEW, do_home);
624
625    sc_init_one(&main_list, NANO_END_KEY, N_("End"),
626	IFSCHELP(nano_end_msg, FALSE, NANO_NO_KEY), NANO_NO_KEY,
627	NANO_NO_KEY, VIEW, do_end);
628
629#ifndef DISABLE_JUSTIFY
630    sc_init_one(&main_list, NANO_NO_KEY, beg_of_par_msg,
631	IFSCHELP(nano_parabegin_msg, FALSE, NANO_PARABEGIN_METAKEY),
632	NANO_NO_KEY, NANO_PARABEGIN_METAKEY2, VIEW, do_para_begin_void);
633
634    sc_init_one(&main_list, NANO_NO_KEY, end_of_par_msg,
635	IFSCHELP(nano_paraend_msg, FALSE, NANO_PARAEND_METAKEY),
636	NANO_NO_KEY, NANO_PARAEND_METAKEY2, VIEW, do_para_end_void);
637#endif
638
639    sc_init_one(&main_list, NANO_NO_KEY, first_line_msg,
640	IFSCHELP(nano_firstline_msg, FALSE, NANO_FIRSTLINE_METAKEY),
641	NANO_NO_KEY, NANO_FIRSTLINE_METAKEY2, VIEW, do_first_line);
642
643    sc_init_one(&main_list, NANO_NO_KEY, last_line_msg,
644	IFSCHELP(nano_lastline_msg, TRUE, NANO_LASTLINE_METAKEY),
645	NANO_NO_KEY, NANO_LASTLINE_METAKEY2, VIEW, do_last_line);
646
647#ifndef NANO_TINY
648    sc_init_one(&main_list, NANO_NO_KEY, N_("Find Other Bracket"),
649	IFSCHELP(nano_bracket_msg, FALSE, NANO_BRACKET_KEY),
650	NANO_NO_KEY, NANO_NO_KEY, VIEW, do_find_bracket);
651
652    sc_init_one(&main_list, NANO_NO_KEY, N_("Scroll Up"),
653	IFSCHELP(nano_scrollup_msg, FALSE, NANO_SCROLLUP_KEY),
654	NANO_NO_KEY, NANO_SCROLLUP_METAKEY, VIEW, do_scroll_up);
655
656    sc_init_one(&main_list, NANO_NO_KEY, N_("Scroll Down"),
657	IFSCHELP(nano_scrolldown_msg, TRUE, NANO_SCROLLDOWN_KEY),
658	NANO_NO_KEY, NANO_SCROLLDOWN_METAKEY, VIEW, do_scroll_down);
659#endif
660
661#ifdef ENABLE_MULTIBUFFER
662    sc_init_one(&main_list, NANO_NO_KEY, N_("Previous File"),
663	IFSCHELP(nano_prevfile_msg, FALSE, NANO_PREVFILE_KEY),
664	NANO_NO_KEY, NANO_PREVFILE_METAKEY, VIEW,
665	switch_to_prev_buffer_void);
666
667    sc_init_one(&main_list, NANO_NO_KEY, N_("Next File"),
668	IFSCHELP(nano_nextfile_msg, TRUE, NANO_NEXTFILE_KEY),
669	NANO_NO_KEY, NANO_NEXTFILE_METAKEY, VIEW,
670	switch_to_next_buffer_void);
671#endif
672
673    sc_init_one(&main_list, NANO_NO_KEY, N_("Verbatim Input"),
674	IFSCHELP(nano_verbatim_msg, FALSE, NANO_VERBATIM_KEY),
675	NANO_NO_KEY, NANO_NO_KEY, NOVIEW, do_verbatim_input);
676
677    sc_init_one(&main_list, NANO_TAB_KEY, N_("Tab"),
678	IFSCHELP(nano_tab_msg, FALSE, NANO_NO_KEY), NANO_NO_KEY,
679	NANO_NO_KEY, NOVIEW, do_tab);
680
681    sc_init_one(&main_list, NANO_ENTER_KEY, N_("Enter"),
682	IFSCHELP(nano_enter_msg, FALSE, NANO_NO_KEY), NANO_NO_KEY,
683	NANO_NO_KEY, NOVIEW, do_enter);
684
685    sc_init_one(&main_list, NANO_DELETE_KEY, N_("Delete"),
686	IFSCHELP(nano_delete_msg, FALSE, NANO_NO_KEY), NANO_NO_KEY,
687	NANO_NO_KEY, NOVIEW, do_delete);
688
689    sc_init_one(&main_list, NANO_BACKSPACE_KEY, N_("Backspace")
690#ifndef NANO_TINY
691	, IFSCHELP(nano_backspace_msg, FALSE, NANO_NO_KEY)
692#else
693	, IFSCHELP(nano_backspace_msg, TRUE, NANO_NO_KEY)
694#endif
695	, NANO_NO_KEY, NANO_NO_KEY, NOVIEW, do_backspace);
696
697#ifndef NANO_TINY
698    sc_init_one(&main_list, NANO_NO_KEY, N_("CutTillEnd"),
699	IFSCHELP(nano_cut_till_end_msg, TRUE, NANO_CUTTILLEND_METAKEY),
700	NANO_NO_KEY, NANO_NO_KEY, NOVIEW, do_cut_till_end);
701#endif
702
703#ifndef DISABLE_JUSTIFY
704    sc_init_one(&main_list, NANO_NO_KEY, fulljstify_msg,
705	IFSCHELP(nano_fulljustify_msg, FALSE, NANO_FULLJUSTIFY_METAKEY),
706	NANO_NO_KEY, NANO_NO_KEY, NOVIEW, do_full_justify);
707#endif
708
709#ifndef NANO_TINY
710    sc_init_one(&main_list, NANO_NO_KEY, N_("Word Count"),
711	IFSCHELP(nano_wordcount_msg, FALSE, NANO_WORDCOUNT_KEY),
712	NANO_NO_KEY, NANO_NO_KEY, VIEW, do_wordlinechar_count);
713#endif
714
715    sc_init_one(&main_list, NANO_REFRESH_KEY, refresh_msg
716#ifndef NANO_TINY
717	, IFSCHELP(nano_refresh_msg, TRUE, NANO_NO_KEY)
718#else
719	, IFSCHELP(nano_refresh_msg, FALSE, NANO_NO_KEY)
720#endif
721	, NANO_NO_KEY, NANO_NO_KEY, VIEW, total_refresh);
722
723    free_shortcutage(&whereis_list);
724
725    sc_init_one(&whereis_list, NANO_HELP_KEY, get_help_msg,
726	IFSCHELP(nano_help_msg, FALSE, NANO_NO_KEY), NANO_HELP_FKEY,
727	NANO_NO_KEY, VIEW,
728#ifndef DISABLE_HELP
729	do_help_void
730#else
731	nano_disabled_msg
732#endif
733	);
734
735    sc_init_one(&whereis_list, NANO_CANCEL_KEY, cancel_msg,
736	IFSCHELP(nano_cancel_msg, FALSE, NANO_NO_KEY), NANO_NO_KEY,
737	NANO_NO_KEY, VIEW, NULL);
738
739    sc_init_one(&whereis_list, NANO_FIRSTLINE_KEY, first_line_msg,
740	IFSCHELP(nano_firstline_msg, FALSE, NANO_FIRSTLINE_METAKEY),
741	NANO_FIRSTLINE_FKEY, NANO_FIRSTLINE_METAKEY2, VIEW,
742	do_first_line);
743
744    sc_init_one(&whereis_list, NANO_LASTLINE_KEY, last_line_msg,
745	IFSCHELP(nano_lastline_msg, FALSE, NANO_LASTLINE_METAKEY),
746	NANO_LASTLINE_FKEY, NANO_LASTLINE_METAKEY2, VIEW, do_last_line);
747
748    sc_init_one(&whereis_list, NANO_TOOTHERSEARCH_KEY, replace_msg,
749	IFSCHELP(nano_replace_msg, FALSE, NANO_NO_KEY),
750	NANO_REPLACE_FKEY, NANO_NO_KEY, VIEW, NULL);
751
752    sc_init_one(&whereis_list, NANO_TOGOTOLINE_KEY, go_to_line_msg,
753	IFSCHELP(nano_gotoline_msg, FALSE, NANO_NO_KEY),
754	NANO_GOTOLINE_FKEY, NANO_NO_KEY, VIEW, NULL);
755
756#ifndef DISABLE_JUSTIFY
757    sc_init_one(&whereis_list, NANO_PARABEGIN_KEY, beg_of_par_msg,
758	IFSCHELP(nano_parabegin_msg, FALSE, NANO_PARABEGIN_METAKEY),
759	NANO_NO_KEY, NANO_PARABEGIN_METAKEY2, VIEW, do_para_begin_void);
760
761    sc_init_one(&whereis_list, NANO_PARAEND_KEY, end_of_par_msg,
762	IFSCHELP(nano_paraend_msg, FALSE, NANO_PARAEND_METAKEY),
763	NANO_NO_KEY, NANO_PARAEND_METAKEY2, VIEW, do_para_end_void);
764#endif
765
766#ifndef NANO_TINY
767    sc_init_one(&whereis_list, NANO_NO_KEY, case_sens_msg,
768	IFSCHELP(nano_case_msg, FALSE, TOGGLE_CASE_KEY), NANO_NO_KEY,
769	NANO_NO_KEY, VIEW, NULL);
770
771    sc_init_one(&whereis_list, NANO_NO_KEY, backwards_msg,
772	IFSCHELP(nano_reverse_msg, FALSE, TOGGLE_BACKWARDS_KEY),
773	NANO_NO_KEY, NANO_NO_KEY, VIEW, NULL);
774#endif
775
776#ifdef HAVE_REGEX_H
777    sc_init_one(&whereis_list, NANO_NO_KEY, regexp_msg,
778	IFSCHELP(nano_regexp_msg, FALSE, NANO_REGEXP_KEY), NANO_NO_KEY,
779	NANO_NO_KEY, VIEW, NULL);
780#endif
781
782#ifndef NANO_TINY
783    sc_init_one(&whereis_list, NANO_PREVLINE_KEY, prev_history_msg,
784	IFSCHELP(nano_prev_history_msg, FALSE, NANO_NO_KEY),
785	NANO_NO_KEY, NANO_NO_KEY, VIEW, NULL);
786
787    sc_init_one(&whereis_list, NANO_NEXTLINE_KEY, next_history_msg,
788	IFSCHELP(nano_next_history_msg, FALSE, NANO_NO_KEY),
789	NANO_NO_KEY, NANO_NO_KEY, VIEW, NULL);
790#endif
791
792#ifndef DISABLE_JUSTIFY
793    sc_init_one(&whereis_list, NANO_FULLJUSTIFY_KEY, fulljstify_msg,
794	IFSCHELP(nano_fulljustify_msg, FALSE, NANO_FULLJUSTIFY_METAKEY),
795	NANO_NO_KEY, NANO_NO_KEY, NOVIEW, do_full_justify);
796#endif
797
798    free_shortcutage(&replace_list);
799
800    sc_init_one(&replace_list, NANO_HELP_KEY, get_help_msg,
801	IFSCHELP(nano_help_msg, FALSE, NANO_NO_KEY), NANO_HELP_FKEY,
802	NANO_NO_KEY, VIEW,
803#ifndef DISABLE_HELP
804	do_help_void
805#else
806	nano_disabled_msg
807#endif
808	);
809
810    sc_init_one(&replace_list, NANO_CANCEL_KEY, cancel_msg,
811	IFSCHELP(nano_cancel_msg, FALSE, NANO_NO_KEY), NANO_NO_KEY,
812	NANO_NO_KEY, VIEW, NULL);
813
814    sc_init_one(&replace_list, NANO_FIRSTLINE_KEY, first_line_msg,
815	IFSCHELP(nano_firstline_msg, FALSE, NANO_FIRSTLINE_METAKEY),
816	NANO_FIRSTLINE_FKEY, NANO_FIRSTLINE_METAKEY2, VIEW,
817	do_first_line);
818
819    sc_init_one(&replace_list, NANO_LASTLINE_KEY, last_line_msg,
820	IFSCHELP(nano_lastline_msg, FALSE, NANO_LASTLINE_METAKEY),
821	NANO_LASTLINE_FKEY, NANO_LASTLINE_METAKEY2, VIEW, do_last_line);
822
823    /* TRANSLATORS: Try to keep this at most 12 characters. */
824    sc_init_one(&replace_list, NANO_TOOTHERSEARCH_KEY, N_("No Replace"),
825	IFSCHELP(nano_whereis_msg, FALSE, NANO_NO_KEY),
826	NANO_REPLACE_FKEY, NANO_NO_KEY, VIEW, NULL);
827
828#ifndef NANO_TINY
829    sc_init_one(&replace_list, NANO_NO_KEY, case_sens_msg,
830	IFSCHELP(nano_case_msg, FALSE, TOGGLE_CASE_KEY), NANO_NO_KEY,
831	NANO_NO_KEY, VIEW, NULL);
832
833    sc_init_one(&replace_list, NANO_NO_KEY, backwards_msg,
834	IFSCHELP(nano_reverse_msg, FALSE, TOGGLE_BACKWARDS_KEY),
835	NANO_NO_KEY, NANO_NO_KEY, VIEW, NULL);
836#endif
837
838#ifdef HAVE_REGEX_H
839    sc_init_one(&replace_list, NANO_NO_KEY, regexp_msg,
840	IFSCHELP(nano_regexp_msg, FALSE, NANO_REGEXP_KEY), NANO_NO_KEY,
841	NANO_NO_KEY, VIEW, NULL);
842#endif
843
844#ifndef NANO_TINY
845    sc_init_one(&replace_list, NANO_PREVLINE_KEY, prev_history_msg,
846	IFSCHELP(nano_prev_history_msg, FALSE, NANO_NO_KEY),
847	NANO_NO_KEY, NANO_NO_KEY, VIEW, NULL);
848
849    sc_init_one(&replace_list, NANO_NEXTLINE_KEY, next_history_msg,
850	IFSCHELP(nano_next_history_msg, FALSE, NANO_NO_KEY),
851	NANO_NO_KEY, NANO_NO_KEY, VIEW, NULL);
852#endif
853
854    free_shortcutage(&replace_list_2);
855
856    sc_init_one(&replace_list_2, NANO_HELP_KEY, get_help_msg,
857	IFSCHELP(nano_help_msg, FALSE, NANO_NO_KEY), NANO_HELP_FKEY,
858	NANO_NO_KEY, VIEW,
859#ifndef DISABLE_HELP
860	do_help_void
861#else
862	nano_disabled_msg
863#endif
864	);
865
866    sc_init_one(&replace_list_2, NANO_CANCEL_KEY, cancel_msg,
867	IFSCHELP(nano_cancel_msg, FALSE, NANO_NO_KEY), NANO_NO_KEY,
868	NANO_NO_KEY, VIEW, NULL);
869
870    sc_init_one(&replace_list_2, NANO_FIRSTLINE_KEY, first_line_msg,
871	IFSCHELP(nano_firstline_msg, FALSE, NANO_FIRSTLINE_METAKEY),
872	NANO_FIRSTLINE_FKEY, NANO_FIRSTLINE_METAKEY2, VIEW,
873	do_first_line);
874
875    sc_init_one(&replace_list_2, NANO_LASTLINE_KEY, last_line_msg,
876	IFSCHELP(nano_lastline_msg, FALSE, NANO_LASTLINE_METAKEY),
877	NANO_LASTLINE_FKEY, NANO_LASTLINE_METAKEY2, VIEW, do_last_line);
878
879#ifndef NANO_TINY
880    sc_init_one(&replace_list_2, NANO_PREVLINE_KEY, prev_history_msg,
881	IFSCHELP(nano_prev_history_msg, FALSE, NANO_NO_KEY),
882	NANO_NO_KEY, NANO_NO_KEY, VIEW, NULL);
883
884    sc_init_one(&replace_list_2, NANO_NEXTLINE_KEY, next_history_msg,
885	IFSCHELP(nano_next_history_msg, FALSE, NANO_NO_KEY),
886	NANO_NO_KEY, NANO_NO_KEY, VIEW, NULL);
887#endif
888
889    free_shortcutage(&gotoline_list);
890
891    sc_init_one(&gotoline_list, NANO_HELP_KEY, get_help_msg,
892	IFSCHELP(nano_help_msg, FALSE, NANO_NO_KEY), NANO_HELP_FKEY,
893	NANO_NO_KEY, VIEW,
894#ifndef DISABLE_HELP
895	do_help_void
896#else
897	nano_disabled_msg
898#endif
899	);
900
901    sc_init_one(&gotoline_list, NANO_CANCEL_KEY, cancel_msg,
902	IFSCHELP(nano_cancel_msg, FALSE, NANO_NO_KEY), NANO_NO_KEY,
903	NANO_NO_KEY, VIEW, NULL);
904
905    sc_init_one(&gotoline_list, NANO_FIRSTLINE_KEY, first_line_msg,
906	IFSCHELP(nano_firstline_msg, FALSE, NANO_FIRSTLINE_METAKEY),
907	NANO_FIRSTLINE_FKEY, NANO_FIRSTLINE_METAKEY2, VIEW,
908	do_first_line);
909
910    sc_init_one(&gotoline_list, NANO_LASTLINE_KEY, last_line_msg,
911	IFSCHELP(nano_lastline_msg, FALSE, NANO_LASTLINE_METAKEY),
912	NANO_LASTLINE_FKEY, NANO_LASTLINE_METAKEY2, VIEW, do_last_line);
913
914    sc_init_one(&gotoline_list, NANO_TOOTHERWHEREIS_KEY,
915	N_("Go To Text"), IFSCHELP(nano_whereis_msg, FALSE,
916	NANO_NO_KEY), NANO_NO_KEY, NANO_NO_KEY, VIEW, NULL);
917
918    free_shortcutage(&writefile_list);
919
920    sc_init_one(&writefile_list, NANO_HELP_KEY, get_help_msg,
921	IFSCHELP(nano_help_msg, FALSE, NANO_NO_KEY), NANO_HELP_FKEY,
922	NANO_NO_KEY, VIEW,
923#ifndef DISABLE_HELP
924	do_help_void
925#else
926	nano_disabled_msg
927#endif
928	);
929
930    sc_init_one(&writefile_list, NANO_CANCEL_KEY, cancel_msg,
931	IFSCHELP(nano_cancel_msg, FALSE, NANO_NO_KEY), NANO_NO_KEY,
932	NANO_NO_KEY, VIEW, NULL);
933
934#ifndef DISABLE_BROWSER
935    /* If we're using restricted mode, the file browser is disabled.
936     * It's useless since inserting files is disabled. */
937    if (!ISSET(RESTRICTED))
938	sc_init_one(&writefile_list, NANO_TOFILES_KEY, to_files_msg,
939		IFSCHELP(nano_tofiles_msg, FALSE, NANO_NO_KEY),
940		NANO_NO_KEY, NANO_NO_KEY, NOVIEW, NULL);
941#endif
942
943#ifndef NANO_TINY
944    /* If we're using restricted mode, the DOS format, Mac format,
945     * append, prepend, and backup toggles are disabled.  The first and
946     * second are useless since inserting files is disabled, the third
947     * and fourth are disabled because they allow writing to files not
948     * specified on the command line, and the fifth is useless since
949     * backups are disabled. */
950    if (!ISSET(RESTRICTED))
951	/* TRANSLATORS: Try to keep this at most 16 characters. */
952	sc_init_one(&writefile_list, NANO_NO_KEY, N_("DOS Format"),
953		IFSCHELP(nano_dos_msg, FALSE, TOGGLE_DOS_KEY),
954		NANO_NO_KEY, NANO_NO_KEY, NOVIEW, NULL);
955
956    if (!ISSET(RESTRICTED))
957	/* TRANSLATORS: Try to keep this at most 16 characters. */
958	sc_init_one(&writefile_list, NANO_NO_KEY, N_("Mac Format"),
959		IFSCHELP(nano_mac_msg, FALSE, TOGGLE_MAC_KEY),
960		NANO_NO_KEY, NANO_NO_KEY, NOVIEW, NULL);
961#endif
962
963    if (!ISSET(RESTRICTED))
964	/* TRANSLATORS: Try to keep this at most 16 characters. */
965	sc_init_one(&writefile_list, NANO_NO_KEY, N_("Append"),
966		IFSCHELP(nano_append_msg, FALSE, NANO_APPEND_KEY),
967		NANO_NO_KEY, NANO_NO_KEY, NOVIEW, NULL);
968
969    if (!ISSET(RESTRICTED))
970	/* TRANSLATORS: Try to keep this at most 16 characters. */
971	sc_init_one(&writefile_list, NANO_NO_KEY, N_("Prepend"),
972		IFSCHELP(nano_prepend_msg, FALSE, NANO_PREPEND_KEY),
973		NANO_NO_KEY, NANO_NO_KEY, NOVIEW, NULL);
974
975#ifndef NANO_TINY
976    if (!ISSET(RESTRICTED))
977	/* TRANSLATORS: Try to keep this at most 16 characters. */
978	sc_init_one(&writefile_list, NANO_NO_KEY, N_("Backup File"),
979		IFSCHELP(nano_backup_msg, FALSE, TOGGLE_BACKUP_KEY),
980		NANO_NO_KEY, NANO_NO_KEY, NOVIEW, NULL);
981#endif
982
983    free_shortcutage(&insertfile_list);
984
985    sc_init_one(&insertfile_list, NANO_HELP_KEY, get_help_msg,
986	IFSCHELP(nano_help_msg, FALSE, NANO_NO_KEY), NANO_HELP_FKEY,
987	NANO_NO_KEY, VIEW,
988#ifndef DISABLE_HELP
989	do_help_void
990#else
991	nano_disabled_msg
992#endif
993	);
994
995    sc_init_one(&insertfile_list, NANO_CANCEL_KEY, cancel_msg,
996	IFSCHELP(nano_cancel_msg, FALSE, NANO_NO_KEY), NANO_NO_KEY,
997	NANO_NO_KEY, VIEW, NULL);
998
999#ifndef DISABLE_BROWSER
1000    /* If we're using restricted mode, the file browser is disabled.
1001     * It's useless since inserting files is disabled. */
1002    if (!ISSET(RESTRICTED))
1003	sc_init_one(&insertfile_list, NANO_TOFILES_KEY, to_files_msg,
1004		IFSCHELP(nano_tofiles_msg, FALSE, NANO_NO_KEY),
1005		NANO_NO_KEY, NANO_NO_KEY, NOVIEW, NULL);
1006#endif
1007
1008#ifndef NANO_TINY
1009    /* If we're using restricted mode, command execution is disabled.
1010     * It's useless since inserting files is disabled. */
1011    if (!ISSET(RESTRICTED))
1012	sc_init_one(&insertfile_list, NANO_TOOTHERINSERT_KEY,
1013		/* TRANSLATORS: Try to keep this at most 22
1014		 * characters. */
1015		N_("Execute Command"), IFSCHELP(nano_execute_msg, FALSE,
1016		NANO_NO_KEY), NANO_NO_KEY, NANO_NO_KEY, NOVIEW, NULL);
1017
1018#ifdef ENABLE_MULTIBUFFER
1019    /* If we're using restricted mode, the multibuffer toggle is
1020     * disabled.  It's useless since inserting files is disabled. */
1021    if (!ISSET(RESTRICTED))
1022	sc_init_one(&insertfile_list, NANO_NO_KEY, new_buffer_msg,
1023		IFSCHELP(nano_multibuffer_msg, FALSE,
1024		TOGGLE_MULTIBUFFER_KEY), NANO_NO_KEY, NANO_NO_KEY,
1025		NOVIEW, NULL);
1026#endif
1027#endif
1028
1029#ifndef NANO_TINY
1030    free_shortcutage(&extcmd_list);
1031
1032    sc_init_one(&extcmd_list, NANO_HELP_KEY, get_help_msg,
1033	IFSCHELP(nano_help_msg, FALSE, NANO_NO_KEY), NANO_HELP_FKEY,
1034	NANO_NO_KEY, VIEW,
1035#ifndef DISABLE_HELP
1036	do_help_void
1037#else
1038	nano_disabled_msg
1039#endif
1040	);
1041
1042    sc_init_one(&extcmd_list, NANO_CANCEL_KEY, cancel_msg,
1043	IFSCHELP(nano_cancel_msg, FALSE, NANO_NO_KEY), NANO_NO_KEY,
1044	NANO_NO_KEY, VIEW, NULL);
1045
1046    sc_init_one(&extcmd_list, NANO_TOOTHERINSERT_KEY, N_("Insert File"),
1047	IFSCHELP(nano_insert_msg, FALSE, NANO_NO_KEY), NANO_NO_KEY,
1048	NANO_NO_KEY, VIEW, NULL);
1049
1050#ifdef ENABLE_MULTIBUFFER
1051    sc_init_one(&extcmd_list, NANO_NO_KEY, new_buffer_msg,
1052	IFSCHELP(nano_multibuffer_msg, FALSE, TOGGLE_MULTIBUFFER_KEY),
1053	NANO_NO_KEY, NANO_NO_KEY, NOVIEW, NULL);
1054#endif
1055#endif
1056
1057#ifndef DISABLE_HELP
1058    free_shortcutage(&help_list);
1059
1060    sc_init_one(&help_list, NANO_REFRESH_KEY, refresh_msg,
1061	IFSCHELP(nano_refresh_msg, FALSE, NANO_NO_KEY), NANO_NO_KEY,
1062	NANO_NO_KEY, VIEW, NULL);
1063
1064    sc_init_one(&help_list, NANO_EXIT_KEY, exit_msg,
1065	IFSCHELP(nano_exit_msg, FALSE, NANO_NO_KEY), NANO_EXIT_FKEY,
1066	NANO_NO_KEY, VIEW, NULL);
1067
1068    sc_init_one(&help_list, NANO_PREVPAGE_KEY, prev_page_msg,
1069	IFSCHELP(nano_prevpage_msg, FALSE, NANO_NO_KEY),
1070	NANO_PREVPAGE_FKEY, NANO_NO_KEY, VIEW, NULL);
1071
1072    sc_init_one(&help_list, NANO_NEXTPAGE_KEY, next_page_msg,
1073	IFSCHELP(nano_nextpage_msg, FALSE, NANO_NO_KEY),
1074	NANO_NEXTPAGE_FKEY, NANO_NO_KEY, VIEW, NULL);
1075
1076    sc_init_one(&help_list, NANO_PREVLINE_KEY, N_("Prev Line"),
1077	IFSCHELP(nano_prevline_msg, FALSE, NANO_NO_KEY), NANO_NO_KEY,
1078	NANO_NO_KEY, VIEW, NULL);
1079
1080    sc_init_one(&help_list, NANO_NEXTLINE_KEY, N_("Next Line"),
1081	IFSCHELP(nano_nextline_msg, FALSE, NANO_NO_KEY), NANO_NO_KEY,
1082	NANO_NO_KEY, VIEW, NULL);
1083
1084    sc_init_one(&help_list, NANO_NO_KEY, first_line_msg,
1085	IFSCHELP(nano_firstline_msg, FALSE, NANO_FIRSTLINE_METAKEY),
1086	NANO_NO_KEY, NANO_FIRSTLINE_METAKEY2, VIEW, NULL);
1087
1088    sc_init_one(&help_list, NANO_NO_KEY, last_line_msg,
1089	IFSCHELP(nano_lastline_msg, TRUE, NANO_LASTLINE_METAKEY),
1090	NANO_NO_KEY, NANO_LASTLINE_METAKEY2, VIEW, NULL);
1091#endif
1092
1093#ifndef DISABLE_SPELLER
1094    free_shortcutage(&spell_list);
1095
1096    sc_init_one(&spell_list, NANO_HELP_KEY, get_help_msg,
1097	IFSCHELP(nano_help_msg, FALSE, NANO_NO_KEY), NANO_HELP_FKEY,
1098	NANO_NO_KEY, VIEW,
1099#ifndef DISABLE_HELP
1100	do_help_void
1101#else
1102	nano_disabled_msg
1103#endif
1104	);
1105
1106    sc_init_one(&spell_list, NANO_CANCEL_KEY, cancel_msg,
1107	IFSCHELP(nano_cancel_msg, FALSE, NANO_NO_KEY), NANO_NO_KEY,
1108	NANO_NO_KEY, VIEW, NULL);
1109#endif
1110
1111#ifndef DISABLE_BROWSER
1112    free_shortcutage(&browser_list);
1113
1114    sc_init_one(&browser_list, NANO_HELP_KEY, get_help_msg,
1115	IFSCHELP(nano_help_msg, FALSE, NANO_NO_KEY), NANO_HELP_FKEY,
1116	NANO_NO_KEY, VIEW, NULL);
1117
1118    sc_init_one(&browser_list, NANO_EXIT_KEY, exit_msg,
1119	IFSCHELP(nano_exitbrowser_msg, FALSE, NANO_NO_KEY),
1120	NANO_EXIT_FKEY, NANO_NO_KEY, VIEW, NULL);
1121
1122    sc_init_one(&browser_list, NANO_WHEREIS_KEY, whereis_msg,
1123	IFSCHELP(nano_whereis_msg, FALSE, NANO_NO_KEY), NANO_NO_KEY,
1124	NANO_NO_KEY, VIEW, NULL);
1125
1126    sc_init_one(&browser_list, NANO_NO_KEY, whereis_next_msg,
1127	IFSCHELP(nano_whereis_next_msg, FALSE, NANO_WHEREIS_NEXT_KEY),
1128	NANO_WHEREIS_NEXT_FKEY, NANO_NO_KEY, VIEW, NULL);
1129
1130    sc_init_one(&browser_list, NANO_PREVPAGE_KEY, prev_page_msg,
1131	IFSCHELP(nano_prevpage_msg, FALSE, NANO_NO_KEY),
1132	NANO_PREVPAGE_FKEY, NANO_NO_KEY, VIEW, NULL);
1133
1134    sc_init_one(&browser_list, NANO_NEXTPAGE_KEY, next_page_msg,
1135	IFSCHELP(nano_nextpage_msg, FALSE, NANO_NO_KEY),
1136	NANO_NEXTPAGE_FKEY, NANO_NO_KEY, VIEW, NULL);
1137
1138    sc_init_one(&browser_list, NANO_NO_KEY, first_file_msg,
1139	IFSCHELP(nano_firstfile_msg, FALSE, NANO_FIRSTFILE_METAKEY),
1140	NANO_NO_KEY, NANO_FIRSTFILE_METAKEY2, VIEW, NULL);
1141
1142    sc_init_one(&browser_list, NANO_NO_KEY, last_file_msg,
1143	IFSCHELP(nano_lastfile_msg, FALSE, NANO_LASTFILE_METAKEY),
1144	NANO_NO_KEY, NANO_LASTFILE_METAKEY2, VIEW, NULL);
1145
1146    /* TRANSLATORS: Try to keep this at most 12 characters. */
1147    sc_init_one(&browser_list, NANO_GOTODIR_KEY, N_("Go To Dir"),
1148	IFSCHELP(nano_gotodir_msg, FALSE, NANO_GOTODIR_METAKEY),
1149	NANO_GOTODIR_FKEY, NANO_NO_KEY, VIEW, NULL);
1150
1151    free_shortcutage(&whereis_file_list);
1152
1153    sc_init_one(&whereis_file_list, NANO_HELP_KEY, get_help_msg,
1154	IFSCHELP(nano_help_msg, FALSE, NANO_NO_KEY), NANO_HELP_FKEY,
1155	NANO_NO_KEY, VIEW,
1156#ifndef DISABLE_HELP
1157	do_browser_help
1158#else
1159	nano_disabled_msg
1160#endif
1161	);
1162
1163    sc_init_one(&whereis_file_list, NANO_CANCEL_KEY, cancel_msg,
1164	IFSCHELP(nano_cancel_msg, FALSE, NANO_NO_KEY), NANO_NO_KEY,
1165	NANO_NO_KEY, VIEW, NULL);
1166
1167    sc_init_one(&whereis_file_list, NANO_FIRSTFILE_KEY, first_file_msg,
1168	IFSCHELP(nano_firstfile_msg, FALSE, NANO_FIRSTFILE_METAKEY),
1169	NANO_FIRSTFILE_FKEY, NANO_FIRSTFILE_METAKEY2, VIEW,
1170	do_first_file);
1171
1172    sc_init_one(&whereis_file_list, NANO_LASTFILE_KEY, last_file_msg,
1173	IFSCHELP(nano_lastfile_msg, FALSE, NANO_LASTFILE_METAKEY),
1174	NANO_LASTFILE_FKEY, NANO_LASTFILE_METAKEY2, VIEW, do_last_file);
1175
1176#ifndef NANO_SMALL
1177    sc_init_one(&whereis_file_list, NANO_NO_KEY, case_sens_msg,
1178	IFSCHELP(nano_case_msg, FALSE, TOGGLE_CASE_KEY), NANO_NO_KEY,
1179	NANO_NO_KEY, VIEW, NULL);
1180
1181    sc_init_one(&whereis_file_list, NANO_NO_KEY, backwards_msg,
1182	IFSCHELP(nano_reverse_msg, FALSE, TOGGLE_BACKWARDS_KEY),
1183	NANO_NO_KEY, NANO_NO_KEY, VIEW, NULL);
1184#endif
1185
1186#ifdef HAVE_REGEX_H
1187    sc_init_one(&whereis_file_list, NANO_NO_KEY, regexp_msg,
1188	IFSCHELP(nano_regexp_msg, FALSE, NANO_REGEXP_KEY), NANO_NO_KEY,
1189	NANO_NO_KEY, VIEW, NULL);
1190#endif
1191
1192#ifndef NANO_SMALL
1193    sc_init_one(&whereis_file_list, NANO_PREVLINE_KEY, prev_history_msg,
1194	IFSCHELP(nano_prev_history_msg, FALSE, NANO_NO_KEY),
1195	NANO_NO_KEY, NANO_NO_KEY, VIEW, NULL);
1196
1197    sc_init_one(&whereis_file_list, NANO_NEXTLINE_KEY, next_history_msg,
1198	IFSCHELP(nano_next_history_msg, FALSE, NANO_NO_KEY),
1199	NANO_NO_KEY, NANO_NO_KEY, VIEW, NULL);
1200#endif
1201
1202    free_shortcutage(&gotodir_list);
1203
1204    sc_init_one(&gotodir_list, NANO_HELP_KEY, get_help_msg,
1205	IFSCHELP(nano_help_msg, FALSE, NANO_NO_KEY), NANO_HELP_FKEY,
1206	NANO_NO_KEY, VIEW,
1207#ifndef DISABLE_HELP
1208	do_browser_help
1209#else
1210	nano_disabled_msg
1211#endif
1212	);
1213
1214    sc_init_one(&gotodir_list, NANO_CANCEL_KEY, cancel_msg,
1215	IFSCHELP(nano_cancel_msg, FALSE, NANO_NO_KEY), NANO_NO_KEY,
1216	NANO_NO_KEY, VIEW, NULL);
1217#endif
1218
1219    currshortcut = main_list;
1220
1221#ifndef NANO_TINY
1222    toggle_init();
1223#endif
1224}
1225
1226/* Free the given shortcut. */
1227void free_shortcutage(shortcut **shortcutage)
1228{
1229    assert(shortcutage != NULL);
1230
1231    while (*shortcutage != NULL) {
1232	shortcut *ps = *shortcutage;
1233	*shortcutage = (*shortcutage)->next;
1234	free(ps);
1235    }
1236}
1237
1238#ifndef NANO_TINY
1239/* Add a new toggle to the end of the global toggle list. */
1240void toggle_init_one(int val
1241#ifndef DISABLE_HELP
1242	, const char *desc, bool blank_after
1243#endif
1244	, long flag)
1245{
1246    toggle *u;
1247
1248    if (toggles == NULL) {
1249	toggles = (toggle *)nmalloc(sizeof(toggle));
1250	u = toggles;
1251    } else {
1252	for (u = toggles; u->next != NULL; u = u->next)
1253	    ;
1254	u->next = (toggle *)nmalloc(sizeof(toggle));
1255	u = u->next;
1256    }
1257
1258    u->val = val;
1259#ifndef DISABLE_HELP
1260    u->desc = (desc == NULL) ? "" : _(desc);
1261    u->blank_after = blank_after;
1262#endif
1263    u->flag = flag;
1264    u->next = NULL;
1265}
1266
1267/* Initialize the global toggle list. */
1268void toggle_init(void)
1269{
1270    /* There is no need to reinitialize the toggles.  They can't
1271     * change. */
1272    if (toggles != NULL)
1273	return;
1274
1275/* The following macro is to be used in calling toggle_init_one().  The
1276 * point is that toggle_init_one() takes 4 arguments, unless
1277 * DISABLE_HELP is defined, when the 2nd and 3rd ones should not be
1278 * there. */
1279#ifndef DISABLE_HELP
1280#define IFTHELP(help, blank, nextvar) help, blank, nextvar
1281#else
1282#define IFTHELP(help, blank, nextvar) nextvar
1283#endif
1284
1285    toggle_init_one(TOGGLE_NOHELP_KEY, IFTHELP(N_("Help mode"), FALSE,
1286	NO_HELP));
1287
1288    toggle_init_one(TOGGLE_CONST_KEY,
1289	IFTHELP(N_("Constant cursor position display"), FALSE,
1290	CONST_UPDATE));
1291
1292    toggle_init_one(TOGGLE_MORESPACE_KEY,
1293	IFTHELP(N_("Use of one more line for editing"), FALSE,
1294	MORE_SPACE));
1295
1296    toggle_init_one(TOGGLE_SMOOTH_KEY,
1297#ifdef ENABLE_NANORC
1298	IFTHELP(N_("Smooth scrolling"), FALSE, SMOOTH_SCROLL)
1299#else
1300	IFTHELP(N_("Smooth scrolling"), TRUE, SMOOTH_SCROLL)
1301#endif
1302	);
1303
1304#ifdef ENABLE_NANORC
1305    toggle_init_one(TOGGLE_WHITESPACE_KEY,
1306#ifdef ENABLE_COLOR
1307	IFTHELP(N_("Whitespace display"), FALSE, WHITESPACE_DISPLAY)
1308#else
1309	IFTHELP(N_("Whitespace display"), TRUE, WHITESPACE_DISPLAY)
1310#endif
1311	);
1312#endif
1313
1314#ifdef ENABLE_COLOR
1315    toggle_init_one(TOGGLE_SYNTAX_KEY,
1316	IFTHELP(N_("Color syntax highlighting"), TRUE, NO_COLOR_SYNTAX));
1317#endif
1318
1319    toggle_init_one(TOGGLE_SMARTHOME_KEY, IFTHELP(N_("Smart home key"),
1320	FALSE, SMART_HOME));
1321
1322    toggle_init_one(TOGGLE_AUTOINDENT_KEY, IFTHELP(N_("Auto indent"),
1323	FALSE, AUTOINDENT));
1324
1325    toggle_init_one(TOGGLE_CUTTOEND_KEY, IFTHELP(N_("Cut to end"),
1326	FALSE, CUT_TO_END));
1327
1328#ifndef DISABLE_WRAPPING
1329    toggle_init_one(TOGGLE_WRAP_KEY, IFTHELP(N_("Long line wrapping"),
1330	FALSE, NO_WRAP));
1331#endif
1332
1333    toggle_init_one(TOGGLE_TABSTOSPACES_KEY,
1334#ifndef DISABLE_MOUSE
1335	IFTHELP(N_("Conversion of typed tabs to spaces"), TRUE,
1336	TABS_TO_SPACES)
1337#else
1338	IFTHELP(N_("Conversion of typed tabs to spaces"),
1339	!ISSET(RESTRICTED) ? TRUE : FALSE, TABS_TO_SPACES)
1340#endif
1341	);
1342
1343    /* If we're using restricted mode, the backup toggle is disabled.
1344     * It's useless since backups are disabled. */
1345    if (!ISSET(RESTRICTED))
1346	toggle_init_one(TOGGLE_BACKUP_KEY, IFTHELP(N_("Backup files"),
1347		FALSE, BACKUP_FILE));
1348
1349#ifdef ENABLE_MULTIBUFFER
1350    /* If we're using restricted mode, the multibuffer toggle is
1351     * disabled.  It's useless since inserting files is disabled. */
1352    if (!ISSET(RESTRICTED))
1353	toggle_init_one(TOGGLE_MULTIBUFFER_KEY,
1354		IFTHELP(N_("Multiple file buffers"), FALSE,
1355		MULTIBUFFER));
1356#endif
1357
1358#ifndef DISABLE_MOUSE
1359    toggle_init_one(TOGGLE_MOUSE_KEY, IFTHELP(N_("Mouse support"),
1360	FALSE, USE_MOUSE));
1361#endif
1362
1363    /* If we're using restricted mode, the DOS/Mac conversion toggle is
1364     * disabled.  It's useless since inserting files is disabled. */
1365    if (!ISSET(RESTRICTED))
1366	toggle_init_one(TOGGLE_NOCONVERT_KEY,
1367		IFTHELP(N_("No conversion from DOS/Mac format"), FALSE,
1368		NO_CONVERT));
1369
1370    /* If we're using restricted mode, the suspend toggle is disabled.
1371     * It's useless since suspending is disabled. */
1372    if (!ISSET(RESTRICTED))
1373	toggle_init_one(TOGGLE_SUSPEND_KEY, IFTHELP(N_("Suspension"),
1374	FALSE, SUSPEND));
1375}
1376#endif /* !NANO_TINY */
1377
1378#ifdef DEBUG
1379/* This function is used to gracefully return all the memory we've used.
1380 * It should be called just before calling exit().  Practically, the
1381 * only effect is to cause a segmentation fault if the various data
1382 * structures got bolloxed earlier.  Thus, we don't bother having this
1383 * function unless debugging is turned on. */
1384void thanks_for_all_the_fish(void)
1385{
1386    delwin(topwin);
1387    delwin(edit);
1388    delwin(bottomwin);
1389
1390#ifndef DISABLE_JUSTIFY
1391    if (quotestr != NULL)
1392	free(quotestr);
1393#ifdef HAVE_REGEX_H
1394    regfree(&quotereg);
1395    if (quoteerr != NULL)
1396	free(quoteerr);
1397#endif
1398#endif
1399#ifndef NANO_TINY
1400    if (backup_dir != NULL)
1401        free(backup_dir);
1402#endif
1403#ifndef DISABLE_OPERATINGDIR
1404    if (operating_dir != NULL)
1405	free(operating_dir);
1406    if (full_operating_dir != NULL)
1407	free(full_operating_dir);
1408#endif
1409    if (last_search != NULL)
1410	free(last_search);
1411    if (last_replace != NULL)
1412	free(last_replace);
1413#ifndef DISABLE_SPELLER
1414    if (alt_speller != NULL)
1415	free(alt_speller);
1416#endif
1417    if (answer != NULL)
1418	free(answer);
1419    if (cutbuffer != NULL)
1420	free_filestruct(cutbuffer);
1421#ifndef DISABLE_JUSTIFY
1422    if (jusbuffer != NULL)
1423	free_filestruct(jusbuffer);
1424#endif
1425    free_shortcutage(&main_list);
1426    free_shortcutage(&whereis_list);
1427    free_shortcutage(&replace_list);
1428    free_shortcutage(&replace_list_2);
1429    free_shortcutage(&gotoline_list);
1430    free_shortcutage(&writefile_list);
1431    free_shortcutage(&insertfile_list);
1432#ifndef NANO_TINY
1433    free_shortcutage(&extcmd_list);
1434#endif
1435#ifndef DISABLE_HELP
1436    free_shortcutage(&help_list);
1437#endif
1438#ifndef DISABLE_SPELLER
1439    free_shortcutage(&spell_list);
1440#endif
1441#ifndef DISABLE_BROWSER
1442    free_shortcutage(&browser_list);
1443    free_shortcutage(&gotodir_list);
1444#endif
1445#ifndef NANO_TINY
1446    /* Free the memory associated with each toggle. */
1447    while (toggles != NULL) {
1448	toggle *t = toggles;
1449
1450	toggles = toggles->next;
1451	free(t);
1452    }
1453#endif
1454    /* Free the memory associated with each open file buffer. */
1455    if (openfile != NULL)
1456	free_openfilestruct(openfile);
1457#ifdef ENABLE_COLOR
1458    if (syntaxstr != NULL)
1459	free(syntaxstr);
1460    while (syntaxes != NULL) {
1461	syntaxtype *bill = syntaxes;
1462
1463	free(syntaxes->desc);
1464	while (syntaxes->extensions != NULL) {
1465	    exttype *bob = syntaxes->extensions;
1466
1467	    syntaxes->extensions = bob->next;
1468	    free(bob->ext_regex);
1469	    if (bob->ext != NULL) {
1470		regfree(bob->ext);
1471		free(bob->ext);
1472	    }
1473	    free(bob);
1474	}
1475	while (syntaxes->color != NULL) {
1476	    colortype *bob = syntaxes->color;
1477
1478	    syntaxes->color = bob->next;
1479	    free(bob->start_regex);
1480	    if (bob->start != NULL) {
1481		regfree(bob->start);
1482		free(bob->start);
1483	    }
1484	    if (bob->end_regex != NULL)
1485		free(bob->end_regex);
1486	    if (bob->end != NULL) {
1487		regfree(bob->end);
1488		free(bob->end);
1489	    }
1490	    free(bob);
1491	}
1492	syntaxes = syntaxes->next;
1493	free(bill);
1494    }
1495#endif /* ENABLE_COLOR */
1496#ifndef NANO_TINY
1497    /* Free the search and replace history lists. */
1498    if (searchage != NULL)
1499	free_filestruct(searchage);
1500    if (replaceage != NULL)
1501	free_filestruct(replaceage);
1502#endif
1503#ifdef ENABLE_NANORC
1504    if (homedir != NULL)
1505	free(homedir);
1506#endif
1507}
1508#endif /* DEBUG */
1509