global.c 45.7 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
 *   Copyright (C) 1999-2004 Chris Allegretta                             *
6
 *   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"

Chris Allegretta's avatar
Chris Allegretta committed
26
/* Global variables */
27
#ifndef DISABLE_WRAPJUSTIFY
28
29
ssize_t fill = 0;
	/* The column where we will wrap lines. */
30
ssize_t wrap_at = -CHARS_FROM_EOL;
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
	/* 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;
	/* The middle portion of the window, i.e, the edit window, where
	 * 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. */
58
#ifndef DISABLE_JUSTIFY
59
60
filestruct *jusbuffer = NULL;
	/* The buffer where we store unjustified text. */
61
#endif
62
63
64
partition *filepart = NULL;
	/* The partition where we store a portion of the current
	 * file. */
65
openfilestruct *openfile = NULL;
66
	/* The list of all open file buffers. */
67

68
69
70
71
72
73
#ifndef NANO_TINY
char *matchbrackets = NULL;
	/* The opening and closing brackets that can be found by bracket
	 * searches. */
#endif

74
#if !defined(NANO_TINY) && defined(ENABLE_NANORC)
75
76
77
78
79
char *whitespace = NULL;
	/* The characters used when displaying the first characters of
	 * tabs and spaces. */
int whitespace_len[2];
	/* The length of these characters. */
80
81
#endif

82
#ifndef DISABLE_JUSTIFY
83
84
85
86
87
88
89
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(). */
90
#ifdef HAVE_REGEX_H
91
92
93
94
95
96
regex_t quotereg;
	/* The compiled regular expression from the quoting string. */
int quoterc;
	/* Whether it actually compiled. */
char *quoteerr = NULL;
	/* The error message, if it didn't. */
97
#else
98
99
size_t quotelen;
	/* The length of the quoting string in bytes. */
Chris Allegretta's avatar
Chris Allegretta committed
100
#endif
101
102
#endif

103
104
char *answer = NULL;
	/* The answer string used in the statusbar prompt. */
Chris Allegretta's avatar
Chris Allegretta committed
105

106
107
108
ssize_t tabsize = -1;
	/* The width of a tab in spaces.  The default value is set in
	 * main(). */
109

110
111
112
113
#ifndef NANO_TINY
char *backup_dir = NULL;
	/* The directory where we store backup files. */
#endif
114
#ifndef DISABLE_OPERATINGDIR
115
116
117
118
119
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. */
120
121
#endif

122
#ifndef DISABLE_SPELLER
123
124
char *alt_speller = NULL;
	/* The command to use for the alternate spell checker. */
125
126
#endif

127
shortcut *main_list = NULL;
128
	/* The main shortcut list. */
129
shortcut *whereis_list = NULL;
130
	/* The "Search" shortcut list. */
131
shortcut *replace_list = NULL;
132
133
134
	/* The "Search (to replace)" shortcut list. */
shortcut *replace_list_2 = NULL;
	/* The "Replace with" shortcut list. */
135
shortcut *gotoline_list = NULL;
136
	/* The "Enter line number, column number" shortcut list. */
137
shortcut *writefile_list = NULL;
138
	/* The "File Name to Write" shortcut list. */
139
shortcut *insertfile_list = NULL;
140
141
142
143
144
	/* 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
145
#ifndef DISABLE_HELP
146
shortcut *help_list = NULL;
147
	/* The help text shortcut list. */
Chris Allegretta's avatar
Chris Allegretta committed
148
149
#endif
#ifndef DISABLE_SPELLER
150
shortcut *spell_list = NULL;
151
	/* The internal spell checker shortcut list. */
Chris Allegretta's avatar
Chris Allegretta committed
152
#endif
153
#ifndef DISABLE_BROWSER
154
shortcut *browser_list = NULL;
155
	/* The file browser shortcut list. */
156
157
shortcut *whereis_file_list = NULL;
	/* The file browser "Search" shortcut list. */
158
shortcut *gotodir_list = NULL;
159
	/* The "Go To Directory" shortcut list. */
Chris Allegretta's avatar
Chris Allegretta committed
160
#endif
161

162
#ifdef ENABLE_COLOR
163
syntaxtype *syntaxes = NULL;
164
	/* The global list of color syntaxes. */
165
char *syntaxstr = NULL;
166
	/* The color syntax name specified on the command line. */
167
168
#endif

169
170
const shortcut *currshortcut;
	/* The current shortcut list we're using. */
171
#ifndef NANO_TINY
172
toggle *toggles = NULL;
173
	/* The global toggle list. */
174
#endif
Chris Allegretta's avatar
Chris Allegretta committed
175

176
#ifndef NANO_TINY
177
filestruct *search_history = NULL;
178
	/* The search string history list. */
179
filestruct *searchage = NULL;
180
	/* The top of the search string history list. */
181
filestruct *searchbot = NULL;
182
	/* The bottom of the search string history list. */
183
filestruct *replace_history = NULL;
184
	/* The replace string history list. */
185
filestruct *replaceage = NULL;
186
	/* The top of the replace string history list. */
187
filestruct *replacebot = NULL;
188
	/* The bottom of the replace string history list. */
189
190
#endif

191
/* Regular expressions */
192
#ifdef HAVE_REGEX_H
193
194
195
196
197
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
198
#endif
199

200
201
int reverse_attr = A_REVERSE;
	/* The curses attribute we use for reverse video. */
202
203
204
205
bool curses_ended = FALSE;
	/* Whether endwin() has ended curses mode and statusbar()
	 * should hence write to stderr instead of displaying on the
	 * statusbar. */
206

207
208
209
char *homedir = NULL;
		/* The user's home directory, from $HOME or
		 * /etc/passwd. */
210

211
/* Return the number of entries in the shortcut list s. */
212
size_t length_of_list(const shortcut *s)
213
{
214
    size_t i = 0;
215

216
    for (; s != NULL; s = s->next)
217
218
219
220
	i++;
    return i;
}

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

    if (*shortcutage == NULL) {
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
232
	*shortcutage = (shortcut *)nmalloc(sizeof(shortcut));
233
234
235
236
	s = *shortcutage;
    } else {
	for (s = *shortcutage; s->next != NULL; s = s->next)
	    ;
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
237
	s->next = (shortcut *)nmalloc(sizeof(shortcut));
238
239
240
	s = s->next; 
    }

241
    s->ctrlval = ctrlval;
242
    s->desc = (desc == NULL) ? "" : _(desc);
243
#ifndef DISABLE_HELP
244
    s->help = (help == NULL) ? "" : _(help);
245
#endif
246
    s->blank_after = blank_after;
247
248
249
    s->metaval = metaval;
    s->funcval = funcval;
    s->miscval = miscval;
Chris Allegretta's avatar
Chris Allegretta committed
250
251
    s->viewok = view;
    s->func = func;
252
    s->next = NULL;
Chris Allegretta's avatar
Chris Allegretta committed
253
254
}

255
256
/* Initialize all shortcut lists.  If unjustify is TRUE, replace the
 * Uncut shortcut in the main shortcut list with UnJustify. */
257
void shortcut_init(bool unjustify)
258
{
259
    /* TRANSLATORS: Try to keep this and following strings at most 10 characters. */
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
260
    const char *cancel_msg = N_("Cancel");
261
262
    const char *get_help_msg = N_("Get Help");
    const char *exit_msg = N_("Exit");
263
    const char *whereis_msg = N_("Where Is");
264
265
266
    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");
267
    /* TRANSLATORS: Try to keep this and previous strings at most 10 characters. */
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
268
    const char *replace_msg = N_("Replace");
269
#ifndef NANO_TINY
270
    /* TRANSLATORS: Try to keep this at most 16 characters. */
271
272
    const char *whereis_next_msg = N_("Where Is Next");
#endif
273
    /* TRANSLATORS: Try to keep this and following strings at most 10 characters. */
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
274
    const char *refresh_msg = N_("Refresh");
275
276
    const char *first_line_msg = N_("First Line");
    const char *last_line_msg = N_("Last Line");
277
#ifndef NANO_TINY
278
279
    const char *cut_till_end_msg = N_("CutTillEnd");
#endif
280
281
282
283
284
#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
285
#ifndef NANO_TINY
286
    const char *case_sens_msg = N_("Case Sens");
287
    const char *backwards_msg = N_("Backwards");
288
#endif
289
290
#ifdef HAVE_REGEX_H
    const char *regexp_msg = N_("Regexp");
291
#endif
292
#ifndef NANO_TINY
293
    /* TRANSLATORS: Try to keep this and previous strings at most 10 characters. */
294
    const char *history_msg = N_("History");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
295
#ifdef ENABLE_MULTIBUFFER
296
    /* TRANSLATORS: Try to keep this at most 16 characters. */
297
    const char *new_buffer_msg = N_("New Buffer");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
298
#endif
299
#endif
300
#ifndef DISABLE_BROWSER
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
301
    /* TRANSLATORS: Try to keep this and following strings at most 16 characters. */
302
    const char *to_files_msg = N_("To Files");
303
    const char *first_file_msg = N_("First File");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
304
    /* TRANSLATORS: Try to keep this and previous strings at most 16 characters. */
305
    const char *last_file_msg = N_("Last File");
306
#endif
307
#ifndef DISABLE_HELP
308
    const char *nano_cancel_msg = N_("Cancel the current function");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
309
    const char *nano_help_msg = N_("Display this help text");
310
    const char *nano_exit_msg =
311
#ifdef ENABLE_MULTIBUFFER
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
312
	N_("Close the current file buffer/Exit from nano")
313
314
315
316
#else
   	N_("Exit from nano")
#endif
	;
317
318
    const char *nano_writeout_msg =
	N_("Write the current file to disk");
319
320
321
    const char *nano_justify_msg = N_("Justify the current paragraph");
    const char *nano_insert_msg =
	N_("Insert another file into the current one");
322
323
    const char *nano_whereis_msg =
	N_("Search for text within the editor");
324
325
326
327
328
329
    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");
330
    const char *nano_cursorpos_msg =
331
	N_("Display the position of the cursor");
332
333
    const char *nano_spell_msg =
	N_("Invoke the spell checker, if available");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
334
    const char *nano_gotoline_msg = N_("Go to line and column number");
335
    const char *nano_replace_msg = N_("Replace text within the editor");
336
#ifndef NANO_TINY
337
338
    const char *nano_mark_msg = N_("Mark text at the cursor position");
    const char *nano_whereis_next_msg = N_("Repeat last search");
339
#endif
340
341
342
343
    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_forward_msg = N_("Move forward one character");
    const char *nano_back_msg = N_("Move back one character");
344
345
346
347
348
349
    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");
    const char *nano_delete_msg =
	N_("Delete the character under the cursor");
350
351
    const char *nano_backspace_msg =
	N_("Delete the character to the left of the cursor");
352
353
    const char *nano_tab_msg =
	N_("Insert a tab character at the cursor position");
354
355
    const char *nano_enter_msg =
	N_("Insert a carriage return at the cursor position");
356
357
    const char *nano_refresh_msg =
	N_("Refresh (redraw) the current screen");
358
#ifndef NANO_TINY
359
360
    const char *nano_nextword_msg = N_("Move forward one word");
    const char *nano_prevword_msg = N_("Move backward one word");
361
    const char *nano_wordcount_msg =
362
	N_("Count the number of words, lines, and characters");
363
    const char *nano_scrollup_msg =
364
	N_("Scroll up one line without scrolling the cursor");
365
    const char *nano_scrolldown_msg =
366
	N_("Scroll down one line without scrolling the cursor");
367
#endif
368
369
370
371
372
373
#ifndef DISABLE_JUSTIFY
    const char *nano_parabegin_msg =
	N_("Go to the beginning of the current paragraph");
    const char *nano_paraend_msg =
	N_("Go to the end of the current paragraph");
#endif
374
#ifdef ENABLE_MULTIBUFFER
375
    const char *nano_prevfile_msg =
376
	N_("Switch to the previous file buffer");
377
    const char *nano_nextfile_msg =
378
	N_("Switch to the next file buffer");
379
380
#endif
    const char *nano_verbatim_msg = N_("Insert character(s) verbatim");
381
#ifndef NANO_TINY
382
383
384
    const char *nano_cut_till_end_msg =
	N_("Cut from the cursor position to the end of the file");
#endif
385
386
#ifndef DISABLE_JUSTIFY
    const char *nano_fulljustify_msg = N_("Justify the entire file");
387
#endif
388
#ifndef NANO_TINY
389
    const char *nano_bracket_msg = N_("Find matching bracket");
390
#endif
391
392
393
394
    const char *nano_firstline_msg =
	N_("Go to the first line of the file");
    const char *nano_lastline_msg =
	N_("Go to the last line of the file");
395
#ifndef NANO_TINY
396
397
398
399
    const char *nano_case_msg =
	N_("Make the current search/replace case (in)sensitive");
    const char *nano_reverse_msg =
	N_("Make the current search/replace go backwards");
400
#endif
401
402
#ifdef HAVE_REGEX_H
    const char *nano_regexp_msg = N_("Use regular expressions");
403
#endif
404
#ifndef NANO_TINY
405
406
    const char *nano_history_msg =
	N_("Edit the previous search/replace strings");
407
#endif
408
409
#ifndef DISABLE_BROWSER
    const char *nano_tofiles_msg = N_("Go to file browser");
Chris Allegretta's avatar
Chris Allegretta committed
410
#endif
411
#ifndef NANO_TINY
412
413
    const char *nano_dos_msg = N_("Write file out in DOS format");
    const char *nano_mac_msg = N_("Write file out in Mac format");
414
#endif
415
416
    const char *nano_append_msg = N_("Append to the current file");
    const char *nano_prepend_msg = N_("Prepend to the current file");
417
#ifndef NANO_TINY
418
419
    const char *nano_backup_msg =
	N_("Back up original file when saving");
420
    const char *nano_execute_msg = N_("Execute external command");
421
#endif
422
#if !defined(NANO_TINY) && defined(ENABLE_MULTIBUFFER)
423
424
425
    const char *nano_multibuffer_msg = N_("Insert into new buffer");
#endif
#ifndef DISABLE_BROWSER
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
426
    const char *nano_exitbrowser_msg = N_("Exit from the file browser");
427
428
429
430
    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
431
    const char *nano_gotodir_msg = N_("Go to directory");
Chris Allegretta's avatar
Chris Allegretta committed
432
#endif
433
#endif /* !DISABLE_HELP */
Chris Allegretta's avatar
Chris Allegretta committed
434

David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
435
/* The following macro is to be used in calling sc_init_one().  The
436
437
 * point is that sc_init_one() takes 10 arguments, unless DISABLE_HELP
 * is defined, when the 4th one should not be there. */
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
438
#ifndef DISABLE_HELP
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
439
#define IFHELP(help, nextvar) help, nextvar
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
440
#else
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
441
#define IFHELP(help, nextvar) nextvar
442
#endif
443

444
445
446
    free_shortcutage(&main_list);

    sc_init_one(&main_list, NANO_HELP_KEY, get_help_msg,
447
448
	IFHELP(nano_help_msg, FALSE), NANO_NO_KEY, NANO_HELP_FKEY,
	NANO_NO_KEY, VIEW,
449
#ifndef DISABLE_HELP
450
	do_help_void
451
#else
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
452
	nano_disabled_msg
453
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
454
	);
Chris Allegretta's avatar
Chris Allegretta committed
455

456
457
    sc_init_one(&main_list, NANO_EXIT_KEY,
#ifdef ENABLE_MULTIBUFFER
458
	/* TRANSLATORS: Try to keep this at most 10 characters. */
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
459
	openfile != NULL && openfile != openfile->next ? N_("Close") :
460
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
461
	exit_msg, IFHELP(nano_exit_msg, FALSE), NANO_NO_KEY,
462
	NANO_EXIT_FKEY, NANO_NO_KEY, VIEW, do_exit);
Chris Allegretta's avatar
Chris Allegretta committed
463

464
    /* TRANSLATORS: Try to keep this at most 10 characters. */
465
    sc_init_one(&main_list, NANO_WRITEOUT_KEY, N_("WriteOut"),
466
467
	IFHELP(nano_writeout_msg, FALSE), NANO_NO_KEY,
	NANO_WRITEOUT_FKEY, NANO_NO_KEY, NOVIEW, do_writeout_void);
Chris Allegretta's avatar
Chris Allegretta committed
468

469
    /* TRANSLATORS: Try to keep this at most 10 characters. */
470
    sc_init_one(&main_list, NANO_JUSTIFY_KEY, N_("Justify"),
471
	IFHELP(nano_justify_msg, TRUE), NANO_NO_KEY, NANO_JUSTIFY_FKEY,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
472
	NANO_NO_KEY, NOVIEW,
473
#ifndef DISABLE_JUSTIFY
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
474
	do_justify_void
475
#else
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
476
	nano_disabled_msg
477
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
478
	);
479

480
    /* We allow inserting files in view mode if multibuffers are
481
482
483
484
485
     * 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. */

486
    /* TRANSLATORS: Try to keep this at most 10 characters. */
487
    sc_init_one(&main_list, NANO_INSERTFILE_KEY, N_("Read File"),
488
489
	IFHELP(nano_insert_msg, FALSE), NANO_NO_KEY,
	NANO_INSERTFILE_FKEY, NANO_NO_KEY,
490
#ifdef ENABLE_MULTIBUFFER
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
491
	VIEW
492
#else
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
493
	NOVIEW
494
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
495
	, !ISSET(RESTRICTED) ? do_insertfile_void : nano_disabled_msg);
Chris Allegretta's avatar
Chris Allegretta committed
496

497
    sc_init_one(&main_list, NANO_WHEREIS_KEY, whereis_msg,
498
	IFHELP(nano_whereis_msg, FALSE), NANO_NO_KEY, NANO_WHEREIS_FKEY,
499
	NANO_NO_KEY, VIEW, do_search);
Chris Allegretta's avatar
Chris Allegretta committed
500

501
    sc_init_one(&main_list, NANO_PREVPAGE_KEY, prev_page_msg,
502
503
	IFHELP(nano_prevpage_msg, FALSE), NANO_NO_KEY,
	NANO_PREVPAGE_FKEY, NANO_NO_KEY, VIEW, do_page_up);
Chris Allegretta's avatar
Chris Allegretta committed
504

505
    sc_init_one(&main_list, NANO_NEXTPAGE_KEY, next_page_msg,
506
507
	IFHELP(nano_nextpage_msg, TRUE), NANO_NO_KEY,
	NANO_NEXTPAGE_FKEY, NANO_NO_KEY, VIEW, do_page_down);
Chris Allegretta's avatar
Chris Allegretta committed
508

509
    /* TRANSLATORS: Try to keep this at most 10 characters. */
510
    sc_init_one(&main_list, NANO_CUT_KEY, N_("Cut Text"),
511
512
	IFHELP(nano_cut_msg, FALSE), NANO_NO_KEY, NANO_CUT_FKEY,
	NANO_NO_KEY, NOVIEW, do_cut_text);
Chris Allegretta's avatar
Chris Allegretta committed
513

514
    if (unjustify)
515
    /* TRANSLATORS: Try to keep this at most 10 characters. */
516
	sc_init_one(&main_list, NANO_UNJUSTIFY_KEY, N_("UnJustify"),
517
		IFHELP(NULL, FALSE), NANO_NO_KEY, NANO_UNJUSTIFY_FKEY,
518
		NANO_NO_KEY, NOVIEW, NULL);
519
    else
520
    /* TRANSLATORS: Try to keep this at most 10 characters. */
521
	sc_init_one(&main_list, NANO_UNCUT_KEY, N_("UnCut Txt"),
522
523
		IFHELP(nano_uncut_msg, FALSE), NANO_NO_KEY,
		NANO_UNCUT_FKEY, NANO_NO_KEY, NOVIEW, do_uncut_text);
Chris Allegretta's avatar
Chris Allegretta committed
524

525
    /* TRANSLATORS: Try to keep this at most 10 characters. */
526
    sc_init_one(&main_list, NANO_CURSORPOS_KEY, N_("Cur Pos"),
527
528
	IFHELP(nano_cursorpos_msg, FALSE), NANO_NO_KEY,
	NANO_CURSORPOS_FKEY, NANO_NO_KEY, VIEW, do_cursorpos_void);
Chris Allegretta's avatar
Chris Allegretta committed
529

530
531
532
    /* 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. */
533
    /* TRANSLATORS: Try to keep this at most 10 characters. */
534
    sc_init_one(&main_list, NANO_SPELL_KEY, N_("To Spell"),
535
	IFHELP(nano_spell_msg, TRUE), NANO_NO_KEY, NANO_SPELL_FKEY,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
536
	NANO_NO_KEY, NOVIEW,
537
#ifndef DISABLE_SPELLER
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
538
	!ISSET(RESTRICTED) ? do_spell :
539
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
540
	nano_disabled_msg);
541

542
543
544
545
546
#ifndef NANO_TINY
    sc_init_one(&main_list, NANO_NO_KEY, whereis_next_msg,
	IFHELP(nano_whereis_next_msg, FALSE), NANO_WHEREIS_NEXT_KEY,
	NANO_WHEREIS_NEXT_FKEY, NANO_NO_KEY, VIEW, do_research);
#endif
547

548
    sc_init_one(&main_list, NANO_REPLACE_KEY, replace_msg,
549
	IFHELP(nano_replace_msg, FALSE), NANO_ALT_REPLACE_KEY,
550
	NANO_REPLACE_FKEY, NANO_NO_KEY, NOVIEW, do_replace);
Chris Allegretta's avatar
Chris Allegretta committed
551

552
#ifndef NANO_TINY
553
    /* TRANSLATORS: Try to keep this at most 16 characters. */
554
    sc_init_one(&main_list, NANO_MARK_KEY, N_("Mark Text"),
555
	IFHELP(nano_mark_msg, FALSE), NANO_MARK_ALTKEY, NANO_MARK_FKEY,
556
	NANO_NO_KEY, VIEW, do_mark);
557
558
#endif

559
560
561
562
#ifndef NANO_TINY
    sc_init_one(&main_list, NANO_NO_KEY, cut_till_end_msg,
	IFHELP(nano_cut_till_end_msg, TRUE), NANO_CUTTILLEND_ALTKEY,
	NANO_NO_KEY, NANO_NO_KEY, NOVIEW, do_cut_till_end);
563
564
#endif

565
    sc_init_one(&main_list, NANO_FORWARD_KEY, N_("Forward"),
566
567
	IFHELP(nano_forward_msg, FALSE), NANO_NO_KEY, NANO_NO_KEY,
	NANO_NO_KEY, VIEW, do_right);
Chris Allegretta's avatar
Chris Allegretta committed
568

569
    sc_init_one(&main_list, NANO_BACK_KEY, N_("Back"),
570
571
	IFHELP(nano_back_msg, FALSE), NANO_NO_KEY, NANO_NO_KEY,
	NANO_NO_KEY, VIEW, do_left);
572

573
#ifndef NANO_TINY
574
    sc_init_one(&main_list, NANO_NEXTWORD_KEY, N_("Next Word"),
575
	IFHELP(nano_nextword_msg, FALSE), NANO_NO_KEY, NANO_NO_KEY,
576
	NANO_NO_KEY, VIEW, do_next_word_void);
577

578
    sc_init_one(&main_list, NANO_NO_KEY, N_("Prev Word"),
579
580
581
	IFHELP(nano_prevword_msg, FALSE), NANO_PREVWORD_KEY,
	NANO_NO_KEY, NANO_NO_KEY, VIEW, do_prev_word_void);
#endif
582

583
584
585
    sc_init_one(&main_list, NANO_PREVLINE_KEY, N_("Prev Line"),
	IFHELP(nano_prevline_msg, FALSE), NANO_NO_KEY, NANO_NO_KEY,
	NANO_NO_KEY, VIEW, do_up);
586

587
588
589
    sc_init_one(&main_list, NANO_NEXTLINE_KEY, N_("Next Line"),
	IFHELP(nano_nextline_msg, TRUE), NANO_NO_KEY, NANO_NO_KEY,
	NANO_NO_KEY, VIEW, do_down);
590

591
592
593
594
595
    sc_init_one(&main_list, NANO_HOME_KEY, N_("Home"),
	IFHELP(nano_home_msg, FALSE), NANO_NO_KEY, NANO_NO_KEY,
	NANO_NO_KEY, VIEW, do_home);

    sc_init_one(&main_list, NANO_END_KEY, N_("End"),
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
596
	IFHELP(nano_end_msg, FALSE), NANO_NO_KEY, NANO_NO_KEY,
597
	NANO_NO_KEY, VIEW, do_end);
598

599
600
#ifndef DISABLE_JUSTIFY
    sc_init_one(&main_list, NANO_NO_KEY, beg_of_par_msg,
601
602
	IFHELP(nano_parabegin_msg, FALSE), NANO_PARABEGIN_ALTKEY,
	NANO_NO_KEY, NANO_PARABEGIN_ALTKEY2, VIEW, do_para_begin_void);
603
604

    sc_init_one(&main_list, NANO_NO_KEY, end_of_par_msg,
605
606
	IFHELP(nano_paraend_msg, FALSE), NANO_PARAEND_ALTKEY,
	NANO_NO_KEY, NANO_PARAEND_ALTKEY2, VIEW, do_para_end_void);
607
#endif
608

609
    sc_init_one(&main_list, NANO_NO_KEY, first_line_msg,
610
611
	IFHELP(nano_firstline_msg, FALSE), NANO_FIRSTLINE_ALTKEY,
	NANO_NO_KEY, NANO_FIRSTLINE_ALTKEY2, VIEW, do_first_line);
612
613

    sc_init_one(&main_list, NANO_NO_KEY, last_line_msg,
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
	IFHELP(nano_lastline_msg, TRUE), NANO_LASTLINE_ALTKEY,
	NANO_NO_KEY, NANO_LASTLINE_ALTKEY2, VIEW, do_last_line);

#ifndef NANO_TINY
    sc_init_one(&main_list, NANO_NO_KEY, N_("Find Other Bracket"),
	IFHELP(nano_bracket_msg, FALSE), NANO_BRACKET_KEY, NANO_NO_KEY,
	NANO_NO_KEY, VIEW, do_find_bracket);
#endif

    sc_init_one(&main_list, NANO_GOTOLINE_KEY, go_to_line_msg,
	IFHELP(nano_gotoline_msg, FALSE), NANO_GOTOLINE_ALTKEY,
	NANO_GOTOLINE_FKEY, NANO_NO_KEY, VIEW,
	do_gotolinecolumn_void);

#ifndef NANO_TINY
    sc_init_one(&main_list, NANO_NO_KEY, N_("Scroll Up"),
	IFHELP(nano_scrollup_msg, FALSE), NANO_SCROLLUP_KEY,
	NANO_NO_KEY, NANO_SCROLLUP_ALTKEY, VIEW, do_scroll_up);

    sc_init_one(&main_list, NANO_NO_KEY, N_("Scroll Down"),
	IFHELP(nano_scrolldown_msg, TRUE), NANO_SCROLLDOWN_KEY,
	NANO_NO_KEY, NANO_SCROLLDOWN_ALTKEY, VIEW, do_scroll_down);
#endif
637

638
#ifdef ENABLE_MULTIBUFFER
639
    sc_init_one(&main_list, NANO_NO_KEY, N_("Previous File"),
640
641
642
	IFHELP(nano_prevfile_msg, FALSE), NANO_PREVFILE_KEY,
	NANO_NO_KEY, NANO_PREVFILE_ALTKEY, VIEW,
	switch_to_prev_buffer_void);
643

644
    sc_init_one(&main_list, NANO_NO_KEY, N_("Next File"),
645
	IFHELP(nano_nextfile_msg, TRUE), NANO_NEXTFILE_KEY, NANO_NO_KEY,
646
	NANO_NEXTFILE_ALTKEY, VIEW, switch_to_next_buffer_void);
647
#endif
648

649
    sc_init_one(&main_list, NANO_NO_KEY, N_("Verbatim Input"),
650
651
	IFHELP(nano_verbatim_msg, FALSE), NANO_VERBATIM_KEY,
	NANO_NO_KEY, NANO_NO_KEY, NOVIEW, do_verbatim_input);
652

653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
    sc_init_one(&main_list, NANO_TAB_KEY, N_("Tab"),
	IFHELP(nano_tab_msg, FALSE), NANO_NO_KEY, NANO_NO_KEY,
	NANO_NO_KEY, NOVIEW, do_tab);

    sc_init_one(&main_list, NANO_ENTER_KEY, N_("Enter"),
	IFHELP(nano_enter_msg, FALSE), NANO_NO_KEY, NANO_NO_KEY,
	NANO_NO_KEY, NOVIEW, do_enter);

    sc_init_one(&main_list, NANO_DELETE_KEY, N_("Delete"),
	IFHELP(nano_delete_msg, FALSE), NANO_NO_KEY, NANO_NO_KEY,
	NANO_NO_KEY, NOVIEW, do_delete);

    sc_init_one(&main_list, NANO_BACKSPACE_KEY, N_("Backspace"),
	IFHELP(nano_backspace_msg, TRUE), NANO_NO_KEY, NANO_NO_KEY,
	NANO_NO_KEY, NOVIEW, do_backspace);
668

669
670
#ifndef DISABLE_JUSTIFY
    sc_init_one(&main_list, NANO_NO_KEY, fulljstify_msg,
671
	IFHELP(nano_fulljustify_msg, FALSE), NANO_FULLJUSTIFY_ALTKEY,
672
	NANO_NO_KEY, NANO_NO_KEY, NOVIEW, do_full_justify);
673
674
#endif

675
#ifndef NANO_TINY
676
677
678
    sc_init_one(&main_list, NANO_NO_KEY, N_("Word Count"),
	IFHELP(nano_wordcount_msg, FALSE), NANO_WORDCOUNT_KEY,
	NANO_NO_KEY, NANO_NO_KEY, VIEW, do_wordlinechar_count);
679
680
#endif

David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
681
    sc_init_one(&main_list, NANO_REFRESH_KEY, refresh_msg
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
682
#ifndef NANO_TINY
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
683
	, IFHELP(nano_wordcount_msg, TRUE)
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
684
#else
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
685
	, IFHELP(nano_wordcount_msg, FALSE)
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
686
687
#endif
	, NANO_NO_KEY, NANO_NO_KEY, NANO_NO_KEY, VIEW, total_refresh);
688

689
    free_shortcutage(&whereis_list);
690

691
    sc_init_one(&whereis_list, NANO_HELP_KEY, get_help_msg,
692
693
	IFHELP(nano_help_msg, FALSE), NANO_NO_KEY, NANO_HELP_FKEY,
	NANO_NO_KEY, VIEW,
694
#ifndef DISABLE_HELP
695
	do_help_void
696
#else
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
697
	nano_disabled_msg
698
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
699
	);
700

701
    sc_init_one(&whereis_list, NANO_CANCEL_KEY, cancel_msg,
702
703
	IFHELP(nano_cancel_msg, FALSE), NANO_NO_KEY, NANO_NO_KEY,
	NANO_NO_KEY, VIEW, NULL);
704

705
    sc_init_one(&whereis_list, NANO_FIRSTLINE_KEY, first_line_msg,
706
	IFHELP(nano_firstline_msg, FALSE), NANO_FIRSTLINE_ALTKEY,
707
708
	NANO_FIRSTLINE_FKEY, NANO_FIRSTLINE_ALTKEY2, VIEW,
	do_first_line);
Chris Allegretta's avatar
Chris Allegretta committed
709

710
    sc_init_one(&whereis_list, NANO_LASTLINE_KEY, last_line_msg,
711
	IFHELP(nano_lastline_msg, FALSE), NANO_LASTLINE_ALTKEY,
712
	NANO_LASTLINE_FKEY, NANO_LASTLINE_ALTKEY2, VIEW, do_last_line);
Chris Allegretta's avatar
Chris Allegretta committed
713

714
    sc_init_one(&whereis_list, NANO_TOOTHERSEARCH_KEY, replace_msg,
715
	IFHELP(nano_replace_msg, FALSE), NANO_NO_KEY, NANO_REPLACE_FKEY,
716
	NANO_NO_KEY, VIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
717

718
    sc_init_one(&whereis_list, NANO_TOGOTOLINE_KEY, go_to_line_msg,
719
720
	IFHELP(nano_gotoline_msg, FALSE), NANO_NO_KEY,
	NANO_GOTOLINE_FKEY, NANO_NO_KEY, VIEW, NULL);
721

722
#ifndef DISABLE_JUSTIFY
723
    sc_init_one(&whereis_list, NANO_PARABEGIN_KEY, beg_of_par_msg,
724
725
	IFHELP(nano_parabegin_msg, FALSE), NANO_PARABEGIN_ALTKEY,
	NANO_NO_KEY, NANO_PARABEGIN_ALTKEY2, VIEW, do_para_begin_void);
726

727
    sc_init_one(&whereis_list, NANO_PARAEND_KEY, end_of_par_msg,
728
729
	IFHELP(nano_paraend_msg, FALSE), NANO_PARAEND_ALTKEY,
	NANO_NO_KEY, NANO_PARAEND_ALTKEY2, VIEW, do_para_end_void);
730
731
#endif

732
#ifndef NANO_TINY
733
    sc_init_one(&whereis_list, NANO_NO_KEY, case_sens_msg,
734
	IFHELP(nano_case_msg, FALSE), TOGGLE_CASE_KEY, NANO_NO_KEY,
735
	NANO_NO_KEY, VIEW, NULL);
736

737
    sc_init_one(&whereis_list, NANO_NO_KEY, backwards_msg,
738
739
	IFHELP(nano_reverse_msg, FALSE), TOGGLE_BACKWARDS_KEY,
	NANO_NO_KEY, NANO_NO_KEY, VIEW, NULL);
740
#endif
Chris Allegretta's avatar
Chris Allegretta committed
741

742
#ifdef HAVE_REGEX_H
743
    sc_init_one(&whereis_list, NANO_NO_KEY, regexp_msg,
744
	IFHELP(nano_regexp_msg, FALSE), NANO_REGEXP_KEY, NANO_NO_KEY,
745
	NANO_NO_KEY, VIEW, NULL);
746
#endif
747

748
#ifndef NANO_TINY
749
    sc_init_one(&whereis_list, NANO_PREVLINE_KEY, history_msg,
750
751
	IFHELP(nano_history_msg, FALSE), NANO_NO_KEY, NANO_NO_KEY,
	NANO_NO_KEY, VIEW, NULL);
752
753

    sc_init_one(&whereis_list, NANO_CUTTILLEND_KEY, cut_till_end_msg,
754
	IFHELP(nano_cut_till_end_msg, FALSE), NANO_CUTTILLEND_ALTKEY,
755
	NANO_NO_KEY, NANO_NO_KEY, NOVIEW, do_cut_till_end);
756
#endif
757
758
759

#ifndef DISABLE_JUSTIFY
    sc_init_one(&whereis_list, NANO_FULLJUSTIFY_KEY, fulljstify_msg,
760
	IFHELP(nano_fulljustify_msg, FALSE), NANO_FULLJUSTIFY_ALTKEY,
761
762
	NANO_NO_KEY, NANO_NO_KEY, NOVIEW, do_full_justify);
#endif
763

764
    free_shortcutage(&replace_list);
765

766
    sc_init_one(&replace_list, NANO_HELP_KEY, get_help_msg,
767
768
	IFHELP(nano_help_msg, FALSE), NANO_NO_KEY, NANO_HELP_FKEY,
	NANO_NO_KEY, VIEW,
769
#ifndef DISABLE_HELP
770
	do_help_void
771
#else
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
772
	nano_disabled_msg
773
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
774
	);
775

776
    sc_init_one(&replace_list, NANO_CANCEL_KEY, cancel_msg,
777
778
	IFHELP(nano_cancel_msg, FALSE), NANO_NO_KEY, NANO_NO_KEY,
	NANO_NO_KEY, VIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
779

780
    sc_init_one(&replace_list, NANO_FIRSTLINE_KEY, first_line_msg,
781
	IFHELP(nano_firstline_msg, FALSE), NANO_FIRSTLINE_ALTKEY,
782
783
	NANO_FIRSTLINE_FKEY, NANO_FIRSTLINE_ALTKEY2, VIEW,
	do_first_line);
Chris Allegretta's avatar
Chris Allegretta committed
784

785
    sc_init_one(&replace_list, NANO_LASTLINE_KEY, last_line_msg,
786
	IFHELP(nano_lastline_msg, FALSE), NANO_LASTLINE_ALTKEY,
787
	NANO_LASTLINE_FKEY, NANO_LASTLINE_ALTKEY2, VIEW, do_last_line);
Chris Allegretta's avatar
Chris Allegretta committed
788

789
    /* TRANSLATORS: Try to keep this at most 12 characters. */
790
    sc_init_one(&replace_list, NANO_TOOTHERSEARCH_KEY, N_("No Replace"),
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
791
792
	IFHELP(nano_whereis_msg, FALSE), NANO_NO_KEY, NANO_REPLACE_FKEY,
	NANO_NO_KEY, VIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
793

794
    sc_init_one(&replace_list, NANO_TOGOTOLINE_KEY, go_to_line_msg,
795
796
	IFHELP(nano_gotoline_msg, FALSE), NANO_NO_KEY,
	NANO_GOTOLINE_FKEY, NANO_NO_KEY, VIEW, NULL);
797

798
#ifndef NANO_TINY
799
    sc_init_one(&replace_list, NANO_NO_KEY, case_sens_msg,
800
	IFHELP(nano_case_msg, FALSE), TOGGLE_CASE_KEY, NANO_NO_KEY,
801
	NANO_NO_KEY, VIEW, NULL);
802

803
    sc_init_one(&replace_list, NANO_NO_KEY, backwards_msg,
804
805
	IFHELP(nano_reverse_msg, FALSE), TOGGLE_BACKWARDS_KEY,
	NANO_NO_KEY, NANO_NO_KEY, VIEW, NULL);
806
#endif
807

808
#ifdef HAVE_REGEX_H
809
    sc_init_one(&replace_list, NANO_NO_KEY, regexp_msg,
810
	IFHELP(nano_regexp_msg, FALSE), NANO_REGEXP_KEY, NANO_NO_KEY,
811
	NANO_NO_KEY, VIEW, NULL);
812
#endif
813

814
#ifndef NANO_TINY
815
    sc_init_one(&replace_list, NANO_PREVLINE_KEY, history_msg,
816
817
	IFHELP(nano_history_msg, FALSE), NANO_NO_KEY, NANO_NO_KEY,
	NANO_NO_KEY, VIEW, NULL);
818
#endif
819

820
    free_shortcutage(&replace_list_2);
821

822
    sc_init_one(&replace_list_2, NANO_HELP_KEY, get_help_msg,
823
824
	IFHELP(nano_help_msg, FALSE), NANO_NO_KEY, NANO_HELP_FKEY,
	NANO_NO_KEY, VIEW,
825
#ifndef DISABLE_HELP
826
	do_help_void
827
#else
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
828
	nano_disabled_msg
829
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
830
	);
831

832
    sc_init_one(&replace_list_2, NANO_CANCEL_KEY, cancel_msg,
833
834
	IFHELP(nano_cancel_msg, FALSE), NANO_NO_KEY, NANO_NO_KEY,
	NANO_NO_KEY, VIEW, NULL);
835

836
    sc_init_one(&replace_list_2, NANO_FIRSTLINE_KEY, first_line_msg,
837
	IFHELP(nano_firstline_msg, FALSE), NANO_FIRSTLINE_ALTKEY,
838
839
	NANO_FIRSTLINE_FKEY, NANO_FIRSTLINE_ALTKEY2, VIEW,
	do_first_line);
840

841
    sc_init_one(&replace_list_2, NANO_LASTLINE_KEY, last_line_msg,
842
	IFHELP(nano_lastline_msg, FALSE), NANO_LASTLINE_ALTKEY,
843
	NANO_LASTLINE_FKEY, NANO_LASTLINE_ALTKEY2, VIEW, do_last_line);
844

845
#ifndef NANO_TINY
846
    sc_init_one(&replace_list_2, NANO_PREVLINE_KEY, history_msg,
847
848
	IFHELP(nano_history_msg, FALSE), NANO_NO_KEY, NANO_NO_KEY,
	NANO_NO_KEY, VIEW, NULL);
849
850
#endif

851
    free_shortcutage(&gotoline_list);
Chris Allegretta's avatar
Chris Allegretta committed
852

853
    sc_init_one(&gotoline_list, NANO_HELP_KEY, get_help_msg,
854
855
	IFHELP(nano_help_msg, FALSE), NANO_NO_KEY, NANO_HELP_FKEY,
	NANO_NO_KEY, VIEW,
856
#ifndef DISABLE_HELP
857
	do_help_void
858
#else
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
859
	nano_disabled_msg
860
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
861
	);
862

863
    sc_init_one(&gotoline_list, NANO_CANCEL_KEY, cancel_msg,
864
865
	IFHELP(nano_cancel_msg, FALSE), NANO_NO_KEY, NANO_NO_KEY,
	NANO_NO_KEY, VIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
866

867
    sc_init_one(&gotoline_list, NANO_FIRSTLINE_KEY, first_line_msg,
868
	IFHELP(nano_firstline_msg, FALSE), NANO_FIRSTLINE_ALTKEY,
869
870
	NANO_FIRSTLINE_FKEY, NANO_FIRSTLINE_ALTKEY2, VIEW,
	do_first_line);
Chris Allegretta's avatar
Chris Allegretta committed
871

872
    sc_init_one(&gotoline_list, NANO_LASTLINE_KEY, last_line_msg,
873
	IFHELP(nano_lastline_msg, FALSE), NANO_LASTLINE_ALTKEY,
874
	NANO_LASTLINE_FKEY, NANO_LASTLINE_ALTKEY2, VIEW, do_last_line);
Chris Allegretta's avatar
Chris Allegretta committed
875

876
    sc_init_one(&gotoline_list, NANO_TOOTHERWHEREIS_KEY,
877
	N_("Go To Text"), IFHELP(nano_whereis_msg, FALSE), NANO_NO_KEY,
878
	NANO_NO_KEY, NANO_NO_KEY, VIEW, NULL);
879

880
    free_shortcutage(&writefile_list);
Chris Allegretta's avatar
Chris Allegretta committed
881

882
    sc_init_one(&writefile_list, NANO_HELP_KEY, get_help_msg,
883
884
	IFHELP(nano_help_msg, FALSE), NANO_NO_KEY, NANO_HELP_FKEY,
	NANO_NO_KEY, VIEW,
885
#ifndef DISABLE_HELP
886
	do_help_void
887
#else
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
888
	nano_disabled_msg
889
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
890
	);
891

892
    sc_init_one(&writefile_list, NANO_CANCEL_KEY, cancel_msg,
893
894
	IFHELP(nano_cancel_msg, FALSE), NANO_NO_KEY, NANO_NO_KEY,
	NANO_NO_KEY, VIEW, NULL);
895

896
#ifndef DISABLE_BROWSER
897
898
    /* If we're using restricted mode, the file browser is disabled.
     * It's useless since inserting files is disabled. */
899

900
    if (!ISSET(RESTRICTED))
901
	sc_init_one(&writefile_list, NANO_TOFILES_KEY, to_files_msg,
902
903
		IFHELP(nano_tofiles_msg, FALSE), NANO_NO_KEY,
		NANO_NO_KEY, NANO_NO_KEY, NOVIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
904
#endif
Chris Allegretta's avatar
Chris Allegretta committed
905

906
#ifndef NANO_TINY
907
908
909
910
911
912
    /* 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. */
913

914
    if (!ISSET(RESTRICTED))
915
	/* TRANSLATORS: Try to keep this at most 16 characters. */
916
	sc_init_one(&writefile_list, NANO_NO_KEY, N_("DOS Format"),
917
918
		IFHELP(nano_dos_msg, FALSE), TOGGLE_DOS_KEY,
		NANO_NO_KEY, NANO_NO_KEY, NOVIEW, NULL);
919

920
    if (!ISSET(RESTRICTED))
921
	/* TRANSLATORS: Try to keep this at most 16 characters. */
922
	sc_init_one(&writefile_list, NANO_NO_KEY, N_("Mac Format"),
923
924
		IFHELP(nano_mac_msg, FALSE), TOGGLE_MAC_KEY,
		NANO_NO_KEY, NANO_NO_KEY, NOVIEW, NULL);
925
926
#endif

927
    if (!ISSET(RESTRICTED))
928
	/* TRANSLATORS: Try to keep this at most 16 characters. */
929
	sc_init_one(&writefile_list, NANO_NO_KEY, N_("Append"),
930
931
		IFHELP(nano_append_msg, FALSE), NANO_APPEND_KEY,
		NANO_NO_KEY, NANO_NO_KEY, NOVIEW, NULL);
932

933
    if (!ISSET(RESTRICTED))
934
	/* TRANSLATORS: Try to keep this at most 16 characters. */
935
	sc_init_one(&writefile_list, NANO_NO_KEY, N_("Prepend"),
936
937
		IFHELP(nano_prepend_msg, FALSE), NANO_PREPEND_KEY,
		NANO_NO_KEY, NANO_NO_KEY, NOVIEW, NULL);
938

939
#ifndef NANO_TINY
940
    if (!ISSET(RESTRICTED))
941
	/* TRANSLATORS: Try to keep this at most 16 characters. */
942
	sc_init_one(&writefile_list, NANO_NO_KEY, N_("Backup File"),
943
944
		IFHELP(nano_backup_msg, FALSE), TOGGLE_BACKUP_KEY,
		NANO_NO_KEY, NANO_NO_KEY, NOVIEW, NULL);
945
946
#endif

947
    free_shortcutage(&insertfile_list);
948

949
    sc_init_one(&insertfile_list, NANO_HELP_KEY, get_help_msg,
950
951
	IFHELP(nano_help_msg, FALSE), NANO_NO_KEY, NANO_HELP_FKEY,
	NANO_NO_KEY, VIEW,
952
#ifndef DISABLE_HELP
953
	do_help_void
954
#else
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
955
	nano_disabled_msg
956
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
957
	);
958

959
    sc_init_one(&insertfile_list, NANO_CANCEL_KEY, cancel_msg,
960
961
	IFHELP(nano_cancel_msg, FALSE), NANO_NO_KEY, NANO_NO_KEY,
	NANO_NO_KEY, VIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
962

963
#ifndef DISABLE_BROWSER
964
965
    /* If we're using restricted mode, the file browser is disabled.
     * It's useless since inserting files is disabled. */
966
    if (!ISSET(RESTRICTED))
967
	sc_init_one(&insertfile_list, NANO_TOFILES_KEY, to_files_msg,
968
969
		IFHELP(nano_tofiles_msg, FALSE), NANO_NO_KEY,
		NANO_NO_KEY, NANO_NO_KEY, NOVIEW, NULL);
970
#endif
971

972
#ifndef NANO_TINY
973
974
    /* If we're using restricted mode, command execution is disabled.
     * It's useless since inserting files is disabled. */
975

976
    if (!ISSET(RESTRICTED))
977
	sc_init_one(&insertfile_list, NANO_TOOTHERINSERT_KEY,
978
		/* TRANSLATORS: Try to keep this at most 22 characters. */
979
980
		N_("Execute Command"), IFHELP(nano_execute_msg, FALSE),
		NANO_NO_KEY, NANO_NO_KEY, NANO_NO_KEY, NOVIEW, NULL);
981

982
#ifdef ENABLE_MULTIBUFFER
983
984
    /* If we're using restricted mode, the multibuffer toggle is
     * disabled.  It's useless since inserting files is disabled. */
985

986
    if (!ISSET(RESTRICTED))
987
	sc_init_one(&insertfile_list, NANO_NO_KEY, new_buffer_msg,
988
989
990
		IFHELP(nano_multibuffer_msg, FALSE),
		TOGGLE_MULTIBUFFER_KEY, NANO_NO_KEY, NANO_NO_KEY,
		NOVIEW, NULL);
991
#endif
992
#endif
993

994
#ifndef NANO_TINY
995
    free_shortcutage(&extcmd_list);
Chris Allegretta's avatar
Chris Allegretta committed
996

997
    sc_init_one(&extcmd_list, NANO_HELP_KEY, get_help_msg,
998
999
	IFHELP(nano_help_msg, FALSE), NANO_NO_KEY, NANO_HELP_FKEY,
	NANO_NO_KEY, VIEW,
1000
#ifndef DISABLE_HELP
1001
	do_help_void
1002
#else
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1003
	nano_disabled_msg
1004
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1005
	);
1006

1007
    sc_init_one(&extcmd_list, NANO_CANCEL_KEY, cancel_msg,
1008
1009
	IFHELP(nano_cancel_msg, FALSE), NANO_NO_KEY, NANO_NO_KEY,
	NANO_NO_KEY, VIEW, NULL);
1010

1011
    sc_init_one(&extcmd_list, NANO_TOOTHERINSERT_KEY, N_("Insert File"),
1012
	IFHELP(nano_insert_msg, FALSE), NANO_NO_KEY, NANO_NO_KEY,
1013
	NANO_NO_KEY, VIEW, NULL);
1014

David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1015
#ifdef ENABLE_MULTIBUFFER
1016
    sc_init_one(&extcmd_list, NANO_NO_KEY, new_buffer_msg,
1017
	IFHELP(nano_multibuffer_msg, FALSE), TOGGLE_MULTIBUFFER_KEY,
1018
	NANO_NO_KEY, NANO_NO_KEY, NOVIEW, NULL);
1019
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1020
#endif
1021

1022
1023
1024
1025
#ifndef DISABLE_HELP
    free_shortcutage(&help_list);

    sc_init_one(&help_list, NANO_REFRESH_KEY, refresh_msg,
1026
1027
	IFHELP(nano_refresh_msg, FALSE), NANO_NO_KEY, NANO_NO_KEY,
	NANO_NO_KEY, VIEW, NULL);
1028
1029

    sc_init_one(&help_list, NANO_EXIT_KEY, exit_msg,
1030
1031
	IFHELP(nano_exit_msg, FALSE), NANO_NO_KEY, NANO_EXIT_FKEY,
	NANO_NO_KEY, VIEW, NULL);
1032
1033

    sc_init_one(&help_list, NANO_PREVPAGE_KEY, prev_page_msg,
1034
1035
	IFHELP(nano_prevpage_msg, FALSE), NANO_NO_KEY,
	NANO_PREVPAGE_FKEY, NANO_NO_KEY, VIEW, NULL);
1036
1037

    sc_init_one(&help_list, NANO_NEXTPAGE_KEY, next_page_msg,
1038
1039
	IFHELP(nano_nextpage_msg, FALSE), NANO_NO_KEY,
	NANO_NEXTPAGE_FKEY, NANO_NO_KEY, VIEW, NULL);
1040
1041

    sc_init_one(&help_list, NANO_PREVLINE_KEY, N_("Prev Line"),
1042
	IFHELP(nano_prevline_msg, FALSE), NANO_NO_KEY, NANO_NO_KEY,
1043
1044
1045
	NANO_NO_KEY, VIEW, NULL);

    sc_init_one(&help_list, NANO_NEXTLINE_KEY, N_("Next Line"),
1046
	IFHELP(nano_nextline_msg, FALSE), NANO_NO_KEY, NANO_NO_KEY,
1047
1048
1049
1050
1051
1052
1053
	NANO_NO_KEY, VIEW, NULL);
#endif

#ifndef DISABLE_SPELLER
    free_shortcutage(&spell_list);

    sc_init_one(&spell_list, NANO_HELP_KEY, get_help_msg,
1054
1055
	IFHELP(nano_help_msg, FALSE), NANO_NO_KEY, NANO_HELP_FKEY,
	NANO_NO_KEY, VIEW,
1056
#ifndef DISABLE_HELP
1057
	do_help_void
1058
#else
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1059
	nano_disabled_msg
1060
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1061
	);
1062
1063

    sc_init_one(&spell_list, NANO_CANCEL_KEY, cancel_msg,
1064
1065
	IFHELP(nano_cancel_msg, FALSE), NANO_NO_KEY, NANO_NO_KEY,
	NANO_NO_KEY, VIEW, NULL);
1066
1067
#endif

1068
#ifndef DISABLE_BROWSER
1069
    free_shortcutage(&browser_list);
1070

1071
    sc_init_one(&browser_list, NANO_HELP_KEY, get_help_msg,
1072
1073
	IFHELP(nano_help_msg, FALSE), NANO_NO_KEY, NANO_HELP_FKEY,
	NANO_NO_KEY, VIEW, NULL);
1074

1075
    sc_init_one(&browser_list, NANO_EXIT_KEY, exit_msg,
1076
1077
	IFHELP(nano_exitbrowser_msg, FALSE), NANO_NO_KEY,
	NANO_EXIT_FKEY, NANO_NO_KEY, VIEW, NULL);
1078

1079
    sc_init_one(&browser_list, NANO_PREVPAGE_KEY, prev_page_msg,
1080
1081
	IFHELP(nano_prevpage_msg, FALSE), NANO_NO_KEY,
	NANO_PREVPAGE_FKEY, NANO_NO_KEY, VIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
1082

1083
    sc_init_one(&browser_list, NANO_NEXTPAGE_KEY, next_page_msg,
1084
1085
	IFHELP(nano_nextpage_msg, FALSE), NANO_NO_KEY,
	NANO_NEXTPAGE_FKEY, NANO_NO_KEY, VIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
1086

1087
    sc_init_one(&browser_list, NANO_WHEREIS_KEY, whereis_msg,
1088
1089
	IFHELP(nano_whereis_msg, FALSE), NANO_NO_KEY, NANO_NO_KEY,
	NANO_NO_KEY, VIEW, NULL);
1090
1091

    sc_init_one(&browser_list, NANO_NO_KEY, whereis_next_msg,
1092
	IFHELP(nano_whereis_next_msg, FALSE), NANO_WHEREIS_NEXT_KEY,
1093
1094
	NANO_WHEREIS_NEXT_FKEY, NANO_NO_KEY, VIEW, NULL);

1095
    /* TRANSLATORS: Try to keep this at most 22 characters. */
1096
    sc_init_one(&browser_list, NANO_GOTOLINE_KEY, N_("Go To Dir"),
1097
	IFHELP(nano_gotodir_msg, FALSE), NANO_GOTOLINE_ALTKEY,
1098
	NANO_GOTOLINE_FKEY, NANO_NO_KEY, VIEW, NULL);
Rocco Corsi's avatar
   
Rocco Corsi committed
1099

1100
1101
1102
    free_shortcutage(&whereis_file_list);

    sc_init_one(&whereis_file_list, NANO_HELP_KEY, get_help_msg,
1103
1104
	IFHELP(nano_help_msg, FALSE), NANO_NO_KEY, NANO_HELP_FKEY,
	NANO_NO_KEY, VIEW,
1105
1106
1107
1108
1109
1110
1111
1112
#ifndef DISABLE_HELP
	do_browser_help
#else
	nano_disabled_msg
#endif
	);

    sc_init_one(&whereis_file_list, NANO_CANCEL_KEY, cancel_msg,
1113
1114
	IFHELP(nano_cancel_msg, FALSE), NANO_NO_KEY, NANO_NO_KEY,
	NANO_NO_KEY, VIEW, NULL);
1115
1116

    sc_init_one(&whereis_file_list, NANO_FIRSTFILE_KEY, first_file_msg,
1117
	IFHELP(nano_firstfile_msg, FALSE), NANO_FIRSTFILE_ALTKEY,
1118
1119
	NANO_FIRSTFILE_FKEY, NANO_FIRSTFILE_ALTKEY2, VIEW,
	do_first_file);
1120
1121

    sc_init_one(&whereis_file_list, NANO_LASTFILE_KEY, last_file_msg,
1122
	IFHELP(nano_lastfile_msg, FALSE), NANO_LASTFILE_ALTKEY,
1123
	NANO_LASTFILE_FKEY, NANO_LASTFILE_ALTKEY2, VIEW, do_last_file);
1124
1125
1126

#ifndef NANO_SMALL
    sc_init_one(&whereis_file_list, NANO_NO_KEY, case_sens_msg,
1127
	IFHELP(nano_case_msg, FALSE), TOGGLE_CASE_KEY, NANO_NO_KEY,
1128
1129
1130
	NANO_NO_KEY, VIEW, NULL);

    sc_init_one(&whereis_file_list, NANO_NO_KEY, backwards_msg,
1131
1132
	IFHELP(nano_reverse_msg, FALSE), TOGGLE_BACKWARDS_KEY,
	NANO_NO_KEY, NANO_NO_KEY, VIEW, NULL);
1133
1134
1135
1136
#endif

#ifdef HAVE_REGEX_H
    sc_init_one(&whereis_file_list, NANO_NO_KEY, regexp_msg,
1137
	IFHELP(nano_regexp_msg, FALSE), NANO_REGEXP_KEY, NANO_NO_KEY,
1138
1139
1140
1141
1142
	NANO_NO_KEY, VIEW, NULL);
#endif

#ifndef NANO_SMALL
    sc_init_one(&whereis_file_list, NANO_PREVLINE_KEY, history_msg,
1143
1144
	IFHELP(nano_history_msg, FALSE), NANO_NO_KEY, NANO_NO_KEY,
	NANO_NO_KEY, VIEW, NULL);
1145
1146
#endif

1147
    free_shortcutage(&gotodir_list);
1148

1149
    sc_init_one(&gotodir_list, NANO_HELP_KEY, get_help_msg,
1150
1151
	IFHELP(nano_help_msg, FALSE), NANO_NO_KEY, NANO_HELP_FKEY,
	NANO_NO_KEY, VIEW,
1152
#ifndef DISABLE_HELP
1153
	do_help_void
1154
#else
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1155
	nano_disabled_msg
1156
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1157
	);
Chris Allegretta's avatar
Chris Allegretta committed
1158

1159
    sc_init_one(&gotodir_list, NANO_CANCEL_KEY, cancel_msg,
1160
1161
	IFHELP(nano_cancel_msg, FALSE), NANO_NO_KEY, NANO_NO_KEY,
	NANO_NO_KEY, VIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
1162
1163
#endif

1164
    currshortcut = main_list;
1165

1166
#ifndef NANO_TINY
1167
    toggle_init();
1168
#endif
1169
}
1170

1171
/* Free the given shortcut. */
1172
1173
1174
void free_shortcutage(shortcut **shortcutage)
{
    assert(shortcutage != NULL);
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1175

1176
1177
1178
1179
1180
1181
1182
    while (*shortcutage != NULL) {
	shortcut *ps = *shortcutage;
	*shortcutage = (*shortcutage)->next;
	free(ps);
    }
}

1183
#ifndef NANO_TINY
1184
/* Add a new toggle to the end of the global toggle list. */
1185
1186
void toggle_init_one(int val, const char *desc, bool blank_after, long
	flag)
1187
1188
1189
1190
{
    toggle *u;

    if (toggles == NULL) {
1191
	toggles = (toggle *)nmalloc(sizeof(toggle));
1192
1193
1194
1195
	u = toggles;
    } else {
	for (u = toggles; u->next != NULL; u = u->next)
	    ;
1196
	u->next = (toggle *)nmalloc(sizeof(toggle));
1197
1198
1199
1200
	u = u->next;
    }

    u->val = val;
1201
    u->desc = (desc == NULL) ? "" : _(desc);
1202
    u->blank_after = blank_after;
1203
1204
1205
1206
    u->flag = flag;
    u->next = NULL;
}

1207
/* Initialize the global toggle list. */
1208
1209
1210
1211
1212
1213
1214
void toggle_init(void)
{
    /* There is no need to reinitialize the toggles.  They can't
     * change. */
    if (toggles != NULL)
	return;

1215
    toggle_init_one(TOGGLE_NOHELP_KEY, N_("Help mode"), FALSE, NO_HELP);
1216

1217
    toggle_init_one(TOGGLE_CONST_KEY,
1218
	N_("Constant cursor position display"), FALSE, CONST_UPDATE);
1219
1220

    toggle_init_one(TOGGLE_MORESPACE_KEY,
1221
	N_("Use of more space for editing"), FALSE, MORE_SPACE);
1222

1223
    toggle_init_one(TOGGLE_SMOOTH_KEY, N_("Smooth scrolling"), FALSE,
1224
1225
1226
1227
	SMOOTH_SCROLL);

#ifdef ENABLE_NANORC
    toggle_init_one(TOGGLE_WHITESPACE_KEY, N_("Whitespace display"),
1228
	FALSE, WHITESPACE_DISPLAY);
1229
#endif
1230
1231
1232

#ifdef ENABLE_COLOR
    toggle_init_one(TOGGLE_SYNTAX_KEY, N_("Color syntax highlighting"),
1233
	TRUE, NO_COLOR_SYNTAX);
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1234
#endif
1235

1236
    toggle_init_one(TOGGLE_SMARTHOME_KEY, N_("Smart home key"), FALSE,
1237
1238
	SMART_HOME);

1239
    toggle_init_one(TOGGLE_AUTOINDENT_KEY, N_("Auto indent"), FALSE,
1240
1241
	AUTOINDENT);

1242
1243
    toggle_init_one(TOGGLE_CUTTOEND_KEY, N_("Cut to end"), FALSE,
	CUT_TO_END);
1244

1245
#ifndef DISABLE_WRAPPING
1246
    toggle_init_one(TOGGLE_WRAP_KEY, N_("Long line wrapping"), FALSE,
1247
	NO_WRAP);
1248
#endif
1249

1250
    toggle_init_one(TOGGLE_TABSTOSPACES_KEY,
1251
	N_("Conversion of typed tabs to spaces"), TRUE, TABS_TO_SPACES);
1252

1253
1254
1255
    /* If we're using restricted mode, the backup toggle is disabled.
     * It's useless since backups are disabled. */
    if (!ISSET(RESTRICTED))
1256
	toggle_init_one(TOGGLE_BACKUP_KEY, N_("Backup files"), FALSE,
1257
		BACKUP_FILE);
1258
1259
1260
1261
1262
1263

#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,
1264
		N_("Multiple file buffers"), FALSE, MULTIBUFFER);
1265
#endif
1266

1267
#ifndef DISABLE_MOUSE
1268
1269
    toggle_init_one(TOGGLE_MOUSE_KEY, N_("Mouse support"), FALSE,
	USE_MOUSE);
1270
1271
#endif

1272
1273
1274
1275
    /* 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,
1276
1277
		N_("No conversion from DOS/Mac format"), FALSE,
		NO_CONVERT);
1278
1279
1280
1281

    /* If we're using restricted mode, the suspend toggle is disabled.
     * It's useless since suspending is disabled. */
    if (!ISSET(RESTRICTED))
1282
1283
	toggle_init_one(TOGGLE_SUSPEND_KEY, N_("Suspend"), FALSE,
	SUSPEND);
1284
}
1285
#endif /* !NANO_TINY */
1286

1287
1288
1289
#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
1290
1291
 * 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
1292
1293
 * function unless debugging is turned on. */
void thanks_for_all_the_fish(void)
1294
{
1295
1296
1297
1298
    delwin(topwin);
    delwin(edit);
    delwin(bottomwin);

Chris Allegretta's avatar
Chris Allegretta committed
1299
1300
1301
#ifndef DISABLE_JUSTIFY
    if (quotestr != NULL)
	free(quotestr);
1302
1303
#ifdef HAVE_REGEX_H
    regfree(&quotereg);
1304
1305
    if (quoteerr != NULL)
	free(quoteerr);
1306
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1307
#endif
1308
#ifndef NANO_TINY
1309
1310
1311
    if (backup_dir != NULL)
        free(backup_dir);
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1312
#ifndef DISABLE_OPERATINGDIR
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
    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);
1325
#endif
1326
1327
1328
    if (answer != NULL)
	free(answer);
    if (cutbuffer != NULL)
Chris Allegretta's avatar
Chris Allegretta committed
1329
	free_filestruct(cutbuffer);
1330
1331
1332
1333
#ifndef DISABLE_JUSTIFY
    if (jusbuffer != NULL)
	free_filestruct(jusbuffer);
#endif
1334
1335
1336
1337
    free_shortcutage(&main_list);
    free_shortcutage(&whereis_list);
    free_shortcutage(&replace_list);
    free_shortcutage(&replace_list_2);
1338
    free_shortcutage(&gotoline_list);
1339
1340
    free_shortcutage(&writefile_list);
    free_shortcutage(&insertfile_list);
1341
1342
1343
#ifndef NANO_TINY
    free_shortcutage(&extcmd_list);
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1344
#ifndef DISABLE_HELP
Chris Allegretta's avatar
Chris Allegretta committed
1345
    free_shortcutage(&help_list);
Chris Allegretta's avatar
Chris Allegretta committed
1346
1347
#endif
#ifndef DISABLE_SPELLER
1348
    free_shortcutage(&spell_list);
Chris Allegretta's avatar
Chris Allegretta committed
1349
#endif
1350
1351
#ifndef DISABLE_BROWSER
    free_shortcutage(&browser_list);
Chris Allegretta's avatar
Chris Allegretta committed
1352
    free_shortcutage(&gotodir_list);
1353
#endif
1354
#ifndef NANO_TINY
1355
    /* Free the memory associated with each toggle. */
1356
1357
    while (toggles != NULL) {
	toggle *t = toggles;
1358

1359
1360
1361
1362
	toggles = toggles->next;
	free(t);
    }
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1363
    /* Free the memory associated with each open file buffer. */
1364
    if (openfile != NULL)
1365
	free_openfilestruct(openfile);
Chris Allegretta's avatar
Chris Allegretta committed
1366
#ifdef ENABLE_COLOR
1367
1368
    if (syntaxstr != NULL)
	free(syntaxstr);
Chris Allegretta's avatar
Chris Allegretta committed
1369
1370
1371
1372
1373
1374
1375
1376
    while (syntaxes != NULL) {
	syntaxtype *bill = syntaxes;

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

	    syntaxes->extensions = bob->next;
1377
	    free(bob->ext_regex);
1378
1379
1380
1381
	    if (bob->ext != NULL) {
		regfree(bob->ext);
		free(bob->ext);
	    }
Chris Allegretta's avatar
Chris Allegretta committed
1382
1383
1384
1385
1386
1387
	    free(bob);
	}
	while (syntaxes->color != NULL) {
	    colortype *bob = syntaxes->color;

	    syntaxes->color = bob->next;
1388
	    free(bob->start_regex);
1389
1390
1391
1392
	    if (bob->start != NULL) {
		regfree(bob->start);
		free(bob->start);
	    }
1393
1394
	    if (bob->end_regex != NULL)
		free(bob->end_regex);
1395
	    if (bob->end != NULL) {
1396
		regfree(bob->end);
1397
1398
		free(bob->end);
	    }
Chris Allegretta's avatar
Chris Allegretta committed
1399
1400
1401
1402
1403
1404
	    free(bob);
	}
	syntaxes = syntaxes->next;
	free(bill);
    }
#endif /* ENABLE_COLOR */
1405
#ifndef NANO_TINY
1406
    /* Free the search and replace history lists. */
1407
1408
1409
1410
    if (searchage != NULL)
	free_filestruct(searchage);
    if (replaceage != NULL)
	free_filestruct(replaceage);
1411
#endif
1412
#ifdef ENABLE_NANORC
1413
1414
    if (homedir != NULL)
	free(homedir);
1415
#endif
1416
}
1417
#endif /* DEBUG */