head	1.5;
access;
symbols
	perseant-exfatfs-base-20250801:1.5
	perseant-exfatfs-base-20240630:1.5
	cjep_sun2x:1.5.0.44
	cjep_sun2x-base:1.5
	cjep_staticlib_x-base1:1.5
	cjep_staticlib_x:1.5.0.42
	cjep_staticlib_x-base:1.5
	phil-wifi-20200421:1.5
	phil-wifi-20200411:1.5
	phil-wifi-20200406:1.5
	pgoyette-compat-merge-20190127:1.5
	pgoyette-compat-20190127:1.5
	pgoyette-compat-20190118:1.5
	pgoyette-compat-1226:1.5
	pgoyette-compat-1126:1.5
	pgoyette-compat-1020:1.5
	pgoyette-compat-0930:1.5
	pgoyette-compat-0906:1.5
	pgoyette-compat-0728:1.5
	pgoyette-compat-0625:1.5
	pgoyette-compat-0521:1.5
	pgoyette-compat-0502:1.5
	pgoyette-compat-0422:1.5
	pgoyette-compat-0415:1.5
	pgoyette-compat-0407:1.5
	pgoyette-compat-0330:1.5
	pgoyette-compat-0322:1.5
	pgoyette-compat-0315:1.5
	pgoyette-compat:1.5.0.40
	pgoyette-compat-base:1.5
	perseant-stdc-iso10646:1.5.0.38
	perseant-stdc-iso10646-base:1.5
	prg-localcount2-base3:1.5
	prg-localcount2-base2:1.5
	prg-localcount2-base1:1.5
	prg-localcount2:1.5.0.36
	prg-localcount2-base:1.5
	pgoyette-localcount-20170426:1.5
	bouyer-socketcan-base1:1.5
	pgoyette-localcount-20170320:1.5
	bouyer-socketcan:1.5.0.34
	bouyer-socketcan-base:1.5
	pgoyette-localcount-20170107:1.5
	pgoyette-localcount-20161104:1.5
	localcount-20160914:1.5
	pgoyette-localcount-20160806:1.5
	pgoyette-localcount-20160726:1.5
	pgoyette-localcount:1.5.0.32
	pgoyette-localcount-base:1.5
	netbsd-5-2-3-RELEASE:1.5
	netbsd-5-1-5-RELEASE:1.5
	yamt-pagecache-base9:1.5
	yamt-pagecache-tag8:1.5
	tls-earlyentropy:1.5.0.28
	tls-earlyentropy-base:1.5
	riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.5
	riastradh-drm2-base3:1.5
	netbsd-5-2-2-RELEASE:1.5
	netbsd-5-1-4-RELEASE:1.5
	netbsd-5-2-1-RELEASE:1.5
	netbsd-5-1-3-RELEASE:1.5
	agc-symver:1.5.0.30
	agc-symver-base:1.5
	tls-maxphys-base:1.5
	yamt-pagecache-base8:1.5
	netbsd-5-2:1.5.0.26
	yamt-pagecache-base7:1.5
	netbsd-5-2-RELEASE:1.5
	netbsd-5-2-RC1:1.5
	yamt-pagecache-base6:1.5
	yamt-pagecache-base5:1.5
	yamt-pagecache-base4:1.5
	netbsd-5-1-2-RELEASE:1.5
	netbsd-5-1-1-RELEASE:1.5
	yamt-pagecache-base3:1.5
	yamt-pagecache-base2:1.5
	yamt-pagecache:1.5.0.24
	yamt-pagecache-base:1.5
	bouyer-quota2-nbase:1.5
	bouyer-quota2:1.5.0.22
	bouyer-quota2-base:1.5
	matt-nb5-pq3:1.5.0.20
	matt-nb5-pq3-base:1.5
	netbsd-5-1:1.5.0.18
	netbsd-5-1-RELEASE:1.5
	netbsd-5-1-RC4:1.5
	netbsd-5-1-RC3:1.5
	netbsd-5-1-RC2:1.5
	netbsd-5-1-RC1:1.5
	netbsd-5-0-2-RELEASE:1.5
	netbsd-5-0-1-RELEASE:1.5
	jym-xensuspend-nbase:1.5
	netbsd-5-0:1.5.0.16
	netbsd-5-0-RELEASE:1.5
	netbsd-5-0-RC4:1.5
	netbsd-5-0-RC3:1.5
	netbsd-5-0-RC2:1.5
	jym-xensuspend:1.5.0.14
	jym-xensuspend-base:1.5
	netbsd-5-0-RC1:1.5
	netbsd-5:1.5.0.12
	netbsd-5-base:1.5
	mjf-devfs2:1.5.0.10
	mjf-devfs2-base:1.5
	yamt-pf42-base4:1.5
	yamt-pf42-base3:1.5
	hpcarm-cleanup-nbase:1.5
	yamt-pf42-base2:1.5
	yamt-pf42:1.5.0.8
	yamt-pf42-base:1.5
	keiichi-mipv6:1.5.0.6
	keiichi-mipv6-base:1.5
	cube-autoconf:1.5.0.4
	cube-autoconf-base:1.5
	hpcarm-cleanup:1.5.0.2
	hpcarm-cleanup-base:1.5
	netbsd-1-3-PATCH003:1.4
	netbsd-1-3-PATCH003-CANDIDATE2:1.4
	netbsd-1-3-PATCH003-CANDIDATE1:1.4
	netbsd-1-3-PATCH003-CANDIDATE0:1.4
	netbsd-1-3-PATCH002:1.4
	netbsd-1-3-PATCH001:1.4
	netbsd-1-3-RELEASE:1.4
	netbsd-1-3-BETA:1.4
	netbsd-1-3:1.4.0.2
	netbsd-1-3-base:1.4
	fsf-bc-1-04:1.1.1.2
	fsf:1.1.1
	netbsd-1-2-PATCH001:1.3
	netbsd-1-2-RELEASE:1.3
	netbsd-1-2-BETA:1.3
	netbsd-1-2-base:1.3
	netbsd-1-2:1.3.0.6
	netbsd-1-1-PATCH001:1.3
	netbsd-1-1-RELEASE:1.3
	netbsd-1-1:1.3.0.2
	netbsd-1-1-base:1.3
	bc-1-03:1.1.1.1
	GNU-bc-1-03:1.1.1
	netbsd-1-0-PATCH06:1.2
	netbsd-1-0-PATCH05:1.2
	netbsd-1-0-PATCH04:1.2
	netbsd-1-0-PATCH03:1.2
	netbsd-1-0-PATCH02:1.2
	netbsd-1-0-PATCH1:1.2
	netbsd-1-0-PATCH0:1.2
	netbsd-1-0-RELEASE:1.2
	netbsd-1-0:1.2.0.2
	netbsd-1-0-base:1.2
	netbsd-0-9-RELEASE:1.1
	netbsd-0-9-BETA:1.1
	netbsd-0-9-ALPHA2:1.1
	netbsd-0-9-ALPHA:1.1
	netbsd-0-9:1.1.0.2
	netbsd-0-9-base:1.1
	netbsd-0-8:1.1
	netbsd-alpha-1:1.1;
locks; strict;
comment	@ * @;


1.5
date	99.01.16.05.57.49;	author simonb;	state dead;
branches;
next	1.4;

1.4
date	97.04.29.00.29.11;	author phil;	state Exp;
branches;
next	1.3;

1.3
date	94.12.02.00.43.36;	author phil;	state Exp;
branches;
next	1.2;

1.2
date	93.08.02.17.25.40;	author mycroft;	state Exp;
branches;
next	1.1;

1.1
date	93.04.10.15.52.21;	author cgd;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	94.12.01.04.24.03;	author phil;	state Exp;
branches;
next	1.1.1.2;

1.1.1.2
date	97.04.29.00.11.18;	author phil;	state Exp;
branches;
next	;


desc
@@


1.5
log
@Update bc to 1.05a and dc to 1.2, which source in src/gnu/dist/bc.
@
text
@/* main.c: The main program for bc.  */

/*  This file is part of GNU bc.
    Copyright (C) 1991, 1992, 1993, 1994, 1997 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
    the Free Software Foundation; either version 2 of the License , or
    (at your option) any later version.

    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.

    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.

    You may contact the author by:
       e-mail:  phil@@cs.wwu.edu
      us-mail:  Philip A. Nelson
                Computer Science Department, 9062
                Western Washington University
                Bellingham, WA 98226-9062
       
*************************************************************************/

#include "bcdefs.h"
#include <signal.h>
#include "global.h"
#include "proto.h"
#include "getopt.h"


/* Variables for processing multiple files. */
char   first_file;
extern FILE *yyin;

/* 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},
  {"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
parse_args (argc, argv)
     int argc;
     char **argv;
{
  int optch;
  int long_index;
  file_node *temp;

  /* Force getopt to initialize.  Depends on GNU getopt. */
  optind = 0;

  /* Parse the command line */
  while (1)
    {
      optch = getopt_long (argc, argv, "lciqsvw", long_options, &long_index);

      if (optch == EOF)  /* End of arguments. */
	break;

      switch (optch)
	{
	case 'c':  /* compile only */
	  compile_only = TRUE;
	  break;

	case 'l':  /* math lib */
	  use_math = TRUE;
	  break;

	case 'i':  /* force interactive */
	  interactive = TRUE;
	  break;

	case 'q':  /* quiet mode */
	  quiet = TRUE;
	  break;

	case 's':  /* Non standard features give errors. */
	  std_only = TRUE;
	  break;

	case 'v':  /* Print the version. */
	  printf ("%s\n", BC_VERSION);
	  exit (0);
	  break;

	case 'w':  /* Non standard features give warnings. */
	  warn_not_std = TRUE;
	  break;
	}
    }

  /* Add file names to a list of files to process. */
  while (optind < argc)
    {
      temp = (file_node *) bc_malloc(sizeof(file_node));
      temp->name = argv[optind];
      temp->next = NULL;
      if (last == NULL)
	file_names = temp;
      else
	last->next = temp;
      last = temp;
      optind++;
    }
}

/* The main program for bc. */
int
main (argc, argv)
     int argc;
     char *argv[];
{
  char *env_value;
  char *env_argv[30];
  int   env_argc;
  
  /* Initialize many variables. */
  compile_only = FALSE;
  use_math = FALSE;
  warn_not_std = FALSE;
  std_only = FALSE;
  if (isatty(0) && isatty(1)) 
    interactive = TRUE;
  else
    interactive = FALSE;
  quiet = FALSE;
  file_names = NULL;

  /* Environment arguments. */
  env_value = getenv ("BC_ENV_ARGS");
  if (env_value != NULL)
    {
      env_argc = 1;
      env_argv[0] = "BC_ENV_ARGS";
      while (*env_value != 0)
	{
	  if (*env_value != ' ')
	    {
	      env_argv[env_argc++] = env_value;
	      while (*env_value != ' ' && *env_value != 0)
		env_value++;
	      if (*env_value != 0)
		{
		  *env_value = 0;
		  env_value++;
		}
	    }
	  else
	    env_value++;
	}
      parse_args (env_argc, env_argv);
    }

  /* Command line arguments. */
  parse_args (argc, argv);

  /* Other environment processing. */
  if (getenv ("POSIXLY_CORRECT") != NULL)
    std_only = TRUE;

  env_value = getenv ("BC_LINE_LENGTH");
  if (env_value != NULL)
    {
      line_size = atoi (env_value);
      if (line_size < 2)
	line_size = 70;
    }
  else
    line_size = 70;

  /* Initialize the machine.  */
  init_storage();
  init_load();

  /* Set up interrupts to print a message. */
  if (interactive)
    signal (SIGINT, use_quit);

  /* Initialize the front end. */
  init_tree();
  init_gen ();
  is_std_in = FALSE;
  first_file = TRUE;
  if (!open_new_file ())
    exit (1);

#ifdef READLINE
  /* Readline support.  Set both application name and input file. */
  rl_readline_name = "bc";
  rl_instream = stdin;
  using_history ();
#endif

  /* Do the parse. */
  yyparse ();

  /* End the compile only output with a newline. */
  if (compile_only)
    printf ("\n");

  exit (0);
}


/* This is the function that opens all the files. 
   It returns TRUE if the file was opened, otherwise
   it returns FALSE. */

int
open_new_file ()
{
  FILE *new_file;
  file_node *temp;

  /* Set the line number. */
  line_no = 1;

  /* Check to see if we are done. */
  if (is_std_in) return (FALSE);

  /* 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[];
      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
	 after "c".  "a" is used in "s"! */
      tmp = lookup ("e", FUNCT);
      tmp = lookup ("l", FUNCT);
      tmp = lookup ("s", FUNCT);
      tmp = lookup ("a", FUNCT);
      tmp = lookup ("c", FUNCT);
      tmp = lookup ("j", FUNCT);
      load_code (libmath);
#endif
    }
  
  /* One of the argv values. */
  if (file_names != NULL)
    {
      new_file = fopen (file_names->name, "r");
      if (new_file != NULL)
	{
	  new_yy_file (new_file);
	  temp = file_names;
	  file_name  = temp->name;
	  file_names = temp->next;
	  free (temp);
	  return TRUE;
	}
      fprintf (stderr, "File %s is unavailable.\n", file_names->name);
      exit (1);
    }
  
  /* If we fall through to here, we should return stdin. */
  new_yy_file (stdin);
  is_std_in = TRUE;
  return TRUE;
}


/* Set yyin to the new file. */

void
new_yy_file (file)
     FILE *file;
{
  if (!first_file) fclose (yyin);
  yyin = file;
  first_file = FALSE;
}


/* Message to use quit.  */

void
use_quit (sig)
     int sig;
{
  printf ("\n(interrupt) use quit to exit.\n");
  signal (SIGINT, use_quit);
}
@


1.4
log
@Cleanup for import of bc-1.04.  Removing many files not needed for bc-1.04.
Cleanup here due to a major reorganization of fsf tree and the desire
to keep the NetBSD tree as clean as possible.
@
text
@@


1.3
log
@Updating to 1.03 with RCS added to most .[chyl] files
@
text
@a0 2
/* 	$NetBSD: $  */

d3 2
a4 2
/*  This file is part of bc written for MINIX.
    Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
d33 2
d40 2
d43 22
a64 3
/* The main program for bc. */
int
main (argc, argv)
d66 1
a66 1
     char *argv[];
d68 6
a73 11
  int  ch; 
  
  /* Initialize many variables. */
  compile_only = FALSE;
  use_math = FALSE;
  warn_not_std = FALSE;
  std_only = FALSE;
  if (isatty(0) && isatty(1)) 
    interactive = TRUE;
  else
    interactive = FALSE;
d76 1
a76 2
  ch = getopt (argc, argv, "lcisvw");
  while (ch != EOF)
d78 6
a83 1
      switch (ch)
d88 1
d92 1
d96 3
a98 2
	case 'w':  /* Non standard features give warnings. */
	  warn_not_std = TRUE;
d100 1
d104 1
d107 5
a113 1
      ch = getopt (argc, argv, "lcisvw");
d116 79
a205 2
  g_argv = argv;
  g_argc = argc;
d211 7
d237 1
d280 1
a280 1
  while (optind < g_argc)
d282 1
a282 1
      new_file = fopen (g_argv[optind], "r");
d286 4
a289 1
	  optind++;
d292 1
a292 1
      fprintf (stderr, "File %s is unavailable.\n", g_argv[optind++]);
@


1.2
log
@Add RCS identifiers, remove some completely useless RCS logs and patchkit
headers, and a few other insignificant changes.
@
text
@d1 2
d6 1
a6 1
    Copyright (C) 1991, 1992 Free Software Foundation, Inc.
a29 4

#ifndef lint
static char rcsid[] = "$Id: $";
#endif /* not lint */
@


1.1
log
@gnu bc.  necessary to compile the distribution
@
text
@d29 4
@


1.1.1.1
log
@Import of GNU bc-1.03
@
text
@d4 1
a4 1
    Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
@


1.1.1.2
log
@Updating to version 1.04.
@
text
@d3 2
a4 2
/*  This file is part of GNU bc.
    Copyright (C) 1991, 1992, 1993, 1994, 1997 Free Software Foundation, Inc.
a32 2
#include "getopt.h"

a37 2
/* Points to the last node in the file name list for easy adding. */
static file_node *last = NULL;
d39 3
a41 22
#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},
  {"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
parse_args (argc, argv)
d43 1
a43 1
     char **argv;
d45 11
a55 6
  int optch;
  int long_index;
  file_node *temp;

  /* Force getopt to initialize.  Depends on GNU getopt. */
  optind = 0;
d58 2
a59 1
  while (1)
d61 1
a61 6
      optch = getopt_long (argc, argv, "lciqsvw", long_options, &long_index);

      if (optch == EOF)  /* End of arguments. */
	break;

      switch (optch)
a65 1

a68 1

d72 2
a73 3

	case 'q':  /* quiet mode */
	  quiet = TRUE;
a74 1

a77 1

a79 5
	  exit (0);
	  break;

	case 'w':  /* Non standard features give warnings. */
	  warn_not_std = TRUE;
d82 1
a84 79
  /* Add file names to a list of files to process. */
  while (optind < argc)
    {
      temp = (file_node *) bc_malloc(sizeof(file_node));
      temp->name = argv[optind];
      temp->next = NULL;
      if (last == NULL)
	file_names = temp;
      else
	last->next = temp;
      last = temp;
      optind++;
    }
}

/* The main program for bc. */
int
main (argc, argv)
     int argc;
     char *argv[];
{
  char *env_value;
  char *env_argv[30];
  int   env_argc;
  
  /* Initialize many variables. */
  compile_only = FALSE;
  use_math = FALSE;
  warn_not_std = FALSE;
  std_only = FALSE;
  if (isatty(0) && isatty(1)) 
    interactive = TRUE;
  else
    interactive = FALSE;
  quiet = FALSE;
  file_names = NULL;

  /* Environment arguments. */
  env_value = getenv ("BC_ENV_ARGS");
  if (env_value != NULL)
    {
      env_argc = 1;
      env_argv[0] = "BC_ENV_ARGS";
      while (*env_value != 0)
	{
	  if (*env_value != ' ')
	    {
	      env_argv[env_argc++] = env_value;
	      while (*env_value != ' ' && *env_value != 0)
		env_value++;
	      if (*env_value != 0)
		{
		  *env_value = 0;
		  env_value++;
		}
	    }
	  else
	    env_value++;
	}
      parse_args (env_argc, env_argv);
    }

  /* Command line arguments. */
  parse_args (argc, argv);

  /* Other environment processing. */
  if (getenv ("POSIXLY_CORRECT") != NULL)
    std_only = TRUE;

  env_value = getenv ("BC_LINE_LENGTH");
  if (env_value != NULL)
    {
      line_size = atoi (env_value);
      if (line_size < 2)
	line_size = 70;
    }
  else
    line_size = 70;

d96 2
a102 7
#ifdef READLINE
  /* Readline support.  Set both application name and input file. */
  rl_readline_name = "bc";
  rl_instream = stdin;
  using_history ();
#endif

a121 1
  file_node *temp;
d164 1
a164 1
  if (file_names != NULL)
d166 1
a166 1
      new_file = fopen (file_names->name, "r");
d170 1
a170 4
	  temp = file_names;
	  file_name  = temp->name;
	  file_names = temp->next;
	  free (temp);
d173 1
a173 1
      fprintf (stderr, "File %s is unavailable.\n", file_names->name);
@
