global.c 48.9 KB
Newer Older
Chris Allegretta's avatar
Chris Allegretta committed
1
/* $Id$ */
Chris Allegretta's avatar
Chris Allegretta committed
2
3
4
/**************************************************************************
 *   global.c                                                             *
 *                                                                        *
5
6
 *   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 Chris Allegretta    *
 *   Copyright (C) 2005, 2006 David Lawrence Ramsey                       *
Chris Allegretta's avatar
Chris Allegretta committed
7
8
 *   This program is free software; you can redistribute it and/or modify *
 *   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)  *
Chris Allegretta's avatar
Chris Allegretta committed
10
11
 *   any later version.                                                   *
 *                                                                        *
12
13
14
15
 *   This program is distributed in the hope that it will be useful, but  *
 *   WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    *
 *   General Public License for more details.                             *
Chris Allegretta's avatar
Chris Allegretta committed
16
17
18
 *                                                                        *
 *   You should have received a copy of the GNU General Public License    *
 *   along with this program; if not, write to the Free Software          *
19
20
 *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA            *
 *   02110-1301, USA.                                                     *
Chris Allegretta's avatar
Chris Allegretta committed
21
22
23
24
25
 *                                                                        *
 **************************************************************************/

#include "proto.h"

26
27
/* Global variables. */
#ifndef NANO_TINY
28
sigjmp_buf jump_buf;
29
30
	/* Used to return to main() or the unjustify routine in
	 * do_justify() after a SIGWINCH. */
31
32
33
bool jump_buf_main = FALSE;
	/* Have we set jump_buf so that we return to main() after a
	 * SIGWINCH? */
34
35
#endif

36
#ifndef DISABLE_WRAPJUSTIFY
37
38
ssize_t fill = 0;
	/* The column where we will wrap lines. */
39
ssize_t wrap_at = -CHARS_FROM_EOL;
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
	/* The position where we will wrap lines.  fill is equal to this
	 * if it's greater than zero, and equal to (COLS + this) if it
	 * isn't. */
#endif

char *last_search = NULL;
	/* The last string we searched for. */
char *last_replace = NULL;
	/* The last replacement string we searched for. */

long flags = 0;
	/* Our flag containing the states of all global options. */
WINDOW *topwin;
	/* The top portion of the window, where we display the version
	 * number of nano, the name of the current file, and whether the
	 * current file has been modified. */
WINDOW *edit;
57
	/* The middle portion of the window, i.e. the edit window, where
58
59
60
61
62
63
64
65
66
	 * we display the current file we're editing. */
WINDOW *bottomwin;
	/* The bottom portion of the window, where we display statusbar
	 * messages, the statusbar prompt, and a list of shortcuts. */
int editwinrows = 0;
	/* How many rows does the edit window take up? */

filestruct *cutbuffer = NULL;
	/* The buffer where we store cut text. */
67
#ifndef DISABLE_JUSTIFY
68
69
filestruct *jusbuffer = NULL;
	/* The buffer where we store unjustified text. */
70
#endif
71
72
73
partition *filepart = NULL;
	/* The partition where we store a portion of the current
	 * file. */
74
openfilestruct *openfile = NULL;
75
	/* The list of all open file buffers. */
76

77
78
79
80
81
82
#ifndef NANO_TINY
char *matchbrackets = NULL;
	/* The opening and closing brackets that can be found by bracket
	 * searches. */
#endif

83
#if !defined(NANO_TINY) && defined(ENABLE_NANORC)
84
85
86
87
88
char *whitespace = NULL;
	/* The characters used when displaying the first characters of
	 * tabs and spaces. */
int whitespace_len[2];
	/* The length of these characters. */
89
90
#endif

91
#ifndef DISABLE_JUSTIFY
92
93
94
95
96
97
98
char *punct = NULL;
	/* The closing punctuation that can end sentences. */
char *brackets = NULL;
	/* The closing brackets that can follow closing punctuation and
	 * can end sentences. */
char *quotestr = NULL;
	/* The quoting string.  The default value is set in main(). */
99
#ifdef HAVE_REGEX_H
100
101
102
regex_t quotereg;
	/* The compiled regular expression from the quoting string. */
int quoterc;
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
103
	/* Whether it was compiled successfully. */
104
105
char *quoteerr = NULL;
	/* The error message, if it didn't. */
106
#else
107
108
size_t quotelen;
	/* The length of the quoting string in bytes. */
Chris Allegretta's avatar
Chris Allegretta committed
109
#endif
110
111
#endif

112
113
char *answer = NULL;
	/* The answer string used in the statusbar prompt. */
Chris Allegretta's avatar
Chris Allegretta committed
114

115
116
117
ssize_t tabsize = -1;
	/* The width of a tab in spaces.  The default value is set in
	 * main(). */
118

119
120
121
122
#ifndef NANO_TINY
char *backup_dir = NULL;
	/* The directory where we store backup files. */
#endif
123
#ifndef DISABLE_OPERATINGDIR
124
125
126
127
128
char *operating_dir = NULL;
	/* The relative path to the operating directory, which we can't
	 * move outside of. */
char *full_operating_dir = NULL;
	/* The full path to it. */
129
130
#endif

131
#ifndef DISABLE_SPELLER
132
133
char *alt_speller = NULL;
	/* The command to use for the alternate spell checker. */
134
135
#endif

136
shortcut *main_list = NULL;
137
	/* The main shortcut list. */
138
shortcut *whereis_list = NULL;
139
	/* The "Search" shortcut list. */
140
shortcut *replace_list = NULL;
141
142
143
	/* The "Search (to replace)" shortcut list. */
shortcut *replace_list_2 = NULL;
	/* The "Replace with" shortcut list. */
144
shortcut *gotoline_list = NULL;
145
	/* The "Enter line number, column number" shortcut list. */
146
shortcut *writefile_list = NULL;
147
	/* The "File Name to Write" shortcut list. */
148
shortcut *insertfile_list = NULL;
149
150
151
152
153
	/* The "File to insert" shortcut list. */
#ifndef NANO_TINY
shortcut *extcmd_list = NULL;
	/* The "Command to execute" shortcut list. */
#endif
Chris Allegretta's avatar
Chris Allegretta committed
154
#ifndef DISABLE_HELP
155
shortcut *help_list = NULL;
156
	/* The help text shortcut list. */
Chris Allegretta's avatar
Chris Allegretta committed
157
158
#endif
#ifndef DISABLE_SPELLER
159
shortcut *spell_list = NULL;
160
	/* The internal spell checker shortcut list. */
Chris Allegretta's avatar
Chris Allegretta committed
161
#endif
162
#ifndef DISABLE_BROWSER
163
shortcut *browser_list = NULL;
164
	/* The file browser shortcut list. */
165
166
shortcut *whereis_file_list = NULL;
	/* The file browser "Search" shortcut list. */
167
shortcut *gotodir_list = NULL;
168
	/* The "Go To Directory" shortcut list. */
Chris Allegretta's avatar
Chris Allegretta committed
169
#endif
170

171
#ifdef ENABLE_COLOR
172
syntaxtype *syntaxes = NULL;
173
	/* The global list of color syntaxes. */
174
char *syntaxstr = NULL;
175
	/* The color syntax name specified on the command line. */
176
177
#endif

178
179
const shortcut *currshortcut;
	/* The current shortcut list we're using. */
180
#ifndef NANO_TINY
181
toggle *toggles = NULL;
182
	/* The global toggle list. */
183
#endif
Chris Allegretta's avatar
Chris Allegretta committed
184

185
#ifndef NANO_TINY
186
filestruct *search_history = NULL;
187
	/* The search string history list. */
188
filestruct *searchage = NULL;
189
	/* The top of the search string history list. */
190
filestruct *searchbot = NULL;
191
	/* The bottom of the search string history list. */
192
filestruct *replace_history = NULL;
193
	/* The replace string history list. */
194
filestruct *replaceage = NULL;
195
	/* The top of the replace string history list. */
196
filestruct *replacebot = NULL;
197
	/* The bottom of the replace string history list. */
198
199
#endif

200
/* Regular expressions. */
201
#ifdef HAVE_REGEX_H
202
203
204
205
206
regex_t search_regexp;
	/* The compiled regular expression to use in searches. */
regmatch_t regmatches[10];
	/* The match positions for parenthetical subexpressions, 10
	 * maximum, used in regular expression searches. */
Chris Allegretta's avatar
Chris Allegretta committed
207
#endif
208

209
210
int reverse_attr = A_REVERSE;
	/* The curses attribute we use for reverse video. */
211

212
char *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. */
216
size_t length_of_list(const shortcut *s)
217
{
218
    size_t i = 0;
219

220
    for (; s != NULL; s = s->next)
221
222
223
224
	i++;
    return i;
}

225
/* Add a new shortcut to the end of the shortcut list. */
226
void sc_init_one(shortcut **shortcutage, int ctrlval, const char *desc
227
#ifndef DISABLE_HELP
228
	, const char *help, bool blank_after
229
#endif
230
231
	, int metaval, int funcval, int miscval, bool view,
	void (*func)(void))
Chris Allegretta's avatar
Chris Allegretta committed
232
{
233
234
235
    shortcut *s;

    if (*shortcutage == NULL) {
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
236
	*shortcutage = (shortcut *)nmalloc(sizeof(shortcut));
237
238
239
240
	s = *shortcutage;
    } else {
	for (s = *shortcutage; s->next != NULL; s = s->next)
	    ;
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
241
	s->next = (shortcut *)nmalloc(sizeof(shortcut));
242
243
244
	s = s->next; 
    }

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
252
253
    s->metaval = metaval;
    s->funcval = funcval;
    s->miscval = miscval;
Chris Allegretta's avatar
Chris Allegretta committed
254
255
    s->viewok = view;
    s->func = func;
256
    s->next = NULL;
Chris Allegretta's avatar
Chris Allegretta committed
257
258
}

259
260
/* Initialize all shortcut lists.  If unjustify is TRUE, replace the
 * Uncut shortcut in the main shortcut list with UnJustify. */
261
void shortcut_init(bool unjustify)
262
{
263
264
    /* TRANSLATORS: Try to keep this and following strings at most 10
     * characters. */
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
265
    const char *cancel_msg = N_("Cancel");
266
267
    const char *get_help_msg = N_("Get Help");
    const char *exit_msg = N_("Exit");
268
    const char *whereis_msg = N_("Where Is");
269
270
271
    const char *prev_page_msg = N_("Prev Page");
    const char *next_page_msg = N_("Next Page");
    const char *go_to_line_msg = N_("Go To Line");
272
273
    /* TRANSLATORS: Try to keep this and previous strings at most 10
     * characters. */
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
274
    const char *replace_msg = N_("Replace");
275
#ifndef NANO_TINY
276
277
    /* TRANSLATORS: Try to keep this at most 12 characters. */
    const char *whereis_next_msg = N_("WhereIs Next");
278
#endif
279
280
    /* TRANSLATORS: Try to keep this and following strings at most 10
     * characters. */
281
282
    const char *first_line_msg = N_("First Line");
    const char *last_line_msg = N_("Last Line");
283
284
285
286
287
#ifndef DISABLE_JUSTIFY
    const char *beg_of_par_msg = N_("Beg of Par");
    const char *end_of_par_msg = N_("End of Par");
    const char *fulljstify_msg = N_("FullJstify");
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
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
294
#ifdef HAVE_REGEX_H
    const char *regexp_msg = N_("Regexp");
295
#endif
296
#ifndef NANO_TINY
297
    const char *prev_history_msg = N_("PrevHstory");
298
299
    /* TRANSLATORS: Try to keep this and previous strings at most 10
     * characters. */
300
    const char *next_history_msg = N_("NextHstory");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
301
#ifdef ENABLE_MULTIBUFFER
302
    /* TRANSLATORS: Try to keep this at most 16 characters. */
303
    const char *new_buffer_msg = N_("New Buffer");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
304
#endif
305
#endif
306
#ifndef DISABLE_BROWSER
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
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");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
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
321
322
323
#else
   	N_("Exit from nano")
#endif
	;
324
325
    const char *nano_writeout_msg =
	N_("Write the current file to disk");
326
327
328
    const char *nano_justify_msg = N_("Justify the current paragraph");
    const char *nano_insert_msg =
	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
332
333
334
335
336
    const char *nano_prevpage_msg = N_("Move to the previous screen");
    const char *nano_nextpage_msg = N_("Move to the next screen");
    const char *nano_cut_msg =
	N_("Cut the current line and store it in the cutbuffer");
    const char *nano_uncut_msg =
	N_("Uncut from the cutbuffer into the current line");
337
    const char *nano_cursorpos_msg =
338
	N_("Display the position of the cursor");
339
340
    const char *nano_spell_msg =
	N_("Invoke the spell checker, if available");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
341
    const char *nano_gotoline_msg = N_("Go to line and column number");
342
343
    const char *nano_replace_msg =
	N_("Replace a string or a regular expression");
344
#ifndef NANO_TINY
345
346
    const char *nano_mark_msg = N_("Mark text at the cursor position");
    const char *nano_whereis_next_msg = N_("Repeat last search");
347
348
    const char *nano_copy_msg =
	N_("Copy the current line and store it in the cutbuffer");
349
350
    const char *nano_indent_msg = N_("Indent the current line");
    const char *nano_unindent_msg = N_("Unindent the current line");
351
#endif
352
353
    const char *nano_forward_msg = N_("Move forward one character");
    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
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
358
359
360
361
362
363
    const char *nano_prevline_msg = N_("Move to the previous line");
    const char *nano_nextline_msg = N_("Move to the next line");
    const char *nano_home_msg =
	N_("Move to the beginning of the current line");
    const char *nano_end_msg =
	N_("Move to the end of the current line");
364
365
#ifndef DISABLE_JUSTIFY
    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");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
369
370
371
372
373
374
375
376
377
378
379
#endif
    const char *nano_firstline_msg =
	N_("Move to the first line of the file");
    const char *nano_lastline_msg =
	N_("Move to the last line of the file");
#ifndef NANO_TINY
    const char *nano_bracket_msg = N_("Move to the matching bracket");
    const char *nano_scrollup_msg =
	N_("Scroll up one line without scrolling the cursor");
    const char *nano_scrolldown_msg =
	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");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
389
    const char *nano_tab_msg =
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
390
	N_("Insert a tab at the cursor position");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
391
    const char *nano_enter_msg =
392
	N_("Insert a newline at the cursor position");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
393
394
395
396
    const char *nano_delete_msg =
	N_("Delete the character under the cursor");
    const char *nano_backspace_msg =
	N_("Delete the character to the left of the cursor");
397
#ifndef NANO_TINY
398
399
400
    const char *nano_cut_till_end_msg =
	N_("Cut from the cursor position to the end of the file");
#endif
401
402
#ifndef DISABLE_JUSTIFY
    const char *nano_fulljustify_msg = N_("Justify the entire file");
403
#endif
404
#ifndef NANO_TINY
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
405
406
    const char *nano_wordcount_msg =
	N_("Count the number of words, lines, and characters");
407
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
408
409
    const char *nano_refresh_msg =
	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
418
    const char *nano_regexp_msg =
	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
427
#ifndef DISABLE_BROWSER
    const char *nano_tofiles_msg = N_("Go to file browser");
Chris Allegretta's avatar
Chris Allegretta committed
428
#endif
429
#ifndef NANO_TINY
430
431
    const char *nano_dos_msg = N_("Toggle the use of DOS format");
    const char *nano_mac_msg = N_("Toggle the use of Mac format");
432
#endif
433
434
    const char *nano_append_msg = N_("Toggle appending");
    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
442
    const char *nano_multibuffer_msg =
	N_("Toggle the use of a new buffer");
443
444
#endif
#ifndef DISABLE_BROWSER
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
445
    const char *nano_exitbrowser_msg = N_("Exit from the file browser");
446
447
448
449
    const char *nano_firstfile_msg =
	N_("Go to the first file in the list");
    const char *nano_lastfile_msg =
	N_("Go to the last file in the list");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
450
    const char *nano_gotodir_msg = N_("Go to directory");
Chris Allegretta's avatar
Chris Allegretta committed
451
#endif
452
#endif /* !DISABLE_HELP */
Chris Allegretta's avatar
Chris Allegretta committed
453

David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
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. */
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
457
#ifndef DISABLE_HELP
458
#define IFSCHELP(help, blank, nextvar) help, blank, nextvar
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
459
#else
460
#define IFSCHELP(help, blank, nextvar) nextvar
461
#endif
462

463
464
465
    free_shortcutage(&main_list);

    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
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
471
	nano_disabled_msg
472
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
473
	);
Chris Allegretta's avatar
Chris Allegretta committed
474

475
476
    sc_init_one(&main_list, NANO_EXIT_KEY,
#ifdef ENABLE_MULTIBUFFER
477
	/* TRANSLATORS: Try to keep this at most 10 characters. */
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
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);
Chris Allegretta's avatar
Chris Allegretta committed
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);
Chris Allegretta's avatar
Chris Allegretta committed
487

488
    /* TRANSLATORS: Try to keep this at most 10 characters. */
489
    sc_init_one(&main_list, NANO_JUSTIFY_KEY, N_("Justify"),
490
491
	IFSCHELP(nano_justify_msg, TRUE, NANO_NO_KEY),
	NANO_JUSTIFY_FKEY, NANO_NO_KEY, NOVIEW,
492
#ifndef DISABLE_JUSTIFY
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
493
	do_justify_void
494
#else
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
495
	nano_disabled_msg
496
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
497
	);
498

499
    /* We allow inserting files in view mode if multibuffers are
500
501
502
503
     * available, so that we can view multiple files.  If we're using
     * restricted mode, inserting files is disabled, since it allows
     * reading from or writing to files not specified on the command
     * 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
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
509
	VIEW
510
#else
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
511
	NOVIEW
512
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
513
	, !ISSET(RESTRICTED) ? do_insertfile_void : nano_disabled_msg);
Chris Allegretta's avatar
Chris Allegretta committed
514

515
    sc_init_one(&main_list, NANO_WHEREIS_KEY, whereis_msg,
516
517
	IFSCHELP(nano_whereis_msg, FALSE, NANO_NO_KEY),
	NANO_WHEREIS_FKEY, NANO_NO_KEY, VIEW, do_search);
Chris Allegretta's avatar
Chris Allegretta committed
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);
Chris Allegretta's avatar
Chris Allegretta committed
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);
Chris Allegretta's avatar
Chris Allegretta committed
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);
Chris Allegretta's avatar
Chris Allegretta committed
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);
Chris Allegretta's avatar
Chris Allegretta committed
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);
Chris Allegretta's avatar
Chris Allegretta committed
547

548
549
550
    /* If we're using restricted mode, spell checking is disabled
     * because it allows reading from or writing to files not specified
     * 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,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
554
	NANO_NO_KEY, NOVIEW,
555
#ifndef DISABLE_SPELLER
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
556
	!ISSET(RESTRICTED) ? do_spell :
557
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
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
563
	NANO_GOTOLINE_FKEY, NANO_NO_KEY, VIEW,
	do_gotolinecolumn_void);
564

565
566
    sc_init_one(&main_list, NANO_REPLACE_KEY, replace_msg
#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);
Chris Allegretta's avatar
Chris Allegretta committed
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
592
	IFSCHELP(nano_unindent_msg, TRUE, NANO_UNINDENT_KEY),
	NANO_NO_KEY, NANO_NO_KEY, NOVIEW, do_unindent);
593
594
#endif

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);
Chris Allegretta's avatar
Chris Allegretta committed
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
611
	NANO_NO_KEY, NANO_NO_KEY, VIEW, do_prev_word_void);
#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
624
625
	NANO_NO_KEY, VIEW, do_home);

    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
630
#ifndef DISABLE_JUSTIFY
    sc_init_one(&main_list, NANO_NO_KEY, beg_of_par_msg,
631
632
	IFSCHELP(nano_parabegin_msg, FALSE, NANO_PARABEGIN_METAKEY),
	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
636
	IFSCHELP(nano_paraend_msg, FALSE, NANO_PARAEND_METAKEY),
	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
641
	IFSCHELP(nano_firstline_msg, FALSE, NANO_FIRSTLINE_METAKEY),
	NANO_NO_KEY, NANO_FIRSTLINE_METAKEY2, VIEW, do_first_line);
642
643

    sc_init_one(&main_list, NANO_NO_KEY, last_line_msg,
644
645
	IFSCHELP(nano_lastline_msg, TRUE, NANO_LASTLINE_METAKEY),
	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
650
	IFSCHELP(nano_bracket_msg, FALSE, NANO_BRACKET_KEY),
	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
680
681
	NANO_NO_KEY, NOVIEW, do_tab);

    sc_init_one(&main_list, NANO_ENTER_KEY, N_("Enter"),
682
	IFSCHELP(nano_enter_msg, FALSE, NANO_NO_KEY), NANO_NO_KEY,
683
684
685
	NANO_NO_KEY, NOVIEW, do_enter);

    sc_init_one(&main_list, NANO_DELETE_KEY, N_("Delete"),
686
	IFSCHELP(nano_delete_msg, FALSE, NANO_NO_KEY), NANO_NO_KEY,
687
688
	NANO_NO_KEY, NOVIEW, do_delete);

689
690
    sc_init_one(&main_list, NANO_BACKSPACE_KEY, N_("Backspace")
#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
701
702
	NANO_NO_KEY, NANO_NO_KEY, NOVIEW, do_cut_till_end);
#endif

703
704
#ifndef DISABLE_JUSTIFY
    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
708
#endif

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
714
#endif

David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
715
    sc_init_one(&main_list, NANO_REFRESH_KEY, refresh_msg
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
716
#ifndef NANO_TINY
717
	, IFSCHELP(nano_refresh_msg, TRUE, NANO_NO_KEY)
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
718
#else
719
	, IFSCHELP(nano_refresh_msg, FALSE, NANO_NO_KEY)
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
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
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
731
	nano_disabled_msg
732
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
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
741
	IFSCHELP(nano_firstline_msg, FALSE, NANO_FIRSTLINE_METAKEY),
	NANO_FIRSTLINE_FKEY, NANO_FIRSTLINE_METAKEY2, VIEW,
742
	do_first_line);
Chris Allegretta's avatar
Chris Allegretta committed
743

744
    sc_init_one(&whereis_list, NANO_LASTLINE_KEY, last_line_msg,
745
746
	IFSCHELP(nano_lastline_msg, FALSE, NANO_LASTLINE_METAKEY),
	NANO_LASTLINE_FKEY, NANO_LASTLINE_METAKEY2, VIEW, do_last_line);
Chris Allegretta's avatar
Chris Allegretta committed
747

748
    sc_init_one(&whereis_list, NANO_TOOTHERSEARCH_KEY, replace_msg,
749
750
	IFSCHELP(nano_replace_msg, FALSE, NANO_NO_KEY),
	NANO_REPLACE_FKEY, NANO_NO_KEY, VIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
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
759
	IFSCHELP(nano_parabegin_msg, FALSE, NANO_PARABEGIN_METAKEY),
	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
763
	IFSCHELP(nano_paraend_msg, FALSE, NANO_PARAEND_METAKEY),
	NANO_NO_KEY, NANO_PARAEND_METAKEY2, VIEW, do_para_end_void);
764
765
#endif

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
Chris Allegretta's avatar
Chris Allegretta committed
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
785
	IFSCHELP(nano_prev_history_msg, FALSE, NANO_NO_KEY),
	NANO_NO_KEY, NANO_NO_KEY, VIEW, NULL);
786
787

    sc_init_one(&whereis_list, NANO_NEXTLINE_KEY, next_history_msg,
788
789
	IFSCHELP(nano_next_history_msg, FALSE, NANO_NO_KEY),
	NANO_NO_KEY, NANO_NO_KEY, VIEW, NULL);
790
#endif
791
792
793

#ifndef DISABLE_JUSTIFY
    sc_init_one(&whereis_list, NANO_FULLJUSTIFY_KEY, fulljstify_msg,
794
	IFSCHELP(nano_fulljustify_msg, FALSE, NANO_FULLJUSTIFY_METAKEY),
795
796
	NANO_NO_KEY, NANO_NO_KEY, NOVIEW, do_full_justify);
#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
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
806
	nano_disabled_msg
807
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
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);
Chris Allegretta's avatar
Chris Allegretta committed
813

814
    sc_init_one(&replace_list, NANO_FIRSTLINE_KEY, first_line_msg,
815
816
	IFSCHELP(nano_firstline_msg, FALSE, NANO_FIRSTLINE_METAKEY),
	NANO_FIRSTLINE_FKEY, NANO_FIRSTLINE_METAKEY2, VIEW,
817
	do_first_line);
Chris Allegretta's avatar
Chris Allegretta committed
818

819
    sc_init_one(&replace_list, NANO_LASTLINE_KEY, last_line_msg,
820
821
	IFSCHELP(nano_lastline_msg, FALSE, NANO_LASTLINE_METAKEY),
	NANO_LASTLINE_FKEY, NANO_LASTLINE_METAKEY2, VIEW, do_last_line);
Chris Allegretta's avatar
Chris Allegretta committed
822

823
    /* TRANSLATORS: Try to keep this at most 12 characters. */
824
    sc_init_one(&replace_list, NANO_TOOTHERSEARCH_KEY, N_("No Replace"),
825
826
	IFSCHELP(nano_whereis_msg, FALSE, NANO_NO_KEY),
	NANO_REPLACE_FKEY, NANO_NO_KEY, VIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
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
847
	IFSCHELP(nano_prev_history_msg, FALSE, NANO_NO_KEY),
	NANO_NO_KEY, NANO_NO_KEY, VIEW, NULL);
848
849

    sc_init_one(&replace_list, NANO_NEXTLINE_KEY, next_history_msg,
850
851
	IFSCHELP(nano_next_history_msg, FALSE, NANO_NO_KEY),
	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
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
862
	nano_disabled_msg
863
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
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
872
	IFSCHELP(nano_firstline_msg, FALSE, NANO_FIRSTLINE_METAKEY),
	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
877
	IFSCHELP(nano_lastline_msg, FALSE, NANO_LASTLINE_METAKEY),
	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
882
	IFSCHELP(nano_prev_history_msg, FALSE, NANO_NO_KEY),
	NANO_NO_KEY, NANO_NO_KEY, VIEW, NULL);
883
884

    sc_init_one(&replace_list_2, NANO_NEXTLINE_KEY, next_history_msg,
885
886
	IFSCHELP(nano_next_history_msg, FALSE, NANO_NO_KEY),
	NANO_NO_KEY, NANO_NO_KEY, VIEW, NULL);
887
888
#endif

889
    free_shortcutage(&gotoline_list);
Chris Allegretta's avatar
Chris Allegretta committed
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
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
897
	nano_disabled_msg
898
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
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);
Chris Allegretta's avatar
Chris Allegretta committed
904

905
    sc_init_one(&gotoline_list, NANO_FIRSTLINE_KEY, first_line_msg,
906
907
	IFSCHELP(nano_firstline_msg, FALSE, NANO_FIRSTLINE_METAKEY),
	NANO_FIRSTLINE_FKEY, NANO_FIRSTLINE_METAKEY2, VIEW,
908
	do_first_line);
Chris Allegretta's avatar
Chris Allegretta committed
909

910
    sc_init_one(&gotoline_list, NANO_LASTLINE_KEY, last_line_msg,
911
912
	IFSCHELP(nano_lastline_msg, FALSE, NANO_LASTLINE_METAKEY),
	NANO_LASTLINE_FKEY, NANO_LASTLINE_METAKEY2, VIEW, do_last_line);
Chris Allegretta's avatar
Chris Allegretta committed
913

914
    sc_init_one(&gotoline_list, NANO_TOOTHERWHEREIS_KEY,
915
916
	N_("Go To Text"), IFSCHELP(nano_whereis_msg, FALSE,
	NANO_NO_KEY), NANO_NO_KEY, NANO_NO_KEY, VIEW, NULL);
917

918
    free_shortcutage(&writefile_list);
Chris Allegretta's avatar
Chris Allegretta committed
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
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
926
	nano_disabled_msg
927
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
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
936
    /* If we're using restricted mode, the file browser is disabled.
     * 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);
Chris Allegretta's avatar
Chris Allegretta committed
941
#endif
Chris Allegretta's avatar
Chris Allegretta committed
942

943
#ifndef NANO_TINY
944
945
946
947
948
949
    /* If we're using restricted mode, the DOS format, Mac format,
     * append, prepend, and backup toggles are disabled.  The first and
     * second are useless since inserting files is disabled, the third
     * and fourth are disabled because they allow writing to files not
     * specified on the command line, and the fifth is useless since
     * 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
962
#endif

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
982
#endif

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
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
991
	nano_disabled_msg
992
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
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);
Chris Allegretta's avatar
Chris Allegretta committed
998

999
#ifndef DISABLE_BROWSER
1000
1001
    /* If we're using restricted mode, the file browser is disabled.
     * 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
1010
    /* If we're using restricted mode, command execution is disabled.
     * It's useless since inserting files is disabled. */
1011
    if (!ISSET(RESTRICTED))
1012
	sc_init_one(&insertfile_list, NANO_TOOTHERINSERT_KEY,
1013
1014
		/* TRANSLATORS: Try to keep this at most 22
		 * characters. */
1015
1016
		N_("Execute Command"), IFSCHELP(nano_execute_msg, FALSE,
		NANO_NO_KEY), NANO_NO_KEY, NANO_NO_KEY, NOVIEW, NULL);
1017

1018
#ifdef ENABLE_MULTIBUFFER
1019
1020
    /* If we're using restricted mode, the multibuffer toggle is
     * 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
1024
		IFSCHELP(nano_multibuffer_msg, FALSE,
		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);
Chris Allegretta's avatar
Chris Allegretta committed
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
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1038
	nano_disabled_msg
1039
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
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

David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
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
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1055
#endif
1056

1057
1058
1059
1060
#ifndef DISABLE_HELP
    free_shortcutage(&help_list);

    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
1079
1080
	NANO_NO_KEY, VIEW, NULL);

    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
1086
	IFSCHELP(nano_firstline_msg, FALSE, NANO_FIRSTLINE_METAKEY),
	NANO_NO_KEY, NANO_FIRSTLINE_METAKEY2, VIEW, NULL);
1087
1088

    sc_init_one(&help_list, NANO_NO_KEY, last_line_msg,
1089
1090
	IFSCHELP(nano_lastline_msg, TRUE, NANO_LASTLINE_METAKEY),
	NANO_NO_KEY, NANO_LASTLINE_METAKEY2, VIEW, NULL);
1091
1092
1093
1094
1095
1096
#endif

#ifndef DISABLE_SPELLER
    free_shortcutage(&spell_list);

    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
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1102
	nano_disabled_msg
1103
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
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
1110
#endif

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
1125
1126
	NANO_NO_KEY, VIEW, NULL);

    sc_init_one(&browser_list, NANO_NO_KEY, whereis_next_msg,
1127
	IFSCHELP(nano_whereis_next_msg, FALSE, NANO_WHEREIS_NEXT_KEY),
1128
1129
	NANO_WHEREIS_NEXT_FKEY, NANO_NO_KEY, VIEW, NULL);

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);
Chris Allegretta's avatar
Chris Allegretta committed
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);
Chris Allegretta's avatar
Chris Allegretta committed
1137

1138
    sc_init_one(&browser_list, NANO_NO_KEY, first_file_msg,
1139
1140
	IFSCHELP(nano_firstfile_msg, FALSE, NANO_FIRSTFILE_METAKEY),
	NANO_NO_KEY, NANO_FIRSTFILE_METAKEY2, VIEW, NULL);
1141

1142
    sc_init_one(&browser_list, NANO_NO_KEY, last_file_msg,
1143
1144
	IFSCHELP(nano_lastfile_msg, FALSE, NANO_LASTFILE_METAKEY),
	NANO_NO_KEY, NANO_LASTFILE_METAKEY2, VIEW, NULL);
1145

David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
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);
Rocco Corsi's avatar
   
Rocco Corsi committed
1150

1151
1152
1153
    free_shortcutage(&whereis_file_list);

    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
1157
1158
1159
1160
1161
1162
1163
#ifndef DISABLE_HELP
	do_browser_help
#else
	nano_disabled_msg
#endif
	);

    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
1169
	IFSCHELP(nano_firstfile_msg, FALSE, NANO_FIRSTFILE_METAKEY),
	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
1174
	IFSCHELP(nano_lastfile_msg, FALSE, NANO_LASTFILE_METAKEY),
	NANO_LASTFILE_FKEY, NANO_LASTFILE_METAKEY2, VIEW, do_last_file);
1175
1176
1177

#ifndef NANO_SMALL
    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
1180
1181
	NANO_NO_KEY, VIEW, NULL);

    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
1185
1186
1187
#endif

#ifdef HAVE_REGEX_H
    sc_init_one(&whereis_file_list, NANO_NO_KEY, regexp_msg,
1188
	IFSCHELP(nano_regexp_msg, FALSE, NANO_REGEXP_KEY), NANO_NO_KEY,
1189
1190
1191
1192
	NANO_NO_KEY, VIEW, NULL);
#endif

#ifndef NANO_SMALL
1193
    sc_init_one(&whereis_file_list, NANO_PREVLINE_KEY, prev_history_msg,
1194
1195
	IFSCHELP(nano_prev_history_msg, FALSE, NANO_NO_KEY),
	NANO_NO_KEY, NANO_NO_KEY, VIEW, NULL);
1196
1197

    sc_init_one(&whereis_file_list, NANO_NEXTLINE_KEY, next_history_msg,
1198
1199
	IFSCHELP(nano_next_history_msg, FALSE, NANO_NO_KEY),
	NANO_NO_KEY, NANO_NO_KEY, VIEW, NULL);
1200
1201
#endif

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
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1210
	nano_disabled_msg
1211
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1212
	);
Chris Allegretta's avatar
Chris Allegretta committed
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);
Chris Allegretta's avatar
Chris Allegretta committed
1217
1218
#endif

1219
    currshortcut = main_list;
1220

1221
#ifndef NANO_TINY
1222
    toggle_init();
1223
#endif
1224
}
1225

1226
/* Free the given shortcut. */
1227
1228
1229
void free_shortcutage(shortcut **shortcutage)
{
    assert(shortcutage != NULL);
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1230

1231
1232
1233
1234
1235
1236
1237
    while (*shortcutage != NULL) {
	shortcut *ps = *shortcutage;
	*shortcutage = (*shortcutage)->next;
	free(ps);
    }
}

1238
#ifndef NANO_TINY
1239
/* Add a new toggle to the end of the global toggle list. */
1240
1241
1242
1243
1244
void toggle_init_one(int val
#ifndef DISABLE_HELP
	, const char *desc, bool blank_after
#endif
	, long flag)
1245
1246
1247
1248
{
    toggle *u;

    if (toggles == NULL) {
1249
	toggles = (toggle *)nmalloc(sizeof(toggle));
1250
1251
1252
1253
	u = toggles;
    } else {
	for (u = toggles; u->next != NULL; u = u->next)
	    ;
1254
	u->next = (toggle *)nmalloc(sizeof(toggle));
1255
1256
1257
1258
	u = u->next;
    }

    u->val = val;
1259
#ifndef DISABLE_HELP
1260
    u->desc = (desc == NULL) ? "" : _(desc);
1261
    u->blank_after = blank_after;
1262
#endif
1263
1264
1265
1266
    u->flag = flag;
    u->next = NULL;
}

1267
/* Initialize the global toggle list. */
1268
1269
1270
1271
1272
1273
1274
void toggle_init(void)
{
    /* There is no need to reinitialize the toggles.  They can't
     * change. */
    if (toggles != NULL)
	return;

1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
/* The following macro is to be used in calling toggle_init_one().  The
 * point is that toggle_init_one() takes 4 arguments, unless
 * DISABLE_HELP is defined, when the 2nd and 3rd ones should not be
 * there. */
#ifndef DISABLE_HELP
#define IFTHELP(help, blank, nextvar) help, blank, nextvar
#else
#define IFTHELP(help, blank, nextvar) nextvar
#endif

    toggle_init_one(TOGGLE_NOHELP_KEY, IFTHELP(N_("Help mode"), FALSE,
	NO_HELP));
1287

1288
    toggle_init_one(TOGGLE_CONST_KEY,
1289
1290
	IFTHELP(N_("Constant cursor position display"), FALSE,
	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
1316
    toggle_init_one(TOGGLE_SYNTAX_KEY,
	IFTHELP(N_("Color syntax highlighting"), TRUE, NO_COLOR_SYNTAX));
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1317
#endif
1318

1319
1320
    toggle_init_one(TOGGLE_SMARTHOME_KEY, IFTHELP(N_("Smart home key"),
	FALSE, SMART_HOME));
1321

1322
1323
    toggle_init_one(TOGGLE_AUTOINDENT_KEY, IFTHELP(N_("Auto indent"),
	FALSE, AUTOINDENT));
1324

1325
1326
    toggle_init_one(TOGGLE_CUTTOEND_KEY, IFTHELP(N_("Cut to end"),
	FALSE, CUT_TO_END));
1327

1328
#ifndef DISABLE_WRAPPING
1329
1330
    toggle_init_one(TOGGLE_WRAP_KEY, IFTHELP(N_("Long line wrapping"),
	FALSE, NO_WRAP));
1331
#endif
1332

1333
    toggle_init_one(TOGGLE_TABSTOSPACES_KEY,
1334
1335
1336
1337
#ifndef DISABLE_MOUSE
	IFTHELP(N_("Conversion of typed tabs to spaces"), TRUE,
	TABS_TO_SPACES)
#else
1338
1339
	IFTHELP(N_("Conversion of typed tabs to spaces"),
	!ISSET(RESTRICTED) ? TRUE : FALSE, TABS_TO_SPACES)
1340
#endif
1341
	);
1342

1343
1344
1345
    /* If we're using restricted mode, the backup toggle is disabled.
     * It's useless since backups are disabled. */
    if (!ISSET(RESTRICTED))
1346
1347
	toggle_init_one(TOGGLE_BACKUP_KEY, IFTHELP(N_("Backup files"),
		FALSE, BACKUP_FILE));
1348
1349
1350
1351
1352
1353

#ifdef ENABLE_MULTIBUFFER
    /* If we're using restricted mode, the multibuffer toggle is
     * disabled.  It's useless since inserting files is disabled. */
    if (!ISSET(RESTRICTED))
	toggle_init_one(TOGGLE_MULTIBUFFER_KEY,
1354
1355
		IFTHELP(N_("Multiple file buffers"), FALSE,
		MULTIBUFFER));
1356
#endif
1357

1358
#ifndef DISABLE_MOUSE
1359
1360
    toggle_init_one(TOGGLE_MOUSE_KEY, IFTHELP(N_("Mouse support"),
	FALSE, USE_MOUSE));
1361
1362
#endif

1363
1364
1365
1366
    /* If we're using restricted mode, the DOS/Mac conversion toggle is
     * disabled.  It's useless since inserting files is disabled. */
    if (!ISSET(RESTRICTED))
	toggle_init_one(TOGGLE_NOCONVERT_KEY,
1367
1368
		IFTHELP(N_("No conversion from DOS/Mac format"), FALSE,
		NO_CONVERT));
1369
1370
1371
1372

    /* If we're using restricted mode, the suspend toggle is disabled.
     * It's useless since suspending is disabled. */
    if (!ISSET(RESTRICTED))
1373
1374
	toggle_init_one(TOGGLE_SUSPEND_KEY, IFTHELP(N_("Suspension"),
	FALSE, SUSPEND));
1375
}
1376
#endif /* !NANO_TINY */
1377

1378
1379
1380
#ifdef DEBUG
/* This function is used to gracefully return all the memory we've used.
 * It should be called just before calling exit().  Practically, the
1381
1382
 * only effect is to cause a segmentation fault if the various data
 * structures got bolloxed earlier.  Thus, we don't bother having this
Chris Allegretta's avatar
Chris Allegretta committed
1383
1384
 * function unless debugging is turned on. */
void thanks_for_all_the_fish(void)
1385
{
1386
1387
1388
1389
    delwin(topwin);
    delwin(edit);
    delwin(bottomwin);

Chris Allegretta's avatar
Chris Allegretta committed
1390
1391
1392
#ifndef DISABLE_JUSTIFY
    if (quotestr != NULL)
	free(quotestr);
1393
1394
#ifdef HAVE_REGEX_H
    regfree(&quotereg);
1395
1396
    if (quoteerr != NULL)
	free(quoteerr);
1397
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1398
#endif
1399
#ifndef NANO_TINY
1400
1401
1402
    if (backup_dir != NULL)
        free(backup_dir);
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1403
#ifndef DISABLE_OPERATINGDIR
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
    if (operating_dir != NULL)
	free(operating_dir);
    if (full_operating_dir != NULL)
	free(full_operating_dir);
#endif
    if (last_search != NULL)
	free(last_search);
    if (last_replace != NULL)
	free(last_replace);
#ifndef DISABLE_SPELLER
    if (alt_speller != NULL)
	free(alt_speller);
1416
#endif
1417
1418
1419
    if (answer != NULL)
	free(answer);
    if (cutbuffer != NULL)
Chris Allegretta's avatar
Chris Allegretta committed
1420
	free_filestruct(cutbuffer);
1421
1422
1423
1424
#ifndef DISABLE_JUSTIFY
    if (jusbuffer != NULL)
	free_filestruct(jusbuffer);
#endif
1425
1426
1427
1428
    free_shortcutage(&main_list);
    free_shortcutage(&whereis_list);
    free_shortcutage(&replace_list);
    free_shortcutage(&replace_list_2);
1429
    free_shortcutage(&gotoline_list);
1430
1431
    free_shortcutage(&writefile_list);
    free_shortcutage(&insertfile_list);
1432
1433
1434
#ifndef NANO_TINY
    free_shortcutage(&extcmd_list);
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1435
#ifndef DISABLE_HELP
Chris Allegretta's avatar
Chris Allegretta committed
1436
    free_shortcutage(&help_list);
Chris Allegretta's avatar
Chris Allegretta committed
1437
1438
#endif
#ifndef DISABLE_SPELLER
1439
    free_shortcutage(&spell_list);
Chris Allegretta's avatar
Chris Allegretta committed
1440
#endif
1441
1442
#ifndef DISABLE_BROWSER
    free_shortcutage(&browser_list);
Chris Allegretta's avatar
Chris Allegretta committed
1443
    free_shortcutage(&gotodir_list);
1444
#endif
1445
#ifndef NANO_TINY
1446
    /* Free the memory associated with each toggle. */
1447
1448
    while (toggles != NULL) {
	toggle *t = toggles;
1449

1450
1451
1452
1453
	toggles = toggles->next;
	free(t);
    }
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1454
    /* Free the memory associated with each open file buffer. */
1455
    if (openfile != NULL)
1456
	free_openfilestruct(openfile);
Chris Allegretta's avatar
Chris Allegretta committed
1457
#ifdef ENABLE_COLOR
1458
1459
    if (syntaxstr != NULL)
	free(syntaxstr);
Chris Allegretta's avatar
Chris Allegretta committed
1460
1461
1462
1463
1464
1465
1466
1467
    while (syntaxes != NULL) {
	syntaxtype *bill = syntaxes;

	free(syntaxes->desc);
	while (syntaxes->extensions != NULL) {
	    exttype *bob = syntaxes->extensions;

	    syntaxes->extensions = bob->next;
1468
	    free(bob->ext_regex);
1469
1470
1471
1472
	    if (bob->ext != NULL) {
		regfree(bob->ext);
		free(bob->ext);
	    }
Chris Allegretta's avatar
Chris Allegretta committed
1473
1474
1475
1476
1477
1478
	    free(bob);
	}
	while (syntaxes->color != NULL) {
	    colortype *bob = syntaxes->color;

	    syntaxes->color = bob->next;
1479
	    free(bob->start_regex);
1480
1481
1482
1483
	    if (bob->start != NULL) {
		regfree(bob->start);
		free(bob->start);
	    }
1484
1485
	    if (bob->end_regex != NULL)
		free(bob->end_regex);
1486
	    if (bob->end != NULL) {
1487
		regfree(bob->end);
1488
1489
		free(bob->end);
	    }
Chris Allegretta's avatar
Chris Allegretta committed
1490
1491
1492
1493
1494
1495
	    free(bob);
	}
	syntaxes = syntaxes->next;
	free(bill);
    }
#endif /* ENABLE_COLOR */
1496
#ifndef NANO_TINY
1497
    /* Free the search and replace history lists. */
1498
1499
1500
1501
    if (searchage != NULL)
	free_filestruct(searchage);
    if (replaceage != NULL)
	free_filestruct(replaceage);
1502
#endif
1503
#ifdef ENABLE_NANORC
1504
1505
    if (homedir != NULL)
	free(homedir);
1506
#endif
1507
}
1508
#endif /* DEBUG */