global.c 57.2 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   *
 *   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
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
filestruct *cutbottom = NULL;
73
#ifndef DISABLE_JUSTIFY
74
75
filestruct *jusbuffer = NULL;
	/* The buffer where we store unjustified text. */
76
#endif
77
78
79
partition *filepart = NULL;
	/* The partition where we store a portion of the current
	 * file. */
80
openfilestruct *openfile = NULL;
81
	/* The list of all open file buffers. */
82

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

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

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

118
119
120
bool nodelay_mode = FALSE;
	/* Are we in nodelay mode (checking for a cancel wile doing something */

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

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

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

140
#ifndef DISABLE_SPELLER
141
142
char *alt_speller = NULL;
	/* The command to use for the alternate spell checker. */
143
144
#endif

145
#ifdef ENABLE_COLOR
146
syntaxtype *syntaxes = NULL;
147
	/* The global list of color syntaxes. */
148
char *syntaxstr = NULL;
149
	/* The color syntax name specified on the command line. */
150

151
152
#endif

153
154
155
156
bool edit_refresh_needed = NULL;
	/* Did a command mangle enough of the buffer refresh that we 
	   should repaint the screen */

157
158
const shortcut *currshortcut;
	/* The current shortcut list we're using. */
159
160
161
162
163
164
165
166
int currmenu;
	/* The currently loaded menu */

sc *sclist = NULL;
	/* New shortcut key struct */
subnfunc *allfuncs = NULL;
	/* New struct for the function list */

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

182
/* Regular expressions. */
183
#ifdef HAVE_REGEX_H
184
185
186
187
188
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
189
#endif
190

191
192
int reverse_attr = A_REVERSE;
	/* The curses attribute we use for reverse video. */
193

194
char *homedir = NULL;
195
	/* The user's home directory, from $HOME or /etc/passwd. */
196

197
198
/* Return the number of entries in the shortcut list s for a given menu. */
size_t length_of_list(int menu)
199
{
200
    subnfunc *f;
201
    size_t i = 0;
202

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

214
215
216
/* Set type of function based on the string */
function_type strtokeytype(char *str)
{
217
    if (str[0] ==  'M' || str[0] == 'm')
218
        return META;
219
    else if (str[0] == '^')
220
        return CONTROL;
221
    else if (str[0] ==  'F' || str[0] == 'F')
222
        return FKEY;
223
    else
224
225
226
227
228
	return RAW;
}

/* Add a string to the new function list strict.
   Does not allow updates, yet anyway */
229
void add_to_funcs(short func, int menus, const char *desc, const char *help,
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
    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;
248
#ifndef DISABLE_HELP
249
250
251
252
253
254
    f->help = help;
    f->blank_after = blank_after;
#endif

#ifdef DEBUG
    fprintf(stderr, "Added func \"%s\"", f->desc);
255
#endif
256
257
}

258
const sc *first_sc_for(int menu, short func) {
259
    const sc *s;
260
    const sc *metasc = NULL;
261
262
263

    for (s = sclist; s != NULL; s = s->next) {
	if ((s->menu & menu) && s->scfunc == func) {
264
265
266
267
268
269
270
271
	    /* 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 */
272
273
274
275
	    return s;
	}
    }

276
277
    /* If we're here we may have found only meta sequences, if so use one */
    if (metasc)
278
	return metasc;
279

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


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

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

313
314
315
316
317
318
319
320
321
322
323
324
    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
325
326
}

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

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

}

340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
/* 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];
355
356
357
358
359
360

    /* 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) ' ';
361
362
363
364
365
366
367
368
369
370
371
372
    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;
373
374
375
376
    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;
377
378
379
380
381
382
383
384
385
386
387
388
    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
389

390
391
392
393
394
395
396
397
398
399
400
401
}

#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
402
	    fprintf(stderr, "Shortcut \"%s\", function: %s, menus %d\n",  s->keystr, f->desc, f->menus);
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
	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
426
427
const char *do_para_begin_msg = "";
const char *do_para_end_msg = "";
428
429
430
431
432
433
434
435
436
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
437
438
439
440
441
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;
442
const char *ext_cmd_msg = "";
Chris Allegretta's avatar
Chris Allegretta committed
443
444

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

Chris Allegretta's avatar
Chris Allegretta committed
470
#endif /* NANO_TINY */
471

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

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

Chris Allegretta's avatar
Chris Allegretta committed
638
#endif
639
#endif /* !DISABLE_HELP */
Chris Allegretta's avatar
Chris Allegretta committed
640

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

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

653
    add_to_funcs(DO_HELP_VOID, MALL, get_help_msg, IFSCHELP(nano_help_msg),
654
	FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
655

656
    add_to_funcs( CANCEL_MSG,
657
	(MWHEREIS|MREPLACE|MREPLACE2|MGOTOLINE|MWRITEFILE|MINSERTFILE|MEXTCMD|MSPELL|MWHEREISFILE|MGOTODIR|MYESNO),
658
	cancel_msg, IFSCHELP(nano_cancel_msg), FALSE, VIEW);
659

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

667
    add_to_funcs(DO_EXIT, MHELP, exit_msg, IFSCHELP(nano_exit_msg), FALSE, VIEW);
668

669
#ifndef DISABLE_BROWSER
670
    add_to_funcs(DO_EXIT, MBROWSER, exit_msg, IFSCHELP(nano_exitbrowser_msg), FALSE, VIEW);
671
#endif
Chris Allegretta's avatar
Chris Allegretta committed
672

673
    /* TRANSLATORS: Try to keep this at most 10 characters. */
674
    add_to_funcs(DO_WRITEOUT_VOID, MMAIN, N_("WriteOut"),
675
	IFSCHELP(nano_writeout_msg), FALSE, NOVIEW);
676

677
#ifndef DISABLE_JUSTIFY
678
    /* TRANSLATORS: Try to keep this at most 10 characters. */
679
    add_to_funcs(DO_JUSTIFY_VOID, MMAIN, N_("Justify"),
680
	nano_justify_msg, TRUE, NOVIEW);
681
#endif
682

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

697
    add_to_funcs(DO_SEARCH, MMAIN|MBROWSER, whereis_msg,
698
	IFSCHELP(nano_whereis_msg), FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
699

700
    add_to_funcs(DO_PAGE_UP, MMAIN|MHELP,
701
	prev_page_msg, IFSCHELP(nano_prevpage_msg), FALSE, VIEW);
702
    add_to_funcs(DO_PAGE_DOWN, MMAIN|MHELP,
703
	next_page_msg, IFSCHELP(nano_nextpage_msg), TRUE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
704

705

706
    /* TRANSLATORS: Try to keep this at most 10 characters. */
707
    add_to_funcs(DO_CUT_TEXT_VOID, MMAIN, N_("Cut Text"), IFSCHELP(nano_cut_msg),
708
	FALSE, NOVIEW);
Chris Allegretta's avatar
Chris Allegretta committed
709

710
    if (unjustify)
711
	/* TRANSLATORS: Try to keep this at most 10 characters. */
712
	add_to_funcs(DO_UNCUT_TEXT, MMAIN, N_("UnJustify"), "",
713
714
	    FALSE, NOVIEW);

715
    else
716
	/* TRANSLATORS: Try to keep this at most 10 characters. */
717
	add_to_funcs(DO_UNCUT_TEXT, MMAIN, N_("UnCut Text"), IFSCHELP(nano_uncut_msg),
718
	    FALSE, NOVIEW);
Chris Allegretta's avatar
Chris Allegretta committed
719

Chris Allegretta's avatar
Chris Allegretta committed
720
#ifndef NANO_TINY
721
    /* TRANSLATORS: Try to keep this at most 10 characters. */
722
    add_to_funcs(DO_CURSORPOS_VOID, MMAIN, N_("Cur Pos"), IFSCHELP(nano_cursorpos_msg),
723
	FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
724
#endif
Chris Allegretta's avatar
Chris Allegretta committed
725

726
727
728
    /* 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. */
729
#ifndef DISABLE_SPELLER
730
	if (!ISSET(RESTRICTED))
731
	    /* TRANSLATORS: Try to keep this at most 10 characters. */
732
	    add_to_funcs(DO_SPELL, MMAIN, N_("To Spell"), IFSCHELP(nano_spell_msg),
733
		TRUE, NOVIEW);
734
#endif
735

736
    add_to_funcs(DO_FIRST_LINE,
737
	(MMAIN|MWHEREIS|MREPLACE|MREPLACE2|MGOTOLINE|MHELP),
738
	first_line_msg, IFSCHELP(nano_firstline_msg), FALSE, VIEW);
739

740
    add_to_funcs(DO_LAST_LINE,
741
	(MMAIN|MWHEREIS|MREPLACE|MREPLACE2|MGOTOLINE|MHELP),
742
	last_line_msg, IFSCHELP(nano_lastline_msg), TRUE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
743

744

745
    add_to_funcs(DO_GOTOLINECOLUMN_VOID, (MMAIN|MWHEREIS),
746
	go_to_line_msg, IFSCHELP(nano_gotoline_msg), FALSE, VIEW);
747

Chris Allegretta's avatar
Chris Allegretta committed
748
#ifdef NANO_TINY
749
    /* TRANSLATORS: Try to keep this at most 10 characters. */
750
    add_to_funcs(DO_CURSORPOS_VOID, MMAIN, N_("Cur Pos"), IFSCHELP(nano_cursorpos_msg),
Chris Allegretta's avatar
Chris Allegretta committed
751
752
753
754
	FALSE, VIEW);
#endif


755
    add_to_funcs(DO_REPLACE, (MMAIN|MWHEREIS), replace_msg, IFSCHELP(nano_replace_msg),
756

757
758
759
760
#ifndef NANO_TINY
	FALSE,
#else
	TRUE,
761
#endif
762
	NOVIEW);
763

764
#ifndef NANO_TINY
765

766
    add_to_funcs(DO_MARK, MMAIN, N_("Mark Text"), 
767
	IFSCHELP(nano_mark_msg), FALSE, VIEW);
768

769
    add_to_funcs(DO_RESEARCH, (MMAIN|MBROWSER), whereis_next_msg,
770
	IFSCHELP(nano_whereis_next_msg), TRUE, VIEW);
771

772
    add_to_funcs(DO_COPY_TEXT, MMAIN, N_("Copy Text"),
773
	IFSCHELP(nano_copy_msg), FALSE, NOVIEW);
774

775
    add_to_funcs(DO_INDENT_VOID, MMAIN, N_("Indent Text"),
776
	IFSCHELP(nano_indent_msg), FALSE, NOVIEW);
777

778
    add_to_funcs(DO_UNINDENT, MMAIN, N_("Unindent Text"),
779
	IFSCHELP(nano_unindent_msg), FALSE, NOVIEW);
780

781
    add_to_funcs(DO_UNDO, MMAIN, N_("Undo"),
782
	IFSCHELP(nano_undo_msg), FALSE, NOVIEW);
783

784
    add_to_funcs(DO_REDO, MMAIN, N_("Redo"),
785
	IFSCHELP(nano_redo_msg), TRUE, NOVIEW);
786

787
#endif
788

789
    add_to_funcs(DO_PAGE_UP, MBROWSER,
790
	prev_page_msg, IFSCHELP(nano_prevpage_msg), FALSE, VIEW);
791
    add_to_funcs(DO_PAGE_DOWN, MBROWSER,
792
	next_page_msg, IFSCHELP(nano_nextpage_msg), TRUE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
793

794

795
    add_to_funcs(DO_RIGHT, (MMAIN|MBROWSER), N_("Forward"), IFSCHELP(nano_forward_msg),
796
	FALSE, VIEW);
797
    add_to_funcs(DO_RIGHT, MALL, "", "", FALSE, VIEW);
798

799
    add_to_funcs(DO_LEFT, (MMAIN|MBROWSER), N_("Back"), IFSCHELP(nano_back_msg),
800
	FALSE, VIEW);
801
    add_to_funcs(DO_LEFT, MALL, "", "", FALSE, VIEW);
802

803
#ifndef NANO_TINY
804
    add_to_funcs(DO_NEXT_WORD_VOID, MMAIN, N_("Next Word"),
805
	IFSCHELP(nano_nextword_msg), FALSE, VIEW);
806

807
    add_to_funcs(DO_PREV_WORD_VOID, MMAIN, N_("Prev Word"),
808
	IFSCHELP(nano_prevword_msg), FALSE, VIEW);
809
#endif
810

811
    add_to_funcs(DO_UP_VOID, (MMAIN|MHELP|MBROWSER), N_("Prev Line"),
812
	IFSCHELP(nano_prevline_msg), FALSE, VIEW);
813

814
    add_to_funcs(DO_DOWN_VOID, (MMAIN|MHELP|MBROWSER), N_("Next Line"),
815
	IFSCHELP(nano_nextline_msg), TRUE, VIEW);
816

817
    add_to_funcs(DO_HOME, MMAIN, N_("Home"), IFSCHELP(nano_home_msg),
818
	FALSE, VIEW);
819

820
    add_to_funcs(DO_END, MMAIN, N_("End"), IFSCHELP(nano_end_msg),
821
	FALSE, VIEW);
822

823
#ifndef DISABLE_JUSTIFY
824
    add_to_funcs(DO_PARA_BEGIN_VOID, (MMAIN|MWHEREIS), beg_of_par_msg,
825
	IFSCHELP(nano_parabegin_msg), FALSE, VIEW);
826

827
    add_to_funcs(DO_PARA_END_VOID, (MMAIN|MWHEREIS), end_of_par_msg,
828
	IFSCHELP(nano_paraend_msg), FALSE, VIEW);
829
#endif
830

831
#ifndef NANO_TINY
832
    add_to_funcs(DO_FIND_BRACKET, MMAIN, _("Find Other Bracket"),
833
	IFSCHELP(nano_bracket_msg), FALSE, VIEW);
834

835
    add_to_funcs(DO_SCROLL_UP, MMAIN, N_("Scroll Up"),
836
	IFSCHELP(nano_scrollup_msg), FALSE, VIEW);
837

838
    add_to_funcs(DO_SCROLL_DOWN, MMAIN, N_("Scroll Down"),
839
	IFSCHELP(nano_scrolldown_msg), FALSE, VIEW);
840
841
#endif

842
#ifdef ENABLE_MULTIBUFFER
843
    add_to_funcs(SWITCH_TO_PREV_BUFFER_VOID, MMAIN, _("Previous File"),
844
	IFSCHELP(nano_prevfile_msg), FALSE, VIEW);
845
    add_to_funcs(SWITCH_TO_NEXT_BUFFER_VOID, MMAIN, N_("Next File"),
846
	IFSCHELP(nano_nextfile_msg), TRUE, VIEW);
847
848
#endif

849
    add_to_funcs(DO_VERBATIM_INPUT, MMAIN, N_("Verbatim Input"),
850
	IFSCHELP(nano_verbatim_msg), FALSE, NOVIEW);
851
    add_to_funcs(DO_VERBATIM_INPUT, MWHEREIS|MREPLACE|MREPLACE2|MEXTCMD|MSPELL,
852
853
	"", "", FALSE, NOVIEW);

854
    add_to_funcs(DO_TAB, MMAIN, N_("Tab"), IFSCHELP(nano_tab_msg),
855
	FALSE, NOVIEW);
856
857
    add_to_funcs(DO_TAB, MALL, "", "", FALSE, NOVIEW);
    add_to_funcs(DO_ENTER, MMAIN, N_("Enter"), IFSCHELP(nano_enter_msg),
858
	FALSE, NOVIEW);
859
860
    add_to_funcs(DO_ENTER, MALL, "", "", FALSE, NOVIEW);
    add_to_funcs(DO_DELETE, MMAIN, N_("Delete"), IFSCHELP(nano_delete_msg),
861
	FALSE, NOVIEW);
862
863
    add_to_funcs(DO_DELETE, MALL, "", "", FALSE, NOVIEW);
    add_to_funcs(DO_BACKSPACE, MMAIN, N_("Backspace"), IFSCHELP(nano_backspace_msg),
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
864
#ifndef NANO_TINY
865
	FALSE,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
866
#else
867
	TRUE,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
868
#endif
869
870
	NOVIEW);

871
    add_to_funcs(DO_BACKSPACE, MALL, "", "",
872
873
874
875
876
877
#ifndef NANO_TINY
	FALSE,
#else
	TRUE,
#endif
	NOVIEW);
878

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

884
885
    add_to_funcs(XON_COMPLAINT, MMAIN, "", "", FALSE, VIEW);
    add_to_funcs(XOFF_COMPLAINT, MMAIN, "", "", FALSE, VIEW);
886

887
#ifndef DISABLE_JUSTIFY
888
    add_to_funcs(DO_FULL_JUSTIFY, (MMAIN|MWHEREIS), fulljstify_msg,
889
	IFSCHELP(nano_fulljustify_msg), FALSE, NOVIEW);
890
891
#endif

892
#ifndef NANO_TINY
893
    add_to_funcs(DO_WORDLINECHAR_COUNT, MMAIN, N_("Word Count"),
894
	IFSCHELP(nano_wordcount_msg), FALSE, VIEW);
895
#endif
896

897
    add_to_funcs(TOTAL_REFRESH, (MMAIN|MHELP), refresh_msg, 
898
899
	IFSCHELP(nano_refresh_msg), FALSE, VIEW);

900
    add_to_funcs(DO_SUSPEND_VOID, MMAIN, suspend_msg,
901
	IFSCHELP(nano_suspend_msg), TRUE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
902

903
#ifndef NANO_TINY
904
    add_to_funcs( CASE_SENS_MSG,
905
	(MWHEREIS|MREPLACE|MWHEREISFILE),
906
	case_sens_msg, IFSCHELP(nano_case_msg), FALSE, VIEW);
907

908
    add_to_funcs( BACKWARDS_MSG,
909
	(MWHEREIS|MREPLACE|MWHEREISFILE),
910
	backwards_msg, IFSCHELP(nano_reverse_msg), FALSE, VIEW);
911
#endif
912

913
#ifdef HAVE_REGEX_H
914
    add_to_funcs( REGEXP_MSG,
915
	(MWHEREIS|MREPLACE|MWHEREISFILE),
916
	regexp_msg, IFSCHELP(nano_regexp_msg), FALSE, VIEW);
917
#endif
918

919
#ifndef NANO_TINY
920
    add_to_funcs( PREV_HISTORY_MSG,
921
	(MWHEREIS|MREPLACE|MREPLACE2|MWHEREISFILE),
922
	prev_history_msg, IFSCHELP(nano_prev_history_msg), FALSE, VIEW);
923

924
    add_to_funcs( NEXT_HISTORY_MSG,
925
	(MWHEREIS|MREPLACE|MREPLACE2|MWHEREISFILE),
926
	next_history_msg, IFSCHELP(nano_next_history_msg), FALSE, VIEW);
927
#endif
928

929
    add_to_funcs( NO_REPLACE_MSG, MREPLACE,
930
	no_replace_msg, IFSCHELP(nano_whereis_msg), FALSE, VIEW);
931

932
    add_to_funcs( GOTOTEXT_MSG, MGOTOLINE,
933
	gototext_msg, IFSCHELP(nano_whereis_msg), TRUE, VIEW);
934

935
#ifndef DISABLE_BROWSER
936
    if (!ISSET(RESTRICTED))
937
	add_to_funcs( TO_FILES_MSG,
938
	    (MGOTOLINE|MINSERTFILE),
939
	    to_files_msg, IFSCHELP(nano_tofiles_msg), FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
940
#endif
Chris Allegretta's avatar
Chris Allegretta committed
941

942
#ifndef NANO_TINY
943
944
945
946
947
948
    /* 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. */
949
    if (!ISSET(RESTRICTED))
950
        add_to_funcs( DOS_FORMAT_MSG, MWRITEFILE,
951
            dos_format_msg, IFSCHELP(nano_dos_msg), FALSE, NOVIEW);
952

953
    if (!ISSET(RESTRICTED))
954
        add_to_funcs( MAC_FORMAT_MSG, MWRITEFILE,
955
            mac_format_msg, IFSCHELP(nano_mac_msg), FALSE, NOVIEW);
956

957
    if (!ISSET(RESTRICTED))
958
        add_to_funcs( APPEND_MSG, MWRITEFILE,
959
            append_msg, IFSCHELP(nano_append_msg), FALSE, NOVIEW);
960

961
    if (!ISSET(RESTRICTED))
962
        add_to_funcs( PREPEND_MSG, MWRITEFILE,
963
            prepend_msg, IFSCHELP(nano_prepend_msg), FALSE, NOVIEW);
964

965
    if (!ISSET(RESTRICTED))
966
        add_to_funcs( BACKUP_FILE_MSG, MWRITEFILE,
967
            backup_file_msg, IFSCHELP(nano_backup_msg), FALSE, NOVIEW);
968
#endif
969

970
#ifndef NANO_TINY
971
972
    /* If we're using restricted mode, command execution is disabled.
     * It's useless since inserting files is disabled. */
973
    if (!ISSET(RESTRICTED))
974
        add_to_funcs( EXT_CMD_MSG, MINSERTFILE,
975
	    ext_cmd_msg, IFSCHELP(nano_execute_msg), FALSE, NOVIEW);
976

977
#ifdef ENABLE_MULTIBUFFER
978
979
    /* If we're using restricted mode, the multibuffer toggle is
     * disabled.  It's useless since inserting files is disabled. */
980
    if (!ISSET(RESTRICTED))
981
	add_to_funcs( NEW_BUFFER_MSG, MINSERTFILE,
982
	new_buffer_msg, IFSCHELP(nano_multibuffer_msg), FALSE, NOVIEW);
983
#endif
984

985
    add_to_funcs(  INSERT_FILE_MSG, MEXTCMD,
986
	insert_file_msg, IFSCHELP(nano_insert_msg), FALSE, VIEW);
987

David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
988
#ifdef ENABLE_MULTIBUFFER
989
     add_to_funcs( NEW_BUFFER_MSG, MEXTCMD,
990
	new_buffer_msg, IFSCHELP(nano_multibuffer_msg), FALSE, NOVIEW);
991
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
992
#endif
993

994
#ifndef DISABLE_HELP
995
    add_to_funcs( REFRESH_MSG, MHELP,
996
	refresh_msg, nano_refresh_msg, FALSE, VIEW);
997
998
#endif

999
#ifndef DISABLE_BROWSER
1000

1001
    add_to_funcs( FIRST_FILE_MSG,
1002
	(MBROWSER|MWHEREISFILE),
1003
	first_file_msg, IFSCHELP(nano_firstfile_msg), FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
1004

1005
    add_to_funcs( LAST_FILE_MSG,
1006
	(MBROWSER|MWHEREISFILE),
1007
	last_file_msg, IFSCHELP(nano_lastfile_msg), FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
1008

1009
    add_to_funcs( GOTO_DIR_MSG, MBROWSER,
1010
	goto_dir_msg, IFSCHELP(nano_gotodir_msg), FALSE, VIEW);
1011
1012
#endif

1013
    currmenu = MMAIN;
1014

1015
1016
1017
1018
1019
1020
1021
1022
    add_to_sclist(MALL, "^G", DO_HELP_VOID, 0, TRUE);
    add_to_sclist(MALL, "F1", DO_HELP_VOID, 0, TRUE);
    add_to_sclist(MMAIN|MHELP|MBROWSER, "^X", DO_EXIT, 0, TRUE);
    add_to_sclist(MMAIN|MHELP|MBROWSER, "F2", DO_EXIT, 0, TRUE);
    add_to_sclist(MMAIN, "^_", DO_GOTOLINECOLUMN_VOID, 0, TRUE);
    add_to_sclist(MMAIN, "F13", DO_GOTOLINECOLUMN_VOID, 0, TRUE);
    add_to_sclist(MMAIN, "^O", DO_WRITEOUT_VOID, 0, TRUE);
    add_to_sclist(MMAIN, "F3", DO_WRITEOUT_VOID, 0, TRUE);
1023
#ifndef DISABLE_JUSTIFY
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
    add_to_sclist(MMAIN, "^J", DO_JUSTIFY_VOID, 0, TRUE);
    add_to_sclist(MMAIN, "F4", DO_JUSTIFY_VOID, 0, TRUE);
#endif
    add_to_sclist(MMAIN, "^R", DO_INSERTFILE_VOID, 0, TRUE);
    add_to_sclist(MMAIN, "F5", DO_INSERTFILE_VOID, 0, TRUE);
    add_to_sclist(MMAIN, "kinsert", DO_INSERTFILE_VOID, 0, TRUE);
    add_to_sclist(MMAIN|MBROWSER, "^W", DO_SEARCH, 0, TRUE);
    add_to_sclist(MMAIN|MBROWSER, "F6", DO_SEARCH, 0, TRUE);
    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);
    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);
1044
#ifndef DISABLE_SPELLER
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
    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", NO_REPLACE_MSG, 0, FALSE);
    add_to_sclist(MWHEREIS, "^T", DO_GOTOLINECOLUMN_VOID, 0, FALSE);
1057
#ifndef NANO_TINY
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
    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);
    add_to_sclist(MALL, "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);
    add_to_sclist(MMAIN, "M-U", DO_UNDO, 0, TRUE);
    add_to_sclist(MMAIN, "M-E", DO_REDO, 0, TRUE);
    add_to_sclist(MALL, "^F", DO_RIGHT, 0, TRUE);
    add_to_sclist(MALL, "^B", DO_LEFT, 0, TRUE);
    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(MALL, "kright", DO_RIGHT, 0, TRUE);
    add_to_sclist(MALL, "kleft", DO_LEFT, 0, TRUE);
    add_to_sclist(MMAIN, "^Q", XON_COMPLAINT, 0, TRUE);
    add_to_sclist(MMAIN, "^S", XOFF_COMPLAINT, 0, TRUE);
    add_to_sclist(MMAIN, "^P", DO_UP_VOID, 0, TRUE);
    add_to_sclist(MMAIN, "kup", DO_UP_VOID, 0, TRUE);
    add_to_sclist(MMAIN, "^N", DO_DOWN_VOID, 0, TRUE);
    add_to_sclist(MMAIN, "kdown", DO_DOWN_VOID, 0, TRUE);
    add_to_sclist(MALL, "^A", DO_HOME, 0, TRUE);
    add_to_sclist(MALL, "khome", DO_HOME, 0, TRUE);
    add_to_sclist(MALL, "^E", DO_END, 0, TRUE);
    add_to_sclist(MALL, "kend", DO_END, 0, TRUE);
1086
#ifndef NANO_TINY
1087
1088
1089
1090
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACE2|MWHEREISFILE, "^P",  PREV_HISTORY_MSG, 0, FALSE);
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACE2|MWHEREISFILE, "kup",  PREV_HISTORY_MSG, 0, FALSE);
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACE2|MWHEREISFILE, "^N",  NEXT_HISTORY_MSG, 0, FALSE);
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACE2|MWHEREISFILE, "kdown",  NEXT_HISTORY_MSG, 0, FALSE);
1091
#endif
1092
#ifndef DISABLE_JUSTIFY
1093
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACE2,
1094
	"^W", DO_PARA_BEGIN_VOID, 0, TRUE);
1095
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACE2,
1096
1097
1098
1099
1100
	"^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
1101
#endif
1102
    add_to_sclist(MWHEREIS,
1103
	"M-C", CASE_SENS_MSG, 0, FALSE);
1104
    add_to_sclist(MREPLACE,
1105
	"M-C", CASE_SENS_MSG, 0, FALSE);
1106
    add_to_sclist(MREPLACE2,
1107
	"M-C", CASE_SENS_MSG, 0, FALSE);
1108
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACE2,
1109
	"M-B", BACKWARDS_MSG, 0, FALSE);
1110
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACE2,
1111
	"M-R", REGEXP_MSG, 0, FALSE);
1112

1113
1114
1115
1116
    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);
1117
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACE2|MGOTOLINE|MHELP,
1118
	"^Y", DO_FIRST_LINE, 0, TRUE);
1119
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACE2|MGOTOLINE|MHELP,
1120
	"^V", DO_LAST_LINE, 0, TRUE);
1121

1122
1123
1124
1125
    add_to_sclist(MBROWSER|MWHEREISFILE, "M-\\",  FIRST_FILE_MSG, 0, TRUE);
    add_to_sclist(MBROWSER|MWHEREISFILE, "M-|",  FIRST_FILE_MSG, 0, TRUE);
    add_to_sclist(MBROWSER|MWHEREISFILE, "M-/",  LAST_FILE_MSG, 0, TRUE);
    add_to_sclist(MBROWSER|MWHEREISFILE, "M-?",  LAST_FILE_MSG, 0, TRUE);
1126
#ifndef NANO_TINY
1127
1128
1129
1130
1131
    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);
1132
1133
#endif

1134
#ifdef ENABLE_MULTIBUFFER
1135
1136
1137
1138
    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);
1139
#endif
1140
    add_to_sclist(MALL, "M-V", DO_VERBATIM_INPUT, 0, TRUE);
1141
#ifndef NANO_TINY
1142
    add_to_sclist(MALL, "M-T", DO_CUT_TILL_END, 0, TRUE);
1143
#ifndef DISABLE_JUSTIFY
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
    add_to_sclist(MALL, "M-J", DO_FULL_JUSTIFY, 0, TRUE);
#endif
    add_to_sclist(MMAIN, "M-D", DO_WORDLINECHAR_COUNT, 0, TRUE);
    add_to_sclist(MMAIN, "M-X", DO_TOGGLE, 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
    add_to_sclist(MGOTOLINE, "^T",  GOTOTEXT_MSG, 0, FALSE);
    add_to_sclist(MINSERTFILE|MEXTCMD, "M-F",  NEW_BUFFER_MSG, 0, FALSE);
1166
    add_to_sclist((MWHEREIS|MREPLACE|MREPLACE2|MGOTOLINE|MWRITEFILE|MINSERTFILE|MEXTCMD|MSPELL|MWHEREISFILE|MGOTODIR|MYESNO),
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
	"^C", 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",  DOS_FORMAT_MSG, 0, FALSE);
    add_to_sclist(MWRITEFILE, "M-M",  MAC_FORMAT_MSG, 0, FALSE);
    add_to_sclist(MWRITEFILE, "M-A",  APPEND_MSG, 0, FALSE);
    add_to_sclist(MWRITEFILE, "M-P",  PREPEND_MSG, 0, FALSE);
    add_to_sclist(MWRITEFILE, "M-B",  BACKUP_FILE_MSG, 0, FALSE);
    add_to_sclist(MWRITEFILE, "^T",  TO_FILES_MSG, 0, FALSE);
    add_to_sclist(MINSERTFILE, "^T",  TO_FILES_MSG, 0, FALSE);
    add_to_sclist(MINSERTFILE, "^X",  EXT_CMD_MSG, 0, FALSE);
    add_to_sclist(MMAIN, "^Z", DO_SUSPEND_VOID, 0, FALSE);
    add_to_sclist(MMAIN, "^L", TOTAL_REFRESH, 0, TRUE);
    add_to_sclist(MALL, "^I", DO_TAB, 0, TRUE);
    add_to_sclist(MALL, "^M", DO_ENTER, 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
1187

1188
1189
#ifdef DEBUG
    print_sclist();
Chris Allegretta's avatar
Chris Allegretta committed
1190
1191
#endif

1192
}
1193

1194
1195
1196
1197
1198
1199
1200
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
/* Given a function alias, execute the proper
   function, and then me */
void iso_me_harder_funcmap(short func)
{
    if (func == TOTAL_REFRESH)
	total_refresh();
    else if (func == DO_HELP_VOID)
	do_help_void();
    else if (func == DO_SEARCH)
	do_search();
    else if (func == DO_PAGE_UP)
	do_page_up();
    else if (func == DO_PAGE_DOWN)
	do_page_down();
    else if (func == DO_UP_VOID)
	do_up_void();
    else if (func == DO_LEFT)
	do_left();
    else if (func == DO_DOWN_VOID)
	do_down_void();
    else if (func == DO_RIGHT)
	do_right();
    else if (func == DO_ENTER)
	do_enter();
    else if (func == DO_EXIT)
	do_exit();
    else if (func == DO_FIRST_LINE)
	do_first_line();
    else if (func == DO_LAST_LINE)
	do_last_line();
    else if (func == DO_BACKSPACE)
	do_backspace();
    else if (func == DO_DELETE)
	do_delete();
    else if (func == DO_TAB)
	do_tab();
    else if (func == DO_VERBATIM_INPUT)
	do_verbatim_input();
1232
#ifdef ENABLE_MULTIBUFFER
1233
1234
1235
1236
    else if (func == SWITCH_TO_NEXT_BUFFER_VOID)
	switch_to_next_buffer_void();
    else if (func == SWITCH_TO_PREV_BUFFER_VOID)
	switch_to_prev_buffer_void();
1237
#endif
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
    else if (func == DO_END)
	do_end();
    else if (func == DO_HOME)
	do_home();
    else if (func == DO_SUSPEND_VOID)
	do_suspend_void();
    else if (func == DO_WRITEOUT_VOID)
	do_writeout_void();
    else if (func == DO_INSERTFILE_VOID)
	do_insertfile_void();
    else if (func == DO_CUT_TEXT_VOID)
	do_cut_text_void();
    else if (func == DO_UNCUT_TEXT)
	do_uncut_text();
    else if (func == DO_CURSORPOS_VOID)
	do_cursorpos_void();
    else if (func == DO_GOTOLINECOLUMN_VOID)
	do_gotolinecolumn_void();
    else if (func == DO_REPLACE)
	do_replace();
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
    else if (func == XOFF_COMPLAINT)
	xoff_complaint();
    else if (func == XON_COMPLAINT)
	xon_complaint();
    else if (func == DO_CUT_TEXT)
	do_cut_text_void();
#ifndef NANO_TINY
    else if (func == DO_CUT_TILL_END)
	do_cut_till_end();
    else if (func == DO_REDO)
	do_redo();
    else if (func == DO_UNDO)
	do_undo();
    else if (func == DO_WORDLINECHAR_COUNT)
	do_wordlinechar_count();
    else if (func == DO_FIND_BRACKET)
	do_find_bracket();
    else if (func == DO_PREV_WORD_VOID)
	do_prev_word_void();
1277
#ifndef DISABLE_JUSTIFY
1278
1279
1280
1281
1282
1283
1284
1285
    else if (func == DO_JUSTIFY_VOID)
	do_justify_void();
    else if (func == DO_PARA_BEGIN_VOID)
	do_para_begin_void();
    else if (func == DO_PARA_END_VOID)
	do_para_end_void();
    else if (func == DO_FULL_JUSTIFY)
	do_full_justify();
1286
#endif
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
    else if (func == DO_MARK)
	do_mark();
    else if (func == DO_RESEARCH)
	do_research();
    else if (func == DO_COPY_TEXT)
	do_copy_text();
    else if (func == DO_INDENT_VOID)
	do_indent_void();
    else if (func == DO_UNINDENT)
	do_unindent();
    else if (func == DO_SCROLL_UP)
	do_scroll_up();
    else if (func == DO_SCROLL_DOWN)
	do_scroll_down();
    else if (func == DO_NEXT_WORD_VOID)
	do_next_word_void();
1303
#ifndef DISABLE_SPELLER
1304
1305
    else if (func == DO_SPELL)
	do_spell();
1306
#endif
1307
1308
1309
1310
    else if (func == DO_NEXT_WORD)
	do_next_word_void();
    else if (func == DO_PREV_WORD)
	do_prev_word_void();
1311
#endif
1312
1313
1314
}


1315
/* Free the given shortcut. */
1316
1317
1318
void free_shortcutage(shortcut **shortcutage)
{
    assert(shortcutage != NULL);
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1319

1320
1321
1322
1323
1324
1325
1326
    while (*shortcutage != NULL) {
	shortcut *ps = *shortcutage;
	*shortcutage = (*shortcutage)->next;
	free(ps);
    }
}

1327
const subnfunc *sctofunc(sc *s)
1328
{
1329
    subnfunc *f;
1330

1331
1332
    for (f = allfuncs; f != NULL && s->scfunc != f->scfunc; f = f->next)
	;
1333

1334
    return f;
1335
1336
}

1337
1338
1339
1340
#ifndef NANO_TINY
/* Now lets come up with a single (hopefully)
   function to get a string for each flag */
char *flagtostr(int flag)
1341
{
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
   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
1379
#endif /* NANO_TINY */
1380

1381
1382
1383
1384
1385
1386
1387
1388
1389
/* 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
1390
1391

#ifndef DISABLE_HELP
1392
    if (!strcasecmp(input, "help"))
1393
	s->scfunc = DO_HELP_VOID;
Chris Allegretta's avatar
Chris Allegretta committed
1394
1395
1396
    else 
#endif
    if (!strcasecmp(input, "cancel")) {
1397
	s->scfunc =  CANCEL_MSG;
1398
1399
	s->execute = FALSE;
    } else if (!strcasecmp(input, "exit"))
1400
	s->scfunc = DO_EXIT;
1401
    else if (!strcasecmp(input, "writeout"))
1402
	s->scfunc = DO_WRITEOUT_VOID;
1403
    else if (!strcasecmp(input, "insert"))
1404
	s->scfunc = DO_INSERTFILE_VOID;
1405
    else if (!strcasecmp(input, "whereis"))
1406
	s->scfunc = DO_SEARCH;
1407
    else if (!strcasecmp(input, "up"))
1408
	s->scfunc = DO_UP_VOID;
1409
    else if (!strcasecmp(input, "down"))
1410
	s->scfunc = DO_DOWN_VOID;
1411
1412
    else if (!strcasecmp(input, "pageup")
	|| !strcasecmp(input, "prevpage"))
1413
	s->scfunc = DO_PAGE_UP;
1414
1415
    else if (!strcasecmp(input, "pagedown")
	|| !strcasecmp(input, "nextpage"))
1416
	s->scfunc = DO_PAGE_DOWN;
1417
    else if (!strcasecmp(input, "cut"))
1418
	s->scfunc = DO_CUT_TEXT_VOID;
1419
    else if (!strcasecmp(input, "uncut"))
1420
	s->scfunc = DO_UNCUT_TEXT;
1421
1422
    else if (!strcasecmp(input, "curpos") ||
	!strcasecmp(input, "cursorpos"))
1423
	s->scfunc = DO_CURSORPOS_VOID;
1424
    else if (!strcasecmp(input, "firstline"))
1425
	s->scfunc = DO_FIRST_LINE;
1426
    else if (!strcasecmp(input, "lastline"))
1427
	s->scfunc = DO_LAST_LINE;
1428
    else if (!strcasecmp(input, "gotoline"))
1429
	s->scfunc = DO_GOTOLINECOLUMN_VOID;
1430
    else if (!strcasecmp(input, "replace"))
1431
	s->scfunc = DO_REPLACE;
1432
#ifndef DISABLE_JUSTIFY
Chris Allegretta's avatar
Chris Allegretta committed
1433
    else if (!strcasecmp(input, "justify"))
1434
	s->scfunc = DO_JUSTIFY_VOID;
1435
    else if (!strcasecmp(input, "beginpara"))
1436
	s->scfunc = DO_PARA_BEGIN_VOID;
1437
    else if (!strcasecmp(input, "endpara"))
1438
	s->scfunc = DO_PARA_END_VOID;
1439
    else if (!strcasecmp(input, "fulljustify"))
1440
	s->scfunc = DO_FULL_JUSTIFY;
1441
1442
#endif
#ifndef NANO_TINY
1443
    else if (!strcasecmp(input, "mark"))
1444
	s->scfunc = DO_MARK;
1445
1446
    else if (!strcasecmp(input, "searchagain") ||
		!strcasecmp(input, "research"))
1447
	s->scfunc = DO_RESEARCH;
1448
    else if (!strcasecmp(input, "copytext"))
1449
	s->scfunc = DO_COPY_TEXT;
1450
    else if (!strcasecmp(input, "indent"))
1451
	s->scfunc = DO_INDENT_VOID;
1452
    else if (!strcasecmp(input, "unindent"))
1453
	s->scfunc = DO_UNINDENT;
Chris Allegretta's avatar
Chris Allegretta committed
1454
    else if (!strcasecmp(input, "scrollup"))
1455
	s->scfunc = DO_SCROLL_UP;
Chris Allegretta's avatar
Chris Allegretta committed
1456
    else if (!strcasecmp(input, "scrolldown"))
1457
	s->scfunc = DO_SCROLL_DOWN;
1458
    else if (!strcasecmp(input, "nextword"))
1459
	s->scfunc = DO_NEXT_WORD_VOID;
1460
    else if (!strcasecmp(input, "suspend"))
1461
	s->scfunc = DO_SUSPEND_VOID;
1462
    else if (!strcasecmp(input, "prevword"))
1463
	s->scfunc = DO_PREV_WORD_VOID;
1464
    else if (!strcasecmp(input, "findbracket"))
1465
	s->scfunc = DO_FIND_BRACKET;
1466
    else if (!strcasecmp(input, "wordcount"))
1467
	s->scfunc = DO_WORDLINECHAR_COUNT;
1468
    else if (!strcasecmp(input, "undo"))
1469
	s->scfunc = DO_UNDO;
1470
    else if (!strcasecmp(input, "redo"))
1471
	s->scfunc = DO_REDO;
Chris Allegretta's avatar
Chris Allegretta committed
1472
    else if (!strcasecmp(input, "prevhistory")) {
1473
	s->scfunc =  PREV_HISTORY_MSG;
1474
1475
	s->execute = FALSE;
    } else if (!strcasecmp(input, "nexthistory")) {
1476
	s->scfunc =  NEXT_HISTORY_MSG;
1477
1478
1479
	s->execute = FALSE;
    } else if (!strcasecmp(input, "nohelp") ||
		!strcasecmp(input, "nohelp")) {
1480
	s->scfunc =  DO_TOGGLE;
1481
1482
1483
	s->execute = FALSE;
	s->toggle = NO_HELP;
    } else if (!strcasecmp(input, "constupdate")) {
1484
	s->scfunc =  DO_TOGGLE;
1485
1486
1487
	s->execute = FALSE;
	s->toggle = CONST_UPDATE;
    } else if (!strcasecmp(input, "morespace")) {
1488
	s->scfunc =  DO_TOGGLE;
1489
1490
1491
	s->execute = FALSE;
	s->toggle = MORE_SPACE;
    } else if (!strcasecmp(input, "smoothscroll")) {
1492
	s->scfunc =  DO_TOGGLE;
1493
1494
	s->execute = FALSE;
	s->toggle = SMOOTH_SCROLL;
1495
    } else if (!strcasecmp(input, "whitespacedisplay")) {
1496
	s->scfunc =  DO_TOGGLE;
1497
1498
1499
	s->execute = FALSE;
	s->toggle = WHITESPACE_DISPLAY;
    } else if (!strcasecmp(input, "nosyntax")) {
1500
	s->scfunc =  DO_TOGGLE;
1501
1502
1503
	s->execute = FALSE;
	s->toggle = NO_COLOR_SYNTAX;
    } else if (!strcasecmp(input, "smarthome")) {
1504
	s->scfunc =  DO_TOGGLE;
1505
1506
1507
	s->execute = FALSE;
	s->toggle = SMART_HOME;
    } else if (!strcasecmp(input, "autoindent")) {
1508
	s->scfunc =  DO_TOGGLE;
1509
1510
1511
	s->execute = FALSE;
	s->toggle = AUTOINDENT;
    } else if (!strcasecmp(input, "cuttoend")) {
1512
	s->scfunc =  DO_TOGGLE;
1513
1514
1515
	s->execute = FALSE;
	s->toggle = CUT_TO_END;
    } else if (!strcasecmp(input, "nowrap")) {
1516
	s->scfunc =  DO_TOGGLE;
1517
1518
1519
	s->execute = FALSE;
	s->toggle = NO_WRAP;
    } else if (!strcasecmp(input, "tabstospaces")) {
1520
	s->scfunc =  DO_TOGGLE;
1521
1522
1523
	s->execute = FALSE;
	s->toggle = TABS_TO_SPACES;
    } else if (!strcasecmp(input, "backupfile")) {
1524
	s->scfunc =  DO_TOGGLE;
1525
1526
1527
	s->execute = FALSE;
	s->toggle = BACKUP_FILE;
    } else if (!strcasecmp(input, "mutlibuffer")) {
1528
	s->scfunc =  DO_TOGGLE;
1529
1530
1531
	s->execute = FALSE;
	s->toggle = MULTIBUFFER;
    } else if (!strcasecmp(input, "mouse")) {
1532
	s->scfunc =  DO_TOGGLE;
1533
1534
1535
	s->execute = FALSE;
	s->toggle = USE_MOUSE;
    } else if (!strcasecmp(input, "noconvert")) {
1536
	s->scfunc =  DO_TOGGLE;
1537
1538
	s->execute = FALSE;
	s->toggle = NO_CONVERT;
1539
    } else if (!strcasecmp(input, "suspendenable")) {
1540
	s->scfunc =  DO_TOGGLE;
1541
1542
	s->execute = FALSE;
	s->toggle = SUSPEND;
1543
    }
Chris Allegretta's avatar
Chris Allegretta committed
1544
1545
1546
#endif /* NANO_TINY */
    else if (!strcasecmp(input, "right") ||
		!strcasecmp(input, "forward"))
1547
	s->scfunc = DO_RIGHT;
Chris Allegretta's avatar
Chris Allegretta committed
1548
1549
    else if (!strcasecmp(input, "left") ||
		!strcasecmp(input, "back"))
1550
	s->scfunc = DO_LEFT;
Chris Allegretta's avatar
Chris Allegretta committed
1551
1552
    else if (!strcasecmp(input, "up") ||
		!strcasecmp(input, "prevline"))
1553
	s->scfunc = DO_UP_VOID;
Chris Allegretta's avatar
Chris Allegretta committed
1554
1555
    else if (!strcasecmp(input, "down") ||
		!strcasecmp(input, "nextline"))
1556
	s->scfunc = DO_DOWN_VOID;
Chris Allegretta's avatar
Chris Allegretta committed
1557
    else if (!strcasecmp(input, "home"))
1558
	s->scfunc = DO_HOME;
Chris Allegretta's avatar
Chris Allegretta committed
1559
    else if (!strcasecmp(input, "end"))
1560
	s->scfunc = DO_END;
Chris Allegretta's avatar
Chris Allegretta committed
1561
1562
#ifdef ENABLE_MULTIBUFFER
    else if (!strcasecmp(input, "prevbuf"))
1563
	s->scfunc = SWITCH_TO_PREV_BUFFER_VOID;
Chris Allegretta's avatar
Chris Allegretta committed
1564
    else if (!strcasecmp(input, "nextbuf"))
1565
	s->scfunc = SWITCH_TO_NEXT_BUFFER_VOID;
Chris Allegretta's avatar
Chris Allegretta committed
1566
1567
#endif
    else if (!strcasecmp(input, "verbatim"))
1568
	s->scfunc = DO_VERBATIM_INPUT;
Chris Allegretta's avatar
Chris Allegretta committed
1569
    else if (!strcasecmp(input, "tab"))
1570
	s->scfunc = DO_TAB;
Chris Allegretta's avatar
Chris Allegretta committed
1571
    else if (!strcasecmp(input, "enter"))
1572
	s->scfunc = DO_ENTER;
Chris Allegretta's avatar
Chris Allegretta committed
1573
    else if (!strcasecmp(input, "delete"))
1574
	s->scfunc = DO_DELETE;
1575
    else if (!strcasecmp(input, "backspace"))
1576
	s->scfunc = DO_BACKSPACE;
Chris Allegretta's avatar
Chris Allegretta committed
1577
    else if (!strcasecmp(input, "refresh"))
1578
	s->scfunc = TOTAL_REFRESH;
Chris Allegretta's avatar
Chris Allegretta committed
1579
    else if (!strcasecmp(input, "casesens")) {
1580
	s->scfunc =  CASE_SENS_MSG;
Chris Allegretta's avatar
Chris Allegretta committed
1581
1582
1583
	s->execute = FALSE;
    } else if (!strcasecmp(input, "regexp") ||
		!strcasecmp(input, "regex")) {
1584
	s->scfunc =  REGEXP_MSG;
Chris Allegretta's avatar
Chris Allegretta committed
1585
1586
	s->execute = FALSE;
    } else if (!strcasecmp(input, "dontreplace")) {
1587
	s->scfunc =  NO_REPLACE_MSG;
Chris Allegretta's avatar
Chris Allegretta committed
1588
1589
	s->execute = FALSE;
    } else if (!strcasecmp(input, "gototext")) {
1590
	s->scfunc =  GOTOTEXT_MSG;
Chris Allegretta's avatar
Chris Allegretta committed
1591
1592
1593
	s->execute = FALSE;
    } else if (!strcasecmp(input, "browser") ||
		!strcasecmp(input, "tofiles")) {
1594
	s->scfunc =  TO_FILES_MSG;
Chris Allegretta's avatar
Chris Allegretta committed
1595
1596
	s->execute = FALSE;
    } else if (!strcasecmp(input, "dosformat")) {
1597
	s->scfunc =  DOS_FORMAT_MSG;
Chris Allegretta's avatar
Chris Allegretta committed
1598
1599
	s->execute = FALSE;
    } else if (!strcasecmp(input, "macformat")) {
1600
	s->scfunc =  MAC_FORMAT_MSG;
Chris Allegretta's avatar
Chris Allegretta committed
1601
1602
	s->execute = FALSE;
    } else if (!strcasecmp(input, "append")) {
1603
	s->scfunc =  APPEND_MSG;
Chris Allegretta's avatar
Chris Allegretta committed
1604
1605
	s->execute = FALSE;
    } else if (!strcasecmp(input, "prepend")) {
1606
	s->scfunc =  PREPEND_MSG;
Chris Allegretta's avatar
Chris Allegretta committed
1607
1608
	s->execute = FALSE;
    } else if (!strcasecmp(input, "backup")) {
1609
	s->scfunc =  BACKUP_FILE_MSG;
Chris Allegretta's avatar
Chris Allegretta committed
1610
1611
1612
	s->execute = FALSE;
#ifdef ENABLE_MULTIBUFFER
    } else if (!strcasecmp(input, "newbuffer")) {
1613
	s->scfunc =  NEW_BUFFER_MSG;
Chris Allegretta's avatar
Chris Allegretta committed
1614
1615
1616
	s->execute = FALSE;
#endif
    } else if (!strcasecmp(input, "firstfile")) {
1617
	s->scfunc =  FIRST_FILE_MSG;
Chris Allegretta's avatar
Chris Allegretta committed
1618
1619
	s->execute = FALSE;
    } else if (!strcasecmp(input, "lastfile")) {
1620
	s->scfunc =  LAST_FILE_MSG;
Chris Allegretta's avatar
Chris Allegretta committed
1621
	s->execute = FALSE;
1622
1623
1624
1625
    } else {
	free(s);
	return NULL;
    }
1626

1627
    return s;
1628

1629
}
1630

Chris Allegretta's avatar
Chris Allegretta committed
1631
#ifdef ENABLE_NANORC
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
/* 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;
}
1668
1669
#endif

Chris Allegretta's avatar
Chris Allegretta committed
1670

1671
1672
1673
#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
1674
1675
 * 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
1676
1677
 * function unless debugging is turned on. */
void thanks_for_all_the_fish(void)
1678
{
1679
1680
1681
1682
    delwin(topwin);
    delwin(edit);
    delwin(bottomwin);

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

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

	    syntaxes->extensions = bob->next;
1732
	    free(bob->ext_regex);
1733
1734
1735
1736
	    if (bob->ext != NULL) {
		regfree(bob->ext);
		free(bob->ext);
	    }
Chris Allegretta's avatar
Chris Allegretta committed
1737
1738
1739
1740
1741
1742
	    free(bob);
	}
	while (syntaxes->color != NULL) {
	    colortype *bob = syntaxes->color;

	    syntaxes->color = bob->next;
1743
	    free(bob->start_regex);
1744
1745
1746
1747
	    if (bob->start != NULL) {
		regfree(bob->start);
		free(bob->start);
	    }
1748
1749
	    if (bob->end_regex != NULL)
		free(bob->end_regex);
1750
	    if (bob->end != NULL) {
1751
		regfree(bob->end);
1752
1753
		free(bob->end);
	    }
Chris Allegretta's avatar
Chris Allegretta committed
1754
1755
1756
1757
1758
1759
	    free(bob);
	}
	syntaxes = syntaxes->next;
	free(bill);
    }
#endif /* ENABLE_COLOR */
1760
#ifndef NANO_TINY
1761
    /* Free the search and replace history lists. */
1762
1763
1764
1765
    if (searchage != NULL)
	free_filestruct(searchage);
    if (replaceage != NULL)
	free_filestruct(replaceage);
1766
#endif
1767
#ifdef ENABLE_NANORC
1768
1769
    if (homedir != NULL)
	free(homedir);
1770
#endif
1771
}
1772
#endif /* DEBUG */
1773