global.c 53.9 KB
Newer Older
1
/* $Id$ */
Chris Allegretta's avatar
Chris Allegretta committed
2
3
4
/**************************************************************************
 *   global.c                                                             *
 *                                                                        *
5
 *   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,  *
6
 *   2008, 2009, 2010, 2011, 2013, 2014 Free Software Foundation, Inc.    *
Chris Allegretta's avatar
Chris Allegretta committed
7
8
 *   This program is free software; you can redistribute it and/or modify *
 *   it under the terms of the GNU General Public License as published by *
9
 *   the Free Software Foundation; either version 3, or (at your option)  *
Chris Allegretta's avatar
Chris Allegretta committed
10
11
 *   any later version.                                                   *
 *                                                                        *
12
13
14
15
 *   This program is distributed in the hope that it will be useful, but  *
 *   WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    *
 *   General Public License for more details.                             *
Chris Allegretta's avatar
Chris Allegretta committed
16
17
18
 *                                                                        *
 *   You should have received a copy of the GNU General Public License    *
 *   along with this program; if not, write to the Free Software          *
19
20
 *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA            *
 *   02110-1301, USA.                                                     *
Chris Allegretta's avatar
Chris Allegretta committed
21
22
23
 *                                                                        *
 **************************************************************************/

24
25
#include "proto.h"

26
#include <ctype.h>
27
#include <string.h>
28
29
#include <strings.h>
#include "assert.h"
Chris Allegretta's avatar
Chris Allegretta committed
30

31
32
/* Global variables. */
#ifndef NANO_TINY
33
sigjmp_buf jump_buf;
34
	/* Used to return to either main() or the unjustify routine in
35
	 * do_justify() after a SIGWINCH. */
36
37
38
bool jump_buf_main = FALSE;
	/* Have we set jump_buf so that we return to main() after a
	 * SIGWINCH? */
39
40
#endif

41
42
43
44
45
bool meta_key;
	/* Whether the current keystroke is a Meta key. */
bool func_key;
	/* Whether the current keystroke is an extended keypad value. */

46
#ifndef DISABLE_WRAPJUSTIFY
47
48
ssize_t fill = 0;
	/* The column where we will wrap lines. */
49
ssize_t wrap_at = -CHARS_FROM_EOL;
50
51
52
53
54
55
56
57
58
59
	/* The position where we will wrap lines.  fill is equal to this
	 * if it's greater than zero, and equal to (COLS + this) if it
	 * isn't. */
#endif

char *last_search = NULL;
	/* The last string we searched for. */
char *last_replace = NULL;
	/* The last replacement string we searched for. */

60
unsigned flags[4] = {0, 0, 0, 0};
61
62
63
64
65
66
	/* Our flag containing the states of all global options. */
WINDOW *topwin;
	/* The top portion of the window, where we display the version
	 * number of nano, the name of the current file, and whether the
	 * current file has been modified. */
WINDOW *edit;
67
	/* The middle portion of the window, i.e. the edit window, where
68
69
70
71
72
73
	 * we display the current file we're editing. */
WINDOW *bottomwin;
	/* The bottom portion of the window, where we display statusbar
	 * messages, the statusbar prompt, and a list of shortcuts. */
int editwinrows = 0;
	/* How many rows does the edit window take up? */
74
int maxrows = 0;
75
	/* How many usable lines there are (due to soft wrapping). */
76
77
78

filestruct *cutbuffer = NULL;
	/* The buffer where we store cut text. */
79
filestruct *cutbottom = NULL;
80
#ifndef DISABLE_JUSTIFY
81
82
filestruct *jusbuffer = NULL;
	/* The buffer where we store unjustified text. */
83
#endif
84
85
86
partition *filepart = NULL;
	/* The partition where we store a portion of the current
	 * file. */
87
openfilestruct *openfile = NULL;
88
	/* The list of all open file buffers. */
89

90
91
92
93
94
95
#ifndef NANO_TINY
char *matchbrackets = NULL;
	/* The opening and closing brackets that can be found by bracket
	 * searches. */
#endif

96
#if !defined(NANO_TINY) && !defined(DISABLE_NANORC)
97
98
99
100
101
char *whitespace = NULL;
	/* The characters used when displaying the first characters of
	 * tabs and spaces. */
int whitespace_len[2];
	/* The length of these characters. */
102
103
#endif

104
#ifndef DISABLE_JUSTIFY
105
106
107
108
109
110
111
char *punct = NULL;
	/* The closing punctuation that can end sentences. */
char *brackets = NULL;
	/* The closing brackets that can follow closing punctuation and
	 * can end sentences. */
char *quotestr = NULL;
	/* The quoting string.  The default value is set in main(). */
112
#ifdef HAVE_REGEX_H
113
114
115
regex_t quotereg;
	/* The compiled regular expression from the quoting string. */
int quoterc;
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
116
	/* Whether it was compiled successfully. */
117
118
char *quoteerr = NULL;
	/* The error message, if it didn't. */
119
#else
120
121
size_t quotelen;
	/* The length of the quoting string in bytes. */
Chris Allegretta's avatar
Chris Allegretta committed
122
#endif
123
124
#endif

125
bool nodelay_mode = FALSE;
126
	/* Are we checking for a cancel wile doing something? */
127

128
char *answer = NULL;
129
	/* The answer string used by the statusbar prompt. */
Chris Allegretta's avatar
Chris Allegretta committed
130

131
132
133
ssize_t tabsize = -1;
	/* The width of a tab in spaces.  The default value is set in
	 * main(). */
134

135
136
137
#ifndef NANO_TINY
char *backup_dir = NULL;
	/* The directory where we store backup files. */
138

139
const char *locking_prefix = ".";
140
        /* Prefix of how to store the vim-style lock file. */
141
const char *locking_suffix = ".swp";
142
        /* Suffix of the vim-style lock file. */
143
#endif
144
#ifndef DISABLE_OPERATINGDIR
145
146
147
148
149
char *operating_dir = NULL;
	/* The relative path to the operating directory, which we can't
	 * move outside of. */
char *full_operating_dir = NULL;
	/* The full path to it. */
150
151
#endif

152
#ifndef DISABLE_SPELLER
153
154
char *alt_speller = NULL;
	/* The command to use for the alternate spell checker. */
155
156
#endif

157
#ifndef DISABLE_COLOR
158
syntaxtype *syntaxes = NULL;
159
	/* The global list of color syntaxes. */
160
char *syntaxstr = NULL;
161
	/* The color syntax name specified on the command line. */
162
163
#endif

164
bool edit_refresh_needed = FALSE;
165
	/* Did a command mangle enough of the buffer refresh that we
166
	 * should repaint the screen? */
167

168
int currmenu;
169
	/* The currently loaded menu. */
170
sc *sclist = NULL;
171
	/* Pointer to the start of the shortcuts list. */
172
subnfunc *allfuncs = NULL;
173
174
175
	/* Pointer to the start of the functions list. */
subnfunc *tailfunc;
	/* Pointer to the last function in the list. */
176
177
subnfunc *exitfunc;
	/* Pointer to the special Exit/Close item. */
178
179
subnfunc *uncutfunc;
	/* Pointer to the special Uncut/Unjustify item. */
180

181
#ifndef DISABLE_HISTORIES
182
filestruct *search_history = NULL;
183
	/* The search string history list. */
184
filestruct *searchage = NULL;
185
	/* The top of the search string history list. */
186
filestruct *searchbot = NULL;
187
	/* The bottom of the search string history list. */
188
filestruct *replace_history = NULL;
189
	/* The replace string history list. */
190
filestruct *replaceage = NULL;
191
	/* The top of the replace string history list. */
192
filestruct *replacebot = NULL;
193
	/* The bottom of the replace string history list. */
194
poshiststruct *poshistory;
195
	/* The cursor position history list. */
196
197
#endif

198
/* Regular expressions. */
199
#ifdef HAVE_REGEX_H
200
201
202
203
204
regex_t search_regexp;
	/* The compiled regular expression to use in searches. */
regmatch_t regmatches[10];
	/* The match positions for parenthetical subexpressions, 10
	 * maximum, used in regular expression searches. */
Chris Allegretta's avatar
Chris Allegretta committed
205
#endif
206

207
int hilite_attribute = A_REVERSE;
208
	/* The curses attribute we use for reverse video. */
209
210
211
212
#ifndef DISABLE_COLOR
char* specified_color_combo[] = {};
	/* The color combinations as specified in the rcfile. */
#endif
213
color_pair interface_color_pair[] = {};
214
	/* The processed color pairs for the interface elements. */
215

216
char *homedir = NULL;
217
	/* The user's home directory, from $HOME or /etc/passwd. */
218

219
/* Return the number of entries in the shortcut list for a given menu. */
220
size_t length_of_list(int menu)
221
{
222
    subnfunc *f;
223
    size_t i = 0;
224

225
    for (f = allfuncs; f != NULL; f = f->next)
226
227
228
229
230
        if ((f->menus & menu) != 0
#ifndef DISABLE_HELP
	    && strlen(f->help) > 0
#endif
	                          ) {
231
232
	    i++;
	}
233
234
235
    return i;
}

236
/* Just throw this here. */
237
238
239
240
241
242
void case_sens_void(void)
{
}
void regexp_void(void)
{
}
243
244
245
void backwards_void(void)
{
}
246
247
248
void gototext_void(void)
{
}
249
#ifndef DISABLE_BROWSER
250
251
252
void to_files_void(void)
{
}
253
254
255
256
void goto_dir_void(void)
{
}
#endif
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
void dos_format_void(void)
{
}
void mac_format_void(void)
{
}
void append_void(void)
{
}
void prepend_void(void)
{
}
void backup_file_void(void)
{
}
void new_buffer_void(void)
{
}
275
void flip_replace_void(void)
276
277
{
}
278
void flip_execute_void(void)
279
280
281
{
}

282
283
/* Set the type of command key based on the string. */
key_type strtokeytype(const char *str)
284
{
285
    if (str[0] == '^')
286
        return CONTROL;
287
288
289
    else if (str[0] == 'M')
        return META;
    else if (str[0] == 'F')
290
        return FKEY;
291
    else
292
	return RAWINPUT;
293
294
}

295
/* Add a string to the function list struct.
296
 * Does not allow updates, not yet anyway. */
297
void add_to_funcs(void (*func)(void), int menus, const char *desc, const char *help,
298
299
    bool blank_after, bool viewok)
{
300
    subnfunc *f = (subnfunc *)nmalloc(sizeof(subnfunc));
301
302
303
304
305
306

    if (allfuncs == NULL)
	allfuncs = f;
    else
	tailfunc->next = f;
    tailfunc = f;
307
308
309
310
311
312

    f->next = NULL;
    f->scfunc = func;
    f->menus = menus;
    f->desc = desc;
    f->viewok = viewok;
313
#ifndef DISABLE_HELP
314
315
316
317
318
    f->help = help;
    f->blank_after = blank_after;
#endif

#ifdef DEBUG
319
    fprintf(stderr, "Added func %ld (%s) for menus %x\n", (long)func, f->desc, menus);
320
#endif
321
322
}

323
324
/* Return the first shortcut in the list of shortcuts that
 * matches the given func in the given menu. */
325
326
const sc *first_sc_for(int menu, void (*func)(void))
{
327
328
    const sc *s;

329
330
331
    for (s = sclist; s != NULL; s = s->next)
	if ((s->menu & menu) && s->scfunc == func)
	    return s;
332

333
#ifdef DEBUG
334
    fprintf(stderr, "Whoops, returning null given func %ld in menu %x\n", (long)func, menu);
335
336
337
338
339
340
#endif
    /* Otherwise... */
    return NULL;
}


341
/* Add a string to the shortcut list.
342
 * Allows updates to existing entries in the list. */
343
void add_to_sclist(int menu, const char *scstring, void (*func)(void), int toggle)
Chris Allegretta's avatar
Chris Allegretta committed
344
{
345
    sc *s;
346

347
    if (sclist == NULL) {
348
	sclist = (sc *)nmalloc(sizeof(sc));
349
350
	s = sclist;
        s->next = NULL;
351
    } else {
352
353
354
355
356
357
358
359
360
361
362
363
	for (s = sclist; s->next != NULL; s = s->next)
            if (s->menu == menu && s->keystr == scstring)
		break;

        if (s->menu != menu || s->keystr != scstring) { /* i.e. this is not a replace... */
#ifdef DEBUG
            fprintf(stderr, "No match found...\n");
#endif
	    s->next = (sc *)nmalloc(sizeof(sc));
	    s = s->next;
            s->next = NULL;
        }
364
365
    }

366
367
368
    s->type = strtokeytype(scstring);
    s->menu = menu;
    s->toggle = toggle;
369
    s->keystr = (char *) scstring;
370
371
372
373
    s->scfunc = func;
    assign_keyinfo(s);

#ifdef DEBUG
374
    fprintf(stderr, "Setting sequence to %d for shortcut \"%s\" in menu %x\n", s->seq, scstring, (int)s->menu);
375
#endif
Chris Allegretta's avatar
Chris Allegretta committed
376
377
}

378
/* Assign one function's shortcuts to another function. */
379
380
381
382
void replace_scs_for(void (*oldfunc)(void), void (*newfunc)(void))
{
    sc *s;

383
    for (s = sclist; s != NULL; s = s->next)
384
	if (s->scfunc == oldfunc)
385
386
387
	    s->scfunc = newfunc;
}

Chris Allegretta's avatar
Chris Allegretta committed
388
/* Return the given menu's first shortcut sequence, or the default value
389
 * (2nd arg).  Assumes currmenu for the menu to check. */
390
int sc_seq_or(void (*func)(void), int defaultval)
Chris Allegretta's avatar
Chris Allegretta committed
391
392
393
{
    const sc *s = first_sc_for(currmenu, func);

394
395
    if (s) {
	meta_key = (s->type == META);
Chris Allegretta's avatar
Chris Allegretta committed
396
        return s->seq;
397
    }
Chris Allegretta's avatar
Chris Allegretta committed
398
399
400
401
    /* else */
    return defaultval;
}

402
403
/* Assign the info to the shortcut struct.
 * Assumes keystr is already assigned, naturally. */
404
405
406
407
408
409
410
411
412
413
414
void assign_keyinfo(sc *s)
{
    if (s->type == CONTROL) {
        assert(strlen(s->keystr) > 1);
        s->seq = s->keystr[1] - 64;
    } else if (s->type == META) {
        assert(strlen(s->keystr) > 2);
        s->seq = tolower((int) s->keystr[2]);
    } else if (s->type == FKEY) {
        assert(strlen(s->keystr) > 1);
        s->seq = KEY_F0 + atoi(&s->keystr[1]);
415
    } else /* RAWINPUT */
416
        s->seq = (int) s->keystr[0];
417

418
    /* Override some keys which don't bind as easily as we'd like. */
419
420
421
422
    if (s->type == CONTROL && (!strcasecmp(&s->keystr[1], "space")))
	s->seq = 0;
    else if (s->type == META && (!strcasecmp(&s->keystr[2], "space")))
	s->seq = (int) ' ';
423
    else if (s->type == RAWINPUT) {
424
	if (!strcasecmp(s->keystr, "Up"))
425
	    s->seq = KEY_UP;
426
	else if (!strcasecmp(s->keystr, "Down"))
427
	    s->seq = KEY_DOWN;
428
	else if (!strcasecmp(s->keystr, "Left"))
429
	    s->seq = KEY_LEFT;
430
	else if (!strcasecmp(s->keystr, "Right"))
431
	    s->seq = KEY_RIGHT;
432
	else if (!strcasecmp(s->keystr, "Ins"))
433
	    s->seq = KEY_IC;
434
	else if (!strcasecmp(s->keystr, "Del"))
435
	    s->seq = KEY_DC;
436
	else if (!strcasecmp(s->keystr, "Bsp"))
437
	    s->seq = KEY_BACKSPACE;
438
	else if (!strcasecmp(s->keystr, "Enter"))
439
	    s->seq = KEY_ENTER;
440
	else if (!strcasecmp(s->keystr, "PgUp"))
441
	    s->seq = KEY_PPAGE;
442
	else if (!strcasecmp(s->keystr, "PgDn"))
443
	    s->seq = KEY_NPAGE;
444
#ifdef KEY_HOME
445
	else if (!strcasecmp(s->keystr, "Home"))
446
	    s->seq = KEY_HOME;
447
448
#endif
#ifdef KEY_END
449
	else if (!strcasecmp(s->keystr, "End"))
450
	    s->seq = KEY_END;
451
#endif
452
    }
453
454
455
456
457
458
459
460
}

#ifdef DEBUG
void print_sclist(void)
{
    sc *s;
    const subnfunc *f;

461
    for (s = sclist; s != NULL; s = s->next) {
462
	f = sctofunc(s);
463
	if (f)
464
	    fprintf(stderr, "Shortcut \"%s\", function: %s, menus %x\n", s->keystr, f->desc, f->menus);
465
	else
466
	    fprintf(stderr, "Hmm, didn't find a func for \"%s\"\n", s->keystr);
467
468
469
470
    }
}
#endif

471
472
473
/* TRANSLATORS: Try to keep the next four strings at most 10 characters. */
const char *exit_tag = N_("Exit");
const char *close_tag = N_("Close");
474
475
476
477
const char *uncut_tag = N_("Uncut Text");
#ifndef DISABLE_JUSITIFY
const char *unjust_tag = N_("Unjustify");
#endif
478
#ifndef NANO_TINY
479
/* TRANSLATORS: Try to keep this at most 12 characters. */
480
const char *whereis_next_tag = N_("WhereIs Next");
481
#endif
482

483
484
/* Initialize the list of functions and the list of shortcuts. */
void shortcut_init(void)
485
{
486
    /* TRANSLATORS: Try to keep the next eight strings at most 10 characters. */
487
    const char *whereis_tag = N_("Where Is");
488
489
    const char *replace_tag = N_("Replace");
    const char *gotoline_tag = N_("Go To Line");
490
491
    const char *prev_line_tag = N_("Prev Line");
    const char *next_line_tag = N_("Next Line");
492
    const char *read_file_tag = N_("Read File");
493
#ifndef DISABLE_JUSTIFY
494
    const char *fulljustify_tag = N_("FullJstify");
495
#endif
496
    const char *refresh_tag = N_("Refresh");
497

498
#ifndef DISABLE_HELP
499
#ifndef DISABLE_JUSTIFY
500
501
    /* TRANSLATORS: The next long series of strings are shortcut descriptions;
     * they are best kept shorter than 56 characters, but may be longer. */
502
503
    const char *nano_justify_msg = N_("Justify the current paragraph");
#endif
504
    const char *nano_cancel_msg = N_("Cancel the current function");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
505
    const char *nano_help_msg = N_("Display this help text");
506
    const char *nano_exit_msg =
507
#ifndef DISABLE_MULTIBUFFER
508
	N_("Close the current file buffer / Exit from nano")
509
#else
510
	N_("Exit from nano")
511
512
#endif
	;
513
514
    const char *nano_writeout_msg =
	N_("Write the current file to disk");
515
516
    const char *nano_insert_msg =
	N_("Insert another file into the current one");
517
    const char *nano_whereis_msg =
518
	N_("Search for a string or a regular expression");
519
#ifndef DISABLE_BROWSER
520
521
    const char *nano_browser_whereis_msg =
	N_("Search for a string");
522
#endif
523
524
    const char *nano_prevpage_msg = N_("Go one screenful up");
    const char *nano_nextpage_msg = N_("Go one screenful down");
525
526
527
528
    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");
529
    const char *nano_cursorpos_msg = N_("Display the position of the cursor");
530
#ifndef DISABLE_SPELLER
531
    const char *nano_spell_msg = N_("Invoke the spell checker, if available");
532
#endif
533
    const char *nano_replace_msg = N_("Replace a string or a regular expression");
Benno Schulenberg's avatar
Benno Schulenberg committed
534
    const char *nano_gotoline_msg = N_("Go to line and column number");
535
#ifndef NANO_TINY
536
537
    const char *nano_mark_msg = N_("Mark text starting from the cursor position");
    const char *nano_whereis_next_msg = N_("Repeat the last search");
538
539
    const char *nano_copy_msg =
	N_("Copy the current line and store it in the cutbuffer");
540
541
    const char *nano_indent_msg = N_("Indent the current line");
    const char *nano_unindent_msg = N_("Unindent the current line");
542
543
    const char *nano_undo_msg = N_("Undo the last operation");
    const char *nano_redo_msg = N_("Redo the last undone operation");
544
#endif
545
546
    const char *nano_forward_msg = N_("Go forward one character");
    const char *nano_back_msg = N_("Go back one character");
547
#ifndef NANO_TINY
548
549
    const char *nano_nextword_msg = N_("Go forward one word");
    const char *nano_prevword_msg = N_("Go back one word");
550
#endif
551
552
553
554
    const char *nano_prevline_msg = N_("Go to previous line");
    const char *nano_nextline_msg = N_("Go to next line");
    const char *nano_home_msg = N_("Go to beginning of current line");
    const char *nano_end_msg = N_("Go to end of current line");
555
556
#ifndef DISABLE_JUSTIFY
    const char *nano_parabegin_msg =
557
	N_("Go to beginning of paragraph; then of previous paragraph");
558
    const char *nano_paraend_msg =
559
	N_("Go just beyond end of paragraph; then of next paragraph");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
560
#endif
561
562
    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");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
563
#ifndef NANO_TINY
564
    const char *nano_bracket_msg = N_("Go to the matching bracket");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
565
566
567
568
    const char *nano_scrollup_msg =
	N_("Scroll up one line without scrolling the cursor");
    const char *nano_scrolldown_msg =
	N_("Scroll down one line without scrolling the cursor");
569
#endif
570
#ifndef DISABLE_MULTIBUFFER
571
572
573
574
575
576
577
    const char *nano_prevfile_msg = N_("Switch to the previous file buffer");
    const char *nano_nextfile_msg = N_("Switch to the next file buffer");
#endif
    const char *nano_verbatim_msg = N_("Insert the next keystroke verbatim");
    const char *nano_tab_msg = N_("Insert a tab at the cursor position");
    const char *nano_enter_msg = N_("Insert a newline at the cursor position");
    const char *nano_delete_msg = N_("Delete the character under the cursor");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
578
579
    const char *nano_backspace_msg =
	N_("Delete the character to the left of the cursor");
580
#ifndef NANO_TINY
581
    const char *nano_cut_till_eof_msg =
582
583
	N_("Cut from the cursor position to the end of the file");
#endif
584
585
#ifndef DISABLE_JUSTIFY
    const char *nano_fulljustify_msg = N_("Justify the entire file");
586
#endif
587
#ifndef NANO_TINY
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
588
589
    const char *nano_wordcount_msg =
	N_("Count the number of words, lines, and characters");
590
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
591
592
    const char *nano_refresh_msg =
	N_("Refresh (redraw) the current screen");
593
594
    const char *nano_suspend_msg =
	N_("Suspend the editor (if suspend is enabled)");
595
#ifndef NANO_TINY
596
    const char *nano_case_msg =
597
	N_("Toggle the case sensitivity of the search");
598
    const char *nano_reverse_msg =
599
	N_("Reverse the direction of the search");
600
#endif
601
#ifdef HAVE_REGEX_H
602
603
    const char *nano_regexp_msg =
	N_("Toggle the use of regular expressions");
604
#endif
605
#ifndef DISABLE_HISTORIES
606
    const char *nano_prev_history_msg =
607
	N_("Recall the previous search/replace string");
608
    const char *nano_next_history_msg =
609
	N_("Recall the next search/replace string");
610
#endif
611
612
#ifndef DISABLE_BROWSER
    const char *nano_tofiles_msg = N_("Go to file browser");
Chris Allegretta's avatar
Chris Allegretta committed
613
#endif
614
#ifndef NANO_TINY
615
616
617
618
    const char *nano_dos_msg = N_("Toggle the use of DOS format");
    const char *nano_mac_msg = N_("Toggle the use of Mac format");
    const char *nano_append_msg = N_("Toggle appending");
    const char *nano_prepend_msg = N_("Toggle prepending");
619
    const char *nano_backup_msg = N_("Toggle backing up of the original file");
620
    const char *nano_execute_msg = N_("Execute external command");
621
#endif
622
#ifndef DISABLE_MULTIBUFFER
623
    const char *nano_multibuffer_msg = N_("Toggle the use of a new buffer");
624
625
#endif
#ifndef DISABLE_BROWSER
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
626
    const char *nano_exitbrowser_msg = N_("Exit from the file browser");
627
628
    const char *nano_firstfile_msg = N_("Go to the first file in the list");
    const char *nano_lastfile_msg = N_("Go to the last file in the list");
629
    const char *nano_backfile_msg = N_("Go to the previous file in the list");
630
    const char *nano_forwardfile_msg = N_("Go to the next file in the list");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
631
    const char *nano_gotodir_msg = N_("Go to directory");
Chris Allegretta's avatar
Chris Allegretta committed
632
#endif
633
#ifndef DISABLE_COLOR
634
    const char *nano_lint_msg = N_("Invoke the linter, if available");
635
636
637
    const char *nano_prevlint_msg = N_("Go to previous linter msg");
    const char *nano_nextlint_msg = N_("Go to next linter msg");
#endif
638
#endif /* !DISABLE_HELP */
Chris Allegretta's avatar
Chris Allegretta committed
639

David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
640
#ifndef DISABLE_HELP
641
#define IFSCHELP(help) help
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
642
#else
643
#define IFSCHELP(help) ""
644
#endif
645

646
647
    while (allfuncs != NULL) {
        subnfunc *f = allfuncs;
648
        allfuncs = allfuncs->next;
649
650
        free(f);
    }
651

Benno Schulenberg's avatar
Benno Schulenberg committed
652
653
    /* Start populating the different menus with functions. */

654
    add_to_funcs(do_help_void, MMOST,
655
656
	/* TRANSLATORS: Try to keep the following strings at most 10 characters. */
	N_("Get Help"), IFSCHELP(nano_help_msg), FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
657

658
    add_to_funcs(do_cancel, ((MMOST & ~MMAIN & ~MBROWSER) | MYESNO),
659
	N_("Cancel"), IFSCHELP(nano_cancel_msg), FALSE, VIEW);
660

661
    add_to_funcs(do_exit, MMAIN,
662
	exit_tag, IFSCHELP(nano_exit_msg), FALSE, VIEW);
663
664
    /* Remember the entry for Exit, to be able to replace it with Close. */
    exitfunc = tailfunc;
Chris Allegretta's avatar
Chris Allegretta committed
665

666
#ifndef DISABLE_BROWSER
667
668
    add_to_funcs(do_exit, MBROWSER,
	exit_tag, IFSCHELP(nano_exitbrowser_msg), FALSE, VIEW);
669
#endif
Chris Allegretta's avatar
Chris Allegretta committed
670

671
672
    add_to_funcs(do_writeout_void, MMAIN,
	N_("Write Out"), IFSCHELP(nano_writeout_msg), FALSE, NOVIEW);
673

674
    /* We allow inserting files in view mode if multibuffers are
675
676
677
678
     * 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. */
679
680
    add_to_funcs(do_insertfile_void, MMAIN,
	read_file_tag, IFSCHELP(nano_insert_msg), TRUE,
681
#ifndef DISABLE_MULTIBUFFER
682
	VIEW);
683
#else
684
	NOVIEW);
685
#endif
Chris Allegretta's avatar
Chris Allegretta committed
686

687
688
    add_to_funcs(do_search, MMAIN,
	whereis_tag, IFSCHELP(nano_whereis_msg), FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
689

690
691
    add_to_funcs(do_replace, MMAIN,
	replace_tag, IFSCHELP(nano_replace_msg), FALSE, NOVIEW);
692
693

#ifndef DISABLE_BROWSER
694
695
    add_to_funcs(do_search, MBROWSER,
	whereis_tag, IFSCHELP(nano_browser_whereis_msg), FALSE, VIEW);
696

697
698
    add_to_funcs(goto_dir_void, MBROWSER,
	N_("Go To Dir"), IFSCHELP(nano_gotodir_msg), TRUE, VIEW);
699
700
#endif

701
#ifndef DISABLE_HELP
702
703
    /* The description ("x") and blank_after (0) are irrelevant,
     * because the help viewer does not have a help text. */
704
    add_to_funcs(do_exit, MHELP, exit_tag, "x", 0, VIEW);
705

706
    add_to_funcs(total_refresh, MHELP, refresh_tag, "x", 0, VIEW);
707
708
709

    add_to_funcs(do_up_void, MHELP, prev_line_tag, "x", 0, VIEW);
    add_to_funcs(do_down_void, MHELP, next_line_tag, "x" , 0, VIEW);
710
711
#endif

712
713
    add_to_funcs(do_cut_text_void, MMAIN,
	N_("Cut Text"), IFSCHELP(nano_cut_msg), FALSE, NOVIEW);
Chris Allegretta's avatar
Chris Allegretta committed
714

715
716
    add_to_funcs(do_uncut_text, MMAIN,
	uncut_tag, IFSCHELP(nano_uncut_msg), TRUE, NOVIEW);
717
    /* Remember the entry for Uncut, to be able to replace it with Unjustify. */
718
    uncutfunc = tailfunc;
Chris Allegretta's avatar
Chris Allegretta committed
719

720
#ifndef DISABLE_JUSTIFY
721
722
    add_to_funcs(do_justify_void, MMAIN,
	N_("Justify"), IFSCHELP(nano_justify_msg), FALSE, NOVIEW);
Chris Allegretta's avatar
Chris Allegretta committed
723
#endif
Chris Allegretta's avatar
Chris Allegretta committed
724

725
#ifndef DISABLE_SPELLER
726
727
    add_to_funcs(do_spell, MMAIN,
	N_("To Spell"), IFSCHELP(nano_spell_msg), FALSE, NOVIEW);
728
#endif
729

730
#ifndef DISABLE_COLOR
731
732
    add_to_funcs(do_linter, MMAIN,
	N_("To Linter"), IFSCHELP(nano_lint_msg), TRUE, NOVIEW);
733
734
#endif

735
#ifndef NANO_TINY
736
    add_to_funcs(case_sens_void, MWHEREIS|MREPLACE,
737
738
739
740
	N_("Case Sens"), IFSCHELP(nano_case_msg), FALSE, VIEW);
#endif

#ifdef HAVE_REGEX_H
741
    add_to_funcs(regexp_void, MWHEREIS|MREPLACE,
742
743
744
745
	N_("Regexp"), IFSCHELP(nano_regexp_msg), FALSE, VIEW);
#endif

#ifndef NANO_TINY
746
    add_to_funcs(backwards_void, MWHEREIS|MREPLACE,
747
748
749
	N_("Backwards"), IFSCHELP(nano_reverse_msg), FALSE, VIEW);
#endif

750
    add_to_funcs(flip_replace_void, MWHEREIS,
751
752
	replace_tag, IFSCHELP(nano_replace_msg), FALSE, VIEW);

753
    add_to_funcs(flip_replace_void, MREPLACE,
754
755
756
	N_("No Replace"), IFSCHELP(nano_whereis_msg), FALSE, VIEW);

#ifndef DISABLE_JUSTIFY
757
758
    add_to_funcs(do_full_justify, MWHEREIS,
	fulljustify_tag, IFSCHELP(nano_fulljustify_msg), FALSE, NOVIEW);
759
760
#endif

761
762
    add_to_funcs(do_cursorpos_void, MMAIN,
	N_("Cur Pos"), IFSCHELP(nano_cursorpos_msg), FALSE, VIEW);
763

764
765
766
#if !defined(NANO_TINY) || defined(DISABLE_COLOR)
    /* Conditionally placing this one here or further on, to keep the
     * help items nicely paired in most conditions. */
767
768
    add_to_funcs(do_gotolinecolumn_void, MMAIN|MWHEREIS,
	gotoline_tag, IFSCHELP(nano_gotoline_msg), TRUE, VIEW);
769
#endif
770
771
772
773
774

    add_to_funcs(do_page_up, MMAIN|MHELP|MBROWSER,
	N_("Prev Page"), IFSCHELP(nano_prevpage_msg), FALSE, VIEW);
    add_to_funcs(do_page_down, MMAIN|MHELP|MBROWSER,
	N_("Next Page"), IFSCHELP(nano_nextpage_msg), FALSE, VIEW);
775

776
    add_to_funcs(do_first_line, MMAIN|MHELP|MWHEREIS|MREPLACE|MREPLACEWITH|MGOTOLINE,
777
	N_("First Line"), IFSCHELP(nano_firstline_msg), FALSE, VIEW);
778
    add_to_funcs(do_last_line, MMAIN|MHELP|MWHEREIS|MREPLACE|MREPLACEWITH|MGOTOLINE,
779
	N_("Last Line"), IFSCHELP(nano_lastline_msg), TRUE, VIEW);
780

781
#ifndef NANO_TINY
782
783
    add_to_funcs(do_research, MMAIN,
	whereis_next_tag, IFSCHELP(nano_whereis_next_msg), FALSE, VIEW);
784

785
786
    add_to_funcs(do_find_bracket, MMAIN,
	N_("To Bracket"), IFSCHELP(nano_bracket_msg), FALSE, VIEW);
787

788
789
    add_to_funcs(do_mark, MMAIN,
	N_("Mark Text"), IFSCHELP(nano_mark_msg), FALSE, VIEW);
790

791
792
    add_to_funcs(do_copy_text, MMAIN,
	N_("Copy Text"), IFSCHELP(nano_copy_msg), TRUE, NOVIEW);
793

794
795
796
797
    add_to_funcs(do_indent_void, MMAIN,
	N_("Indent Text"), IFSCHELP(nano_indent_msg), FALSE, NOVIEW);
    add_to_funcs(do_unindent, MMAIN,
	N_("Unindent Text"), IFSCHELP(nano_unindent_msg), TRUE, NOVIEW);
798

799
800
801
802
    add_to_funcs(do_undo, MMAIN,
	N_("Undo"), IFSCHELP(nano_undo_msg), FALSE, NOVIEW);
    add_to_funcs(do_redo, MMAIN,
	N_("Redo"), IFSCHELP(nano_redo_msg), TRUE, NOVIEW);
803
#endif /* !NANO_TINY */
804

805
806
807
808
    add_to_funcs(do_left, MMAIN,
	N_("Back"), IFSCHELP(nano_back_msg), FALSE, VIEW);
    add_to_funcs(do_right, MMAIN,
	N_("Forward"), IFSCHELP(nano_forward_msg), FALSE, VIEW);
809
810

#ifndef DISABLE_BROWSER
811
812
813
814
    add_to_funcs(do_left, MBROWSER,
	N_("Back"), IFSCHELP(nano_backfile_msg), FALSE, VIEW);
    add_to_funcs(do_right, MBROWSER,
	N_("Forward"), IFSCHELP(nano_forwardfile_msg), FALSE, VIEW);
815
816
#endif

817
#ifndef NANO_TINY
818
819
820
821
    add_to_funcs(do_prev_word_void, MMAIN,
	N_("Prev Word"), IFSCHELP(nano_prevword_msg), FALSE, VIEW);
    add_to_funcs(do_next_word_void, MMAIN,
	N_("Next Word"), IFSCHELP(nano_nextword_msg), FALSE, VIEW);
822
#endif
823

824
825
826
827
    add_to_funcs(do_home, MMAIN,
	N_("Home"), IFSCHELP(nano_home_msg), FALSE, VIEW);
    add_to_funcs(do_end, MMAIN,
	N_("End"), IFSCHELP(nano_end_msg), FALSE, VIEW);
828

829
830
831
832
    add_to_funcs(do_up_void, MMAIN|MBROWSER,
	prev_line_tag, IFSCHELP(nano_prevline_msg), FALSE, VIEW);
    add_to_funcs(do_down_void, MMAIN|MBROWSER,
	next_line_tag, IFSCHELP(nano_nextline_msg), TRUE, VIEW);
833

834
#ifndef DISABLE_JUSTIFY
835
836
837
838
    add_to_funcs(do_para_begin_void, MMAIN|MWHEREIS,
	N_("Beg of Par"), IFSCHELP(nano_parabegin_msg), FALSE, VIEW);
    add_to_funcs(do_para_end_void, MMAIN|MWHEREIS,
	N_("End of Par"), IFSCHELP(nano_paraend_msg), FALSE, VIEW);
839
#endif
840

841
#ifndef NANO_TINY
842
843
844
845
    add_to_funcs(do_scroll_up, MMAIN,
	N_("Scroll Up"), IFSCHELP(nano_scrollup_msg), FALSE, VIEW);
    add_to_funcs(do_scroll_down, MMAIN,
	N_("Scroll Down"), IFSCHELP(nano_scrolldown_msg), TRUE, VIEW);
846
847
#endif

848
#ifndef DISABLE_MULTIBUFFER
849
850
851
852
    add_to_funcs(switch_to_prev_buffer_void, MMAIN,
	N_("Prev File"), IFSCHELP(nano_prevfile_msg), FALSE, VIEW);
    add_to_funcs(switch_to_next_buffer_void, MMAIN,
	N_("Next File"), IFSCHELP(nano_nextfile_msg), TRUE, VIEW);
853
854
#endif

855
856
857
858
859
#if defined(NANO_TINY) && !defined(DISABLE_COLOR)
    add_to_funcs(do_gotolinecolumn_void, MMAIN|MWHEREIS,
	gotoline_tag, IFSCHELP(nano_gotoline_msg), TRUE, VIEW);
#endif

860
861
    add_to_funcs(do_verbatim_input, MMAIN,
	N_("Verbatim"), IFSCHELP(nano_verbatim_msg), FALSE, NOVIEW);
862

863
864
865
866
867
868
869
870
    add_to_funcs(do_tab, MMAIN,
	N_("Tab"), IFSCHELP(nano_tab_msg), FALSE, NOVIEW);
    add_to_funcs(do_enter_void, MMAIN,
	N_("Enter"), IFSCHELP(nano_enter_msg), FALSE, NOVIEW);
    add_to_funcs(do_delete, MMAIN,
	N_("Delete"), IFSCHELP(nano_delete_msg), FALSE, NOVIEW);
    add_to_funcs(do_backspace, MMAIN,
	N_("Backspace"), IFSCHELP(nano_backspace_msg),
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
871
#ifndef NANO_TINY
872
	FALSE,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
873
#else
874
	TRUE,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
875
#endif
876
877
	NOVIEW);

878
#ifndef NANO_TINY
879
880
    add_to_funcs(do_cut_till_eof, MMAIN,
	N_("CutTillEnd"), IFSCHELP(nano_cut_till_eof_msg), TRUE, NOVIEW);
881
#endif
Chris Allegretta's avatar
Chris Allegretta committed
882

883
#ifndef DISABLE_JUSTIFY
884
885
    add_to_funcs(do_full_justify, MMAIN,
	fulljustify_tag, IFSCHELP(nano_fulljustify_msg), FALSE, NOVIEW);
886
887
#endif

888
#ifndef NANO_TINY
889
890
    add_to_funcs(do_wordlinechar_count, MMAIN,
	N_("Word Count"), IFSCHELP(nano_wordcount_msg), FALSE, VIEW);
891
#endif
892

893
894
    add_to_funcs(total_refresh, MMAIN,
	refresh_tag, IFSCHELP(nano_refresh_msg), FALSE, VIEW);
895

896
897
    add_to_funcs(do_suspend_void, MMAIN,
	N_("Suspend"), IFSCHELP(nano_suspend_msg), TRUE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
898

899
#ifndef DISABLE_HISTORIES
900
    add_to_funcs(get_history_older_void,
901
	(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE),
902
	N_("PrevHstory"), IFSCHELP(nano_prev_history_msg), FALSE, VIEW);
903
    add_to_funcs(get_history_newer_void,
904
	(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE),
905
	N_("NextHstory"), IFSCHELP(nano_next_history_msg), FALSE, VIEW);
906
#endif
907

908
    add_to_funcs(gototext_void, MGOTOLINE,
909
	N_("Go To Text"), IFSCHELP(nano_whereis_msg), TRUE, VIEW);
910

911
#ifndef NANO_TINY
912
913
914
915
916
917
    /* 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. */
918
    if (!ISSET(RESTRICTED)) {
919
        add_to_funcs(dos_format_void, MWRITEFILE,
920
            N_("DOS Format"), IFSCHELP(nano_dos_msg), FALSE, NOVIEW);
921

922
        add_to_funcs(mac_format_void, MWRITEFILE,
923
            N_("Mac Format"), IFSCHELP(nano_mac_msg), FALSE, NOVIEW);
924

Benno Schulenberg's avatar
Benno Schulenberg committed
925
        add_to_funcs(append_void, MWRITEFILE,
926
            N_("Append"), IFSCHELP(nano_append_msg), FALSE, NOVIEW);
Benno Schulenberg's avatar
Benno Schulenberg committed
927
        add_to_funcs(prepend_void, MWRITEFILE,
928
            N_("Prepend"), IFSCHELP(nano_prepend_msg), FALSE, NOVIEW);
929

Benno Schulenberg's avatar
Benno Schulenberg committed
930
        add_to_funcs(backup_file_void, MWRITEFILE,
931
            N_("Backup File"), IFSCHELP(nano_backup_msg), FALSE, NOVIEW);
932
    }
933

934
935
936
    /* If we're using restricted mode, file insertion is disabled, and
     * thus command execution and the multibuffer toggle have no place. */
    if (!ISSET(RESTRICTED)) {
937
        add_to_funcs(flip_execute_void, MINSERTFILE,
938
	    N_("Execute Command"), IFSCHELP(nano_execute_msg), FALSE, NOVIEW);
939

940
        add_to_funcs(flip_execute_void, MEXTCMD,
941
942
	    read_file_tag, IFSCHELP(nano_insert_msg), FALSE, NOVIEW);

943
#ifndef DISABLE_MULTIBUFFER
944
	add_to_funcs(new_buffer_void, MINSERTFILE|MEXTCMD,
945
	    N_("New Buffer"), IFSCHELP(nano_multibuffer_msg), FALSE, NOVIEW);
946
#endif
947
    }
948
#endif /* !NANO_TINY */
949

950
#ifndef DISABLE_BROWSER
951
952
953
954
    if (!ISSET(RESTRICTED))
	add_to_funcs(to_files_void, MWRITEFILE|MINSERTFILE,
	    N_("To Files"), IFSCHELP(nano_tofiles_msg), FALSE, VIEW);

Benno Schulenberg's avatar
Benno Schulenberg committed
955
    add_to_funcs(do_first_file, (MBROWSER|MWHEREISFILE),
956
	N_("First File"), IFSCHELP(nano_firstfile_msg), FALSE, VIEW);
Benno Schulenberg's avatar
Benno Schulenberg committed
957
    add_to_funcs(do_last_file, (MBROWSER|MWHEREISFILE),
958
	N_("Last File"), IFSCHELP(nano_lastfile_msg), FALSE, VIEW);
959
#endif
Chris Allegretta's avatar
Chris Allegretta committed
960

961
#if !defined(NANO_TINY) && !defined(DISABLE_BROWSER)
962
963
    add_to_funcs(do_research, MBROWSER,
	whereis_next_tag, IFSCHELP(nano_whereis_next_msg), FALSE, VIEW);
964
965
966
#endif

#ifndef DISABLE_COLOR
967
    /* TRANSLATORS: Try to keep the next two strings at most 20 characters. */
968
    add_to_funcs(do_page_up, MLINTER,
969
	N_("Prev Lint Msg"), IFSCHELP(nano_prevlint_msg), FALSE, VIEW);
970
    add_to_funcs(do_page_down, MLINTER,
971
	N_("Next Lint Msg"), IFSCHELP(nano_nextlint_msg), FALSE, VIEW);
972
973
#endif

Benno Schulenberg's avatar
Benno Schulenberg committed
974
975
    /* Start associating key combos with functions in specific menus. */

976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
    add_to_sclist(MMOST, "^G", do_help_void, 0);
    add_to_sclist(MMOST, "F1", do_help_void, 0);
    add_to_sclist(MMAIN|MHELP|MBROWSER, "^X", do_exit, 0);
    add_to_sclist(MMAIN|MHELP|MBROWSER, "F2", do_exit, 0);
    add_to_sclist(MMAIN, "^O", do_writeout_void, 0);
    add_to_sclist(MMAIN, "F3", do_writeout_void, 0);
    add_to_sclist(MMAIN, "^R", do_insertfile_void, 0);
    add_to_sclist(MMAIN, "F5", do_insertfile_void, 0);
    add_to_sclist(MMAIN, "Ins", do_insertfile_void, 0);
    add_to_sclist(MMAIN|MBROWSER, "^W", do_search, 0);
    add_to_sclist(MMAIN|MBROWSER, "F6", do_search, 0);
    add_to_sclist(MMAIN, "^\\", do_replace, 0);
    add_to_sclist(MMAIN, "M-R", do_replace, 0);
    add_to_sclist(MMAIN, "F14", do_replace, 0);
    add_to_sclist(MMOST, "^K", do_cut_text_void, 0);
    add_to_sclist(MMOST, "F9", do_cut_text_void, 0);
    add_to_sclist(MMAIN, "^U", do_uncut_text, 0);
    add_to_sclist(MMAIN, "F10", do_uncut_text, 0);
994
#ifndef DISABLE_JUSTIFY
995
996
    add_to_sclist(MMAIN, "^J", do_justify_void, 0);
    add_to_sclist(MMAIN, "F4", do_justify_void, 0);
997
#endif
998
#ifndef DISABLE_SPELLER
999
1000
    add_to_sclist(MMAIN, "^T", do_spell, 0);
    add_to_sclist(MMAIN, "F12", do_spell, 0);
1001
1002
#else
#ifndef DISABLE_COLOR
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
    add_to_sclist(MMAIN, "^T", do_linter, 0);
    add_to_sclist(MMAIN, "F12", do_linter, 0);
#endif
#endif
    add_to_sclist(MMAIN, "^C", do_cursorpos_void, 0);
    add_to_sclist(MMAIN, "F11", do_cursorpos_void, 0);
    add_to_sclist(MMAIN, "^_", do_gotolinecolumn_void, 0);
    add_to_sclist(MMAIN, "M-G", do_gotolinecolumn_void, 0);
    add_to_sclist(MMAIN, "F13", do_gotolinecolumn_void, 0);
    add_to_sclist(MMAIN|MBROWSER|MHELP|MWHEREISFILE|MLINTER, "^Y", do_page_up, 0);
    add_to_sclist(MMAIN|MBROWSER|MHELP|MWHEREISFILE|MLINTER, "F7", do_page_up, 0);
    add_to_sclist(MMAIN|MBROWSER|MHELP|MWHEREISFILE|MLINTER, "PgUp", do_page_up, 0);
    add_to_sclist(MMAIN|MBROWSER|MHELP|MWHEREISFILE|MLINTER, "^V", do_page_down, 0);
    add_to_sclist(MMAIN|MBROWSER|MHELP|MWHEREISFILE|MLINTER, "F8", do_page_down, 0);
    add_to_sclist(MMAIN|MBROWSER|MHELP|MWHEREISFILE|MLINTER, "PgDn", do_page_down, 0);
    add_to_sclist(MMAIN|MHELP, "M-\\", do_first_line, 0);
    add_to_sclist(MMAIN|MHELP, "M-|", do_first_line, 0);
    add_to_sclist(MMAIN|MHELP, "M-/", do_last_line, 0);
    add_to_sclist(MMAIN|MHELP, "M-?", do_last_line, 0);
1022
#ifndef NANO_TINY
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
    add_to_sclist(MMAIN|MBROWSER, "M-W", do_research, 0);
    add_to_sclist(MMAIN|MBROWSER, "F16", do_research, 0);
    add_to_sclist(MMAIN, "M-]", do_find_bracket, 0);
    add_to_sclist(MMAIN, "^^", do_mark, 0);
    add_to_sclist(MMAIN, "M-A", do_mark, 0);
    add_to_sclist(MMAIN, "F15", do_mark, 0);
    add_to_sclist(MMAIN, "M-^", do_copy_text, 0);
    add_to_sclist(MMAIN, "M-6", do_copy_text, 0);
    add_to_sclist(MMAIN, "M-}", do_indent_void, 0);
    add_to_sclist(MMAIN, "M-{", do_unindent, 0);
    add_to_sclist(MMAIN, "M-U", do_undo, 0);
    add_to_sclist(MMAIN, "M-E", do_redo, 0);
#endif
    add_to_sclist(MMOST, "^B", do_left, 0);
    add_to_sclist(MMOST, "Left", do_left, 0);
    add_to_sclist(MMOST, "^F", do_right, 0);
    add_to_sclist(MMOST, "Right", do_right, 0);
1040
#ifndef NANO_TINY
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
    add_to_sclist(MMOST, "M-Space", do_prev_word_void, 0);
    add_to_sclist(MMOST, "^Space", do_next_word_void, 0);
#endif
    add_to_sclist(MMOST, "^A", do_home, 0);
    add_to_sclist(MMOST, "Home", do_home, 0);
    add_to_sclist(MMOST, "^E", do_end, 0);
    add_to_sclist(MMOST, "End", do_end, 0);
    add_to_sclist(MMAIN|MHELP|MBROWSER, "^P", do_up_void, 0);
    add_to_sclist(MMAIN|MHELP|MBROWSER, "Up", do_up_void, 0);
    add_to_sclist(MMAIN|MHELP|MBROWSER, "^N", do_down_void, 0);
    add_to_sclist(MMAIN|MHELP|MBROWSER, "Down", do_down_void, 0);
1052
#ifndef DISABLE_JUSTIFY
1053
1054
1055
1056
    add_to_sclist(MMAIN, "M-(", do_para_begin_void, 0);
    add_to_sclist(MMAIN, "M-9", do_para_begin_void, 0);
    add_to_sclist(MMAIN, "M-)", do_para_end_void, 0);
    add_to_sclist(MMAIN, "M-0", do_para_end_void, 0);
Benno Schulenberg's avatar
Benno Schulenberg committed
1057
#endif
1058
#ifndef NANO_TINY
1059
1060
1061
1062
    add_to_sclist(MMAIN, "M--", do_scroll_up, 0);
    add_to_sclist(MMAIN, "M-_", do_scroll_up, 0);
    add_to_sclist(MMAIN, "M-+", do_scroll_down, 0);
    add_to_sclist(MMAIN, "M-=", do_scroll_down, 0);
1063
#endif
1064
#ifndef DISABLE_MULTIBUFFER
1065
1066
1067
1068
    add_to_sclist(MMAIN, "M-<", switch_to_prev_buffer_void, 0);
    add_to_sclist(MMAIN, "M-,", switch_to_prev_buffer_void, 0);
    add_to_sclist(MMAIN, "M->", switch_to_next_buffer_void, 0);
    add_to_sclist(MMAIN, "M-.", switch_to_next_buffer_void, 0);
1069
#endif
1070
    add_to_sclist(MMOST, "M-V", do_verbatim_input, 0);
1071
#ifndef NANO_TINY
1072
    add_to_sclist(MMAIN, "M-T", do_cut_till_eof, 0);
1073
    add_to_sclist(MMAIN, "M-D", do_wordlinechar_count, 0);
1074
#endif
1075
#ifndef DISABLE_JUSTIFY
1076
    add_to_sclist(MMAIN|MWHEREIS, "M-J", do_full_justify, 0);
1077
#endif
1078
1079
    add_to_sclist(MMAIN|MHELP, "^L", total_refresh, 0);
    add_to_sclist(MMAIN, "^Z", do_suspend_void, 0);
1080

1081
#ifndef NANO_TINY
1082
    /* Group of "Appearance" toggles. */
1083
1084
1085
1086
1087
1088
    add_to_sclist(MMAIN, "M-X", do_toggle_void, NO_HELP);
    add_to_sclist(MMAIN, "M-C", do_toggle_void, CONST_UPDATE);
    add_to_sclist(MMAIN, "M-O", do_toggle_void, MORE_SPACE);
    add_to_sclist(MMAIN, "M-S", do_toggle_void, SMOOTH_SCROLL);
    add_to_sclist(MMAIN, "M-$", do_toggle_void, SOFTWRAP);
    add_to_sclist(MMAIN, "M-P", do_toggle_void, WHITESPACE_DISPLAY);
1089
#ifndef DISABLE_COLOR
1090
    add_to_sclist(MMAIN, "M-Y", do_toggle_void, NO_COLOR_SYNTAX);
1091
#endif
1092

1093
    /* Group of "Editing-behavior" toggles. */
1094
1095
1096
    add_to_sclist(MMAIN, "M-H", do_toggle_void, SMART_HOME);
    add_to_sclist(MMAIN, "M-I", do_toggle_void, AUTOINDENT);
    add_to_sclist(MMAIN, "M-K", do_toggle_void, CUT_TO_END);
1097
#ifndef DISABLE_WRAPPING
1098
    add_to_sclist(MMAIN, "M-L", do_toggle_void, NO_WRAP);
1099
#endif
1100
    add_to_sclist(MMAIN, "M-Q", do_toggle_void, TABS_TO_SPACES);
1101

1102
    /* Group of "Peripheral-feature" toggles. */
1103
    add_to_sclist(MMAIN, "M-B", do_toggle_void, BACKUP_FILE);
1104
#ifndef DISABLE_MULTIBUFFER
1105
    add_to_sclist(MMAIN, "M-F", do_toggle_void, MULTIBUFFER);
1106
1107
#endif
#ifndef DISABLE_MOUSE
1108
    add_to_sclist(MMAIN, "M-M", do_toggle_void, USE_MOUSE);
1109
#endif
1110
1111
    add_to_sclist(MMAIN, "M-N", do_toggle_void, NO_CONVERT);
    add_to_sclist(MMAIN, "M-Z", do_toggle_void, SUSPEND);
1112
#endif /* !NANO_TINY */
Benno Schulenberg's avatar
Benno Schulenberg committed
1113

1114
1115
    add_to_sclist(MMAIN, "^Q", xon_complaint, 0);
    add_to_sclist(MMAIN, "^S", xoff_complaint, 0);
1116

1117
    add_to_sclist(((MMOST & ~MMAIN & ~MBROWSER) | MYESNO), "^C", do_cancel, 0);
1118

1119
#ifndef NANO_TINY
1120
1121
    add_to_sclist(MWHEREIS|MREPLACE, "M-B", backwards_void, 0);
    add_to_sclist(MWHEREIS|MREPLACE, "M-C", case_sens_void, 0);
1122
#endif
1123
1124
1125
1126
    add_to_sclist(MWHEREIS|MREPLACE, "M-R", regexp_void, 0);
    add_to_sclist(MWHEREIS|MREPLACE, "^R", flip_replace_void, 0);
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MGOTOLINE, "^Y", do_first_line, 0);
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MGOTOLINE, "^V", do_last_line, 0);
1127
#ifndef DISABLE_JUSTIFY
1128
1129
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH, "^W", do_para_begin_void, 0);
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH, "^O", do_para_end_void, 0);
1130
#endif
1131
1132
    add_to_sclist(MWHEREIS, "^T", do_gotolinecolumn_void, 0);
    add_to_sclist(MGOTOLINE, "^T", gototext_void, 0);
1133
#ifndef DISABLE_HISTORIES
1134
1135
1136
1137
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE, "^P", get_history_older_void, 0);
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE, "Up", get_history_older_void, 0);
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE, "^N", get_history_newer_void, 0);
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE, "Down", get_history_newer_void, 0);
1138
1139
#endif
#ifndef DISABLE_BROWSER
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
    add_to_sclist(MBROWSER|MWHEREISFILE, "M-\\", do_first_file, 0);
    add_to_sclist(MBROWSER|MWHEREISFILE, "M-|", do_first_file, 0);
    add_to_sclist(MBROWSER|MWHEREISFILE, "M-/", do_last_file, 0);
    add_to_sclist(MBROWSER|MWHEREISFILE, "M-?", do_last_file, 0);
    add_to_sclist(MBROWSER|MWHEREISFILE, "^_", goto_dir_void, 0);
    add_to_sclist(MBROWSER|MWHEREISFILE, "M-G", goto_dir_void, 0);
    add_to_sclist(MBROWSER|MWHEREISFILE, "F13", goto_dir_void, 0);
#endif
    add_to_sclist(MWRITEFILE, "M-D", dos_format_void, 0);
    add_to_sclist(MWRITEFILE, "M-M", mac_format_void, 0);
    add_to_sclist(MWRITEFILE, "M-A", append_void, 0);
    add_to_sclist(MWRITEFILE, "M-P", prepend_void, 0);
    add_to_sclist(MWRITEFILE, "M-B", backup_file_void, 0);
1153
#ifndef DISABLE_BROWSER
1154
    add_to_sclist(MWRITEFILE|MINSERTFILE, "^T", to_files_void, 0);
1155
#endif
1156
1157
1158
    add_to_sclist(MINSERTFILE|MEXTCMD, "^X", flip_execute_void, 0);
    add_to_sclist(MINSERTFILE|MEXTCMD, "M-F", new_buffer_void, 0);
    add_to_sclist(MHELP|MBROWSER, "^C", do_exit, 0);
1159
#ifndef DISABLE_HELP
1160
    add_to_sclist(MHELP, "^G", do_exit, 0);
1161
#endif
1162
1163
1164
1165
1166
1167
1168
    add_to_sclist(MMOST, "^I", do_tab, 0);
    add_to_sclist(MMOST, "^M", do_enter_void, 0);
    add_to_sclist(MMOST, "Enter", do_enter_void, 0);
    add_to_sclist(MMOST, "^D", do_delete, 0);
    add_to_sclist(MMOST, "Del", do_delete, 0);
    add_to_sclist(MMOST, "^H", do_backspace, 0);
    add_to_sclist(MMOST, "Bsp", do_backspace, 0);
Chris Allegretta's avatar
Chris Allegretta committed
1169

1170
1171
#ifdef DEBUG
    print_sclist();
Chris Allegretta's avatar
Chris Allegretta committed
1172
#endif
1173
}
1174

1175
#ifndef DISABLE_COLOR
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
void set_lint_shortcuts(void)
{
#ifndef DISABLE_SPELLER
    replace_scs_for(do_spell, do_linter);
#endif
}

void set_spell_shortcuts(void)
{
#ifndef DISABLE_SPELLER
    replace_scs_for(do_linter, do_spell);
#endif
}
#endif

1191
const subnfunc *sctofunc(sc *s)
1192
{
1193
    subnfunc *f;
1194

1195
1196
    for (f = allfuncs; f != NULL && s->scfunc != f->scfunc; f = f->next)
	;
1197

1198
    return f;
1199
1200
}

1201
#ifndef NANO_TINY
1202
1203
/* Now let's come up with a single (hopefully) function to get a string
 * for each flag. */
1204
const char *flagtostr(int flag)
1205
{
1206
    switch (flag) {
1207
        case NO_HELP:
1208
1209
            /* TRANSLATORS: The next seventeen strings are toggle descriptions;
             * they are best kept shorter than 40 characters, but may be longer. */
1210
1211
1212
1213
1214
1215
1216
            return N_("Help mode");
        case CONST_UPDATE:
            return N_("Constant cursor position display");
        case MORE_SPACE:
            return N_("Use of one more line for editing");
        case SMOOTH_SCROLL:
            return N_("Smooth scrolling");
1217
1218
        case SOFTWRAP:
            return N_("Soft wrapping of overlong lines");
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
        case WHITESPACE_DISPLAY:
            return N_("Whitespace display");
        case NO_COLOR_SYNTAX:
            return N_("Color syntax highlighting");
        case SMART_HOME:
            return N_("Smart home key");
        case AUTOINDENT:
            return N_("Auto indent");
        case CUT_TO_END:
            return N_("Cut to end");
        case NO_WRAP:
1230
            return N_("Hard wrapping of overlong lines");
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
        case TABS_TO_SPACES:
            return N_("Conversion of typed tabs to spaces");
        case BACKUP_FILE:
            return N_("Backup files");
        case MULTIBUFFER:
            return N_("Multiple file buffers");
        case USE_MOUSE:
            return N_("Mouse support");
        case NO_CONVERT:
            return N_("No conversion from DOS/Mac format");
        case SUSPEND:
            return N_("Suspension");
        default:
            return "?????";
    }
}
1247
#endif /* !NANO_TINY */
1248

1249
#ifndef DISABLE_NANORC
1250
/* Interpret a function string given in the rc file, and return a
1251
 * shortcut struct with the corresponding function filled in. */
1252
sc *strtosc(char *input)
1253
{
1254
    sc *s;
1255
1256
1257

    s = (sc *)nmalloc(sizeof(sc));

Chris Allegretta's avatar
Chris Allegretta committed
1258
#ifndef DISABLE_HELP
1259
    if (!strcasecmp(input, "help"))
1260
1261
	s->scfunc = do_help_void;
    else
Chris Allegretta's avatar
Chris Allegretta committed
1262
#endif
1263
    if (!strcasecmp(input, "cancel"))
1264
	s->scfunc = do_cancel;
1265
    else if (!strcasecmp(input, "exit"))
1266
	s->scfunc = do_exit;
1267
    else if (!strcasecmp(input, "writeout"))
1268
	s->scfunc = do_writeout_void;
1269
    else if (!strcasecmp(input, "insert"))
1270
	s->scfunc = do_insertfile_void;
1271
    else if (!strcasecmp(input, "whereis"))
1272
	s->scfunc = do_search;
1273
#ifndef NANO_TINY
1274
1275
1276
    else if (!strcasecmp(input, "searchagain") ||
	     !strcasecmp(input, "research"))
	s->scfunc = do_research;
1277
#endif
1278
1279
    else if (!strcasecmp(input, "replace"))
	s->scfunc = do_replace;
1280
    else if (!strcasecmp(input, "cut"))
1281
	s->scfunc = do_cut_text_void;
1282
    else if (!strcasecmp(input, "uncut"))
1283
	s->scfunc = do_uncut_text;
1284
#ifndef NANO_TINY
1285
    else if (!strcasecmp(input, "cutrestoffile"))
1286
	s->scfunc = do_cut_till_eof;
1287
1288
    else if (!strcasecmp(input, "copytext"))
	s->scfunc = do_copy_text;
1289
1290
    else if (!strcasecmp(input, "mark"))
	s->scfunc = do_mark;
1291
1292
#endif
#ifndef DISABLE_SPELLER
1293
1294
1295
    else if (!strcasecmp(input, "tospell") ||
	     !strcasecmp(input, "speller"))
	s->scfunc = do_spell;
1296
#endif
1297
    else if (!strcasecmp(input, "curpos") ||
1298
	     !strcasecmp(input, "cursorpos"))
1299
	s->scfunc = do_cursorpos_void;
1300
    else if (!strcasecmp(input, "gotoline"))
1301
	s->scfunc = do_gotolinecolumn_void;
1302
#ifndef DISABLE_JUSTIFY
Chris Allegretta's avatar
Chris Allegretta committed
1303
    else if (!strcasecmp(input, "justify"))
1304
	s->scfunc = do_justify_void;
1305
1306
    else if (!strcasecmp(input, "fulljustify"))
	s->scfunc = do_full_justify;
1307
    else if (!strcasecmp(input, "beginpara"))
1308
	s->scfunc = do_para_begin_void;
1309
    else if (!strcasecmp(input, "endpara"))
1310
	s->scfunc = do_para_end_void;
1311
1312
#endif
#ifndef NANO_TINY
1313
    else if (!strcasecmp(input, "indent"))
1314
	s->scfunc = do_indent_void;
1315
    else if (!strcasecmp(input, "unindent"))
1316
	s->scfunc = do_unindent;
Chris Allegretta's avatar
Chris Allegretta committed
1317
    else if (!strcasecmp(input, "scrollup"))
1318
	s->scfunc = do_scroll_up;
Chris Allegretta's avatar
Chris Allegretta committed
1319
    else if (!strcasecmp(input, "scrolldown"))
1320
	s->scfunc = do_scroll_down;
1321
    else if (!strcasecmp(input, "prevword"))
1322
	s->scfunc = do_prev_word_void;
1323
1324
    else if (!strcasecmp(input, "nextword"))
	s->scfunc = do_next_word_void;
1325
    else if (!strcasecmp(input, "findbracket"))
1326
	s->scfunc = do_find_bracket;
1327
    else if (!strcasecmp(input, "wordcount"))
1328
	s->scfunc = do_wordlinechar_count;
1329
    else if (!strcasecmp(input, "undo"))
1330
	s->scfunc = do_undo;
1331
    else if (!strcasecmp(input, "redo"))
1332
	s->scfunc = do_redo;
1333
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1334
    else if (!strcasecmp(input, "left") ||
1335
	     !strcasecmp(input, "back"))
1336
	s->scfunc = do_left;
1337
1338
1339
    else if (!strcasecmp(input, "right") ||
	     !strcasecmp(input, "forward"))
	s->scfunc = do_right;
Chris Allegretta's avatar
Chris Allegretta committed
1340
    else if (!strcasecmp(input, "up") ||
1341
	     !strcasecmp(input, "prevline"))
1342
	s->scfunc = do_up_void;
Chris Allegretta's avatar
Chris Allegretta committed
1343
    else if (!strcasecmp(input, "down") ||
1344
	     !strcasecmp(input, "nextline"))
1345
	s->scfunc = do_down_void;
Chris Allegretta's avatar
Chris Allegretta committed
1346
    else if (!strcasecmp(input, "home"))
1347
	s->scfunc = do_home;
Chris Allegretta's avatar
Chris Allegretta committed
1348
    else if (!strcasecmp(input, "end"))
1349
	s->scfunc = do_end;
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
    else if (!strcasecmp(input, "pageup") ||
	     !strcasecmp(input, "prevpage"))
	s->scfunc = do_page_up;
    else if (!strcasecmp(input, "pagedown") ||
	     !strcasecmp(input, "nextpage"))
	s->scfunc = do_page_down;
    else if (!strcasecmp(input, "firstline"))
	s->scfunc = do_first_line;
    else if (!strcasecmp(input, "lastline"))
	s->scfunc = do_last_line;
1360
#ifndef DISABLE_MULTIBUFFER
Chris Allegretta's avatar
Chris Allegretta committed
1361
    else if (!strcasecmp(input, "prevbuf"))
1362
	s->scfunc = switch_to_prev_buffer_void;
Chris Allegretta's avatar
Chris Allegretta committed
1363
    else if (!strcasecmp(input, "nextbuf"))
1364
	s->scfunc = switch_to_next_buffer_void;
Chris Allegretta's avatar
Chris Allegretta committed
1365
1366
#endif
    else if (!strcasecmp(input, "verbatim"))
1367
	s->scfunc = do_verbatim_input;
Chris Allegretta's avatar
Chris Allegretta committed
1368
    else if (!strcasecmp(input, "tab"))
1369
	s->scfunc = do_tab;
Chris Allegretta's avatar
Chris Allegretta committed
1370
    else if (!strcasecmp(input, "enter"))
1371
	s->scfunc = do_enter_void;
Chris Allegretta's avatar
Chris Allegretta committed
1372
    else if (!strcasecmp(input, "delete"))
1373
	s->scfunc = do_delete;
1374
    else if (!strcasecmp(input, "backspace"))
1375
	s->scfunc = do_backspace;
Chris Allegretta's avatar
Chris Allegretta committed
1376
    else if (!strcasecmp(input, "refresh"))
1377
	s->scfunc = total_refresh;
1378
1379
    else if (!strcasecmp(input, "suspend"))
	s->scfunc = do_suspend_void;
1380
    else if (!strcasecmp(input, "casesens"))
1381
	s->scfunc = case_sens_void;
1382
#ifndef NANO_TINY
1383
1384
    else if (!strcasecmp(input, "regexp") ||
	     !strcasecmp(input, "regex"))
1385
	s->scfunc = regexp_void;
1386
    else if (!strcasecmp(input, "backwards"))
1387
	s->scfunc = backwards_void;
1388
#endif
1389
1390
    else if (!strcasecmp(input, "flipreplace") ||
	     !strcasecmp(input, "dontreplace"))
1391
	s->scfunc = flip_replace_void;
1392
    else if (!strcasecmp(input, "gototext"))
1393
	s->scfunc = gototext_void;
1394
1395
1396
1397
1398
1399
1400
#ifndef DISABLE_HISTORIES
    else if (!strcasecmp(input, "prevhistory"))
	s->scfunc = get_history_older_void;
    else if (!strcasecmp(input, "nexthistory"))
	s->scfunc = get_history_newer_void;
#endif
    else if (!strcasecmp(input, "dosformat"))
1401
	s->scfunc = dos_format_void;
1402
    else if (!strcasecmp(input, "macformat"))
1403
	s->scfunc = mac_format_void;
1404
    else if (!strcasecmp(input, "append"))
1405
	s->scfunc = append_void;
1406
    else if (!strcasecmp(input, "prepend"))
1407
	s->scfunc = prepend_void;
1408
    else if (!strcasecmp(input, "backup"))
1409
	s->scfunc = backup_file_void;
1410
#ifndef ENABLE_TINY
1411
    else if (!strcasecmp(input, "flipexecute"))
1412
1413
	s->scfunc = flip_execute_void;
#endif
1414
#ifndef DISABLE_MULTIBUFFER
1415
1416
    else if (!strcasecmp(input, "flipnewbuffer") ||
	     !strcasecmp(input, "newbuffer"))
1417
	s->scfunc = new_buffer_void;
Chris Allegretta's avatar
Chris Allegretta committed
1418
#endif
1419
#ifndef DISABLE_BROWSER
1420
1421
    else if (!strcasecmp(input, "tofiles") ||
	     !strcasecmp(input, "browser"))
1422
	s->scfunc = to_files_void;
1423
    else if (!strcasecmp(input, "gotodir"))
1424
	s->scfunc = goto_dir_void;
1425
    else if (!strcasecmp(input, "firstfile"))
1426
	s->scfunc = do_first_file;
1427
    else if (!strcasecmp(input, "lastfile"))
1428
1429
	s->scfunc = do_last_file;
#endif
1430
#ifndef NANO_TINY
1431
    else {
1432
	s->scfunc = do_toggle_void;
1433
	if (!strcasecmp(input, "nohelp"))
1434
	    s->toggle = NO_HELP;
1435
	else if (!strcasecmp(input, "constupdate"))
1436
	    s->toggle = CONST_UPDATE;
1437
	else if (!strcasecmp(input, "morespace"))
1438
	    s->toggle = MORE_SPACE;
1439
	else if (!strcasecmp(input, "smoothscroll"))
1440
	    s->toggle = SMOOTH_SCROLL;
1441
	else if (!strcasecmp(input, "softwrap"))
1442
	    s->toggle = SOFTWRAP;
1443
	else if (!strcasecmp(input, "whitespacedisplay"))
1444
	    s->toggle = WHITESPACE_DISPLAY;
1445
#ifndef DISABLE_COLOR
1446
	else if (!strcasecmp(input, "nosyntax"))
1447
1448
	    s->toggle = NO_COLOR_SYNTAX;
#endif
1449
	else if (!strcasecmp(input, "smarthome"))
1450
	    s->toggle = SMART_HOME;
1451
	else if (!strcasecmp(input, "autoindent"))
1452
	    s->toggle = AUTOINDENT;
1453
	else if (!strcasecmp(input, "cuttoend"))
1454
	    s->toggle = CUT_TO_END;
1455
#ifndef DISABLE_WRAPPING
1456
	else if (!strcasecmp(input, "nowrap"))
1457
	    s->toggle = NO_WRAP;
1458
#endif
1459
	else if (!strcasecmp(input, "tabstospaces"))
1460
	    s->toggle = TABS_TO_SPACES;
1461
	else if (!strcasecmp(input, "backupfile"))
1462
	    s->toggle = BACKUP_FILE;
1463
#ifndef DISABLE_MULTIBUFFER
1464
	else if (!strcasecmp(input, "multibuffer"))
1465
	    s->toggle = MULTIBUFFER;
1466
1467
#endif
#ifndef DISABLE_MOUSE
1468
	else if (!strcasecmp(input, "mouse"))
1469
	    s->toggle = USE_MOUSE;
1470
#endif
1471
	else if (!strcasecmp(input, "noconvert"))
1472
	    s->toggle = NO_CONVERT;
1473
	else if (!strcasecmp(input, "suspendenable"))
1474
	    s->toggle = SUSPEND;
1475
#endif /* !NANO_TINY */
1476
	else {
1477
1478
1479
1480
	    free(s);
	    return NULL;
	}
#ifndef NANO_TINY
1481
    }
1482
#endif
1483
1484
    return s;
}
1485

1486
/* Interpret a menu name and return the corresponding menu flag. */
1487
1488
1489
int strtomenu(char *input)
{
    if (!strcasecmp(input, "all"))
1490
	return (MMOST|MHELP|MYESNO);
1491
1492
1493
1494
1495
1496
1497
    else if (!strcasecmp(input, "main"))
	return MMAIN;
    else if (!strcasecmp(input, "search"))
	return MWHEREIS;
    else if (!strcasecmp(input, "replace"))
	return MREPLACE;
    else if (!strcasecmp(input, "replace2") ||
Benno Schulenberg's avatar
Benno Schulenberg committed
1498
	     !strcasecmp(input, "replacewith"))
1499
	return MREPLACEWITH;
1500
1501
1502
1503
1504
1505
1506
    else if (!strcasecmp(input, "gotoline"))
	return MGOTOLINE;
    else if (!strcasecmp(input, "writeout"))
	return MWRITEFILE;
    else if (!strcasecmp(input, "insert"))
	return MINSERTFILE;
    else if (!strcasecmp(input, "externalcmd") ||
Benno Schulenberg's avatar
Benno Schulenberg committed
1507
	     !strcasecmp(input, "extcmd"))
1508
	return MEXTCMD;
1509
#ifndef DISABLE_HELP
1510
1511
    else if (!strcasecmp(input, "help"))
	return MHELP;
1512
1513
#endif
#ifndef DISABLE_SPELLER
1514
1515
    else if (!strcasecmp(input, "spell"))
	return MSPELL;
1516
#endif
1517
1518
    else if (!strcasecmp(input, "linter"))
	return MLINTER;
1519
#ifndef DISABLE_BROWSER
1520
1521
1522
1523
1524
1525
    else if (!strcasecmp(input, "browser"))
	return MBROWSER;
    else if (!strcasecmp(input, "whereisfile"))
	return MWHEREISFILE;
    else if (!strcasecmp(input, "gotodir"))
	return MGOTODIR;
1526
#endif
1527
1528
    return -1;
}
1529
#endif /* !DISABLE_NANORC */
1530

Chris Allegretta's avatar
Chris Allegretta committed
1531

1532
1533
1534
#ifdef DEBUG
/* This function is used to gracefully return all the memory we've used.
 * It should be called just before calling exit().  Practically, the
1535
1536
 * 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
1537
1538
 * function unless debugging is turned on. */
void thanks_for_all_the_fish(void)
1539
{
1540
1541
1542
1543
    delwin(topwin);
    delwin(edit);
    delwin(bottomwin);

Chris Allegretta's avatar
Chris Allegretta committed
1544
1545
1546
#ifndef DISABLE_JUSTIFY
    if (quotestr != NULL)
	free(quotestr);
1547
1548
#ifdef HAVE_REGEX_H
    regfree(&quotereg);
1549
1550
    if (quoteerr != NULL)
	free(quoteerr);
1551
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1552
#endif
1553
#ifndef NANO_TINY
1554
1555
1556
    if (backup_dir != NULL)
        free(backup_dir);
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1557
#ifndef DISABLE_OPERATINGDIR
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
    if (operating_dir != NULL)
	free(operating_dir);
    if (full_operating_dir != NULL)
	free(full_operating_dir);
#endif
    if (last_search != NULL)
	free(last_search);
    if (last_replace != NULL)
	free(last_replace);
#ifndef DISABLE_SPELLER
    if (alt_speller != NULL)
	free(alt_speller);
1570
#endif
1571
1572
1573
    if (answer != NULL)
	free(answer);
    if (cutbuffer != NULL)
Chris Allegretta's avatar
Chris Allegretta committed
1574
	free_filestruct(cutbuffer);
1575
1576
1577
#ifndef DISABLE_JUSTIFY
    if (jusbuffer != NULL)
	free_filestruct(jusbuffer);
1578
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1579
    /* Free the memory associated with each open file buffer. */
1580
    if (openfile != NULL)
1581
	free_openfilestruct(openfile);
1582
#ifndef DISABLE_COLOR
1583
1584
    if (syntaxstr != NULL)
	free(syntaxstr);
Chris Allegretta's avatar
Chris Allegretta committed
1585
1586
1587
1588
1589
    while (syntaxes != NULL) {
	syntaxtype *bill = syntaxes;

	free(syntaxes->desc);
	while (syntaxes->extensions != NULL) {
1590
	    regexlisttype *bob = syntaxes->extensions;
Chris Allegretta's avatar
Chris Allegretta committed
1591
	    syntaxes->extensions = bob->next;
1592
	    free(bob->ext_regex);
1593
1594
1595
1596
	    if (bob->ext != NULL) {
		regfree(bob->ext);
		free(bob->ext);
	    }
Chris Allegretta's avatar
Chris Allegretta committed
1597
1598
	    free(bob);
	}
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
	while (syntaxes->headers != NULL) {
	    regexlisttype *bob = syntaxes->headers;
	    syntaxes->headers = bob->next;
	    free(bob->ext_regex);
	    if (bob->ext != NULL) {
		regfree(bob->ext);
		free(bob->ext);
	    }
	    free(bob);
	}
	while (syntaxes->magics != NULL) {
	    regexlisttype *bob = syntaxes->magics;
	    syntaxes->magics = bob->next;
	    free(bob->ext_regex);
	    if (bob->ext != NULL) {
		regfree(bob->ext);
		free(bob->ext);
	    }
	    free(bob);
	}
Chris Allegretta's avatar
Chris Allegretta committed
1619
1620
1621
1622
	while (syntaxes->color != NULL) {
	    colortype *bob = syntaxes->color;

	    syntaxes->color = bob->next;
1623
	    free(bob->start_regex);
1624
1625
1626
1627
	    if (bob->start != NULL) {
		regfree(bob->start);
		free(bob->start);
	    }
1628
1629
	    if (bob->end_regex != NULL)
		free(bob->end_regex);
1630
	    if (bob->end != NULL) {
1631
		regfree(bob->end);
1632
1633
		free(bob->end);
	    }
Chris Allegretta's avatar
Chris Allegretta committed
1634
1635
1636
1637
1638
	    free(bob);
	}
	syntaxes = syntaxes->next;
	free(bill);
    }
1639
#endif /* !DISABLE_COLOR */
1640
#ifndef DISABLE_HISTORIES
1641
    /* Free the search and replace history lists. */
1642
1643
1644
1645
    if (searchage != NULL)
	free_filestruct(searchage);
    if (replaceage != NULL)
	free_filestruct(replaceage);
1646
#endif
1647
1648
1649
1650
1651
1652
1653
    /* Free the functions and shortcuts lists. */
    while (allfuncs != NULL) {
        subnfunc *f = allfuncs;
        allfuncs = allfuncs->next;
        free(f);
    }
    while (sclist != NULL) {
1654
        sc *s = sclist;
1655
        sclist = sclist->next;
1656
        free(s);
1657
    }
1658
#ifndef DISABLE_NANORC
1659
1660
    if (homedir != NULL)
	free(homedir);
1661
#endif
1662
}
1663

1664
#endif /* DEBUG */