global.c 58.3 KB
Newer Older
1
/* $Id$ */
Chris Allegretta's avatar
Chris Allegretta committed
2
3
4
/**************************************************************************
 *   global.c                                                             *
 *                                                                        *
5
6
 *   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,  *
 *   2008, 2009 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(ENABLE_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
121
122
bool nodelay_mode = FALSE;
	/* Are we in nodelay mode (checking for a cancel wile doing something */

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
#ifdef ENABLE_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
	/* New shortcut key struct. */
171
subnfunc *allfuncs = NULL;
172
	/* New struct for the function list. */
173

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

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

200
201
int reverse_attr = A_REVERSE;
	/* The curses attribute we use for reverse video. */
202

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

206
/* Return the number of entries in the shortcut list for a given menu. */
207
size_t length_of_list(int menu)
208
{
209
    subnfunc *f;
210
    size_t i = 0;
211

212
    for (f = allfuncs; f != NULL; f = f->next)
213
214
215
216
217
        if ((f->menus & menu) != 0
#ifndef DISABLE_HELP
	    && strlen(f->help) > 0
#endif
	                          ) {
218
219
	    i++;
	}
220
221
222
    return i;
}

223
/* Just throw this here. */
224
225
226
227
228
229
230
231
232
233
234
235
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
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)
{
}

267
/* Set type of function based on the string. */
268
function_type strtokeytype(const char *str)
269
{
270
    if (str[0] ==  'M' || str[0] == 'm')
271
        return META;
272
    else if (str[0] == '^')
273
        return CONTROL;
274
    else if (str[0] ==  'F' || str[0] == 'f')
275
        return FKEY;
276
    else
277
	return RAWINPUT;
278
279
}

280
281
/* Add a string to the new function list struct.
 * Does not allow updates, not yet anyway. */
282
void add_to_funcs(void (*func)(void), int menus, const char *desc, const char *help,
283
284
285
286
287
    bool blank_after, bool viewok)
{
    subnfunc *f;

    if (allfuncs == NULL) {
288
	allfuncs = (subnfunc *) nmalloc(sizeof(subnfunc));
289
290
291
292
293
294
295
296
297
298
299
300
	f = allfuncs;
    } else {
	for (f = allfuncs; f->next != NULL; f = f->next)
		;
        f->next = (subnfunc *)nmalloc(sizeof(subnfunc));
        f = f->next;
    }
    f->next = NULL;
    f->scfunc = func;
    f->menus = menus;
    f->desc = desc;
    f->viewok = viewok;
301
#ifndef DISABLE_HELP
302
303
304
305
306
    f->help = help;
    f->blank_after = blank_after;
#endif

#ifdef DEBUG
307
    fprintf(stderr, "Added func \"%s\"\n", f->desc);
308
#endif
309
310
}

311
312
const sc *first_sc_for(int menu, void (*func)(void))
{
313
    const sc *s;
314
    const sc *fkeysc = NULL;
315
    const sc *metasc = NULL;
316
    const sc *rawsc = NULL;
317
318
319

    for (s = sclist; s != NULL; s = s->next) {
	if ((s->menu & menu) && s->scfunc == func) {
320
321
322
323
324
325
326
327
328
329
330
331
	    /* Try to use function keys and meta sequences as last
	     * resorts.  Otherwise, we will run into problems when we
	     * try and handle things like the arrow keys, Home, etc., if
	     * for some reason the user bound them to a function key or
	     * meta sequence first *shrug*. */
	    if (s->type == FKEY) {
		if (!fkeysc)
		    fkeysc = s;
		continue;
	    } else if (s->type == META) {
		if (!metasc)
		    metasc = s;
332
		continue;
333
334
335
336
	    } else if (s->type == RAWINPUT) {
		if (!rawsc)
		    rawsc = s;
		continue;
337
338
339
	    }

	    /* Otherwise, it was something else, so use it. */
340
341
342
343
	    return s;
	}
    }

344
345
346
    /* If we're here, we may have found only function keys or meta
     * sequences.  If so, use one, with the same priority as in the
     * help browser: function keys come first, unless meta sequences are
347
348
     * available, in which case meta sequences come first. Last choice
     * is the raw key. */
349
350
351
    if (fkeysc && !metasc)
	return fkeysc;
    else if (metasc)
352
	return metasc;
353
354
    else if (rawsc)
	return rawsc;
355

356
#ifdef DEBUG
Chris Allegretta's avatar
Chris Allegretta committed
357
    fprintf(stderr, "Whoops, returning null given func %ld in menu %d\n", (long) func, menu);
358
359
360
361
362
363
#endif
    /* Otherwise... */
    return NULL;
}


364
365
/* Add a string to the new shortcut list implementation.
 * Allows updates to existing entries in the list. */
366
void add_to_sclist(int menu, const char *scstring, void (*func)(void), int toggle, int execute)
Chris Allegretta's avatar
Chris Allegretta committed
367
{
368
    sc *s;
369

370
    if (sclist == NULL) {
371
	sclist = (sc *) nmalloc(sizeof(sc));
372
373
	s = sclist;
        s->next = NULL;
374
    } else {
375
376
377
378
379
380
381
382
383
384
385
386
	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;
        }
387
388
    }

389
390
391
    s->type = strtokeytype(scstring);
    s->menu = menu;
    s->toggle = toggle;
392
    s->keystr = (char *) scstring;
393
394
395
396
397
398
399
400
    s->scfunc = func;
    s->execute = execute;
    assign_keyinfo(s);

#ifdef DEBUG
    fprintf(stderr, "list val = %d\n", (int) s->menu);
    fprintf(stderr, "Hey, set sequence to %d for shortcut \"%s\"\n", s->seq, scstring);
#endif
Chris Allegretta's avatar
Chris Allegretta committed
401
402
}

403

404
/* Assign one menu's shortcuts to another function. */
405
406
407
408
409
410
411
412
413
414
415
416
417
418
void replace_scs_for(void (*oldfunc)(void), void (*newfunc)(void))
{
    sc *s;

    if (sclist == NULL)
	return;

    for (s = sclist; s->next != NULL; s = s->next)
	if (s->scfunc == oldfunc) {
	    s->scfunc = newfunc;
	}
}


Chris Allegretta's avatar
Chris Allegretta committed
419
/* Return the given menu's first shortcut sequence, or the default value
420
 * (2nd arg).  Assumes currmenu for the menu to check. */
421
int sc_seq_or (void (*func)(void), int defaultval)
Chris Allegretta's avatar
Chris Allegretta committed
422
423
424
425
426
427
428
429
430
431
{
    const sc *s = first_sc_for(currmenu, func);

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

}

432
433
/* Assign the info to the shortcut struct.
 * Assumes keystr is already assigned, naturally. */
434
435
436
437
438
439
440
441
442
443
444
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]);
445
    } else /* RAWINPUT */
446
        s->seq = (int) s->keystr[0];
447

448
    /* Override some keys which don't bind as nicely as we'd like. */
449
450
451
452
    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) ' ';
453
    else if (s->type == RAWINPUT && (!strcasecmp(s->keystr, "kup")))
454
	s->seq = KEY_UP;
455
    else if (s->type == RAWINPUT && (!strcasecmp(s->keystr, "kdown")))
456
	s->seq = KEY_DOWN;
457
    else if (s->type == RAWINPUT && (!strcasecmp(s->keystr, "kleft")))
458
	s->seq = KEY_LEFT;
459
    else if (s->type == RAWINPUT && (!strcasecmp(s->keystr, "kright")))
460
	s->seq = KEY_RIGHT;
461
    else if (s->type == RAWINPUT && (!strcasecmp(s->keystr, "kinsert")))
462
	s->seq = KEY_IC;
463
    else if (s->type == RAWINPUT && (!strcasecmp(s->keystr, "kdel")))
464
	s->seq = KEY_DC;
465
    else if (s->type == RAWINPUT && (!strcasecmp(s->keystr, "kbsp")))
466
	s->seq = KEY_BACKSPACE;
467
    else if (s->type == RAWINPUT && (!strcasecmp(s->keystr, "kenter")))
468
	s->seq = KEY_ENTER;
469
    else if (s->type == RAWINPUT && (!strcasecmp(s->keystr, "kpup")))
470
	s->seq = KEY_PPAGE;
471
    else if (s->type == RAWINPUT && (!strcasecmp(s->keystr, "kpdown")))
472
473
	s->seq = KEY_NPAGE;
#ifdef KEY_HOME
474
    else if (s->type == RAWINPUT && (!strcasecmp(s->keystr, "khome")))
475
476
477
	s->seq = KEY_HOME;
#endif
#ifdef KEY_END
478
    else if (s->type == RAWINPUT && (!strcasecmp(s->keystr, "kend")))
479
480
	s->seq = KEY_END;
#endif
481

482
483
484
485
486
487
488
489
490
491
492
}

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

    for (s = sclist; s->next != NULL; s = s->next) {
	f = sctofunc(s);
        if (f)
Chris Allegretta's avatar
Chris Allegretta committed
493
	    fprintf(stderr, "Shortcut \"%s\", function: %s, menus %d\n",  s->keystr, f->desc, f->menus);
494
495
496
497
498
499
500
	else
	    fprintf(stderr, "Hmm, didnt find a func for \"%s\"\n", s->keystr);
    }
}
#endif


501
502
/* Stuff we need to make at least static here so we can access it below. */
/* TRANSLATORS: Try to keep the next six strings at most 10 characters. */
503
const char *cancel_msg = N_("Cancel");
504
505
const char *replace_msg = N_("Replace");
const char *no_replace_msg = N_("No Replace");
506
507
508
509
510
511
512
513
514
515

#ifndef NANO_TINY
const char *case_sens_msg = N_("Case Sens");
const char *backwards_msg = N_("Backwards");
#endif

#ifdef HAVE_REGEX_H
const char *regexp_msg = N_("Regexp");
#endif

516
/* Stuff we want to just stun out if we're in TINY mode. */
517
518
#ifdef NANO_TINY
const char *gototext_msg = "";
Chris Allegretta's avatar
Chris Allegretta committed
519
520
const char *do_para_begin_msg = "";
const char *do_para_end_msg = "";
521
522
523
524
525
526
527
528
529
const char *case_sens_msg = "";
const char *backwards_msg = "";
const char *do_cut_till_end = "";
const char *dos_format_msg = "";
const char *mac_format_msg = "";
const char *append_msg = "";
const char *prepend_msg = "";
const char *backup_file_msg = "";
const char *to_files_msg = "";
Chris Allegretta's avatar
Chris Allegretta committed
530
531
532
533
534
const char *first_file_msg = "";
const char *whereis_next_msg = "";
const char *last_file_msg = "";
const char *new_buffer_msg = "";
const char *goto_dir_msg;
535
const char *ext_cmd_msg = "";
Chris Allegretta's avatar
Chris Allegretta committed
536
537

#else
538
/* TRANSLATORS: Try to keep the next three strings at most 10 characters. */
Chris Allegretta's avatar
Chris Allegretta committed
539
const char *prev_history_msg = N_("PrevHstory");
540
541
const char *next_history_msg = N_("NextHstory");
const char *gototext_msg = N_("Go To Text");
542
/* TRANSLATORS: Try to keep the next three strings at most 12 characters. */
Chris Allegretta's avatar
Chris Allegretta committed
543
const char *whereis_next_msg = N_("WhereIs Next");
544
545
546
#ifndef DISABLE_BROWSER
const char *first_file_msg = N_("First File");
const char *last_file_msg = N_("Last File");
547
548
/* TRANSLATORS: Try to keep the next nine strings at most 16 characters. */
const char *to_files_msg = N_("To Files");
549
550
551
552
553
554
#endif
const char *dos_format_msg = N_("DOS Format");
const char *mac_format_msg = N_("Mac Format");
const char *append_msg = N_("Append");
const char *prepend_msg = N_("Prepend");
const char *backup_file_msg = N_("Backup File");
555
const char *ext_cmd_msg = N_("Execute Command");
556
557
558
#ifdef ENABLE_MULTIBUFFER
const char *new_buffer_msg = N_("New Buffer");
#endif
Chris Allegretta's avatar
Chris Allegretta committed
559
const char *goto_dir_msg = N_("Go To Dir");
560

Chris Allegretta's avatar
Chris Allegretta committed
561
#endif /* NANO_TINY */
562

563
564
/* Initialize all shortcut lists.  If unjustify is TRUE, replace
 * the Uncut shortcut in the main shortcut list with UnJustify. */
565
void shortcut_init(bool unjustify)
566
{
567
    /* TRANSLATORS: Try to keep the following strings at most 10 characters. */
568
569
    const char *get_help_msg = N_("Get Help");
    const char *exit_msg = N_("Exit");
570
    const char *whereis_msg = N_("Where Is");
571
572
573
574
    const char *prev_page_msg = N_("Prev Page");
    const char *next_page_msg = N_("Next Page");
    const char *first_line_msg = N_("First Line");
    const char *last_line_msg = N_("Last Line");
575
    const char *suspend_msg = N_("Suspend");
576
577
578
579
580
#ifndef DISABLE_JUSTIFY
    const char *beg_of_par_msg = N_("Beg of Par");
    const char *end_of_par_msg = N_("End of Par");
    const char *fulljstify_msg = N_("FullJstify");
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
581
    const char *refresh_msg = N_("Refresh");
582
#ifndef NANO_TINY
583
    const char *insert_file_msg =  N_("Insert File");
584
#endif
Chris Allegretta's avatar
Chris Allegretta committed
585
    const char *go_to_line_msg = N_("Go To Line");
586
587
588
589
590
591
592
593
    const char *spell_msg = N_("To Spell");
#ifdef ENABLE_COLOR
    const char *lint_msg = N_("To Linter");
    const char *nano_lint_msg =
	N_("Invoke the linter, if available");
    const char *prev_lint_msg = N_("Prev Lint Msg");
    const char *next_lint_msg = N_("Next Lint Msg");
#endif
594

595
#ifndef DISABLE_JUSTIFY
596
597
    /* TRANSLATORS: The next long series of strings are shortcut descriptions;
     * they are best kept shorter than 56 characters, but may be longer. */
598
599
    const char *nano_justify_msg = N_("Justify the current paragraph");
#endif
600
#ifndef DISABLE_HELP
601
    const char *nano_cancel_msg = N_("Cancel the current function");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
602
    const char *nano_help_msg = N_("Display this help text");
603
    const char *nano_exit_msg =
604
#ifdef ENABLE_MULTIBUFFER
605
	N_("Close the current file buffer / Exit from nano")
606
#else
607
	N_("Exit from nano")
608
609
#endif
	;
610
611
    const char *nano_writeout_msg =
	N_("Write the current file to disk");
612
613
    const char *nano_insert_msg =
	N_("Insert another file into the current one");
614
    const char *nano_whereis_msg =
615
	N_("Search for a string or a regular expression");
616
617
    const char *nano_browser_whereis_msg =
	N_("Search for a string");
618
619
    const char *nano_prevpage_msg = N_("Go to previous screen");
    const char *nano_nextpage_msg = N_("Go to next screen");
620
621
622
623
    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");
624
    const char *nano_cursorpos_msg =
625
	N_("Display the position of the cursor");
626
627
    const char *nano_spell_msg =
	N_("Invoke the spell checker, if available");
628
629
    const char *nano_replace_msg =
	N_("Replace a string or a regular expression");
630
     const char *nano_gotoline_msg = N_("Go to line and column number");
631
#ifndef NANO_TINY
632
633
    const char *nano_mark_msg = N_("Mark text at the cursor position");
    const char *nano_whereis_next_msg = N_("Repeat last search");
634
635
    const char *nano_copy_msg =
	N_("Copy the current line and store it in the cutbuffer");
636
637
    const char *nano_indent_msg = N_("Indent the current line");
    const char *nano_unindent_msg = N_("Unindent the current line");
638
639
    const char *nano_undo_msg = N_("Undo the last operation");
    const char *nano_redo_msg = N_("Redo the last undone operation");
640
#endif
641
642
    const char *nano_forward_msg = N_("Go forward one character");
    const char *nano_back_msg = N_("Go back one character");
643
#ifndef NANO_TINY
644
645
    const char *nano_nextword_msg = N_("Go forward one word");
    const char *nano_prevword_msg = N_("Go back one word");
646
#endif
647
648
649
650
    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");
651
652
#ifndef DISABLE_JUSTIFY
    const char *nano_parabegin_msg =
653
	N_("Go to beginning of paragraph; then of previous paragraph");
654
    const char *nano_paraend_msg =
655
	N_("Go just beyond end of paragraph; then of next paragraph");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
656
657
#endif
    const char *nano_firstline_msg =
658
	N_("Go to the first line of the file");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
659
    const char *nano_lastline_msg =
660
	N_("Go to the last line of the file");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
661
#ifndef NANO_TINY
662
    const char *nano_bracket_msg = N_("Go to the matching bracket");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
663
664
665
666
    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");
667
#endif
668
#ifdef ENABLE_MULTIBUFFER
669
    const char *nano_prevfile_msg =
670
	N_("Switch to the previous file buffer");
671
    const char *nano_nextfile_msg =
672
	N_("Switch to the next file buffer");
673
#endif
674
    const char *nano_verbatim_msg =
675
	N_("Insert the next keystroke verbatim");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
676
    const char *nano_tab_msg =
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
677
	N_("Insert a tab at the cursor position");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
678
    const char *nano_enter_msg =
679
	N_("Insert a newline at the cursor position");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
680
681
682
683
    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");
684
#ifndef NANO_TINY
685
686
687
    const char *nano_cut_till_end_msg =
	N_("Cut from the cursor position to the end of the file");
#endif
688
689
#ifndef DISABLE_JUSTIFY
    const char *nano_fulljustify_msg = N_("Justify the entire file");
690
#endif
691
#ifndef NANO_TINY
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
692
693
    const char *nano_wordcount_msg =
	N_("Count the number of words, lines, and characters");
694
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
695
696
    const char *nano_refresh_msg =
	N_("Refresh (redraw) the current screen");
697
698
    const char *nano_suspend_msg =
	N_("Suspend the editor (if suspend is enabled)");
699
#ifndef NANO_TINY
700
    const char *nano_case_msg =
701
	N_("Toggle the case sensitivity of the search");
702
    const char *nano_reverse_msg =
703
	N_("Reverse the direction of the search");
704
#endif
705
#ifdef HAVE_REGEX_H
706
707
    const char *nano_regexp_msg =
	N_("Toggle the use of regular expressions");
708
#endif
709
#ifndef NANO_TINY
710
    const char *nano_prev_history_msg =
711
	N_("Recall the previous search/replace string");
712
    const char *nano_next_history_msg =
713
	N_("Recall the next search/replace string");
714
#endif
715
716
#ifndef DISABLE_BROWSER
    const char *nano_tofiles_msg = N_("Go to file browser");
Chris Allegretta's avatar
Chris Allegretta committed
717
#endif
718
#ifndef NANO_TINY
719
720
    const char *nano_dos_msg = N_("Toggle the use of DOS format");
    const char *nano_mac_msg = N_("Toggle the use of Mac format");
721
#endif
722
723
    const char *nano_append_msg = N_("Toggle appending");
    const char *nano_prepend_msg = N_("Toggle prepending");
724
#ifndef NANO_TINY
725
    const char *nano_backup_msg =
726
	N_("Toggle backing up of the original file");
727
    const char *nano_execute_msg = N_("Execute external command");
728
#endif
729
#if !defined(NANO_TINY) && defined(ENABLE_MULTIBUFFER)
730
731
    const char *nano_multibuffer_msg =
	N_("Toggle the use of a new buffer");
732
733
#endif
#ifndef DISABLE_BROWSER
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
734
    const char *nano_exitbrowser_msg = N_("Exit from the file browser");
735
736
737
738
    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");
739
740
    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
741
    const char *nano_gotodir_msg = N_("Go to directory");
Chris Allegretta's avatar
Chris Allegretta committed
742
#endif
743
744
745
746
#ifdef ENABLE_COLOR
    const char *nano_prevlint_msg = N_("Go to previous linter msg");
    const char *nano_nextlint_msg = N_("Go to next linter msg");
#endif
747
#endif /* !DISABLE_HELP */
Chris Allegretta's avatar
Chris Allegretta committed
748

David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
749
#ifndef DISABLE_HELP
750
#define IFSCHELP(help) help
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
751
#else
752
#define IFSCHELP(help) ""
753
#endif
754

755
756
757
758
759
    while (allfuncs != NULL) {
        subnfunc *f = allfuncs;
        allfuncs = (allfuncs)->next;
        free(f);
    }
760

761
    add_to_funcs(do_help_void,
762
	(MMAIN|MWHEREIS|MREPLACE|MREPLACE2|MGOTOLINE|MWRITEFILE|MINSERTFILE|MEXTCMD|MSPELL|MBROWSER|MWHEREISFILE|MGOTODIR|MLINTER),
763
	get_help_msg, IFSCHELP(nano_help_msg), FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
764

Benno Schulenberg's avatar
Benno Schulenberg committed
765
    add_to_funcs(do_cancel,
766
	(MWHEREIS|MREPLACE|MREPLACE2|MGOTOLINE|MWRITEFILE|MINSERTFILE|MEXTCMD|MSPELL|MWHEREISFILE|MGOTODIR|MYESNO|MLINTER),
767
	cancel_msg, IFSCHELP(nano_cancel_msg), FALSE, VIEW);
768

769
    add_to_funcs(do_exit, MMAIN,
770
#ifdef ENABLE_MULTIBUFFER
771
	/* TRANSLATORS: Try to keep this at most 10 characters. */
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
772
	openfile != NULL && openfile != openfile->next ? N_("Close") :
773
#endif
774
	exit_msg, IFSCHELP(nano_exit_msg), FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
775

776
#ifndef DISABLE_BROWSER
777
    add_to_funcs(do_exit, MBROWSER, exit_msg, IFSCHELP(nano_exitbrowser_msg), FALSE, VIEW);
778
#endif
Chris Allegretta's avatar
Chris Allegretta committed
779

780
    /* TRANSLATORS: Try to keep this at most 10 characters. */
781
    add_to_funcs(do_writeout_void, MMAIN, N_("Write Out"),
782
	IFSCHELP(nano_writeout_msg), FALSE, NOVIEW);
783

784
    /* We allow inserting files in view mode if multibuffers are
785
786
787
788
     * 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. */
789

790
    add_to_funcs(do_insertfile_void,
791
	/* TRANSLATORS: Try to keep this at most 10 characters. */
792
	MMAIN, N_("Read File"), IFSCHELP(nano_insert_msg), FALSE,
793
#ifdef ENABLE_MULTIBUFFER
794
	VIEW);
795
#else
796
	NOVIEW);
797
#endif
Chris Allegretta's avatar
Chris Allegretta committed
798

799
    add_to_funcs(do_search, MMAIN, whereis_msg,
800
	IFSCHELP(nano_whereis_msg), FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
801

802
803
804
    add_to_funcs(do_search, MBROWSER, whereis_msg,
	IFSCHELP(nano_browser_whereis_msg), FALSE, VIEW);

805
#ifndef NANO_TINY
806
807
    add_to_funcs(do_research, MBROWSER, whereis_next_msg,
	IFSCHELP(nano_whereis_next_msg), TRUE, VIEW);
808
#endif
809
810
811
812
813
814
815

#ifndef DISABLE_JUSTIFY
    /* TRANSLATORS: Try to keep this at most 10 characters. */
    add_to_funcs(do_justify_void, MMAIN, N_("Justify"),
	nano_justify_msg, TRUE, NOVIEW);
#endif

816
    add_to_funcs(do_page_up, MMAIN|MHELP|MBROWSER,
817
	prev_page_msg, IFSCHELP(nano_prevpage_msg), FALSE, VIEW);
818
    add_to_funcs(do_page_down, MMAIN|MHELP|MBROWSER,
819
	next_page_msg, IFSCHELP(nano_nextpage_msg), TRUE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
820

821
822
823
824
825
826
#ifdef ENABLE_COLOR
    add_to_funcs(do_page_up, MLINTER,
	prev_lint_msg, IFSCHELP(nano_prevlint_msg), FALSE, VIEW);
    add_to_funcs(do_page_down, MLINTER,
	next_lint_msg, IFSCHELP(nano_nextlint_msg), FALSE, VIEW);
#endif
827

828
    /* TRANSLATORS: Try to keep this at most 10 characters. */
829
    add_to_funcs(do_cut_text_void, MMAIN, N_("Cut Text"), IFSCHELP(nano_cut_msg),
830
	FALSE, NOVIEW);
Chris Allegretta's avatar
Chris Allegretta committed
831

832
    if (unjustify)
833
	/* TRANSLATORS: Try to keep this at most 10 characters. */
834
	add_to_funcs(do_uncut_text, MMAIN, N_("Unjustify"), "",
835
	    FALSE, NOVIEW);
836
    else
837
	/* TRANSLATORS: Try to keep this at most 10 characters. */
838
	add_to_funcs(do_uncut_text, MMAIN, N_("Uncut Text"), IFSCHELP(nano_uncut_msg),
839
	    FALSE, NOVIEW);
Chris Allegretta's avatar
Chris Allegretta committed
840

Chris Allegretta's avatar
Chris Allegretta committed
841
#ifndef NANO_TINY
842
    /* TRANSLATORS: Try to keep this at most 10 characters. */
843
    add_to_funcs(do_cursorpos_void, MMAIN, N_("Cur Pos"), IFSCHELP(nano_cursorpos_msg),
844
	FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
845
#endif
Chris Allegretta's avatar
Chris Allegretta committed
846

847
848
849
    /* If we're using restricted mode, spell checking is disabled
     * because it allows reading from or writing to files not specified
     * on the command line. */
850
#ifndef DISABLE_SPELLER
851
	/* TRANSLATORS: Try to keep this at most 10 characters. */
852
	add_to_funcs(do_spell, MMAIN, spell_msg, IFSCHELP(nano_spell_msg),
853
	    TRUE, NOVIEW);
854
#endif
855

856
857
858
859
860
#ifdef ENABLE_COLOR
    add_to_funcs(do_linter, MMAIN, lint_msg, IFSCHELP(nano_lint_msg),
	TRUE, NOVIEW);
#endif

861
    add_to_funcs(do_first_line,
862
	(MMAIN|MWHEREIS|MREPLACE|MREPLACE2|MGOTOLINE),
863
	first_line_msg, IFSCHELP(nano_firstline_msg), FALSE, VIEW);
864

865
    add_to_funcs(do_last_line,
866
	(MMAIN|MWHEREIS|MREPLACE|MREPLACE2|MGOTOLINE),
867
	last_line_msg, IFSCHELP(nano_lastline_msg), TRUE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
868

869
    add_to_funcs(do_gotolinecolumn_void, (MMAIN|MWHEREIS),
870
	go_to_line_msg, IFSCHELP(nano_gotoline_msg), FALSE, VIEW);
871

Chris Allegretta's avatar
Chris Allegretta committed
872
#ifdef NANO_TINY
873
    /* TRANSLATORS: Try to keep this at most 10 characters. */
874
    add_to_funcs(do_cursorpos_void, MMAIN, N_("Cur Pos"), IFSCHELP(nano_cursorpos_msg),
Chris Allegretta's avatar
Chris Allegretta committed
875
876
877
	FALSE, VIEW);
#endif

878
    add_to_funcs(do_replace, (MMAIN|MWHEREIS), replace_msg, IFSCHELP(nano_replace_msg),
879
880
881
882
#ifndef NANO_TINY
	FALSE,
#else
	TRUE,
883
#endif
884
	NOVIEW);
885

886
#ifndef NANO_TINY
887
    add_to_funcs(do_mark, MMAIN, N_("Mark Text"),
888
	IFSCHELP(nano_mark_msg), FALSE, VIEW);
889

890
    add_to_funcs(do_research, MMAIN, whereis_next_msg,
891
	IFSCHELP(nano_whereis_next_msg), TRUE, VIEW);
892

893
    add_to_funcs(do_copy_text, MMAIN, N_("Copy Text"),
894
	IFSCHELP(nano_copy_msg), FALSE, NOVIEW);
895

896
    add_to_funcs(do_indent_void, MMAIN, N_("Indent Text"),
897
	IFSCHELP(nano_indent_msg), FALSE, NOVIEW);
898

899
    add_to_funcs(do_unindent, MMAIN, N_("Unindent Text"),
900
	IFSCHELP(nano_unindent_msg), FALSE, NOVIEW);
901

902
    if (ISSET(UNDOABLE)) {
903
	add_to_funcs(do_undo, MMAIN, N_("Undo"),
904
	    IFSCHELP(nano_undo_msg), FALSE, NOVIEW);
905

906
	add_to_funcs(do_redo, MMAIN, N_("Redo"),
907
908
	    IFSCHELP(nano_redo_msg), TRUE, NOVIEW);
    }
909
#endif /* !NANO_TINY */
910

911
    add_to_funcs(do_left, MMAIN, N_("Back"), IFSCHELP(nano_back_msg),
912
	FALSE, VIEW);
913
914
    add_to_funcs(do_right, MMAIN, N_("Forward"), IFSCHELP(nano_forward_msg),
	FALSE, VIEW);
915
916

#ifndef DISABLE_BROWSER
917
    add_to_funcs(do_left, MBROWSER, N_("Back"), IFSCHELP(nano_backfile_msg),
918
	FALSE, VIEW);
919
920
    add_to_funcs(do_right, MBROWSER, N_("Forward"), IFSCHELP(nano_forwardfile_msg),
	FALSE, VIEW);
921
922
#endif

923
    add_to_funcs(do_left, MALL, "", "", FALSE, VIEW);
924
    add_to_funcs(do_right, MALL, "", "", FALSE, VIEW);
925

926
#ifndef NANO_TINY
927
    add_to_funcs(do_prev_word_void, MMAIN, N_("Prev Word"),
928
	IFSCHELP(nano_prevword_msg), FALSE, VIEW);
929
930
931

    add_to_funcs(do_next_word_void, MMAIN, N_("Next Word"),
	IFSCHELP(nano_nextword_msg), FALSE, VIEW);
932
#endif
933

934
    add_to_funcs(do_up_void, (MMAIN|MHELP|MBROWSER), N_("Prev Line"),
935
	IFSCHELP(nano_prevline_msg), FALSE, VIEW);
936

937
    add_to_funcs(do_down_void, (MMAIN|MHELP|MBROWSER), N_("Next Line"),
938
	IFSCHELP(nano_nextline_msg), TRUE, VIEW);
939

940
    add_to_funcs(do_home, MMAIN, N_("Home"), IFSCHELP(nano_home_msg),
941
	FALSE, VIEW);
942

943
    add_to_funcs(do_end, MMAIN, N_("End"), IFSCHELP(nano_end_msg),
944
	FALSE, VIEW);
945

946
#ifndef DISABLE_JUSTIFY
947
    add_to_funcs(do_para_begin_void, (MMAIN|MWHEREIS), beg_of_par_msg,
948
	IFSCHELP(nano_parabegin_msg), FALSE, VIEW);
949

950
    add_to_funcs(do_para_end_void, (MMAIN|MWHEREIS), end_of_par_msg,
951
	IFSCHELP(nano_paraend_msg), FALSE, VIEW);
952
#endif
953

954
#ifndef NANO_TINY
955
    add_to_funcs(do_find_bracket, MMAIN, N_("Find Other Bracket"),
956
	IFSCHELP(nano_bracket_msg), FALSE, VIEW);
957

958
    add_to_funcs(do_scroll_up, MMAIN, N_("Scroll Up"),
959
	IFSCHELP(nano_scrollup_msg), FALSE, VIEW);
960

961
    add_to_funcs(do_scroll_down, MMAIN, N_("Scroll Down"),
962
	IFSCHELP(nano_scrolldown_msg), FALSE, VIEW);
963
964
#endif

965
#ifdef ENABLE_MULTIBUFFER
966
    add_to_funcs(switch_to_prev_buffer_void, MMAIN, N_("Previous File"),
967
	IFSCHELP(nano_prevfile_msg), FALSE, VIEW);
968
    add_to_funcs(switch_to_next_buffer_void, MMAIN, N_("Next File"),
969
	IFSCHELP(nano_nextfile_msg), TRUE, VIEW);
970
971
#endif

972
    add_to_funcs(do_verbatim_input, MMAIN, N_("Verbatim Input"),
973
	IFSCHELP(nano_verbatim_msg), FALSE, NOVIEW);
974
    add_to_funcs(do_verbatim_input, MWHEREIS|MREPLACE|MREPLACE2|MEXTCMD|MSPELL,
975
976
	"", "", FALSE, NOVIEW);

977
    add_to_funcs(do_tab, MMAIN, N_("Tab"), IFSCHELP(nano_tab_msg),
978
	FALSE, NOVIEW);
979
980
    add_to_funcs(do_tab, MALL, "", "", FALSE, NOVIEW);
    add_to_funcs(do_enter_void, MMAIN, N_("Enter"), IFSCHELP(nano_enter_msg),
981
	FALSE, NOVIEW);
982
983
    add_to_funcs(do_enter_void, MALL, "", "", FALSE, NOVIEW);
    add_to_funcs(do_delete, MMAIN, N_("Delete"), IFSCHELP(nano_delete_msg),
984
	FALSE, NOVIEW);
985
986
    add_to_funcs(do_delete, MALL, "", "", FALSE, NOVIEW);
    add_to_funcs(do_backspace, MMAIN, N_("Backspace"), IFSCHELP(nano_backspace_msg),
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
987
#ifndef NANO_TINY
988
	FALSE,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
989
#else
990
	TRUE,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
991
#endif
992
993
	NOVIEW);

994
    add_to_funcs(do_backspace, MALL, "", "",
995
996
997
998
999
1000
#ifndef NANO_TINY
	FALSE,
#else
	TRUE,
#endif
	NOVIEW);
1001

1002
#ifndef NANO_TINY
1003
    add_to_funcs(do_cut_till_end, MMAIN, N_("CutTillEnd"),
1004
	IFSCHELP(nano_cut_till_end_msg), TRUE, NOVIEW);
1005
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1006

1007
1008
    add_to_funcs(xon_complaint, MMAIN, "", "", FALSE, VIEW);
    add_to_funcs(xoff_complaint, MMAIN, "", "", FALSE, VIEW);
1009

1010
#ifndef DISABLE_JUSTIFY
1011
    add_to_funcs(do_full_justify, (MMAIN|MWHEREIS), fulljstify_msg,
1012
	IFSCHELP(nano_fulljustify_msg), FALSE, NOVIEW);
1013
1014
#endif

1015
#ifndef NANO_TINY
1016
    add_to_funcs(do_wordlinechar_count, MMAIN, N_("Word Count"),
1017
	IFSCHELP(nano_wordcount_msg), FALSE, VIEW);
1018
#endif
1019

1020
    add_to_funcs(total_refresh, (MMAIN|MHELP), refresh_msg,
1021
1022
	IFSCHELP(nano_refresh_msg), FALSE, VIEW);

1023
    add_to_funcs(do_suspend_void, MMAIN, suspend_msg,
1024
	IFSCHELP(nano_suspend_msg), TRUE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
1025

1026
#ifndef NANO_TINY
Benno Schulenberg's avatar
Benno Schulenberg committed
1027
    add_to_funcs(case_sens_void, (MWHEREIS|MREPLACE|MWHEREISFILE),
1028
	case_sens_msg, IFSCHELP(nano_case_msg), FALSE, VIEW);
1029

Benno Schulenberg's avatar
Benno Schulenberg committed
1030
    add_to_funcs(backwards_void, (MWHEREIS|MREPLACE|MWHEREISFILE),
1031
	backwards_msg, IFSCHELP(nano_reverse_msg), FALSE, VIEW);
1032
#endif
1033

1034
#ifdef HAVE_REGEX_H
Benno Schulenberg's avatar
Benno Schulenberg committed
1035
    add_to_funcs(regexp_void, (MWHEREIS|MREPLACE|MWHEREISFILE),
1036
	regexp_msg, IFSCHELP(nano_regexp_msg), FALSE, VIEW);
1037
#endif
1038

1039
#ifndef NANO_TINY
1040
    add_to_funcs(get_history_older_void,
1041
	(MWHEREIS|MREPLACE|MREPLACE2|MWHEREISFILE),
1042
	prev_history_msg, IFSCHELP(nano_prev_history_msg), FALSE, VIEW);
1043

1044
    add_to_funcs(get_history_newer_void,
1045
	(MWHEREIS|MREPLACE|MREPLACE2|MWHEREISFILE),
1046
	next_history_msg, IFSCHELP(nano_next_history_msg), FALSE, VIEW);
1047
#endif
1048

1049
    add_to_funcs(no_replace_void, MREPLACE,
1050
	no_replace_msg, IFSCHELP(nano_whereis_msg), FALSE, VIEW);
1051

1052
    add_to_funcs(gototext_void, MGOTOLINE,
1053
	gototext_msg, IFSCHELP(nano_whereis_msg), TRUE, VIEW);
1054

1055
#ifndef DISABLE_BROWSER
1056
    if (!ISSET(RESTRICTED))
Benno Schulenberg's avatar
Benno Schulenberg committed
1057
	add_to_funcs(to_files_void, (MGOTOLINE|MINSERTFILE),
1058
	    to_files_msg, IFSCHELP(nano_tofiles_msg), FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
1059
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1060

1061
#ifndef NANO_TINY
1062
1063
1064
1065
1066
1067
    /* 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. */
1068
    if (!ISSET(RESTRICTED))
1069
        add_to_funcs(dos_format_void, MWRITEFILE,
1070
            dos_format_msg, IFSCHELP(nano_dos_msg), FALSE, NOVIEW);
1071

1072
    if (!ISSET(RESTRICTED))
1073
        add_to_funcs(mac_format_void, MWRITEFILE,
1074
            mac_format_msg, IFSCHELP(nano_mac_msg), FALSE, NOVIEW);
1075

1076
    if (!ISSET(RESTRICTED))
Benno Schulenberg's avatar
Benno Schulenberg committed
1077
        add_to_funcs(append_void, MWRITEFILE,
1078
            append_msg, IFSCHELP(nano_append_msg), FALSE, NOVIEW);
1079

1080
    if (!ISSET(RESTRICTED))
Benno Schulenberg's avatar
Benno Schulenberg committed
1081
        add_to_funcs(prepend_void, MWRITEFILE,
1082
            prepend_msg, IFSCHELP(nano_prepend_msg), FALSE, NOVIEW);
1083

1084
    if (!ISSET(RESTRICTED))
Benno Schulenberg's avatar
Benno Schulenberg committed
1085
        add_to_funcs(backup_file_void, MWRITEFILE,
1086
            backup_file_msg, IFSCHELP(nano_backup_msg), FALSE, NOVIEW);
1087

1088
1089
    /* If we're using restricted mode, command execution is disabled.
     * It's useless since inserting files is disabled. */
1090
    if (!ISSET(RESTRICTED))
Benno Schulenberg's avatar
Benno Schulenberg committed
1091
        add_to_funcs(ext_cmd_void, MINSERTFILE,
1092
	    ext_cmd_msg, IFSCHELP(nano_execute_msg), FALSE, NOVIEW);
1093

1094
#ifdef ENABLE_MULTIBUFFER
1095
1096
    /* If we're using restricted mode, the multibuffer toggle is
     * disabled.  It's useless since inserting files is disabled. */
1097
    if (!ISSET(RESTRICTED))
Benno Schulenberg's avatar
Benno Schulenberg committed
1098
	add_to_funcs(new_buffer_void, MINSERTFILE,
1099
	new_buffer_msg, IFSCHELP(nano_multibuffer_msg), FALSE, NOVIEW);
1100
#endif
1101

Benno Schulenberg's avatar
Benno Schulenberg committed
1102
    add_to_funcs(do_insertfile_void, MEXTCMD,
1103
	insert_file_msg, IFSCHELP(nano_insert_msg), FALSE, VIEW);
1104

David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1105
#ifdef ENABLE_MULTIBUFFER
Benno Schulenberg's avatar
Benno Schulenberg committed
1106
    add_to_funcs(new_buffer_void, MEXTCMD,
1107
	new_buffer_msg, IFSCHELP(nano_multibuffer_msg), FALSE, NOVIEW);
1108
#endif
1109
#endif /* !NANO_TINY */
1110

1111
#ifndef DISABLE_HELP
1112
    add_to_funcs(edit_refresh, MHELP,
1113
	refresh_msg, nano_refresh_msg, FALSE, VIEW);
1114

1115
    add_to_funcs(do_exit, MHELP, exit_msg, IFSCHELP(nano_exit_msg), FALSE, VIEW);
1116
1117
#endif

1118
#ifndef DISABLE_BROWSER
Benno Schulenberg's avatar
Benno Schulenberg committed
1119
    add_to_funcs(do_first_file, (MBROWSER|MWHEREISFILE),
1120
	first_file_msg, IFSCHELP(nano_firstfile_msg), FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
1121

Benno Schulenberg's avatar
Benno Schulenberg committed
1122
    add_to_funcs(do_last_file, (MBROWSER|MWHEREISFILE),
1123
	last_file_msg, IFSCHELP(nano_lastfile_msg), FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
1124

1125
    add_to_funcs(goto_dir_void, MBROWSER,
1126
	goto_dir_msg, IFSCHELP(nano_gotodir_msg), FALSE, VIEW);
1127
1128
#endif

1129
    currmenu = MMAIN;
1130

1131
    add_to_sclist(MMAIN|MWHEREIS|MREPLACE|MREPLACE2|MGOTOLINE|MWRITEFILE|MINSERTFILE|MEXTCMD|MSPELL|MBROWSER|MWHEREISFILE|MGOTODIR|MLINTER,
1132
	"^G", do_help_void, 0, TRUE);
1133
    add_to_sclist(MMAIN|MWHEREIS|MREPLACE|MREPLACE2|MGOTOLINE|MWRITEFILE|MINSERTFILE|MEXTCMD|MSPELL|MBROWSER|MWHEREISFILE|MGOTODIR|MLINTER,
1134
1135
1136
1137
1138
1139
1140
1141
	"F1", do_help_void, 0, TRUE);
    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, "^_", do_gotolinecolumn_void, 0, TRUE);
    add_to_sclist(MMAIN, "F13", do_gotolinecolumn_void, 0, TRUE);
    add_to_sclist(MMAIN, "M-G", do_gotolinecolumn_void, 0, TRUE);
    add_to_sclist(MMAIN, "^O", do_writeout_void, 0, TRUE);
    add_to_sclist(MMAIN, "F3", do_writeout_void, 0, TRUE);
1142
#ifndef DISABLE_JUSTIFY
1143
1144
1145
1146
1147
1148
1149
1150
    add_to_sclist(MMAIN, "^J", do_justify_void, 0, TRUE);
    add_to_sclist(MMAIN, "F4", do_justify_void, 0, TRUE);
#endif
    add_to_sclist(MMAIN, "^R", do_insertfile_void, 0, TRUE);
    add_to_sclist(MMAIN, "F5", do_insertfile_void, 0, TRUE);
    add_to_sclist(MMAIN, "kinsert", do_insertfile_void, 0, TRUE);
    add_to_sclist(MMAIN|MBROWSER, "^W", do_search, 0, TRUE);
    add_to_sclist(MMAIN|MBROWSER, "F6", do_search, 0, TRUE);
1151
1152
1153
1154
1155
1156
    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, "kpup", 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, "kpdown", do_page_down, 0, TRUE);
1157
1158
1159
1160
1161
1162
    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);
    add_to_sclist(MMAIN, "^C", do_cursorpos_void, 0, TRUE);
    add_to_sclist(MMAIN, "F11", do_cursorpos_void, 0, TRUE);
1163
#ifndef DISABLE_SPELLER
1164
1165
1166
1167
1168
1169
1170
1171
1172
    add_to_sclist(MMAIN, "^T", do_spell, 0, TRUE);
    add_to_sclist(MMAIN, "F12", do_spell, 0, TRUE);
#endif
    add_to_sclist(MMAIN, "^\\", do_replace, 0, TRUE);
    add_to_sclist(MMAIN, "F14", do_replace, 0, TRUE);
    add_to_sclist(MMAIN, "M-R", do_replace, 0, TRUE);
    add_to_sclist(MWHEREIS, "^R", do_replace, 0, FALSE);
    add_to_sclist(MREPLACE, "^R", no_replace_void, 0, FALSE);
    add_to_sclist(MWHEREIS, "^T", do_gotolinecolumn_void, 0, FALSE);
1173
#ifndef NANO_TINY
1174
1175
1176
1177
1178
1179
1180
1181
1182
    add_to_sclist(MMAIN, "^^", do_mark, 0, TRUE);
    add_to_sclist(MMAIN, "F15", do_mark, 0, TRUE);
    add_to_sclist(MMAIN, "M-A", do_mark, 0, TRUE);
    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_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);
1183
    if (ISSET(UNDOABLE)) {
1184
	add_to_sclist(MMAIN, "M-U", do_undo, 0, TRUE);
1185
	add_to_sclist(MMAIN, "M-E", do_redo, 0, TRUE);
1186
    }
1187
#endif
1188
1189
    add_to_sclist(MALL, "^F", do_right, 0, TRUE);
    add_to_sclist(MALL, "^B", do_left, 0, TRUE);
1190
1191
1192
    add_to_sclist(MALL, "kright", do_right, 0, TRUE);
    add_to_sclist(MALL, "kleft", do_left, 0, TRUE);
#ifndef NANO_TINY
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
    add_to_sclist(MMAIN, "^Space", do_next_word_void, 0, TRUE);
    add_to_sclist(MMAIN, "M-Space", do_prev_word_void, 0, TRUE);
#endif
    add_to_sclist(MMAIN, "^Q", xon_complaint, 0, TRUE);
    add_to_sclist(MMAIN, "^S", xoff_complaint, 0, TRUE);
    add_to_sclist(MMAIN|MHELP|MBROWSER, "^P", do_up_void, 0, TRUE);
    add_to_sclist(MMAIN|MHELP|MBROWSER, "kup", do_up_void, 0, TRUE);
    add_to_sclist(MMAIN|MHELP|MBROWSER, "^N", do_down_void, 0, TRUE);
    add_to_sclist(MMAIN|MHELP|MBROWSER, "kdown", do_down_void, 0, TRUE);
    add_to_sclist(MALL, "^A", do_home, 0, TRUE);
    add_to_sclist(MALL, "khome", do_home, 0, TRUE);
    add_to_sclist(MALL, "^E", do_end, 0, TRUE);
    add_to_sclist(MALL, "kend", do_end, 0, TRUE);
1206
#ifndef NANO_TINY
1207
1208
1209
1210
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACE2|MWHEREISFILE, "^P", get_history_older_void, 0, FALSE);
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACE2|MWHEREISFILE, "kup", get_history_older_void, 0, FALSE);
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACE2|MWHEREISFILE, "^N", get_history_newer_void, 0, FALSE);
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACE2|MWHEREISFILE, "kdown", get_history_newer_void, 0, FALSE);
1211
#endif
1212
#ifndef DISABLE_JUSTIFY
1213
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACE2,
1214
	"^W", do_para_begin_void, 0, TRUE);
1215
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACE2,
1216
1217
1218
1219
1220
	"^O", do_para_end_void, 0, TRUE);
    add_to_sclist(MALL, "M-(", do_para_begin_void, 0, TRUE);
    add_to_sclist(MALL, "M-9", do_para_begin_void, 0, TRUE);
    add_to_sclist(MALL, "M-)", do_para_end_void, 0, TRUE);
    add_to_sclist(MALL, "M-0", do_para_end_void, 0, TRUE);
Chris Allegretta's avatar
Chris Allegretta committed
1221
#endif
Benno Schulenberg's avatar
Benno Schulenberg committed
1222
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACE2,
1223
	"M-C", case_sens_void, 0, FALSE);
1224
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACE2,
1225
	"M-B", backwards_void, 0, FALSE);
1226
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACE2,
1227
	"M-R", regexp_void, 0, FALSE);
1228

1229
1230
1231
1232
    add_to_sclist(MMAIN, "M-\\", do_first_line, 0, TRUE);
    add_to_sclist(MMAIN, "M-|", do_first_line, 0, TRUE);
    add_to_sclist(MMAIN, "M-/", do_last_line, 0, TRUE);
    add_to_sclist(MMAIN, "M-?", do_last_line, 0, TRUE);
1233
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACE2|MGOTOLINE|MHELP,
1234
	"^Y", do_first_line, 0, TRUE);
1235
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACE2|MGOTOLINE|MHELP,
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
	"^V", do_last_line, 0, TRUE);

#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, "F13", goto_dir_void, 0, TRUE);
    add_to_sclist(MBROWSER|MWHEREISFILE, "M-G", goto_dir_void, 0, TRUE);
Benno Schulenberg's avatar
Benno Schulenberg committed
1246
#endif
1247
#ifndef NANO_TINY
1248
1249
1250
1251
1252
    add_to_sclist(MMAIN, "M-]", do_find_bracket, 0, TRUE);
    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);
1253
1254
#endif

1255
#ifdef ENABLE_MULTIBUFFER
1256
1257
1258
1259
    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);
1260
#endif
1261
    add_to_sclist(MALL, "M-V", do_verbatim_input, 0, TRUE);
Benno Schulenberg's avatar
Benno Schulenberg committed
1262

1263
#ifndef NANO_TINY
1264
    add_to_sclist(MALL, "M-T", do_cut_till_end, 0, TRUE);
1265
#ifndef DISABLE_JUSTIFY
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
    add_to_sclist(MALL, "M-J", do_full_justify, 0, TRUE);
#endif
    add_to_sclist(MMAIN, "M-D", do_wordlinechar_count, 0, TRUE);
    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);
    add_to_sclist(MMAIN, "M-P", do_toggle_void, WHITESPACE_DISPLAY, TRUE);
    add_to_sclist(MMAIN, "M-Y", do_toggle_void, NO_COLOR_SYNTAX, TRUE);
    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);
    add_to_sclist(MMAIN, "M-L", do_toggle_void, NO_WRAP, TRUE);
    add_to_sclist(MMAIN, "M-Q", do_toggle_void, TABS_TO_SPACES, TRUE);
    add_to_sclist(MMAIN, "M-B", do_toggle_void, BACKUP_FILE, TRUE);
    add_to_sclist(MMAIN, "M-F", do_toggle_void, MULTIBUFFER, TRUE);
    add_to_sclist(MMAIN, "M-M", do_toggle_void, USE_MOUSE, TRUE);
    add_to_sclist(MMAIN, "M-N", do_toggle_void, NO_CONVERT, TRUE);
    add_to_sclist(MMAIN, "M-Z", do_toggle_void, SUSPEND, TRUE);
    add_to_sclist(MMAIN, "M-$", do_toggle_void, SOFTWRAP, TRUE);
1286
#endif /* !NANO_TINY */
Benno Schulenberg's avatar
Benno Schulenberg committed
1287

1288
1289
    add_to_sclist(MHELP|MBROWSER, "^C", do_exit, 0, TRUE);
    add_to_sclist(MHELP, "^G", do_exit, 0, TRUE);
1290
1291
    add_to_sclist(MGOTOLINE, "^T",  gototext_void, 0, FALSE);
    add_to_sclist(MINSERTFILE|MEXTCMD, "M-F",  new_buffer_void, 0, FALSE);
1292
    add_to_sclist((MWHEREIS|MREPLACE|MREPLACE2|MGOTOLINE|MWRITEFILE|MINSERTFILE|MEXTCMD|MSPELL|MWHEREISFILE|MGOTODIR|MYESNO|MLINTER),
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
	"^C", do_cancel, 0, FALSE);
    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);
    add_to_sclist(MWRITEFILE, "^T",   to_files_void, 0, FALSE);
    add_to_sclist(MINSERTFILE, "^T",  to_files_void, 0, FALSE);
    add_to_sclist(MINSERTFILE, "^X",  ext_cmd_void, 0, FALSE);
    add_to_sclist(MMAIN, "^Z", do_suspend_void, 0, FALSE);
    add_to_sclist(MMAIN, "^L", total_refresh, 0, TRUE);
    add_to_sclist(MALL, "^I", do_tab, 0, TRUE);
    add_to_sclist(MALL, "^M", do_enter_void, 0, TRUE);
    add_to_sclist(MALL, "kenter", do_enter_void, 0, TRUE);
    add_to_sclist(MALL, "^D", do_delete, 0, TRUE);
    add_to_sclist(MALL, "kdel", do_delete, 0, TRUE);
    add_to_sclist(MALL, "^H", do_backspace, 0, TRUE);
    add_to_sclist(MALL, "kbsp", do_backspace, 0, TRUE);
Chris Allegretta's avatar
Chris Allegretta committed
1311

1312
1313
#ifdef DEBUG
    print_sclist();
Chris Allegretta's avatar
Chris Allegretta committed
1314
1315
#endif

1316
}
1317

1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
#ifdef ENABLE_COLOR
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


1335
const subnfunc *sctofunc(sc *s)
1336
{
1337
    subnfunc *f;
1338

1339
1340
    for (f = allfuncs; f != NULL && s->scfunc != f->scfunc; f = f->next)
	;
1341

1342
    return f;
1343
1344
}

1345
#ifndef NANO_TINY
1346
1347
/* Now let's come up with a single (hopefully)
 * function to get a string for each flag. */
1348
const char *flagtostr(int flag)
1349
{
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
   switch (flag) {
        case NO_HELP:
            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");
        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:
            return N_("Long line wrapping");
        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");
1383
1384
        case SOFTWRAP:
            return N_("Soft line wrapping");
1385
1386
1387
1388
        default:
            return "?????";
    }
}
1389
#endif /* !NANO_TINY */
1390

1391
/* Interpret the string given by the rc file and return a
1392
 * shortcut struct, complete with proper value for execute. */
1393
1394
1395
1396
1397
1398
1399
sc *strtosc(int menu, char *input)
{
     sc *s;

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

Chris Allegretta's avatar
Chris Allegretta committed
1400
#ifndef DISABLE_HELP
1401
    if (!strcasecmp(input, "help"))
1402
1403
	s->scfunc = do_help_void;
    else
Chris Allegretta's avatar
Chris Allegretta committed
1404
1405
#endif
    if (!strcasecmp(input, "cancel")) {
1406
	s->scfunc = do_cancel;
1407
1408
	s->execute = FALSE;
    } else if (!strcasecmp(input, "exit"))
1409
	s->scfunc = do_exit;
1410
    else if (!strcasecmp(input, "writeout"))
1411
	s->scfunc = do_writeout_void;
1412
    else if (!strcasecmp(input, "insert"))
1413
	s->scfunc = do_insertfile_void;
1414
    else if (!strcasecmp(input, "whereis"))
1415
	s->scfunc = do_search;
1416
    else if (!strcasecmp(input, "up"))
1417
	s->scfunc = do_up_void;
1418
    else if (!strcasecmp(input, "down"))
1419
	s->scfunc = do_down_void;
1420
1421
    else if (!strcasecmp(input, "pageup") ||
	     !strcasecmp(input, "prevpage"))
1422
	s->scfunc = do_page_up;
1423
1424
    else if (!strcasecmp(input, "pagedown") ||
	     !strcasecmp(input, "nextpage"))
1425
	s->scfunc = do_page_down;
1426
    else if (!strcasecmp(input, "cut"))
1427
	s->scfunc = do_cut_text_void;
1428
    else if (!strcasecmp(input, "uncut"))
1429
	s->scfunc = do_uncut_text;
1430
    else if (!strcasecmp(input, "curpos") ||
1431
	     !strcasecmp(input, "cursorpos"))
1432
	s->scfunc = do_cursorpos_void;
1433
    else if (!strcasecmp(input, "firstline"))
1434
	s->scfunc = do_first_line;
1435
    else if (!strcasecmp(input, "lastline"))
1436
	s->scfunc = do_last_line;
1437
    else if (!strcasecmp(input, "gotoline"))
1438
	s->scfunc = do_gotolinecolumn_void;
1439
    else if (!strcasecmp(input, "replace"))
1440
	s->scfunc = do_replace;
1441
#ifndef DISABLE_JUSTIFY
Chris Allegretta's avatar
Chris Allegretta committed
1442
    else if (!strcasecmp(input, "justify"))
1443
	s->scfunc = do_justify_void;
1444
    else if (!strcasecmp(input, "beginpara"))
1445
	s->scfunc = do_para_begin_void;
1446
    else if (!strcasecmp(input, "endpara"))
1447
	s->scfunc = do_para_end_void;
1448
    else if (!strcasecmp(input, "fulljustify"))
1449
	s->scfunc = do_full_justify;
1450
1451
#endif
#ifndef NANO_TINY
1452
    else if (!strcasecmp(input, "mark"))
1453
	s->scfunc = do_mark;
1454
    else if (!strcasecmp(input, "searchagain") ||
1455
	     !strcasecmp(input, "research"))
1456
	s->scfunc = do_research;
1457
    else if (!strcasecmp(input, "copytext"))
1458
	s->scfunc = do_copy_text;
1459
    else if (!strcasecmp(input, "indent"))
1460
	s->scfunc = do_indent_void;
1461
    else if (!strcasecmp(input, "unindent"))
1462
	s->scfunc = do_unindent;
Chris Allegretta's avatar
Chris Allegretta committed
1463
    else if (!strcasecmp(input, "scrollup"))
1464
	s->scfunc = do_scroll_up;
Chris Allegretta's avatar
Chris Allegretta committed
1465
    else if (!strcasecmp(input, "scrolldown"))
1466
	s->scfunc = do_scroll_down;
1467
    else if (!strcasecmp(input, "nextword"))
1468
	s->scfunc = do_next_word_void;
1469
    else if (!strcasecmp(input, "suspend"))
1470
	s->scfunc = do_suspend_void;
1471
    else if (!strcasecmp(input, "prevword"))
1472
	s->scfunc = do_prev_word_void;
1473
    else if (!strcasecmp(input, "findbracket"))
1474
	s->scfunc = do_find_bracket;
1475
    else if (!strcasecmp(input, "wordcount"))
1476
	s->scfunc = do_wordlinechar_count;
1477
    else if (!strcasecmp(input, "undo"))
1478
	s->scfunc = do_undo;
1479
    else if (!strcasecmp(input, "redo"))
1480
	s->scfunc = do_redo;
Chris Allegretta's avatar
Chris Allegretta committed
1481
    else if (!strcasecmp(input, "prevhistory")) {
1482
	s->scfunc =  get_history_older_void;
1483
1484
	s->execute = FALSE;
    } else if (!strcasecmp(input, "nexthistory")) {
1485
	s->scfunc =  get_history_newer_void;
1486
	s->execute = FALSE;
1487
    } else if (!strcasecmp(input, "nohelp")) {
1488
	s->scfunc =  do_toggle_void;
1489
1490
1491
	s->execute = FALSE;
	s->toggle = NO_HELP;
    } else if (!strcasecmp(input, "constupdate")) {
1492
	s->scfunc =  do_toggle_void;
1493
1494
1495
	s->execute = FALSE;
	s->toggle = CONST_UPDATE;
    } else if (!strcasecmp(input, "morespace")) {
1496
	s->scfunc =  do_toggle_void;
1497
1498
1499
	s->execute = FALSE;
	s->toggle = MORE_SPACE;
    } else if (!strcasecmp(input, "smoothscroll")) {
1500
	s->scfunc =  do_toggle_void;
1501
1502
	s->execute = FALSE;
	s->toggle = SMOOTH_SCROLL;
1503
    } else if (!strcasecmp(input, "whitespacedisplay")) {
1504
	s->scfunc =  do_toggle_void;
1505
1506
1507
	s->execute = FALSE;
	s->toggle = WHITESPACE_DISPLAY;
    } else if (!strcasecmp(input, "nosyntax")) {
1508
	s->scfunc =  do_toggle_void;
1509
1510
1511
	s->execute = FALSE;
	s->toggle = NO_COLOR_SYNTAX;
    } else if (!strcasecmp(input, "smarthome")) {
1512
	s->scfunc =  do_toggle_void;
1513
1514
1515
	s->execute = FALSE;
	s->toggle = SMART_HOME;
    } else if (!strcasecmp(input, "autoindent")) {
1516
	s->scfunc =  do_toggle_void;
1517
1518
1519
	s->execute = FALSE;
	s->toggle = AUTOINDENT;
    } else if (!strcasecmp(input, "cuttoend")) {
1520
	s->scfunc =  do_toggle_void;
1521
1522
1523
	s->execute = FALSE;
	s->toggle = CUT_TO_END;
    } else if (!strcasecmp(input, "nowrap")) {
1524
	s->scfunc =  do_toggle_void;
1525
1526
	s->execute = FALSE;
	s->toggle = NO_WRAP;
1527
1528
1529
1530
    } else if (!strcasecmp(input, "softwrap")) {
	s->scfunc =  do_toggle_void;
	s->execute = FALSE;
	s->toggle = SOFTWRAP;
1531
    } else if (!strcasecmp(input, "tabstospaces")) {
1532
	s->scfunc =  do_toggle_void;
1533
1534
1535
	s->execute = FALSE;
	s->toggle = TABS_TO_SPACES;
    } else if (!strcasecmp(input, "backupfile")) {
1536
	s->scfunc =  do_toggle_void;
1537
1538
	s->execute = FALSE;
	s->toggle = BACKUP_FILE;
1539
    } else if (!strcasecmp(input, "multibuffer")) {
1540
	s->scfunc =  do_toggle_void;
1541
1542
1543
	s->execute = FALSE;
	s->toggle = MULTIBUFFER;
    } else if (!strcasecmp(input, "mouse")) {
1544
	s->scfunc =  do_toggle_void;
1545
1546
1547
	s->execute = FALSE;
	s->toggle = USE_MOUSE;
    } else if (!strcasecmp(input, "noconvert")) {
1548
	s->scfunc =  do_toggle_void;
1549
1550
	s->execute = FALSE;
	s->toggle = NO_CONVERT;
1551
    } else if (!strcasecmp(input, "suspendenable")) {
1552
	s->scfunc =  do_toggle_void;
1553
1554
	s->execute = FALSE;
	s->toggle = SUSPEND;
1555
    }
1556
#endif /* !NANO_TINY */
Chris Allegretta's avatar
Chris Allegretta committed
1557
    else if (!strcasecmp(input, "right") ||
1558
	     !strcasecmp(input, "forward"))
1559
	s->scfunc = do_right;
Chris Allegretta's avatar
Chris Allegretta committed
1560
    else if (!strcasecmp(input, "left") ||
1561
	     !strcasecmp(input, "back"))
1562
	s->scfunc = do_left;
Chris Allegretta's avatar
Chris Allegretta committed
1563
    else if (!strcasecmp(input, "up") ||
1564
	     !strcasecmp(input, "prevline"))
1565
	s->scfunc = do_up_void;
Chris Allegretta's avatar
Chris Allegretta committed
1566
    else if (!strcasecmp(input, "down") ||
1567
	     !strcasecmp(input, "nextline"))
1568
	s->scfunc = do_down_void;
Chris Allegretta's avatar
Chris Allegretta committed
1569
    else if (!strcasecmp(input, "home"))
1570
	s->scfunc = do_home;
Chris Allegretta's avatar
Chris Allegretta committed
1571
    else if (!strcasecmp(input, "end"))
1572
	s->scfunc = do_end;
Chris Allegretta's avatar
Chris Allegretta committed
1573
1574
#ifdef ENABLE_MULTIBUFFER
    else if (!strcasecmp(input, "prevbuf"))
1575
	s->scfunc = switch_to_prev_buffer_void;
Chris Allegretta's avatar
Chris Allegretta committed
1576
    else if (!strcasecmp(input, "nextbuf"))
1577
	s->scfunc = switch_to_next_buffer_void;
Chris Allegretta's avatar
Chris Allegretta committed
1578
1579
#endif
    else if (!strcasecmp(input, "verbatim"))
1580
	s->scfunc = do_verbatim_input;
Chris Allegretta's avatar
Chris Allegretta committed
1581
    else if (!strcasecmp(input, "tab"))
1582
	s->scfunc = do_tab;
Chris Allegretta's avatar
Chris Allegretta committed
1583
    else if (!strcasecmp(input, "enter"))
1584
	s->scfunc = do_enter_void;
Chris Allegretta's avatar
Chris Allegretta committed
1585
    else if (!strcasecmp(input, "delete"))
1586
	s->scfunc = do_delete;
1587
    else if (!strcasecmp(input, "backspace"))
1588
	s->scfunc = do_backspace;
Chris Allegretta's avatar
Chris Allegretta committed
1589
    else if (!strcasecmp(input, "refresh"))
1590
	s->scfunc = total_refresh;
Chris Allegretta's avatar
Chris Allegretta committed
1591
    else if (!strcasecmp(input, "casesens")) {
1592
	s->scfunc = case_sens_void;
Chris Allegretta's avatar
Chris Allegretta committed
1593
1594
	s->execute = FALSE;
    } else if (!strcasecmp(input, "regexp") ||
1595
	       !strcasecmp(input, "regex")) {
1596
	s->scfunc = regexp_void;
Chris Allegretta's avatar
Chris Allegretta committed
1597
1598
	s->execute = FALSE;
    } else if (!strcasecmp(input, "dontreplace")) {
1599
	s->scfunc = no_replace_void;
Chris Allegretta's avatar
Chris Allegretta committed
1600
1601
	s->execute = FALSE;
    } else if (!strcasecmp(input, "gototext")) {
1602
	s->scfunc = gototext_void;
Chris Allegretta's avatar
Chris Allegretta committed
1603
1604
	s->execute = FALSE;
    } else if (!strcasecmp(input, "browser") ||
1605
	       !strcasecmp(input, "tofiles")) {
1606
	s->scfunc = to_files_void;
Chris Allegretta's avatar
Chris Allegretta committed
1607
1608
	s->execute = FALSE;
    } else if (!strcasecmp(input, "dosformat")) {
1609
	s->scfunc = dos_format_void;
Chris Allegretta's avatar
Chris Allegretta committed
1610
1611
	s->execute = FALSE;
    } else if (!strcasecmp(input, "macformat")) {
1612
	s->scfunc =  mac_format_void;
Chris Allegretta's avatar
Chris Allegretta committed
1613
1614
	s->execute = FALSE;
    } else if (!strcasecmp(input, "append")) {
1615
	s->scfunc =  append_void;
Chris Allegretta's avatar
Chris Allegretta committed
1616
1617
	s->execute = FALSE;
    } else if (!strcasecmp(input, "prepend")) {
1618
	s->scfunc =  prepend_void;
Chris Allegretta's avatar
Chris Allegretta committed
1619
1620
	s->execute = FALSE;
    } else if (!strcasecmp(input, "backup")) {
1621
	s->scfunc =  backup_file_void;
Chris Allegretta's avatar
Chris Allegretta committed
1622
1623
1624
	s->execute = FALSE;
#ifdef ENABLE_MULTIBUFFER
    } else if (!strcasecmp(input, "newbuffer")) {
1625
	s->scfunc =  new_buffer_void;
Chris Allegretta's avatar
Chris Allegretta committed
1626
1627
	s->execute = FALSE;
#endif
1628
#ifndef DISABLE_BROWSER
Chris Allegretta's avatar
Chris Allegretta committed
1629
    } else if (!strcasecmp(input, "firstfile")) {
1630
	s->scfunc =  do_first_file;
Chris Allegretta's avatar
Chris Allegretta committed
1631
1632
	s->execute = FALSE;
    } else if (!strcasecmp(input, "lastfile")) {
1633
	s->scfunc = do_last_file;
Chris Allegretta's avatar
Chris Allegretta committed
1634
	s->execute = FALSE;
1635
#endif
1636
1637
1638
1639
1640
1641
    } else {
	free(s);
	return NULL;
    }
    return s;
}
1642

Chris Allegretta's avatar
Chris Allegretta committed
1643
#ifdef ENABLE_NANORC
1644
/* Same thing as above but for the menu. */
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
int strtomenu(char *input)
{
    if (!strcasecmp(input, "all"))
	return MALL;
    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") ||
		!strcasecmp(input, "replacewith"))
	return MREPLACE2;
    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") ||
		!strcasecmp(input, "extcmd"))
	return MEXTCMD;
    else if (!strcasecmp(input, "help"))
	return MHELP;
    else if (!strcasecmp(input, "spell"))
	return MSPELL;
    else if (!strcasecmp(input, "browser"))
	return MBROWSER;
    else if (!strcasecmp(input, "whereisfile"))
	return MWHEREISFILE;
    else if (!strcasecmp(input, "gotodir"))
	return MGOTODIR;

    return -1;
}
1680
1681
#endif

Chris Allegretta's avatar
Chris Allegretta committed
1682

1683
1684
1685
#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
1686
1687
 * 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
1688
1689
 * function unless debugging is turned on. */
void thanks_for_all_the_fish(void)
1690
{
1691
1692
1693
1694
    delwin(topwin);
    delwin(edit);
    delwin(bottomwin);

Chris Allegretta's avatar
Chris Allegretta committed
1695
1696
1697
#ifndef DISABLE_JUSTIFY
    if (quotestr != NULL)
	free(quotestr);
1698
1699
#ifdef HAVE_REGEX_H
    regfree(&quotereg);
1700
1701
    if (quoteerr != NULL)
	free(quoteerr);
1702
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1703
#endif
1704
#ifndef NANO_TINY
1705
1706
1707
    if (backup_dir != NULL)
        free(backup_dir);
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1708
#ifndef DISABLE_OPERATINGDIR
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
    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);
1721
#endif
1722
1723
1724
    if (answer != NULL)
	free(answer);
    if (cutbuffer != NULL)
Chris Allegretta's avatar
Chris Allegretta committed
1725
	free_filestruct(cutbuffer);
1726
1727
1728
#ifndef DISABLE_JUSTIFY
    if (jusbuffer != NULL)
	free_filestruct(jusbuffer);
1729
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1730
    /* Free the memory associated with each open file buffer. */
1731
    if (openfile != NULL)
1732
	free_openfilestruct(openfile);
Chris Allegretta's avatar
Chris Allegretta committed
1733
#ifdef ENABLE_COLOR
1734
1735
    if (syntaxstr != NULL)
	free(syntaxstr);
Chris Allegretta's avatar
Chris Allegretta committed
1736
1737
1738
1739
1740
1741
1742
1743
    while (syntaxes != NULL) {
	syntaxtype *bill = syntaxes;

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

	    syntaxes->extensions = bob->next;
1744
	    free(bob->ext_regex);
1745
1746
1747
1748
	    if (bob->ext != NULL) {
		regfree(bob->ext);
		free(bob->ext);
	    }
Chris Allegretta's avatar
Chris Allegretta committed
1749
1750
1751
1752
1753
1754
	    free(bob);
	}
	while (syntaxes->color != NULL) {
	    colortype *bob = syntaxes->color;

	    syntaxes->color = bob->next;
1755
	    free(bob->start_regex);
1756
1757
1758
1759
	    if (bob->start != NULL) {
		regfree(bob->start);
		free(bob->start);
	    }
1760
1761
	    if (bob->end_regex != NULL)
		free(bob->end_regex);
1762
	    if (bob->end != NULL) {
1763
		regfree(bob->end);
1764
1765
		free(bob->end);
	    }
Chris Allegretta's avatar
Chris Allegretta committed
1766
1767
1768
1769
1770
1771
	    free(bob);
	}
	syntaxes = syntaxes->next;
	free(bill);
    }
#endif /* ENABLE_COLOR */
1772
#ifndef NANO_TINY
1773
    /* Free the search and replace history lists. */
1774
1775
1776
1777
    if (searchage != NULL)
	free_filestruct(searchage);
    if (replaceage != NULL)
	free_filestruct(replaceage);
1778
#endif
1779
#ifdef ENABLE_NANORC
1780
1781
    if (homedir != NULL)
	free(homedir);
1782
#endif
1783
}
1784

1785
#endif /* DEBUG */