global.c 36.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-2004 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
22
 *   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.            *
 *                                                                        *
 **************************************************************************/

#include "config.h"
23

24
#include <stdlib.h>
25
#include <assert.h>
26
#include <sys/stat.h>
Chris Allegretta's avatar
Chris Allegretta committed
27
#include "proto.h"
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
28
#include "nano.h"
Chris Allegretta's avatar
Chris Allegretta committed
29

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

32
#ifndef DISABLE_WRAPJUSTIFY
Chris Allegretta's avatar
Chris Allegretta committed
33
34
/* wrap_at might be set in rcfile.c or nano.c */
int wrap_at = -CHARS_FROM_EOL;/* Right justified fill value, allows resize */
35
36
#endif

Chris Allegretta's avatar
Chris Allegretta committed
37
38
39
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? */
Chris Allegretta's avatar
Chris Allegretta committed
40
int search_offscreen;		/* Search lines not displayed */
Chris Allegretta's avatar
Chris Allegretta committed
41

42
int flags = 0;			/* Our new flag containing many options */
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
43
WINDOW *edit;			/* The file portion of the editor */
Chris Allegretta's avatar
Chris Allegretta committed
44
45
WINDOW *topwin;			/* Top line of screen */
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
55
56
57
58
59
60
61
62
63
64
int editwinrows = 0;		/* How many rows long is the edit
				   window? */
filestruct *current;		/* Current buffer pointer */
int current_x = 0, current_y = 0;	/* Current position of X and Y in
					   the editor - relative to edit
					   window (0,0) */
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
#ifdef ENABLE_MULTIBUFFER
66
openfilestruct *open_files = NULL;	/* The list of open files */
67
68
#endif

69
#ifndef DISABLE_JUSTIFY
Chris Allegretta's avatar
Chris Allegretta committed
70
71
char *quotestr = NULL;		/* Quote string.  The default value is
				   set in main(). */
Chris Allegretta's avatar
Chris Allegretta committed
72
#endif
73

74
75
76
77
#ifndef NANO_SMALL
char *backup_dir = NULL;	/* Backup directory. */
#endif

78
79
int resetstatuspos;		/* Hack for resetting the status bar 
				   cursor position */
Chris Allegretta's avatar
Chris Allegretta committed
80
char *answer = NULL;		/* Answer str to many questions */
Chris Allegretta's avatar
Chris Allegretta committed
81
int totlines = 0;		/* Total number of lines in the file */
82
long totsize = 0;		/* Total number of bytes in the file */
83
int placewewant = 0;		/* The column we'd like the cursor
Chris Allegretta's avatar
Chris Allegretta committed
84
85
86
				   to jump to when we go to the
				   next or previous line */

Chris Allegretta's avatar
Chris Allegretta committed
87
88
int tabsize = -1;		/* Our internal tabsize variable.  The
				   default value 8 is set in main(). */
89

Chris Allegretta's avatar
Chris Allegretta committed
90
char *hblank = NULL;		/* A horizontal blank line */
Chris Allegretta's avatar
Chris Allegretta committed
91
#ifndef DISABLE_HELP
Chris Allegretta's avatar
Chris Allegretta committed
92
char *help_text;		/* The text in the help window */
Chris Allegretta's avatar
Chris Allegretta committed
93
#endif
Chris Allegretta's avatar
Chris Allegretta committed
94
95
96

/* More stuff for the marker select */

Chris Allegretta's avatar
Chris Allegretta committed
97
#ifndef NANO_SMALL
98
filestruct *mark_beginbuf;	/* The begin marker buffer */
Chris Allegretta's avatar
Chris Allegretta committed
99
int mark_beginx;		/* X value in the string to start */
Chris Allegretta's avatar
Chris Allegretta committed
100
#endif
Chris Allegretta's avatar
Chris Allegretta committed
101

102
#ifndef DISABLE_OPERATINGDIR
103
104
char *operating_dir = NULL;	/* Operating directory, which we can't */
char *full_operating_dir = NULL;/* go higher than */
105
106
#endif

107
#ifndef DISABLE_SPELLER
108
char *alt_speller = NULL;		/* Alternative spell command */
109
110
#endif

111
112
113
shortcut *main_list = NULL;
shortcut *whereis_list = NULL;
shortcut *replace_list = NULL;
114
shortcut *replace_list_2 = NULL; 	/* 2nd half of replace dialog */
115
116
117
shortcut *goto_list = NULL;
shortcut *writefile_list = NULL;
shortcut *insertfile_list = NULL;
Chris Allegretta's avatar
Chris Allegretta committed
118
#ifndef DISABLE_HELP
119
shortcut *help_list = NULL;
Chris Allegretta's avatar
Chris Allegretta committed
120
121
#endif
#ifndef DISABLE_SPELLER
122
shortcut *spell_list = NULL;
Chris Allegretta's avatar
Chris Allegretta committed
123
#endif
Chris Allegretta's avatar
Chris Allegretta committed
124
#ifndef NANO_SMALL
125
shortcut *extcmd_list = NULL;
Chris Allegretta's avatar
Chris Allegretta committed
126
#endif
127
#ifndef DISABLE_BROWSER
128
shortcut *browser_list = NULL;
129
shortcut *gotodir_list = NULL;
Chris Allegretta's avatar
Chris Allegretta committed
130
#endif
131

132
#ifdef ENABLE_COLOR
133
134
135
const colortype *colorstrings = NULL;
syntaxtype *syntaxes = NULL;
char *syntaxstr = NULL;
136
137
#endif

138
#if !defined(DISABLE_BROWSER) || !defined(DISABLE_HELP) || !defined(DISABLE_MOUSE)
Chris Allegretta's avatar
Chris Allegretta committed
139
const shortcut *currshortcut;	/* Current shortcut list we're using */
140
#endif
141

142
#ifndef NANO_SMALL
143
toggle *toggles = NULL;
144
#endif
Chris Allegretta's avatar
Chris Allegretta committed
145

146
147
148
149
150
#ifndef NANO_SMALL
historyheadtype search_history;
historyheadtype replace_history;
#endif

151
152
/* Regular expressions */

153
#ifdef HAVE_REGEX_H
154
155
156
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
157
#endif
158

159
160
161
162
163
int curses_ended = FALSE;	/* Indicates to statusbar() to simply
				 * write to stderr, since endwin() has
				 * ended curses mode. */


David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
164
int length_of_list(const shortcut *s)
165
166
{
    int i = 0;
167

168
    for (; s != NULL; s = s->next)
169
170
171
172
	i++;
    return i;
}

Chris Allegretta's avatar
Chris Allegretta committed
173
/* Initialize a struct *without* our lovely braces =( */
174
void sc_init_one(shortcut **shortcutage, int ctrlval, const char *desc,
175
#ifndef DISABLE_HELP
176
	const char *help,
177
#endif
178
179
	int metaval, int funcval, int miscval, int view, int
	(*func)(void))
Chris Allegretta's avatar
Chris Allegretta committed
180
{
181
182
183
    shortcut *s;

    if (*shortcutage == NULL) {
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
184
	*shortcutage = (shortcut *)nmalloc(sizeof(shortcut));
185
186
187
188
	s = *shortcutage;
    } else {
	for (s = *shortcutage; s->next != NULL; s = s->next)
	    ;
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
189
	s->next = (shortcut *)nmalloc(sizeof(shortcut));
190
191
192
	s = s->next; 
    }

193
    s->ctrlval = ctrlval;
Chris Allegretta's avatar
Chris Allegretta committed
194
    s->desc = desc;
195
#ifndef DISABLE_HELP
Chris Allegretta's avatar
Chris Allegretta committed
196
    s->help = help;
197
#endif
198
199
200
    s->metaval = metaval;
    s->funcval = funcval;
    s->miscval = miscval;
Chris Allegretta's avatar
Chris Allegretta committed
201
202
    s->viewok = view;
    s->func = func;
203
    s->next = NULL;
Chris Allegretta's avatar
Chris Allegretta committed
204
205
}

206
#ifndef NANO_SMALL
207
208
/* Create one new toggle structure, at the end of the toggles
 * linked list. */
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
209
void toggle_init_one(int val, const char *desc, int flag)
210
{
211
212
213
    toggle *u;

    if (toggles == NULL) {
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
214
	toggles = (toggle *)nmalloc(sizeof(toggle));
215
216
217
218
	u = toggles;
    } else {
	for (u = toggles; u->next != NULL; u = u->next)
	    ;
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
219
	u->next = (toggle *)nmalloc(sizeof(toggle));
220
221
222
223
224
225
226
	u = u->next;
    }

    u->val = val;
    u->desc = desc;
    u->flag = flag;
    u->next = NULL;
227
228
}

David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
229
void toggle_init(void)
230
231
{
    char *toggle_const_msg, *toggle_autoindent_msg, *toggle_suspend_msg,
232
	*toggle_nohelp_msg, *toggle_cuttoend_msg,
233
234
	*toggle_noconvert_msg, *toggle_dos_msg, *toggle_mac_msg,
	*toggle_backup_msg, *toggle_smooth_msg;
235
#ifndef DISABLE_MOUSE
236
237
    char *toggle_mouse_msg;
#endif
Chris Allegretta's avatar
Chris Allegretta committed
238
239
240
#ifndef DISABLE_WRAPPING
    char *toggle_wrap_msg;
#endif
241
#ifdef ENABLE_MULTIBUFFER
242
    char *toggle_multibuffer_msg;
243
#endif
244
245
246
#ifdef ENABLE_COLOR
    char *toggle_syntax_msg;
#endif
247

248
    /* There is no need to reinitialize the toggles.  They can't
Chris Allegretta's avatar
Chris Allegretta committed
249
       change. */
250
251
252
    if (toggles != NULL)
	return;

253
    toggle_const_msg = _("Constant cursor position");
254
    toggle_autoindent_msg = _("Auto indent");
255
    toggle_suspend_msg = _("Suspend");
256
    toggle_nohelp_msg = _("Help mode");
257
#ifndef DISABLE_MOUSE
258
    toggle_mouse_msg = _("Mouse support");
259
#endif
260
    toggle_cuttoend_msg = _("Cut to end");
261
262
263
    toggle_noconvert_msg = _("No conversion from DOS/Mac format");
    toggle_dos_msg = _("Writing file in DOS format");
    toggle_mac_msg = _("Writing file in Mac format");
264
    toggle_backup_msg = _("Backing up file");
265
    toggle_smooth_msg = _("Smooth scrolling");
266
267
268
#ifdef ENABLE_COLOR
    toggle_syntax_msg = _("Color syntax highlighting");
#endif
Chris Allegretta's avatar
Chris Allegretta committed
269
#ifndef DISABLE_WRAPPING
270
    toggle_wrap_msg = _("Auto line wrap");
Chris Allegretta's avatar
Chris Allegretta committed
271
#endif
272
#ifdef ENABLE_MULTIBUFFER
273
    toggle_multibuffer_msg = _("Multiple file buffers");
274
275
#endif

276
277
    toggle_init_one(TOGGLE_NOHELP_KEY, toggle_nohelp_msg, NO_HELP);
#ifdef ENABLE_MULTIBUFFER
278
279
    if (!ISSET(RESTRICTED))
	toggle_init_one(TOGGLE_MULTIBUFFER_KEY, toggle_multibuffer_msg, MULTIBUFFER);
280
#endif
281
282
    toggle_init_one(TOGGLE_CONST_KEY, toggle_const_msg, CONSTUPDATE);
    toggle_init_one(TOGGLE_AUTOINDENT_KEY, toggle_autoindent_msg, AUTOINDENT);
Chris Allegretta's avatar
Chris Allegretta committed
283
#ifndef DISABLE_WRAPPING
284
    toggle_init_one(TOGGLE_WRAP_KEY, toggle_wrap_msg, NO_WRAP);
Chris Allegretta's avatar
Chris Allegretta committed
285
#endif
286
    toggle_init_one(TOGGLE_CUTTOEND_KEY, toggle_cuttoend_msg, CUT_TO_END);
287
288
    if (!ISSET(RESTRICTED))
	toggle_init_one(TOGGLE_SUSPEND_KEY, toggle_suspend_msg, SUSPEND);
289
#ifndef DISABLE_MOUSE
290
    toggle_init_one(TOGGLE_MOUSE_KEY, toggle_mouse_msg, USE_MOUSE);
291
#endif
292
293
294
295
296
297
    if (!ISSET(RESTRICTED)) {
	toggle_init_one(TOGGLE_NOCONVERT_KEY, toggle_noconvert_msg, NO_CONVERT);
	toggle_init_one(TOGGLE_DOS_KEY, toggle_dos_msg, DOS_FILE);
	toggle_init_one(TOGGLE_MAC_KEY, toggle_mac_msg, MAC_FILE);
	toggle_init_one(TOGGLE_BACKUP_KEY, toggle_backup_msg, BACKUP_FILE);
    }
298
    toggle_init_one(TOGGLE_SMOOTH_KEY, toggle_smooth_msg, SMOOTHSCROLL);
299
300
301
#ifdef ENABLE_COLOR
    toggle_init_one(TOGGLE_SYNTAX_KEY, toggle_syntax_msg, COLOR_SYNTAX);
#endif
302
}
303
304
305
306
307
308
309
310
311
312
313
314
315

#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
316
#endif /* !NANO_SMALL */
317
318

/* Deallocate the given shortcut. */
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
319
void free_shortcutage(shortcut **shortcutage)
320
321
{
    assert(shortcutage != NULL);
Chris Allegretta's avatar
Chris Allegretta committed
322
323
324
    while (*shortcutage != NULL) {
	shortcut *ps = *shortcutage;
	*shortcutage = (*shortcutage)->next;
325
326
	free(ps);
    }
327
328
}

329
void shortcut_init(int unjustify)
Chris Allegretta's avatar
Chris Allegretta committed
330
{
331
#ifndef DISABLE_HELP
332
333
334
335
336
337
338
    const char *nano_help_msg = "", *nano_writeout_msg =
	"", *nano_exit_msg = "", *nano_goto_msg =
	"", *nano_justify_msg = "", *nano_replace_msg =
	"", *nano_insert_msg = "", *nano_whereis_msg =
	"", *nano_whereis_next_msg = "", *nano_prevpage_msg =
	"", *nano_nextpage_msg = "", *nano_cut_msg =
	"", *nano_uncut_msg = "", *nano_cursorpos_msg =
339
340
	"", *nano_spell_msg = "", *nano_prevline_msg =
	"", *nano_nextline_msg = "", *nano_forward_msg =
341
	"", *nano_back_msg = "", *nano_home_msg =
Chris Allegretta's avatar
Chris Allegretta committed
342
343
344
345
	"", *nano_end_msg = "", *nano_firstline_msg =
	"", *nano_lastline_msg = "", *nano_refresh_msg =
	"", *nano_mark_msg = "", *nano_delete_msg =
	"", *nano_backspace_msg = "", *nano_tab_msg =
346
347
348
349
350
351
352
353
354
355
	"", *nano_enter_msg = "", *nano_prevword_msg =
	"", *nano_nextword_msg = "", *nano_verbatim_msg =
	"", *nano_cancel_msg = "", *nano_unjustify_msg =
	"", *nano_append_msg = "", *nano_prepend_msg =
	"", *nano_tofiles_msg = "", *nano_gotodir_msg =
	"", *nano_case_msg = "", *nano_reverse_msg =
	"", *nano_execute_msg = "", *nano_dos_msg =
	"", *nano_mac_msg = "", *nano_backup_msg =
	"", *nano_editstr_msg = "", *nano_parabegin_msg =
	"", *nano_paraend_msg = "";
Chris Allegretta's avatar
Chris Allegretta committed
356

Chris Allegretta's avatar
Chris Allegretta committed
357
#ifdef ENABLE_MULTIBUFFER
358
    const char *nano_openprev_msg = "", *nano_opennext_msg =
359
	"", *nano_multibuffer_msg = "";
Chris Allegretta's avatar
Chris Allegretta committed
360
#endif
361
#ifdef HAVE_REGEX_H
362
    const char *nano_regexp_msg = "", *nano_bracket_msg = "";
363
#endif
364

Chris Allegretta's avatar
Chris Allegretta committed
365
366
    nano_help_msg = _("Invoke the help menu");
    nano_writeout_msg = _("Write the current file to disk");
367
#ifdef ENABLE_MULTIBUFFER
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
368
    nano_exit_msg = _("Close current file buffer/Exit from nano");
369
#else
Chris Allegretta's avatar
Chris Allegretta committed
370
    nano_exit_msg = _("Exit from nano");
371
#endif
372
    nano_goto_msg = _("Go to a specific line number");
Chris Allegretta's avatar
Chris Allegretta committed
373
    nano_justify_msg = _("Justify the current paragraph");
374
    nano_unjustify_msg = _("Unjustify after a justify");
Chris Allegretta's avatar
Chris Allegretta committed
375
376
377
    nano_replace_msg = _("Replace text within the editor");
    nano_insert_msg = _("Insert another file into the current one");
    nano_whereis_msg = _("Search for text within the editor");
378
    nano_whereis_next_msg = _("Repeat last search");
Chris Allegretta's avatar
Chris Allegretta committed
379
380
381
382
    nano_prevpage_msg = _("Move to the previous screen");
    nano_nextpage_msg = _("Move to the next screen");
    nano_cut_msg = _("Cut the current line and store it in the cutbuffer");
    nano_uncut_msg = _("Uncut from the cutbuffer into the current line");
383
    nano_cursorpos_msg = _("Show the position of the cursor");
384
    nano_spell_msg = _("Invoke the spell checker, if available");
385
386
    nano_prevline_msg = _("Move to the previous line");
    nano_nextline_msg = _("Move to the next line");
Chris Allegretta's avatar
Chris Allegretta committed
387
388
389
390
391
392
393
394
395
396
397
398
399
    nano_forward_msg = _("Move forward one character");
    nano_back_msg = _("Move back one character");
    nano_home_msg = _("Move to the beginning of the current line");
    nano_end_msg = _("Move to the end of the current line");
    nano_firstline_msg = _("Go to the first line of the file");
    nano_lastline_msg = _("Go to the last line of the file");
    nano_refresh_msg = _("Refresh (redraw) the current screen");
    nano_mark_msg = _("Mark text at the current cursor location");
    nano_delete_msg = _("Delete the character under the cursor");
    nano_backspace_msg =
	_("Delete the character to the left of the cursor");
    nano_tab_msg = _("Insert a tab character");
    nano_enter_msg = _("Insert a carriage return at the cursor position");
400
401
402
403
    nano_prevword_msg = _("Move backward one word");
    nano_nextword_msg = _("Move forward one word");
    nano_verbatim_msg = _("Insert character(s) verbatim");
    nano_enter_msg = _("Insert a carriage return at the cursor position");
Chris Allegretta's avatar
Chris Allegretta committed
404
405
    nano_case_msg =
	_("Make the current search or replace case (in)sensitive");
Chris Allegretta's avatar
Chris Allegretta committed
406
    nano_tofiles_msg = _("Go to file browser");
407
    nano_execute_msg = _("Execute external command");
408
    nano_gotodir_msg = _("Go to directory");
Chris Allegretta's avatar
Chris Allegretta committed
409
    nano_cancel_msg = _("Cancel the current function");
410
    nano_append_msg = _("Append to the current file");
411
    nano_prepend_msg = _("Prepend to the current file");
412
    nano_reverse_msg = _("Search backwards");
413
414
    nano_dos_msg = _("Write file out in DOS format");
    nano_mac_msg = _("Write file out in Mac format");
415
    nano_backup_msg = _("Back up original file when saving");
416
    nano_editstr_msg = _("Edit the previous search/replace strings");
417
418
    nano_parabegin_msg = _("Go to the beginning of the current paragraph");
    nano_paraend_msg = _("Go to the end of the current paragraph");
419
#ifdef HAVE_REGEX_H
420
    nano_regexp_msg = _("Use regular expressions");
421
    nano_bracket_msg = _("Find other bracket");
422
#endif
423
#ifdef ENABLE_MULTIBUFFER
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
424
425
    nano_openprev_msg = _("Switch to previous file buffer");
    nano_opennext_msg = _("Switch to next file buffer");
426
    nano_multibuffer_msg = _("Toggle insert into new file buffer");
Chris Allegretta's avatar
Chris Allegretta committed
427
#endif
428
#endif /* !DISABLE_HELP */
Chris Allegretta's avatar
Chris Allegretta committed
429

430
    free_shortcutage(&main_list);
431

432
433
434
/* 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 fourth one should not be there. */
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
435
#ifndef DISABLE_HELP
436
#  define IFHELP(help, nextvar) help, nextvar
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
437
438
#else
#  define IFHELP(help, nextvar) nextvar
439
#endif
440

441
    /* Translators: try to keep this string under 10 characters long */
442
    sc_init_one(&main_list, NANO_HELP_KEY, _("Get Help"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
443
		IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
444
445
446
447
448
449
450
		NANO_NO_KEY, VIEW,
#ifndef DISABLE_HELP
		do_help
#else
		nano_disabled_msg
#endif
		);
Chris Allegretta's avatar
Chris Allegretta committed
451

452
#ifdef ENABLE_MULTIBUFFER
453
    if (open_files != NULL && (open_files->prev != NULL || open_files->next != NULL))
454
    /* Translators: try to keep this string under 10 characters long */
455
	sc_init_one(&main_list, NANO_EXIT_KEY, _("Close"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
456
457
		IFHELP(nano_exit_msg, NANO_NO_KEY), NANO_EXIT_FKEY,
		NANO_NO_KEY, VIEW, do_exit);
458
459
    else
#endif
460

461
    /* Translators: try to keep this string under 10 characters long */
462
	sc_init_one(&main_list, NANO_EXIT_KEY, _("Exit"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
463
464
		IFHELP(nano_exit_msg, NANO_NO_KEY), NANO_EXIT_FKEY,
		NANO_NO_KEY, VIEW, do_exit);
Chris Allegretta's avatar
Chris Allegretta committed
465

466
    /* Translators: try to keep this string under 10 characters long */
467
    sc_init_one(&main_list, NANO_WRITEOUT_KEY, _("WriteOut"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
468
469
		IFHELP(nano_writeout_msg, NANO_NO_KEY), NANO_WRITEOUT_FKEY,
		NANO_NO_KEY, NOVIEW, do_writeout_void);
Chris Allegretta's avatar
Chris Allegretta committed
470

471
    /* Translators: try to keep this string under 10 characters long */
472
    sc_init_one(&main_list, NANO_JUSTIFY_KEY, _("Justify"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
473
		IFHELP(nano_justify_msg, NANO_NO_KEY),
474
475
476
477
478
479
480
		NANO_JUSTIFY_FKEY, NANO_NO_KEY, NOVIEW,
#ifndef NANO_SMALL
		do_justify
#else
		nano_disabled_msg
#endif
		);
481

482
    /* this is so we can view multiple files */
483
    /* Translators: try to keep this string under 10 characters long */
484
    sc_init_one(&main_list, NANO_INSERTFILE_KEY, _("Read File"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
485
486
		IFHELP(nano_insert_msg, NANO_NO_KEY), NANO_INSERTFILE_FKEY,
		NANO_NO_KEY,
487
#ifdef ENABLE_MULTIBUFFER
488
		VIEW
489
#else
490
		NOVIEW
491
#endif
492
		, !ISSET(RESTRICTED) ? do_insertfile_void : nano_disabled_msg);
Chris Allegretta's avatar
Chris Allegretta committed
493

494
    /* Translators: try to keep this string under 10 characters long */
495
    sc_init_one(&main_list, NANO_WHEREIS_KEY, _("Where Is"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
496
497
		IFHELP(nano_whereis_msg, NANO_NO_KEY), NANO_WHEREIS_FKEY,
		NANO_NO_KEY, VIEW, do_search);
Chris Allegretta's avatar
Chris Allegretta committed
498

499
    /* Translators: try to keep this string under 10 characters long */
500
    sc_init_one(&main_list, NANO_PREVPAGE_KEY, _("Prev Page"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
501
502
		IFHELP(nano_prevpage_msg, NANO_NO_KEY), NANO_PREVPAGE_FKEY,
		NANO_NO_KEY, VIEW, do_page_up);
Chris Allegretta's avatar
Chris Allegretta committed
503

504
    /* Translators: try to keep this string under 10 characters long */
505
    sc_init_one(&main_list, NANO_NEXTPAGE_KEY, _("Next Page"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
506
507
		IFHELP(nano_nextpage_msg, NANO_NO_KEY), NANO_NEXTPAGE_FKEY,
		NANO_NO_KEY, VIEW, do_page_down);
Chris Allegretta's avatar
Chris Allegretta committed
508

509
    /* Translators: try to keep this string under 10 characters long */
510
    sc_init_one(&main_list, NANO_CUT_KEY, _("Cut Text"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
511
512
		IFHELP(nano_cut_msg, NANO_NO_KEY), NANO_CUT_FKEY,
		NANO_NO_KEY, NOVIEW, do_cut_text);
Chris Allegretta's avatar
Chris Allegretta committed
513

514
    if (unjustify)
515
    /* Translators: try to keep this string under 10 characters long */
516
	sc_init_one(&main_list, NANO_UNJUSTIFY_KEY, _("UnJustify"),
517
		IFHELP(nano_unjustify_msg, NANO_NO_KEY), NANO_UNJUSTIFY_FKEY,
518
		NANO_NO_KEY, NOVIEW, 0);
519
    else
520
    /* Translators: try to keep this string under 10 characters long */
521
	sc_init_one(&main_list, NANO_UNCUT_KEY, _("UnCut Txt"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
522
523
		IFHELP(nano_uncut_msg, NANO_NO_KEY), NANO_UNCUT_FKEY,
		NANO_NO_KEY, NOVIEW, do_uncut_text);
Chris Allegretta's avatar
Chris Allegretta committed
524

525
    /* Translators: try to keep this string under 10 characters long */
526
    sc_init_one(&main_list, NANO_CURSORPOS_KEY, _("Cur Pos"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
527
528
		IFHELP(nano_cursorpos_msg, NANO_NO_KEY), NANO_CURSORPOS_FKEY,
		NANO_NO_KEY, VIEW, do_cursorpos_void);
Chris Allegretta's avatar
Chris Allegretta committed
529

530
    /* Translators: try to keep this string under 10 characters long */
531
    sc_init_one(&main_list, NANO_SPELL_KEY, _("To Spell"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
532
		IFHELP(nano_spell_msg, NANO_NO_KEY), NANO_SPELL_FKEY,
533
534
535
536
537
		NANO_NO_KEY, NOVIEW,
#ifndef DISABLE_SPELLER
		!ISSET(RESTRICTED) ? do_spell :
#endif
		nano_disabled_msg);
538
539

    sc_init_one(&main_list, NANO_GOTO_KEY, _("Go To Line"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
540
541
		IFHELP(nano_goto_msg, NANO_ALT_GOTO_KEY), NANO_GOTO_FKEY,
		NANO_NO_KEY, VIEW, do_gotoline_void);
542
543

    sc_init_one(&main_list, NANO_REPLACE_KEY, _("Replace"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
544
545
		IFHELP(nano_replace_msg, NANO_ALT_REPLACE_KEY), NANO_REPLACE_FKEY,
		NANO_NO_KEY, NOVIEW, do_replace);
Chris Allegretta's avatar
Chris Allegretta committed
546

547
548
    sc_init_one(&main_list, NANO_PREVLINE_KEY, _("Prev Line"),
		IFHELP(nano_prevline_msg, NANO_NO_KEY), NANO_NO_KEY,
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
549
		NANO_NO_KEY, VIEW, do_up);
Chris Allegretta's avatar
Chris Allegretta committed
550

551
552
    sc_init_one(&main_list, NANO_NEXTLINE_KEY, _("Next Line"),
		IFHELP(nano_nextline_msg, NANO_NO_KEY), NANO_NO_KEY,
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
553
		NANO_NO_KEY, VIEW, do_down);
Chris Allegretta's avatar
Chris Allegretta committed
554

555
    sc_init_one(&main_list, NANO_FORWARD_KEY, _("Forward"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
556
557
		IFHELP(nano_forward_msg, NANO_NO_KEY), NANO_NO_KEY,
		NANO_NO_KEY, VIEW, do_right);
Chris Allegretta's avatar
Chris Allegretta committed
558

559
    sc_init_one(&main_list, NANO_BACK_KEY, _("Back"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
560
561
		IFHELP(nano_back_msg, NANO_NO_KEY), NANO_NO_KEY,
		NANO_NO_KEY, VIEW, do_left);
Chris Allegretta's avatar
Chris Allegretta committed
562

563
    sc_init_one(&main_list, NANO_HOME_KEY, _("Home"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
564
565
		IFHELP(nano_home_msg, NANO_NO_KEY), NANO_NO_KEY,
		NANO_NO_KEY, VIEW, do_home);
Chris Allegretta's avatar
Chris Allegretta committed
566

567
    sc_init_one(&main_list, NANO_END_KEY, _("End"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
568
569
		IFHELP(nano_end_msg, NANO_NO_KEY), NANO_NO_KEY,
		NANO_NO_KEY, VIEW, do_end);
Chris Allegretta's avatar
Chris Allegretta committed
570

571
    sc_init_one(&main_list, NANO_REFRESH_KEY, _("Refresh"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
572
573
		IFHELP(nano_refresh_msg, NANO_NO_KEY), NANO_NO_KEY,
		NANO_NO_KEY, VIEW, total_refresh);
Chris Allegretta's avatar
Chris Allegretta committed
574

575
    sc_init_one(&main_list, NANO_MARK_KEY, _("Mark Text"),
576
		IFHELP(nano_mark_msg, NANO_ALT_MARK_KEY),
577
578
579
580
581
582
583
		NANO_NO_KEY, NANO_NO_KEY, NOVIEW,
#ifndef NANO_SMALL
		do_mark
#else
		nano_disabled_msg
#endif
		);
Chris Allegretta's avatar
Chris Allegretta committed
584

585
    sc_init_one(&main_list, NANO_DELETE_KEY, _("Delete"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
586
587
		IFHELP(nano_delete_msg, NANO_NO_KEY), NANO_NO_KEY,
		NANO_NO_KEY, NOVIEW, do_delete);
Chris Allegretta's avatar
Chris Allegretta committed
588

589
    sc_init_one(&main_list, NANO_BACKSPACE_KEY, _("Backspace"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
590
591
		IFHELP(nano_backspace_msg, NANO_NO_KEY), NANO_NO_KEY,
		NANO_NO_KEY, NOVIEW, do_backspace);
Chris Allegretta's avatar
Chris Allegretta committed
592

593
    sc_init_one(&main_list, NANO_TAB_KEY, _("Tab"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
594
595
		IFHELP(nano_tab_msg, NANO_NO_KEY), NANO_NO_KEY,
		NANO_NO_KEY, NOVIEW, do_tab);
Chris Allegretta's avatar
Chris Allegretta committed
596

597
    sc_init_one(&main_list, NANO_ENTER_KEY, _("Enter"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
598
599
		IFHELP(nano_enter_msg, NANO_NO_KEY), NANO_NO_KEY,
		NANO_NO_KEY, NOVIEW, do_enter);
600

601
602
#ifndef NANO_SMALL
    sc_init_one(&main_list, NANO_NEXTWORD_KEY, _("Next Word"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
603
604
		IFHELP(nano_nextword_msg, NANO_NO_KEY), NANO_NO_KEY,
		NANO_NO_KEY, VIEW, do_next_word);
605

David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
606
607
608
    sc_init_one(&main_list, NANO_NO_KEY, _("Prev Word"),
		IFHELP(nano_prevword_msg, NANO_PREVWORD_KEY), NANO_NO_KEY,
		NANO_NO_KEY, VIEW, do_prev_word);
609
#endif
610

David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
611
612
    sc_init_one(&main_list, NANO_NO_KEY, _("Verbatim Input"),
		IFHELP(nano_verbatim_msg, NANO_VERBATIM_KEY), NANO_NO_KEY,
613
		NANO_NO_KEY, NOVIEW, do_verbatim_input);
614

615
#ifdef ENABLE_MULTIBUFFER
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
616
617
618
    sc_init_one(&main_list, NANO_NO_KEY, _("Previous File"),
		IFHELP(nano_openprev_msg, NANO_OPENPREV_KEY), NANO_NO_KEY,
		NANO_OPENPREV_ALTKEY, VIEW, open_prevfile_void);
619

David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
620
621
622
    sc_init_one(&main_list, NANO_NO_KEY, _("Next File"),
		IFHELP(nano_opennext_msg, NANO_OPENNEXT_KEY), NANO_NO_KEY,
		NANO_OPENNEXT_ALTKEY, VIEW, open_nextfile_void);
623
#endif
624

625
626
#ifndef NANO_SMALL
#ifdef HAVE_REGEX_H
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
627
628
629
    sc_init_one(&main_list, NANO_NO_KEY, _("Find Other Bracket"),
		IFHELP(nano_bracket_msg, NANO_BRACKET_KEY), NANO_NO_KEY,
		NANO_NO_KEY, VIEW, do_find_bracket);
630
631
#endif

David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
632
    sc_init_one(&main_list, NANO_NO_KEY, _("Where Is Next"),
633
		IFHELP(nano_whereis_next_msg, NANO_WHEREIS_NEXT_KEY),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
634
		NANO_NO_KEY, NANO_NO_KEY, VIEW, do_research);
635
#endif
636

637
    free_shortcutage(&whereis_list);
638

639
    sc_init_one(&whereis_list, NANO_HELP_KEY, _("Get Help"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
640
		IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
641
642
643
644
645
646
647
		NANO_NO_KEY, VIEW,
#ifndef DISABLE_HELP
		do_help
#else
		nano_disabled_msg
#endif
		);
648

649
    /* Translators: try to keep this string under 10 characters long */
650
    sc_init_one(&whereis_list, NANO_CANCEL_KEY, _("Cancel"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
651
652
		IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY,
		NANO_NO_KEY, VIEW, 0);
653

654
    /* Translators: try to keep this string under 10 characters long */
655
    sc_init_one(&whereis_list, NANO_FIRSTLINE_KEY, _("First Line"),
656
		IFHELP(nano_firstline_msg, NANO_NO_KEY), NANO_FIRSTLINE_FKEY,
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
657
		NANO_NO_KEY, VIEW, do_first_line);
Chris Allegretta's avatar
Chris Allegretta committed
658

659
    /* Translators: try to keep this string under 10 characters long */
660
    sc_init_one(&whereis_list, NANO_LASTLINE_KEY, _("Last Line"),
661
		IFHELP(nano_lastline_msg, NANO_NO_KEY), NANO_LASTLINE_FKEY,
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
662
		NANO_NO_KEY, VIEW, do_last_line);
Chris Allegretta's avatar
Chris Allegretta committed
663

664
    /* Translators: try to keep this string under 10 characters long */
665
    sc_init_one(&whereis_list, NANO_OTHERSEARCH_KEY, _("Replace"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
666
667
		IFHELP(nano_replace_msg, NANO_NO_KEY), NANO_REPLACE_FKEY,
		NANO_NO_KEY, VIEW, do_replace);
Chris Allegretta's avatar
Chris Allegretta committed
668

669
    /* Translators: try to keep this string under 10 characters long */
Chris Allegretta's avatar
Chris Allegretta committed
670
    sc_init_one(&whereis_list, NANO_FROMSEARCHTOGOTO_KEY, _("Go To Line"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
671
672
		IFHELP(nano_goto_msg, NANO_NO_KEY), NANO_GOTO_FKEY,
		NANO_NO_KEY, VIEW, do_gotoline_void);
673

674
675
676
#ifndef DISABLE_JUSTIFY
    /* Translators: try to keep this string under 10 characters long */
    sc_init_one(&whereis_list, NANO_PARABEGIN_KEY, _("Beg of Par"),
677
		IFHELP(nano_parabegin_msg, NANO_NO_KEY), NANO_NO_KEY,
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
678
		NANO_NO_KEY, VIEW, do_para_begin);
679
680
681

    /* Translators: try to keep this string under 10 characters long */
    sc_init_one(&whereis_list, NANO_PARAEND_KEY, _("End of Par"),
682
		IFHELP(nano_paraend_msg, NANO_NO_KEY), NANO_NO_KEY,
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
683
		NANO_NO_KEY, VIEW, do_para_end);
684
685
#endif

686
#ifndef NANO_SMALL
687
    /* Translators: try to keep this string under 10 characters long */
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
688
689
690
    sc_init_one(&whereis_list, NANO_NO_KEY, _("Case Sens"),
		IFHELP(nano_case_msg, TOGGLE_CASE_KEY), NANO_NO_KEY,
		NANO_NO_KEY, VIEW, 0);
691

692
    /* Translators: try to keep this string under 10 characters long */
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
693
694
695
    sc_init_one(&whereis_list, NANO_NO_KEY, _("Direction"),
		IFHELP(nano_reverse_msg, TOGGLE_BACKWARDS_KEY), NANO_NO_KEY,
		NANO_NO_KEY, VIEW, 0);
Chris Allegretta's avatar
Chris Allegretta committed
696

697
#ifdef HAVE_REGEX_H
698
    /* Translators: try to keep this string under 10 characters long */
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
699
700
701
    sc_init_one(&whereis_list, NANO_NO_KEY, _("Regexp"),
		IFHELP(nano_regexp_msg, TOGGLE_REGEXP_KEY), NANO_NO_KEY,
		NANO_NO_KEY, VIEW, 0);
702
#endif
703
704

#ifndef NANO_SMALL
705
    /* Translators: try to keep this string under 10 characters long */
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
706
707
708
    sc_init_one(&whereis_list, NANO_HISTORY_KEY, _("History"),
		IFHELP(nano_editstr_msg, NANO_NO_KEY), NANO_NO_KEY,
		NANO_NO_KEY, VIEW, 0);
709
710
#endif

711
#endif /* !NANO_SMALL */
712

713
    free_shortcutage(&replace_list);
714

715
    sc_init_one(&replace_list, NANO_HELP_KEY, _("Get Help"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
716
		IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
717
718
719
720
721
722
723
		NANO_NO_KEY, VIEW,
#ifndef DISABLE_HELP
		do_help
#else
		nano_disabled_msg
#endif
		);
724

725
    sc_init_one(&replace_list, NANO_CANCEL_KEY, _("Cancel"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
726
727
		IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY,
		NANO_NO_KEY, VIEW, 0);
Chris Allegretta's avatar
Chris Allegretta committed
728

729
    sc_init_one(&replace_list, NANO_FIRSTLINE_KEY, _("First Line"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
730
731
		IFHELP(nano_firstline_msg, NANO_NO_KEY), NANO_NO_KEY,
		NANO_NO_KEY, VIEW, do_first_line);
Chris Allegretta's avatar
Chris Allegretta committed
732

733
    sc_init_one(&replace_list, NANO_LASTLINE_KEY, _("Last Line"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
734
735
		IFHELP(nano_lastline_msg, NANO_NO_KEY), NANO_NO_KEY,
		NANO_NO_KEY, VIEW, do_last_line);
Chris Allegretta's avatar
Chris Allegretta committed
736

737
    /* Translators: try to keep this string under 12 characters long */
738
    sc_init_one(&replace_list, NANO_OTHERSEARCH_KEY, _("No Replace"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
739
740
		IFHELP(nano_whereis_msg, NANO_NO_KEY), NANO_REPLACE_FKEY,
		NANO_NO_KEY, VIEW, do_search);
Chris Allegretta's avatar
Chris Allegretta committed
741

742
    sc_init_one(&replace_list, NANO_FROMSEARCHTOGOTO_KEY, _("Go To Line"), 
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
743
744
		IFHELP(nano_goto_msg, NANO_NO_KEY), NANO_GOTO_FKEY,
		NANO_NO_KEY, VIEW, do_gotoline_void);
745

746
#ifndef NANO_SMALL
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
747
748
749
    sc_init_one(&replace_list, NANO_NO_KEY, _("Case Sens"),
		IFHELP(nano_case_msg, TOGGLE_CASE_KEY), NANO_NO_KEY,
		NANO_NO_KEY, VIEW, 0);
750

David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
751
752
753
    sc_init_one(&replace_list, NANO_NO_KEY, _("Direction"),
		IFHELP(nano_reverse_msg, TOGGLE_BACKWARDS_KEY), NANO_NO_KEY,
		NANO_NO_KEY, VIEW, 0);
754

755
#ifdef HAVE_REGEX_H
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
756
757
758
    sc_init_one(&replace_list, NANO_NO_KEY, _("Regexp"),
		IFHELP(nano_regexp_msg, TOGGLE_REGEXP_KEY), NANO_NO_KEY,
		NANO_NO_KEY, VIEW, 0);
759
#endif
760

David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
761
762
    sc_init_one(&replace_list, NANO_HISTORY_KEY, _("History"),
		IFHELP(nano_editstr_msg, NANO_NO_KEY), NANO_NO_KEY,
763
		NANO_NO_KEY, VIEW, 0);
764
#endif /* !NANO_SMALL */
765

766
    free_shortcutage(&replace_list_2);
767

768
    sc_init_one(&replace_list_2, NANO_HELP_KEY, _("Get Help"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
769
		IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
770
771
772
773
774
775
776
		NANO_NO_KEY, VIEW,
#ifndef DISABLE_HELP
		do_help
#else
		nano_disabled_msg
#endif
		);
777

778
    sc_init_one(&replace_list_2, NANO_CANCEL_KEY, _("Cancel"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
779
780
		IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY,
		NANO_NO_KEY, VIEW, 0);
781

782
    sc_init_one(&replace_list_2, NANO_FIRSTLINE_KEY, _("First Line"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
783
784
		IFHELP(nano_firstline_msg, NANO_NO_KEY), NANO_NO_KEY,
		NANO_NO_KEY, VIEW, do_first_line);
785

786
    sc_init_one(&replace_list_2, NANO_LASTLINE_KEY, _("Last Line"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
787
788
		IFHELP(nano_lastline_msg, NANO_NO_KEY), NANO_NO_KEY,
		NANO_NO_KEY, VIEW, do_last_line);
789

790
#ifndef NANO_SMALL
791
    sc_init_one(&replace_list_2, NANO_HISTORY_KEY, _("History"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
792
		IFHELP(nano_editstr_msg, NANO_NO_KEY), NANO_NO_KEY,
793
		NANO_NO_KEY, VIEW, 0);
794
795
#endif

796
    free_shortcutage(&goto_list);
Chris Allegretta's avatar
Chris Allegretta committed
797

798
    sc_init_one(&goto_list, NANO_HELP_KEY, _("Get Help"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
799
		IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
800
801
802
803
804
805
806
		NANO_NO_KEY, VIEW,
#ifndef DISABLE_HELP
		do_help
#else
		nano_disabled_msg
#endif
		);
807

808
    sc_init_one(&goto_list, NANO_CANCEL_KEY, _("Cancel"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
809
810
		IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY,
		NANO_NO_KEY, VIEW, 0);
Chris Allegretta's avatar
Chris Allegretta committed
811

812
    sc_init_one(&goto_list, NANO_FIRSTLINE_KEY, _("First Line"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
813
814
		IFHELP(nano_firstline_msg, NANO_NO_KEY), NANO_NO_KEY,
		NANO_NO_KEY, VIEW, do_first_line);
Chris Allegretta's avatar
Chris Allegretta committed
815

816
    sc_init_one(&goto_list, NANO_LASTLINE_KEY, _("Last Line"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
817
818
		IFHELP(nano_lastline_msg, NANO_NO_KEY), NANO_NO_KEY,
		NANO_NO_KEY, VIEW, do_last_line);
Chris Allegretta's avatar
Chris Allegretta committed
819

Chris Allegretta's avatar
Chris Allegretta committed
820
#ifndef DISABLE_HELP
821
    free_shortcutage(&help_list);
Chris Allegretta's avatar
Chris Allegretta committed
822

823
    sc_init_one(&help_list, NANO_PREVPAGE_KEY, _("Prev Page"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
824
825
		IFHELP(nano_prevpage_msg, NANO_NO_KEY), NANO_PREVPAGE_FKEY,
		NANO_NO_KEY, VIEW, do_page_up);
Chris Allegretta's avatar
Chris Allegretta committed
826

827
    sc_init_one(&help_list, NANO_NEXTPAGE_KEY, _("Next Page"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
828
829
		IFHELP(nano_nextpage_msg, NANO_NO_KEY), NANO_NEXTPAGE_FKEY,
		NANO_NO_KEY, VIEW, do_page_down);
Chris Allegretta's avatar
Chris Allegretta committed
830

831
    sc_init_one(&help_list, NANO_EXIT_KEY, _("Exit"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
832
833
		IFHELP(nano_exit_msg, NANO_NO_KEY), NANO_EXIT_FKEY,
		NANO_NO_KEY, VIEW, do_exit);
Chris Allegretta's avatar
Chris Allegretta committed
834
#endif
Chris Allegretta's avatar
Chris Allegretta committed
835

836
    free_shortcutage(&writefile_list);
Chris Allegretta's avatar
Chris Allegretta committed
837

838
    sc_init_one(&writefile_list, NANO_HELP_KEY, _("Get Help"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
839
		IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
840
841
842
843
844
845
846
		NANO_NO_KEY, VIEW,
#ifndef DISABLE_HELP
		do_help
#else
		nano_disabled_msg
#endif
		);
847

848
#ifndef DISABLE_BROWSER
849
    /* Translators: try to keep this string under 16 characters long */
850
851
    if (!ISSET(RESTRICTED))
	sc_init_one(&writefile_list, NANO_TOFILES_KEY, _("To Files"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
852
853
		IFHELP(nano_tofiles_msg, NANO_NO_KEY), NANO_NO_KEY,
		NANO_NO_KEY, NOVIEW, 0);
Chris Allegretta's avatar
Chris Allegretta committed
854
#endif
Chris Allegretta's avatar
Chris Allegretta committed
855

856
#ifndef NANO_SMALL
857
    /* Translators: try to keep this string under 16 characters long */
858
859
    if (!ISSET(RESTRICTED))
	sc_init_one(&writefile_list, NANO_NO_KEY, _("DOS Format"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
860
861
		IFHELP(nano_dos_msg, TOGGLE_DOS_KEY), NANO_NO_KEY,
		NANO_NO_KEY, NOVIEW, 0);
862

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

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

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

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

890
    sc_init_one(&writefile_list, NANO_CANCEL_KEY, _("Cancel"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
891
892
		IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY,
		NANO_NO_KEY, VIEW, 0);
893

894
    free_shortcutage(&insertfile_list);
895

896
    sc_init_one(&insertfile_list, NANO_HELP_KEY, _("Get Help"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
897
		IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
898
899
900
901
902
903
904
		NANO_NO_KEY, VIEW,
#ifndef DISABLE_HELP
		do_help
#else
		nano_disabled_msg
#endif
		);
905

906
    sc_init_one(&insertfile_list, NANO_CANCEL_KEY, _("Cancel"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
907
908
		IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY,
		NANO_NO_KEY, VIEW, 0);
Chris Allegretta's avatar
Chris Allegretta committed
909

910
#ifndef DISABLE_BROWSER
911
912
    if (!ISSET(RESTRICTED))
	sc_init_one(&insertfile_list, NANO_TOFILES_KEY, _("To Files"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
913
914
		IFHELP(nano_tofiles_msg, NANO_NO_KEY), NANO_NO_KEY,
		NANO_NO_KEY, NOVIEW, 0);
915
#endif
916

917
#ifndef NANO_SMALL
918
    /* Translators: try to keep this string under 22 characters long */
919
920
    if (!ISSET(RESTRICTED))
	sc_init_one(&insertfile_list, NANO_EXTCMD_KEY, _("Execute Command"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
921
922
		IFHELP(nano_execute_msg, NANO_NO_KEY), NANO_NO_KEY,
		NANO_NO_KEY, NOVIEW, 0);
923

924
#ifdef ENABLE_MULTIBUFFER
925
    /* Translators: try to keep this string under 22 characters long */
926
927
    if (!ISSET(RESTRICTED))
	sc_init_one(&insertfile_list, NANO_NO_KEY, _("New Buffer"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
928
929
		IFHELP(nano_multibuffer_msg, TOGGLE_MULTIBUFFER_KEY), NANO_NO_KEY,
		NANO_NO_KEY, NOVIEW, 0);
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
    sc_init_one(&spell_list, NANO_HELP_KEY, _("Get Help"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
937
		IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
938
939
940
941
942
943
944
		NANO_NO_KEY, VIEW,
#ifndef DISABLE_HELP
		do_help
#else
		nano_disabled_msg
#endif
		);
945

946
    sc_init_one(&spell_list, NANO_CANCEL_KEY, _("Cancel"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
947
948
		IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY,
		NANO_NO_KEY, VIEW, 0);
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
    sc_init_one(&extcmd_list, NANO_HELP_KEY, _("Get Help"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
955
		IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
956
957
958
959
960
961
962
		NANO_NO_KEY, VIEW,
#ifndef DISABLE_HELP
		do_help
#else
		nano_disabled_msg
#endif
		);
963
964

    sc_init_one(&extcmd_list, NANO_CANCEL_KEY, _("Cancel"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
965
966
		IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY,
		NANO_NO_KEY, VIEW, 0);
967
#endif
968

969
#ifndef DISABLE_BROWSER
970
    free_shortcutage(&browser_list);
971

972
    sc_init_one(&browser_list, NANO_HELP_KEY, _("Get Help"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
973
		IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
974
975
976
977
978
979
980
		NANO_NO_KEY, VIEW,
#ifndef DISABLE_HELP
		do_help
#else
		nano_disabled_msg
#endif
		);
981

982
    sc_init_one(&browser_list, NANO_CANCEL_KEY, _("Cancel"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
983
984
		IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY,
		NANO_NO_KEY, VIEW, 0);
985

986
    sc_init_one(&browser_list, NANO_PREVPAGE_KEY, _("Prev Page"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
987
988
		IFHELP(nano_prevpage_msg, NANO_NO_KEY), NANO_PREVPAGE_FKEY,
		NANO_NO_KEY, VIEW, 0);
Chris Allegretta's avatar
Chris Allegretta committed
989

990
    sc_init_one(&browser_list, NANO_NEXTPAGE_KEY, _("Next Page"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
991
992
		IFHELP(nano_nextpage_msg, NANO_NO_KEY), NANO_NEXTPAGE_FKEY,
		NANO_NO_KEY, VIEW, 0);
Chris Allegretta's avatar
Chris Allegretta committed
993

994
    /* Translators: try to keep this string under 22 characters long */
995
    sc_init_one(&browser_list, NANO_GOTO_KEY, _("Go To Dir"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
996
997
		IFHELP(nano_gotodir_msg, NANO_ALT_GOTO_KEY), NANO_GOTO_FKEY,
		NANO_NO_KEY, VIEW, 0);
Rocco Corsi's avatar
   
Rocco Corsi committed
998

999
    free_shortcutage(&gotodir_list);
1000

1001
    sc_init_one(&gotodir_list, NANO_HELP_KEY, _("Get Help"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
1002
		IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
1003
1004
1005
1006
1007
1008
1009
		NANO_NO_KEY, VIEW,
#ifndef DISABLE_HELP
		do_help
#else
		nano_disabled_msg
#endif
		);
Chris Allegretta's avatar
Chris Allegretta committed
1010

1011
    sc_init_one(&gotodir_list, NANO_CANCEL_KEY, _("Cancel"),
David Lawrence Ramsey's avatar
   
David Lawrence Ramsey committed
1012
1013
		IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY,
		NANO_NO_KEY, VIEW, 0);
Chris Allegretta's avatar
Chris Allegretta committed
1014
1015
#endif

1016
#if !defined(DISABLE_BROWSER) || !defined(DISABLE_HELP) || !defined(DISABLE_MOUSE)
1017
1018
    currshortcut = main_list;
#endif
1019
#ifndef NANO_SMALL
1020
    toggle_init();
1021
#endif
1022
}
1023

1024
1025
1026
/* 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
1027
 * function unless debugging is turned on. */
1028
#ifdef DEBUG
1029
/* added by SPK for memory cleanup, gracefully return our malloc()s */
Chris Allegretta's avatar
Chris Allegretta committed
1030
void thanks_for_all_the_fish(void)
1031
{
Chris Allegretta's avatar
Chris Allegretta committed
1032
1033
1034
1035
#ifndef DISABLE_JUSTIFY
    if (quotestr != NULL)
	free(quotestr);
#endif
1036
1037
1038
1039
#ifndef NANO_SMALL
    if (backup_dir != NULL)
        free(backup_dir);
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1040
#ifndef DISABLE_OPERATINGDIR
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
    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
1056
#ifndef DISABLE_HELP
1057
1058
    if (help_text != NULL)
	free(help_text);
1059
#endif
1060
1061
1062
1063
1064
    if (filename != NULL)
	free(filename);
    if (answer != NULL)
	free(answer);
    if (cutbuffer != NULL)
Chris Allegretta's avatar
Chris Allegretta committed
1065
	free_filestruct(cutbuffer);
1066
1067
1068
1069
1070

    free_shortcutage(&main_list);
    free_shortcutage(&whereis_list);
    free_shortcutage(&replace_list);
    free_shortcutage(&replace_list_2);
Chris Allegretta's avatar
Chris Allegretta committed
1071
    free_shortcutage(&goto_list);
1072
1073
    free_shortcutage(&writefile_list);
    free_shortcutage(&insertfile_list);
Chris Allegretta's avatar
Chris Allegretta committed
1074
#ifndef DISABLE_HELP
Chris Allegretta's avatar
Chris Allegretta committed
1075
    free_shortcutage(&help_list);
Chris Allegretta's avatar
Chris Allegretta committed
1076
1077
#endif
#ifndef DISABLE_SPELLER
1078
    free_shortcutage(&spell_list);
Chris Allegretta's avatar
Chris Allegretta committed
1079
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1080
1081
1082
#ifndef NANO_SMALL
    free_shortcutage(&extcmd_list);
#endif
1083
1084
#ifndef DISABLE_BROWSER
    free_shortcutage(&browser_list);
Chris Allegretta's avatar
Chris Allegretta committed
1085
    free_shortcutage(&gotodir_list);
1086
1087
1088
1089
1090
1091
1092
#endif

#ifndef NANO_SMALL
    free_toggles();
#endif

#ifdef ENABLE_MULTIBUFFER
1093
    if (open_files != NULL) {
1094
	/* We free the memory associated with each open file. */
1095
1096
	while (open_files->prev != NULL)
	    open_files = open_files->prev;
Chris Allegretta's avatar
Chris Allegretta committed
1097
	free_openfilestruct(open_files);
1098
    }
1099
#else
1100
    free_filestruct(fileage);
1101
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112

#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
1113
	    regfree(&bob->val);
Chris Allegretta's avatar
Chris Allegretta committed
1114
1115
1116
1117
1118
1119
	    free(bob);
	}
	while (syntaxes->color != NULL) {
	    colortype *bob = syntaxes->color;

	    syntaxes->color = bob->next;
Chris Allegretta's avatar
Chris Allegretta committed
1120
1121
	    regfree(&bob->start);
	    if (bob->end != NULL)
1122
1123
		regfree(bob->end);
	    free(bob->end);
Chris Allegretta's avatar
Chris Allegretta committed
1124
1125
1126
1127
1128
1129
	    free(bob);
	}
	syntaxes = syntaxes->next;
	free(bill);
    }
#endif /* ENABLE_COLOR */
1130
1131
1132
1133
1134
#ifndef NANO_SMALL
    /* free history lists */
    free_history(&search_history);
    free_history(&replace_history);
#endif
1135
}
1136
#endif /* DEBUG */