diff options
author | kris <kris@FreeBSD.org> | 2001-02-26 07:13:00 +0000 |
---|---|---|
committer | kris <kris@FreeBSD.org> | 2001-02-26 07:13:00 +0000 |
commit | 719baf164e794b772e8b1869bbf106ef68bfd40e (patch) | |
tree | 1f4f6cec66b553514b27fc7b72541e0f7adc79e5 /contrib/bc/dc | |
parent | 9657c835ffcf45e0a6d46f291505b0b112f8a244 (diff) | |
download | FreeBSD-src-719baf164e794b772e8b1869bbf106ef68bfd40e.zip FreeBSD-src-719baf164e794b772e8b1869bbf106ef68bfd40e.tar.gz |
Initial import of bc 1.0.6
Diffstat (limited to 'contrib/bc/dc')
-rw-r--r-- | contrib/bc/dc/Makefile.am | 4 | ||||
-rw-r--r-- | contrib/bc/dc/Makefile.in | 140 | ||||
-rw-r--r-- | contrib/bc/dc/array.c | 7 | ||||
-rw-r--r-- | contrib/bc/dc/dc-proto.h | 7 | ||||
-rw-r--r-- | contrib/bc/dc/dc-regdef.h | 7 | ||||
-rw-r--r-- | contrib/bc/dc/dc.c | 38 | ||||
-rw-r--r-- | contrib/bc/dc/dc.h | 7 | ||||
-rw-r--r-- | contrib/bc/dc/eval.c | 23 | ||||
-rw-r--r-- | contrib/bc/dc/misc.c | 10 | ||||
-rw-r--r-- | contrib/bc/dc/numeric.c | 133 | ||||
-rw-r--r-- | contrib/bc/dc/stack.c | 9 | ||||
-rw-r--r-- | contrib/bc/dc/string.c | 7 |
12 files changed, 230 insertions, 162 deletions
diff --git a/contrib/bc/dc/Makefile.am b/contrib/bc/dc/Makefile.am index 4de00ab..99164ba 100644 --- a/contrib/bc/dc/Makefile.am +++ b/contrib/bc/dc/Makefile.am @@ -7,4 +7,8 @@ noinst_HEADERS = dc.h dc-proto.h dc-regdef.h INCLUDES = -I$(srcdir)/.. -I$(srcdir)/../h LDADD = ../lib/libbc.a +MAINTAINERCLEANFILES = Makefile.in + +CFLAGS = @CFLAGS@ -Wall -funsigned-char + $(PROGRAMS): $(LDADD) diff --git a/contrib/bc/dc/Makefile.in b/contrib/bc/dc/Makefile.in index ae4e460..0772dd6 100644 --- a/contrib/bc/dc/Makefile.in +++ b/contrib/bc/dc/Makefile.in @@ -1,6 +1,6 @@ -# Makefile.in generated automatically by automake 1.3 from Makefile.am +# Makefile.in generated automatically by automake 1.4 from Makefile.am -# Copyright (C) 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc. +# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -11,7 +11,7 @@ # PARTICULAR PURPOSE. -SHELL = /bin/sh +SHELL = @SHELL@ srcdir = @srcdir@ top_srcdir = @top_srcdir@ @@ -32,7 +32,7 @@ mandir = @mandir@ includedir = @includedir@ oldincludedir = /usr/include -DISTDIR = +DESTDIR = pkgdatadir = $(datadir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ @@ -46,7 +46,7 @@ AUTOMAKE = @AUTOMAKE@ AUTOHEADER = @AUTOHEADER@ INSTALL = @INSTALL@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS) INSTALL_DATA = @INSTALL_DATA@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ transform = @program_transform_name@ @@ -62,6 +62,7 @@ LEX = @LEX@ MAKEINFO = @MAKEINFO@ PACKAGE = @PACKAGE@ RANLIB = @RANLIB@ +READLINELIB = @READLINELIB@ VERSION = @VERSION@ YACC = @YACC@ @@ -72,6 +73,10 @@ noinst_HEADERS = dc.h dc-proto.h dc-regdef.h INCLUDES = -I$(srcdir)/.. -I$(srcdir)/../h LDADD = ../lib/libbc.a + +MAINTAINERCLEANFILES = Makefile.in + +CFLAGS = @CFLAGS@ -Wall -funsigned-char mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs CONFIG_HEADER = ../config.h CONFIG_CLEAN_FILES = @@ -86,9 +91,9 @@ dc_OBJECTS = dc.o misc.o eval.o stack.o array.o numeric.o string.o dc_LDADD = $(LDADD) dc_DEPENDENCIES = ../lib/libbc.a dc_LDFLAGS = -CFLAGS = @CFLAGS@ -COMPILE = $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) -LINK = $(CC) $(CFLAGS) $(LDFLAGS) -o $@ +COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ HEADERS = $(noinst_HEADERS) DIST_COMMON = Makefile.am Makefile.in @@ -97,15 +102,14 @@ DIST_COMMON = Makefile.am Makefile.in DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) TAR = tar -GZIP = --best +GZIP_ENV = --best SOURCES = $(dc_SOURCES) OBJECTS = $(dc_OBJECTS) -all: Makefile $(PROGRAMS) $(HEADERS) - +all: all-redirect .SUFFIXES: .SUFFIXES: .S .c .o .s -$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) +$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) cd $(top_srcdir) && $(AUTOMAKE) --gnu --include-deps dc/Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @@ -127,15 +131,15 @@ install-binPROGRAMS: $(bin_PROGRAMS) $(mkinstalldirs) $(DESTDIR)$(bindir) @list='$(bin_PROGRAMS)'; for p in $$list; do \ if test -f $$p; then \ - echo " $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed '$(transform)'`"; \ - $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed '$(transform)'`; \ + echo " $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`"; \ + $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \ else :; fi; \ done uninstall-binPROGRAMS: @$(NORMAL_UNINSTALL) list='$(bin_PROGRAMS)'; for p in $$list; do \ - rm -f $(DESTDIR)$(bindir)/`echo $$p|sed '$(transform)'`; \ + rm -f $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \ done .c.o: @@ -164,8 +168,12 @@ dc: $(dc_OBJECTS) $(dc_DEPENDENCIES) tags: TAGS ID: $(HEADERS) $(SOURCES) $(LISP) + list='$(SOURCES) $(HEADERS)'; \ + unique=`for i in $$list; do echo $$i; done | \ + awk ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ here=`pwd` && cd $(srcdir) \ - && mkid -f$$here/ID $(SOURCES) $(HEADERS) $(LISP) + && mkid -f$$here/ID $$unique $(LISP) TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP) tags=; \ @@ -193,70 +201,92 @@ subdir = dc distdir: $(DISTFILES) @for file in $(DISTFILES); do \ d=$(srcdir); \ - test -f $(distdir)/$$file \ - || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ - || cp -p $$d/$$file $(distdir)/$$file; \ + if test -d $$d/$$file; then \ + cp -pr $$/$$file $(distdir)/$$file; \ + else \ + test -f $(distdir)/$$file \ + || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ + || cp -p $$d/$$file $(distdir)/$$file || :; \ + fi; \ done -info: -dvi: -check: all - $(MAKE) -installcheck: -install-exec: install-binPROGRAMS - @$(NORMAL_INSTALL) - -install-data: - @$(NORMAL_INSTALL) - -install: install-exec install-data all - @: - -uninstall: uninstall-binPROGRAMS - +array.o: array.c ../config.h dc.h dc-proto.h dc-regdef.h +dc.o: dc.c ../config.h ../h/getopt.h dc.h dc-proto.h +eval.o: eval.c ../config.h dc.h dc-proto.h +misc.o: misc.c ../config.h ../h/getopt.h dc.h dc-proto.h +numeric.o: numeric.c ../config.h ../h/number.h dc.h dc-proto.h +stack.o: stack.c ../config.h dc.h dc-proto.h dc-regdef.h +string.o: string.c ../config.h dc.h dc-proto.h + +info-am: +info: info-am +dvi-am: +dvi: dvi-am +check-am: all-am +check: check-am +installcheck-am: +installcheck: installcheck-am +install-exec-am: install-binPROGRAMS +install-exec: install-exec-am + +install-data-am: +install-data: install-data-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am +install: install-am +uninstall-am: uninstall-binPROGRAMS +uninstall: uninstall-am +all-am: Makefile $(PROGRAMS) $(HEADERS) +all-redirect: all-am install-strip: - $(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' INSTALL_SCRIPT='$(INSTALL_PROGRAM)' install + $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install installdirs: - $(mkinstalldirs) $(DATADIR)$(bindir) + $(mkinstalldirs) $(DESTDIR)$(bindir) mostlyclean-generic: - -test -z "$(MOSTLYCLEANFILES)" || rm -f $(MOSTLYCLEANFILES) clean-generic: - -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) distclean-generic: - -rm -f Makefile $(DISTCLEANFILES) + -rm -f Makefile $(CONFIG_CLEAN_FILES) -rm -f config.cache config.log stamp-h stamp-h[0-9]* - -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) maintainer-clean-generic: -test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES) - -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES) -mostlyclean: mostlyclean-binPROGRAMS mostlyclean-compile \ +mostlyclean-am: mostlyclean-binPROGRAMS mostlyclean-compile \ mostlyclean-tags mostlyclean-generic -clean: clean-binPROGRAMS clean-compile clean-tags clean-generic \ - mostlyclean +mostlyclean: mostlyclean-am -distclean: distclean-binPROGRAMS distclean-compile distclean-tags \ - distclean-generic clean - -rm -f config.status +clean-am: clean-binPROGRAMS clean-compile clean-tags clean-generic \ + mostlyclean-am -maintainer-clean: maintainer-clean-binPROGRAMS maintainer-clean-compile \ - maintainer-clean-tags maintainer-clean-generic \ - distclean +clean: clean-am + +distclean-am: distclean-binPROGRAMS distclean-compile distclean-tags \ + distclean-generic clean-am + +distclean: distclean-am + +maintainer-clean-am: maintainer-clean-binPROGRAMS \ + maintainer-clean-compile maintainer-clean-tags \ + maintainer-clean-generic distclean-am @echo "This command is intended for maintainers to use;" @echo "it deletes files that may require special tools to rebuild." +maintainer-clean: maintainer-clean-am + .PHONY: mostlyclean-binPROGRAMS distclean-binPROGRAMS clean-binPROGRAMS \ maintainer-clean-binPROGRAMS uninstall-binPROGRAMS install-binPROGRAMS \ mostlyclean-compile distclean-compile clean-compile \ maintainer-clean-compile tags mostlyclean-tags distclean-tags \ -clean-tags maintainer-clean-tags distdir info dvi installcheck \ -install-exec install-data install uninstall all installdirs \ -mostlyclean-generic distclean-generic clean-generic \ -maintainer-clean-generic clean mostlyclean distclean maintainer-clean +clean-tags maintainer-clean-tags distdir info-am info dvi-am dvi check \ +check-am installcheck-am installcheck install-exec-am install-exec \ +install-data-am install-data install-am install uninstall-am uninstall \ +all-redirect all-am all installdirs mostlyclean-generic \ +distclean-generic clean-generic maintainer-clean-generic clean \ +mostlyclean distclean maintainer-clean $(PROGRAMS): $(LDADD) diff --git a/contrib/bc/dc/array.c b/contrib/bc/dc/array.c index bc701a1..d97f716 100644 --- a/contrib/bc/dc/array.c +++ b/contrib/bc/dc/array.c @@ -15,8 +15,11 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, you can either send email to this - * program's author (see below) or write to: The Free Software Foundation, - * Inc.; 675 Mass Ave. Cambridge, MA 02139, USA. + * program's author (see below) or write to: + * + * The Free Software Foundation, Inc. + * 59 Temple Place, Suite 330 + * Boston, MA 02111 USA */ /* This module is the only one that knows what arrays look like. */ diff --git a/contrib/bc/dc/dc-proto.h b/contrib/bc/dc/dc-proto.h index 1e7c52c..f0ac28b 100644 --- a/contrib/bc/dc/dc-proto.h +++ b/contrib/bc/dc/dc-proto.h @@ -15,8 +15,11 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, you can either send email to this - * program's author (see below) or write to: The Free Software Foundation, - * Inc.; 675 Mass Ave. Cambridge, MA 02139, USA. + * program's author (see below) or write to: + * + * The Free Software Foundation, Inc. + * 59 Temple Place, Suite 330 + * Boston, MA 02111 USA */ extern const char *dc_str2charp DC_PROTO((dc_str)); diff --git a/contrib/bc/dc/dc-regdef.h b/contrib/bc/dc/dc-regdef.h index 129d0ae..540268c 100644 --- a/contrib/bc/dc/dc-regdef.h +++ b/contrib/bc/dc/dc-regdef.h @@ -15,8 +15,11 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, you can either send email to this - * program's author (see below) or write to: The Free Software Foundation, - * Inc.; 675 Mass Ave. Cambridge, MA 02139, USA. + * program's author (see below) or write to: + * + * The Free Software Foundation, Inc. + * 59 Temple Place, Suite 330 + * Boston, MA 02111 USA */ #ifdef HAVE_LIMITS_H diff --git a/contrib/bc/dc/dc.c b/contrib/bc/dc/dc.c index fa213ba..a72644c 100644 --- a/contrib/bc/dc/dc.c +++ b/contrib/bc/dc/dc.c @@ -1,7 +1,7 @@ /* * implement the "dc" Desk Calculator language. * - * Copyright (C) 1994, 1997, 1998 Free Software Foundation, Inc. + * Copyright (C) 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,8 +15,10 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, you can either send email to this - * program's author (see below) or write to: The Free Software Foundation, - * Inc.; 675 Mass Ave. Cambridge, MA 02139, USA. + * program's author (see below) or write to: + * The Free Software Foundation, Inc. + * 59 Temple Place, Suite 330 + * Boston, MA 02111 USA */ /* Written with strong hiding of implementation details @@ -42,8 +44,6 @@ #include "dc.h" #include "dc-proto.h" -#include "version.h" - #ifndef EXIT_SUCCESS /* C89 <stdlib.h> */ # define EXIT_SUCCESS 0 #endif @@ -53,6 +53,22 @@ const char *progname; /* basename of program invocation */ +static void +bug_report_info DC_DECLVOID() +{ + printf("Email bug reports to: bug-dc@gnu.org .\n"); +} + +static void +show_version DC_DECLVOID() +{ + printf("dc (GNU %s %s) %s\n", PACKAGE, VERSION, DC_VERSION); + printf("\n%s\n\ +This is free software; see the source for copying conditions. There is NO\n\ +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,\n\ +to the extent permitted by law.\n", DC_COPYRIGHT); +} + /* your generic usage function */ static void usage DC_DECLARG((f)) @@ -65,18 +81,8 @@ Usage: %s [OPTION] [file ...]\n\ -h, --help display this help and exit\n\ -V, --version output version information and exit\n\ \n\ -Report bugs to bug-gnu-utils@prep.ai.mit.edu\n\ -Be sure to include the word ``dc'' somewhere in the ``Subject:'' field.\n\ ", progname); -} - -static void -show_version DC_DECLVOID() -{ - printf("%s\n\n", DC_VERSION); - printf("Email bug reports to: bug-gnu-utils@prep.ai.mit.edu .\n"); - printf("Be sure to include the word ``dc'' \ -somewhere in the ``Subject:'' field.\n"); + bug_report_info(); } /* returns a pointer to one past the last occurance of c in s, diff --git a/contrib/bc/dc/dc.h b/contrib/bc/dc/dc.h index 5e2d65a..3300f44 100644 --- a/contrib/bc/dc/dc.h +++ b/contrib/bc/dc/dc.h @@ -15,8 +15,11 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, you can either send email to this - * program's author (see below) or write to: The Free Software Foundation, - * Inc.; 675 Mass Ave. Cambridge, MA 02139, USA. + * program's author (see below) or write to: + * + * The Free Software Foundation, Inc. + * 59 Temple Place, Suite 330 + * Boston, MA 02111 USA */ #ifndef DC_DEFS_H diff --git a/contrib/bc/dc/eval.c b/contrib/bc/dc/eval.c index 0cb2185..21592d9 100644 --- a/contrib/bc/dc/eval.c +++ b/contrib/bc/dc/eval.c @@ -1,7 +1,7 @@ /* * evaluate the dc language, from a FILE* or a string * - * Copyright (C) 1994, 1997, 1998 Free Software Foundation, Inc. + * Copyright (C) 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,8 +15,10 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, you can either send email to this - * program's author (see below) or write to: The Free Software Foundation, - * Inc.; 675 Mass Ave. Cambridge, MA 02139, USA. + * program's author (see below) or write to: + * The Free Software Foundation, Inc. + * 59 Temple Place, Suite 330 + * Boston, MA 02111 USA */ /* This is the only module which knows about the dc input language */ @@ -185,12 +187,13 @@ dc_func DC_DECLARG((c, peekc, negcmp)) case '|': /* Consider the top three elements of the stack as (base, exp, mod), * where mod is top-of-stack, exp is next-to-top, and base is - * second-from-top. Mod must be non-zero and exp must be a - * non-negative integer. Push the result of raising base to the exp - * power, reduced modulo mod. If we had base in register b, exp in - * register e, and mod in register m then this is conceptually - * equivalent to "lble^lm%", but it is implemented in a more efficient - * manner, and can handle arbritrarily large values for exp. + * second-from-top. Mod must be non-zero, exp must be non-negative, + * and all three must be integers. Push the result of raising + * base to the exp power, reduced modulo mod. If we had base in + * register b, exp in register e, and mod in register m then this + * is conceptually equivalent to "lble^lm%", but it is implemented + * in a more efficient manner, and can handle arbritrarily large + * values for exp. */ dc_triop(dc_modexp, dc_scale); break; @@ -633,7 +636,7 @@ dc_evalfile DC_DECLARG((fp)) break; case DC_QUIT: if (unwind_noexit != DC_TRUE) - return DC_FAIL; + return DC_SUCCESS; fprintf(stderr, "%s: Q command argument exceeded string execution depth\n", progname); diff --git a/contrib/bc/dc/misc.c b/contrib/bc/dc/misc.c index 65f986b..fa94de1 100644 --- a/contrib/bc/dc/misc.c +++ b/contrib/bc/dc/misc.c @@ -1,7 +1,7 @@ /* * misc. functions for the "dc" Desk Calculator language. * - * Copyright (C) 1994, 1997, 1998 Free Software Foundation, Inc. + * Copyright (C) 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,8 +15,10 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, you can either send email to this - * program's author (see below) or write to: The Free Software Foundation, - * Inc.; 675 Mass Ave. Cambridge, MA 02139, USA. + * program's author (see below) or write to: + * The Free Software Foundation, Inc. + * 59 Temple Place, Suite 330 + * Boston, MA 02111 USA */ /* This module contains miscelaneous functions that have no @@ -48,8 +50,6 @@ #include "dc.h" #include "dc-proto.h" -#include "version.h" - #ifndef EXIT_FAILURE /* C89 <stdlib.h> */ # define EXIT_FAILURE 1 #endif diff --git a/contrib/bc/dc/numeric.c b/contrib/bc/dc/numeric.c index d5abf13..6086be5 100644 --- a/contrib/bc/dc/numeric.c +++ b/contrib/bc/dc/numeric.c @@ -1,7 +1,7 @@ /* * interface dc to the bc numeric routines * - * Copyright (C) 1994, 1997, 1998 Free Software Foundation, Inc. + * Copyright (C) 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,8 +15,10 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, you can either send email to this - * program's author (see below) or write to: The Free Software Foundation, - * Inc.; 675 Mass Ave. Cambridge, MA 02139, USA. + * program's author (see below) or write to: + * The Free Software Foundation, Inc. + * 59 Temple Place, Suite 330 + * Boston, MA 02111 USA */ /* This should be the only module that knows the internals of type dc_num */ @@ -33,18 +35,23 @@ #else # define UCHAR_MAX ((unsigned char)~0) #endif -#include "bcdefs.h" -#include "proto.h" -#include "global.h" +#include <stdlib.h> +#include "number.h" #include "dc.h" #include "dc-proto.h" #ifdef __GNUC__ -# define ATTRIB(x) __attribute__(x) -#else +# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__-0 >= 7) +# define ATTRIB(x) __attribute__(x) +# endif +#endif +#ifndef ATTRIB # define ATTRIB(x) #endif +/* Forward prototype */ +static void out_char (int); + /* there is no POSIX standard for dc, so we'll take the GNU definitions */ int std_only = FALSE; @@ -61,7 +68,7 @@ dc_add DC_DECLARG((a, b, kscale, result)) int kscale ATTRIB((unused)) DC_DECLSEP dc_num *result DC_DECLEND { - init_num((bc_num *)result); + bc_init_num((bc_num *)result); bc_add(CastNum(a), CastNum(b), (bc_num *)result, 0); return DC_SUCCESS; } @@ -76,7 +83,7 @@ dc_sub DC_DECLARG((a, b, kscale, result)) int kscale ATTRIB((unused)) DC_DECLSEP dc_num *result DC_DECLEND { - init_num((bc_num *)result); + bc_init_num((bc_num *)result); bc_sub(CastNum(a), CastNum(b), (bc_num *)result, 0); return DC_SUCCESS; } @@ -91,7 +98,7 @@ dc_mul DC_DECLARG((a, b, kscale, result)) int kscale DC_DECLSEP dc_num *result DC_DECLEND { - init_num((bc_num *)result); + bc_init_num((bc_num *)result); bc_multiply(CastNum(a), CastNum(b), (bc_num *)result, kscale); return DC_SUCCESS; } @@ -106,7 +113,7 @@ dc_div DC_DECLARG((a, b, kscale, result)) int kscale DC_DECLSEP dc_num *result DC_DECLEND { - init_num((bc_num *)result); + bc_init_num((bc_num *)result); if (bc_divide(CastNum(a), CastNum(b), (bc_num *)result, kscale)){ fprintf(stderr, "%s: divide by zero\n", progname); return DC_DOMAIN_ERROR; @@ -126,8 +133,8 @@ dc_divrem DC_DECLARG((a, b, kscale, quotient, remainder)) dc_num *quotient DC_DECLSEP dc_num *remainder DC_DECLEND { - init_num((bc_num *)quotient); - init_num((bc_num *)remainder); + bc_init_num((bc_num *)quotient); + bc_init_num((bc_num *)remainder); if (bc_divmod(CastNum(a), CastNum(b), (bc_num *)quotient, (bc_num *)remainder, kscale)){ fprintf(stderr, "%s: divide by zero\n", progname); @@ -146,7 +153,7 @@ dc_rem DC_DECLARG((a, b, kscale, result)) int kscale DC_DECLSEP dc_num *result DC_DECLEND { - init_num((bc_num *)result); + bc_init_num((bc_num *)result); if (bc_modulo(CastNum(a), CastNum(b), (bc_num *)result, kscale)){ fprintf(stderr, "%s: remainder by zero\n", progname); return DC_DOMAIN_ERROR; @@ -162,10 +169,10 @@ dc_modexp DC_DECLARG((base, expo, mod, kscale, result)) int kscale DC_DECLSEP dc_num *result DC_DECLEND { - init_num((bc_num *)result); + bc_init_num((bc_num *)result); if (bc_raisemod(CastNum(base), CastNum(expo), CastNum(mod), (bc_num *)result, kscale)){ - if (is_zero(CastNum(mod))) + if (bc_is_zero(CastNum(mod))) fprintf(stderr, "%s: remainder by zero\n", progname); return DC_DOMAIN_ERROR; } @@ -182,7 +189,7 @@ dc_exp DC_DECLARG((a, b, kscale, result)) int kscale DC_DECLSEP dc_num *result DC_DECLEND { - init_num((bc_num *)result); + bc_init_num((bc_num *)result); bc_raise(CastNum(a), CastNum(b), (bc_num *)result, kscale); return DC_SUCCESS; } @@ -198,10 +205,10 @@ dc_sqrt DC_DECLARG((value, kscale, result)) { bc_num tmp; - tmp = copy_num(CastNum(value)); + tmp = bc_copy_num(CastNum(value)); if (!bc_sqrt(&tmp, kscale)){ fprintf(stderr, "%s: square root of negative number\n", progname); - free_num(&tmp); + bc_free_num(&tmp); return DC_DOMAIN_ERROR; } *((bc_num *)result) = tmp; @@ -231,7 +238,7 @@ dc_num2int DC_DECLARG((value, discard_p)) { long result; - result = num2long(CastNum(value)); + result = bc_num2long(CastNum(value)); if (discard_p == DC_TOSS) dc_free_num(&value); return (int)result; @@ -247,8 +254,8 @@ dc_int2data DC_DECLARG((value)) { dc_data result; - init_num((bc_num *)&result.v.number); - int2num((bc_num *)&result.v.number, value); + bc_init_num((bc_num *)&result.v.number); + bc_int2num((bc_num *)&result.v.number, value); result.dc_type = DC_NUMBER; return result; } @@ -279,11 +286,11 @@ dc_getnum DC_DECLARG((input, ibase, readahead)) int decimal; int c; - init_num(&tmp); - init_num(&build); - init_num(&base); - result = copy_num(_zero_); - int2num(&base, ibase); + bc_init_num(&tmp); + bc_init_num(&build); + bc_init_num(&base); + result = bc_copy_num(_zero_); + bc_int2num(&base, ibase); c = (*input)(); while (isspace(c)) c = (*input)(); @@ -303,15 +310,15 @@ dc_getnum DC_DECLARG((input, ibase, readahead)) else break; c = (*input)(); - int2num(&tmp, digit); + bc_int2num(&tmp, digit); bc_multiply(result, base, &result, 0); bc_add(result, tmp, &result, 0); } if (c == '.'){ - free_num(&build); - free_num(&tmp); - divisor = copy_num(_one_); - build = copy_num(_zero_); + bc_free_num(&build); + bc_free_num(&tmp); + divisor = bc_copy_num(_one_); + build = bc_copy_num(_zero_); decimal = 0; for (;;){ c = (*input)(); @@ -321,7 +328,7 @@ dc_getnum DC_DECLARG((input, ibase, readahead)) digit = 10 + c - 'A'; else break; - int2num(&tmp, digit); + bc_int2num(&tmp, digit); bc_multiply(build, base, &build, 0); bc_add(build, tmp, &build, 0); bc_multiply(divisor, base, &divisor, 0); @@ -334,9 +341,9 @@ dc_getnum DC_DECLARG((input, ibase, readahead)) if (negative) bc_sub(_zero_, result, &result, 0); - free_num(&tmp); - free_num(&build); - free_num(&base); + bc_free_num(&tmp); + bc_free_num(&build); + bc_free_num(&base); if (readahead) *readahead = c; full_result.v.number = (dc_num)result; @@ -353,7 +360,7 @@ dc_numlen DC_DECLARG((value)) bc_num num = CastNum(value); /* is this right??? */ - return num->n_len + num->n_scale; + return num->n_len + num->n_scale - (*num->n_value == '\0'); } /* return the scale factor of the passed dc_num @@ -377,7 +384,7 @@ dc_tell_scale DC_DECLARG((value, discard_p)) void dc_math_init DC_DECLVOID() { - init_numbers(); + bc_init_numbers(); } /* print out a dc_num in output base obase to stdout; @@ -391,9 +398,10 @@ dc_out_num DC_DECLARG((value, obase, newline_p, discard_p)) dc_newline newline_p DC_DECLSEP dc_discard discard_p DC_DECLEND { - out_num(CastNum(value), obase, out_char); + out_char('\0'); /* clear the column counter */ + bc_out_num(CastNum(value), obase, out_char, 0); if (newline_p == DC_WITHNL) - out_char('\n'); + putchar ('\n'); if (discard_p == DC_TOSS) dc_free_num(&value); } @@ -403,7 +411,7 @@ dc_out_num DC_DECLARG((value, obase, newline_p, discard_p)) * if discard_p is DC_TOSS then deallocate the value after use */ void -dc_dump_num DC_DECLARG((value, discard_p)) +dc_dump_num DC_DECLARG((dcvalue, discard_p)) dc_num dcvalue DC_DECLSEP dc_discard discard_p DC_DECLEND { @@ -415,9 +423,9 @@ dc_dump_num DC_DECLARG((value, discard_p)) bc_num obase; bc_num digit; - init_num(&value); - init_num(&obase); - init_num(&digit); + bc_init_num(&value); + bc_init_num(&obase); + bc_init_num(&digit); /* we only handle the integer portion: */ bc_divide(CastNum(dcvalue), _one_, &value, 0); @@ -427,14 +435,14 @@ dc_dump_num DC_DECLARG((value, discard_p)) if (discard_p == DC_TOSS) dc_free_num(&dcvalue); - int2num(&obase, 1+UCHAR_MAX); + bc_int2num(&obase, 1+UCHAR_MAX); do { (void) bc_divmod(value, obase, &value, &digit, 0); cur = dc_malloc(sizeof *cur); - cur->digit = (int)num2long(digit); + cur->digit = (int)bc_num2long(digit); cur->link = top_of_stack; top_of_stack = cur; - } while (!is_zero(value)); + } while (!bc_is_zero(value)); for (cur=top_of_stack; cur; cur=next) { putchar(cur->digit); @@ -442,9 +450,9 @@ dc_dump_num DC_DECLARG((value, discard_p)) free(cur); } - free_num(&digit); - free_num(&obase); - free_num(&value); + bc_free_num(&digit); + bc_free_num(&obase); + bc_free_num(&value); } /* deallocate an instance of a dc_num */ @@ -452,7 +460,7 @@ void dc_free_num DC_DECLARG((value)) dc_num *value DC_DECLEND { - free_num((bc_num *)value); + bc_free_num((bc_num *)value); } /* return a duplicate of the number in the passed value */ @@ -498,15 +506,14 @@ int out_col = 0; It keeps track of the number of characters output and may break the output with a "\<cr>". */ -void +static void out_char (ch) - char ch; + int ch; { - if (ch == '\n') + if (ch == '\0') { out_col = 0; - putchar ('\n'); } else { @@ -547,17 +554,16 @@ rt_error (mesg, va_alist) #endif { va_list args; - char error_mesg [255]; + fprintf (stderr, "Runtime error: "); #ifdef HAVE_STDARG_H va_start (args, mesg); #else va_start (args); #endif - vsprintf (error_mesg, mesg, args); + vfprintf (stderr, mesg, args); va_end (args); - - fprintf (stderr, "Runtime error: %s\n", error_mesg); + fprintf (stderr, "\n"); } @@ -581,15 +587,14 @@ rt_warn (mesg, va_alist) #endif { va_list args; - char error_mesg [255]; + fprintf (stderr, "Runtime warning: "); #ifdef HAVE_STDARG_H va_start (args, mesg); #else va_start (args); #endif - vsprintf (error_mesg, mesg, args); + vfprintf (stderr, mesg, args); va_end (args); - - fprintf (stderr, "Runtime warning: %s\n", error_mesg); + fprintf (stderr, "\n"); } diff --git a/contrib/bc/dc/stack.c b/contrib/bc/dc/stack.c index 0268b70..1d8a9bf 100644 --- a/contrib/bc/dc/stack.c +++ b/contrib/bc/dc/stack.c @@ -15,8 +15,11 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, you can either send email to this - * program's author (see below) or write to: The Free Software Foundation, - * Inc.; 675 Mass Ave. Cambridge, MA 02139, USA. + * program's author (see below) or write to: + * + * The Free Software Foundation, Inc. + * 59 Temple Place, Suite 330 + * Boston, MA 02111 USA */ /* This module is the only one that knows what stacks (both the @@ -347,6 +350,8 @@ dc_register_set DC_DECLARG((regid, value)) dc_free_num(&r->value.v.number); else if (r->value.dc_type == DC_STRING) dc_free_str(&r->value.v.string); + else if (r->value.dc_type == DC_UNINITIALIZED) + ; else dc_garbage("", regid); dc_register[regid]->value = value; diff --git a/contrib/bc/dc/string.c b/contrib/bc/dc/string.c index 6cffffd..a7f79a4 100644 --- a/contrib/bc/dc/string.c +++ b/contrib/bc/dc/string.c @@ -15,8 +15,11 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, you can either send email to this - * program's author (see below) or write to: The Free Software Foundation, - * Inc.; 675 Mass Ave. Cambridge, MA 02139, USA. + * program's author (see below) or write to: + * + * The Free Software Foundation, Inc. + * 59 Temple Place, Suite 330 + * Boston, MA 02111 USA */ /* This should be the only module that knows the internals of type dc_string */ |