global.c 53.5 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 following five strings at most 10
442
 * characters. */
Chris Allegretta's avatar
Chris Allegretta committed
443
const char *prev_history_msg = N_("PrevHstory");
444
445
446
447
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");
Chris Allegretta's avatar
Chris Allegretta committed
448
449
/* TRANSLATORS: Try to keep this at most 12 characters. */
const char *whereis_next_msg = N_("WhereIs Next");
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
#ifndef DISABLE_BROWSER
/* TRANSLATORS: Try to keep this at most 16 characters. */
const char *to_files_msg = N_("To Files");
/* TRANSLATORS: Try to keep this at most 12 characters. */
const char *first_file_msg = N_("First File");
/* TRANSLATORS: Try to keep this at most 12 characters. */
const char *last_file_msg = N_("Last File");
#endif
/* TRANSLATORS: Try to keep this at most 16 characters. */
const char *dos_format_msg = N_("DOS Format");
/* TRANSLATORS: Try to keep this at most 16 characters. */
const char *mac_format_msg = N_("Mac Format");
/* TRANSLATORS: Try to keep this at most 16 characters. */
const char *append_msg = N_("Append");
/* TRANSLATORS: Try to keep this at most 16 characters. */
const char *prepend_msg = N_("Prepend");
/* TRANSLATORS: Try to keep this at most 16 characters. */
const char *backup_file_msg = N_("Backup File");
468
/* TRANSLATORS: Try to keep this at most 16 characters. */
469
const char *ext_cmd_msg = N_("Execute Command");
470
471
472
473
474

#ifdef ENABLE_MULTIBUFFER
/* TRANSLATORS: Try to keep this at most 16 characters. */
const char *new_buffer_msg = N_("New Buffer");
#endif
Chris Allegretta's avatar
Chris Allegretta committed
475
const char *goto_dir_msg = N_("Go To Dir");
476

Chris Allegretta's avatar
Chris Allegretta committed
477
#endif /* NANO_TINY */
478

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

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

Chris Allegretta's avatar
Chris Allegretta committed
642
#endif
643
#endif /* !DISABLE_HELP */
Chris Allegretta's avatar
Chris Allegretta committed
644

David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
645
#ifndef DISABLE_HELP
646
#define IFSCHELP(help) help
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
647
#else
648
#define IFSCHELP(help) ""
649
#endif
650

651
652
653
654
655
    while (allfuncs != NULL) {
        subnfunc *f = allfuncs;
        allfuncs = (allfuncs)->next;
        free(f);
    }
656

657
#ifndef DISABLE_HELP
658
659
    add_to_funcs(do_help_void, MALL, get_help_msg, nano_help_msg,
	FALSE, VIEW);
660
#endif
Chris Allegretta's avatar
Chris Allegretta committed
661

662
663
    add_to_funcs((void *) cancel_msg,
	(MWHEREIS|MREPLACE|MREPLACE2|MGOTOLINE|MWRITEFILE|MINSERTFILE|MEXTCMD|MSPELL|MWHEREISFILE|MGOTODIR),
664
	cancel_msg, IFSCHELP(nano_cancel_msg), FALSE, VIEW);
665
666

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

673
    add_to_funcs(do_exit, MBROWSER|MHELP, exit_msg, IFSCHELP(nano_exit_msg), FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
674

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

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

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

Chris Allegretta's avatar
Chris Allegretta committed
699
    add_to_funcs(do_search, MMAIN|MBROWSER, whereis_msg,
700
	IFSCHELP(nano_whereis_msg), FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
701

Chris Allegretta's avatar
Chris Allegretta committed
702
    add_to_funcs(do_page_up, MMAIN|MHELP,
703
	prev_page_msg, IFSCHELP(nano_prevpage_msg), FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
704
    add_to_funcs(do_page_down, MMAIN|MHELP,
705
	next_page_msg, IFSCHELP(nano_nextpage_msg), TRUE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
706

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

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

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

Chris Allegretta's avatar
Chris Allegretta committed
721
#ifndef NANO_TINY
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
    /* TRANSLATORS: Try to keep this at most 10 characters. */
730
#ifndef DISABLE_SPELLER
731
732
733
	if (!ISSET(RESTRICTED))
	    add_to_funcs(do_spell, MMAIN, N_("To Spell"), nano_spell_msg,
		TRUE, NOVIEW);
734
#endif
735

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

740
741
    add_to_funcs(do_last_line,
	(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
749
    /* TRANSLATORS: Try to keep this at most 10 characters. */
#ifdef NANO_TINY
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
767
    add_to_funcs(do_mark, MMAIN, N_("Mark Text"), 
	nano_mark_msg, FALSE, VIEW);
768

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

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

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

778
779
    add_to_funcs(do_unindent, MMAIN, N_("Unindent Text"),
	nano_unindent_msg, TRUE, NOVIEW);
780

781
#endif
782

Chris Allegretta's avatar
Chris Allegretta committed
783
    add_to_funcs(do_page_up, MBROWSER,
784
	prev_page_msg, IFSCHELP(nano_prevpage_msg), FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
785
    add_to_funcs(do_page_down, MBROWSER,
786
	next_page_msg, IFSCHELP(nano_nextpage_msg), TRUE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
787

788

789
    add_to_funcs(do_right, (MMAIN|MBROWSER), N_("Forward"), IFSCHELP(nano_forward_msg),
790
	FALSE, VIEW);
791
    add_to_funcs(do_right, MALL, "", "", FALSE, VIEW);
792

793
    add_to_funcs(do_left, (MMAIN|MBROWSER), N_("Back"), IFSCHELP(nano_back_msg),
794
	FALSE, VIEW);
795
    add_to_funcs(do_left, MALL, "", "", FALSE, VIEW);
796

797
798
799
#ifndef NANO_TINY
    add_to_funcs(do_next_word_void, MMAIN, N_("Next Word"),
	nano_nextword_msg, FALSE, VIEW);
800

801
802
    add_to_funcs(do_prev_word_void, MMAIN, N_("Prev Word"),
	nano_prevword_msg, FALSE, VIEW);
803
#endif
804

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

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

811
    add_to_funcs(do_home, MMAIN, N_("Home"), IFSCHELP(nano_home_msg),
812
	FALSE, VIEW);
813

814
    add_to_funcs(do_end, MMAIN, N_("End"), IFSCHELP(nano_end_msg),
815
	FALSE, VIEW);
816

817
818
819
#ifndef DISABLE_JUSTIFY
    add_to_funcs(do_para_begin_void, (MMAIN|MWHEREIS), beg_of_par_msg,
	nano_parabegin_msg, FALSE, VIEW);
820

821
822
    add_to_funcs(do_para_end_void, (MMAIN|MWHEREIS), end_of_par_msg,
	nano_paraend_msg, FALSE, VIEW);
823
#endif
824

825
#ifndef NANO_TINY
826
827
    add_to_funcs(do_find_bracket, MMAIN, _("Find Other Bracket"),
	nano_bracket_msg, FALSE, VIEW);
828

829
830
    add_to_funcs(do_scroll_up, MMAIN, N_("Scroll Up"),
	nano_scrollup_msg, FALSE, VIEW);
831

832
833
    add_to_funcs(do_scroll_down, MMAIN, N_("Scroll Down"),
	nano_scrolldown_msg, FALSE, VIEW);
834
835
#endif

836
837
838
839
840
841
842
843
#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"),
844
845
	IFSCHELP(nano_verbatim_msg), FALSE, NOVIEW);
    add_to_funcs(do_tab, MMAIN, N_("Tab"), IFSCHELP(nano_tab_msg),
846
	FALSE, NOVIEW);
847
    add_to_funcs(do_tab, MALL, "", "", FALSE, NOVIEW);
848
    add_to_funcs(do_enter, MMAIN, N_("Enter"), IFSCHELP(nano_enter_msg),
849
	FALSE, NOVIEW);
850
    add_to_funcs(do_enter, MALL, "", "", FALSE, NOVIEW);
851
    add_to_funcs(do_delete, MMAIN, N_("Delete"), IFSCHELP(nano_delete_msg),
852
	FALSE, NOVIEW);
853
    add_to_funcs(do_delete, MALL, "", "", FALSE, NOVIEW);
854
    add_to_funcs(do_backspace, MMAIN, N_("Backspace"), IFSCHELP(nano_backspace_msg),
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
855
#ifndef NANO_TINY
856
	FALSE,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
857
#else
858
	TRUE,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
859
#endif
860
861
862
863
864
865
866
867
868
	NOVIEW);

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

870
871
872
#ifndef NANO_TINY
    add_to_funcs(do_cut_till_end, MMAIN, N_("CutTillEnd"),
	nano_cut_till_end_msg, TRUE, NOVIEW);
873
#endif
Chris Allegretta's avatar
Chris Allegretta committed
874

875
876
    add_to_funcs(xon_complaint, MMAIN, "", "", FALSE, VIEW);
    add_to_funcs(xoff_complaint, MMAIN, "", "", FALSE, VIEW);
877

878
#ifndef DISABLE_JUSTIFY
879
880
    add_to_funcs(do_full_justify, (MMAIN|MWHEREIS), fulljstify_msg,
	nano_fulljustify_msg, FALSE, NOVIEW);
881
882
#endif

883
#ifndef NANO_TINY
884
885
    add_to_funcs(do_wordlinechar_count, MMAIN, N_("Word Count"),
	nano_wordcount_msg, FALSE, VIEW);
886
#endif
887

888
889
890
891
892
    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
893

894
#ifndef NANO_TINY
895
896
897
    add_to_funcs((void *) case_sens_msg,
	(MWHEREIS|MREPLACE|MWHEREISFILE),
	case_sens_msg, nano_case_msg, FALSE, VIEW);
898

899
900
901
    add_to_funcs((void *) backwards_msg,
	(MWHEREIS|MREPLACE|MWHEREISFILE),
	backwards_msg, nano_reverse_msg, FALSE, VIEW);
902
#endif
903

904
#ifdef HAVE_REGEX_H
905
906
    add_to_funcs((void *) regexp_msg,
	(MWHEREIS|MREPLACE|MWHEREISFILE),
907
	regexp_msg, IFSCHELP(nano_regexp_msg), FALSE, VIEW);
908
#endif
909

910
#ifndef NANO_TINY
911
912
913
    add_to_funcs((void *) prev_history_msg,
	(MWHEREIS|MREPLACE|MREPLACE2|MWHEREISFILE),
	prev_history_msg, nano_prev_history_msg, FALSE, VIEW);
914

915
916
917
    add_to_funcs((void *) next_history_msg,
	(MWHEREIS|MREPLACE|MREPLACE2|MWHEREISFILE),
	next_history_msg, nano_next_history_msg, FALSE, VIEW);
918
#endif
919

920
    add_to_funcs((void *) no_replace_msg, MREPLACE,
921
	no_replace_msg, IFSCHELP(nano_whereis_msg), FALSE, VIEW);
922

923
    add_to_funcs((void *) gototext_msg, MGOTOLINE,
924
	gototext_msg, IFSCHELP(nano_whereis_msg), TRUE, VIEW);
925

926
#ifndef DISABLE_BROWSER
927
    if (!ISSET(RESTRICTED))
928
929
930
	add_to_funcs((void *) to_files_msg,
	    (MGOTOLINE|MINSERTFILE),
	    to_files_msg, nano_tofiles_msg, FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
931
#endif
Chris Allegretta's avatar
Chris Allegretta committed
932

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

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

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

952
    if (!ISSET(RESTRICTED))
953
954
        add_to_funcs((void *) prepend_msg, MWRITEFILE,
            prepend_msg, nano_prepend_msg, FALSE, NOVIEW);
955

956
    if (!ISSET(RESTRICTED))
957
958
        add_to_funcs((void *) backup_file_msg, MWRITEFILE,
            backup_file_msg, nano_backup_msg, FALSE, NOVIEW);
959
#endif
960

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

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

976
    add_to_funcs((void *)  insert_file_msg, MEXTCMD,
977
	insert_file_msg, IFSCHELP(nano_insert_msg), FALSE, VIEW);
978

David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
979
#ifdef ENABLE_MULTIBUFFER
980
981
     add_to_funcs((void *) new_buffer_msg, MEXTCMD,
	new_buffer_msg, nano_multibuffer_msg, FALSE, NOVIEW);
982
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
983
#endif
984

985
#ifndef DISABLE_HELP
986
987
    add_to_funcs((void *) refresh_msg, MHELP,
	refresh_msg, nano_refresh_msg, FALSE, VIEW);
988
989
#endif

990
#ifndef DISABLE_BROWSER
991

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

996
997
998
    add_to_funcs((void *) last_file_msg,
	(MBROWSER|MWHEREISFILE),
	last_file_msg, nano_lastfile_msg, FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
999

1000
1001
    add_to_funcs((void *) goto_dir_msg, MBROWSER,
	goto_dir_msg, nano_gotodir_msg, FALSE, VIEW);
1002
1003
#endif

1004
    currmenu = MMAIN;
1005

1006
1007
1008
1009
#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
1010
1011
    add_to_sclist(MMAIN|MHELP|MBROWSER, "^X", do_exit, 0, TRUE);
    add_to_sclist(MMAIN|MHELP|MBROWSER, "F2", do_exit, 0, TRUE);
1012
1013
1014
1015
    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);
1016
#ifndef DISABLE_JUSTIFY
1017
1018
1019
1020
1021
    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);
1022
    add_to_sclist(MMAIN, "kinsert", do_insertfile_void, 0, TRUE);
Chris Allegretta's avatar
Chris Allegretta committed
1023
1024
    add_to_sclist(MMAIN|MBROWSER, "^W", do_search, 0, TRUE);
    add_to_sclist(MMAIN|MBROWSER, "F6", do_search, 0, TRUE);
1025
1026
1027
1028
1029
1030
    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);
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
    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
1055
    add_to_sclist(MALL, "F16", do_research, 0, TRUE);
1056
1057
1058
1059
    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);
1060
1061
1062
1063
    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);
1064
1065
1066
    add_to_sclist(MMAIN, "^Space", do_next_word_void, 0, TRUE);
    add_to_sclist(MMAIN, "M-Space", do_prev_word_void, 0, TRUE);
#endif
1067
1068
    add_to_sclist(MMAIN, "^Q", xon_complaint, 0, TRUE);
    add_to_sclist(MMAIN, "^S", xoff_complaint, 0, TRUE);
1069
    add_to_sclist(MALL, "^P", do_up_void, 0, TRUE);
1070
    add_to_sclist(MALL, "kup", do_up_void, 0, TRUE);
1071
    add_to_sclist(MALL, "^N", do_down_void, 0, TRUE);
1072
    add_to_sclist(MALL, "kdown", do_down_void, 0, TRUE);
1073
    add_to_sclist(MALL, "^A", do_home, 0, TRUE);
1074
    add_to_sclist(MALL, "khome", do_home, 0, TRUE);
1075
    add_to_sclist(MALL, "^E", do_end, 0, TRUE);
1076
    add_to_sclist(MALL, "kend", do_end, 0, TRUE);
1077
#ifndef DISABLE_JUSTIFY
1078
1079
1080
1081
1082
1083
1084
1085
    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
1086
#endif
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
    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);
1102
1103
1104
1105
1106
    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
1107
1108
1109
1110
    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);
1111
1112
1113
1114
1115
1116
#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);
1117
1118
#endif

1119
1120
1121
1122
1123
1124
1125
1126
#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
    add_to_sclist(MMAIN, "M-V", do_verbatim_input, 0, TRUE);
#ifndef NANO_TINY
Chris Allegretta's avatar
Chris Allegretta committed
1127
    add_to_sclist(MALL, "M-T", do_cut_till_end, 0, TRUE);
1128
#ifndef DISABLE_JUSTIFY
1129
    add_to_sclist(MALL, "M-J", do_full_justify, 0, TRUE);
1130
#endif
1131
    add_to_sclist(MMAIN, "M-D", do_wordlinechar_count, 0, TRUE);
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
    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
1149
1150
    add_to_sclist(MGOTOLINE, "^T", (void *) gototext_msg, 0, FALSE);
    add_to_sclist(MINSERTFILE|MEXTCMD, "M-F", (void *) new_buffer_msg, 0, FALSE);
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
    add_to_sclist((MWHEREIS|MREPLACE|MREPLACE2|MGOTOLINE|MWRITEFILE|MINSERTFILE|MEXTCMD|MSPELL|MWHEREISFILE|MGOTODIR), 
	"^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);
1163
    add_to_sclist(MMAIN, "^Z", do_suspend_void, 0, FALSE);
1164
    add_to_sclist(MMAIN, "^L", total_refresh, 0, TRUE);
1165
1166
1167
1168
1169
1170
1171
    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
1172

1173
1174
#ifdef DEBUG
    print_sclist();
Chris Allegretta's avatar
Chris Allegretta committed
1175
1176
#endif

1177
}
1178

1179
/* Free the given shortcut. */
1180
1181
1182
void free_shortcutage(shortcut **shortcutage)
{
    assert(shortcutage != NULL);
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1183

1184
1185
1186
1187
1188
1189
1190
    while (*shortcutage != NULL) {
	shortcut *ps = *shortcutage;
	*shortcutage = (*shortcutage)->next;
	free(ps);
    }
}

1191
const subnfunc *sctofunc(sc *s)
1192
{
1193
    subnfunc *f;
1194

1195
1196
    for (f = allfuncs; f != NULL && s->scfunc != f->scfunc; f = f->next)
	;
1197

1198
    return f;
1199
1200
}

1201
1202
1203
1204
#ifndef NANO_TINY
/* Now lets come up with a single (hopefully)
   function to get a string for each flag */
char *flagtostr(int flag)
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
1239
1240
1241
1242
   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
1243
#endif /* NANO_TINY */
1244

1245
1246
1247
1248
1249
1250
1251
1252
1253
/* 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
1254
1255

#ifndef DISABLE_HELP
1256
1257
    if (!strcasecmp(input, "help"))
	s->scfunc = do_help_void;
Chris Allegretta's avatar
Chris Allegretta committed
1258
1259
1260
    else 
#endif
    if (!strcasecmp(input, "cancel")) {
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
	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"))
1272
	s->scfunc = do_up_void;
1273
    else if (!strcasecmp(input, "down"))
1274
1275
1276
1277
1278
1279
	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"))
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
	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;
1296
#ifndef DISABLE_JUSTIFY
Chris Allegretta's avatar
Chris Allegretta committed
1297
1298
    else if (!strcasecmp(input, "justify"))
	s->scfunc = do_justify_void;
1299
1300
1301
1302
1303
1304
1305
1306
    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
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
    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
1318
1319
1320
1321
    else if (!strcasecmp(input, "scrollup"))
	s->scfunc = do_scroll_up;
    else if (!strcasecmp(input, "scrolldown"))
	s->scfunc = do_scroll_down;
1322
1323
    else if (!strcasecmp(input, "nextword"))
	s->scfunc = do_next_word_void;
1324
1325
    else if (!strcasecmp(input, "suspend"))
	s->scfunc = do_suspend_void;
1326
1327
1328
1329
1330
1331
    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
1332
    else if (!strcasecmp(input, "prevhistory")) {
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
	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;
1355
    } else if (!strcasecmp(input, "whitespacedisplay")) {
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
1395
1396
1397
1398
	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;
1399
    } else if (!strcasecmp(input, "suspendenable")) {
1400
1401
1402
	s->scfunc = (void *) do_toggle;
	s->execute = FALSE;
	s->toggle = SUSPEND;
1403
    }
Chris Allegretta's avatar
Chris Allegretta committed
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
1476
1477
1478
1479
#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;
1480
1481
1482
1483
    } else {
	free(s);
	return NULL;
    }
1484

1485
    return s;
1486

1487
}
1488

Chris Allegretta's avatar
Chris Allegretta committed
1489
#ifdef ENABLE_NANORC
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
1522
1523
1524
1525
/* 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;
}
1526
1527
#endif

Chris Allegretta's avatar
Chris Allegretta committed
1528

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

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

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

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

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

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