global.c 53.4 KB
Newer Older
1
2
/* $Id$ 
*/
Chris Allegretta's avatar
Chris Allegretta committed
3
4
5
/**************************************************************************
 *   global.c                                                             *
 *                                                                        *
6
7
 *   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007   *
 *   Free Software Foundation, Inc.                                       *
Chris Allegretta's avatar
Chris Allegretta committed
8
9
 *   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 *
10
 *   the Free Software Foundation; either version 3, or (at your option)  *
Chris Allegretta's avatar
Chris Allegretta committed
11
12
 *   any later version.                                                   *
 *                                                                        *
13
14
15
16
 *   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
17
18
19
 *                                                                        *
 *   You should have received a copy of the GNU General Public License    *
 *   along with this program; if not, write to the Free Software          *
20
21
 *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA            *
 *   02110-1301, USA.                                                     *
Chris Allegretta's avatar
Chris Allegretta committed
22
23
24
 *                                                                        *
 **************************************************************************/

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

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
55
56
57
58
59
60
61
	/* 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. */

long flags = 0;
	/* 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
69
70
71
	 * 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? */

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

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

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

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

117
char *answer = NULL;
118
	/* The answer string used by the statusbar prompt. */
Chris Allegretta's avatar
Chris Allegretta committed
119

120
121
122
ssize_t tabsize = -1;
	/* The width of a tab in spaces.  The default value is set in
	 * main(). */
123

124
125
126
127
#ifndef NANO_TINY
char *backup_dir = NULL;
	/* The directory where we store backup files. */
#endif
128
#ifndef DISABLE_OPERATINGDIR
129
130
131
132
133
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. */
134
135
#endif

136
#ifndef DISABLE_SPELLER
137
138
char *alt_speller = NULL;
	/* The command to use for the alternate spell checker. */
139
140
#endif

141
#ifdef ENABLE_COLOR
142
syntaxtype *syntaxes = NULL;
143
	/* The global list of color syntaxes. */
144
char *syntaxstr = NULL;
145
	/* The color syntax name specified on the command line. */
146
147
#endif

148
149
const shortcut *currshortcut;
	/* The current shortcut list we're using. */
150
151
152
int currmenu;
	/* The currently loaded menu */

153
#ifndef NANO_TINY
154
toggle *toggles = NULL;
155
	/* The global toggle list. */
156
#endif
Chris Allegretta's avatar
Chris Allegretta committed
157

158
159
160
161
162
sc *sclist = NULL;
	/* New shortcut key struct */
subnfunc *allfuncs = NULL;
	/* New struct for the function list */

163
#ifndef NANO_TINY
164
filestruct *search_history = NULL;
165
	/* The search string history list. */
166
filestruct *searchage = NULL;
167
	/* The top of the search string history list. */
168
filestruct *searchbot = NULL;
169
	/* The bottom of the search string history list. */
170
filestruct *replace_history = NULL;
171
	/* The replace string history list. */
172
filestruct *replaceage = NULL;
173
	/* The top of the replace string history list. */
174
filestruct *replacebot = NULL;
175
	/* The bottom of the replace string history list. */
176
177
#endif

178
/* Regular expressions. */
179
#ifdef HAVE_REGEX_H
180
181
182
183
184
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
185
#endif
186

187
188
int reverse_attr = A_REVERSE;
	/* The curses attribute we use for reverse video. */
189

190
char *homedir = NULL;
191
	/* The user's home directory, from $HOME or /etc/passwd. */
192

193
194
/* Return the number of entries in the shortcut list s for a given menu. */
size_t length_of_list(int menu)
195
{
196
    subnfunc *f;
197
    size_t i = 0;
198

199
    for (f = allfuncs; f != NULL; f = f->next)
200
201
202
203
204
        if ((f->menus & menu) != 0
#ifndef DISABLE_HELP
	    && strlen(f->help) > 0
#endif
	                          ) {
205
206
	    i++;
	}
207
208
209
    return i;
}

210
211
212
/* Set type of function based on the string */
function_type strtokeytype(char *str)
{
213
    if (str[0] ==  'M' || str[0] == 'm')
214
        return META;
215
    else if (str[0] == '^')
216
        return CONTROL;
217
    else if (str[0] ==  'F' || str[0] == 'F')
218
        return FKEY;
219
    else
220
221
222
223
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
	return RAW;
}

/* Add a string to the new function list strict.
   Does not allow updates, yet anyway */
void add_to_funcs(void *func, int menus, const char *desc, const char *help,
    bool blank_after, bool viewok)
{
    subnfunc *f;

    if (allfuncs == NULL) {
	allfuncs = nmalloc(sizeof(subnfunc));
	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;
#ifndef NANO_TINY
    f->help = help;
    f->blank_after = blank_after;
#endif

#ifdef DEBUG
    fprintf(stderr, "Added func \"%s\"", f->desc);
251
#endif
252
253
254
255
}

const sc *first_sc_for(int menu, void *func) {
    const sc *s;
256
    const sc *metasc = NULL;
257
258
259

    for (s = sclist; s != NULL; s = s->next) {
	if ((s->menu & menu) && s->scfunc == func) {
260
261
262
263
264
265
266
267
	    /* try to use a meta sequence as a last resort.  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 meta sequence first *shrug* */
	    if (s->type == META) {
		metasc = s;
		continue;
	    } /* otherwise it was something else, use it */
268
269
270
271
	    return s;
	}
    }

272
273
    /* If we're here we may have found only meta sequences, if so use one */
    if (metasc)
274
	return metasc;
275

276
#ifdef DEBUG
Chris Allegretta's avatar
Chris Allegretta committed
277
    fprintf(stderr, "Whoops, returning null given func %ld in menu %d\n", (long) func, menu);
278
279
280
281
282
283
284
285
286
#endif
    /* Otherwise... */
    return NULL;
}


/* Add a string to the new shortcut list implementation
   Allows updates to existing entries in the list */
void add_to_sclist(int menu, char *scstring, void *func, int toggle, int execute)
Chris Allegretta's avatar
Chris Allegretta committed
287
{
288
    sc *s;
289

290
291
292
293
    if (sclist == NULL) {
	sclist = nmalloc(sizeof(sc));
	s = sclist;
        s->next = NULL;
294
    } else {
295
296
297
298
299
300
301
302
303
304
305
306
	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;
        }
307
308
    }

309
310
311
312
313
314
315
316
317
318
319
320
    s->type = strtokeytype(scstring);
    s->menu = menu;
    s->toggle = toggle;
    s->keystr = scstring;
    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
321
322
}

Chris Allegretta's avatar
Chris Allegretta committed
323
324
325
326
327
328
329
330
331
332
333
334
335
/* Return the given menu's first shortcut sequence, or the default value
  (2nd arg).  Assumes currmenu for the menu to check*/
int sc_seq_or (void *func, int defaultval) 
{
    const sc *s = first_sc_for(currmenu, func);

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

}

336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
/* Assign the info to the shortcut struct 
   Assumes keystr is already assigned, naturally */
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]);
    } else /* raw */
        s->seq = (int) s->keystr[0];
351
352
353
354
355
356

    /* Override some keys which don't bind as nicely as we'd like */
    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) ' ';
357
358
359
360
361
362
363
364
365
366
367
368
    else if (s->type == RAW && (!strcasecmp(s->keystr, "kup")))
	s->seq = KEY_UP;
    else if (s->type == RAW && (!strcasecmp(s->keystr, "kdown")))
	s->seq = KEY_DOWN;
    else if (s->type == RAW && (!strcasecmp(s->keystr, "kleft")))
	s->seq = KEY_LEFT;
    else if (s->type == RAW && (!strcasecmp(s->keystr, "kright")))
	s->seq = KEY_RIGHT;
    else if (s->type == RAW && (!strcasecmp(s->keystr, "kinsert")))
	s->seq = KEY_IC;
    else if (s->type == RAW && (!strcasecmp(s->keystr, "kdel")))
	s->seq = KEY_DC;
369
370
371
372
    else if (s->type == RAW && (!strcasecmp(s->keystr, "kbsp")))
	s->seq = KEY_BACKSPACE;
    else if (s->type == RAW && (!strcasecmp(s->keystr, "kenter")))
	s->seq = KEY_ENTER;
373
374
375
376
377
378
379
380
381
382
383
384
    else if (s->type == RAW && (!strcasecmp(s->keystr, "kpup")))
	s->seq = KEY_PPAGE;
    else if (s->type == RAW && (!strcasecmp(s->keystr, "kpdown")))
	s->seq = KEY_NPAGE;
#ifdef KEY_HOME
    else if (s->type == RAW && (!strcasecmp(s->keystr, "khome")))
	s->seq = KEY_HOME;
#endif
#ifdef KEY_END
    else if (s->type == RAW && (!strcasecmp(s->keystr, "kend")))
	s->seq = KEY_END;
#endif
385

386
387
388
389
390
391
392
393
394
395
396
397
}

#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
398
	    fprintf(stderr, "Shortcut \"%s\", function: %s, menus %d\n",  s->keystr, f->desc, f->menus);
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
	else
	    fprintf(stderr, "Hmm, didnt find a func for \"%s\"\n", s->keystr);
    }

}
#endif


/* Stuff we need to make at least static here so we can access it below */
const char *cancel_msg = N_("Cancel");

#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

/* Stuff we want to just stun out if we're in TINY mode */
#ifdef NANO_TINY
const char *gototext_msg = "";
Chris Allegretta's avatar
Chris Allegretta committed
422
423
const char *do_para_begin_msg = "";
const char *do_para_end_msg = "";
424
425
426
427
428
429
430
431
432
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
433
434
435
436
437
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;
438
const char *ext_cmd_msg = "";
Chris Allegretta's avatar
Chris Allegretta committed
439
440

#else
441
/* TRANSLATORS: Try to keep the next five strings at most 10 characters. */
Chris Allegretta's avatar
Chris Allegretta committed
442
const char *prev_history_msg = N_("PrevHstory");
443
444
445
446
const char *next_history_msg = N_("NextHstory");
const char *replace_msg = N_("Replace");
const char *no_replace_msg = N_("No Replace");
const char *gototext_msg = N_("Go To Text");
447
/* TRANSLATORS: Try to keep the next three strings at most 12 characters. */
Chris Allegretta's avatar
Chris Allegretta committed
448
const char *whereis_next_msg = N_("WhereIs Next");
449
450
451
#ifndef DISABLE_BROWSER
const char *first_file_msg = N_("First File");
const char *last_file_msg = N_("Last File");
452
453
/* TRANSLATORS: Try to keep the next nine strings at most 16 characters. */
const char *to_files_msg = N_("To Files");
454
455
456
457
458
459
#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");
460
const char *ext_cmd_msg = N_("Execute Command");
461
462
463
#ifdef ENABLE_MULTIBUFFER
const char *new_buffer_msg = N_("New Buffer");
#endif
Chris Allegretta's avatar
Chris Allegretta committed
464
const char *goto_dir_msg = N_("Go To Dir");
465

Chris Allegretta's avatar
Chris Allegretta committed
466
#endif /* NANO_TINY */
467

468
469
/* Initialize all shortcut lists.  If unjustify is TRUE, replace the
 * Uncut shortcut in the main shortcut list with UnJustify. */
470
void shortcut_init(bool unjustify)
471
{
472
    /* TRANSLATORS: Try to keep the following strings at most 10 characters. */
473
474
    const char *get_help_msg = N_("Get Help");
    const char *exit_msg = N_("Exit");
475
    const char *whereis_msg = N_("Where Is");
476
477
478
479
    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");
480
    const char *suspend_msg = N_("Suspend");
481
482
483
484
485
#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
486
    const char *refresh_msg = N_("Refresh");
487
    const char *insert_file_msg =  N_("Insert File");
Chris Allegretta's avatar
Chris Allegretta committed
488
    const char *go_to_line_msg = N_("Go To Line");
489

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

Chris Allegretta's avatar
Chris Allegretta committed
632
#endif
633
#endif /* !DISABLE_HELP */
Chris Allegretta's avatar
Chris Allegretta committed
634

David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
635
#ifndef DISABLE_HELP
636
#define IFSCHELP(help) help
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
637
#else
638
#define IFSCHELP(help) ""
639
#endif
640

641
642
643
644
645
    while (allfuncs != NULL) {
        subnfunc *f = allfuncs;
        allfuncs = (allfuncs)->next;
        free(f);
    }
646

647
#ifndef DISABLE_HELP
648
649
    add_to_funcs(do_help_void, MALL, get_help_msg, nano_help_msg,
	FALSE, VIEW);
650
#endif
Chris Allegretta's avatar
Chris Allegretta committed
651

652
    add_to_funcs((void *) cancel_msg,
653
	(MWHEREIS|MREPLACE|MREPLACE2|MGOTOLINE|MWRITEFILE|MINSERTFILE|MEXTCMD|MSPELL|MWHEREISFILE|MGOTODIR|MYESNO),
654
	cancel_msg, IFSCHELP(nano_cancel_msg), FALSE, VIEW);
655
656

    add_to_funcs(do_exit, MMAIN,
657
#ifdef ENABLE_MULTIBUFFER
658
	/* TRANSLATORS: Try to keep this at most 10 characters. */
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
659
	openfile != NULL && openfile != openfile->next ? N_("Close") :
660
#endif
661
	exit_msg, IFSCHELP(nano_exit_msg), FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
662

663
664
665
    add_to_funcs(do_exit, MHELP, exit_msg, IFSCHELP(nano_exit_msg), FALSE, VIEW);

    add_to_funcs(do_exit, MBROWSER, exit_msg, IFSCHELP(nano_exitbrowser_msg), FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
666

667
    /* TRANSLATORS: Try to keep this at most 10 characters. */
668
    add_to_funcs(do_writeout_void, MMAIN, N_("WriteOut"),
669
	IFSCHELP(nano_writeout_msg), FALSE, NOVIEW);
670

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

677
    /* We allow inserting files in view mode if multibuffers are
678
679
680
681
     * 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. */
682
    add_to_funcs(!ISSET(RESTRICTED) ? do_insertfile_void : nano_disabled_msg,
683
	/* TRANSLATORS: Try to keep this at most 10 characters. */
684
	MMAIN, N_("Read File"), IFSCHELP(nano_insert_msg), FALSE,
685
#ifdef ENABLE_MULTIBUFFER
686
	VIEW);
687
#else
688
	NOVIEW);
689
#endif
Chris Allegretta's avatar
Chris Allegretta committed
690

Chris Allegretta's avatar
Chris Allegretta committed
691
    add_to_funcs(do_search, MMAIN|MBROWSER, whereis_msg,
692
	IFSCHELP(nano_whereis_msg), FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
693

Chris Allegretta's avatar
Chris Allegretta committed
694
    add_to_funcs(do_page_up, MMAIN|MHELP,
695
	prev_page_msg, IFSCHELP(nano_prevpage_msg), FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
696
    add_to_funcs(do_page_down, MMAIN|MHELP,
697
	next_page_msg, IFSCHELP(nano_nextpage_msg), TRUE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
698

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

703
    if (unjustify)
704
	/* TRANSLATORS: Try to keep this at most 10 characters. */
705
706
707
	add_to_funcs(do_uncut_text, MMAIN, N_("UnJustify"), "",
	    FALSE, NOVIEW);

708
    else
709
	/* TRANSLATORS: Try to keep this at most 10 characters. */
710
	add_to_funcs(do_uncut_text, MMAIN, N_("UnCut Text"), IFSCHELP(nano_uncut_msg),
711
	    FALSE, NOVIEW);
Chris Allegretta's avatar
Chris Allegretta committed
712

Chris Allegretta's avatar
Chris Allegretta committed
713
#ifndef NANO_TINY
714
    /* TRANSLATORS: Try to keep this at most 10 characters. */
715
    add_to_funcs(do_cursorpos_void, MMAIN, N_("Cur Pos"), IFSCHELP(nano_cursorpos_msg),
716
	FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
717
#endif
Chris Allegretta's avatar
Chris Allegretta committed
718

719
720
721
    /* 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. */
722
#ifndef DISABLE_SPELLER
723
	if (!ISSET(RESTRICTED))
724
	    /* TRANSLATORS: Try to keep this at most 10 characters. */
725
726
	    add_to_funcs(do_spell, MMAIN, N_("To Spell"), nano_spell_msg,
		TRUE, NOVIEW);
727
#endif
728

729
730
    add_to_funcs(do_first_line,
	(MMAIN|MWHEREIS|MREPLACE|MREPLACE2|MGOTOLINE|MHELP),
731
	first_line_msg, IFSCHELP(nano_firstline_msg), FALSE, VIEW);
732

733
734
    add_to_funcs(do_last_line,
	(MMAIN|MWHEREIS|MREPLACE|MREPLACE2|MGOTOLINE|MHELP),
735
	last_line_msg, IFSCHELP(nano_lastline_msg), TRUE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
736

737

738
    add_to_funcs(do_gotolinecolumn_void, (MMAIN|MWHEREIS),
739
	go_to_line_msg, IFSCHELP(nano_gotoline_msg), FALSE, VIEW);
740

Chris Allegretta's avatar
Chris Allegretta committed
741
#ifdef NANO_TINY
742
    /* TRANSLATORS: Try to keep this at most 10 characters. */
743
    add_to_funcs(do_cursorpos_void, MMAIN, N_("Cur Pos"), IFSCHELP(nano_cursorpos_msg),
Chris Allegretta's avatar
Chris Allegretta committed
744
745
746
747
	FALSE, VIEW);
#endif


748
    add_to_funcs(do_replace, (MMAIN|MWHEREIS), replace_msg, IFSCHELP(nano_replace_msg),
749

750
751
752
753
#ifndef NANO_TINY
	FALSE,
#else
	TRUE,
754
#endif
755
	NOVIEW);
756

757
#ifndef NANO_TINY
758

759
760
    add_to_funcs(do_mark, MMAIN, N_("Mark Text"), 
	nano_mark_msg, FALSE, VIEW);
761

762
763
    add_to_funcs(do_research, (MMAIN|MBROWSER), whereis_next_msg,
	nano_whereis_next_msg, TRUE, VIEW);
764

765
766
    add_to_funcs(do_copy_text, MMAIN, N_("Copy Text"),
	nano_copy_msg, FALSE, NOVIEW);
767

768
769
    add_to_funcs(do_indent_void, MMAIN, N_("Indent Text"),
	nano_indent_msg, FALSE, NOVIEW);
770

771
772
    add_to_funcs(do_unindent, MMAIN, N_("Unindent Text"),
	nano_unindent_msg, TRUE, NOVIEW);
773

774
#endif
775

Chris Allegretta's avatar
Chris Allegretta committed
776
    add_to_funcs(do_page_up, MBROWSER,
777
	prev_page_msg, IFSCHELP(nano_prevpage_msg), FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
778
    add_to_funcs(do_page_down, MBROWSER,
779
	next_page_msg, IFSCHELP(nano_nextpage_msg), TRUE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
780

781

782
    add_to_funcs(do_right, (MMAIN|MBROWSER), N_("Forward"), IFSCHELP(nano_forward_msg),
783
	FALSE, VIEW);
784
    add_to_funcs(do_right, MALL, "", "", FALSE, VIEW);
785

786
    add_to_funcs(do_left, (MMAIN|MBROWSER), N_("Back"), IFSCHELP(nano_back_msg),
787
	FALSE, VIEW);
788
    add_to_funcs(do_left, MALL, "", "", FALSE, VIEW);
789

790
791
792
#ifndef NANO_TINY
    add_to_funcs(do_next_word_void, MMAIN, N_("Next Word"),
	nano_nextword_msg, FALSE, VIEW);
793

794
795
    add_to_funcs(do_prev_word_void, MMAIN, N_("Prev Word"),
	nano_prevword_msg, FALSE, VIEW);
796
#endif
797

Chris Allegretta's avatar
Chris Allegretta committed
798
    add_to_funcs(do_up_void, (MMAIN|MHELP|MBROWSER), N_("Prev Line"),
799
	IFSCHELP(nano_prevline_msg), FALSE, VIEW);
800

Chris Allegretta's avatar
Chris Allegretta committed
801
    add_to_funcs(do_down_void, (MMAIN|MHELP|MBROWSER), N_("Next Line"),
802
	IFSCHELP(nano_nextline_msg), TRUE, VIEW);
803

804
    add_to_funcs(do_home, MMAIN, N_("Home"), IFSCHELP(nano_home_msg),
805
	FALSE, VIEW);
806

807
    add_to_funcs(do_end, MMAIN, N_("End"), IFSCHELP(nano_end_msg),
808
	FALSE, VIEW);
809

810
811
812
#ifndef DISABLE_JUSTIFY
    add_to_funcs(do_para_begin_void, (MMAIN|MWHEREIS), beg_of_par_msg,
	nano_parabegin_msg, FALSE, VIEW);
813

814
815
    add_to_funcs(do_para_end_void, (MMAIN|MWHEREIS), end_of_par_msg,
	nano_paraend_msg, FALSE, VIEW);
816
#endif
817

818
#ifndef NANO_TINY
819
820
    add_to_funcs(do_find_bracket, MMAIN, _("Find Other Bracket"),
	nano_bracket_msg, FALSE, VIEW);
821

822
823
    add_to_funcs(do_scroll_up, MMAIN, N_("Scroll Up"),
	nano_scrollup_msg, FALSE, VIEW);
824

825
826
    add_to_funcs(do_scroll_down, MMAIN, N_("Scroll Down"),
	nano_scrolldown_msg, FALSE, VIEW);
827
828
#endif

829
830
831
832
833
834
835
836
#ifdef ENABLE_MULTIBUFFER
    add_to_funcs(switch_to_prev_buffer_void, MMAIN, _("Previous File"),
	nano_prevfile_msg, FALSE, VIEW);
    add_to_funcs(switch_to_next_buffer_void, MMAIN, N_("Next File"),
	nano_nextfile_msg, TRUE, VIEW);
#endif

    add_to_funcs(do_verbatim_input, MMAIN, N_("Verbatim Input"),
837
	IFSCHELP(nano_verbatim_msg), FALSE, NOVIEW);
838
839
840
    add_to_funcs(do_verbatim_input, MWHEREIS|MREPLACE|MREPLACE2|MEXTCMD|MSPELL,
	"", "", FALSE, NOVIEW);

841
    add_to_funcs(do_tab, MMAIN, N_("Tab"), IFSCHELP(nano_tab_msg),
842
	FALSE, NOVIEW);
843
    add_to_funcs(do_tab, MALL, "", "", FALSE, NOVIEW);
844
    add_to_funcs(do_enter, MMAIN, N_("Enter"), IFSCHELP(nano_enter_msg),
845
	FALSE, NOVIEW);
846
    add_to_funcs(do_enter, MALL, "", "", FALSE, NOVIEW);
847
    add_to_funcs(do_delete, MMAIN, N_("Delete"), IFSCHELP(nano_delete_msg),
848
	FALSE, NOVIEW);
849
    add_to_funcs(do_delete, MALL, "", "", FALSE, NOVIEW);
850
    add_to_funcs(do_backspace, MMAIN, N_("Backspace"), IFSCHELP(nano_backspace_msg),
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
851
#ifndef NANO_TINY
852
	FALSE,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
853
#else
854
	TRUE,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
855
#endif
856
857
858
859
860
861
862
863
864
	NOVIEW);

    add_to_funcs(do_backspace, MALL, "", "",
#ifndef NANO_TINY
	FALSE,
#else
	TRUE,
#endif
	NOVIEW);
865

866
867
868
#ifndef NANO_TINY
    add_to_funcs(do_cut_till_end, MMAIN, N_("CutTillEnd"),
	nano_cut_till_end_msg, TRUE, NOVIEW);
869
#endif
Chris Allegretta's avatar
Chris Allegretta committed
870

871
872
    add_to_funcs(xon_complaint, MMAIN, "", "", FALSE, VIEW);
    add_to_funcs(xoff_complaint, MMAIN, "", "", FALSE, VIEW);
873

874
#ifndef DISABLE_JUSTIFY
875
876
    add_to_funcs(do_full_justify, (MMAIN|MWHEREIS), fulljstify_msg,
	nano_fulljustify_msg, FALSE, NOVIEW);
877
878
#endif

879
#ifndef NANO_TINY
880
881
    add_to_funcs(do_wordlinechar_count, MMAIN, N_("Word Count"),
	nano_wordcount_msg, FALSE, VIEW);
882
#endif
883

884
885
886
887
888
    add_to_funcs(total_refresh, (MMAIN|MHELP), refresh_msg, 
	IFSCHELP(nano_refresh_msg), FALSE, VIEW);

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

890
#ifndef NANO_TINY
891
892
893
    add_to_funcs((void *) case_sens_msg,
	(MWHEREIS|MREPLACE|MWHEREISFILE),
	case_sens_msg, nano_case_msg, FALSE, VIEW);
894

895
896
897
    add_to_funcs((void *) backwards_msg,
	(MWHEREIS|MREPLACE|MWHEREISFILE),
	backwards_msg, nano_reverse_msg, FALSE, VIEW);
898
#endif
899

900
#ifdef HAVE_REGEX_H
901
902
    add_to_funcs((void *) regexp_msg,
	(MWHEREIS|MREPLACE|MWHEREISFILE),
903
	regexp_msg, IFSCHELP(nano_regexp_msg), FALSE, VIEW);
904
#endif
905

906
#ifndef NANO_TINY
907
908
909
    add_to_funcs((void *) prev_history_msg,
	(MWHEREIS|MREPLACE|MREPLACE2|MWHEREISFILE),
	prev_history_msg, nano_prev_history_msg, FALSE, VIEW);
910

911
912
913
    add_to_funcs((void *) next_history_msg,
	(MWHEREIS|MREPLACE|MREPLACE2|MWHEREISFILE),
	next_history_msg, nano_next_history_msg, FALSE, VIEW);
914
#endif
915

916
    add_to_funcs((void *) no_replace_msg, MREPLACE,
917
	no_replace_msg, IFSCHELP(nano_whereis_msg), FALSE, VIEW);
918

919
    add_to_funcs((void *) gototext_msg, MGOTOLINE,
920
	gototext_msg, IFSCHELP(nano_whereis_msg), TRUE, VIEW);
921

922
#ifndef DISABLE_BROWSER
923
    if (!ISSET(RESTRICTED))
924
925
926
	add_to_funcs((void *) to_files_msg,
	    (MGOTOLINE|MINSERTFILE),
	    to_files_msg, nano_tofiles_msg, FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
927
#endif
Chris Allegretta's avatar
Chris Allegretta committed
928

929
#ifndef NANO_TINY
930
931
932
933
934
935
    /* 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. */
936
    if (!ISSET(RESTRICTED))
937
938
        add_to_funcs((void *) dos_format_msg, MWRITEFILE,
            dos_format_msg, nano_dos_msg, FALSE, NOVIEW);
939

940
    if (!ISSET(RESTRICTED))
941
942
        add_to_funcs((void *) mac_format_msg, MWRITEFILE,
            mac_format_msg, nano_mac_msg, FALSE, NOVIEW);
943

944
    if (!ISSET(RESTRICTED))
945
946
        add_to_funcs((void *) append_msg, MWRITEFILE,
            append_msg, nano_append_msg, FALSE, NOVIEW);
947

948
    if (!ISSET(RESTRICTED))
949
950
        add_to_funcs((void *) prepend_msg, MWRITEFILE,
            prepend_msg, nano_prepend_msg, FALSE, NOVIEW);
951

952
    if (!ISSET(RESTRICTED))
953
954
        add_to_funcs((void *) backup_file_msg, MWRITEFILE,
            backup_file_msg, nano_backup_msg, FALSE, NOVIEW);
955
#endif
956

957
#ifndef NANO_TINY
958
959
    /* If we're using restricted mode, command execution is disabled.
     * It's useless since inserting files is disabled. */
960
    if (!ISSET(RESTRICTED))
961
962
        add_to_funcs((void *) ext_cmd_msg, MINSERTFILE,
	    ext_cmd_msg, nano_execute_msg, FALSE, NOVIEW);
963

964
#ifdef ENABLE_MULTIBUFFER
965
966
    /* If we're using restricted mode, the multibuffer toggle is
     * disabled.  It's useless since inserting files is disabled. */
967
    if (!ISSET(RESTRICTED))
968
	add_to_funcs((void *) new_buffer_msg, MINSERTFILE,
969
	new_buffer_msg, nano_multibuffer_msg, FALSE, NOVIEW);
970
#endif
971

972
    add_to_funcs((void *)  insert_file_msg, MEXTCMD,
973
	insert_file_msg, IFSCHELP(nano_insert_msg), FALSE, VIEW);
974

David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
975
#ifdef ENABLE_MULTIBUFFER
976
977
     add_to_funcs((void *) new_buffer_msg, MEXTCMD,
	new_buffer_msg, nano_multibuffer_msg, FALSE, NOVIEW);
978
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
979
#endif
980

981
#ifndef DISABLE_HELP
982
983
    add_to_funcs((void *) refresh_msg, MHELP,
	refresh_msg, nano_refresh_msg, FALSE, VIEW);
984
985
#endif

986
#ifndef DISABLE_BROWSER
987

988
989
990
    add_to_funcs((void *) first_file_msg,
	(MBROWSER|MWHEREISFILE),
	first_file_msg, nano_firstfile_msg, FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
991

992
993
994
    add_to_funcs((void *) last_file_msg,
	(MBROWSER|MWHEREISFILE),
	last_file_msg, nano_lastfile_msg, FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
995

996
997
    add_to_funcs((void *) goto_dir_msg, MBROWSER,
	goto_dir_msg, nano_gotodir_msg, FALSE, VIEW);
998
999
#endif

1000
    currmenu = MMAIN;
1001

1002
1003
1004
1005
#ifndef NANO_TINY
    add_to_sclist(MALL, "^G", do_help_void, 0, TRUE);
    add_to_sclist(MALL, "F1", do_help_void, 0, TRUE);
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1006
1007
    add_to_sclist(MMAIN|MHELP|MBROWSER, "^X", do_exit, 0, TRUE);
    add_to_sclist(MMAIN|MHELP|MBROWSER, "F2", do_exit, 0, TRUE);
1008
1009
1010
1011
    add_to_sclist(MMAIN, "^_", do_gotolinecolumn_void, 0, TRUE);
    add_to_sclist(MMAIN, "F13", 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);
1012
#ifndef DISABLE_JUSTIFY
1013
1014
1015
1016
1017
    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);
1018
    add_to_sclist(MMAIN, "kinsert", do_insertfile_void, 0, TRUE);
Chris Allegretta's avatar
Chris Allegretta committed
1019
1020
    add_to_sclist(MMAIN|MBROWSER, "^W", do_search, 0, TRUE);
    add_to_sclist(MMAIN|MBROWSER, "F6", do_search, 0, TRUE);
1021
1022
1023
1024
1025
1026
    add_to_sclist(MMAIN|MBROWSER|MHELP|MWHEREISFILE, "^Y", do_page_up, 0, TRUE);
    add_to_sclist(MMAIN|MBROWSER|MHELP|MWHEREISFILE, "F7", do_page_up, 0, TRUE);
    add_to_sclist(MMAIN|MBROWSER|MHELP|MWHEREISFILE, "kpup", do_page_up, 0, TRUE);
    add_to_sclist(MMAIN|MBROWSER|MHELP|MWHEREISFILE, "^V", do_page_down, 0, TRUE);
    add_to_sclist(MMAIN|MBROWSER|MHELP|MWHEREISFILE, "F8", do_page_down, 0, TRUE);
    add_to_sclist(MMAIN|MBROWSER|MHELP|MWHEREISFILE, "kpdown", do_page_down, 0, TRUE);
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
    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);
#ifndef NANO_TINY
    add_to_sclist(MMAIN, "^T", do_spell, 0, TRUE);
    add_to_sclist(MMAIN, "F12", do_spell, 0, TRUE);
#endif
    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, "^\\", 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", (void *) no_replace_msg, 0, FALSE);
    add_to_sclist(MWHEREIS, "^T", do_gotolinecolumn_void, 0, TRUE);
#ifndef NANO_TINY
    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(MALL, "M-W", do_research, 0, TRUE);
Chris Allegretta's avatar
Chris Allegretta committed
1051
    add_to_sclist(MALL, "F16", do_research, 0, TRUE);
1052
1053
1054
1055
    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);
1056
1057
1058
1059
    add_to_sclist(MALL, "^F", do_right, 0, TRUE);
    add_to_sclist(MALL, "kright", do_right, 0, TRUE);
    add_to_sclist(MALL, "^B", do_left, 0, TRUE);
    add_to_sclist(MALL, "kleft", do_left, 0, TRUE);
1060
1061
1062
    add_to_sclist(MMAIN, "^Space", do_next_word_void, 0, TRUE);
    add_to_sclist(MMAIN, "M-Space", do_prev_word_void, 0, TRUE);
#endif
1063
1064
    add_to_sclist(MMAIN, "^Q", xon_complaint, 0, TRUE);
    add_to_sclist(MMAIN, "^S", xoff_complaint, 0, TRUE);
1065
    add_to_sclist(MALL, "^P", do_up_void, 0, TRUE);
1066
    add_to_sclist(MALL, "kup", do_up_void, 0, TRUE);
1067
    add_to_sclist(MALL, "^N", do_down_void, 0, TRUE);
1068
    add_to_sclist(MALL, "kdown", do_down_void, 0, TRUE);
1069
    add_to_sclist(MALL, "^A", do_home, 0, TRUE);
1070
    add_to_sclist(MALL, "khome", do_home, 0, TRUE);
1071
    add_to_sclist(MALL, "^E", do_end, 0, TRUE);
1072
    add_to_sclist(MALL, "kend", do_end, 0, TRUE);
1073
#ifndef DISABLE_JUSTIFY
1074
1075
1076
1077
1078
1079
1080
1081
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACE2,
	"^W", do_para_begin_void, 0, TRUE);
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACE2,
	"^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
1082
#endif
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
    add_to_sclist(MWHEREIS,
	"M-C", (void *) case_sens_msg, 0, FALSE);
    add_to_sclist(MREPLACE,
	"M-C", (void *) case_sens_msg, 0, FALSE);
    add_to_sclist(MREPLACE2,
	"M-C", (void *) case_sens_msg, 0, FALSE);
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACE2,
	"M-B", (void *) backwards_msg, 0, FALSE);
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACE2,
	"M-R", (void *) regexp_msg, 0, FALSE);

    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);
1098
1099
1100
1101
1102
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACE2|MGOTOLINE|MHELP,
	"^Y", do_first_line, 0, TRUE);
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACE2|MGOTOLINE|MHELP,
	"^V", do_last_line, 0, TRUE);

Chris Allegretta's avatar
Chris Allegretta committed
1103
1104
1105
1106
    add_to_sclist(MBROWSER|MWHEREISFILE, "M-\\", (void *) first_file_msg, 0, TRUE);
    add_to_sclist(MBROWSER|MWHEREISFILE, "M-|", (void *) first_file_msg, 0, TRUE);
    add_to_sclist(MBROWSER|MWHEREISFILE, "M-/", (void *) last_file_msg, 0, TRUE);
    add_to_sclist(MBROWSER|MWHEREISFILE, "M-?", (void *) last_file_msg, 0, TRUE);
1107
1108
1109
1110
1111
1112
#ifndef NANO_TINY
    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);
1113
1114
#endif

1115
1116
1117
1118
1119
1120
#ifdef ENABLE_MULTIBUFFER
    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);
#endif
1121
    add_to_sclist(MALL, "M-V", do_verbatim_input, 0, TRUE);
1122
#ifndef NANO_TINY
Chris Allegretta's avatar
Chris Allegretta committed
1123
    add_to_sclist(MALL, "M-T", do_cut_till_end, 0, TRUE);
1124
#ifndef DISABLE_JUSTIFY
1125
    add_to_sclist(MALL, "M-J", do_full_justify, 0, TRUE);
1126
#endif
1127
    add_to_sclist(MMAIN, "M-D", do_wordlinechar_count, 0, TRUE);
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
    add_to_sclist(MMAIN, "M-X", do_toggle, NO_HELP, TRUE);
    add_to_sclist(MMAIN, "M-C", do_toggle, CONST_UPDATE, TRUE);
    add_to_sclist(MMAIN, "M-O", do_toggle, MORE_SPACE, TRUE);
    add_to_sclist(MMAIN, "M-S", do_toggle, SMOOTH_SCROLL, TRUE);
    add_to_sclist(MMAIN, "M-P", do_toggle, WHITESPACE_DISPLAY, TRUE);
    add_to_sclist(MMAIN, "M-Y", do_toggle, NO_COLOR_SYNTAX, TRUE);
    add_to_sclist(MMAIN, "M-H", do_toggle, SMART_HOME, TRUE);
    add_to_sclist(MMAIN, "M-I", do_toggle, AUTOINDENT, TRUE);
    add_to_sclist(MMAIN, "M-K", do_toggle, CUT_TO_END, TRUE);
    add_to_sclist(MMAIN, "M-L", do_toggle, NO_WRAP, TRUE);
    add_to_sclist(MMAIN, "M-Q", do_toggle, TABS_TO_SPACES, TRUE);
    add_to_sclist(MMAIN, "M-B", do_toggle, BACKUP_FILE, TRUE);
    add_to_sclist(MMAIN, "M-F", do_toggle, MULTIBUFFER, TRUE);
    add_to_sclist(MMAIN, "M-M", do_toggle, USE_MOUSE, TRUE);
    add_to_sclist(MMAIN, "M-N", do_toggle, NO_CONVERT, TRUE);
    add_to_sclist(MMAIN, "M-Z", do_toggle, SUSPEND, TRUE);
#endif
1145
1146
    add_to_sclist(MGOTOLINE, "^T", (void *) gototext_msg, 0, FALSE);
    add_to_sclist(MINSERTFILE|MEXTCMD, "M-F", (void *) new_buffer_msg, 0, FALSE);
1147
    add_to_sclist((MWHEREIS|MREPLACE|MREPLACE2|MGOTOLINE|MWRITEFILE|MINSERTFILE|MEXTCMD|MSPELL|MWHEREISFILE|MGOTODIR|MYESNO),
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
	"^C", (void *) cancel_msg, 0, FALSE);
    add_to_sclist(MHELP, "^X", do_exit, 0, TRUE);
    add_to_sclist(MHELP, "F2", do_exit, 0, TRUE);
    add_to_sclist(MWRITEFILE, "M-D", (void *) dos_format_msg, 0, FALSE);
    add_to_sclist(MWRITEFILE, "M-M", (void *) mac_format_msg, 0, FALSE);
    add_to_sclist(MWRITEFILE, "M-A", (void *) append_msg, 0, FALSE);
    add_to_sclist(MWRITEFILE, "M-P", (void *) prepend_msg, 0, FALSE);
    add_to_sclist(MWRITEFILE, "M-B", (void *) backup_file_msg, 0, FALSE);
    add_to_sclist(MWRITEFILE, "^T", (void *) to_files_msg, 0, FALSE);
    add_to_sclist(MINSERTFILE, "^T", (void *) to_files_msg, 0, FALSE);
    add_to_sclist(MINSERTFILE, "^X", (void *) ext_cmd_msg, 0, FALSE);
1159
    add_to_sclist(MMAIN, "^Z", do_suspend_void, 0, FALSE);
1160
    add_to_sclist(MMAIN, "^L", total_refresh, 0, TRUE);
1161
1162
1163
1164
1165
1166
1167
    add_to_sclist(MALL, "^I", do_tab, 0, TRUE);
    add_to_sclist(MALL, "^M", do_enter, 0, TRUE);
    add_to_sclist(MALL, "kenter", do_enter, 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
1168

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

1173
}
1174

1175
/* Free the given shortcut. */
1176
1177
1178
void free_shortcutage(shortcut **shortcutage)
{
    assert(shortcutage != NULL);
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1179

1180
1181
1182
1183
1184
1185
1186
    while (*shortcutage != NULL) {
	shortcut *ps = *shortcutage;
	*shortcutage = (*shortcutage)->next;
	free(ps);
    }
}

1187
const subnfunc *sctofunc(sc *s)
1188
{
1189
    subnfunc *f;
1190

1191
1192
    for (f = allfuncs; f != NULL && s->scfunc != f->scfunc; f = f->next)
	;
1193

1194
    return f;
1195
1196
}

1197
1198
1199
1200
#ifndef NANO_TINY
/* Now lets come up with a single (hopefully)
   function to get a string for each flag */
char *flagtostr(int flag)
1201
{
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
   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");
        default:
            return "?????";
    }
}
Chris Allegretta's avatar
Chris Allegretta committed
1239
#endif /* NANO_TINY */
1240

1241
1242
1243
1244
1245
1246
1247
1248
1249
/* Interpret the string given by the rc file and return a
    shortcut struct, complete with proper value for execute */
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
1250
1251

#ifndef DISABLE_HELP
1252
1253
    if (!strcasecmp(input, "help"))
	s->scfunc = do_help_void;
Chris Allegretta's avatar
Chris Allegretta committed
1254
1255
1256
    else 
#endif
    if (!strcasecmp(input, "cancel")) {
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
	s->scfunc = (void *) cancel_msg;
	s->execute = FALSE;
    } else if (!strcasecmp(input, "exit"))
	s->scfunc = do_exit;
    else if (!strcasecmp(input, "writeout"))
	s->scfunc = do_writeout_void;
    else if (!strcasecmp(input, "insert"))
	s->scfunc = do_insertfile_void;
    else if (!strcasecmp(input, "whereis"))
	s->scfunc = do_search;
    else if (!strcasecmp(input, "up"))
1268
	s->scfunc = do_up_void;
1269
    else if (!strcasecmp(input, "down"))
1270
1271
1272
1273
1274
1275
	s->scfunc = do_down_void;
    else if (!strcasecmp(input, "pageup")
	|| !strcasecmp(input, "prevpage"))
	s->scfunc = do_page_up;
    else if (!strcasecmp(input, "pagedown")
	|| !strcasecmp(input, "nextpage"))
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
	s->scfunc = do_page_down;
    else if (!strcasecmp(input, "cut"))
	s->scfunc = do_cut_text_void;
    else if (!strcasecmp(input, "uncut"))
	s->scfunc = do_uncut_text;
    else if (!strcasecmp(input, "curpos") ||
	!strcasecmp(input, "cursorpos"))
	s->scfunc = do_cursorpos_void;
    else if (!strcasecmp(input, "firstline"))
	s->scfunc = do_first_line;
    else if (!strcasecmp(input, "lastline"))
	s->scfunc = do_last_line;
    else if (!strcasecmp(input, "gotoline"))
	s->scfunc = do_gotolinecolumn_void;
    else if (!strcasecmp(input, "replace"))
	s->scfunc = do_replace;
1292
#ifndef DISABLE_JUSTIFY
Chris Allegretta's avatar
Chris Allegretta committed
1293
1294
    else if (!strcasecmp(input, "justify"))
	s->scfunc = do_justify_void;
1295
1296
1297
1298
1299
1300
1301
1302
    else if (!strcasecmp(input, "beginpara"))
	s->scfunc = do_para_begin_void;
    else if (!strcasecmp(input, "endpara"))
	s->scfunc = do_para_end_void;
    else if (!strcasecmp(input, "fulljustify"))
	s->scfunc = do_full_justify;
#endif
#ifndef NANO_TINY
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
    else if (!strcasecmp(input, "mark"))
	s->scfunc = do_mark;
    else if (!strcasecmp(input, "searchagain") ||
		!strcasecmp(input, "research"))
	s->scfunc = do_research;
    else if (!strcasecmp(input, "copytext"))
	s->scfunc = do_copy_text;
    else if (!strcasecmp(input, "indent"))
	s->scfunc = do_indent_void;
    else if (!strcasecmp(input, "unindent"))
	s->scfunc = do_unindent;
Chris Allegretta's avatar
Chris Allegretta committed
1314
1315
1316
1317
    else if (!strcasecmp(input, "scrollup"))
	s->scfunc = do_scroll_up;
    else if (!strcasecmp(input, "scrolldown"))
	s->scfunc = do_scroll_down;
1318
1319
    else if (!strcasecmp(input, "nextword"))
	s->scfunc = do_next_word_void;
1320
1321
    else if (!strcasecmp(input, "suspend"))
	s->scfunc = do_suspend_void;
1322
1323
1324
1325
1326
1327
    else if (!strcasecmp(input, "prevword"))
	s->scfunc = do_prev_word_void;
    else if (!strcasecmp(input, "findbracket"))
	s->scfunc = do_find_bracket;
    else if (!strcasecmp(input, "wordcount"))
	s->scfunc = do_wordlinechar_count;
Chris Allegretta's avatar
Chris Allegretta committed
1328
    else if (!strcasecmp(input, "prevhistory")) {
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
	s->scfunc = (void *) prev_history_msg;
	s->execute = FALSE;
    } else if (!strcasecmp(input, "nexthistory")) {
	s->scfunc = (void *) next_history_msg;
	s->execute = FALSE;
    } else if (!strcasecmp(input, "nohelp") ||
		!strcasecmp(input, "nohelp")) {
	s->scfunc = (void *) do_toggle;
	s->execute = FALSE;
	s->toggle = NO_HELP;
    } else if (!strcasecmp(input, "constupdate")) {
	s->scfunc = (void *) do_toggle;
	s->execute = FALSE;
	s->toggle = CONST_UPDATE;
    } else if (!strcasecmp(input, "morespace")) {
	s->scfunc = (void *) do_toggle;
	s->execute = FALSE;
	s->toggle = MORE_SPACE;
    } else if (!strcasecmp(input, "smoothscroll")) {
	s->scfunc = (void *) do_toggle;
	s->execute = FALSE;
	s->toggle = SMOOTH_SCROLL;
1351
    } else if (!strcasecmp(input, "whitespacedisplay")) {
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
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
	s->scfunc = (void *) do_toggle;
	s->execute = FALSE;
	s->toggle = WHITESPACE_DISPLAY;
    } else if (!strcasecmp(input, "nosyntax")) {
	s->scfunc = (void *) do_toggle;
	s->execute = FALSE;
	s->toggle = NO_COLOR_SYNTAX;
    } else if (!strcasecmp(input, "smarthome")) {
	s->scfunc = (void *) do_toggle;
	s->execute = FALSE;
	s->toggle = SMART_HOME;
    } else if (!strcasecmp(input, "autoindent")) {
	s->scfunc = (void *) do_toggle;
	s->execute = FALSE;
	s->toggle = AUTOINDENT;
    } else if (!strcasecmp(input, "cuttoend")) {
	s->scfunc = (void *) do_toggle;
	s->execute = FALSE;
	s->toggle = CUT_TO_END;
    } else if (!strcasecmp(input, "nowrap")) {
	s->scfunc = (void *) do_toggle;
	s->execute = FALSE;
	s->toggle = NO_WRAP;
    } else if (!strcasecmp(input, "tabstospaces")) {
	s->scfunc = (void *) do_toggle;
	s->execute = FALSE;
	s->toggle = TABS_TO_SPACES;
    } else if (!strcasecmp(input, "backupfile")) {
	s->scfunc = (void *) do_toggle;
	s->execute = FALSE;
	s->toggle = BACKUP_FILE;
    } else if (!strcasecmp(input, "mutlibuffer")) {
	s->scfunc = (void *) do_toggle;
	s->execute = FALSE;
	s->toggle = MULTIBUFFER;
    } else if (!strcasecmp(input, "mouse")) {
	s->scfunc = (void *) do_toggle;
	s->execute = FALSE;
	s->toggle = USE_MOUSE;
    } else if (!strcasecmp(input, "noconvert")) {
	s->scfunc = (void *) do_toggle;
	s->execute = FALSE;
	s->toggle = NO_CONVERT;
1395
    } else if (!strcasecmp(input, "suspendenable")) {
1396
1397
1398
	s->scfunc = (void *) do_toggle;
	s->execute = FALSE;
	s->toggle = SUSPEND;
1399
    }
Chris Allegretta's avatar
Chris Allegretta committed
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
#endif /* NANO_TINY */
    else if (!strcasecmp(input, "right") ||
		!strcasecmp(input, "forward"))
	s->scfunc = do_right;
    else if (!strcasecmp(input, "left") ||
		!strcasecmp(input, "back"))
	s->scfunc = do_left;
    else if (!strcasecmp(input, "up") ||
		!strcasecmp(input, "prevline"))
	s->scfunc = do_up_void;
    else if (!strcasecmp(input, "down") ||
		!strcasecmp(input, "nextline"))
	s->scfunc = do_down_void;
    else if (!strcasecmp(input, "home"))
	s->scfunc = do_home;
    else if (!strcasecmp(input, "end"))
	s->scfunc = do_end;
#ifdef ENABLE_MULTIBUFFER
    else if (!strcasecmp(input, "prevbuf"))
	s->scfunc = switch_to_prev_buffer_void;
    else if (!strcasecmp(input, "nextbuf"))
	s->scfunc = switch_to_next_buffer_void;
#endif
    else if (!strcasecmp(input, "verbatim"))
	s->scfunc = do_verbatim_input;
    else if (!strcasecmp(input, "tab"))
	s->scfunc = do_tab;
    else if (!strcasecmp(input, "enter"))
	s->scfunc = do_enter;
    else if (!strcasecmp(input, "delete"))
	s->scfunc = do_delete;
    else if (!strcasecmp(input, "refresh"))
	s->scfunc = total_refresh;
    else if (!strcasecmp(input, "casesens")) {
	s->scfunc = (void *) case_sens_msg;
	s->execute = FALSE;
    } else if (!strcasecmp(input, "regexp") ||
		!strcasecmp(input, "regex")) {
	s->scfunc = (void *) regexp_msg;
	s->execute = FALSE;
    } else if (!strcasecmp(input, "dontreplace")) {
	s->scfunc = (void *) no_replace_msg;
	s->execute = FALSE;
    } else if (!strcasecmp(input, "gototext")) {
	s->scfunc = (void *) gototext_msg;
	s->execute = FALSE;
    } else if (!strcasecmp(input, "browser") ||
		!strcasecmp(input, "tofiles")) {
	s->scfunc = (void *) to_files_msg;
	s->execute = FALSE;
    } else if (!strcasecmp(input, "dosformat")) {
	s->scfunc = (void *) dos_format_msg;
	s->execute = FALSE;
    } else if (!strcasecmp(input, "macformat")) {
	s->scfunc = (void *) mac_format_msg;
	s->execute = FALSE;
    } else if (!strcasecmp(input, "append")) {
	s->scfunc = (void *) append_msg;
	s->execute = FALSE;
    } else if (!strcasecmp(input, "prepend")) {
	s->scfunc = (void *) prepend_msg;
	s->execute = FALSE;
    } else if (!strcasecmp(input, "backup")) {
	s->scfunc = (void *) backup_file_msg;
	s->execute = FALSE;
#ifdef ENABLE_MULTIBUFFER
    } else if (!strcasecmp(input, "newbuffer")) {
	s->scfunc = (void *) new_buffer_msg;
	s->execute = FALSE;
#endif
    } else if (!strcasecmp(input, "firstfile")) {
	s->scfunc = (void *) first_file_msg;
	s->execute = FALSE;
    } else if (!strcasecmp(input, "lastfile")) {
	s->scfunc = (void *) last_file_msg;
	s->execute = FALSE;
1476
1477
1478
1479
    } else {
	free(s);
	return NULL;
    }
1480

1481
    return s;
1482

1483
}
1484

Chris Allegretta's avatar
Chris Allegretta committed
1485
#ifdef ENABLE_NANORC
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
/* Same thing as abnove but for the menu */
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;
}
1522
1523
#endif

Chris Allegretta's avatar
Chris Allegretta committed
1524

1525
1526
1527
#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
1528
1529
 * 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
1530
1531
 * function unless debugging is turned on. */
void thanks_for_all_the_fish(void)
1532
{
1533
1534
1535
1536
    delwin(topwin);
    delwin(edit);
    delwin(bottomwin);

Chris Allegretta's avatar
Chris Allegretta committed
1537
1538
1539
#ifndef DISABLE_JUSTIFY
    if (quotestr != NULL)
	free(quotestr);
1540
1541
#ifdef HAVE_REGEX_H
    regfree(&quotereg);
1542
1543
    if (quoteerr != NULL)
	free(quoteerr);
1544
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1545
#endif
1546
#ifndef NANO_TINY
1547
1548
1549
    if (backup_dir != NULL)
        free(backup_dir);
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1550
#ifndef DISABLE_OPERATINGDIR
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
    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);
1563
#endif
1564
1565
1566
    if (answer != NULL)
	free(answer);
    if (cutbuffer != NULL)
Chris Allegretta's avatar
Chris Allegretta committed
1567
	free_filestruct(cutbuffer);
1568
1569
1570
#ifndef DISABLE_JUSTIFY
    if (jusbuffer != NULL)
	free_filestruct(jusbuffer);
1571
#endif
1572
#ifndef NANO_TINY
1573
    /* Free the memory associated with each toggle. */
1574
1575
    while (toggles != NULL) {
	toggle *t = toggles;
1576

1577
1578
1579
1580
	toggles = toggles->next;
	free(t);
    }
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1581
    /* Free the memory associated with each open file buffer. */
1582
    if (openfile != NULL)
1583
	free_openfilestruct(openfile);
Chris Allegretta's avatar
Chris Allegretta committed
1584
#ifdef ENABLE_COLOR
1585
1586
    if (syntaxstr != NULL)
	free(syntaxstr);
Chris Allegretta's avatar
Chris Allegretta committed
1587
1588
1589
1590
1591
1592
1593
1594
    while (syntaxes != NULL) {
	syntaxtype *bill = syntaxes;

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

	    syntaxes->extensions = bob->next;
1595
	    free(bob->ext_regex);
1596
1597
1598
1599
	    if (bob->ext != NULL) {
		regfree(bob->ext);
		free(bob->ext);
	    }
Chris Allegretta's avatar
Chris Allegretta committed
1600
1601
1602
1603
1604
1605
	    free(bob);
	}
	while (syntaxes->color != NULL) {
	    colortype *bob = syntaxes->color;

	    syntaxes->color = bob->next;
1606
	    free(bob->start_regex);
1607
1608
1609
1610
	    if (bob->start != NULL) {
		regfree(bob->start);
		free(bob->start);
	    }
1611
1612
	    if (bob->end_regex != NULL)
		free(bob->end_regex);
1613
	    if (bob->end != NULL) {
1614
		regfree(bob->end);
1615
1616
		free(bob->end);
	    }
Chris Allegretta's avatar
Chris Allegretta committed
1617
1618
1619
1620
1621
1622
	    free(bob);
	}
	syntaxes = syntaxes->next;
	free(bill);
    }
#endif /* ENABLE_COLOR */
1623
#ifndef NANO_TINY
1624
    /* Free the search and replace history lists. */
1625
1626
1627
1628
    if (searchage != NULL)
	free_filestruct(searchage);
    if (replaceage != NULL)
	free_filestruct(replaceage);
1629
#endif
1630
#ifdef ENABLE_NANORC
1631
1632
    if (homedir != NULL)
	free(homedir);
1633
#endif
1634
}
1635
#endif /* DEBUG */
1636