Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/gnu/dist/bc Finish the import of bc-1.06.



details:   https://anonhg.NetBSD.org/src/rev/f337c80121e5
branches:  trunk
changeset: 501821:f337c80121e5
user:      phil <phil%NetBSD.org@localhost>
date:      Mon Jan 08 04:03:30 2001 +0000

description:
Finish the import of bc-1.06.

diffstat:

 gnu/dist/bc/bc/libmath.b |     6 +-
 gnu/dist/bc/bc/main.c    |    92 ++-
 gnu/dist/bc/bc/scan.l    |   118 ++++-
 gnu/dist/bc/doc/bc.1     |   119 ++--
 gnu/dist/bc/doc/dc.texi  |    26 +-
 gnu/dist/bc/lib/getopt.c |     3 +-
 gnu/dist/bc/lib/number.c |  1113 +++++++++++++++++++++++++++------------------
 7 files changed, 896 insertions(+), 581 deletions(-)

diffs (truncated from 2420 to 300 lines):

diff -r 0d09b4dbf98e -r f337c80121e5 gnu/dist/bc/bc/libmath.b
--- a/gnu/dist/bc/bc/libmath.b  Mon Jan 08 03:28:58 2001 +0000
+++ b/gnu/dist/bc/bc/libmath.b  Mon Jan 08 04:03:30 2001 +0000
@@ -15,10 +15,12 @@
 
     You should have received a copy of the GNU General Public License
     along with this program; see the file COPYING.  If not, write to
-    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+      The Free Software Foundation, Inc.
+      59 Temple Place, Suite 330
+      Boston, MA 02111 USA
 
     You may contact the author by:
-       e-mail:  phil%cs.wwu.edu@localhost
+       e-mail:  philnelson%acm.org@localhost
       us-mail:  Philip A. Nelson
                 Computer Science Department, 9062
                 Western Washington University
diff -r 0d09b4dbf98e -r f337c80121e5 gnu/dist/bc/bc/main.c
--- a/gnu/dist/bc/bc/main.c     Mon Jan 08 03:28:58 2001 +0000
+++ b/gnu/dist/bc/bc/main.c     Mon Jan 08 04:03:30 2001 +0000
@@ -1,7 +1,7 @@
 /* main.c: The main program for bc.  */
 
 /*  This file is part of GNU bc.
-    Copyright (C) 1991, 1992, 1993, 1994, 1997, 1998 Free Software Foundation, Inc.
+    Copyright (C) 1991-1994, 1997, 1998, 2000 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
@@ -15,10 +15,12 @@
 
     You should have received a copy of the GNU General Public License
     along with this program; see the file COPYING.  If not, write to
-    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+      The Free Software Foundation, Inc.
+      59 Temple Place, Suite 330
+      Boston, MA 02111 USA
 
     You may contact the author by:
-       e-mail:  phil%cs.wwu.edu@localhost
+       e-mail:  philnelson%acm.org@localhost
       us-mail:  Philip A. Nelson
                 Computer Science Department, 9062
                 Western Washington University
@@ -30,26 +32,21 @@
 #include <signal.h>
 #include "global.h"
 #include "proto.h"
-#include <getopt.h>
+#include "getopt.h"
 
 
 /* Variables for processing multiple files. */
-char   first_file;
-extern FILE *yyin;
+static char first_file;
 
 /* Points to the last node in the file name list for easy adding. */
 static file_node *last = NULL;
 
-#ifdef READLINE
-/* Readline support. */
-extern char *rl_readline_name;
-extern FILE *rl_instream;
-#endif
-
 /* 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},
@@ -61,6 +58,20 @@
 
 
 void
+usage (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",
+         "  -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",
+         "  -v  --version      print version information and exit\n");
+}
+
+
+void
 parse_args (argc, argv)
      int argc;
      char **argv;
@@ -75,7 +86,7 @@
   /* Parse the command line */
   while (1)
     {
-      optch = getopt_long (argc, argv, "lciqsvw", long_options, &long_index);
+      optch = getopt_long (argc, argv, "chilqswv", long_options, &long_index);
 
       if (optch == EOF)  /* End of arguments. */
        break;
@@ -86,14 +97,19 @@
          compile_only = TRUE;
          break;
 
-       case 'l':  /* math lib */
-         use_math = TRUE;
+       case 'h':  /* help */
+         usage(argv[0]);
+         exit (0);
          break;
 
        case 'i':  /* force interactive */
          interactive = TRUE;
          break;
 
+       case 'l':  /* math lib */
+         use_math = TRUE;
+         break;
+
        case 'q':  /* quiet mode */
          quiet = TRUE;
          break;
@@ -103,13 +119,17 @@
          break;
 
        case 'v':  /* Print the version. */
-         printf ("%s\n", BC_VERSION);
+         show_bc_version ();
          exit (0);
          break;
 
        case 'w':  /* Non standard features give warnings. */
          warn_not_std = TRUE;
          break;
+
+       default:
+         usage(argv[0]);
+         exit (1);
        }
     }
 
@@ -213,7 +233,20 @@
   if (!open_new_file ())
     exit (1);
 
-#ifdef READLINE
+#if defined(LIBEDIT)
+  if (interactive) {
+    /* Enable libedit support. */
+    edit = el_init ("bc", stdin, stdout, stderr);
+    hist = history_init();
+    el_set (edit, EL_EDITOR, "emacs");
+    el_set (edit, EL_HIST, history, hist);
+    el_set (edit, EL_PROMPT, null_prompt);
+    el_source (edit, NULL);
+    history (hist, &histev, H_SETSIZE, INT_MAX);
+  }
+#endif
+
+#if defined(READLINE)
   if (interactive) {
     /* Readline support.  Set both application name and input file. */
     rl_readline_name = "bc";
@@ -252,23 +285,9 @@
   /* Open the other files. */
   if (use_math && first_file)
     {
-#ifdef BC_MATH_FILE
-      /* Make the first file be the math library. */
-      new_file = fopen (BC_MATH_FILE, "r");
-      use_math = FALSE;
-      if (new_file != NULL)
-       {
-         new_yy_file (new_file);
-         return TRUE;
-       }       
-      else
-       {
-         fprintf (stderr, "Math Library unavailable.\n");
-         exit (1);
-       }
-#else
       /* Load the code from a precompiled version of the math libarary. */
-      extern char libmath[];
+      extern char *libmath[];
+      char **mstr;
       char tmp;
       /* These MUST be in the order of first mention of each function.
         That is why "a" comes before "c" even though "a" is defined after
@@ -279,8 +298,11 @@
       tmp = lookup ("a", FUNCT);
       tmp = lookup ("c", FUNCT);
       tmp = lookup ("j", FUNCT);
-      load_code (libmath);
-#endif
+      mstr = libmath;
+      while (*mstr) {
+           load_code (*mstr);
+          mstr++;
+      }
     }
   
   /* One of the argv values. */
diff -r 0d09b4dbf98e -r f337c80121e5 gnu/dist/bc/bc/scan.l
--- a/gnu/dist/bc/bc/scan.l     Mon Jan 08 03:28:58 2001 +0000
+++ b/gnu/dist/bc/bc/scan.l     Mon Jan 08 04:03:30 2001 +0000
@@ -16,10 +16,12 @@
 
     You should have received a copy of the GNU General Public License
     along with this program; see the file COPYING.  If not, write to
-    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+      The Free Software Foundation, Inc.
+      59 Temple Place, Suite 330
+      Boston, MA 02111 USA
 
     You may contact the author by:
-       e-mail:  phil%cs.wwu.edu@localhost
+       e-mail:  philnelson%acm.org@localhost
       us-mail:  Philip A. Nelson
                 Computer Science Department, 9062
                 Western Washington University
@@ -48,6 +50,83 @@
 #undef yywrap
 _PROTOTYPE(int yywrap, (void));
 
+#if defined(LIBEDIT)
+/* Support for the BSD libedit with history for
+   nicer input on the interactive part of input. */
+
+#include <histedit.h>
+
+/* Have input call the following function. */
+#undef  YY_INPUT
+#define YY_INPUT(buf,result,max_size) \
+               bcel_input((char *)buf, &result, max_size)
+
+/* Variables to help interface editline with bc. */
+static const char *bcel_line = (char *)NULL;
+static int   bcel_len = 0;
+
+
+/* Required to get rid of that ugly ? default prompt! */
+char *
+null_prompt (EditLine *el)
+{
+  return "";
+}
+
+
+/* bcel_input puts upto MAX characters into BUF with the number put in
+   BUF placed in *RESULT.  If the yy input file is the same as
+   stdin, use editline.  Otherwise, just read it.
+*/
+
+static void
+bcel_input (buf, result, max)
+       char *buf;
+       int  *result;
+       int   max;
+{
+  if (!edit || yyin != stdin)
+    {
+      while ( (*result = read( fileno(yyin), buf, max )) < 0 )
+        if (errno != EINTR)
+         {
+           yyerror( "read() in flex scanner failed" );
+           exit (1);
+         }
+      return;
+    }
+
+  /* Do we need a new string? */
+  if (bcel_len == 0)
+    {
+      bcel_line = el_gets(edit, &bcel_len);
+      if (bcel_line == NULL) {
+       /* end of file */
+       *result = 0;
+       bcel_len = 0;
+       return;
+      }
+      if (bcel_len != 0)
+       history (hist, &histev, H_ENTER, bcel_line); 
+      fflush (stdout);
+    }
+
+  if (bcel_len <= max)
+    {
+      strncpy (buf, bcel_line, bcel_len);
+      *result = bcel_len;
+      bcel_len = 0;
+    }
+  else
+    {



Home | Main Index | Thread Index | Old Index