global.c 43.8 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;
}

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

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

242
    s->ctrlval = ctrlval;
243
    s->desc = _(desc);
244
#ifndef DISABLE_HELP
245
    s->help = _(help);
246
#endif
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
301
    /* TRANSLATORS: Try to keep this at most 16 characters. */
302
    const char *to_files_msg = N_("To Files");
303
304
    const char *first_file_msg = N_("First File");
    const char *last_file_msg = N_("Last File");
305
#endif
306
#ifndef DISABLE_HELP
307
    const char *nano_cancel_msg = N_("Cancel the current function");
308
309
    const char *nano_help_msg = N_("Invoke the help menu");
    const char *nano_exit_msg =
310
#ifdef ENABLE_MULTIBUFFER
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
311
	N_("Close the current file buffer/Exit from nano")
312
313
314
315
#else
   	N_("Exit from nano")
#endif
	;
316
317
    const char *nano_writeout_msg =
	N_("Write the current file to disk");
318
319
320
    const char *nano_justify_msg = N_("Justify the current paragraph");
    const char *nano_insert_msg =
	N_("Insert another file into the current one");
321
322
    const char *nano_whereis_msg =
	N_("Search for text within the editor");
323
324
325
326
327
328
    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");
329
330
331
332
    const char *nano_cursorpos_msg =
	N_("Show the position of the cursor");
    const char *nano_spell_msg =
	N_("Invoke the spell checker, if available");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
333
    const char *nano_gotoline_msg = N_("Go to line and column number");
334
    const char *nano_replace_msg = N_("Replace text within the editor");
335
#ifndef NANO_TINY
336
337
    const char *nano_mark_msg = N_("Mark text at the cursor position");
    const char *nano_whereis_next_msg = N_("Repeat last search");
338
#endif
339
340
341
342
    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");
343
344
345
346
347
348
349
350
    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_refresh_msg =
	N_("Refresh (redraw) the current screen");
    const char *nano_delete_msg =
	N_("Delete the character under the cursor");
351
352
    const char *nano_backspace_msg =
	N_("Delete the character to the left of the cursor");
353
354
    const char *nano_tab_msg =
	N_("Insert a tab character at the cursor position");
355
356
    const char *nano_enter_msg =
	N_("Insert a carriage return at the cursor position");
357
#ifndef NANO_TINY
358
359
    const char *nano_nextword_msg = N_("Move forward one word");
    const char *nano_prevword_msg = N_("Move backward one word");
360
    const char *nano_wordcount_msg =
361
	N_("Count the number of words, lines, and characters");
362
    const char *nano_scrollup_msg =
363
	N_("Scroll up one line without scrolling the cursor");
364
    const char *nano_scrolldown_msg =
365
	N_("Scroll down one line without scrolling the cursor");
366
#endif
367
368
369
370
371
372
#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
373
#ifdef ENABLE_MULTIBUFFER
374
    const char *nano_prevfile_msg =
375
	N_("Switch to the previous file buffer");
376
    const char *nano_nextfile_msg =
377
	N_("Switch to the next file buffer");
378
379
#endif
    const char *nano_verbatim_msg = N_("Insert character(s) verbatim");
380
#ifndef NANO_TINY
381
382
383
    const char *nano_cut_till_end_msg =
	N_("Cut from the cursor position to the end of the file");
#endif
384
385
#ifndef DISABLE_JUSTIFY
    const char *nano_fulljustify_msg = N_("Justify the entire file");
386
#endif
387
#ifndef NANO_TINY
388
    const char *nano_bracket_msg = N_("Find matching bracket");
389
#endif
390
391
392
393
    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");
394
#ifndef NANO_TINY
395
396
397
398
    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");
399
#endif
400
401
#ifdef HAVE_REGEX_H
    const char *nano_regexp_msg = N_("Use regular expressions");
402
#endif
403
#ifndef NANO_TINY
404
405
    const char *nano_history_msg =
	N_("Edit the previous search/replace strings");
406
#endif
407
408
#ifndef DISABLE_BROWSER
    const char *nano_tofiles_msg = N_("Go to file browser");
Chris Allegretta's avatar
Chris Allegretta committed
409
#endif
410
#ifndef NANO_TINY
411
412
    const char *nano_dos_msg = N_("Write file out in DOS format");
    const char *nano_mac_msg = N_("Write file out in Mac format");
413
#endif
414
415
    const char *nano_append_msg = N_("Append to the current file");
    const char *nano_prepend_msg = N_("Prepend to the current file");
416
#ifndef NANO_TINY
417
418
    const char *nano_backup_msg =
	N_("Back up original file when saving");
419
    const char *nano_execute_msg = N_("Execute external command");
420
#endif
421
#if !defined(NANO_TINY) && defined(ENABLE_MULTIBUFFER)
422
423
424
    const char *nano_multibuffer_msg = N_("Insert into new buffer");
#endif
#ifndef DISABLE_BROWSER
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
425
    const char *nano_exitbrowser_msg = N_("Exit from the file browser");
426
427
428
429
    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
430
    const char *nano_gotodir_msg = N_("Go to directory");
Chris Allegretta's avatar
Chris Allegretta committed
431
#endif
432
#endif /* !DISABLE_HELP */
Chris Allegretta's avatar
Chris Allegretta committed
433

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

443
444
445
    free_shortcutage(&main_list);

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

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

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

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

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

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

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

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

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

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

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

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

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

541
    sc_init_one(&main_list, NANO_GOTOLINE_KEY, go_to_line_msg,
542
	IFHELP(nano_gotoline_msg, NANO_GOTOLINE_ALTKEY),
543
544
	NANO_GOTOLINE_FKEY, NANO_NO_KEY, VIEW,
	do_gotolinecolumn_void);
545

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

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

556
    sc_init_one(&main_list, NANO_NO_KEY, whereis_next_msg,
557
	IFHELP(nano_whereis_next_msg, NANO_WHEREIS_NEXT_KEY),
558
	NANO_WHEREIS_NEXT_FKEY, NANO_NO_KEY, VIEW, do_research);
559
560
#endif

561
562
563
    sc_init_one(&main_list, NANO_PREVLINE_KEY, N_("Prev Line"),
	IFHELP(nano_prevline_msg, NANO_NO_KEY), NANO_NO_KEY,
	NANO_NO_KEY, VIEW, do_up);
Chris Allegretta's avatar
Chris Allegretta committed
564

565
566
567
    sc_init_one(&main_list, NANO_NEXTLINE_KEY, N_("Next Line"),
	IFHELP(nano_nextline_msg, NANO_NO_KEY), NANO_NO_KEY,
	NANO_NO_KEY, VIEW, do_down);
Chris Allegretta's avatar
Chris Allegretta committed
568

569
    sc_init_one(&main_list, NANO_FORWARD_KEY, N_("Forward"),
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
570
571
	IFHELP(nano_forward_msg, NANO_NO_KEY), NANO_NO_KEY, NANO_NO_KEY,
	VIEW, do_right);
Chris Allegretta's avatar
Chris Allegretta committed
572

573
    sc_init_one(&main_list, NANO_BACK_KEY, N_("Back"),
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
574
575
	IFHELP(nano_back_msg, NANO_NO_KEY), NANO_NO_KEY, NANO_NO_KEY,
	VIEW, do_left);
Chris Allegretta's avatar
Chris Allegretta committed
576

577
    sc_init_one(&main_list, NANO_HOME_KEY, N_("Home"),
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
578
579
	IFHELP(nano_home_msg, NANO_NO_KEY), NANO_NO_KEY, NANO_NO_KEY,
	VIEW, do_home);
Chris Allegretta's avatar
Chris Allegretta committed
580

581
    sc_init_one(&main_list, NANO_END_KEY, N_("End"),
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
582
583
	IFHELP(nano_end_msg, NANO_NO_KEY), NANO_NO_KEY, NANO_NO_KEY,
	VIEW, do_end);
Chris Allegretta's avatar
Chris Allegretta committed
584

585
    sc_init_one(&main_list, NANO_REFRESH_KEY, refresh_msg,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
586
587
	IFHELP(nano_refresh_msg, NANO_NO_KEY), NANO_NO_KEY, NANO_NO_KEY,
	VIEW, total_refresh);
Chris Allegretta's avatar
Chris Allegretta committed
588

589
    sc_init_one(&main_list, NANO_DELETE_KEY, N_("Delete"),
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
590
591
	IFHELP(nano_delete_msg, NANO_NO_KEY), NANO_NO_KEY, NANO_NO_KEY,
	NOVIEW, do_delete);
Chris Allegretta's avatar
Chris Allegretta committed
592

593
594
595
    sc_init_one(&main_list, NANO_BACKSPACE_KEY, N_("Backspace"),
	IFHELP(nano_backspace_msg, NANO_NO_KEY), NANO_NO_KEY,
	NANO_NO_KEY, NOVIEW, do_backspace);
Chris Allegretta's avatar
Chris Allegretta committed
596

597
    sc_init_one(&main_list, NANO_TAB_KEY, N_("Tab"),
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
598
599
	IFHELP(nano_tab_msg, NANO_NO_KEY), NANO_NO_KEY, NANO_NO_KEY,
	NOVIEW, do_tab);
Chris Allegretta's avatar
Chris Allegretta committed
600

601
    sc_init_one(&main_list, NANO_ENTER_KEY, N_("Enter"),
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
602
603
	IFHELP(nano_enter_msg, NANO_NO_KEY), NANO_NO_KEY, NANO_NO_KEY,
	NOVIEW, do_enter);
604

605
#ifndef NANO_TINY
606
607
    sc_init_one(&main_list, NANO_NEXTWORD_KEY, N_("Next Word"),
	IFHELP(nano_nextword_msg, NANO_NO_KEY), NANO_NO_KEY,
608
	NANO_NO_KEY, VIEW, do_next_word_void);
609

610
611
    sc_init_one(&main_list, NANO_NO_KEY, N_("Prev Word"),
	IFHELP(nano_prevword_msg, NANO_PREVWORD_KEY), NANO_NO_KEY,
612
	NANO_NO_KEY, VIEW, do_prev_word_void);
613
614
615

    sc_init_one(&main_list, NANO_NO_KEY, N_("Word Count"),
	IFHELP(nano_wordcount_msg, NANO_WORDCOUNT_KEY), NANO_NO_KEY,
616
	NANO_NO_KEY, VIEW, do_wordlinechar_count);
617

618
619
620
    sc_init_one(&main_list, NANO_NO_KEY, N_("Scroll Up"),
	IFHELP(nano_scrollup_msg, NANO_SCROLLUP_KEY), NANO_NO_KEY,
	NANO_SCROLLUP_ALTKEY, VIEW, do_scroll_up);
621

622
623
624
    sc_init_one(&main_list, NANO_NO_KEY, N_("Scroll Down"),
	IFHELP(nano_scrolldown_msg, NANO_SCROLLDOWN_KEY), NANO_NO_KEY,
	NANO_SCROLLDOWN_ALTKEY, VIEW, do_scroll_down);
625
#endif
626

627
628
629
#ifndef DISABLE_JUSTIFY
    sc_init_one(&main_list, NANO_NO_KEY, beg_of_par_msg,
	IFHELP(nano_parabegin_msg, NANO_PARABEGIN_ALTKEY1), NANO_NO_KEY,
630
	NANO_PARABEGIN_ALTKEY2, VIEW, do_para_begin_void);
631
632
633

    sc_init_one(&main_list, NANO_NO_KEY, end_of_par_msg,
	IFHELP(nano_paraend_msg, NANO_PARAEND_ALTKEY1), NANO_NO_KEY,
634
	NANO_PARAEND_ALTKEY2, VIEW, do_para_end_void);
635
#endif
636

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

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

647
648
649
650
    sc_init_one(&main_list, NANO_NO_KEY, N_("Verbatim Input"),
	IFHELP(nano_verbatim_msg, NANO_VERBATIM_KEY), NANO_NO_KEY,
	NANO_NO_KEY, NOVIEW, do_verbatim_input);

651
#ifndef NANO_TINY
652
653
654
655
656
    sc_init_one(&main_list, NANO_NO_KEY, cut_till_end_msg,
	IFHELP(nano_cut_till_end_msg, NANO_CUTTILLEND_ALTKEY),
	NANO_NO_KEY, NANO_NO_KEY, NOVIEW, do_cut_till_end);
#endif

657
658
#ifndef DISABLE_JUSTIFY
    sc_init_one(&main_list, NANO_NO_KEY, fulljstify_msg,
659
660
	IFHELP(nano_fulljustify_msg, NANO_FULLJUSTIFY_ALTKEY),
	NANO_NO_KEY, NANO_NO_KEY, NOVIEW, do_full_justify);
661
662
#endif

663
#ifndef NANO_TINY
664
665
666
    sc_init_one(&main_list, NANO_NO_KEY, N_("Find Other Bracket"),
	IFHELP(nano_bracket_msg, NANO_BRACKET_KEY), NANO_NO_KEY,
	NANO_NO_KEY, VIEW, do_find_bracket);
667
668
#endif

669
    free_shortcutage(&whereis_list);
670

671
    sc_init_one(&whereis_list, NANO_HELP_KEY, get_help_msg,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
672
673
	IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY, NANO_NO_KEY,
	VIEW,
674
#ifndef DISABLE_HELP
675
	do_help_void
676
#else
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
677
	nano_disabled_msg
678
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
679
	);
680

681
    sc_init_one(&whereis_list, NANO_CANCEL_KEY, cancel_msg,
682
683
	IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY, NANO_NO_KEY,
	VIEW, NULL);
684

685
686
687
    sc_init_one(&whereis_list, NANO_FIRSTLINE_KEY, first_line_msg,
	IFHELP(nano_firstline_msg, NANO_NO_KEY), NANO_FIRSTLINE_FKEY,
	NANO_NO_KEY, VIEW, do_first_line);
Chris Allegretta's avatar
Chris Allegretta committed
688

689
690
691
    sc_init_one(&whereis_list, NANO_LASTLINE_KEY, last_line_msg,
	IFHELP(nano_lastline_msg, NANO_NO_KEY), NANO_LASTLINE_FKEY,
	NANO_NO_KEY, VIEW, do_last_line);
Chris Allegretta's avatar
Chris Allegretta committed
692

693
    sc_init_one(&whereis_list, NANO_TOOTHERSEARCH_KEY, replace_msg,
694
	IFHELP(nano_replace_msg, NANO_NO_KEY), NANO_REPLACE_FKEY,
695
	NANO_NO_KEY, VIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
696

697
698
    sc_init_one(&whereis_list, NANO_TOGOTOLINE_KEY, go_to_line_msg,
	IFHELP(nano_gotoline_msg, NANO_NO_KEY), NANO_GOTOLINE_FKEY,
699
	NANO_NO_KEY, VIEW, NULL);
700

701
#ifndef DISABLE_JUSTIFY
702
    sc_init_one(&whereis_list, NANO_PARABEGIN_KEY, beg_of_par_msg,
703
	IFHELP(nano_parabegin_msg, NANO_PARABEGIN_ALTKEY1), NANO_NO_KEY,
704
	NANO_PARABEGIN_ALTKEY2, VIEW, do_para_begin_void);
705

706
    sc_init_one(&whereis_list, NANO_PARAEND_KEY, end_of_par_msg,
707
	IFHELP(nano_paraend_msg, NANO_PARAEND_ALTKEY1), NANO_NO_KEY,
708
	NANO_PARAEND_ALTKEY2, VIEW, do_para_end_void);
709
710
#endif

711
#ifndef NANO_TINY
712
713
    sc_init_one(&whereis_list, NANO_NO_KEY, case_sens_msg,
	IFHELP(nano_case_msg, TOGGLE_CASE_KEY), NANO_NO_KEY,
714
	NANO_NO_KEY, VIEW, NULL);
715

716
    sc_init_one(&whereis_list, NANO_NO_KEY, backwards_msg,
717
	IFHELP(nano_reverse_msg, TOGGLE_BACKWARDS_KEY), NANO_NO_KEY,
718
	NANO_NO_KEY, VIEW, NULL);
719
#endif
Chris Allegretta's avatar
Chris Allegretta committed
720

721
#ifdef HAVE_REGEX_H
722
    sc_init_one(&whereis_list, NANO_NO_KEY, regexp_msg,
723
	IFHELP(nano_regexp_msg, NANO_REGEXP_KEY), NANO_NO_KEY,
724
	NANO_NO_KEY, VIEW, NULL);
725
#endif
726

727
#ifndef NANO_TINY
728
    sc_init_one(&whereis_list, NANO_PREVLINE_KEY, history_msg,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
729
730
	IFHELP(nano_history_msg, NANO_NO_KEY), NANO_NO_KEY, NANO_NO_KEY,
	VIEW, NULL);
731
732
733
734

    sc_init_one(&whereis_list, NANO_CUTTILLEND_KEY, cut_till_end_msg,
	IFHELP(nano_cut_till_end_msg, NANO_CUTTILLEND_ALTKEY),
	NANO_NO_KEY, NANO_NO_KEY, NOVIEW, do_cut_till_end);
735
#endif
736
737
738
739
740
741

#ifndef DISABLE_JUSTIFY
    sc_init_one(&whereis_list, NANO_FULLJUSTIFY_KEY, fulljstify_msg,
	IFHELP(nano_fulljustify_msg, NANO_FULLJUSTIFY_ALTKEY),
	NANO_NO_KEY, NANO_NO_KEY, NOVIEW, do_full_justify);
#endif
742

743
    free_shortcutage(&replace_list);
744

745
    sc_init_one(&replace_list, NANO_HELP_KEY, get_help_msg,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
746
747
	IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY, NANO_NO_KEY,
	VIEW,
748
#ifndef DISABLE_HELP
749
	do_help_void
750
#else
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
751
	nano_disabled_msg
752
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
753
	);
754

755
    sc_init_one(&replace_list, NANO_CANCEL_KEY, cancel_msg,
756
757
	IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY, NANO_NO_KEY,
	VIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
758

759
760
761
    sc_init_one(&replace_list, NANO_FIRSTLINE_KEY, first_line_msg,
	IFHELP(nano_firstline_msg, NANO_NO_KEY), NANO_FIRSTLINE_FKEY,
	NANO_NO_KEY, VIEW, do_first_line);
Chris Allegretta's avatar
Chris Allegretta committed
762

763
764
765
    sc_init_one(&replace_list, NANO_LASTLINE_KEY, last_line_msg,
	IFHELP(nano_lastline_msg, NANO_NO_KEY), NANO_LASTLINE_FKEY,
	NANO_NO_KEY, VIEW, do_last_line);
Chris Allegretta's avatar
Chris Allegretta committed
766

767
    /* TRANSLATORS: Try to keep this at most 12 characters. */
768
    sc_init_one(&replace_list, NANO_TOOTHERSEARCH_KEY, N_("No Replace"),
769
	IFHELP(nano_whereis_msg, NANO_NO_KEY), NANO_REPLACE_FKEY,
770
	NANO_NO_KEY, VIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
771

772
773
    sc_init_one(&replace_list, NANO_TOGOTOLINE_KEY, go_to_line_msg,
	IFHELP(nano_gotoline_msg, NANO_NO_KEY), NANO_GOTOLINE_FKEY,
774
	NANO_NO_KEY, VIEW, NULL);
775

776
#ifndef NANO_TINY
777
778
    sc_init_one(&replace_list, NANO_NO_KEY, case_sens_msg,
	IFHELP(nano_case_msg, TOGGLE_CASE_KEY), NANO_NO_KEY,
779
	NANO_NO_KEY, VIEW, NULL);
780

781
    sc_init_one(&replace_list, NANO_NO_KEY, backwards_msg,
782
	IFHELP(nano_reverse_msg, TOGGLE_BACKWARDS_KEY), NANO_NO_KEY,
783
	NANO_NO_KEY, VIEW, NULL);
784
#endif
785

786
#ifdef HAVE_REGEX_H
787
    sc_init_one(&replace_list, NANO_NO_KEY, regexp_msg,
788
	IFHELP(nano_regexp_msg, NANO_REGEXP_KEY), NANO_NO_KEY,
789
	NANO_NO_KEY, VIEW, NULL);
790
#endif
791

792
#ifndef NANO_TINY
793
    sc_init_one(&replace_list, NANO_PREVLINE_KEY, history_msg,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
794
795
	IFHELP(nano_history_msg, NANO_NO_KEY), NANO_NO_KEY, NANO_NO_KEY,
	VIEW, NULL);
796
#endif
797

798
    free_shortcutage(&replace_list_2);
799

800
    sc_init_one(&replace_list_2, NANO_HELP_KEY, get_help_msg,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
801
802
	IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY, 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_2, NANO_CANCEL_KEY, cancel_msg,
811
812
	IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY, NANO_NO_KEY,
	VIEW, NULL);
813

814
815
816
    sc_init_one(&replace_list_2, NANO_FIRSTLINE_KEY, first_line_msg,
	IFHELP(nano_firstline_msg, NANO_NO_KEY), NANO_NO_KEY,
	NANO_NO_KEY, VIEW, do_first_line);
817

818
819
820
    sc_init_one(&replace_list_2, NANO_LASTLINE_KEY, last_line_msg,
	IFHELP(nano_lastline_msg, NANO_NO_KEY), NANO_NO_KEY,
	NANO_NO_KEY, VIEW, do_last_line);
821

822
#ifndef NANO_TINY
823
    sc_init_one(&replace_list_2, NANO_PREVLINE_KEY, history_msg,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
824
825
	IFHELP(nano_history_msg, NANO_NO_KEY), NANO_NO_KEY, NANO_NO_KEY,
	VIEW, NULL);
826
827
#endif

828
    free_shortcutage(&gotoline_list);
Chris Allegretta's avatar
Chris Allegretta committed
829

830
    sc_init_one(&gotoline_list, NANO_HELP_KEY, get_help_msg,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
831
832
	IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY, NANO_NO_KEY,
	VIEW,
833
#ifndef DISABLE_HELP
834
	do_help_void
835
#else
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
836
	nano_disabled_msg
837
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
838
	);
839

840
    sc_init_one(&gotoline_list, NANO_CANCEL_KEY, cancel_msg,
841
842
	IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY, NANO_NO_KEY,
	VIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
843

844
    sc_init_one(&gotoline_list, NANO_FIRSTLINE_KEY, first_line_msg,
845
846
	IFHELP(nano_firstline_msg, NANO_NO_KEY), NANO_NO_KEY,
	NANO_NO_KEY, VIEW, do_first_line);
Chris Allegretta's avatar
Chris Allegretta committed
847

848
    sc_init_one(&gotoline_list, NANO_LASTLINE_KEY, last_line_msg,
849
850
	IFHELP(nano_lastline_msg, NANO_NO_KEY), NANO_NO_KEY,
	NANO_NO_KEY, VIEW, do_last_line);
Chris Allegretta's avatar
Chris Allegretta committed
851

852
853
    sc_init_one(&gotoline_list, NANO_TOOTHERWHEREIS_KEY,
	N_("Go To Text"), IFHELP(nano_whereis_msg, NANO_NO_KEY),
854
	NANO_NO_KEY, NANO_NO_KEY, VIEW, NULL);
855

856
    free_shortcutage(&writefile_list);
Chris Allegretta's avatar
Chris Allegretta committed
857

858
    sc_init_one(&writefile_list, NANO_HELP_KEY, get_help_msg,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
859
860
	IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY, NANO_NO_KEY,
	VIEW,
861
#ifndef DISABLE_HELP
862
	do_help_void
863
#else
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
864
	nano_disabled_msg
865
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
866
	);
867

868
    sc_init_one(&writefile_list, NANO_CANCEL_KEY, cancel_msg,
869
870
	IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY, NANO_NO_KEY,
	VIEW, NULL);
871

872
#ifndef DISABLE_BROWSER
873
874
    /* If we're using restricted mode, the file browser is disabled.
     * It's useless since inserting files is disabled. */
875

876
    if (!ISSET(RESTRICTED))
877
	sc_init_one(&writefile_list, NANO_TOFILES_KEY, to_files_msg,
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
878
		IFHELP(nano_tofiles_msg, NANO_NO_KEY), NANO_NO_KEY,
879
		NANO_NO_KEY, NOVIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
880
#endif
Chris Allegretta's avatar
Chris Allegretta committed
881

882
#ifndef NANO_TINY
883
884
885
886
887
888
    /* 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. */
889

890
    if (!ISSET(RESTRICTED))
891
	/* TRANSLATORS: Try to keep this at most 16 characters. */
892
	sc_init_one(&writefile_list, NANO_NO_KEY, N_("DOS Format"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
893
		IFHELP(nano_dos_msg, TOGGLE_DOS_KEY), NANO_NO_KEY,
894
		NANO_NO_KEY, NOVIEW, NULL);
895

896
    if (!ISSET(RESTRICTED))
897
	/* TRANSLATORS: Try to keep this at most 16 characters. */
898
	sc_init_one(&writefile_list, NANO_NO_KEY, N_("Mac Format"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
899
		IFHELP(nano_mac_msg, TOGGLE_MAC_KEY), NANO_NO_KEY,
900
		NANO_NO_KEY, NOVIEW, NULL);
901
902
#endif

903
    if (!ISSET(RESTRICTED))
904
	/* TRANSLATORS: Try to keep this at most 16 characters. */
905
	sc_init_one(&writefile_list, NANO_NO_KEY, N_("Append"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
906
		IFHELP(nano_append_msg, NANO_APPEND_KEY), NANO_NO_KEY,
907
		NANO_NO_KEY, NOVIEW, NULL);
908

909
    if (!ISSET(RESTRICTED))
910
	/* TRANSLATORS: Try to keep this at most 16 characters. */
911
	sc_init_one(&writefile_list, NANO_NO_KEY, N_("Prepend"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
912
		IFHELP(nano_prepend_msg, NANO_PREPEND_KEY), NANO_NO_KEY,
913
		NANO_NO_KEY, NOVIEW, NULL);
914

915
#ifndef NANO_TINY
916
    if (!ISSET(RESTRICTED))
917
	/* TRANSLATORS: Try to keep this at most 16 characters. */
918
	sc_init_one(&writefile_list, NANO_NO_KEY, N_("Backup File"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
919
		IFHELP(nano_backup_msg, TOGGLE_BACKUP_KEY), NANO_NO_KEY,
920
		NANO_NO_KEY, NOVIEW, NULL);
921
922
#endif

923
    free_shortcutage(&insertfile_list);
924

925
    sc_init_one(&insertfile_list, NANO_HELP_KEY, get_help_msg,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
926
927
	IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY, NANO_NO_KEY,
	VIEW,
928
#ifndef DISABLE_HELP
929
	do_help_void
930
#else
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
931
	nano_disabled_msg
932
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
933
	);
934

935
    sc_init_one(&insertfile_list, NANO_CANCEL_KEY, cancel_msg,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
936
937
	IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY, NANO_NO_KEY,
	VIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
938

939
#ifndef DISABLE_BROWSER
940
941
    /* If we're using restricted mode, the file browser is disabled.
     * It's useless since inserting files is disabled. */
942
    if (!ISSET(RESTRICTED))
943
	sc_init_one(&insertfile_list, NANO_TOFILES_KEY, to_files_msg,
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
944
		IFHELP(nano_tofiles_msg, NANO_NO_KEY), NANO_NO_KEY,
945
		NANO_NO_KEY, NOVIEW, NULL);
946
#endif
947

948
#ifndef NANO_TINY
949
950
    /* If we're using restricted mode, command execution is disabled.
     * It's useless since inserting files is disabled. */
951

952
    if (!ISSET(RESTRICTED))
953
	sc_init_one(&insertfile_list, NANO_TOOTHERINSERT_KEY,
954
		/* TRANSLATORS: Try to keep this at most 22 characters. */
955
		N_("Execute Command"), IFHELP(nano_execute_msg,
956
		NANO_NO_KEY), NANO_NO_KEY, NANO_NO_KEY, NOVIEW, NULL);
957

958
#ifdef ENABLE_MULTIBUFFER
959
960
    /* If we're using restricted mode, the multibuffer toggle is
     * disabled.  It's useless since inserting files is disabled. */
961

962
    if (!ISSET(RESTRICTED))
963
	sc_init_one(&insertfile_list, NANO_NO_KEY, new_buffer_msg,
964
		IFHELP(nano_multibuffer_msg, TOGGLE_MULTIBUFFER_KEY),
965
		NANO_NO_KEY, NANO_NO_KEY, NOVIEW, NULL);
966
#endif
967
#endif
968

969
#ifndef NANO_TINY
970
    free_shortcutage(&extcmd_list);
Chris Allegretta's avatar
Chris Allegretta committed
971

972
    sc_init_one(&extcmd_list, NANO_HELP_KEY, get_help_msg,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
973
974
	IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY, NANO_NO_KEY,
	VIEW,
975
#ifndef DISABLE_HELP
976
	do_help_void
977
#else
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
978
	nano_disabled_msg
979
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
980
	);
981

982
    sc_init_one(&extcmd_list, NANO_CANCEL_KEY, cancel_msg,
983
984
	IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY, NANO_NO_KEY,
	VIEW, NULL);
985

986
987
    sc_init_one(&extcmd_list, NANO_TOOTHERINSERT_KEY, N_("Insert File"),
	IFHELP(nano_insert_msg, NANO_NO_KEY), NANO_NO_KEY,
988
	NANO_NO_KEY, VIEW, NULL);
989

David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
990
#ifdef ENABLE_MULTIBUFFER
991
    sc_init_one(&extcmd_list, NANO_NO_KEY, new_buffer_msg,
992
	IFHELP(nano_multibuffer_msg, TOGGLE_MULTIBUFFER_KEY),
993
	NANO_NO_KEY, NANO_NO_KEY, NOVIEW, NULL);
994
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
995
#endif
996

997
998
999
1000
#ifndef DISABLE_HELP
    free_shortcutage(&help_list);

    sc_init_one(&help_list, NANO_REFRESH_KEY, refresh_msg,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1001
1002
	IFHELP(nano_refresh_msg, NANO_NO_KEY), NANO_NO_KEY, NANO_NO_KEY,
	VIEW, NULL);
1003
1004

    sc_init_one(&help_list, NANO_EXIT_KEY, exit_msg,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1005
1006
	IFHELP(nano_exit_msg, NANO_NO_KEY), NANO_EXIT_FKEY, NANO_NO_KEY,
	VIEW, NULL);
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028

    sc_init_one(&help_list, NANO_PREVPAGE_KEY, prev_page_msg,
	IFHELP(nano_prevpage_msg, NANO_NO_KEY), NANO_PREVPAGE_FKEY,
	NANO_NO_KEY, VIEW, NULL);

    sc_init_one(&help_list, NANO_NEXTPAGE_KEY, next_page_msg,
	IFHELP(nano_nextpage_msg, NANO_NO_KEY), NANO_NEXTPAGE_FKEY,
	NANO_NO_KEY, VIEW, NULL);

    sc_init_one(&help_list, NANO_PREVLINE_KEY, N_("Prev Line"),
	IFHELP(nano_prevline_msg, NANO_NO_KEY), NANO_NO_KEY,
	NANO_NO_KEY, VIEW, NULL);

    sc_init_one(&help_list, NANO_NEXTLINE_KEY, N_("Next Line"),
	IFHELP(nano_nextline_msg, NANO_NO_KEY), NANO_NO_KEY,
	NANO_NO_KEY, VIEW, NULL);
#endif

#ifndef DISABLE_SPELLER
    free_shortcutage(&spell_list);

    sc_init_one(&spell_list, NANO_HELP_KEY, get_help_msg,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1029
1030
	IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY, NANO_NO_KEY,
	VIEW,
1031
#ifndef DISABLE_HELP
1032
	do_help_void
1033
#else
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1034
	nano_disabled_msg
1035
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1036
	);
1037
1038

    sc_init_one(&spell_list, NANO_CANCEL_KEY, cancel_msg,
1039
1040
	IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY, NANO_NO_KEY,
	VIEW, NULL);
1041
1042
#endif

1043
#ifndef DISABLE_BROWSER
1044
    free_shortcutage(&browser_list);
1045

1046
    sc_init_one(&browser_list, NANO_HELP_KEY, get_help_msg,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1047
1048
	IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY, NANO_NO_KEY,
	VIEW, NULL);
1049

1050
    sc_init_one(&browser_list, NANO_EXIT_KEY, exit_msg,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1051
	IFHELP(nano_exitbrowser_msg, NANO_NO_KEY), NANO_EXIT_FKEY,
1052
	NANO_NO_KEY, VIEW, NULL);
1053

1054
1055
    sc_init_one(&browser_list, NANO_PREVPAGE_KEY, prev_page_msg,
	IFHELP(nano_prevpage_msg, NANO_NO_KEY), NANO_PREVPAGE_FKEY,
1056
	NANO_NO_KEY, VIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
1057

1058
1059
    sc_init_one(&browser_list, NANO_NEXTPAGE_KEY, next_page_msg,
	IFHELP(nano_nextpage_msg, NANO_NO_KEY), NANO_NEXTPAGE_FKEY,
1060
	NANO_NO_KEY, VIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
1061

1062
1063
1064
1065
1066
1067
1068
1069
    sc_init_one(&browser_list, NANO_WHEREIS_KEY, whereis_msg,
	IFHELP(nano_whereis_msg, NANO_NO_KEY), NANO_NO_KEY, NANO_NO_KEY,
	VIEW, NULL);

    sc_init_one(&browser_list, NANO_NO_KEY, whereis_next_msg,
	IFHELP(nano_whereis_next_msg, NANO_WHEREIS_NEXT_KEY),
	NANO_WHEREIS_NEXT_FKEY, NANO_NO_KEY, VIEW, NULL);

1070
    /* TRANSLATORS: Try to keep this at most 22 characters. */
1071
    sc_init_one(&browser_list, NANO_GOTOLINE_KEY, N_("Go To Dir"),
1072
	IFHELP(nano_gotodir_msg, NANO_GOTOLINE_ALTKEY),
1073
	NANO_GOTOLINE_FKEY, NANO_NO_KEY, VIEW, NULL);
Rocco Corsi's avatar
   
Rocco Corsi committed
1074

1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
    free_shortcutage(&whereis_file_list);

    sc_init_one(&whereis_file_list, NANO_HELP_KEY, get_help_msg,
	IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY, NANO_NO_KEY,
	VIEW,
#ifndef DISABLE_HELP
	do_browser_help
#else
	nano_disabled_msg
#endif
	);

    sc_init_one(&whereis_file_list, NANO_CANCEL_KEY, cancel_msg,
	IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY, NANO_NO_KEY,
	VIEW, NULL);

    sc_init_one(&whereis_file_list, NANO_FIRSTFILE_KEY, first_file_msg,
	IFHELP(nano_firstfile_msg, NANO_NO_KEY), NANO_FIRSTFILE_FKEY,
	NANO_NO_KEY, VIEW, do_first_file);

    sc_init_one(&whereis_file_list, NANO_LASTFILE_KEY, last_file_msg,
	IFHELP(nano_lastfile_msg, NANO_NO_KEY), NANO_LASTFILE_FKEY,
	NANO_NO_KEY, VIEW, do_last_file);

#ifndef NANO_SMALL
    sc_init_one(&whereis_file_list, NANO_NO_KEY, case_sens_msg,
	IFHELP(nano_case_msg, TOGGLE_CASE_KEY), NANO_NO_KEY,
	NANO_NO_KEY, VIEW, NULL);

    sc_init_one(&whereis_file_list, NANO_NO_KEY, backwards_msg,
	IFHELP(nano_reverse_msg, TOGGLE_BACKWARDS_KEY), NANO_NO_KEY,
	NANO_NO_KEY, VIEW, NULL);
#endif

#ifdef HAVE_REGEX_H
    sc_init_one(&whereis_file_list, NANO_NO_KEY, regexp_msg,
	IFHELP(nano_regexp_msg, NANO_REGEXP_KEY), NANO_NO_KEY,
	NANO_NO_KEY, VIEW, NULL);
#endif

#ifndef NANO_SMALL
    sc_init_one(&whereis_file_list, NANO_PREVLINE_KEY, history_msg,
	IFHELP(nano_history_msg, NANO_NO_KEY), NANO_NO_KEY, NANO_NO_KEY,
	VIEW, NULL);
#endif

1121
    free_shortcutage(&gotodir_list);
1122

1123
    sc_init_one(&gotodir_list, NANO_HELP_KEY, get_help_msg,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1124
1125
	IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY, NANO_NO_KEY,
	VIEW,
1126
#ifndef DISABLE_HELP
1127
	do_help_void
1128
#else
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1129
	nano_disabled_msg
1130
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1131
	);
Chris Allegretta's avatar
Chris Allegretta committed
1132

1133
    sc_init_one(&gotodir_list, NANO_CANCEL_KEY, cancel_msg,
1134
1135
	IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY, NANO_NO_KEY,
	VIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
1136
1137
#endif

1138
    currshortcut = main_list;
1139

1140
#ifndef NANO_TINY
1141
    toggle_init();
1142
#endif
1143
}
1144

1145
1146
1147
1148
/* Deallocate the given shortcut. */
void free_shortcutage(shortcut **shortcutage)
{
    assert(shortcutage != NULL);
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1149

1150
1151
1152
1153
1154
1155
1156
    while (*shortcutage != NULL) {
	shortcut *ps = *shortcutage;
	*shortcutage = (*shortcutage)->next;
	free(ps);
    }
}

1157
#ifndef NANO_TINY
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1158
/* Create a new toggle structure, at the end of the toggles linked
1159
1160
1161
1162
1163
1164
 * list. */
void toggle_init_one(int val, const char *desc, long flag)
{
    toggle *u;

    if (toggles == NULL) {
1165
	toggles = (toggle *)nmalloc(sizeof(toggle));
1166
1167
1168
1169
	u = toggles;
    } else {
	for (u = toggles; u->next != NULL; u = u->next)
	    ;
1170
	u->next = (toggle *)nmalloc(sizeof(toggle));
1171
1172
1173
1174
1175
1176
1177
1178
1179
	u = u->next;
    }

    u->val = val;
    u->desc = _(desc);
    u->flag = flag;
    u->next = NULL;
}

1180
/* Initialize the global toggle list. */
1181
1182
1183
1184
1185
1186
1187
1188
void toggle_init(void)
{
    /* There is no need to reinitialize the toggles.  They can't
     * change. */
    if (toggles != NULL)
	return;

    toggle_init_one(TOGGLE_NOHELP_KEY, N_("Help mode"), NO_HELP);
1189
1190
    toggle_init_one(TOGGLE_MORESPACE_KEY,
	N_("Use of more space for editing"), MORE_SPACE);
1191
1192
1193
1194
#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))
1195
1196
	toggle_init_one(TOGGLE_MULTIBUFFER_KEY,
		N_("Multiple file buffers"), MULTIBUFFER);
1197
#endif
1198
    toggle_init_one(TOGGLE_CUTTOEND_KEY, N_("Cut to end"), CUT_TO_END);
1199
#ifndef DISABLE_WRAPPING
1200
1201
    toggle_init_one(TOGGLE_WRAP_KEY, N_("Long line wrapping"),
	NO_WRAP);
1202
#endif
1203
1204
1205
#ifndef DISABLE_MOUSE
    toggle_init_one(TOGGLE_MOUSE_KEY, N_("Mouse support"), USE_MOUSE);
#endif
1206
1207
1208
1209
    /* If we're using restricted mode, the suspend toggle is disabled.
     * It's useless since suspending is disabled. */
    if (!ISSET(RESTRICTED))
	toggle_init_one(TOGGLE_SUSPEND_KEY, N_("Suspend"), SUSPEND);
1210
1211
1212
1213
1214
1215
    toggle_init_one(TOGGLE_CONST_KEY,
	N_("Constant cursor position display"), CONST_UPDATE);
    toggle_init_one(TOGGLE_AUTOINDENT_KEY, N_("Auto indent"),
	AUTOINDENT);
    toggle_init_one(TOGGLE_TABSTOSPACES_KEY,
	N_("Conversion of typed tabs to spaces"), TABS_TO_SPACES);
1216
1217
1218
    /* If we're using restricted mode, the DOS/Mac conversion toggle is
     * disabled.  It's useless since inserting files is disabled. */
    if (!ISSET(RESTRICTED))
1219
1220
	toggle_init_one(TOGGLE_NOCONVERT_KEY,
		N_("No conversion from DOS/Mac format"), NO_CONVERT);
1221
1222
1223
    /* If we're using restricted mode, the backup toggle is disabled.
     * It's useless since backups are disabled. */
    if (!ISSET(RESTRICTED))
1224
1225
1226
	toggle_init_one(TOGGLE_BACKUP_KEY, N_("Backup files"),
		BACKUP_FILE);
    toggle_init_one(TOGGLE_SMOOTH_KEY, N_("Smooth scrolling"),
1227
	SMOOTH_SCROLL);
1228
1229
    toggle_init_one(TOGGLE_SMARTHOME_KEY, N_("Smart home key"),
	SMART_HOME);
1230
1231
#ifdef ENABLE_COLOR
    toggle_init_one(TOGGLE_SYNTAX_KEY, N_("Color syntax highlighting"),
1232
	NO_COLOR_SYNTAX);
1233
1234
1235
1236
1237
1238
#endif
#ifdef ENABLE_NANORC
    toggle_init_one(TOGGLE_WHITESPACE_KEY, N_("Whitespace display"),
	WHITESPACE_DISPLAY);
#endif
}
1239
#endif /* !NANO_TINY */
1240

1241
1242
1243
/* This function is called just before calling exit().  Practically, the
 * 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
1244
 * function unless debugging is turned on. */
1245
#ifdef DEBUG
1246
/* Added by SPK for memory cleanup; gracefully return our malloc()s. */
Chris Allegretta's avatar
Chris Allegretta committed
1247
void thanks_for_all_the_fish(void)
1248
{
1249
1250
1251
1252
    delwin(topwin);
    delwin(edit);
    delwin(bottomwin);

Chris Allegretta's avatar
Chris Allegretta committed
1253
1254
1255
#ifndef DISABLE_JUSTIFY
    if (quotestr != NULL)
	free(quotestr);
1256
1257
#ifdef HAVE_REGEX_H
    regfree(&quotereg);
1258
1259
    if (quoteerr != NULL)
	free(quoteerr);
1260
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1261
#endif
1262
#ifndef NANO_TINY
1263
1264
1265
    if (backup_dir != NULL)
        free(backup_dir);
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1266
#ifndef DISABLE_OPERATINGDIR
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
    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);
1279
#endif
1280
1281
1282
    if (answer != NULL)
	free(answer);
    if (cutbuffer != NULL)
Chris Allegretta's avatar
Chris Allegretta committed
1283
	free_filestruct(cutbuffer);
1284
1285
1286
1287
#ifndef DISABLE_JUSTIFY
    if (jusbuffer != NULL)
	free_filestruct(jusbuffer);
#endif
1288
1289
1290
1291
    free_shortcutage(&main_list);
    free_shortcutage(&whereis_list);
    free_shortcutage(&replace_list);
    free_shortcutage(&replace_list_2);
1292
    free_shortcutage(&gotoline_list);
1293
1294
    free_shortcutage(&writefile_list);
    free_shortcutage(&insertfile_list);
1295
1296
1297
#ifndef NANO_TINY
    free_shortcutage(&extcmd_list);
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1298
#ifndef DISABLE_HELP
Chris Allegretta's avatar
Chris Allegretta committed
1299
    free_shortcutage(&help_list);
Chris Allegretta's avatar
Chris Allegretta committed
1300
1301
#endif
#ifndef DISABLE_SPELLER
1302
    free_shortcutage(&spell_list);
Chris Allegretta's avatar
Chris Allegretta committed
1303
#endif
1304
1305
#ifndef DISABLE_BROWSER
    free_shortcutage(&browser_list);
Chris Allegretta's avatar
Chris Allegretta committed
1306
    free_shortcutage(&gotodir_list);
1307
#endif
1308
#ifndef NANO_TINY
1309
    /* Free the memory associated with each toggle. */
1310
1311
    while (toggles != NULL) {
	toggle *t = toggles;
1312

1313
1314
1315
1316
	toggles = toggles->next;
	free(t);
    }
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1317
    /* Free the memory associated with each open file buffer. */
1318
    if (openfile != NULL)
1319
	free_openfilestruct(openfile);
Chris Allegretta's avatar
Chris Allegretta committed
1320
#ifdef ENABLE_COLOR
1321
1322
    if (syntaxstr != NULL)
	free(syntaxstr);
Chris Allegretta's avatar
Chris Allegretta committed
1323
1324
1325
1326
1327
1328
1329
1330
    while (syntaxes != NULL) {
	syntaxtype *bill = syntaxes;

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

	    syntaxes->extensions = bob->next;
1331
	    free(bob->ext_regex);
1332
1333
1334
1335
	    if (bob->ext != NULL) {
		regfree(bob->ext);
		free(bob->ext);
	    }
Chris Allegretta's avatar
Chris Allegretta committed
1336
1337
1338
1339
1340
1341
	    free(bob);
	}
	while (syntaxes->color != NULL) {
	    colortype *bob = syntaxes->color;

	    syntaxes->color = bob->next;
1342
	    free(bob->start_regex);
1343
1344
1345
1346
	    if (bob->start != NULL) {
		regfree(bob->start);
		free(bob->start);
	    }
1347
1348
	    if (bob->end_regex != NULL)
		free(bob->end_regex);
1349
	    if (bob->end != NULL) {
1350
		regfree(bob->end);
1351
1352
		free(bob->end);
	    }
Chris Allegretta's avatar
Chris Allegretta committed
1353
1354
1355
1356
1357
1358
	    free(bob);
	}
	syntaxes = syntaxes->next;
	free(bill);
    }
#endif /* ENABLE_COLOR */
1359
#ifndef NANO_TINY
1360
    /* Free the search and replace history lists. */
1361
1362
1363
1364
    if (searchage != NULL)
	free_filestruct(searchage);
    if (replaceage != NULL)
	free_filestruct(replaceage);
1365
#endif
1366
#ifdef ENABLE_NANORC
1367
1368
    if (homedir != NULL)
	free(homedir);
1369
#endif
1370
}
1371
#endif /* DEBUG */