~ubuntu-branches/ubuntu/vivid/bc/vivid-proposed

« back to all changes in this revision

Viewing changes to bc/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-12-05 12:24:03 UTC
  • mfrom: (3.1.2 lenny)
  • Revision ID: james.westby@ubuntu.com-20071205122403-rv1a7x90ktu1wl95
Tags: 1.06.94-3ubuntu1
* Merge with Debian; remaining changes:
  - Make bc/dc notice read and write errors on its input and output.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* main.c: The main program for bc.  */
2
 
 
3
1
/*  This file is part of GNU bc.
4
 
    Copyright (C) 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
 
2
 
 
3
    Copyright (C) 1991-1994, 1997, 2006 Free Software Foundation, Inc.
5
4
 
6
5
    This program is free software; you can redistribute it and/or modify
7
6
    it under the terms of the GNU General Public License as published by
14
13
    GNU General Public License for more details.
15
14
 
16
15
    You should have received a copy of the GNU General Public License
17
 
    along with this program; see the file COPYING.  If not, write to
 
16
    along with this program; see the file COPYING.  If not, write to:
18
17
      The Free Software Foundation, Inc.
19
 
      59 Temple Place, Suite 330
20
 
      Boston, MA 02111 USA
 
18
      Foundation, Inc.  51 Franklin Street, Fifth Floor,
 
19
      Boston, MA 02110-1301  USA
21
20
 
22
21
    You may contact the author by:
23
22
       e-mail:  philnelson@acm.org
28
27
       
29
28
*************************************************************************/
30
29
 
 
30
/* main.c: The main program for bc.  */
 
31
 
31
32
#include "bcdefs.h"
32
33
#include <signal.h>
33
 
#include "global.h"
 
34
#include <errno.h>
34
35
#include "proto.h"
35
36
#include "getopt.h"
36
37
 
44
45
/* long option support */
45
46
static struct option long_options[] =
46
47
{
47
 
  {"compile",  0, &compile_only, TRUE},
48
 
  {"help",     0, 0,             'h'},
49
 
  {"interactive", 0, 0,          'i'},
50
 
  {"mathlib",  0, &use_math,     TRUE},
51
 
  {"quiet",    0, &quiet,        TRUE},
52
 
  {"standard", 0, &std_only,     TRUE},
53
 
  {"version",  0, 0,             'v'},
54
 
  {"warn",     0, &warn_not_std, TRUE},
 
48
  {"compile",     0, &compile_only, TRUE},
 
49
  {"help",        0, 0,             'h'},
 
50
  {"interactive", 0, 0,             'i'},
 
51
  {"mathlib",     0, &use_math,     TRUE},
 
52
  {"quiet",       0, &quiet,        TRUE},
 
53
  {"standard",    0, &std_only,     TRUE},
 
54
  {"version",     0, 0,             'v'},
 
55
  {"warn",        0, &warn_not_std, TRUE},
55
56
 
56
57
  {0, 0, 0, 0}
57
58
};
63
64
  printf ("usage: %s [options] [file ...]\n%s%s%s%s%s%s%s", progname,
64
65
          "  -h  --help         print this usage and exit\n",
65
66
          "  -i  --interactive  force interactive mode\n",
66
 
          "  -l  --mathlib      use the predefined math routines\n",
 
67
          "  -l  --mathlib      use the predefined math routines\n",
67
68
          "  -q  --quiet        don't print initial banner\n",
68
69
          "  -s  --standard     non-standard bc constructs are errors\n",
69
70
          "  -w  --warn         warn about non-standard bc constructs\n",
136
137
        }
137
138
    }
138
139
 
 
140
#ifdef QUIET
 
141
  quiet = TRUE;
 
142
#endif
 
143
 
139
144
  /* Add file names to a list of files to process. */
140
145
  while (optind < argc)
141
146
    {
161
166
  char *env_argv[30];
162
167
  int   env_argc;
163
168
  
164
 
  /* Initialize many variables. */
165
 
  compile_only = FALSE;
166
 
  use_math = FALSE;
167
 
  warn_not_std = FALSE;
168
 
  std_only = FALSE;
 
169
  /* Interactive? */
169
170
  if (isatty(0) && isatty(1)) 
170
171
    interactive = TRUE;
171
 
  else
172
 
    interactive = FALSE;
173
 
  quiet = FALSE;
174
 
  file_names = NULL;
175
172
 
176
173
#ifdef HAVE_SETVBUF
177
174
  /* attempt to simplify interaction with applications such as emacs */
214
211
  if (env_value != NULL)
215
212
    {
216
213
      line_size = atoi (env_value);
217
 
      if (line_size < 2)
 
214
      if (line_size < 3 && line_size != 0)
218
215
        line_size = 70;
219
216
    }
220
217
  else
265
262
  if (compile_only)
266
263
    printf ("\n");
267
264
 
 
265
#if defined(LIBEDIT)
 
266
  if (edit != NULL)
 
267
    el_end(edit);
 
268
#endif
268
269
  exit (0);
269
270
}
270
271
 
350
351
use_quit (sig)
351
352
     int sig;
352
353
{
353
 
  printf ("\n(interrupt) use quit to exit.\n");
 
354
#ifdef DONTEXIT
 
355
  int save = errno;
 
356
  write (1, "\n(interrupt) use quit to exit.\n", 31);
 
357
#ifdef READLINE
 
358
  rl_initialize (); /* Clear readline buffer */
 
359
#endif
 
360
#ifdef LIBEDIT
 
361
  el_reset (edit); /* Clear editline buffer */
 
362
#endif
354
363
  signal (SIGINT, use_quit);
 
364
  errno = save;
 
365
#else
 
366
  write (1, "\n(interrupt) Exiting bc.\n", 26);
 
367
#ifdef LIBEDIT
 
368
  if (edit != NULL)
 
369
    el_end(edit);
 
370
#endif
 
371
  exit(0);
 
372
#endif
355
373
}