global.c 56.7 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(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
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
#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
	/* Struct for the shortcut-key list. */
171
subnfunc *allfuncs = NULL;
172
	/* Struct for the function list. */
173
174
subnfunc *uncutfunc;
	/* Pointer to the special Uncut/Unjustify item. */
175

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

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

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

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

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

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

225
/* Just throw this here. */
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
267
268
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)
{
}

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

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

    if (allfuncs == NULL) {
290
	allfuncs = (subnfunc *) nmalloc(sizeof(subnfunc));
291
292
293
294
295
296
297
298
299
300
301
302
	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;
303
#ifndef DISABLE_HELP
304
305
306
307
308
    f->help = help;
    f->blank_after = blank_after;
#endif

#ifdef DEBUG
309
    fprintf(stderr, "Added func %ld (%s) for menus %x\n", (long)func, f->desc, menus);
310
#endif
311
312
}

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

    for (s = sclist; s != NULL; s = s->next) {
	if ((s->menu & menu) && s->scfunc == func) {
Benno Schulenberg's avatar
Benno Schulenberg committed
322
323
324
325
	    /* Memorize the first meta sequence, first function key,
	     * and first dedicated key.  The latter is needed to be
	     * able to show something when the user has rebound all
	     * other sequences for a specific func. */
326
	    if (s->type == META) {
327
328
		if (!metasc)
		    metasc = s;
329
		continue;
330
331
332
333
	    } else if (s->type == FKEY) {
		if (!fkeysc)
		    fkeysc = s;
		continue;
334
335
336
337
	    } else if (s->type == RAWINPUT) {
		if (!rawsc)
		    rawsc = s;
		continue;
338
339
340
	    }

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

Benno Schulenberg's avatar
Benno Schulenberg committed
345
346
    /* If we did not find any control sequence, then prefer a
     * meta sequence over a function key over a dedicated key. */
347
    if (metasc)
348
	return metasc;
349
350
    else if (fkeysc)
	return fkeysc;
351
352
    else if (rawsc)
	return rawsc;
353

354
#ifdef DEBUG
355
    fprintf(stderr, "Whoops, returning null given func %ld in menu %x\n", (long) func, menu);
356
357
358
359
360
361
#endif
    /* Otherwise... */
    return NULL;
}


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

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

387
388
389
    s->type = strtokeytype(scstring);
    s->menu = menu;
    s->toggle = toggle;
390
    s->keystr = (char *) scstring;
391
392
393
394
395
    s->scfunc = func;
    s->execute = execute;
    assign_keyinfo(s);

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

400
/* Assign one menu's shortcuts to another function. */
401
402
403
404
405
406
407
408
409
410
411
412
413
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
414
/* Return the given menu's first shortcut sequence, or the default value
415
 * (2nd arg).  Assumes currmenu for the menu to check. */
416
int sc_seq_or (void (*func)(void), int defaultval)
Chris Allegretta's avatar
Chris Allegretta committed
417
418
419
420
421
422
423
424
425
{
    const sc *s = first_sc_for(currmenu, func);

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

426
427
/* Assign the info to the shortcut struct.
 * Assumes keystr is already assigned, naturally. */
428
429
430
431
432
433
434
435
436
437
438
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]);
439
    } else /* RAWINPUT */
440
        s->seq = (int) s->keystr[0];
441

442
    /* Override some keys which don't bind as easily as we'd like. */
443
444
445
446
    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) ' ';
447
    else if (s->type == RAWINPUT) {
448
	if (!strcasecmp(s->keystr, "Up"))
449
	    s->seq = KEY_UP;
450
	else if (!strcasecmp(s->keystr, "Down"))
451
	    s->seq = KEY_DOWN;
452
	else if (!strcasecmp(s->keystr, "Left"))
453
	    s->seq = KEY_LEFT;
454
	else if (!strcasecmp(s->keystr, "Right"))
455
	    s->seq = KEY_RIGHT;
456
	else if (!strcasecmp(s->keystr, "Ins"))
457
	    s->seq = KEY_IC;
458
	else if (!strcasecmp(s->keystr, "Del"))
459
	    s->seq = KEY_DC;
460
	else if (!strcasecmp(s->keystr, "Bsp"))
461
	    s->seq = KEY_BACKSPACE;
462
	else if (!strcasecmp(s->keystr, "Enter"))
463
	    s->seq = KEY_ENTER;
464
	else if (!strcasecmp(s->keystr, "PgUp"))
465
	    s->seq = KEY_PPAGE;
466
	else if (!strcasecmp(s->keystr, "PgDn"))
467
	    s->seq = KEY_NPAGE;
468
#ifdef KEY_HOME
469
	else if (!strcasecmp(s->keystr, "Home"))
470
	    s->seq = KEY_HOME;
471
472
#endif
#ifdef KEY_END
473
	else if (!strcasecmp(s->keystr, "End"))
474
	    s->seq = KEY_END;
475
#endif
476
    }
477
478
479
480
481
482
483
484
}

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

485
    for (s = sclist; s != NULL; s = s->next) {
486
	f = sctofunc(s);
487
	if (f)
488
	    fprintf(stderr, "Shortcut \"%s\", function: %s, menus %x\n", s->keystr, f->desc, f->menus);
489
	else
490
	    fprintf(stderr, "Hmm, didn't find a func for \"%s\"\n", s->keystr);
491
492
493
494
    }
}
#endif

495
496
/* 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. */
497
498
499
const char *cancel_tag = N_("Cancel");
const char *replace_tag = N_("Replace");
const char *no_replace_tag = N_("No Replace");
500
501

#ifndef NANO_TINY
502
503
const char *case_sens_tag = N_("Case Sens");
const char *backwards_tag = N_("Backwards");
504
505
506
#endif

#ifdef HAVE_REGEX_H
507
const char *regexp_tag = N_("Regexp");
508
509
#endif

510
511
512
513
514
/* TRANSLATORS: Try to keep the next four strings at most 10 characters. */
const char *uncut_tag = N_("Uncut Text");
#ifndef DISABLE_JUSITIFY
const char *unjust_tag = N_("Unjustify");
#endif
515
#ifndef NANO_TINY
516
517
const char *prev_history_tag = N_("PrevHstory");
const char *next_history_tag = N_("NextHstory");
518
/* TRANSLATORS: Try to keep the next four strings at most 12 characters. */
519
const char *whereis_next_tag = N_("WhereIs Next");
520
#endif
521
const char *gototext_tag = N_("Go To Text");
522
#ifndef DISABLE_BROWSER
523
524
const char *first_file_tag = N_("First File");
const char *last_file_tag = N_("Last File");
525
/* TRANSLATORS: Try to keep the next nine strings at most 16 characters. */
526
527
const char *to_files_tag = N_("To Files");
const char *goto_dir_tag = N_("Go To Dir");
528
#endif
529
#ifndef NANO_TINY
530
531
532
533
534
535
const char *dos_format_tag = N_("DOS Format");
const char *mac_format_tag = N_("Mac Format");
const char *append_tag = N_("Append");
const char *prepend_tag = N_("Prepend");
const char *backup_file_tag = N_("Backup File");
const char *ext_cmd_tag = N_("Execute Command");
536
#endif
537
#ifndef DISABLE_MULTIBUFFER
538
const char *new_buffer_tag = N_("New Buffer");
539
540
#endif

541
542
/* Initialize the list of functions and the list of shortcuts. */
void shortcut_init(void)
543
{
544
    /* TRANSLATORS: Try to keep the following strings at most 10 characters. */
545
546
547
    const char *get_help_tag = N_("Get Help");
    const char *exit_tag = N_("Exit");
    const char *whereis_tag = N_("Where Is");
548
549
    const char *prev_line_tag = N_("Prev Line");
    const char *next_line_tag = N_("Next Line");
550
551
552
553
554
    const char *prev_page_tag = N_("Prev Page");
    const char *next_page_tag = N_("Next Page");
    const char *first_line_tag = N_("First Line");
    const char *last_line_tag = N_("Last Line");
    const char *suspend_tag = N_("Suspend");
555
#ifndef DISABLE_JUSTIFY
556
557
558
    const char *beg_of_par_tag = N_("Beg of Par");
    const char *end_of_par_tag = N_("End of Par");
    const char *fulljstify_tag = N_("FullJstify");
559
#endif
560
561
    const char *refresh_tag = N_("Refresh");
    const char *go_to_line_tag = N_("Go To Line");
562
#ifndef DISABLE_SPELLER
563
    const char *spell_tag = N_("To Spell");
564
#endif
565
#ifndef DISABLE_COLOR
566
567
568
    const char *lint_tag = N_("To Linter");
    const char *prev_lint_tag = N_("Prev Lint Msg");
    const char *next_lint_tag = N_("Next Lint Msg");
569
#endif
570

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

David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
726
#ifndef DISABLE_HELP
727
#define IFSCHELP(help) help
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
728
#else
729
#define IFSCHELP(help) ""
730
#endif
731

732
733
734
735
736
    while (allfuncs != NULL) {
        subnfunc *f = allfuncs;
        allfuncs = (allfuncs)->next;
        free(f);
    }
737

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

740
    add_to_funcs(do_help_void, MMOST,
741
	get_help_tag, IFSCHELP(nano_help_msg), FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
742

743
    add_to_funcs(do_cancel, ((MMOST & ~MMAIN & ~MBROWSER) | MYESNO),
744
	cancel_tag, IFSCHELP(nano_cancel_msg), FALSE, VIEW);
745

746
    add_to_funcs(do_exit, MMAIN,
747
#ifndef DISABLE_MULTIBUFFER
748
	/* TRANSLATORS: Try to keep this at most 10 characters. */
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
749
	openfile != NULL && openfile != openfile->next ? N_("Close") :
750
#endif
751
	exit_tag, IFSCHELP(nano_exit_msg), FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
752

753
#ifndef DISABLE_BROWSER
754
    add_to_funcs(do_exit, MBROWSER, exit_tag, IFSCHELP(nano_exitbrowser_msg), FALSE, VIEW);
755
#endif
Chris Allegretta's avatar
Chris Allegretta committed
756

757
    /* TRANSLATORS: Try to keep this at most 10 characters. */
758
    add_to_funcs(do_writeout_void, MMAIN, N_("Write Out"),
759
	IFSCHELP(nano_writeout_msg), FALSE, NOVIEW);
760

761
    /* We allow inserting files in view mode if multibuffers are
762
763
764
765
     * 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. */
766
    add_to_funcs(do_insertfile_void,
767
	/* TRANSLATORS: Try to keep this at most 10 characters. */
768
	MMAIN, N_("Read File"), IFSCHELP(nano_insert_msg), FALSE,
769
#ifndef DISABLE_MULTIBUFFER
770
	VIEW);
771
#else
772
	NOVIEW);
773
#endif
Chris Allegretta's avatar
Chris Allegretta committed
774

775
    add_to_funcs(do_search, MMAIN, whereis_tag,
776
	IFSCHELP(nano_whereis_msg), FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
777

778
    add_to_funcs(do_search, MBROWSER, whereis_tag,
779
780
	IFSCHELP(nano_browser_whereis_msg), FALSE, VIEW);

781
#ifndef NANO_TINY
782
    add_to_funcs(do_research, MBROWSER, whereis_next_tag,
783
	IFSCHELP(nano_whereis_next_msg), TRUE, VIEW);
784
#endif
785
786
787
788
789
790
791

#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

792
#ifndef DISABLE_HELP
793
794
    /* The description ("x") and blank_after (0) are irrelevant,
     * because the help viewer does not have a help text. */
795
    add_to_funcs(do_exit, MHELP, exit_tag, "x", 0, VIEW);
796

797
    add_to_funcs(total_refresh, MHELP, refresh_tag, "x", 0, VIEW);
798
799
800

    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);
801
802
#endif

803
    add_to_funcs(do_page_up, MMAIN|MHELP|MBROWSER,
804
	prev_page_tag, IFSCHELP(nano_prevpage_msg), FALSE, VIEW);
805
    add_to_funcs(do_page_down, MMAIN|MHELP|MBROWSER,
806
	next_page_tag, IFSCHELP(nano_nextpage_msg), TRUE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
807

808
#ifndef DISABLE_COLOR
809
    add_to_funcs(do_page_up, MLINTER,
810
	prev_lint_tag, IFSCHELP(nano_prevlint_msg), FALSE, VIEW);
811
    add_to_funcs(do_page_down, MLINTER,
812
	next_lint_tag, IFSCHELP(nano_nextlint_msg), FALSE, VIEW);
813
#endif
814

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

819
820
821
822
823
824
    add_to_funcs(do_uncut_text, MMAIN, uncut_tag, IFSCHELP(nano_uncut_msg),
	FALSE, NOVIEW);

    /* Remember the entry for Uncut, to be able to replace it with Unjustify. */
    for (uncutfunc = allfuncs; uncutfunc->next != NULL; uncutfunc = uncutfunc->next)
	;
Chris Allegretta's avatar
Chris Allegretta committed
825

Chris Allegretta's avatar
Chris Allegretta committed
826
#ifndef NANO_TINY
827
    /* TRANSLATORS: Try to keep this at most 10 characters. */
828
    add_to_funcs(do_cursorpos_void, MMAIN, N_("Cur Pos"), IFSCHELP(nano_cursorpos_msg),
829
	FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
830
#endif
Chris Allegretta's avatar
Chris Allegretta committed
831

832
833
834
    /* 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. */
835
#ifndef DISABLE_SPELLER
836
    /* TRANSLATORS: Try to keep this at most 10 characters. */
837
    add_to_funcs(do_spell, MMAIN, spell_tag, IFSCHELP(nano_spell_msg),
838
	TRUE, NOVIEW);
839
#endif
840

841
#ifndef DISABLE_COLOR
842
    add_to_funcs(do_linter, MMAIN, lint_tag, IFSCHELP(nano_lint_msg),
843
844
845
	TRUE, NOVIEW);
#endif

846
    add_to_funcs(do_first_line,
847
	(MMAIN|MHELP|MWHEREIS|MREPLACE|MREPLACEWITH|MGOTOLINE),
848
	first_line_tag, IFSCHELP(nano_firstline_msg), FALSE, VIEW);
849
    add_to_funcs(do_last_line,
850
	(MMAIN|MHELP|MWHEREIS|MREPLACE|MREPLACEWITH|MGOTOLINE),
851
	last_line_tag, IFSCHELP(nano_lastline_msg), TRUE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
852

853
    add_to_funcs(do_gotolinecolumn_void, (MMAIN|MWHEREIS),
854
	go_to_line_tag, IFSCHELP(nano_gotoline_msg), FALSE, VIEW);
855

Chris Allegretta's avatar
Chris Allegretta committed
856
#ifdef NANO_TINY
857
    /* TRANSLATORS: Try to keep this at most 10 characters. */
858
    add_to_funcs(do_cursorpos_void, MMAIN, N_("Cur Pos"), IFSCHELP(nano_cursorpos_msg),
Chris Allegretta's avatar
Chris Allegretta committed
859
860
861
	FALSE, VIEW);
#endif

862
    add_to_funcs(do_replace, (MMAIN|MWHEREIS), replace_tag, IFSCHELP(nano_replace_msg),
863
864
865
866
#ifndef NANO_TINY
	FALSE,
#else
	TRUE,
867
#endif
868
	NOVIEW);
869

870
#ifndef NANO_TINY
871
    add_to_funcs(do_mark, MMAIN, N_("Mark Text"),
872
	IFSCHELP(nano_mark_msg), FALSE, VIEW);
873

874
    add_to_funcs(do_research, MMAIN, whereis_next_tag,
875
	IFSCHELP(nano_whereis_next_msg), TRUE, VIEW);
876

877
    add_to_funcs(do_copy_text, MMAIN, N_("Copy Text"),
878
	IFSCHELP(nano_copy_msg), FALSE, NOVIEW);
879

880
    add_to_funcs(do_indent_void, MMAIN, N_("Indent Text"),
881
	IFSCHELP(nano_indent_msg), FALSE, NOVIEW);
882
    add_to_funcs(do_unindent, MMAIN, N_("Unindent Text"),
883
	IFSCHELP(nano_unindent_msg), FALSE, NOVIEW);
884

885
    if (ISSET(UNDOABLE)) {
886
	add_to_funcs(do_undo, MMAIN, N_("Undo"),
887
	    IFSCHELP(nano_undo_msg), FALSE, NOVIEW);
888
	add_to_funcs(do_redo, MMAIN, N_("Redo"),
889
890
	    IFSCHELP(nano_redo_msg), TRUE, NOVIEW);
    }
891
#endif /* !NANO_TINY */
892

893
    add_to_funcs(do_left, MMAIN, N_("Back"), IFSCHELP(nano_back_msg),
894
	FALSE, VIEW);
895
896
    add_to_funcs(do_right, MMAIN, N_("Forward"), IFSCHELP(nano_forward_msg),
	FALSE, VIEW);
897
898

#ifndef DISABLE_BROWSER
899
    add_to_funcs(do_left, MBROWSER, N_("Back"), IFSCHELP(nano_backfile_msg),
900
	FALSE, VIEW);
901
902
    add_to_funcs(do_right, MBROWSER, N_("Forward"), IFSCHELP(nano_forwardfile_msg),
	FALSE, VIEW);
903
904
#endif

905
906
    add_to_funcs(do_left, MMOST, "", "", FALSE, VIEW);
    add_to_funcs(do_right, MMOST, "", "", FALSE, VIEW);
907

908
#ifndef NANO_TINY
909
    add_to_funcs(do_prev_word_void, MMAIN, N_("Prev Word"),
910
	IFSCHELP(nano_prevword_msg), FALSE, VIEW);
911
912
    add_to_funcs(do_next_word_void, MMAIN, N_("Next Word"),
	IFSCHELP(nano_nextword_msg), FALSE, VIEW);
913
#endif
914

915
    add_to_funcs(do_up_void, (MMAIN|MBROWSER), prev_line_tag,
916
	IFSCHELP(nano_prevline_msg), FALSE, VIEW);
917
    add_to_funcs(do_down_void, (MMAIN|MBROWSER), next_line_tag,
918
	IFSCHELP(nano_nextline_msg), TRUE, VIEW);
919

920
    add_to_funcs(do_home, MMAIN, N_("Home"), IFSCHELP(nano_home_msg),
921
	FALSE, VIEW);
922
    add_to_funcs(do_end, MMAIN, N_("End"), IFSCHELP(nano_end_msg),
923
	FALSE, VIEW);
924

925
#ifndef DISABLE_JUSTIFY
926
    add_to_funcs(do_para_begin_void, (MMAIN|MWHEREIS), beg_of_par_tag,
927
	IFSCHELP(nano_parabegin_msg), FALSE, VIEW);
928
    add_to_funcs(do_para_end_void, (MMAIN|MWHEREIS), end_of_par_tag,
929
	IFSCHELP(nano_paraend_msg), FALSE, VIEW);
930
#endif
931

932
#ifndef NANO_TINY
933
    add_to_funcs(do_find_bracket, MMAIN, N_("Find Other Bracket"),
934
	IFSCHELP(nano_bracket_msg), FALSE, VIEW);
935

936
    add_to_funcs(do_scroll_up, MMAIN, N_("Scroll Up"),
937
	IFSCHELP(nano_scrollup_msg), FALSE, VIEW);
938
    add_to_funcs(do_scroll_down, MMAIN, N_("Scroll Down"),
939
	IFSCHELP(nano_scrolldown_msg), FALSE, VIEW);
940
941
#endif

942
#ifndef DISABLE_MULTIBUFFER
943
    add_to_funcs(switch_to_prev_buffer_void, MMAIN, N_("Previous File"),
944
	IFSCHELP(nano_prevfile_msg), FALSE, VIEW);
945
    add_to_funcs(switch_to_next_buffer_void, MMAIN, N_("Next File"),
946
	IFSCHELP(nano_nextfile_msg), TRUE, VIEW);
947
948
#endif

949
    add_to_funcs(do_verbatim_input, MMAIN, N_("Verbatim Input"),
950
	IFSCHELP(nano_verbatim_msg), FALSE, NOVIEW);
951
    add_to_funcs(do_verbatim_input, MWHEREIS|MREPLACE|MREPLACEWITH|MEXTCMD|MSPELL,
952
953
	"", "", FALSE, NOVIEW);

954
    add_to_funcs(do_tab, MMAIN, N_("Tab"), IFSCHELP(nano_tab_msg),
955
	FALSE, NOVIEW);
956
    add_to_funcs(do_tab, MMOST, "", "", FALSE, NOVIEW);
957
    add_to_funcs(do_enter_void, MMAIN, N_("Enter"), IFSCHELP(nano_enter_msg),
958
	FALSE, NOVIEW);
959
    add_to_funcs(do_enter_void, MMOST, "", "", FALSE, NOVIEW);
960
    add_to_funcs(do_delete, MMAIN, N_("Delete"), IFSCHELP(nano_delete_msg),
961
	FALSE, NOVIEW);
962
    add_to_funcs(do_delete, MMOST, "", "", FALSE, NOVIEW);
963
    add_to_funcs(do_backspace, MMAIN, N_("Backspace"), IFSCHELP(nano_backspace_msg),
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
964
#ifndef NANO_TINY
965
	FALSE,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
966
#else
967
	TRUE,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
968
#endif
969
970
	NOVIEW);

971
    add_to_funcs(do_backspace, MMOST, "", "",
972
973
974
975
976
977
#ifndef NANO_TINY
	FALSE,
#else
	TRUE,
#endif
	NOVIEW);
978

979
#ifndef NANO_TINY
980
    add_to_funcs(do_cut_till_end, MMAIN, N_("CutTillEnd"),
981
	IFSCHELP(nano_cut_till_end_msg), TRUE, NOVIEW);
982
#endif
Chris Allegretta's avatar
Chris Allegretta committed
983

984
985
    add_to_funcs(xon_complaint, MMAIN, "", "", FALSE, VIEW);
    add_to_funcs(xoff_complaint, MMAIN, "", "", FALSE, VIEW);
986

987
#ifndef DISABLE_JUSTIFY
988
    add_to_funcs(do_full_justify, (MMAIN|MWHEREIS), fulljstify_tag,
989
	IFSCHELP(nano_fulljustify_msg), FALSE, NOVIEW);
990
991
#endif

992
#ifndef NANO_TINY
993
    add_to_funcs(do_wordlinechar_count, MMAIN, N_("Word Count"),
994
	IFSCHELP(nano_wordcount_msg), FALSE, VIEW);
995
#endif
996

997
    add_to_funcs(total_refresh, MMAIN, refresh_tag,
998
999
	IFSCHELP(nano_refresh_msg), FALSE, VIEW);

1000
    add_to_funcs(do_suspend_void, MMAIN, suspend_tag,
1001
	IFSCHELP(nano_suspend_msg), TRUE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
1002

1003
#ifndef NANO_TINY
Benno Schulenberg's avatar
Benno Schulenberg committed
1004
    add_to_funcs(case_sens_void, (MWHEREIS|MREPLACE|MWHEREISFILE),
1005
	case_sens_tag, IFSCHELP(nano_case_msg), FALSE, VIEW);
1006

Benno Schulenberg's avatar
Benno Schulenberg committed
1007
    add_to_funcs(backwards_void, (MWHEREIS|MREPLACE|MWHEREISFILE),
1008
	backwards_tag, IFSCHELP(nano_reverse_msg), FALSE, VIEW);
1009
#endif
1010

1011
#ifdef HAVE_REGEX_H
Benno Schulenberg's avatar
Benno Schulenberg committed
1012
    add_to_funcs(regexp_void, (MWHEREIS|MREPLACE|MWHEREISFILE),
1013
	regexp_tag, IFSCHELP(nano_regexp_msg), FALSE, VIEW);
1014
#endif
1015

1016
#ifndef NANO_TINY
1017
    add_to_funcs(get_history_older_void,
1018
	(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE),
1019
	prev_history_tag, IFSCHELP(nano_prev_history_msg), FALSE, VIEW);
1020

1021
    add_to_funcs(get_history_newer_void,
1022
	(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE),
1023
	next_history_tag, IFSCHELP(nano_next_history_msg), FALSE, VIEW);
1024
#endif
1025

1026
    add_to_funcs(no_replace_void, MREPLACE,
1027
	no_replace_tag, IFSCHELP(nano_whereis_msg), FALSE, VIEW);
1028

1029
    add_to_funcs(gototext_void, MGOTOLINE,
1030
	gototext_tag, IFSCHELP(nano_whereis_msg), TRUE, VIEW);
1031

1032
#ifndef DISABLE_BROWSER
1033
    if (!ISSET(RESTRICTED))
1034
	add_to_funcs(to_files_void, MINSERTFILE,
1035
	    to_files_tag, IFSCHELP(nano_tofiles_msg), FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
1036
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1037

1038
#ifndef NANO_TINY
1039
1040
1041
1042
1043
1044
    /* 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. */
1045
    if (!ISSET(RESTRICTED)) {
1046
        add_to_funcs(dos_format_void, MWRITEFILE,
1047
            dos_format_tag, IFSCHELP(nano_dos_msg), FALSE, NOVIEW);
1048

1049
        add_to_funcs(mac_format_void, MWRITEFILE,
1050
            mac_format_tag, IFSCHELP(nano_mac_msg), FALSE, NOVIEW);
1051

Benno Schulenberg's avatar
Benno Schulenberg committed
1052
        add_to_funcs(append_void, MWRITEFILE,
1053
            append_tag, IFSCHELP(nano_append_msg), FALSE, NOVIEW);
Benno Schulenberg's avatar
Benno Schulenberg committed
1054
        add_to_funcs(prepend_void, MWRITEFILE,
1055
            prepend_tag, IFSCHELP(nano_prepend_msg), FALSE, NOVIEW);
1056

Benno Schulenberg's avatar
Benno Schulenberg committed
1057
        add_to_funcs(backup_file_void, MWRITEFILE,
1058
            backup_file_tag, IFSCHELP(nano_backup_msg), FALSE, NOVIEW);
1059
    }
1060

1061
1062
1063
    /* 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
1064
        add_to_funcs(ext_cmd_void, MINSERTFILE,
1065
	    ext_cmd_tag, IFSCHELP(nano_execute_msg), FALSE, NOVIEW);
1066

1067
#ifndef DISABLE_MULTIBUFFER
1068
	add_to_funcs(new_buffer_void, MINSERTFILE|MEXTCMD,
1069
	    new_buffer_tag, IFSCHELP(nano_multibuffer_msg), FALSE, NOVIEW);
1070
#endif
1071
    }
1072
#endif /* !NANO_TINY */
1073

1074
#ifndef DISABLE_BROWSER
Benno Schulenberg's avatar
Benno Schulenberg committed
1075
    add_to_funcs(do_first_file, (MBROWSER|MWHEREISFILE),
1076
	first_file_tag, IFSCHELP(nano_firstfile_msg), FALSE, VIEW);
Benno Schulenberg's avatar
Benno Schulenberg committed
1077
    add_to_funcs(do_last_file, (MBROWSER|MWHEREISFILE),
1078
	last_file_tag, IFSCHELP(nano_lastfile_msg), FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
1079

1080
    add_to_funcs(goto_dir_void, MBROWSER,
1081
	goto_dir_tag, IFSCHELP(nano_gotodir_msg), FALSE, VIEW);
1082
1083
#endif

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

1086
1087
    add_to_sclist(MMOST, "^G", do_help_void, 0, TRUE);
    add_to_sclist(MMOST, "F1", do_help_void, 0, TRUE);
1088
1089
1090
1091
1092
1093
1094
    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);
1095
#ifndef DISABLE_JUSTIFY
1096
1097
1098
1099
1100
    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);
1101
    add_to_sclist(MMAIN, "Ins", do_insertfile_void, 0, TRUE);
1102
1103
    add_to_sclist(MMAIN|MBROWSER, "^W", do_search, 0, TRUE);
    add_to_sclist(MMAIN|MBROWSER, "F6", do_search, 0, TRUE);
1104
1105
    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);
1106
    add_to_sclist(MMAIN|MBROWSER|MHELP|MWHEREISFILE|MLINTER, "PgUp", do_page_up, 0, TRUE);
1107
1108
    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);
1109
    add_to_sclist(MMAIN|MBROWSER|MHELP|MWHEREISFILE|MLINTER, "PgDn", do_page_down, 0, TRUE);
1110
1111
1112
1113
1114
1115
    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);
1116
#ifndef DISABLE_SPELLER
1117
1118
1119
1120
1121
1122
1123
1124
1125
    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);
1126
#ifndef NANO_TINY
1127
1128
1129
1130
1131
1132
1133
1134
1135
    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);
1136
    if (ISSET(UNDOABLE)) {
1137
	add_to_sclist(MMAIN, "M-U", do_undo, 0, TRUE);
1138
	add_to_sclist(MMAIN, "M-E", do_redo, 0, TRUE);
1139
    }
1140
#endif
1141
1142
    add_to_sclist(MMOST, "^F", do_right, 0, TRUE);
    add_to_sclist(MMOST, "^B", do_left, 0, TRUE);
1143
1144
    add_to_sclist(MMOST, "Right", do_right, 0, TRUE);
    add_to_sclist(MMOST, "Left", do_left, 0, TRUE);
1145
#ifndef NANO_TINY
1146
1147
1148
1149
1150
1151
    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);
1152
    add_to_sclist(MMAIN|MHELP|MBROWSER, "Up", do_up_void, 0, TRUE);
1153
    add_to_sclist(MMAIN|MHELP|MBROWSER, "^N", do_down_void, 0, TRUE);
1154
    add_to_sclist(MMAIN|MHELP|MBROWSER, "Down", do_down_void, 0, TRUE);
1155
    add_to_sclist(MMOST, "^A", do_home, 0, TRUE);
1156
    add_to_sclist(MMOST, "Home", do_home, 0, TRUE);
1157
    add_to_sclist(MMOST, "^E", do_end, 0, TRUE);
1158
    add_to_sclist(MMOST, "End", do_end, 0, TRUE);
1159
#ifndef NANO_TINY
1160
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE, "^P", get_history_older_void, 0, FALSE);
1161
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE, "Up", get_history_older_void, 0, FALSE);
1162
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE, "^N", get_history_newer_void, 0, FALSE);
1163
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE, "Down", get_history_newer_void, 0, FALSE);
1164
#endif
1165
#ifndef DISABLE_JUSTIFY
1166
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH,
1167
	"^W", do_para_begin_void, 0, TRUE);
1168
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH,
1169
	"^O", do_para_end_void, 0, TRUE);
1170
1171
1172
1173
    add_to_sclist(MMOST, "M-(", do_para_begin_void, 0, TRUE);
    add_to_sclist(MMOST, "M-9", do_para_begin_void, 0, TRUE);
    add_to_sclist(MMOST, "M-)", do_para_end_void, 0, TRUE);
    add_to_sclist(MMOST, "M-0", do_para_end_void, 0, TRUE);
Chris Allegretta's avatar
Chris Allegretta committed
1174
#endif
1175
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH,
1176
	"M-C", case_sens_void, 0, FALSE);
1177
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH,
1178
	"M-B", backwards_void, 0, FALSE);
1179
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH,
1180
	"M-R", regexp_void, 0, FALSE);
1181

1182
1183
1184
1185
    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);
1186
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MGOTOLINE,
1187
	"^Y", do_first_line, 0, TRUE);
1188
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MGOTOLINE,
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
	"^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
1199
#endif
1200
#ifndef NANO_TINY
1201
1202
1203
1204
1205
    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);
1206
1207
#endif

1208
#ifndef DISABLE_MULTIBUFFER
1209
1210
1211
1212
    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);
1213
#endif
Benno Schulenberg's avatar
Benno Schulenberg committed
1214

1215
    add_to_sclist(MMOST, "M-V", do_verbatim_input, 0, TRUE);
1216
#ifndef NANO_TINY
1217
    add_to_sclist(MMAIN, "M-T", do_cut_till_end, 0, TRUE);
1218
#endif
1219
#ifndef DISABLE_JUSTIFY
1220
    add_to_sclist(MMAIN|MWHEREIS, "M-J", do_full_justify, 0, TRUE);
1221
#endif
1222
#ifndef NANO_TINY
1223
    add_to_sclist(MMAIN, "M-D", do_wordlinechar_count, 0, TRUE);
1224

1225
1226
1227
1228
1229
1230
    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);
1231
    add_to_sclist(MMAIN, "M-$", do_toggle_void, SOFTWRAP, TRUE);
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
    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);
1242
#endif /* !NANO_TINY */
Benno Schulenberg's avatar
Benno Schulenberg committed
1243

1244
1245
    add_to_sclist(MGOTOLINE, "^T", gototext_void, 0, FALSE);
    add_to_sclist(MINSERTFILE|MEXTCMD, "M-F", new_buffer_void, 0, FALSE);
1246
    add_to_sclist(((MMOST & ~MMAIN & ~MBROWSER) | MYESNO), "^C", do_cancel, 0, FALSE);
1247
1248
1249
1250
1251
    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
1252
    add_to_sclist(MWRITEFILE|MINSERTFILE, "^T", to_files_void, 0, FALSE);
1253
    add_to_sclist(MINSERTFILE, "^X", ext_cmd_void, 0, FALSE);
1254
    add_to_sclist(MMAIN, "^Z", do_suspend_void, 0, FALSE);
1255
    add_to_sclist(MMAIN|MHELP, "^L", total_refresh, 0, FALSE);
1256
1257
    add_to_sclist(MHELP|MBROWSER, "^C", do_exit, 0, TRUE);
    add_to_sclist(MHELP, "^G", do_exit, 0, TRUE);
1258
1259
    add_to_sclist(MMOST, "^I", do_tab, 0, TRUE);
    add_to_sclist(MMOST, "^M", do_enter_void, 0, TRUE);
1260
    add_to_sclist(MMOST, "Enter", do_enter_void, 0, TRUE);
1261
    add_to_sclist(MMOST, "^D", do_delete, 0, TRUE);
1262
    add_to_sclist(MMOST, "Del", do_delete, 0, TRUE);
1263
    add_to_sclist(MMOST, "^H", do_backspace, 0, TRUE);
1264
    add_to_sclist(MMOST, "Bsp", do_backspace, 0, TRUE);
Chris Allegretta's avatar
Chris Allegretta committed
1265

1266
1267
#ifdef DEBUG
    print_sclist();
Chris Allegretta's avatar
Chris Allegretta committed
1268
#endif
1269
}
1270

1271
#ifndef DISABLE_COLOR
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
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

1287
const subnfunc *sctofunc(sc *s)
1288
{
1289
    subnfunc *f;
1290

1291
1292
    for (f = allfuncs; f != NULL && s->scfunc != f->scfunc; f = f->next)
	;
1293

1294
    return f;
1295
1296
}

1297
#ifndef NANO_TINY
1298
1299
/* Now let's come up with a single (hopefully) function to get a string
 * for each flag. */
1300
const char *flagtostr(int flag)
1301
{
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
   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");
1315
1316
        case SOFTWRAP:
            return N_("Soft line wrapping");
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
        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");
        default:
            return "?????";
    }
}
1341
#endif /* !NANO_TINY */
1342

1343
1344
1345
/* 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)
1346
{
1347
    sc *s;
1348
1349

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

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

1595
#ifndef DISABLE_NANORC
1596
/* Same thing as above but for the menu. */
1597
1598
1599
int strtomenu(char *input)
{
    if (!strcasecmp(input, "all"))
1600
	return (MMOST|MHELP|MYESNO);
1601
1602
1603
1604
1605
1606
1607
    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
1608
	     !strcasecmp(input, "replacewith"))
1609
	return MREPLACEWITH;
1610
1611
1612
1613
1614
1615
1616
    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
1617
	     !strcasecmp(input, "extcmd"))
1618
1619
1620
1621
1622
	return MEXTCMD;
    else if (!strcasecmp(input, "help"))
	return MHELP;
    else if (!strcasecmp(input, "spell"))
	return MSPELL;
1623
1624
    else if (!strcasecmp(input, "linter"))
	return MLINTER;
1625
1626
1627
1628
1629
1630
1631
1632
1633
    else if (!strcasecmp(input, "browser"))
	return MBROWSER;
    else if (!strcasecmp(input, "whereisfile"))
	return MWHEREISFILE;
    else if (!strcasecmp(input, "gotodir"))
	return MGOTODIR;

    return -1;
}
1634
1635
#endif

Chris Allegretta's avatar
Chris Allegretta committed
1636

1637
1638
1639
#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
1640
1641
 * 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
1642
1643
 * function unless debugging is turned on. */
void thanks_for_all_the_fish(void)
1644
{
1645
1646
1647
1648
    delwin(topwin);
    delwin(edit);
    delwin(bottomwin);

Chris Allegretta's avatar
Chris Allegretta committed
1649
1650
1651
#ifndef DISABLE_JUSTIFY
    if (quotestr != NULL)
	free(quotestr);
1652
1653
#ifdef HAVE_REGEX_H
    regfree(&quotereg);
1654
1655
    if (quoteerr != NULL)
	free(quoteerr);
1656
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1657
#endif
1658
#ifndef NANO_TINY
1659
1660
1661
    if (backup_dir != NULL)
        free(backup_dir);
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1662
#ifndef DISABLE_OPERATINGDIR
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
    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);
1675
#endif
1676
1677
1678
    if (answer != NULL)
	free(answer);
    if (cutbuffer != NULL)
Chris Allegretta's avatar
Chris Allegretta committed
1679
	free_filestruct(cutbuffer);
1680
1681
1682
#ifndef DISABLE_JUSTIFY
    if (jusbuffer != NULL)
	free_filestruct(jusbuffer);
1683
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1684
    /* Free the memory associated with each open file buffer. */
1685
    if (openfile != NULL)
1686
	free_openfilestruct(openfile);
1687
#ifndef DISABLE_COLOR
1688
1689
    if (syntaxstr != NULL)
	free(syntaxstr);
Chris Allegretta's avatar
Chris Allegretta committed
1690
1691
1692
1693
1694
1695
1696
1697
    while (syntaxes != NULL) {
	syntaxtype *bill = syntaxes;

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

	    syntaxes->extensions = bob->next;
1698
	    free(bob->ext_regex);
1699
1700
1701
1702
	    if (bob->ext != NULL) {
		regfree(bob->ext);
		free(bob->ext);
	    }
Chris Allegretta's avatar
Chris Allegretta committed
1703
1704
1705
1706
1707
1708
	    free(bob);
	}
	while (syntaxes->color != NULL) {
	    colortype *bob = syntaxes->color;

	    syntaxes->color = bob->next;
1709
	    free(bob->start_regex);
1710
1711
1712
1713
	    if (bob->start != NULL) {
		regfree(bob->start);
		free(bob->start);
	    }
1714
1715
	    if (bob->end_regex != NULL)
		free(bob->end_regex);
1716
	    if (bob->end != NULL) {
1717
		regfree(bob->end);
1718
1719
		free(bob->end);
	    }
Chris Allegretta's avatar
Chris Allegretta committed
1720
1721
1722
1723
1724
	    free(bob);
	}
	syntaxes = syntaxes->next;
	free(bill);
    }
1725
#endif /* !DISABLE_COLOR */
1726
#ifndef NANO_TINY
1727
    /* Free the search and replace history lists. */
1728
1729
1730
1731
    if (searchage != NULL)
	free_filestruct(searchage);
    if (replaceage != NULL)
	free_filestruct(replaceage);
1732
#endif
1733
#ifndef DISABLE_NANORC
1734
1735
    if (homedir != NULL)
	free(homedir);
1736
#endif
1737
}
1738

1739
#endif /* DEBUG */