diff options
Diffstat (limited to 'bc/main.c')
-rw-r--r-- | bc/main.c | 80 |
1 files changed, 49 insertions, 31 deletions
@@ -1,7 +1,6 @@ -/* main.c: The main program for bc. */ - /* This file is part of GNU bc. - Copyright (C) 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc. + + Copyright (C) 1991-1994, 1997, 2006 Free Software Foundation, Inc. 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 @@ -14,10 +13,10 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; see the file COPYING. If not, write to + along with this program; see the file COPYING. If not, write to: The Free Software Foundation, Inc. - 59 Temple Place, Suite 330 - Boston, MA 02111 USA + Foundation, Inc. 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301 USA You may contact the author by: e-mail: philnelson@acm.org @@ -28,9 +27,11 @@ *************************************************************************/ +/* main.c: The main program for bc. */ + #include "bcdefs.h" #include <signal.h> -#include "global.h" +#include <errno.h> #include "proto.h" #include "getopt.h" @@ -44,26 +45,26 @@ static file_node *last = NULL; /* long option support */ static struct option long_options[] = { - {"compile", 0, &compile_only, TRUE}, - {"help", 0, 0, 'h'}, - {"interactive", 0, 0, 'i'}, - {"mathlib", 0, &use_math, TRUE}, - {"quiet", 0, &quiet, TRUE}, - {"standard", 0, &std_only, TRUE}, - {"version", 0, 0, 'v'}, - {"warn", 0, &warn_not_std, TRUE}, + {"compile", 0, &compile_only, TRUE}, + {"help", 0, 0, 'h'}, + {"interactive", 0, 0, 'i'}, + {"mathlib", 0, &use_math, TRUE}, + {"quiet", 0, &quiet, TRUE}, + {"standard", 0, &std_only, TRUE}, + {"version", 0, 0, 'v'}, + {"warn", 0, &warn_not_std, TRUE}, {0, 0, 0, 0} }; -void -usage (char *progname) +static void +usage (const char *progname) { printf ("usage: %s [options] [file ...]\n%s%s%s%s%s%s%s", progname, " -h --help print this usage and exit\n", " -i --interactive force interactive mode\n", - " -l --mathlib use the predefine math routnes\n", + " -l --mathlib use the predefined math routines\n", " -q --quiet don't print initial banner\n", " -s --standard non-standard bc constructs are errors\n", " -w --warn warn about non-standard bc constructs\n", @@ -71,7 +72,7 @@ usage (char *progname) } -void +static void parse_args (argc, argv) int argc; char **argv; @@ -93,6 +94,9 @@ parse_args (argc, argv) switch (optch) { + case 0: /* Long option setting a var. */ + break; + case 'c': /* compile only */ compile_only = TRUE; break; @@ -133,6 +137,10 @@ parse_args (argc, argv) } } +#ifdef QUIET + quiet = TRUE; +#endif + /* Add file names to a list of files to process. */ while (optind < argc) { @@ -155,20 +163,12 @@ main (argc, argv) char *argv[]; { char *env_value; - char *env_argv[30]; + const char *env_argv[30]; int env_argc; - /* Initialize many variables. */ - compile_only = FALSE; - use_math = FALSE; - warn_not_std = FALSE; - std_only = FALSE; + /* Interactive? */ if (isatty(0) && isatty(1)) interactive = TRUE; - else - interactive = FALSE; - quiet = FALSE; - file_names = NULL; #ifdef HAVE_SETVBUF /* attempt to simplify interaction with applications such as emacs */ @@ -211,7 +211,7 @@ main (argc, argv) if (env_value != NULL) { line_size = atoi (env_value); - if (line_size < 2) + if (line_size < 3 && line_size != 0) line_size = 70; } else @@ -262,6 +262,10 @@ main (argc, argv) if (compile_only) printf ("\n"); +#if defined(LIBEDIT) + if (edit != NULL) + el_end(edit); +#endif exit (0); } @@ -347,6 +351,20 @@ void use_quit (sig) int sig; { - printf ("\n(interrupt) use quit to exit.\n"); +#ifdef DONTEXIT + int save = errno; + write (1, "\n(interrupt) use quit to exit.\n", 31); signal (SIGINT, use_quit); + errno = save; +#else + write (1, "\n(interrupt) Exiting bc.\n", 26); +#ifdef READLINE + rl_initialize (); /* Clear readline buffer */ +#endif +#if defined(LIBEDIT) + if (edit != NULL) + el_end(edit); +#endif + exit(0); +#endif } |