global.c 42.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
shortcut *gotodir_list = NULL;
157
	/* The "Go To Directory" shortcut list. */
Chris Allegretta's avatar
Chris Allegretta committed
158
#endif
159

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

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

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

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

198
199
200
201
bool curses_ended = FALSE;
	/* Whether endwin() has ended curses mode and statusbar()
	 * should hence write to stderr instead of displaying on the
	 * statusbar. */
202

203
204
205
char *homedir = NULL;
		/* The user's home directory, from $HOME or
		 * /etc/passwd. */
206

207
/* Return the number of entries in the shortcut list s. */
208
size_t length_of_list(const shortcut *s)
209
{
210
    size_t i = 0;
211

212
    for (; s != NULL; s = s->next)
213
214
215
216
	i++;
    return i;
}

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

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

238
    s->ctrlval = ctrlval;
239
    s->desc = _(desc);
240
#ifndef DISABLE_HELP
241
    s->help = _(help);
242
#endif
243
244
245
    s->metaval = metaval;
    s->funcval = funcval;
    s->miscval = miscval;
Chris Allegretta's avatar
Chris Allegretta committed
246
247
    s->viewok = view;
    s->func = func;
248
    s->next = NULL;
Chris Allegretta's avatar
Chris Allegretta committed
249
250
}

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

David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
413
414
415
/* 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
416
#ifndef DISABLE_HELP
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
417
#define IFHELP(help, nextvar) help, nextvar
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
418
#else
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
419
#define IFHELP(help, nextvar) nextvar
420
#endif
421

422
423
    free_shortcutage(&main_list);

424
    /* Translators: try to keep this string under 10 characters long. */
425
426
427
    sc_init_one(&main_list, NANO_HELP_KEY, get_help_msg,
	IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
	NANO_NO_KEY, VIEW,
428
#ifndef DISABLE_HELP
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
429
	do_help
430
#else
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
431
	nano_disabled_msg
432
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
433
	);
Chris Allegretta's avatar
Chris Allegretta committed
434

435
    /* Translators: try to keep this string under 10 characters long. */
436
437
    sc_init_one(&main_list, NANO_EXIT_KEY,
#ifdef ENABLE_MULTIBUFFER
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
438
	openfile != NULL && openfile != openfile->next ? N_("Close") :
439
#endif
440
441
	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
442

443
    /* Translators: try to keep this string under 10 characters long. */
444
445
446
    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
447

448
    /* Translators: try to keep this string under 10 characters long. */
449
450
451
    sc_init_one(&main_list, NANO_JUSTIFY_KEY, N_("Justify"),
	IFHELP(nano_justify_msg, NANO_NO_KEY),
	NANO_JUSTIFY_FKEY, NANO_NO_KEY, NOVIEW,
452
#ifndef DISABLE_JUSTIFY
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
453
	do_justify_void
454
#else
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
455
	nano_disabled_msg
456
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
457
	);
458

459
    /* We allow inserting files in view mode if multibuffers are
460
461
462
463
464
465
     * 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. */

    /* Translators: try to keep this string under 10 characters long. */
466
467
468
    sc_init_one(&main_list, NANO_INSERTFILE_KEY, N_("Read File"),
	IFHELP(nano_insert_msg, NANO_NO_KEY), NANO_INSERTFILE_FKEY,
	NANO_NO_KEY,
469
#ifdef ENABLE_MULTIBUFFER
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
470
	VIEW
471
#else
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
472
	NOVIEW
473
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
474
	, !ISSET(RESTRICTED) ? do_insertfile_void : nano_disabled_msg);
Chris Allegretta's avatar
Chris Allegretta committed
475

476
    /* Translators: try to keep this string under 10 characters long. */
477
478
479
    sc_init_one(&main_list, NANO_WHEREIS_KEY, N_("Where Is"),
	IFHELP(nano_whereis_msg, NANO_NO_KEY), NANO_WHEREIS_FKEY,
	NANO_NO_KEY, VIEW, do_search);
Chris Allegretta's avatar
Chris Allegretta committed
480

481
    /* Translators: try to keep this string under 10 characters long. */
482
483
484
    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
485

486
    /* Translators: try to keep this string under 10 characters long. */
487
488
489
    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
490

491
    /* Translators: try to keep this string under 10 characters long. */
492
493
494
    sc_init_one(&main_list, NANO_CUT_KEY, N_("Cut Text"),
	IFHELP(nano_cut_msg, NANO_NO_KEY), NANO_CUT_FKEY,
	NANO_NO_KEY, NOVIEW, do_cut_text);
Chris Allegretta's avatar
Chris Allegretta committed
495

496
    if (unjustify)
497
    /* Translators: try to keep this string under 10 characters long. */
498
499
	sc_init_one(&main_list, NANO_UNJUSTIFY_KEY, N_("UnJustify"),
		IFHELP(NULL, NANO_NO_KEY), NANO_UNJUSTIFY_FKEY,
500
		NANO_NO_KEY, NOVIEW, NULL);
501
    else
502
    /* Translators: try to keep this string under 10 characters long. */
503
	sc_init_one(&main_list, NANO_UNCUT_KEY, N_("UnCut Txt"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
504
505
		IFHELP(nano_uncut_msg, NANO_NO_KEY), NANO_UNCUT_FKEY,
		NANO_NO_KEY, NOVIEW, do_uncut_text);
Chris Allegretta's avatar
Chris Allegretta committed
506

507
    /* Translators: try to keep this string under 10 characters long. */
508
509
510
    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
511

512
513
514
    /* 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. */
515
    /* Translators: try to keep this string under 10 characters long. */
516
    sc_init_one(&main_list, NANO_SPELL_KEY, N_("To Spell"),
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
517
518
	IFHELP(nano_spell_msg, NANO_NO_KEY), NANO_SPELL_FKEY,
	NANO_NO_KEY, NOVIEW,
519
#ifndef DISABLE_SPELLER
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
520
	!ISSET(RESTRICTED) ? do_spell :
521
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
522
	nano_disabled_msg);
523

524
    sc_init_one(&main_list, NANO_GOTOLINE_KEY, go_to_line_msg,
525
	IFHELP(nano_gotoline_msg, NANO_GOTOLINE_ALTKEY),
526
527
	NANO_GOTOLINE_FKEY, NANO_NO_KEY, VIEW,
	do_gotolinecolumn_void);
528

529
    sc_init_one(&main_list, NANO_REPLACE_KEY, replace_msg,
530
531
	IFHELP(nano_replace_msg, NANO_ALT_REPLACE_KEY),
	NANO_REPLACE_FKEY, NANO_NO_KEY, NOVIEW, do_replace);
Chris Allegretta's avatar
Chris Allegretta committed
532

533
#ifndef NANO_TINY
534
535
    sc_init_one(&main_list, NANO_MARK_KEY, N_("Mark Text"),
	IFHELP(nano_mark_msg, NANO_MARK_ALTKEY), NANO_MARK_FKEY,
536
	NANO_NO_KEY, VIEW, do_mark);
537
538
539

    sc_init_one(&main_list, NANO_NO_KEY, N_("Where Is Next"),
	IFHELP(nano_whereis_next_msg, NANO_WHEREIS_NEXT_KEY),
540
	NANO_WHEREIS_NEXT_FKEY, NANO_NO_KEY, VIEW, do_research);
541
542
#endif

543
544
545
    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
546

547
548
549
    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
550

551
552
    sc_init_one(&main_list, NANO_FORWARD_KEY, N_("Forward"),
	IFHELP(nano_forward_msg, NANO_NO_KEY), NANO_NO_KEY,
553
	NANO_NO_KEY, VIEW, do_right);
Chris Allegretta's avatar
Chris Allegretta committed
554

555
556
    sc_init_one(&main_list, NANO_BACK_KEY, N_("Back"),
	IFHELP(nano_back_msg, NANO_NO_KEY), NANO_NO_KEY,
557
	NANO_NO_KEY, VIEW, do_left);
Chris Allegretta's avatar
Chris Allegretta committed
558

559
560
561
    sc_init_one(&main_list, NANO_HOME_KEY, N_("Home"),
	IFHELP(nano_home_msg, NANO_NO_KEY), NANO_NO_KEY,
	NANO_NO_KEY, VIEW, do_home);
Chris Allegretta's avatar
Chris Allegretta committed
562

563
564
565
    sc_init_one(&main_list, NANO_END_KEY, N_("End"),
	IFHELP(nano_end_msg, NANO_NO_KEY), NANO_NO_KEY,
	NANO_NO_KEY, VIEW, do_end);
Chris Allegretta's avatar
Chris Allegretta committed
566

567
    sc_init_one(&main_list, NANO_REFRESH_KEY, refresh_msg,
568
569
	IFHELP(nano_refresh_msg, NANO_NO_KEY), NANO_NO_KEY,
	NANO_NO_KEY, VIEW, total_refresh);
Chris Allegretta's avatar
Chris Allegretta committed
570

571
572
573
    sc_init_one(&main_list, NANO_DELETE_KEY, N_("Delete"),
	IFHELP(nano_delete_msg, NANO_NO_KEY), NANO_NO_KEY,
	NANO_NO_KEY, NOVIEW, do_delete);
Chris Allegretta's avatar
Chris Allegretta committed
574

575
576
577
    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
578

579
580
581
    sc_init_one(&main_list, NANO_TAB_KEY, N_("Tab"),
	IFHELP(nano_tab_msg, NANO_NO_KEY), NANO_NO_KEY,
	NANO_NO_KEY, NOVIEW, do_tab);
Chris Allegretta's avatar
Chris Allegretta committed
582

583
584
585
    sc_init_one(&main_list, NANO_ENTER_KEY, N_("Enter"),
	IFHELP(nano_enter_msg, NANO_NO_KEY), NANO_NO_KEY,
	NANO_NO_KEY, NOVIEW, do_enter);
586

587
#ifndef NANO_TINY
588
589
    sc_init_one(&main_list, NANO_NEXTWORD_KEY, N_("Next Word"),
	IFHELP(nano_nextword_msg, NANO_NO_KEY), NANO_NO_KEY,
590
	NANO_NO_KEY, VIEW, do_next_word_void);
591

592
593
    sc_init_one(&main_list, NANO_NO_KEY, N_("Prev Word"),
	IFHELP(nano_prevword_msg, NANO_PREVWORD_KEY), NANO_NO_KEY,
594
	NANO_NO_KEY, VIEW, do_prev_word_void);
595
596
597

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

600
601
602
    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);
603

604
605
606
    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);
607
#endif
608

609
#ifndef DISABLE_JUSTIFY
610
    /* Translators: try to keep this string under 10 characters long. */
611
612
    sc_init_one(&main_list, NANO_NO_KEY, beg_of_par_msg,
	IFHELP(nano_parabegin_msg, NANO_PARABEGIN_ALTKEY1), NANO_NO_KEY,
613
	NANO_PARABEGIN_ALTKEY2, VIEW, do_para_begin_void);
614

615
    /* Translators: try to keep this string under 10 characters long. */
616
617
    sc_init_one(&main_list, NANO_NO_KEY, end_of_par_msg,
	IFHELP(nano_paraend_msg, NANO_PARAEND_ALTKEY1), NANO_NO_KEY,
618
	NANO_PARAEND_ALTKEY2, VIEW, do_para_end_void);
619
#endif
620

621
#ifdef ENABLE_MULTIBUFFER
622
    sc_init_one(&main_list, NANO_NO_KEY, N_("Previous File"),
623
624
	IFHELP(nano_prevfile_msg, NANO_PREVFILE_KEY), NANO_NO_KEY,
	NANO_PREVFILE_ALTKEY, VIEW, switch_to_prev_buffer_void);
625

626
    sc_init_one(&main_list, NANO_NO_KEY, N_("Next File"),
627
628
	IFHELP(nano_nextfile_msg, NANO_NEXTFILE_KEY), NANO_NO_KEY,
	NANO_NEXTFILE_ALTKEY, VIEW, switch_to_next_buffer_void);
629
#endif
630

631
632
633
634
    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);

635
#ifndef NANO_TINY
636
    /* Translators: try to keep this string under 10 characters long. */
637
638
639
640
641
    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

642
#ifndef DISABLE_JUSTIFY
643
    /* Translators: try to keep this string under 10 characters long. */
644
    sc_init_one(&main_list, NANO_NO_KEY, fulljstify_msg,
645
646
	IFHELP(nano_fulljustify_msg, NANO_FULLJUSTIFY_ALTKEY),
	NANO_NO_KEY, NANO_NO_KEY, NOVIEW, do_full_justify);
647
648
#endif

649
#ifndef NANO_TINY
650
651
652
    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);
653
654
#endif

655
    free_shortcutage(&whereis_list);
656

657
658
659
    sc_init_one(&whereis_list, NANO_HELP_KEY, get_help_msg,
	IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
	NANO_NO_KEY, VIEW,
660
#ifndef DISABLE_HELP
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
661
	do_help
662
#else
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
663
	nano_disabled_msg
664
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
665
	);
666

667
    /* Translators: try to keep this string under 10 characters long. */
668
    sc_init_one(&whereis_list, NANO_CANCEL_KEY, cancel_msg,
669
670
	IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY, NANO_NO_KEY,
	VIEW, NULL);
671

672
    /* Translators: try to keep this string under 10 characters long. */
673
674
675
    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
676

677
    /* Translators: try to keep this string under 10 characters long. */
678
679
680
    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
681

682
    /* Translators: try to keep this string under 10 characters long. */
683
    sc_init_one(&whereis_list, NANO_TOOTHERSEARCH_KEY, replace_msg,
684
	IFHELP(nano_replace_msg, NANO_NO_KEY), NANO_REPLACE_FKEY,
685
	NANO_NO_KEY, VIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
686

687
    /* Translators: try to keep this string under 10 characters long. */
688
689
    sc_init_one(&whereis_list, NANO_TOGOTOLINE_KEY, go_to_line_msg,
	IFHELP(nano_gotoline_msg, NANO_NO_KEY), NANO_GOTOLINE_FKEY,
690
	NANO_NO_KEY, VIEW, NULL);
691

692
#ifndef DISABLE_JUSTIFY
693
    /* Translators: try to keep this string under 10 characters long. */
694
    sc_init_one(&whereis_list, NANO_PARABEGIN_KEY, beg_of_par_msg,
695
	IFHELP(nano_parabegin_msg, NANO_PARABEGIN_ALTKEY1), NANO_NO_KEY,
696
	NANO_PARABEGIN_ALTKEY2, VIEW, do_para_begin_void);
697

698
    /* Translators: try to keep this string under 10 characters long. */
699
    sc_init_one(&whereis_list, NANO_PARAEND_KEY, end_of_par_msg,
700
	IFHELP(nano_paraend_msg, NANO_PARAEND_ALTKEY1), NANO_NO_KEY,
701
	NANO_PARAEND_ALTKEY2, VIEW, do_para_end_void);
702
703
#endif

704
#ifndef NANO_TINY
705
    /* Translators: try to keep this string under 10 characters long. */
706
707
    sc_init_one(&whereis_list, NANO_NO_KEY, case_sens_msg,
	IFHELP(nano_case_msg, TOGGLE_CASE_KEY), NANO_NO_KEY,
708
	NANO_NO_KEY, VIEW, NULL);
709

710
    /* Translators: try to keep this string under 10 characters long. */
711
    sc_init_one(&whereis_list, NANO_NO_KEY, backwards_msg,
712
	IFHELP(nano_reverse_msg, TOGGLE_BACKWARDS_KEY), NANO_NO_KEY,
713
	NANO_NO_KEY, VIEW, NULL);
714
#endif
Chris Allegretta's avatar
Chris Allegretta committed
715

716
#ifdef HAVE_REGEX_H
717
    /* Translators: try to keep this string under 10 characters long. */
718
    sc_init_one(&whereis_list, NANO_NO_KEY, regexp_msg,
719
	IFHELP(nano_regexp_msg, NANO_REGEXP_KEY), NANO_NO_KEY,
720
	NANO_NO_KEY, VIEW, NULL);
721
#endif
722

723
#ifndef NANO_TINY
724
    /* Translators: try to keep this string under 10 characters long. */
725
726
    sc_init_one(&whereis_list, NANO_PREVLINE_KEY, history_msg,
	IFHELP(nano_history_msg, NANO_NO_KEY), NANO_NO_KEY,
727
	NANO_NO_KEY, VIEW, NULL);
728

729
    /* Translators: try to keep this string under 10 characters long. */
730
731
732
    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);
733
#endif
734
735

#ifndef DISABLE_JUSTIFY
736
    /* Translators: try to keep this string under 10 characters long. */
737
738
739
740
    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
741

742
    free_shortcutage(&replace_list);
743

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

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

758
759
760
    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
761

762
763
764
    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
765

766
    /* Translators: try to keep this string under 12 characters long. */
767
    sc_init_one(&replace_list, NANO_TOOTHERSEARCH_KEY, N_("No Replace"),
768
	IFHELP(nano_whereis_msg, NANO_NO_KEY), NANO_REPLACE_FKEY,
769
	NANO_NO_KEY, VIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
770

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

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

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

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

791
#ifndef NANO_TINY
792
793
    sc_init_one(&replace_list, NANO_PREVLINE_KEY, history_msg,
	IFHELP(nano_history_msg, NANO_NO_KEY), NANO_NO_KEY,
794
	NANO_NO_KEY, VIEW, NULL);
795
#endif
796

797
    free_shortcutage(&replace_list_2);
798

799
800
801
    sc_init_one(&replace_list_2, NANO_HELP_KEY, get_help_msg,
	IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
	NANO_NO_KEY, VIEW,
802
#ifndef DISABLE_HELP
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
803
	do_help
804
#else
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
805
	nano_disabled_msg
806
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
807
	);
808

809
    sc_init_one(&replace_list_2, NANO_CANCEL_KEY, cancel_msg,
810
811
	IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY, NANO_NO_KEY,
	VIEW, NULL);
812

813
814
815
    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);
816

817
818
819
    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);
820

821
#ifndef NANO_TINY
822
823
    sc_init_one(&replace_list_2, NANO_PREVLINE_KEY, history_msg,
	IFHELP(nano_history_msg, NANO_NO_KEY), NANO_NO_KEY,
824
	NANO_NO_KEY, VIEW, NULL);
825
826
#endif

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

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

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

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

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

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

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

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

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

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

    /* Translators: try to keep this string under 16 characters long. */
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

    /* Translators: try to keep this string under 16 characters long. */
891
    if (!ISSET(RESTRICTED))
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
    /* Translators: try to keep this string under 16 characters long. */
897
    if (!ISSET(RESTRICTED))
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
    /* Translators: try to keep this string under 16 characters long. */
904
    if (!ISSET(RESTRICTED))
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
    /* Translators: try to keep this string under 16 characters long. */
910
    if (!ISSET(RESTRICTED))
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
    /* Translators: try to keep this string under 16 characters long. */
917
    if (!ISSET(RESTRICTED))
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
926
927
    sc_init_one(&insertfile_list, NANO_HELP_KEY, get_help_msg,
	IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
	NANO_NO_KEY, VIEW,
928
#ifndef DISABLE_HELP
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
929
	do_help
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

    /* Translators: try to keep this string under 22 characters long. */
953
    if (!ISSET(RESTRICTED))
954
955
	sc_init_one(&insertfile_list, NANO_TOOTHERINSERT_KEY,
		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

    /* Translators: try to keep this string under 22 characters long. */
963
    if (!ISSET(RESTRICTED))
964
	sc_init_one(&insertfile_list, NANO_NO_KEY, new_buffer_msg,
965
		IFHELP(nano_multibuffer_msg, TOGGLE_MULTIBUFFER_KEY),
966
		NANO_NO_KEY, NANO_NO_KEY, NOVIEW, NULL);
967
#endif
968
#endif
969

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

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

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

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

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

998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
#ifndef DISABLE_HELP
    free_shortcutage(&help_list);

    sc_init_one(&help_list, NANO_REFRESH_KEY, refresh_msg,
	IFHELP(nano_refresh_msg, NANO_NO_KEY), NANO_NO_KEY,
	NANO_NO_KEY, VIEW, NULL);

    sc_init_one(&help_list, NANO_EXIT_KEY, exit_msg,
	IFHELP(nano_exit_msg, NANO_NO_KEY), NANO_EXIT_FKEY,
	NANO_NO_KEY, VIEW, NULL);

    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,
	IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
	NANO_NO_KEY, VIEW,
#ifndef DISABLE_HELP
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1033
	do_help
1034
#else
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1035
	nano_disabled_msg
1036
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1037
	);
1038
1039

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

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

1047
1048
    sc_init_one(&browser_list, NANO_HELP_KEY, get_help_msg,
	IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
1049
	NANO_NO_KEY, VIEW, NULL);
1050

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

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

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

1063
    /* Translators: try to keep this string under 22 characters long. */
1064
    sc_init_one(&browser_list, NANO_GOTOLINE_KEY, N_("Go To Dir"),
1065
	IFHELP(nano_gotodir_msg, NANO_GOTOLINE_ALTKEY),
1066
	NANO_GOTOLINE_FKEY, NANO_NO_KEY, VIEW, NULL);
Rocco Corsi's avatar
   
Rocco Corsi committed
1067

1068
    free_shortcutage(&gotodir_list);
1069

1070
1071
1072
    sc_init_one(&gotodir_list, NANO_HELP_KEY, get_help_msg,
	IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
	NANO_NO_KEY, VIEW,
1073
#ifndef DISABLE_HELP
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1074
	do_help
1075
#else
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1076
	nano_disabled_msg
1077
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1078
	);
Chris Allegretta's avatar
Chris Allegretta committed
1079

1080
    sc_init_one(&gotodir_list, NANO_CANCEL_KEY, cancel_msg,
1081
1082
	IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY, NANO_NO_KEY,
	VIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
1083
1084
#endif

1085
    currshortcut = main_list;
1086

1087
#ifndef NANO_TINY
1088
    toggle_init();
1089
#endif
1090
}
1091

1092
1093
1094
1095
/* Deallocate the given shortcut. */
void free_shortcutage(shortcut **shortcutage)
{
    assert(shortcutage != NULL);
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1096

1097
1098
1099
1100
1101
1102
1103
    while (*shortcutage != NULL) {
	shortcut *ps = *shortcutage;
	*shortcutage = (*shortcutage)->next;
	free(ps);
    }
}

1104
#ifndef NANO_TINY
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1105
/* Create a new toggle structure, at the end of the toggles linked
1106
1107
1108
1109
1110
1111
 * list. */
void toggle_init_one(int val, const char *desc, long flag)
{
    toggle *u;

    if (toggles == NULL) {
1112
	toggles = (toggle *)nmalloc(sizeof(toggle));
1113
1114
1115
1116
	u = toggles;
    } else {
	for (u = toggles; u->next != NULL; u = u->next)
	    ;
1117
	u->next = (toggle *)nmalloc(sizeof(toggle));
1118
1119
1120
1121
1122
1123
1124
1125
1126
	u = u->next;
    }

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

1127
/* Initialize the global toggle list. */
1128
1129
1130
1131
1132
1133
1134
1135
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);
1136
1137
    toggle_init_one(TOGGLE_MORESPACE_KEY,
	N_("Use of more space for editing"), MORE_SPACE);
1138
1139
1140
1141
#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))
1142
1143
	toggle_init_one(TOGGLE_MULTIBUFFER_KEY,
		N_("Multiple file buffers"), MULTIBUFFER);
1144
#endif
1145
    toggle_init_one(TOGGLE_CUTTOEND_KEY, N_("Cut to end"), CUT_TO_END);
1146
#ifndef DISABLE_WRAPPING
1147
1148
    toggle_init_one(TOGGLE_WRAP_KEY, N_("Long line wrapping"),
	NO_WRAP);
1149
#endif
1150
1151
1152
#ifndef DISABLE_MOUSE
    toggle_init_one(TOGGLE_MOUSE_KEY, N_("Mouse support"), USE_MOUSE);
#endif
1153
1154
1155
1156
    /* 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);
1157
1158
1159
1160
1161
1162
    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);
1163
1164
1165
    /* If we're using restricted mode, the DOS/Mac conversion toggle is
     * disabled.  It's useless since inserting files is disabled. */
    if (!ISSET(RESTRICTED))
1166
1167
	toggle_init_one(TOGGLE_NOCONVERT_KEY,
		N_("No conversion from DOS/Mac format"), NO_CONVERT);
1168
1169
1170
    /* If we're using restricted mode, the backup toggle is disabled.
     * It's useless since backups are disabled. */
    if (!ISSET(RESTRICTED))
1171
1172
1173
	toggle_init_one(TOGGLE_BACKUP_KEY, N_("Backup files"),
		BACKUP_FILE);
    toggle_init_one(TOGGLE_SMOOTH_KEY, N_("Smooth scrolling"),
1174
	SMOOTH_SCROLL);
1175
1176
    toggle_init_one(TOGGLE_SMARTHOME_KEY, N_("Smart home key"),
	SMART_HOME);
1177
1178
#ifdef ENABLE_COLOR
    toggle_init_one(TOGGLE_SYNTAX_KEY, N_("Color syntax highlighting"),
1179
	NO_COLOR_SYNTAX);
1180
1181
1182
1183
1184
1185
#endif
#ifdef ENABLE_NANORC
    toggle_init_one(TOGGLE_WHITESPACE_KEY, N_("Whitespace display"),
	WHITESPACE_DISPLAY);
#endif
}
1186
#endif /* !NANO_TINY */
1187

1188
1189
1190
/* 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
1191
 * function unless debugging is turned on. */
1192
#ifdef DEBUG
1193
/* Added by SPK for memory cleanup; gracefully return our malloc()s. */
Chris Allegretta's avatar
Chris Allegretta committed
1194
void thanks_for_all_the_fish(void)
1195
{
1196
1197
1198
1199
    delwin(topwin);
    delwin(edit);
    delwin(bottomwin);

Chris Allegretta's avatar
Chris Allegretta committed
1200
1201
1202
#ifndef DISABLE_JUSTIFY
    if (quotestr != NULL)
	free(quotestr);
1203
1204
#ifdef HAVE_REGEX_H
    regfree(&quotereg);
1205
1206
    if (quoteerr != NULL)
	free(quoteerr);
1207
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1208
#endif
1209
#ifndef NANO_TINY
1210
1211
1212
    if (backup_dir != NULL)
        free(backup_dir);
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1213
#ifndef DISABLE_OPERATINGDIR
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
    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);
1226
#endif
1227
1228
1229
    if (answer != NULL)
	free(answer);
    if (cutbuffer != NULL)
Chris Allegretta's avatar
Chris Allegretta committed
1230
	free_filestruct(cutbuffer);
1231
1232
1233
1234
#ifndef DISABLE_JUSTIFY
    if (jusbuffer != NULL)
	free_filestruct(jusbuffer);
#endif
1235
1236
1237
1238
    free_shortcutage(&main_list);
    free_shortcutage(&whereis_list);
    free_shortcutage(&replace_list);
    free_shortcutage(&replace_list_2);
1239
    free_shortcutage(&gotoline_list);
1240
1241
    free_shortcutage(&writefile_list);
    free_shortcutage(&insertfile_list);
1242
1243
1244
#ifndef NANO_TINY
    free_shortcutage(&extcmd_list);
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1245
#ifndef DISABLE_HELP
Chris Allegretta's avatar
Chris Allegretta committed
1246
    free_shortcutage(&help_list);
Chris Allegretta's avatar
Chris Allegretta committed
1247
1248
#endif
#ifndef DISABLE_SPELLER
1249
    free_shortcutage(&spell_list);
Chris Allegretta's avatar
Chris Allegretta committed
1250
#endif
1251
1252
#ifndef DISABLE_BROWSER
    free_shortcutage(&browser_list);
Chris Allegretta's avatar
Chris Allegretta committed
1253
    free_shortcutage(&gotodir_list);
1254
#endif
1255
#ifndef NANO_TINY
1256
    /* Free the memory associated with each toggle. */
1257
1258
    while (toggles != NULL) {
	toggle *t = toggles;
1259

1260
1261
1262
1263
	toggles = toggles->next;
	free(t);
    }
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1264
    /* Free the memory associated with each open file buffer. */
1265
    if (openfile != NULL)
1266
	free_openfilestruct(openfile);
Chris Allegretta's avatar
Chris Allegretta committed
1267
#ifdef ENABLE_COLOR
1268
1269
    if (syntaxstr != NULL)
	free(syntaxstr);
Chris Allegretta's avatar
Chris Allegretta committed
1270
1271
1272
1273
1274
1275
1276
1277
    while (syntaxes != NULL) {
	syntaxtype *bill = syntaxes;

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

	    syntaxes->extensions = bob->next;
1278
	    free(bob->ext_regex);
1279
1280
1281
1282
	    if (bob->ext != NULL) {
		regfree(bob->ext);
		free(bob->ext);
	    }
Chris Allegretta's avatar
Chris Allegretta committed
1283
1284
1285
1286
1287
1288
	    free(bob);
	}
	while (syntaxes->color != NULL) {
	    colortype *bob = syntaxes->color;

	    syntaxes->color = bob->next;
1289
	    free(bob->start_regex);
1290
1291
1292
1293
	    if (bob->start != NULL) {
		regfree(bob->start);
		free(bob->start);
	    }
1294
1295
	    if (bob->end_regex != NULL)
		free(bob->end_regex);
1296
	    if (bob->end != NULL) {
1297
		regfree(bob->end);
1298
1299
		free(bob->end);
	    }
Chris Allegretta's avatar
Chris Allegretta committed
1300
1301
1302
1303
1304
1305
	    free(bob);
	}
	syntaxes = syntaxes->next;
	free(bill);
    }
#endif /* ENABLE_COLOR */
1306
#ifndef NANO_TINY
1307
    /* Free the search and replace history lists. */
1308
1309
1310
1311
    if (searchage != NULL)
	free_filestruct(searchage);
    if (replaceage != NULL)
	free_filestruct(replaceage);
1312
#endif
1313
#ifdef ENABLE_NANORC
1314
1315
    if (homedir != NULL)
	free(homedir);
1316
#endif
1317
}
1318
#endif /* DEBUG */