global.c 49.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
26
27
#include <ctype.h>
#include <strings.h>
#include "assert.h"
Chris Allegretta's avatar
Chris Allegretta committed
28
29
#include "proto.h"

30
31
/* Global variables. */
#ifndef NANO_TINY
32
sigjmp_buf jump_buf;
33
	/* Used to return to either main() or the unjustify routine in
34
	 * do_justify() after a SIGWINCH. */
35
36
37
bool jump_buf_main = FALSE;
	/* Have we set jump_buf so that we return to main() after a
	 * SIGWINCH? */
38
39
#endif

40
#ifndef DISABLE_WRAPJUSTIFY
41
42
ssize_t fill = 0;
	/* The column where we will wrap lines. */
43
ssize_t wrap_at = -CHARS_FROM_EOL;
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
	/* 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;
61
	/* The middle portion of the window, i.e. the edit window, where
62
63
64
65
66
67
68
69
70
	 * 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. */
71
#ifndef DISABLE_JUSTIFY
72
73
filestruct *jusbuffer = NULL;
	/* The buffer where we store unjustified text. */
74
#endif
75
76
77
partition *filepart = NULL;
	/* The partition where we store a portion of the current
	 * file. */
78
openfilestruct *openfile = NULL;
79
	/* The list of all open file buffers. */
80

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

198
199
200
201
    for (f = allfuncs; f != NULL; f = f->next)
        if ((f->menus & menu) != 0) {
	    i++;
	}
202
203
204
    return i;
}

205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
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
/* Set type of function based on the string */
function_type strtokeytype(char *str)
{
    if (str[0] ==  'M' || str[0] == 'm') {
        return META;
    } else if (str[0] == '^') {
        return CONTROL;
    } else if (str[0] ==  'M' || str[0] == 'm') {
        return FKEY;
    } else {
	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);
247
#endif
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
}

const sc *first_sc_for(int menu, void *func) {
    const sc *s;

    for (s = sclist; s != NULL; s = s->next) {
	if ((s->menu & menu) && s->scfunc == func) {
	    return s;
	}
    }

#ifdef DEBUG
    fprintf(stderr, "Whoops, returning null given func %ld\n", (long) func);
#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
270
{
271
    sc *s;
272

273
274
275
276
    if (sclist == NULL) {
	sclist = nmalloc(sizeof(sc));
	s = sclist;
        s->next = NULL;
277
    } else {
278
279
280
281
282
283
284
285
286
287
288
289
	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;
        }
290
291
    }

292
293
294
295
296
297
298
299
300
301
302
303
    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
304
305
}

306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
/* 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];
321
322
323
324
325
326
327

    /* 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) ' ';

328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
}

#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)
	    fprintf(stderr, "Shortcut \"%s\", function: %s\n",  s->keystr, f->desc);
	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 *nano_cancel_msg = "";
const char *nano_exit_msg = "";
const char *nano_writeout_msg = "";
const char *nano_insert_msg = "";
const char *nano_whereis_msg = "";
const char *nano_prevpage_msg = "";
const char *nano_nextpage_msg = "";
const char *nano_cut_msg = "";
const char *nano_uncut_msg = "";
const char *nano_cursorpos_msg = "";
const char *nano_lastline_msg = "";
const char *nano_gotoline_msg = "";
const char *nano_replace_msg = "";
const char *nano_forward_msg = "";
const char *nano_back_msg = "";
const char *nano_prevline_msg = "";
const char *nano_nextline_msg = "";
const char *nano_home_msg = "";
const char *nano_end_msg = "";
const char *nano_verbatim_msg = "";
const char *nano_tab_msg = "";
const char *nano_enter_msg = "";
const char *nano_delete_msg = "";
const char *nano_backspace_msg = "";
const char *nano_regexp_msg = "";
const char *gototext_msg = "";
const char *do_para_begin_void = "";
const char *do_para_end_void = "";
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 = "";
#else /* NANO_TINY */
const char *prev_history_msg = N_("PrevHstory");
/* TRANSLATORS: Try to keep this and previous strings at most 10
 * characters. */
const char *next_history_msg = N_("NextHstory");
const char *replace_msg = N_("Replace");
const char *no_replace_msg = N_("No Replace");
const char *go_to_line_msg = N_("Go To Line");
const char *gototext_msg = N_("Go To Text");
#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");

#ifdef ENABLE_MULTIBUFFER
/* TRANSLATORS: Try to keep this at most 16 characters. */
const char *new_buffer_msg = N_("New Buffer");
#endif

#endif

435
436
/* Initialize all shortcut lists.  If unjustify is TRUE, replace the
 * Uncut shortcut in the main shortcut list with UnJustify. */
437
void shortcut_init(bool unjustify)
438
{
439
440
    /* TRANSLATORS: Try to keep this and following strings at most 10
     * characters. */
441
442
    const char *get_help_msg = N_("Get Help");
    const char *exit_msg = N_("Exit");
443
    const char *whereis_msg = N_("Where Is");
444
445
    const char *prev_page_msg = N_("Prev Page");
    const char *next_page_msg = N_("Next Page");
446
447
    /* TRANSLATORS: Try to keep this string at most 10 characters. */

448
#ifndef NANO_TINY
449
450
    /* TRANSLATORS: Try to keep this at most 12 characters. */
    const char *whereis_next_msg = N_("WhereIs Next");
451
#endif
452
453
    /* TRANSLATORS: Try to keep this and following strings at most 10
     * characters. */
454
455
    const char *first_line_msg = N_("First Line");
    const char *last_line_msg = N_("Last Line");
456
457
458
459
460
#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
461
    const char *refresh_msg = N_("Refresh");
462
463
464
465
    const char *insert_file_msg =  N_("Insert File");
    const char *goto_dir_msg = N_("Go To Dir");
    const char *ext_cmd_msg = N_("Execute Command");

466
#ifndef DISABLE_HELP
467
    const char *nano_cancel_msg = N_("Cancel the current function");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
468
    const char *nano_help_msg = N_("Display this help text");
469
    const char *nano_exit_msg =
470
#ifdef ENABLE_MULTIBUFFER
471
	N_("Close the current file buffer / Exit from nano")
472
473
474
475
#else
   	N_("Exit from nano")
#endif
	;
476
477
    const char *nano_writeout_msg =
	N_("Write the current file to disk");
478
479
480
    const char *nano_justify_msg = N_("Justify the current paragraph");
    const char *nano_insert_msg =
	N_("Insert another file into the current one");
481
    const char *nano_whereis_msg =
482
	N_("Search for a string or a regular expression");
483
484
    const char *nano_prevpage_msg = N_("Go to previous screen");
    const char *nano_nextpage_msg = N_("Go to next screen");
485
486
487
488
    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");
489
    const char *nano_cursorpos_msg =
490
	N_("Display the position of the cursor");
491
492
    const char *nano_spell_msg =
	N_("Invoke the spell checker, if available");
493
494
    const char *nano_replace_msg =
	N_("Replace a string or a regular expression");
495
     const char *nano_gotoline_msg = N_("Go to line and column number");
496
#ifndef NANO_TINY
497
498
    const char *nano_mark_msg = N_("Mark text at the cursor position");
    const char *nano_whereis_next_msg = N_("Repeat last search");
499
500
    const char *nano_copy_msg =
	N_("Copy the current line and store it in the cutbuffer");
501
502
    const char *nano_indent_msg = N_("Indent the current line");
    const char *nano_unindent_msg = N_("Unindent the current line");
503
#endif
504
505
    const char *nano_forward_msg = N_("Go forward one character");
    const char *nano_back_msg = N_("Go back one character");
506
#ifndef NANO_TINY
507
508
    const char *nano_nextword_msg = N_("Go forward one word");
    const char *nano_prevword_msg = N_("Go back one word");
509
#endif
510
511
512
513
    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");
514
515
#ifndef DISABLE_JUSTIFY
    const char *nano_parabegin_msg =
516
	N_("Go to beginning of paragraph; then of previous paragraph");
517
    const char *nano_paraend_msg =
518
	N_("Go just beyond end of paragraph; then of next paragraph");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
519
520
#endif
    const char *nano_firstline_msg =
521
	N_("Go to the first line of the file");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
522
    const char *nano_lastline_msg =
523
	N_("Go to the last line of the file");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
524
#ifndef NANO_TINY
525
    const char *nano_bracket_msg = N_("Go to the matching bracket");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
526
527
528
529
    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");
530
#endif
531
#ifdef ENABLE_MULTIBUFFER
532
    const char *nano_prevfile_msg =
533
	N_("Switch to the previous file buffer");
534
    const char *nano_nextfile_msg =
535
	N_("Switch to the next file buffer");
536
#endif
537
    const char *nano_verbatim_msg =
538
	N_("Insert the next keystroke verbatim");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
539
    const char *nano_tab_msg =
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
540
	N_("Insert a tab at the cursor position");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
541
    const char *nano_enter_msg =
542
	N_("Insert a newline at the cursor position");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
543
544
545
546
    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");
547
#ifndef NANO_TINY
548
549
550
    const char *nano_cut_till_end_msg =
	N_("Cut from the cursor position to the end of the file");
#endif
551
552
#ifndef DISABLE_JUSTIFY
    const char *nano_fulljustify_msg = N_("Justify the entire file");
553
#endif
554
#ifndef NANO_TINY
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
555
556
    const char *nano_wordcount_msg =
	N_("Count the number of words, lines, and characters");
557
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
558
559
    const char *nano_refresh_msg =
	N_("Refresh (redraw) the current screen");
560
#ifndef NANO_TINY
561
    const char *nano_case_msg =
562
	N_("Toggle the case sensitivity of the search");
563
    const char *nano_reverse_msg =
564
	N_("Reverse the direction of the search");
565
#endif
566
#ifdef HAVE_REGEX_H
567
568
    const char *nano_regexp_msg =
	N_("Toggle the use of regular expressions");
569
#endif
570
#ifndef NANO_TINY
571
    const char *nano_prev_history_msg =
572
	N_("Recall the previous search/replace string");
573
    const char *nano_next_history_msg =
574
	N_("Recall the next search/replace string");
575
#endif
576
577
#ifndef DISABLE_BROWSER
    const char *nano_tofiles_msg = N_("Go to file browser");
Chris Allegretta's avatar
Chris Allegretta committed
578
#endif
579
#ifndef NANO_TINY
580
581
    const char *nano_dos_msg = N_("Toggle the use of DOS format");
    const char *nano_mac_msg = N_("Toggle the use of Mac format");
582
#endif
583
584
    const char *nano_append_msg = N_("Toggle appending");
    const char *nano_prepend_msg = N_("Toggle prepending");
585
#ifndef NANO_TINY
586
    const char *nano_backup_msg =
587
	N_("Toggle backing up of the original file");
588
    const char *nano_execute_msg = N_("Execute external command");
589
#endif
590
#if !defined(NANO_TINY) && defined(ENABLE_MULTIBUFFER)
591
592
    const char *nano_multibuffer_msg =
	N_("Toggle the use of a new buffer");
593
594
#endif
#ifndef DISABLE_BROWSER
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
595
    const char *nano_exitbrowser_msg = N_("Exit from the file browser");
596
597
598
599
    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
600
    const char *nano_gotodir_msg = N_("Go to directory");
601

Chris Allegretta's avatar
Chris Allegretta committed
602
#endif
603
#endif /* !DISABLE_HELP */
Chris Allegretta's avatar
Chris Allegretta committed
604

David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
605
#ifndef DISABLE_HELP
606
#define IFSCHELP(help, blank, nextvar) help, blank, nextvar
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
607
#else
608
#define IFSCHELP(help, blank, nextvar) nextvar
609
#endif
610

611
612
613
614
615
    while (allfuncs != NULL) {
        subnfunc *f = allfuncs;
        allfuncs = (allfuncs)->next;
        free(f);
    }
616

617
#ifndef DISABLE_HELP
618
619
    add_to_funcs(do_help_void, MALL, get_help_msg, nano_help_msg,
	FALSE, VIEW);
620
#endif
Chris Allegretta's avatar
Chris Allegretta committed
621

622
623
624
625
626
    add_to_funcs((void *) cancel_msg,
	(MWHEREIS|MREPLACE|MREPLACE2|MGOTOLINE|MWRITEFILE|MINSERTFILE|MEXTCMD|MSPELL|MWHEREISFILE|MGOTODIR),
	cancel_msg, nano_cancel_msg, FALSE, VIEW);

    add_to_funcs(do_exit, MMAIN,
627
#ifdef ENABLE_MULTIBUFFER
628
	/* TRANSLATORS: Try to keep this at most 10 characters. */
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
629
	openfile != NULL && openfile != openfile->next ? N_("Close") :
630
#endif
631
	exit_msg, nano_exit_msg, FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
632

633
    add_to_funcs(do_exit, MBROWSER|MHELP, exit_msg, nano_exit_msg, FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
634

635
    /* TRANSLATORS: Try to keep this at most 10 characters. */
636
637
638
    add_to_funcs(do_writeout_void, MMAIN, N_("WriteOut"),
	nano_writeout_msg, FALSE, NOVIEW);

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

645
    /* We allow inserting files in view mode if multibuffers are
646
647
648
649
     * 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. */
650
    /* TRANSLATORS: Try to keep this at most 10 characters. */
651
652
    add_to_funcs(!ISSET(RESTRICTED) ? do_insertfile_void : nano_disabled_msg,
	MMAIN, N_("Read File"), nano_insert_msg, FALSE,
653
#ifdef ENABLE_MULTIBUFFER
654
	VIEW);
655
#else
656
	NOVIEW);
657
#endif
Chris Allegretta's avatar
Chris Allegretta committed
658

659
660
    add_to_funcs(do_search, MMAIN, whereis_msg,
	nano_whereis_msg, FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
661

662
663
664
665
    add_to_funcs(do_page_up, (MMAIN|MHELP|MBROWSER),
	prev_page_msg, nano_prevpage_msg, FALSE, VIEW);
    add_to_funcs(do_page_down, (MMAIN|MHELP|MBROWSER),
	next_page_msg, nano_nextpage_msg, TRUE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
666

667
    /* TRANSLATORS: Try to keep this at most 10 characters. */
668
669
    add_to_funcs(do_cut_text_void, MMAIN, N_("Cut Text"), nano_cut_msg,
	FALSE, NOVIEW);
Chris Allegretta's avatar
Chris Allegretta committed
670

671
    if (unjustify)
672
	/* TRANSLATORS: Try to keep this at most 10 characters. */
673
674
675
	add_to_funcs(do_uncut_text, MMAIN, N_("UnJustify"), "",
	    FALSE, NOVIEW);

676
    else
677
	/* TRANSLATORS: Try to keep this at most 10 characters. */
678
679
	add_to_funcs(do_uncut_text, MMAIN, N_("UnCut Text"), nano_uncut_msg,
	    FALSE, NOVIEW);
Chris Allegretta's avatar
Chris Allegretta committed
680

681
    /* TRANSLATORS: Try to keep this at most 10 characters. */
682
683
    add_to_funcs(do_cursorpos_void, MMAIN, N_("Cur Pos"), nano_cursorpos_msg,
	FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
684

685
686
687
    /* 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. */
688
    /* TRANSLATORS: Try to keep this at most 10 characters. */
689
#ifndef DISABLE_SPELLER
690
691
692
	if (!ISSET(RESTRICTED))
	    add_to_funcs(do_spell, MMAIN, N_("To Spell"), nano_spell_msg,
		TRUE, NOVIEW);
693
#endif
694

695
696
697
    add_to_funcs(do_first_line,
	(MMAIN|MWHEREIS|MREPLACE|MREPLACE2|MGOTOLINE|MHELP),
	first_line_msg, first_line_msg, FALSE, VIEW);
698

699
700
701
    add_to_funcs(do_last_line,
	(MMAIN|MWHEREIS|MREPLACE|MREPLACE2|MGOTOLINE|MHELP),
	last_line_msg, nano_lastline_msg, TRUE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
702

703

704
705
    add_to_funcs(do_gotolinecolumn_void, (MMAIN|MWHEREIS),
	go_to_line_msg, nano_gotoline_msg, FALSE, VIEW);
706

707
    add_to_funcs(do_replace, (MMAIN|MWHEREIS), replace_msg, nano_replace_msg,
708

709
710
711
712
#ifndef NANO_TINY
	FALSE,
#else
	TRUE,
713
#endif
714
	NOVIEW);
715

716
#ifndef NANO_TINY
717

718
719
    add_to_funcs(do_mark, MMAIN, N_("Mark Text"), 
	nano_mark_msg, FALSE, VIEW);
720

721
722
    add_to_funcs(do_research, (MMAIN|MBROWSER), whereis_next_msg,
	nano_whereis_next_msg, TRUE, VIEW);
723

724
725
    add_to_funcs(do_copy_text, MMAIN, N_("Copy Text"),
	nano_copy_msg, FALSE, NOVIEW);
726

727
728
    add_to_funcs(do_indent_void, MMAIN, N_("Indent Text"),
	nano_indent_msg, FALSE, NOVIEW);
729

730
731
    add_to_funcs(do_unindent, MMAIN, N_("Unindent Text"),
	nano_unindent_msg, TRUE, NOVIEW);
732

733
#endif
734

735

736
737
    add_to_funcs(do_right, MMAIN, N_("Forward"), nano_forward_msg,
	FALSE, VIEW);
738

739
740
    add_to_funcs(do_left, MMAIN, N_("Back"), nano_back_msg,
	FALSE, VIEW);
741

742
743
744
#ifndef NANO_TINY
    add_to_funcs(do_next_word_void, MMAIN, N_("Next Word"),
	nano_nextword_msg, FALSE, VIEW);
745

746
747
    add_to_funcs(do_prev_word_void, MMAIN, N_("Prev Word"),
	nano_prevword_msg, FALSE, VIEW);
748
#endif
749

750
751
    add_to_funcs(do_up_void, (MMAIN|MHELP), N_("Prev Line"),
	nano_prevline_msg, FALSE, VIEW);
752

753
754
    add_to_funcs(do_down_void, (MMAIN|MHELP), N_("Next Line"),
	nano_nextline_msg, TRUE, VIEW);
755

756
757
    add_to_funcs(do_home, MMAIN, N_("Home"), nano_home_msg,
	FALSE, VIEW);
758

759
760
    add_to_funcs(do_end, MMAIN, N_("End"), nano_end_msg,
	FALSE, VIEW);
761

762
763
764
#ifndef DISABLE_JUSTIFY
    add_to_funcs(do_para_begin_void, (MMAIN|MWHEREIS), beg_of_par_msg,
	nano_parabegin_msg, FALSE, VIEW);
765

766
767
    add_to_funcs(do_para_end_void, (MMAIN|MWHEREIS), end_of_par_msg,
	nano_paraend_msg, FALSE, VIEW);
768
#endif
769

770
#ifndef NANO_TINY
771
772
    add_to_funcs(do_find_bracket, MMAIN, _("Find Other Bracket"),
	nano_bracket_msg, FALSE, VIEW);
773

774
775
    add_to_funcs(do_scroll_up, MMAIN, N_("Scroll Up"),
	nano_scrollup_msg, FALSE, VIEW);
776

777
778
    add_to_funcs(do_scroll_down, MMAIN, N_("Scroll Down"),
	nano_scrolldown_msg, FALSE, VIEW);
779
780
#endif

781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
#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"),
	nano_verbatim_msg, FALSE, NOVIEW);
    add_to_funcs(do_tab, MMAIN, N_("Tab"), nano_tab_msg,
	FALSE, NOVIEW);
    add_to_funcs(do_enter, MMAIN, N_("Enter"), nano_enter_msg,
	FALSE, NOVIEW);
    add_to_funcs(do_delete, MMAIN, N_("Delete"), nano_delete_msg,
	FALSE, NOVIEW);
    add_to_funcs(do_backspace, MMAIN, N_("Backspace"), nano_backspace_msg,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
797
#ifndef NANO_TINY
798
	FALSE,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
799
#else
800
	TRUE,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
801
#endif
802
	VIEW);
803

804
805
806
#ifndef NANO_TINY
    add_to_funcs(do_cut_till_end, MMAIN, N_("CutTillEnd"),
	nano_cut_till_end_msg, TRUE, NOVIEW);
807
#endif
Chris Allegretta's avatar
Chris Allegretta committed
808

809
810
    add_to_funcs(xon_complaint, MMAIN, "", "", FALSE, VIEW);
    add_to_funcs(xoff_complaint, MMAIN, "", "", FALSE, VIEW);
811

812
#ifndef DISABLE_JUSTIFY
813
814
    add_to_funcs(do_full_justify, (MMAIN|MWHEREIS), fulljstify_msg,
	nano_fulljustify_msg, FALSE, NOVIEW);
815
816
#endif

817
#ifndef NANO_TINY
818
819
    add_to_funcs(do_wordlinechar_count, MMAIN, N_("Word Count"),
	nano_wordcount_msg, FALSE, VIEW);
820
#endif
821

822
    add_to_funcs(total_refresh, (MMAIN|MHELP), refresh_msg, refresh_msg,
823
#ifndef NANO_TINY
824
	TRUE,
825
#else
826
	FALSE,
827
#endif
828
	VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
829

830
#ifndef NANO_TINY
831
832
833
    add_to_funcs((void *) case_sens_msg,
	(MWHEREIS|MREPLACE|MWHEREISFILE),
	case_sens_msg, nano_case_msg, FALSE, VIEW);
834

835
836
837
    add_to_funcs((void *) backwards_msg,
	(MWHEREIS|MREPLACE|MWHEREISFILE),
	backwards_msg, nano_reverse_msg, FALSE, VIEW);
838
#endif
839

840
#ifdef HAVE_REGEX_H
841
842
843
    add_to_funcs((void *) regexp_msg,
	(MWHEREIS|MREPLACE|MWHEREISFILE),
	regexp_msg, nano_regexp_msg, FALSE, VIEW);
844
#endif
845

846
#ifndef NANO_TINY
847
848
849
    add_to_funcs((void *) prev_history_msg,
	(MWHEREIS|MREPLACE|MREPLACE2|MWHEREISFILE),
	prev_history_msg, nano_prev_history_msg, FALSE, VIEW);
850

851
852
853
    add_to_funcs((void *) next_history_msg,
	(MWHEREIS|MREPLACE|MREPLACE2|MWHEREISFILE),
	next_history_msg, nano_next_history_msg, FALSE, VIEW);
854
#endif
855

856
857
    add_to_funcs((void *) no_replace_msg, MREPLACE,
	no_replace_msg, nano_whereis_msg, FALSE, VIEW);
858

859
860
    add_to_funcs((void *) gototext_msg, MGOTOLINE,
	gototext_msg, nano_whereis_msg, FALSE, VIEW);
861

862
#ifndef DISABLE_BROWSER
863
    if (!ISSET(RESTRICTED))
864
865
866
	add_to_funcs((void *) to_files_msg,
	    (MGOTOLINE|MINSERTFILE),
	    to_files_msg, nano_tofiles_msg, FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
867
#endif
Chris Allegretta's avatar
Chris Allegretta committed
868

869
#ifndef NANO_TINY
870
871
872
873
874
875
    /* 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. */
876
    if (!ISSET(RESTRICTED))
877
878
        add_to_funcs((void *) dos_format_msg, MWRITEFILE,
            dos_format_msg, nano_dos_msg, FALSE, NOVIEW);
879

880
    if (!ISSET(RESTRICTED))
881
882
        add_to_funcs((void *) mac_format_msg, MWRITEFILE,
            mac_format_msg, nano_mac_msg, FALSE, NOVIEW);
883

884
    if (!ISSET(RESTRICTED))
885
886
        add_to_funcs((void *) append_msg, MWRITEFILE,
            append_msg, nano_append_msg, FALSE, NOVIEW);
887

888
    if (!ISSET(RESTRICTED))
889
890
        add_to_funcs((void *) prepend_msg, MWRITEFILE,
            prepend_msg, nano_prepend_msg, FALSE, NOVIEW);
891

892
    if (!ISSET(RESTRICTED))
893
894
        add_to_funcs((void *) backup_file_msg, MWRITEFILE,
            backup_file_msg, nano_backup_msg, FALSE, NOVIEW);
895
#endif
896

897
#ifndef NANO_TINY
898
899
    /* If we're using restricted mode, command execution is disabled.
     * It's useless since inserting files is disabled. */
900
    if (!ISSET(RESTRICTED))
901
902
        add_to_funcs((void *) ext_cmd_msg, MINSERTFILE,
	    ext_cmd_msg, nano_execute_msg, FALSE, NOVIEW);
903

904
#ifdef ENABLE_MULTIBUFFER
905
906
    /* If we're using restricted mode, the multibuffer toggle is
     * disabled.  It's useless since inserting files is disabled. */
907
    if (!ISSET(RESTRICTED))
908
909
	add_to_funcs((void *) new_buffer_msg, MWRITEFILE,
	new_buffer_msg, nano_multibuffer_msg, FALSE, NOVIEW);
910
#endif
911

912
913
    add_to_funcs((void *)  insert_file_msg, MEXTCMD,
	insert_file_msg, nano_insert_msg, FALSE, VIEW);
914

David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
915
#ifdef ENABLE_MULTIBUFFER
916
917
     add_to_funcs((void *) new_buffer_msg, MEXTCMD,
	new_buffer_msg, nano_multibuffer_msg, FALSE, NOVIEW);
918
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
919
#endif
920

921
#ifndef DISABLE_HELP
922
923
    add_to_funcs((void *) refresh_msg, MHELP,
	refresh_msg, nano_refresh_msg, FALSE, VIEW);
924
925
#endif

926
#ifndef DISABLE_BROWSER
927

928
929
930
    add_to_funcs((void *) first_file_msg,
	(MBROWSER|MWHEREISFILE),
	first_file_msg, nano_firstfile_msg, FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
931

932
933
934
    add_to_funcs((void *) last_file_msg,
	(MBROWSER|MWHEREISFILE),
	last_file_msg, nano_lastfile_msg, FALSE, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
935

936
937
    add_to_funcs((void *) goto_dir_msg, MBROWSER,
	goto_dir_msg, nano_gotodir_msg, FALSE, VIEW);
938
939
#endif

940
    currmenu = MMAIN;
941

942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
#ifndef NANO_TINY
    add_to_sclist(MALL, "^G", do_help_void, 0, TRUE);
    add_to_sclist(MALL, "F1", do_help_void, 0, TRUE);
#endif
    add_to_sclist(MMAIN, "^X", do_exit, 0, TRUE);
    add_to_sclist(MMAIN, "F2", do_exit, 0, TRUE);
    add_to_sclist(MHELP, "^X", do_exit, 0, TRUE);
    add_to_sclist(MHELP, "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);
#ifndef NANO_TINY
    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, "^W", do_search, 0, TRUE);
    add_to_sclist(MMAIN, "F6", do_search, 0, TRUE);
    add_to_sclist(MMAIN, "^Y", do_page_up, 0, TRUE);
    add_to_sclist(MMAIN, "F7", do_page_up, 0, TRUE);
    add_to_sclist(MMAIN, "^V", do_page_down, 0, TRUE);
    add_to_sclist(MMAIN, "F8", 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);
#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, "F16", do_research, 0, TRUE);
    add_to_sclist(MALL, "M-W", 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|MBROWSER|MHELP, "^F", do_right, 0, TRUE);
    add_to_sclist(MMAIN|MBROWSER|MHELP, "^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, "^Q", xon_complaint, 0, TRUE);
    add_to_sclist(MALL, "^X", xoff_complaint, 0, TRUE);
    add_to_sclist(MALL, "^P", do_up_void, 0, TRUE);
    add_to_sclist(MALL, "^N", do_down_void, 0, TRUE);
    add_to_sclist(MALL, "^A", do_home, 0, TRUE);
    add_to_sclist(MALL, "^E", do_end, 0, TRUE);
    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);
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACE2,
	"^Y", do_first_line, 0, TRUE);
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACE2,
	"^V", do_last_line, 0, TRUE);

    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);
#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);
1040
1041
#endif

1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
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
1086
1087
1088
1089
1090
#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);
    add_to_sclist(MALL, "^I", do_tab, 0, TRUE);
    add_to_sclist(MALL, "^M", do_enter, 0, TRUE);
    add_to_sclist(MALL, "^D", do_delete, 0, TRUE);
    add_to_sclist(MALL, "^H", do_backspace, 0, TRUE);
    add_to_sclist(MALL, "M-T", do_cut_till_end, 0, TRUE);
#ifndef NANO_TINY
    add_to_sclist(MALL, "M-J", do_full_justify, 0, TRUE);
    add_to_sclist(MALL, "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((MWHEREIS|MREPLACE|MREPLACE2|MGOTOLINE|MWRITEFILE|MINSERTFILE|MEXTCMD|MSPELL|MWHEREISFILE|MGOTODIR), 
	"^C", (void *) cancel_msg, 0, FALSE);
    add_to_sclist(MHELP, "^Y", do_page_up, 0, TRUE);
    add_to_sclist(MHELP, "F7", do_page_up, 0, TRUE);
    add_to_sclist(MHELP, "^V", do_page_down, 0, TRUE);
    add_to_sclist(MHELP, "F8", do_page_down, 0, TRUE);
    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);
    add_to_sclist(MMAIN, "^L", total_refresh, 0, TRUE);
Chris Allegretta's avatar
Chris Allegretta committed
1091

1092
1093
#ifdef DEBUG
    print_sclist();
Chris Allegretta's avatar
Chris Allegretta committed
1094
1095
#endif

1096
}
1097

1098
/* Free the given shortcut. */
1099
1100
1101
void free_shortcutage(shortcut **shortcutage)
{
    assert(shortcutage != NULL);
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1102

1103
1104
1105
1106
1107
1108
1109
    while (*shortcutage != NULL) {
	shortcut *ps = *shortcutage;
	*shortcutage = (*shortcutage)->next;
	free(ps);
    }
}

1110
const subnfunc *sctofunc(sc *s)
1111
{
1112
    subnfunc *f;
1113

1114
1115
    for (f = allfuncs; f != NULL && s->scfunc != f->scfunc; f = f->next)
	;
1116

1117
    return f;
1118
1119
}

1120
1121
1122
1123
#ifndef NANO_TINY
/* Now lets come up with a single (hopefully)
   function to get a string for each flag */
char *flagtostr(int flag)
1124
{
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
   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 "?????";
    }
}
1162

1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
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
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
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
1379
1380
1381
1382
1383
1384
/* 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 */

    if (!strcasecmp(input, "help"))
	s->scfunc = do_help_void;
    else if (!strcasecmp(input, "cancel")) {
	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, "justify"))
	s->scfunc = do_justify_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"))
	s->scfunc = do_page_up;
    else if (!strcasecmp(input, "down"))
	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;
    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;
    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, "nextword"))
	s->scfunc = do_next_word_void;
    else if (!strcasecmp(input, "prevword"))
	s->scfunc = do_prev_word_void;
    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;
    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, "findbracket"))
	s->scfunc = do_find_bracket;
    else if (!strcasecmp(input, "scrollup"))
	s->scfunc = do_scroll_up;
    else if (!strcasecmp(input, "scrolldown"))
	s->scfunc = do_scroll_down;
#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, "fulljustify"))
	s->scfunc = do_full_justify;
    else if (!strcasecmp(input, "wordcount"))
	s->scfunc = do_wordlinechar_count;
    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, "prevhistory")) {
	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, "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;
    } 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;
    } else if (!strcasecmp(input, "whitesplacedisplay")) {
	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;
    } else if (!strcasecmp(input, "suspend")) {
	s->scfunc = (void *) do_toggle;
	s->execute = FALSE;
	s->toggle = SUSPEND;
    } else {
	free(s);
	return NULL;
    }
1385

1386
    return s;
1387

1388
}
1389

1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
/* 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;
}
1426
1427


1428
1429
#endif

1430
1431
1432
#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
1433
1434
 * 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
1435
1436
 * function unless debugging is turned on. */
void thanks_for_all_the_fish(void)
1437
{
1438
1439
1440
1441
    delwin(topwin);
    delwin(edit);
    delwin(bottomwin);

Chris Allegretta's avatar
Chris Allegretta committed
1442
1443
1444
#ifndef DISABLE_JUSTIFY
    if (quotestr != NULL)
	free(quotestr);
1445
1446
#ifdef HAVE_REGEX_H
    regfree(&quotereg);
1447
1448
    if (quoteerr != NULL)
	free(quoteerr);
1449
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1450
#endif
1451
#ifndef NANO_TINY
1452
1453
1454
    if (backup_dir != NULL)
        free(backup_dir);
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1455
#ifndef DISABLE_OPERATINGDIR
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
    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);
1468
#endif
1469
1470
1471
    if (answer != NULL)
	free(answer);
    if (cutbuffer != NULL)
Chris Allegretta's avatar
Chris Allegretta committed
1472
	free_filestruct(cutbuffer);
1473
1474
1475
#ifndef DISABLE_JUSTIFY
    if (jusbuffer != NULL)
	free_filestruct(jusbuffer);
1476
#endif
1477
#ifndef NANO_TINY
1478
    /* Free the memory associated with each toggle. */
1479
1480
    while (toggles != NULL) {
	toggle *t = toggles;
1481

1482
1483
1484
1485
	toggles = toggles->next;
	free(t);
    }
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1486
    /* Free the memory associated with each open file buffer. */
1487
    if (openfile != NULL)
1488
	free_openfilestruct(openfile);
Chris Allegretta's avatar
Chris Allegretta committed
1489
#ifdef ENABLE_COLOR
1490
1491
    if (syntaxstr != NULL)
	free(syntaxstr);
Chris Allegretta's avatar
Chris Allegretta committed
1492
1493
1494
1495
1496
1497
1498
1499
    while (syntaxes != NULL) {
	syntaxtype *bill = syntaxes;

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

	    syntaxes->extensions = bob->next;
1500
	    free(bob->ext_regex);
1501
1502
1503
1504
	    if (bob->ext != NULL) {
		regfree(bob->ext);
		free(bob->ext);
	    }
Chris Allegretta's avatar
Chris Allegretta committed
1505
1506
1507
1508
1509
1510
	    free(bob);
	}
	while (syntaxes->color != NULL) {
	    colortype *bob = syntaxes->color;

	    syntaxes->color = bob->next;
1511
	    free(bob->start_regex);
1512
1513
1514
1515
	    if (bob->start != NULL) {
		regfree(bob->start);
		free(bob->start);
	    }
1516
1517
	    if (bob->end_regex != NULL)
		free(bob->end_regex);
1518
	    if (bob->end != NULL) {
1519
		regfree(bob->end);
1520
1521
		free(bob->end);
	    }
Chris Allegretta's avatar
Chris Allegretta committed
1522
1523
1524
1525
1526
1527
	    free(bob);
	}
	syntaxes = syntaxes->next;
	free(bill);
    }
#endif /* ENABLE_COLOR */
1528
#ifndef NANO_TINY
1529
    /* Free the search and replace history lists. */
1530
1531
1532
1533
    if (searchage != NULL)
	free_filestruct(searchage);
    if (replaceage != NULL)
	free_filestruct(replaceage);
1534
#endif
1535
#ifdef ENABLE_NANORC
1536
1537
    if (homedir != NULL)
	free(homedir);
1538
#endif
1539
}
1540
#endif /* DEBUG */
1541