global.c 41.1 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-2005 Chris Allegretta                             *
Chris Allegretta's avatar
Chris Allegretta committed
6
7
 *   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 *
8
 *   the Free Software Foundation; either version 2, or (at your option)  *
Chris Allegretta's avatar
Chris Allegretta committed
9
10
11
12
13
14
15
16
17
18
19
20
21
 *   any later version.                                                   *
 *                                                                        *
 *   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.                         *
 *                                                                        *
 *   You should have received a copy of the GNU General Public License    *
 *   along with this program; if not, write to the Free Software          *
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.            *
 *                                                                        *
 **************************************************************************/

22
23
24
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
25

26
#include <stdlib.h>
27
#include <assert.h>
Chris Allegretta's avatar
Chris Allegretta committed
28
29
#include "proto.h"

Chris Allegretta's avatar
Chris Allegretta committed
30
/* Global variables */
31

32
#ifndef DISABLE_WRAPJUSTIFY
33
34
35
/* wrap_at might be set in rcfile.c or nano.c. */
ssize_t wrap_at = -CHARS_FROM_EOL;	/* Right justified fill value,
					   allows resize */
36
37
#endif

Chris Allegretta's avatar
Chris Allegretta committed
38
39
40
41
char *last_search = NULL;	/* Last string we searched for */
char *last_replace = NULL;	/* Last replacement string */
int search_last_line;		/* Is this the last search line? */

42
unsigned long flags = 0;	/* Our flag containing many options */
43
WINDOW *topwin;			/* Top buffer */
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
44
WINDOW *edit;			/* The file portion of the editor */
Chris Allegretta's avatar
Chris Allegretta committed
45
WINDOW *bottomwin;		/* Bottom buffer */
Chris Allegretta's avatar
Chris Allegretta committed
46
char *filename = NULL;		/* Name of the file */
47
48
49
50
51

#ifndef NANO_SMALL
struct stat originalfilestat;	/* Stat for the file as we loaded it */
#endif

Chris Allegretta's avatar
Chris Allegretta committed
52
53
54
int editwinrows = 0;		/* How many rows long is the edit
				   window? */
filestruct *current;		/* Current buffer pointer */
55
56
57
58
size_t current_x = 0;		/* Current x-coordinate in the edit
				   window */
int current_y = 0;		/* Current y-coordinate in the edit
				   window */
Chris Allegretta's avatar
Chris Allegretta committed
59
60
61
62
63
64
filestruct *fileage = NULL;	/* Our file buffer */
filestruct *edittop = NULL;	/* Pointer to the top of the edit
				   buffer with respect to the
				   file struct */
filestruct *filebot = NULL;	/* Last node in the file struct */
filestruct *cutbuffer = NULL;	/* A place to store cut text */
65
66
67
#ifndef DISABLE_JUSTIFY
filestruct *jusbuffer = NULL;	/* A place to store unjustified text */
#endif
68
69
70
partition *filepart = NULL;	/* A place to store a portion of the
				   file struct */

71
#ifdef ENABLE_MULTIBUFFER
72
73
openfilestruct *open_files = NULL;	/* The list of open file
					   buffers */
74
75
#endif

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

83
#ifndef DISABLE_JUSTIFY
84
85
86
87
88
char *punct = NULL;		/* Closing punctuation that can end
				   sentences. */
char *brackets = NULL;		/* Closing brackets that can follow
				   closing punctuation and can end
				   sentences. */
Chris Allegretta's avatar
Chris Allegretta committed
89
90
char *quotestr = NULL;		/* Quote string.  The default value is
				   set in main(). */
91
92
93
94
95
96
97
#ifdef HAVE_REGEX_H
regex_t quotereg;		/* Compiled quotestr regular expression. */
int quoterc;			/* Did it compile? */
char *quoteerr = NULL;		/* The error message. */
#else
size_t quotelen;		/* strlen(quotestr) */
#endif
Chris Allegretta's avatar
Chris Allegretta committed
98
#endif
99

100
101
102
103
#ifndef NANO_SMALL
char *backup_dir = NULL;	/* Backup directory. */
#endif

Chris Allegretta's avatar
Chris Allegretta committed
104
char *answer = NULL;		/* Answer str to many questions */
Chris Allegretta's avatar
Chris Allegretta committed
105
int totlines = 0;		/* Total number of lines in the file */
106
107
size_t totsize = 0;		/* Total number of characters in the
				   file */
108
size_t placewewant = 0;		/* The column we'd like the cursor
Chris Allegretta's avatar
Chris Allegretta committed
109
110
111
				   to jump to when we go to the
				   next or previous line */

112
113
ssize_t tabsize = -1;		/* Our internal tabsize variable.  The
				   default value is set in main(). */
114

Chris Allegretta's avatar
Chris Allegretta committed
115
char *hblank = NULL;		/* A horizontal blank line */
Chris Allegretta's avatar
Chris Allegretta committed
116
#ifndef DISABLE_HELP
Chris Allegretta's avatar
Chris Allegretta committed
117
char *help_text;		/* The text in the help window */
Chris Allegretta's avatar
Chris Allegretta committed
118
#endif
Chris Allegretta's avatar
Chris Allegretta committed
119
120
121

/* More stuff for the marker select */

Chris Allegretta's avatar
Chris Allegretta committed
122
#ifndef NANO_SMALL
123
filestruct *mark_beginbuf;	/* The begin marker buffer */
124
size_t mark_beginx;		/* X value in the string to start */
Chris Allegretta's avatar
Chris Allegretta committed
125
#endif
Chris Allegretta's avatar
Chris Allegretta committed
126

127
#ifndef DISABLE_OPERATINGDIR
128
129
char *operating_dir = NULL;	/* Operating directory, which we can't */
char *full_operating_dir = NULL;/* go higher than */
130
131
#endif

132
#ifndef DISABLE_SPELLER
133
char *alt_speller = NULL;		/* Alternative spell command */
134
135
#endif

136
137
138
shortcut *main_list = NULL;
shortcut *whereis_list = NULL;
shortcut *replace_list = NULL;
139
shortcut *replace_list_2 = NULL; 	/* 2nd half of replace dialog */
140
shortcut *gotoline_list = NULL;
141
142
shortcut *writefile_list = NULL;
shortcut *insertfile_list = NULL;
Chris Allegretta's avatar
Chris Allegretta committed
143
#ifndef DISABLE_HELP
144
shortcut *help_list = NULL;
Chris Allegretta's avatar
Chris Allegretta committed
145
146
#endif
#ifndef DISABLE_SPELLER
147
shortcut *spell_list = NULL;
Chris Allegretta's avatar
Chris Allegretta committed
148
#endif
Chris Allegretta's avatar
Chris Allegretta committed
149
#ifndef NANO_SMALL
150
shortcut *extcmd_list = NULL;
Chris Allegretta's avatar
Chris Allegretta committed
151
#endif
152
#ifndef DISABLE_BROWSER
153
shortcut *browser_list = NULL;
154
shortcut *gotodir_list = NULL;
Chris Allegretta's avatar
Chris Allegretta committed
155
#endif
156

157
#ifdef ENABLE_COLOR
158
159
160
const colortype *colorstrings = NULL;
syntaxtype *syntaxes = NULL;
char *syntaxstr = NULL;
161
162
#endif

Chris Allegretta's avatar
Chris Allegretta committed
163
const shortcut *currshortcut;	/* Current shortcut list we're using */
164

165
#ifndef NANO_SMALL
166
toggle *toggles = NULL;
167
#endif
Chris Allegretta's avatar
Chris Allegretta committed
168

169
170
171
172
173
#ifndef NANO_SMALL
historyheadtype search_history;
historyheadtype replace_history;
#endif

174
175
/* Regular expressions */

176
#ifdef HAVE_REGEX_H
177
178
179
regex_t search_regexp;		/* Global to store compiled search regexp */
regmatch_t regmatches[10];	/* Match positions for parenthetical
				   subexpressions, max of 10 */
Chris Allegretta's avatar
Chris Allegretta committed
180
#endif
181

182
bool curses_ended = FALSE;	/* Indicates to statusbar() to simply
183
184
185
				 * write to stderr, since endwin() has
				 * ended curses mode. */

186
187
char *homedir = NULL;		/* $HOME or from /etc/passwd. */

188
size_t length_of_list(const shortcut *s)
189
{
190
    size_t i = 0;
191

192
    for (; s != NULL; s = s->next)
193
194
195
196
	i++;
    return i;
}

Chris Allegretta's avatar
Chris Allegretta committed
197
/* Initialize a struct *without* our lovely braces =( */
198
void sc_init_one(shortcut **shortcutage, int ctrlval, const char *desc,
199
#ifndef DISABLE_HELP
200
	const char *help,
201
#endif
202
	int metaval, int funcval, int miscval, bool view, void
203
	(*func)(void))
Chris Allegretta's avatar
Chris Allegretta committed
204
{
205
206
207
    shortcut *s;

    if (*shortcutage == NULL) {
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
208
	*shortcutage = (shortcut *)nmalloc(sizeof(shortcut));
209
210
211
212
	s = *shortcutage;
    } else {
	for (s = *shortcutage; s->next != NULL; s = s->next)
	    ;
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
213
	s->next = (shortcut *)nmalloc(sizeof(shortcut));
214
215
216
	s = s->next; 
    }

217
    s->ctrlval = ctrlval;
218
    s->desc = _(desc);
219
#ifndef DISABLE_HELP
220
    s->help = _(help);
221
#endif
222
223
224
    s->metaval = metaval;
    s->funcval = funcval;
    s->miscval = miscval;
Chris Allegretta's avatar
Chris Allegretta committed
225
226
    s->viewok = view;
    s->func = func;
227
    s->next = NULL;
Chris Allegretta's avatar
Chris Allegretta committed
228
229
}

230
void shortcut_init(bool unjustify)
231
{
232
233
234
235
236
237
238
239
240
    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 *replace_msg = N_("Replace");
    const char *go_to_line_msg = N_("Go To Line");
    const char *cancel_msg = N_("Cancel");
    const char *first_line_msg = N_("First Line");
    const char *last_line_msg = N_("Last Line");
241
242
243
#ifndef NANO_SMALL
    const char *cut_till_end_msg = N_("CutTillEnd");
#endif
244
245
246
247
248
#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
249
250
251
252
253
#ifndef NANO_SMALL
    const char *case_sens_msg = N_("Case Sens");
    const char *direction_msg = N_("Direction");
#ifdef HAVE_REGEX_H
    const char *regexp_msg = N_("Regexp");
254
#endif
255
    const char *history_msg = N_("History");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
256
#ifdef ENABLE_MULTIBUFFER
257
    const char *new_buffer_msg = N_("New Buffer");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
258
#endif
259
260
261
#endif /* !NANO_SMALL */
#ifndef DISABLE_BROWSER
    const char *to_files_msg = N_("To Files");
262
#endif
263

264
265
266
#ifndef DISABLE_HELP
    const char *nano_help_msg = N_("Invoke the help menu");
    const char *nano_exit_msg =
267
#ifdef ENABLE_MULTIBUFFER
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
	N_("Close currently loaded file/Exit from nano")
#else
   	N_("Exit from nano")
#endif
	;
    const char *nano_writeout_msg = N_("Write the current file to disk");
    const char *nano_justify_msg = N_("Justify the current paragraph");
    const char *nano_insert_msg =
	N_("Insert another file into the current one");
    const char *nano_whereis_msg = N_("Search for text within the editor");
    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");
    const char *nano_cursorpos_msg = N_("Show the position of the cursor");
    const char *nano_spell_msg = N_("Invoke the spell checker, if available");
286
    const char *nano_gotoline_msg = N_("Go to a specific line number");
287
    const char *nano_replace_msg = N_("Replace text within the editor");
288
#ifndef NANO_SMALL
289
290
    const char *nano_mark_msg = N_("Mark text at the cursor position");
    const char *nano_whereis_next_msg = N_("Repeat last search");
291
#endif
292
293
294
295
296
297
298
299
300
301
    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");
    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");
    const char *nano_backspace_msg =
	N_("Delete the character to the left of the cursor");
302
303
    const char *nano_tab_msg =
	N_("Insert a tab character at the cursor position");
304
305
    const char *nano_enter_msg =
	N_("Insert a carriage return at the cursor position");
306
#ifndef NANO_SMALL
307
308
    const char *nano_nextword_msg = N_("Move forward one word");
    const char *nano_prevword_msg = N_("Move backward one word");
309
#endif
310
311
312
313
314
315
#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
316
#ifdef ENABLE_MULTIBUFFER
317
318
319
320
    const char *nano_openprev_msg = N_("Switch to the previous file buffer");
    const char *nano_opennext_msg = N_("Switch to the next file buffer");
#endif
    const char *nano_verbatim_msg = N_("Insert character(s) verbatim");
321
322
323
324
#ifndef NANO_SMALL
    const char *nano_cut_till_end_msg =
	N_("Cut from the cursor position to the end of the file");
#endif
325
326
#ifndef DISABLE_JUSTIFY
    const char *nano_fulljustify_msg = N_("Justify the entire file");
327
#endif
328
#if !defined(NANO_SMALL) && defined(HAVE_REGEX_H)
329
    const char *nano_bracket_msg = N_("Find other bracket");
330
#endif
331
332
333
334
335
336
337
338
339
340
    const char *nano_cancel_msg = N_("Cancel the current function");
    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");
#ifndef NANO_SMALL
    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");
#ifdef HAVE_REGEX_H
    const char *nano_regexp_msg = N_("Use regular expressions");
341
#endif
342
343
    const char *nano_editstr_msg =
	N_("Edit the previous search/replace strings");
344
#endif /* !NANO_SMALL */
345

346
347
#ifndef DISABLE_BROWSER
    const char *nano_tofiles_msg = N_("Go to file browser");
Chris Allegretta's avatar
Chris Allegretta committed
348
#endif
349
350
351
#ifndef NANO_SMALL
    const char *nano_dos_msg = N_("Write file out in DOS format");
    const char *nano_mac_msg = N_("Write file out in Mac format");
352
#endif
353
354
355
356
357
    const char *nano_append_msg = N_("Append to the current file");
    const char *nano_prepend_msg = N_("Prepend to the current file");
#ifndef NANO_SMALL
    const char *nano_backup_msg = N_("Back up original file when saving");
    const char *nano_execute_msg = N_("Execute external command");
358
#endif
359
#if !defined(NANO_SMALL) && defined(ENABLE_MULTIBUFFER)
360
361
362
    const char *nano_multibuffer_msg = N_("Insert into new buffer");
#endif
#ifndef DISABLE_BROWSER
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
363
364
    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
365
#endif
366
#endif /* !DISABLE_HELP */
Chris Allegretta's avatar
Chris Allegretta committed
367

David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
368
369
370
/* 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
371
#ifndef DISABLE_HELP
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
372
#define IFHELP(help, nextvar) help, nextvar
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
373
#else
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
374
#define IFHELP(help, nextvar) nextvar
375
#endif
376

377
378
    free_shortcutage(&main_list);

379
    /* Translators: try to keep this string under 10 characters long */
380
381
382
    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,
383
384
385
386
387
388
#ifndef DISABLE_HELP
		do_help
#else
		nano_disabled_msg
#endif
		);
Chris Allegretta's avatar
Chris Allegretta committed
389

390
    /* Translators: try to keep this string under 10 characters long */
391
392
393
394
    sc_init_one(&main_list, NANO_EXIT_KEY,
#ifdef ENABLE_MULTIBUFFER
	open_files != NULL && open_files != open_files->next ?
	N_("Close") :
395
#endif
396
397
	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
398

399
    /* Translators: try to keep this string under 10 characters long */
400
401
402
    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
403

404
    /* Translators: try to keep this string under 10 characters long */
405
406
407
    sc_init_one(&main_list, NANO_JUSTIFY_KEY, N_("Justify"),
	IFHELP(nano_justify_msg, NANO_NO_KEY),
	NANO_JUSTIFY_FKEY, NANO_NO_KEY, NOVIEW,
408
#ifndef DISABLE_JUSTIFY
409
		do_justify_void
410
411
412
413
#else
		nano_disabled_msg
#endif
		);
414

415
416
417
418
419
    /* We allow inserting files in view mode if multibuffers are
     * 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. */
420
    /* Translators: try to keep this string under 10 characters long */
421
422
423
    sc_init_one(&main_list, NANO_INSERTFILE_KEY, N_("Read File"),
	IFHELP(nano_insert_msg, NANO_NO_KEY), NANO_INSERTFILE_FKEY,
	NANO_NO_KEY,
424
#ifdef ENABLE_MULTIBUFFER
425
		VIEW
426
#else
427
		NOVIEW
428
#endif
429
430
		, !ISSET(RESTRICTED) ? do_insertfile_void :
		nano_disabled_msg);
Chris Allegretta's avatar
Chris Allegretta committed
431

432
    /* Translators: try to keep this string under 10 characters long */
433
434
435
    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
436

437
    /* Translators: try to keep this string under 10 characters long */
438
439
440
    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
441

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

447
    /* Translators: try to keep this string under 10 characters long */
448
449
450
    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
451

452
    if (unjustify)
453
    /* Translators: try to keep this string under 10 characters long */
454
455
	sc_init_one(&main_list, NANO_UNJUSTIFY_KEY, N_("UnJustify"),
		IFHELP(NULL, NANO_NO_KEY), NANO_UNJUSTIFY_FKEY,
456
		NANO_NO_KEY, NOVIEW, NULL);
457
    else
458
    /* Translators: try to keep this string under 10 characters long */
459
	sc_init_one(&main_list, NANO_UNCUT_KEY, N_("UnCut Txt"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
460
461
		IFHELP(nano_uncut_msg, NANO_NO_KEY), NANO_UNCUT_FKEY,
		NANO_NO_KEY, NOVIEW, do_uncut_text);
Chris Allegretta's avatar
Chris Allegretta committed
462

463
    /* Translators: try to keep this string under 10 characters long */
464
465
466
    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
467

468
469
470
    /* 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. */
471
    /* Translators: try to keep this string under 10 characters long */
472
    sc_init_one(&main_list, NANO_SPELL_KEY, N_("To Spell"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
473
		IFHELP(nano_spell_msg, NANO_NO_KEY), NANO_SPELL_FKEY,
474
475
476
477
478
		NANO_NO_KEY, NOVIEW,
#ifndef DISABLE_SPELLER
		!ISSET(RESTRICTED) ? do_spell :
#endif
		nano_disabled_msg);
479

480
    sc_init_one(&main_list, NANO_GOTOLINE_KEY, go_to_line_msg,
481
482
	IFHELP(nano_gotoline_msg, NANO_GOTOLINE_ALTKEY),
	NANO_GOTOLINE_FKEY, NANO_NO_KEY, VIEW, do_gotoline_void);
483

484
    sc_init_one(&main_list, NANO_REPLACE_KEY, replace_msg,
485
486
	IFHELP(nano_replace_msg, NANO_ALT_REPLACE_KEY),
	NANO_REPLACE_FKEY, NANO_NO_KEY, NOVIEW, do_replace);
Chris Allegretta's avatar
Chris Allegretta committed
487

488
#ifndef NANO_SMALL
489
490
    sc_init_one(&main_list, NANO_MARK_KEY, N_("Mark Text"),
	IFHELP(nano_mark_msg, NANO_MARK_ALTKEY), NANO_MARK_FKEY,
491
	NANO_NO_KEY, NOVIEW, do_mark);
492
493
494

    sc_init_one(&main_list, NANO_NO_KEY, N_("Where Is Next"),
	IFHELP(nano_whereis_next_msg, NANO_WHEREIS_NEXT_KEY),
495
	NANO_WHEREIS_NEXT_FKEY, NANO_NO_KEY, VIEW, do_research);
496
497
#endif

498
499
500
    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
501

502
503
504
    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
505

506
507
508
    sc_init_one(&main_list, NANO_FORWARD_KEY, N_("Forward"),
	IFHELP(nano_forward_msg, NANO_NO_KEY), NANO_NO_KEY,
	NANO_NO_KEY, VIEW, do_right_void);
Chris Allegretta's avatar
Chris Allegretta committed
509

510
511
512
    sc_init_one(&main_list, NANO_BACK_KEY, N_("Back"),
	IFHELP(nano_back_msg, NANO_NO_KEY), NANO_NO_KEY,
	NANO_NO_KEY, VIEW, do_left_void);
Chris Allegretta's avatar
Chris Allegretta committed
513

514
515
516
    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
517

518
519
520
    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
521

522
523
524
    sc_init_one(&main_list, NANO_REFRESH_KEY, N_("Refresh"),
	IFHELP(nano_refresh_msg, NANO_NO_KEY), NANO_NO_KEY,
	NANO_NO_KEY, VIEW, total_refresh);
Chris Allegretta's avatar
Chris Allegretta committed
525

526
527
528
    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
529

530
531
532
    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
533

534
535
536
    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
537

538
539
540
    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);
541

542
#ifndef NANO_SMALL
543
544
545
    sc_init_one(&main_list, NANO_NEXTWORD_KEY, N_("Next Word"),
	IFHELP(nano_nextword_msg, NANO_NO_KEY), NANO_NO_KEY,
	NANO_NO_KEY, VIEW, do_next_word);
546

547
548
549
    sc_init_one(&main_list, NANO_NO_KEY, N_("Prev Word"),
	IFHELP(nano_prevword_msg, NANO_PREVWORD_KEY), NANO_NO_KEY,
	NANO_NO_KEY, VIEW, do_prev_word);
550
#endif
551

552
553
554
555
#ifndef DISABLE_JUSTIFY
    /* Translators: try to keep this string under 10 characters long */
    sc_init_one(&main_list, NANO_NO_KEY, beg_of_par_msg,
	IFHELP(nano_parabegin_msg, NANO_PARABEGIN_ALTKEY1), NANO_NO_KEY,
556
	NANO_PARABEGIN_ALTKEY2, VIEW, do_para_begin_void);
557
558
559
560

    /* Translators: try to keep this string under 10 characters long */
    sc_init_one(&main_list, NANO_NO_KEY, end_of_par_msg,
	IFHELP(nano_paraend_msg, NANO_PARAEND_ALTKEY1), NANO_NO_KEY,
561
	NANO_PARAEND_ALTKEY2, VIEW, do_para_end_void);
562
#endif
563

564
#ifdef ENABLE_MULTIBUFFER
565
566
567
    sc_init_one(&main_list, NANO_NO_KEY, N_("Previous File"),
	IFHELP(nano_openprev_msg, NANO_OPENPREV_KEY), NANO_NO_KEY,
	NANO_OPENPREV_ALTKEY, VIEW, open_prevfile_void);
568

569
570
571
    sc_init_one(&main_list, NANO_NO_KEY, N_("Next File"),
	IFHELP(nano_opennext_msg, NANO_OPENNEXT_KEY), NANO_NO_KEY,
	NANO_OPENNEXT_ALTKEY, VIEW, open_nextfile_void);
572
#endif
573

574
575
576
577
    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);

578
579
580
581
582
583
584
#ifndef NANO_SMALL
    /* Translators: try to keep this string under 10 characters long */
    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

585
586
587
#ifndef DISABLE_JUSTIFY
    /* Translators: try to keep this string under 10 characters long */
    sc_init_one(&main_list, NANO_NO_KEY, fulljstify_msg,
588
589
	IFHELP(nano_fulljustify_msg, NANO_FULLJUSTIFY_ALTKEY),
	NANO_NO_KEY, NANO_NO_KEY, NOVIEW, do_full_justify);
590
591
#endif

592
#if !defined(NANO_SMALL) && defined(HAVE_REGEX_H)
593
594
595
    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);
596
597
#endif

598
    free_shortcutage(&whereis_list);
599

600
601
602
    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,
603
604
605
606
607
608
#ifndef DISABLE_HELP
		do_help
#else
		nano_disabled_msg
#endif
		);
609

610
    /* Translators: try to keep this string under 10 characters long */
611
612
    sc_init_one(&whereis_list, NANO_CANCEL_KEY, cancel_msg,
	IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY,
613
	NANO_NO_KEY, VIEW, NULL);
614

615
    /* Translators: try to keep this string under 10 characters long */
616
617
618
    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
619

620
    /* Translators: try to keep this string under 10 characters long */
621
622
623
    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
624

625
    /* Translators: try to keep this string under 10 characters long */
626
    sc_init_one(&whereis_list, NANO_TOOTHERSEARCH_KEY, replace_msg,
627
	IFHELP(nano_replace_msg, NANO_NO_KEY), NANO_REPLACE_FKEY,
628
	NANO_NO_KEY, VIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
629

630
    /* Translators: try to keep this string under 10 characters long */
631
632
    sc_init_one(&whereis_list, NANO_TOGOTOLINE_KEY, go_to_line_msg,
	IFHELP(nano_gotoline_msg, NANO_NO_KEY), NANO_GOTOLINE_FKEY,
633
	NANO_NO_KEY, VIEW, NULL);
634

635
636
#ifndef DISABLE_JUSTIFY
    /* Translators: try to keep this string under 10 characters long */
637
    sc_init_one(&whereis_list, NANO_PARABEGIN_KEY, beg_of_par_msg,
638
	IFHELP(nano_parabegin_msg, NANO_PARABEGIN_ALTKEY1), NANO_NO_KEY,
639
	NANO_PARABEGIN_ALTKEY2, VIEW, do_para_begin_void);
640
641

    /* Translators: try to keep this string under 10 characters long */
642
    sc_init_one(&whereis_list, NANO_PARAEND_KEY, end_of_par_msg,
643
	IFHELP(nano_paraend_msg, NANO_PARAEND_ALTKEY1), NANO_NO_KEY,
644
	NANO_PARAEND_ALTKEY2, VIEW, do_para_end_void);
645
646
#endif

647
#ifndef NANO_SMALL
648
    /* Translators: try to keep this string under 10 characters long */
649
650
    sc_init_one(&whereis_list, NANO_NO_KEY, case_sens_msg,
	IFHELP(nano_case_msg, TOGGLE_CASE_KEY), NANO_NO_KEY,
651
	NANO_NO_KEY, VIEW, NULL);
652

653
    /* Translators: try to keep this string under 10 characters long */
654
655
    sc_init_one(&whereis_list, NANO_NO_KEY, direction_msg,
	IFHELP(nano_reverse_msg, TOGGLE_BACKWARDS_KEY), NANO_NO_KEY,
656
	NANO_NO_KEY, VIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
657

658
#ifdef HAVE_REGEX_H
659
    /* Translators: try to keep this string under 10 characters long */
660
661
    sc_init_one(&whereis_list, NANO_NO_KEY, regexp_msg,
	IFHELP(nano_regexp_msg, TOGGLE_REGEXP_KEY), NANO_NO_KEY,
662
	NANO_NO_KEY, VIEW, NULL);
663
#endif
664

665
    /* Translators: try to keep this string under 10 characters long */
666
667
    sc_init_one(&whereis_list, NANO_HISTORY_KEY, history_msg,
	IFHELP(nano_editstr_msg, NANO_NO_KEY), NANO_NO_KEY,
668
	NANO_NO_KEY, VIEW, NULL);
669
670
671
672
673

    /* Translators: try to keep this string under 10 characters long */
    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);
674
#endif /* !NANO_SMALL */
675
676
677
678
679
680
681

#ifndef DISABLE_JUSTIFY
    /* Translators: try to keep this string under 10 characters long */
    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
682

683
    free_shortcutage(&replace_list);
684

685
686
687
    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,
688
689
690
691
692
693
#ifndef DISABLE_HELP
		do_help
#else
		nano_disabled_msg
#endif
		);
694

695
696
    sc_init_one(&replace_list, NANO_CANCEL_KEY, cancel_msg,
	IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY,
697
	NANO_NO_KEY, VIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
698

699
700
701
    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
702

703
704
705
    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
706

707
    /* Translators: try to keep this string under 12 characters long */
708
    sc_init_one(&replace_list, NANO_TOOTHERSEARCH_KEY, N_("No Replace"),
709
	IFHELP(nano_whereis_msg, NANO_NO_KEY), NANO_REPLACE_FKEY,
710
	NANO_NO_KEY, VIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
711

712
713
    sc_init_one(&replace_list, NANO_TOGOTOLINE_KEY, go_to_line_msg,
	IFHELP(nano_gotoline_msg, NANO_NO_KEY), NANO_GOTOLINE_FKEY,
714
	NANO_NO_KEY, VIEW, NULL);
715

716
#ifndef NANO_SMALL
717
718
    sc_init_one(&replace_list, NANO_NO_KEY, case_sens_msg,
	IFHELP(nano_case_msg, TOGGLE_CASE_KEY), NANO_NO_KEY,
719
	NANO_NO_KEY, VIEW, NULL);
720

721
722
    sc_init_one(&replace_list, NANO_NO_KEY, direction_msg,
	IFHELP(nano_reverse_msg, TOGGLE_BACKWARDS_KEY), NANO_NO_KEY,
723
	NANO_NO_KEY, VIEW, NULL);
724

725
#ifdef HAVE_REGEX_H
726
727
    sc_init_one(&replace_list, NANO_NO_KEY, regexp_msg,
	IFHELP(nano_regexp_msg, TOGGLE_REGEXP_KEY), NANO_NO_KEY,
728
	NANO_NO_KEY, VIEW, NULL);
729
#endif
730

731
732
    sc_init_one(&replace_list, NANO_HISTORY_KEY, history_msg,
	IFHELP(nano_editstr_msg, NANO_NO_KEY), NANO_NO_KEY,
733
	NANO_NO_KEY, VIEW, NULL);
734
#endif /* !NANO_SMALL */
735

736
    free_shortcutage(&replace_list_2);
737

738
739
740
    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,
741
742
743
744
745
746
#ifndef DISABLE_HELP
		do_help
#else
		nano_disabled_msg
#endif
		);
747

748
749
    sc_init_one(&replace_list_2, NANO_CANCEL_KEY, cancel_msg,
	IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY,
750
	NANO_NO_KEY, VIEW, NULL);
751

752
753
754
    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);
755

756
757
758
    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);
759

760
#ifndef NANO_SMALL
761
762
    sc_init_one(&replace_list_2, NANO_HISTORY_KEY, history_msg,
	IFHELP(nano_editstr_msg, NANO_NO_KEY), NANO_NO_KEY,
763
	NANO_NO_KEY, VIEW, NULL);
764
765
#endif

766
    free_shortcutage(&gotoline_list);
Chris Allegretta's avatar
Chris Allegretta committed
767

768
    sc_init_one(&gotoline_list, NANO_HELP_KEY, get_help_msg,
769
770
	IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
	NANO_NO_KEY, VIEW,
771
772
773
774
775
776
#ifndef DISABLE_HELP
		do_help
#else
		nano_disabled_msg
#endif
		);
777

778
    sc_init_one(&gotoline_list, NANO_CANCEL_KEY, cancel_msg,
779
	IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY,
780
	NANO_NO_KEY, VIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
781

782
    sc_init_one(&gotoline_list, NANO_FIRSTLINE_KEY, first_line_msg,
783
784
	IFHELP(nano_firstline_msg, NANO_NO_KEY), NANO_NO_KEY,
	NANO_NO_KEY, VIEW, do_first_line);
Chris Allegretta's avatar
Chris Allegretta committed
785

786
    sc_init_one(&gotoline_list, NANO_LASTLINE_KEY, last_line_msg,
787
788
	IFHELP(nano_lastline_msg, NANO_NO_KEY), NANO_NO_KEY,
	NANO_NO_KEY, VIEW, do_last_line);
Chris Allegretta's avatar
Chris Allegretta committed
789

790
791
    sc_init_one(&gotoline_list, NANO_TOOTHERWHEREIS_KEY,
	N_("Go To Text"), IFHELP(nano_whereis_msg, NANO_NO_KEY),
792
	NANO_NO_KEY, NANO_NO_KEY, VIEW, NULL);
793

Chris Allegretta's avatar
Chris Allegretta committed
794
#ifndef DISABLE_HELP
795
    free_shortcutage(&help_list);
Chris Allegretta's avatar
Chris Allegretta committed
796

797
798
    sc_init_one(&help_list, NANO_PREVPAGE_KEY, prev_page_msg,
	IFHELP(nano_prevpage_msg, NANO_NO_KEY), NANO_PREVPAGE_FKEY,
799
	NANO_NO_KEY, VIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
800

801
802
    sc_init_one(&help_list, NANO_NEXTPAGE_KEY, next_page_msg,
	IFHELP(nano_nextpage_msg, NANO_NO_KEY), NANO_NEXTPAGE_FKEY,
803
	NANO_NO_KEY, VIEW, NULL);
804

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

809
810
    sc_init_one(&help_list, NANO_NEXTLINE_KEY, N_("Next Line"),
	IFHELP(nano_nextline_msg, NANO_NO_KEY), NANO_NO_KEY,
811
	NANO_NO_KEY, VIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
812

813
814
815
816
    sc_init_one(&help_list, NANO_REFRESH_KEY, N_("Refresh"),
	IFHELP(nano_refresh_msg, NANO_NO_KEY), NANO_NO_KEY,
	NANO_NO_KEY, VIEW, NULL);

817
818
    sc_init_one(&help_list, NANO_EXIT_KEY, exit_msg,
	IFHELP(nano_exit_msg, NANO_NO_KEY), NANO_EXIT_FKEY,
819
	NANO_NO_KEY, VIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
820
#endif
Chris Allegretta's avatar
Chris Allegretta committed
821

822
    free_shortcutage(&writefile_list);
Chris Allegretta's avatar
Chris Allegretta committed
823

824
825
826
    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,
827
828
829
830
831
832
#ifndef DISABLE_HELP
		do_help
#else
		nano_disabled_msg
#endif
		);
833

834
835
    sc_init_one(&writefile_list, NANO_CANCEL_KEY, cancel_msg,
	IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY,
836
	NANO_NO_KEY, VIEW, NULL);
837

838
#ifndef DISABLE_BROWSER
839
840
    /* If we're using restricted mode, the file browser is disabled.
     * It's useless since inserting files is disabled. */
841
    /* Translators: try to keep this string under 16 characters long */
842
    if (!ISSET(RESTRICTED))
843
	sc_init_one(&writefile_list, NANO_TOFILES_KEY, to_files_msg,
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
844
		IFHELP(nano_tofiles_msg, NANO_NO_KEY), NANO_NO_KEY,
845
		NANO_NO_KEY, NOVIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
846
#endif
Chris Allegretta's avatar
Chris Allegretta committed
847

848
#ifndef NANO_SMALL
849
850
851
852
853
854
    /* 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. */
855
    /* Translators: try to keep this string under 16 characters long */
856
    if (!ISSET(RESTRICTED))
857
	sc_init_one(&writefile_list, NANO_NO_KEY, N_("DOS Format"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
858
		IFHELP(nano_dos_msg, TOGGLE_DOS_KEY), NANO_NO_KEY,
859
		NANO_NO_KEY, NOVIEW, NULL);
860

861
    /* Translators: try to keep this string under 16 characters long */
862
    if (!ISSET(RESTRICTED))
863
	sc_init_one(&writefile_list, NANO_NO_KEY, N_("Mac Format"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
864
		IFHELP(nano_mac_msg, TOGGLE_MAC_KEY), NANO_NO_KEY,
865
		NANO_NO_KEY, NOVIEW, NULL);
866
867
#endif

868
    /* Translators: try to keep this string under 16 characters long */
869
    if (!ISSET(RESTRICTED))
870
	sc_init_one(&writefile_list, NANO_NO_KEY, N_("Append"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
871
		IFHELP(nano_append_msg, NANO_APPEND_KEY), NANO_NO_KEY,
872
		NANO_NO_KEY, NOVIEW, NULL);
873

874
    /* Translators: try to keep this string under 16 characters long */
875
    if (!ISSET(RESTRICTED))
876
	sc_init_one(&writefile_list, NANO_NO_KEY, N_("Prepend"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
877
		IFHELP(nano_prepend_msg, NANO_PREPEND_KEY), NANO_NO_KEY,
878
		NANO_NO_KEY, NOVIEW, NULL);
879

880
#ifndef NANO_SMALL
881
    /* Translators: try to keep this string under 16 characters long */
882
    if (!ISSET(RESTRICTED))
883
	sc_init_one(&writefile_list, NANO_NO_KEY, N_("Backup File"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
884
		IFHELP(nano_backup_msg, TOGGLE_BACKUP_KEY), NANO_NO_KEY,
885
		NANO_NO_KEY, NOVIEW, NULL);
886
887
#endif

888
    free_shortcutage(&insertfile_list);
889

890
891
892
    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,
893
894
895
896
897
898
#ifndef DISABLE_HELP
		do_help
#else
		nano_disabled_msg
#endif
		);
899

900
    sc_init_one(&insertfile_list, NANO_CANCEL_KEY, cancel_msg,
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
901
		IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY,
902
		NANO_NO_KEY, VIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
903

904
#ifndef DISABLE_BROWSER
905
906
    /* If we're using restricted mode, the file browser is disabled.
     * It's useless since inserting files is disabled. */
907
    if (!ISSET(RESTRICTED))
908
	sc_init_one(&insertfile_list, NANO_TOFILES_KEY, to_files_msg,
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
909
		IFHELP(nano_tofiles_msg, NANO_NO_KEY), NANO_NO_KEY,
910
		NANO_NO_KEY, NOVIEW, NULL);
911
#endif
912

913
#ifndef NANO_SMALL
914
915
    /* If we're using restricted mode, command execution is disabled.
     * It's useless since inserting files is disabled. */
916
    /* Translators: try to keep this string under 22 characters long */
917
    if (!ISSET(RESTRICTED))
918
919
	sc_init_one(&insertfile_list, NANO_TOOTHERINSERT_KEY,
		N_("Execute Command"), IFHELP(nano_execute_msg,
920
		NANO_NO_KEY), NANO_NO_KEY, NANO_NO_KEY, NOVIEW, NULL);
921

922
#ifdef ENABLE_MULTIBUFFER
923
924
    /* If we're using restricted mode, the multibuffer toggle is
     * disabled.  It's useless since inserting files is disabled. */
925
    /* Translators: try to keep this string under 22 characters long */
926
    if (!ISSET(RESTRICTED))
927
	sc_init_one(&insertfile_list, NANO_NO_KEY, new_buffer_msg,
928
		IFHELP(nano_multibuffer_msg, TOGGLE_MULTIBUFFER_KEY),
929
		NANO_NO_KEY, NANO_NO_KEY, NOVIEW, NULL);
930
#endif
931
#endif
932

Chris Allegretta's avatar
Chris Allegretta committed
933
#ifndef DISABLE_SPELLER
934
    free_shortcutage(&spell_list);
Chris Allegretta's avatar
Chris Allegretta committed
935

936
937
938
    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,
939
940
941
942
943
944
#ifndef DISABLE_HELP
		do_help
#else
		nano_disabled_msg
#endif
		);
945

946
947
    sc_init_one(&spell_list, NANO_CANCEL_KEY, cancel_msg,
	IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY,
948
	NANO_NO_KEY, VIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
949
#endif
Chris Allegretta's avatar
Chris Allegretta committed
950

951
#ifndef NANO_SMALL
952
    free_shortcutage(&extcmd_list);
Chris Allegretta's avatar
Chris Allegretta committed
953

954
955
956
    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,
957
958
959
960
961
962
#ifndef DISABLE_HELP
		do_help
#else
		nano_disabled_msg
#endif
		);
963

964
965
    sc_init_one(&extcmd_list, NANO_CANCEL_KEY, cancel_msg,
	IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY,
966
	NANO_NO_KEY, VIEW, NULL);
967

968
969
    sc_init_one(&extcmd_list, NANO_TOOTHERINSERT_KEY, N_("Insert File"),
	IFHELP(nano_insert_msg, NANO_NO_KEY), NANO_NO_KEY,
970
	NANO_NO_KEY, VIEW, NULL);
971

David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
972
#ifdef ENABLE_MULTIBUFFER
973
    sc_init_one(&extcmd_list, NANO_NO_KEY, new_buffer_msg,
974
	IFHELP(nano_multibuffer_msg, TOGGLE_MULTIBUFFER_KEY),
975
	NANO_NO_KEY, NANO_NO_KEY, NOVIEW, NULL);
976
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
977
#endif
978

979
#ifndef DISABLE_BROWSER
980
    free_shortcutage(&browser_list);
981

982
983
984
    sc_init_one(&browser_list, NANO_HELP_KEY, get_help_msg,
	IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
	NANO_NO_KEY, VIEW,
985
986
987
988
989
990
#ifndef DISABLE_HELP
		do_help
#else
		nano_disabled_msg
#endif
		);
991

992
    sc_init_one(&browser_list, NANO_EXIT_KEY, exit_msg,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
993
	IFHELP(nano_exitbrowser_msg, NANO_NO_KEY), NANO_EXIT_FKEY,
994
	NANO_NO_KEY, VIEW, NULL);
995

996
997
    sc_init_one(&browser_list, NANO_PREVPAGE_KEY, prev_page_msg,
	IFHELP(nano_prevpage_msg, NANO_NO_KEY), NANO_PREVPAGE_FKEY,
998
	NANO_NO_KEY, VIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
999

1000
1001
    sc_init_one(&browser_list, NANO_NEXTPAGE_KEY, next_page_msg,
	IFHELP(nano_nextpage_msg, NANO_NO_KEY), NANO_NEXTPAGE_FKEY,
1002
	NANO_NO_KEY, VIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
1003

1004
1005
1006
1007
    sc_init_one(&browser_list, NANO_REFRESH_KEY, N_("Refresh"),
	IFHELP(nano_refresh_msg, NANO_NO_KEY), NANO_NO_KEY,
	NANO_NO_KEY, VIEW, NULL);

1008
    /* Translators: try to keep this string under 22 characters long */
1009
    sc_init_one(&browser_list, NANO_GOTOLINE_KEY, N_("Go To Dir"),
1010
	IFHELP(nano_gotodir_msg, NANO_GOTOLINE_ALTKEY),
1011
	NANO_GOTOLINE_FKEY, NANO_NO_KEY, VIEW, NULL);
Rocco Corsi's avatar
   
Rocco Corsi committed
1012

1013
    free_shortcutage(&gotodir_list);
1014

1015
1016
1017
    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,
1018
1019
1020
1021
1022
1023
#ifndef DISABLE_HELP
		do_help
#else
		nano_disabled_msg
#endif
		);
Chris Allegretta's avatar
Chris Allegretta committed
1024

1025
1026
    sc_init_one(&gotodir_list, NANO_CANCEL_KEY, cancel_msg,
	IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY,
1027
	NANO_NO_KEY, VIEW, NULL);
Chris Allegretta's avatar
Chris Allegretta committed
1028
1029
#endif

1030
    currshortcut = main_list;
1031

1032
#ifndef NANO_SMALL
1033
    toggle_init();
1034
#endif
1035
}
1036

1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
/* Deallocate the given shortcut. */
void free_shortcutage(shortcut **shortcutage)
{
    assert(shortcutage != NULL);
    while (*shortcutage != NULL) {
	shortcut *ps = *shortcutage;
	*shortcutage = (*shortcutage)->next;
	free(ps);
    }
}

#ifndef NANO_SMALL
/* Create one new toggle structure, at the end of the toggles linked
 * list. */
void toggle_init_one(int val, const char *desc, long flag)
{
    toggle *u;

    if (toggles == NULL) {
1056
	toggles = (toggle *)nmalloc(sizeof(toggle));
1057
1058
1059
1060
	u = toggles;
    } else {
	for (u = toggles; u->next != NULL; u = u->next)
	    ;
1061
	u->next = (toggle *)nmalloc(sizeof(toggle));
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
	u = u->next;
    }

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

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);
#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))
1083
1084
	toggle_init_one(TOGGLE_MULTIBUFFER_KEY,
		N_("Multiple file buffers"), MULTIBUFFER);
1085
1086
1087
#endif
    toggle_init_one(TOGGLE_CONST_KEY, N_("Constant cursor position"),
	CONSTUPDATE);
1088
1089
    toggle_init_one(TOGGLE_AUTOINDENT_KEY, N_("Auto indent"),
	AUTOINDENT);
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
#ifndef DISABLE_WRAPPING
    toggle_init_one(TOGGLE_WRAP_KEY, N_("Auto line wrap"), NO_WRAP);
#endif
    toggle_init_one(TOGGLE_CUTTOEND_KEY, N_("Cut to end"), CUT_TO_END);
    /* 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);
#ifndef DISABLE_MOUSE
    toggle_init_one(TOGGLE_MOUSE_KEY, N_("Mouse support"), USE_MOUSE);
#endif
1101
1102
1103
    /* If we're using restricted mode, the DOS/Mac conversion toggle is
     * disabled.  It's useless since inserting files is disabled. */
    if (!ISSET(RESTRICTED))
1104
1105
	toggle_init_one(TOGGLE_NOCONVERT_KEY,
		N_("No conversion from DOS/Mac format"), NO_CONVERT);
1106
1107
1108
    /* If we're using restricted mode, the backup toggle is disabled.
     * It's useless since backups are disabled. */
    if (!ISSET(RESTRICTED))
1109
1110
1111
1112
1113
1114
	toggle_init_one(TOGGLE_BACKUP_KEY, N_("Backup files"),
		BACKUP_FILE);
    toggle_init_one(TOGGLE_SMOOTH_KEY, N_("Smooth scrolling"),
	SMOOTHSCROLL);
    toggle_init_one(TOGGLE_SMARTHOME_KEY, N_("Smart home key"),
	SMART_HOME);
1115
1116
#ifdef ENABLE_COLOR
    toggle_init_one(TOGGLE_SYNTAX_KEY, N_("Color syntax highlighting"),
1117
	NO_COLOR_SYNTAX);
1118
1119
1120
1121
1122
#endif
#ifdef ENABLE_NANORC
    toggle_init_one(TOGGLE_WHITESPACE_KEY, N_("Whitespace display"),
	WHITESPACE_DISPLAY);
#endif
1123
1124
    toggle_init_one(TOGGLE_MORESPACE_KEY, N_("Use of more space for editing"),
	MORE_SPACE);
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
}

#ifdef DEBUG
/* Deallocate all of the toggles. */
void free_toggles(void)
{
    while (toggles != NULL) {
	toggle *pt = toggles;	/* Think "previous toggle". */

	toggles = toggles->next;
	free(pt);
    }
}
#endif
#endif /* !NANO_SMALL */

1141
1142
1143
/* 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
1144
 * function unless debugging is turned on. */
1145
#ifdef DEBUG
1146
/* Added by SPK for memory cleanup; gracefully return our malloc()s. */
Chris Allegretta's avatar
Chris Allegretta committed
1147
void thanks_for_all_the_fish(void)
1148
{
1149
1150
1151
1152
    delwin(topwin);
    delwin(edit);
    delwin(bottomwin);

Chris Allegretta's avatar
Chris Allegretta committed
1153
1154
1155
#ifndef DISABLE_JUSTIFY
    if (quotestr != NULL)
	free(quotestr);
1156
1157
1158
1159
#ifdef HAVE_REGEX_H
    regfree(&quotereg);
    free(quoteerr);
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1160
#endif
1161
1162
1163
1164
#ifndef NANO_SMALL
    if (backup_dir != NULL)
        free(backup_dir);
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1165
#ifndef DISABLE_OPERATINGDIR
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
    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);
    if (hblank != NULL)
	free(hblank);
#ifndef DISABLE_SPELLER
    if (alt_speller != NULL)
	free(alt_speller);
#endif
1181
#ifndef DISABLE_HELP
1182
1183
    if (help_text != NULL)
	free(help_text);
1184
#endif
1185
1186
1187
1188
1189
    if (filename != NULL)
	free(filename);
    if (answer != NULL)
	free(answer);
    if (cutbuffer != NULL)
Chris Allegretta's avatar
Chris Allegretta committed
1190
	free_filestruct(cutbuffer);
1191
1192
1193
1194
#ifndef DISABLE_JUSTIFY
    if (jusbuffer != NULL)
	free_filestruct(jusbuffer);
#endif
1195
1196
1197
1198
    free_shortcutage(&main_list);
    free_shortcutage(&whereis_list);
    free_shortcutage(&replace_list);
    free_shortcutage(&replace_list_2);
1199
    free_shortcutage(&gotoline_list);
1200
1201
    free_shortcutage(&writefile_list);
    free_shortcutage(&insertfile_list);
Chris Allegretta's avatar
Chris Allegretta committed
1202
#ifndef DISABLE_HELP
Chris Allegretta's avatar
Chris Allegretta committed
1203
    free_shortcutage(&help_list);
Chris Allegretta's avatar
Chris Allegretta committed
1204
1205
#endif
#ifndef DISABLE_SPELLER
1206
    free_shortcutage(&spell_list);
Chris Allegretta's avatar
Chris Allegretta committed
1207
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1208
1209
1210
#ifndef NANO_SMALL
    free_shortcutage(&extcmd_list);
#endif
1211
1212
#ifndef DISABLE_BROWSER
    free_shortcutage(&browser_list);
Chris Allegretta's avatar
Chris Allegretta committed
1213
    free_shortcutage(&gotodir_list);
1214
1215
1216
1217
1218
1219
1220
#endif

#ifndef NANO_SMALL
    free_toggles();
#endif

#ifdef ENABLE_MULTIBUFFER
1221
    if (open_files != NULL) {
1222
	/* We free the memory associated with each open file. */
1223
1224
	while (open_files->prev != NULL)
	    open_files = open_files->prev;
Chris Allegretta's avatar
Chris Allegretta committed
1225
	free_openfilestruct(open_files);
1226
    }
1227
#else
1228
    free_filestruct(fileage);
1229
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240

#ifdef ENABLE_COLOR
    free(syntaxstr);
    while (syntaxes != NULL) {
	syntaxtype *bill = syntaxes;

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

	    syntaxes->extensions = bob->next;
Chris Allegretta's avatar
Chris Allegretta committed
1241
	    regfree(&bob->val);
Chris Allegretta's avatar
Chris Allegretta committed
1242
1243
1244
1245
1246
1247
	    free(bob);
	}
	while (syntaxes->color != NULL) {
	    colortype *bob = syntaxes->color;

	    syntaxes->color = bob->next;
Chris Allegretta's avatar
Chris Allegretta committed
1248
1249
	    regfree(&bob->start);
	    if (bob->end != NULL)
1250
1251
		regfree(bob->end);
	    free(bob->end);
Chris Allegretta's avatar
Chris Allegretta committed
1252
1253
1254
1255
1256
1257
	    free(bob);
	}
	syntaxes = syntaxes->next;
	free(bill);
    }
#endif /* ENABLE_COLOR */
1258
1259
1260
1261
1262
#ifndef NANO_SMALL
    /* free history lists */
    free_history(&search_history);
    free_history(&replace_history);
#endif
1263
1264
1265
#ifdef ENABLE_NANORC
    free(homedir);
#endif
1266
}
1267
#endif /* DEBUG */