global.c 55.2 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
#ifndef DISABLE_WRAPJUSTIFY
42
43
ssize_t fill = 0;
	/* The column where we will wrap lines. */
44
ssize_t wrap_at = -CHARS_FROM_EOL;
45
46
47
48
49
50
51
52
53
54
	/* 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. */

55
unsigned flags[4] = {0, 0, 0, 0};
56
57
58
59
60
61
	/* 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;
62
	/* The middle portion of the window, i.e. the edit window, where
63
64
65
66
67
68
	 * 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? */
69
int maxrows = 0;
70
	/* How many usable lines there are (due to soft wrapping). */
71
72
73

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

85
86
87
88
89
90
#ifndef NANO_TINY
char *matchbrackets = NULL;
	/* The opening and closing brackets that can be found by bracket
	 * searches. */
#endif

91
#if !defined(NANO_TINY) && !defined(DISABLE_NANORC)
92
93
94
95
96
char *whitespace = NULL;
	/* The characters used when displaying the first characters of
	 * tabs and spaces. */
int whitespace_len[2];
	/* The length of these characters. */
97
98
#endif

99
#ifndef DISABLE_JUSTIFY
100
101
102
103
104
105
106
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(). */
107
#ifdef HAVE_REGEX_H
108
109
110
regex_t quotereg;
	/* The compiled regular expression from the quoting string. */
int quoterc;
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
111
	/* Whether it was compiled successfully. */
112
113
char *quoteerr = NULL;
	/* The error message, if it didn't. */
114
#else
115
116
size_t quotelen;
	/* The length of the quoting string in bytes. */
Chris Allegretta's avatar
Chris Allegretta committed
117
#endif
118
119
#endif

120
bool nodelay_mode = FALSE;
121
	/* Are we checking for a cancel wile doing something? */
122

123
char *answer = NULL;
124
	/* The answer string used by the statusbar prompt. */
Chris Allegretta's avatar
Chris Allegretta committed
125

126
127
128
ssize_t tabsize = -1;
	/* The width of a tab in spaces.  The default value is set in
	 * main(). */
129

130
131
132
#ifndef NANO_TINY
char *backup_dir = NULL;
	/* The directory where we store backup files. */
133

134
const char *locking_prefix = ".";
135
        /* Prefix of how to store the vim-style lock file. */
136
const char *locking_suffix = ".swp";
137
        /* Suffix of the vim-style lock file. */
138
#endif
139
#ifndef DISABLE_OPERATINGDIR
140
141
142
143
144
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. */
145
146
#endif

147
#ifndef DISABLE_SPELLER
148
149
char *alt_speller = NULL;
	/* The command to use for the alternate spell checker. */
150
151
#endif

152
#ifndef DISABLE_COLOR
153
syntaxtype *syntaxes = NULL;
154
	/* The global list of color syntaxes. */
155
char *syntaxstr = NULL;
156
	/* The color syntax name specified on the command line. */
157

158
159
#endif

160
bool edit_refresh_needed = 0;
161
	/* Did a command mangle enough of the buffer refresh that we
162
	 * should repaint the screen? */
163

164
165
const shortcut *currshortcut;
	/* The current shortcut list we're using. */
166
int currmenu;
167
	/* The currently loaded menu. */
168
169

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

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

197
/* Regular expressions. */
198
#ifdef HAVE_REGEX_H
199
200
201
202
203
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
204
#endif
205

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

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

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

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

235
/* Just throw this here. */
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
void case_sens_void(void)
{
}
void regexp_void(void)
{
}
void gototext_void(void)
{
}
void to_files_void(void)
{
}
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)
{
}
void backwards_void(void)
{
}
void goto_dir_void(void)
{
}
void no_replace_void(void)
{
}
void ext_cmd_void(void)
{
}

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

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

    if (allfuncs == NULL)
	allfuncs = f;
    else
	tailfunc->next = f;
    tailfunc = f;
304
305
306
307
308
309

    f->next = NULL;
    f->scfunc = func;
    f->menus = menus;
    f->desc = desc;
    f->viewok = viewok;
310
#ifndef DISABLE_HELP
311
312
313
314
315
    f->help = help;
    f->blank_after = blank_after;
#endif

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

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

326
327
328
    for (s = sclist; s != NULL; s = s->next)
	if ((s->menu & menu) && s->scfunc == func)
	    return s;
329

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


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

344
    if (sclist == NULL) {
345
	sclist = (sc *) nmalloc(sizeof(sc));
346
347
	s = sclist;
        s->next = NULL;
348
    } else {
349
350
351
352
353
354
355
356
357
358
359
360
	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;
        }
361
362
    }

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

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

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

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

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

    if (s)
        return s->seq;
    /* else */
    return defaultval;
}

399
400
/* Assign the info to the shortcut struct.
 * Assumes keystr is already assigned, naturally. */
401
402
403
404
405
406
407
408
409
410
411
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]);
412
    } else /* RAWINPUT */
413
        s->seq = (int) s->keystr[0];
414

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

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

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

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

480
481
/* Initialize the list of functions and the list of shortcuts. */
void shortcut_init(void)
482
{
483
    /* TRANSLATORS: Try to keep the next nine strings at most 10 characters. */
484
    const char *whereis_tag = N_("Where Is");
485
486
    const char *replace_tag = N_("Replace");
    const char *gotoline_tag = N_("Go To Line");
487
488
    const char *prev_line_tag = N_("Prev Line");
    const char *next_line_tag = N_("Next Line");
489
#ifndef DISABLE_JUSTIFY
490
    const char *fulljustify_tag = N_("FullJstify");
491
#endif
492
    const char *refresh_tag = N_("Refresh");
493
#ifndef DISABLE_SPELLER
494
    const char *spell_tag = N_("To Spell");
495
#endif
496
#ifndef DISABLE_COLOR
497
    const char *lint_tag = N_("To Linter");
498
    /* TRANSLATORS: Try to keep the next two strings at most 14 characters. */
499
500
    const char *prev_lint_tag = N_("Prev Lint Msg");
    const char *next_lint_tag = N_("Next Lint Msg");
501
#endif
502

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

David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
658
#ifndef DISABLE_HELP
659
#define IFSCHELP(help) help
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
660
#else
661
#define IFSCHELP(help) ""
662
#endif
663

664
665
    while (allfuncs != NULL) {
        subnfunc *f = allfuncs;
666
        allfuncs = allfuncs->next;
667
668
        free(f);
    }
669

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

672
    add_to_funcs(do_help_void, MMOST,
673
674
	/* 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
675

676
    add_to_funcs(do_cancel, ((MMOST & ~MMAIN & ~MBROWSER) | MYESNO),
677
	N_("Cancel"), IFSCHELP(nano_cancel_msg), FALSE, VIEW);
678

679
    add_to_funcs(do_exit, MMAIN,
680
	exit_tag, IFSCHELP(nano_exit_msg), FALSE, VIEW);
681
682
    /* Remember the entry for Exit, to be able to replace it with Close. */
    exitfunc = tailfunc;
Chris Allegretta's avatar
Chris Allegretta committed
683

684
#ifndef DISABLE_BROWSER
685
    add_to_funcs(do_exit, MBROWSER, exit_tag, IFSCHELP(nano_exitbrowser_msg), FALSE, VIEW);
686
#endif
Chris Allegretta's avatar
Chris Allegretta committed
687

688
    add_to_funcs(do_writeout_void, MMAIN, N_("Write Out"),
689
	IFSCHELP(nano_writeout_msg), FALSE, NOVIEW);
690

691
    /* We allow inserting files in view mode if multibuffers are
692
693
694
695
     * 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. */
696
    add_to_funcs(do_insertfile_void,
697
	MMAIN, N_("Read File"), IFSCHELP(nano_insert_msg), TRUE,
698
#ifndef DISABLE_MULTIBUFFER
699
	VIEW);
700
#else
701
	NOVIEW);
702
#endif
Chris Allegretta's avatar
Chris Allegretta committed
703

704
    add_to_funcs(do_search, MMAIN, whereis_tag,
705
	IFSCHELP(nano_whereis_msg), FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
706

707
708
709
710
    add_to_funcs(do_replace, MMAIN, replace_tag,
	IFSCHELP(nano_replace_msg), FALSE, NOVIEW);

#ifndef DISABLE_BROWSER
711
    add_to_funcs(do_search, MBROWSER, whereis_tag,
712
713
	IFSCHELP(nano_browser_whereis_msg), FALSE, VIEW);

714
715
    add_to_funcs(goto_dir_void, MBROWSER,
	N_("Go To Dir"), IFSCHELP(nano_gotodir_msg), TRUE, VIEW);
716
717
#endif

718
#ifndef DISABLE_HELP
719
720
    /* The description ("x") and blank_after (0) are irrelevant,
     * because the help viewer does not have a help text. */
721
    add_to_funcs(do_exit, MHELP, exit_tag, "x", 0, VIEW);
722

723
    add_to_funcs(total_refresh, MHELP, refresh_tag, "x", 0, VIEW);
724
725
726

    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);
727
728
#endif

729
    add_to_funcs(do_cut_text_void, MMAIN, N_("Cut Text"), IFSCHELP(nano_cut_msg),
730
	FALSE, NOVIEW);
Chris Allegretta's avatar
Chris Allegretta committed
731

732
    add_to_funcs(do_uncut_text, MMAIN, uncut_tag, IFSCHELP(nano_uncut_msg),
733
	TRUE, NOVIEW);
734
    /* Remember the entry for Uncut, to be able to replace it with Unjustify. */
735
    uncutfunc = tailfunc;
Chris Allegretta's avatar
Chris Allegretta committed
736

737
738
739
#ifndef DISABLE_JUSTIFY
    add_to_funcs(do_justify_void, MMAIN, N_("Justify"),
	nano_justify_msg, FALSE, NOVIEW);
Chris Allegretta's avatar
Chris Allegretta committed
740
#endif
Chris Allegretta's avatar
Chris Allegretta committed
741

742
#ifndef DISABLE_SPELLER
743
    add_to_funcs(do_spell, MMAIN, spell_tag, IFSCHELP(nano_spell_msg),
744
	FALSE, NOVIEW);
745
#endif
746

747
#ifndef DISABLE_COLOR
748
    add_to_funcs(do_linter, MMAIN, lint_tag, IFSCHELP(nano_lint_msg),
749
750
751
	TRUE, NOVIEW);
#endif

752
#ifndef NANO_TINY
753
    add_to_funcs(case_sens_void, MWHEREIS|MREPLACE,
754
755
756
757
	N_("Case Sens"), IFSCHELP(nano_case_msg), FALSE, VIEW);
#endif

#ifdef HAVE_REGEX_H
758
    add_to_funcs(regexp_void, MWHEREIS|MREPLACE,
759
760
761
762
	N_("Regexp"), IFSCHELP(nano_regexp_msg), FALSE, VIEW);
#endif

#ifndef NANO_TINY
763
    add_to_funcs(backwards_void, MWHEREIS|MREPLACE,
764
765
766
767
768
769
770
771
772
773
774
775
776
777
	N_("Backwards"), IFSCHELP(nano_reverse_msg), FALSE, VIEW);
#endif

    add_to_funcs(do_replace, MWHEREIS,
	replace_tag, IFSCHELP(nano_replace_msg), FALSE, VIEW);

    add_to_funcs(no_replace_void, MREPLACE,
	N_("No Replace"), IFSCHELP(nano_whereis_msg), FALSE, VIEW);

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

778
779
780
781
782
783
784
785
786
787
    add_to_funcs(do_cursorpos_void, MMAIN, N_("Cur Pos"),
	IFSCHELP(nano_cursorpos_msg), FALSE, VIEW);

    add_to_funcs(do_gotolinecolumn_void, MMAIN|MWHEREIS,
	gotoline_tag, IFSCHELP(nano_gotoline_msg), TRUE, VIEW);

    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);
788

789
    add_to_funcs(do_first_line,
790
	(MMAIN|MHELP|MWHEREIS|MREPLACE|MREPLACEWITH|MGOTOLINE),
791
	N_("First Line"), IFSCHELP(nano_firstline_msg), FALSE, VIEW);
792
    add_to_funcs(do_last_line,
793
	(MMAIN|MHELP|MWHEREIS|MREPLACE|MREPLACEWITH|MGOTOLINE),
794
	N_("Last Line"), IFSCHELP(nano_lastline_msg), TRUE, VIEW);
795

796
#ifndef NANO_TINY
797
798
799
800
801
802
    add_to_funcs(do_research, MMAIN, whereis_next_tag,
	IFSCHELP(nano_whereis_next_msg), FALSE, VIEW);

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

803
    add_to_funcs(do_mark, MMAIN, N_("Mark Text"),
804
	IFSCHELP(nano_mark_msg), FALSE, VIEW);
805

806
    add_to_funcs(do_copy_text, MMAIN, N_("Copy Text"),
807
	IFSCHELP(nano_copy_msg), TRUE, NOVIEW);
808

809
    add_to_funcs(do_indent_void, MMAIN, N_("Indent Text"),
810
	IFSCHELP(nano_indent_msg), FALSE, NOVIEW);
811
    add_to_funcs(do_unindent, MMAIN, N_("Unindent Text"),
812
	IFSCHELP(nano_unindent_msg), TRUE, NOVIEW);
813

814
    if (ISSET(UNDOABLE)) {
815
	add_to_funcs(do_undo, MMAIN, N_("Undo"),
816
	    IFSCHELP(nano_undo_msg), FALSE, NOVIEW);
817
	add_to_funcs(do_redo, MMAIN, N_("Redo"),
818
819
	    IFSCHELP(nano_redo_msg), TRUE, NOVIEW);
    }
820
#endif /* !NANO_TINY */
821

822
    add_to_funcs(do_left, MMAIN, N_("Back"), IFSCHELP(nano_back_msg),
823
	FALSE, VIEW);
824
825
    add_to_funcs(do_right, MMAIN, N_("Forward"), IFSCHELP(nano_forward_msg),
	FALSE, VIEW);
826
827

#ifndef DISABLE_BROWSER
828
    add_to_funcs(do_left, MBROWSER, N_("Back"), IFSCHELP(nano_backfile_msg),
829
	FALSE, VIEW);
830
831
    add_to_funcs(do_right, MBROWSER, N_("Forward"), IFSCHELP(nano_forwardfile_msg),
	FALSE, VIEW);
832
833
#endif

834
#ifndef NANO_TINY
835
    add_to_funcs(do_prev_word_void, MMAIN, N_("Prev Word"),
836
	IFSCHELP(nano_prevword_msg), FALSE, VIEW);
837
838
    add_to_funcs(do_next_word_void, MMAIN, N_("Next Word"),
	IFSCHELP(nano_nextword_msg), FALSE, VIEW);
839
#endif
840

841
842
843
844
845
    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);

846
    add_to_funcs(do_up_void, (MMAIN|MBROWSER), prev_line_tag,
847
	IFSCHELP(nano_prevline_msg), FALSE, VIEW);
848
    add_to_funcs(do_down_void, (MMAIN|MBROWSER), next_line_tag,
849
	IFSCHELP(nano_nextline_msg), TRUE, VIEW);
850

851
#ifndef DISABLE_JUSTIFY
852
    add_to_funcs(do_para_begin_void, (MMAIN|MWHEREIS), N_("Beg of Par"),
853
	IFSCHELP(nano_parabegin_msg), FALSE, VIEW);
854
    add_to_funcs(do_para_end_void, (MMAIN|MWHEREIS), N_("End of Par"),
855
	IFSCHELP(nano_paraend_msg), FALSE, VIEW);
856
#endif
857

858
#ifndef NANO_TINY
859
    add_to_funcs(do_scroll_up, MMAIN, N_("Scroll Up"),
860
	IFSCHELP(nano_scrollup_msg), FALSE, VIEW);
861
    add_to_funcs(do_scroll_down, MMAIN, N_("Scroll Down"),
862
	IFSCHELP(nano_scrolldown_msg), TRUE, VIEW);
863
864
#endif

865
#ifndef DISABLE_MULTIBUFFER
866
    add_to_funcs(switch_to_prev_buffer_void, MMAIN, N_("Prev File"),
867
	IFSCHELP(nano_prevfile_msg), FALSE, VIEW);
868
    add_to_funcs(switch_to_next_buffer_void, MMAIN, N_("Next File"),
869
	IFSCHELP(nano_nextfile_msg), TRUE, VIEW);
870
871
#endif

872
    add_to_funcs(do_verbatim_input, MMAIN, N_("Verbatim"),
873
	IFSCHELP(nano_verbatim_msg), FALSE, NOVIEW);
874

875
    add_to_funcs(do_tab, MMAIN, N_("Tab"), IFSCHELP(nano_tab_msg),
876
	FALSE, NOVIEW);
877
    add_to_funcs(do_enter_void, MMAIN, N_("Enter"), IFSCHELP(nano_enter_msg),
878
	FALSE, NOVIEW);
879
    add_to_funcs(do_delete, MMAIN, N_("Delete"), IFSCHELP(nano_delete_msg),
880
	FALSE, NOVIEW);
881
    add_to_funcs(do_backspace, MMAIN, N_("Backspace"), IFSCHELP(nano_backspace_msg),
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
882
#ifndef NANO_TINY
883
	FALSE,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
884
#else
885
	TRUE,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
886
#endif
887
888
	NOVIEW);

889
#ifndef NANO_TINY
890
    add_to_funcs(do_cut_till_end, MMAIN, N_("CutTillEnd"),
891
	IFSCHELP(nano_cut_till_end_msg), TRUE, NOVIEW);
892
#endif
Chris Allegretta's avatar
Chris Allegretta committed
893

894
#ifndef DISABLE_JUSTIFY
895
    add_to_funcs(do_full_justify, MMAIN, fulljustify_tag,
896
	IFSCHELP(nano_fulljustify_msg), FALSE, NOVIEW);
897
898
#endif

899
#ifndef NANO_TINY
900
    add_to_funcs(do_wordlinechar_count, MMAIN, N_("Word Count"),
901
	IFSCHELP(nano_wordcount_msg), FALSE, VIEW);
902
#endif
903

904
    add_to_funcs(total_refresh, MMAIN, refresh_tag,
905
906
	IFSCHELP(nano_refresh_msg), FALSE, VIEW);

907
    add_to_funcs(do_suspend_void, MMAIN, N_("Suspend"),
908
	IFSCHELP(nano_suspend_msg), TRUE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
909

910
#ifndef NANO_TINY
911
    add_to_funcs(get_history_older_void,
912
	(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE),
913
	N_("PrevHstory"), IFSCHELP(nano_prev_history_msg), FALSE, VIEW);
914

915
    add_to_funcs(get_history_newer_void,
916
	(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE),
917
	N_("NextHstory"), IFSCHELP(nano_next_history_msg), FALSE, VIEW);
918
#endif
919

920
    add_to_funcs(gototext_void, MGOTOLINE,
921
	N_("Go To Text"), IFSCHELP(nano_whereis_msg), TRUE, VIEW);
922

923
#ifndef NANO_TINY
924
925
926
927
928
929
    /* 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. */
930
    if (!ISSET(RESTRICTED)) {
931
        add_to_funcs(dos_format_void, MWRITEFILE,
932
            N_("DOS Format"), IFSCHELP(nano_dos_msg), FALSE, NOVIEW);
933

934
        add_to_funcs(mac_format_void, MWRITEFILE,
935
            N_("Mac Format"), IFSCHELP(nano_mac_msg), FALSE, NOVIEW);
936

Benno Schulenberg's avatar
Benno Schulenberg committed
937
        add_to_funcs(append_void, MWRITEFILE,
938
            N_("Append"), IFSCHELP(nano_append_msg), FALSE, NOVIEW);
Benno Schulenberg's avatar
Benno Schulenberg committed
939
        add_to_funcs(prepend_void, MWRITEFILE,
940
            N_("Prepend"), IFSCHELP(nano_prepend_msg), FALSE, NOVIEW);
941

Benno Schulenberg's avatar
Benno Schulenberg committed
942
        add_to_funcs(backup_file_void, MWRITEFILE,
943
            N_("Backup File"), IFSCHELP(nano_backup_msg), FALSE, NOVIEW);
944
    }
945

946
947
948
    /* If we're using restricted mode, file insertion is disabled, and
     * thus command execution and the multibuffer toggle have no place. */
    if (!ISSET(RESTRICTED)) {
Benno Schulenberg's avatar
Benno Schulenberg committed
949
        add_to_funcs(ext_cmd_void, MINSERTFILE,
950
	    N_("Execute Command"), IFSCHELP(nano_execute_msg), FALSE, NOVIEW);
951

952
#ifndef DISABLE_MULTIBUFFER
953
	add_to_funcs(new_buffer_void, MINSERTFILE|MEXTCMD,
954
	    N_("New Buffer"), IFSCHELP(nano_multibuffer_msg), FALSE, NOVIEW);
955
#endif
956
    }
957
#endif /* !NANO_TINY */
958

959
#ifndef DISABLE_BROWSER
960
961
962
963
    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
964
    add_to_funcs(do_first_file, (MBROWSER|MWHEREISFILE),
965
	N_("First File"), IFSCHELP(nano_firstfile_msg), FALSE, VIEW);
Benno Schulenberg's avatar
Benno Schulenberg committed
966
    add_to_funcs(do_last_file, (MBROWSER|MWHEREISFILE),
967
	N_("Last File"), IFSCHELP(nano_lastfile_msg), FALSE, VIEW);
968
#endif
Chris Allegretta's avatar
Chris Allegretta committed
969

970
971
972
973
974
975
976
977
978
979
#if !defined(NANO_TINY) && !defined(DISABLE_BROWSER)
    add_to_funcs(do_research, MBROWSER, whereis_next_tag,
	IFSCHELP(nano_whereis_next_msg), FALSE, VIEW);
#endif

#ifndef DISABLE_COLOR
    add_to_funcs(do_page_up, MLINTER,
	prev_lint_tag, IFSCHELP(nano_prevlint_msg), FALSE, VIEW);
    add_to_funcs(do_page_down, MLINTER,
	next_lint_tag, IFSCHELP(nano_nextlint_msg), FALSE, VIEW);
980
981
#endif

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

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

1091
#ifndef NANO_TINY
1092
    /* Group of "Appearance" toggles. */
1093
1094
1095
1096
    add_to_sclist(MMAIN, "M-X", do_toggle_void, NO_HELP, TRUE);
    add_to_sclist(MMAIN, "M-C", do_toggle_void, CONST_UPDATE, TRUE);
    add_to_sclist(MMAIN, "M-O", do_toggle_void, MORE_SPACE, TRUE);
    add_to_sclist(MMAIN, "M-S", do_toggle_void, SMOOTH_SCROLL, TRUE);
1097
    add_to_sclist(MMAIN, "M-$", do_toggle_void, SOFTWRAP, TRUE);
1098
    add_to_sclist(MMAIN, "M-P", do_toggle_void, WHITESPACE_DISPLAY, TRUE);
1099
#ifndef DISABLE_COLOR
1100
    add_to_sclist(MMAIN, "M-Y", do_toggle_void, NO_COLOR_SYNTAX, TRUE);
1101
#endif
1102

1103
    /* Group of "Editing-behavior" toggles. */
1104
1105
1106
    add_to_sclist(MMAIN, "M-H", do_toggle_void, SMART_HOME, TRUE);
    add_to_sclist(MMAIN, "M-I", do_toggle_void, AUTOINDENT, TRUE);
    add_to_sclist(MMAIN, "M-K", do_toggle_void, CUT_TO_END, TRUE);
1107
#ifndef DISABLE_WRAPPING
1108
    add_to_sclist(MMAIN, "M-L", do_toggle_void, NO_WRAP, TRUE);
1109
#endif
1110
    add_to_sclist(MMAIN, "M-Q", do_toggle_void, TABS_TO_SPACES, TRUE);
1111

1112
    /* Group of "Peripheral-feature" toggles. */
1113
    add_to_sclist(MMAIN, "M-B", do_toggle_void, BACKUP_FILE, TRUE);
1114
#ifndef DISABLE_MULTIBUFFER
1115
    add_to_sclist(MMAIN, "M-F", do_toggle_void, MULTIBUFFER, TRUE);
1116
1117
#endif
#ifndef DISABLE_MOUSE
1118
    add_to_sclist(MMAIN, "M-M", do_toggle_void, USE_MOUSE, TRUE);
1119
#endif
1120
1121
    add_to_sclist(MMAIN, "M-N", do_toggle_void, NO_CONVERT, TRUE);
    add_to_sclist(MMAIN, "M-Z", do_toggle_void, SUSPEND, TRUE);
1122
#endif /* !NANO_TINY */
Benno Schulenberg's avatar
Benno Schulenberg committed
1123

1124
1125
1126
    add_to_sclist(MMAIN, "^Q", xon_complaint, 0, TRUE);
    add_to_sclist(MMAIN, "^S", xoff_complaint, 0, TRUE);

1127
    add_to_sclist(((MMOST & ~MMAIN & ~MBROWSER) | MYESNO), "^C", do_cancel, 0, FALSE);
1128

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

1175
1176
#ifdef DEBUG
    print_sclist();
Chris Allegretta's avatar
Chris Allegretta committed
1177
#endif
1178
}
1179

1180
#ifndef DISABLE_COLOR
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
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

1196
const subnfunc *sctofunc(sc *s)
1197
{
1198
    subnfunc *f;
1199

1200
1201
    for (f = allfuncs; f != NULL && s->scfunc != f->scfunc; f = f->next)
	;
1202

1203
    return f;
1204
1205
}

1206
#ifndef NANO_TINY
1207
1208
/* Now let's come up with a single (hopefully) function to get a string
 * for each flag. */
1209
const char *flagtostr(int flag)
1210
{
1211
1212
   switch (flag) {
        case NO_HELP:
1213
1214
            /* TRANSLATORS: The next seventeen strings are toggle descriptions;
             * they are best kept shorter than 40 characters, but may be longer. */
1215
1216
1217
1218
1219
1220
1221
            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");
1222
1223
        case SOFTWRAP:
            return N_("Soft wrapping of overlong lines");
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
        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:
1235
            return N_("Hard wrapping of overlong lines");
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
        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 "?????";
    }
}
1252
#endif /* !NANO_TINY */
1253

1254
1255
1256
/* Interpret a function string given in the rc file, and return a
 * shortcut struct, complete with the proper value for execute. */
sc *strtosc(char *input)
1257
{
1258
    sc *s;
1259
1260

    s = (sc *)nmalloc(sizeof(sc));
1261
    s->execute = TRUE; /* will be overridden as needed below */
1262

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

1524
#ifndef DISABLE_NANORC
1525
/* Same thing as above but for the menu. */
1526
1527
1528
int strtomenu(char *input)
{
    if (!strcasecmp(input, "all"))
1529
	return (MMOST|MHELP|MYESNO);
1530
1531
1532
1533
1534
1535
1536
    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
1537
	     !strcasecmp(input, "replacewith"))
1538
	return MREPLACEWITH;
1539
1540
1541
1542
1543
1544
1545
    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
1546
	     !strcasecmp(input, "extcmd"))
1547
1548
1549
1550
1551
	return MEXTCMD;
    else if (!strcasecmp(input, "help"))
	return MHELP;
    else if (!strcasecmp(input, "spell"))
	return MSPELL;
1552
1553
    else if (!strcasecmp(input, "linter"))
	return MLINTER;
1554
1555
1556
1557
1558
1559
1560
1561
1562
    else if (!strcasecmp(input, "browser"))
	return MBROWSER;
    else if (!strcasecmp(input, "whereisfile"))
	return MWHEREISFILE;
    else if (!strcasecmp(input, "gotodir"))
	return MGOTODIR;

    return -1;
}
1563
1564
#endif

Chris Allegretta's avatar
Chris Allegretta committed
1565

1566
1567
1568
#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
1569
1570
 * 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
1571
1572
 * function unless debugging is turned on. */
void thanks_for_all_the_fish(void)
1573
{
1574
1575
1576
1577
    delwin(topwin);
    delwin(edit);
    delwin(bottomwin);

Chris Allegretta's avatar
Chris Allegretta committed
1578
1579
1580
#ifndef DISABLE_JUSTIFY
    if (quotestr != NULL)
	free(quotestr);
1581
1582
#ifdef HAVE_REGEX_H
    regfree(&quotereg);
1583
1584
    if (quoteerr != NULL)
	free(quoteerr);
1585
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1586
#endif
1587
#ifndef NANO_TINY
1588
1589
1590
    if (backup_dir != NULL)
        free(backup_dir);
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1591
#ifndef DISABLE_OPERATINGDIR
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
    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);
1604
#endif
1605
1606
1607
    if (answer != NULL)
	free(answer);
    if (cutbuffer != NULL)
Chris Allegretta's avatar
Chris Allegretta committed
1608
	free_filestruct(cutbuffer);
1609
1610
1611
#ifndef DISABLE_JUSTIFY
    if (jusbuffer != NULL)
	free_filestruct(jusbuffer);
1612
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1613
    /* Free the memory associated with each open file buffer. */
1614
    if (openfile != NULL)
1615
	free_openfilestruct(openfile);
1616
#ifndef DISABLE_COLOR
1617
1618
    if (syntaxstr != NULL)
	free(syntaxstr);
Chris Allegretta's avatar
Chris Allegretta committed
1619
1620
1621
1622
1623
    while (syntaxes != NULL) {
	syntaxtype *bill = syntaxes;

	free(syntaxes->desc);
	while (syntaxes->extensions != NULL) {
1624
	    regexlisttype *bob = syntaxes->extensions;
Chris Allegretta's avatar
Chris Allegretta committed
1625
	    syntaxes->extensions = bob->next;
1626
	    free(bob->ext_regex);
1627
1628
1629
1630
	    if (bob->ext != NULL) {
		regfree(bob->ext);
		free(bob->ext);
	    }
Chris Allegretta's avatar
Chris Allegretta committed
1631
1632
	    free(bob);
	}
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
	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
1653
1654
1655
1656
	while (syntaxes->color != NULL) {
	    colortype *bob = syntaxes->color;

	    syntaxes->color = bob->next;
1657
	    free(bob->start_regex);
1658
1659
1660
1661
	    if (bob->start != NULL) {
		regfree(bob->start);
		free(bob->start);
	    }
1662
1663
	    if (bob->end_regex != NULL)
		free(bob->end_regex);
1664
	    if (bob->end != NULL) {
1665
		regfree(bob->end);
1666
1667
		free(bob->end);
	    }
Chris Allegretta's avatar
Chris Allegretta committed
1668
1669
1670
1671
1672
	    free(bob);
	}
	syntaxes = syntaxes->next;
	free(bill);
    }
1673
#endif /* !DISABLE_COLOR */
1674
#ifndef NANO_TINY
1675
    /* Free the search and replace history lists. */
1676
1677
1678
1679
    if (searchage != NULL)
	free_filestruct(searchage);
    if (replaceage != NULL)
	free_filestruct(replaceage);
1680
#endif
1681
1682
1683
1684
1685
1686
1687
    /* Free the functions and shortcuts lists. */
    while (allfuncs != NULL) {
        subnfunc *f = allfuncs;
        allfuncs = allfuncs->next;
        free(f);
    }
    while (sclist != NULL) {
1688
        sc *s = sclist;
1689
        sclist = sclist->next;
1690
        free(s);
1691
    }
1692
#ifndef DISABLE_NANORC
1693
1694
    if (homedir != NULL)
	free(homedir);
1695
#endif
1696
}
1697

1698
#endif /* DEBUG */