clean up main() a bit

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1808 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2004-06-12 21:03:14 +00:00
parent 3b0729cf5d
commit 74af3a7419
2 changed files with 53 additions and 52 deletions

View File

@ -246,6 +246,8 @@ CVS code -
one from the command line and/or rcfile, as Pico does. Don't one from the command line and/or rcfile, as Pico does. Don't
do this if we're in restricted mode, since spell checking is do this if we're in restricted mode, since spell checking is
disabled then. (DLR) disabled then. (DLR)
- Add some cleanups for greater readability, and remove a few
bits of redundant code. (DLR and David Benbennick)
- nano.h: - nano.h:
- Since REGEXP_COMPILED is only used in search.c, convert it - Since REGEXP_COMPILED is only used in search.c, convert it
from a flag to a static int there. (DLR) from a flag to a static int there. (DLR)

View File

@ -3032,10 +3032,9 @@ int main(int argc, char *argv[])
{ {
int optchr; int optchr;
int startline = 0; /* Line to try and start at */ int startline = 0; /* Line to try and start at */
int modify_control_seq = 0; int fill_flag_used = FALSE; /* Was the fill option used? */
int fill_flag_used = 0; /* Was the fill option used? */
const shortcut *s; const shortcut *s;
int keyhandled = 0; /* Have we handled the keystroke yet? */ int keyhandled = FALSE; /* Have we handled the keystroke yet? */
int kbinput; /* Input from keyboard */ int kbinput; /* Input from keyboard */
int meta_key; int meta_key;
@ -3260,7 +3259,7 @@ int main(int argc, char *argv[])
else else
wrap_at = i; wrap_at = i;
} }
fill_flag_used = 1; fill_flag_used = TRUE;
break; break;
#endif #endif
#ifndef DISABLE_SPELLER #ifndef DISABLE_SPELLER
@ -3406,17 +3405,19 @@ int main(int argc, char *argv[])
#ifndef DISABLE_JUSTIFY #ifndef DISABLE_JUSTIFY
if (punct == NULL) if (punct == NULL)
punct = mallocstrcpy(punct, ".?!"); punct = mallocstrcpy(punct, ".?!");
if (brackets == NULL) if (brackets == NULL)
brackets = mallocstrcpy(brackets, "'\")}]>"); brackets = mallocstrcpy(brackets, "'\")}]>");
if (quotestr == NULL) if (quotestr == NULL)
quotestr = mallocstrcpy(NULL,
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
quotestr = mallocstrcpy(NULL, "^([ \t]*[|>:}#])+"); "^([ \t]*[|>:}#])+"
#else #else
quotestr = mallocstrcpy(NULL, "> "); "> "
#endif #endif
);
#endif /* !DISABLE_JUSTIFY */ #endif /* !DISABLE_JUSTIFY */
#ifndef DISABLE_SPELLER #ifndef DISABLE_SPELLER
@ -3548,20 +3549,11 @@ int main(int argc, char *argv[])
sigsetjmp(jmpbuf, 1); sigsetjmp(jmpbuf, 1);
#endif #endif
/* SHUT UP GCC! */
startline = 0;
fill_flag_used = 0;
keyhandled = 0;
/* This variable should be initialized after the sigsetjmp(), so we
can't do Esc-Esc then quickly resize and muck things up. */
modify_control_seq = 0;
edit_refresh(); edit_refresh();
reset_cursor(); reset_cursor();
while (TRUE) { while (TRUE) {
keyhandled = 0; keyhandled = FALSE;
if (ISSET(CONSTUPDATE)) if (ISSET(CONSTUPDATE))
do_cursorpos(1); do_cursorpos(1);
@ -3576,7 +3568,13 @@ int main(int argc, char *argv[])
#endif #endif
if (meta_key == TRUE) { if (meta_key == TRUE) {
/* Check for the metaval and miscval defs... */ /* Check for the metaval and miscval defs... */
for (s = main_list; s != NULL; s = s->next) for (s =
#if !defined(DISABLE_BROWSER) || !defined (DISABLE_HELP) || !defined(DISABLE_MOUSE)
currshortcut
#else
main_list
#endif
; s != NULL && !keyhandled; s = s->next) {
if ((s->metaval != NANO_NO_KEY && kbinput == s->metaval) || if ((s->metaval != NANO_NO_KEY && kbinput == s->metaval) ||
(s->miscval != NANO_NO_KEY && kbinput == s->miscval)) { (s->miscval != NANO_NO_KEY && kbinput == s->miscval)) {
if (ISSET(VIEW_MODE) && !s->viewok) if (ISSET(VIEW_MODE) && !s->viewok)
@ -3586,18 +3584,21 @@ int main(int argc, char *argv[])
cutbuffer_reset(); cutbuffer_reset();
s->func(); s->func();
} }
keyhandled = 1; keyhandled = TRUE;
} }
#ifndef NANO_SMALL #ifndef NANO_SMALL
if (!keyhandled) if (!keyhandled) {
/* And for toggle switches */ /* And for toggle switches */
for (t = toggles; t != NULL; t = t->next) for (t = toggles; t != NULL; t = t->next) {
if (kbinput == t->val) { if (kbinput == t->val) {
cutbuffer_reset(); cutbuffer_reset();
do_toggle(t); do_toggle(t);
keyhandled = 1; keyhandled = TRUE;
} }
}
}
#endif #endif
}
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "I got Alt-%c! (%d)\n", kbinput, fprintf(stderr, "I got Alt-%c! (%d)\n", kbinput,
kbinput); kbinput);
@ -3607,12 +3608,14 @@ int main(int argc, char *argv[])
/* Look through the main shortcut list to see if we've hit a /* Look through the main shortcut list to see if we've hit a
shortcut key or function key */ shortcut key or function key */
if (!keyhandled) if (!keyhandled) {
for (s =
#if !defined(DISABLE_BROWSER) || !defined (DISABLE_HELP) || !defined(DISABLE_MOUSE) #if !defined(DISABLE_BROWSER) || !defined (DISABLE_HELP) || !defined(DISABLE_MOUSE)
for (s = currshortcut; s != NULL && !keyhandled; s = s->next) { currshortcut
#else #else
for (s = main_list; s != NULL && !keyhandled; s = s->next) { main_list
#endif #endif
; s != NULL && !keyhandled; s = s->next) {
if ((s->ctrlval != NANO_NO_KEY && kbinput == s->ctrlval) || if ((s->ctrlval != NANO_NO_KEY && kbinput == s->ctrlval) ||
(s->funcval != NANO_NO_KEY && kbinput == s->funcval)) { (s->funcval != NANO_NO_KEY && kbinput == s->funcval)) {
if (ISSET(VIEW_MODE) && !s->viewok) if (ISSET(VIEW_MODE) && !s->viewok)
@ -3622,12 +3625,10 @@ int main(int argc, char *argv[])
cutbuffer_reset(); cutbuffer_reset();
s->func(); s->func();
} }
keyhandled = 1; keyhandled = TRUE;
/* Break out explicitly once we successfully handle
a shortcut */
break;
} }
} }
}
if (!keyhandled) if (!keyhandled)
cutbuffer_reset(); cutbuffer_reset();
@ -3641,42 +3642,40 @@ int main(int argc, char *argv[])
/* If we're in raw mode or using Alt-Alt-x, we have to catch /* If we're in raw mode or using Alt-Alt-x, we have to catch
Control-S and Control-Q */ Control-S and Control-Q */
if (kbinput == NANO_CONTROL_Q || kbinput == NANO_CONTROL_S) if (kbinput == NANO_CONTROL_Q || kbinput == NANO_CONTROL_S)
keyhandled = 1; keyhandled = TRUE;
/* Catch ^Z by hand when triggered also */ /* Catch ^Z by hand when triggered also */
if (kbinput == NANO_SUSPEND_KEY) { if (kbinput == NANO_SUSPEND_KEY) {
if (ISSET(SUSPEND)) if (ISSET(SUSPEND))
do_suspend(0); do_suspend(0);
keyhandled = 1; keyhandled = TRUE;
} }
/* Last gasp, stuff that's not in the main lists */ /* Last gasp, stuff that's not in the main lists */
if (!keyhandled) if (!keyhandled) {
switch (kbinput) { switch (kbinput) {
#ifndef DISABLE_MOUSE #ifndef DISABLE_MOUSE
case KEY_MOUSE: case KEY_MOUSE:
do_mouse(); do_mouse();
break; break;
#endif #endif
case NANO_CONTROL_3: /* Ctrl-[ (Esc), which should
case NANO_CONTROL_3: /* Ctrl-[ (Esc), which should * have been handled before we
* have been handled before we * got here */
* got here */ case NANO_CONTROL_5: /* Ctrl-] */
case NANO_CONTROL_5: /* Ctrl-] */ break;
break; default:
default:
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "I got %c (%d)!\n", kbinput, kbinput); fprintf(stderr, "I got %c (%d)!\n", kbinput, kbinput);
#endif #endif
/* We no longer stop unhandled sequences so that people with /* We no longer stop unhandled sequences so that
odd character sets can type... */ people with odd character sets can type... */
if (ISSET(VIEW_MODE))
if (ISSET(VIEW_MODE)) print_view_warning();
print_view_warning(); else
else do_char((char)kbinput);
do_char((char)kbinput);
} }
}
reset_cursor(); reset_cursor();
wrefresh(edit); wrefresh(edit);
} }