Initial import of bc 1.0.6

This commit is contained in:
Kris Kennaway 2001-02-26 07:13:00 +00:00
parent 65865e2a46
commit a078a05252
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/vendor/bc/dist/; revision=73064
61 changed files with 4668 additions and 1573 deletions

View File

@ -1,4 +1,4 @@
Phil Nelson <phil@cs.wwu.edu> wrote bc, including the number.c
Phil Nelson <philnelson@acm.org> wrote bc, including the number.c
source in the "lib" directory.
Ken Pizzini wrote dc.

View File

@ -1,3 +1,224 @@
Wed Sep 27 17:19:48 2000 Phil Nelson <phil@cs.wwu.edu>
* doc/bc.texi: Added new file. Mainly translated from bc.1
by Brian Youmans.
doc/bc.1: Minor changes made as part of reviewing bc.texi.
Wed Sep 20 11:45:00 2000 Phil Nelson <phil@cs.wwu.edu>
* bc/bc.y: Added a comment on the meanings of lvals.
Wed Sep 13 11:40:24 2000 Phil Nelson <phil@cs.wwu.edu>
* bc/main.c: add --interactive to long options.
bc/bc.1: add -i/--interactive to doc.
MANY: Update FSF address and Phil's e-mail.
Tue Sep 12 13:58:16 2000 Phil Nelson <phil@cs.wwu.edu>
* NEWS: update for recent changes.
bc/bc.y: remove required parens around return expression.
doc/bc.1: update for recent changes.
Fri Sep 8 10:20:01 2000 Phil Nelson <phil@cs.wwu.edu>
* bc/Makefile.am, dc/Makefile.am, lib/Makefile.am:
Compile with unsigned characters.
bc/main.c: Add --help option.
bc/scan.l: Print illegal, non-printable characters in octal.
Fri Sep 8 09:36:54 2000 Phil Nelson <phil@cs.wwu.edu>
* bc/bc.y: Allow more newlines in function definitions.
bc/proto.h: Don't prototype main.
Fri Sep 1 16:09:50 2000 Phil Nelson <phil@cs.wwu.edu>
* bc/bc.y: Spelling correction
bc/execute.c: Correct expressions for multi-byte names.
bc/load.c: Add parens for correct casting.
doc/bc.1: Typos.
Above fixes pointed out by kwzh@gnu.org (Karl Heuer).
Tue Aug 29 23:03:30 PDT 2000 Phil Nelson <phil@cs.wwu.edu>
* lib/testmul.c: #ifdef out a declaration matching #ifdef out
code.
Mon Jul 31 07:01:42 2000 Ken Pizzini <ken@gnu.org>
* dc/numeric.c: use of the "n" command can cause a number to be printed
without a trailing newline, which would cause the column counter to
fail to be reset and result in inappropriately wrapped numeric outputs.
Fixed by always clearing the column counter before outputting each number.
* dc/stack.c: if a stack is used without ever using the correspondingly
named register, it is perfectly legitimate for the register to be
uninitialized; added an "else if" to handle this case without aborting.
* dc/eval.c: updated the comment explaining the restrictions
on the | command to better reflect reality.
* doc/dc.texi: update the FSF office address in the copyright notice
Thu Jul 13 18:13:00 2000 Phil Nelson <phil@cs.wwu.edu>
* README: note --with-libedit configure parameter.
Tue Jun 20 22:52:10 2000 Phil Nelson <phil@cs.wwu.edu>
* bc/bcdefs.h: Include <readline/history.h> to quiet warnings.
* configure.in: make --with-readline and --with-libedit work correctly.
* Makefile.am: use $(MAKE) instead of directly calling make.
* lib/testmul.c: Update to use bc_ on all number.c routines.
Sat Jun 10 22:44:29 2000 Phil Nelson <phil@cs.wwu.edu>
* bc/Makefile.am: Add scan.c to maintainer-clean target.
* acconfig.h configure.in stamp-h.in bc/Makefile.am bc/execute.c
bc/fix-libmath_h bc/global.c bc/load.c bc/main.c bc/storage.c:
Remove long string for libmath. Clean up for compiler errors.
* dc/numeric.c: Correct parameter name.
Wed May 10 15:51:16 2000 Phil Nelson <phil@cs.wwu.edu>
* {bc,doc,dc,lib}/Makefile.am: Add Makefile.in to maintainer-clean.
* bootstrap.sh: Added script to run the auto* tools.
* Imported all into CVS tree.
Sun 2000-05-07 Phil Nelson <phil@cs.wwu.edu>
* bc/Makefile.am, dc/Makefile.am, lib/Makefile.am: Add -Wall to CFLAGS.
* bc/{execute.c,proto.h,storage.c,util.c}, dc/numeric.c: Changes for
-Wall and for name changes in lib/number.c. (Added bc_ to several
routine. Updated copyright notice.)
* h/number.h, lib/number.c: Now comes from bcmath library which is
distributed in a different place.
Wed Mar 29 17:47:34 2000 Phil Nelson <phil@cs.wwu.edu>
* bc/{bc.y,bcdefs.h,global.h,main.c,proto.h,scan.l,storage.c}:
Added BSD libedit support. Generic support for both where possible.
Fixed bugs in readline support noticed during libedit addition.
Works with NetBSD-1.4.1 libedit.
* doc/bc.1: Documented libedit addition.
Wed Mar 29 10:20:18 2000 Phil Nelson <phil@cs.wwu.edu>
* FAQ: Added this file.
* Makfile.am: Added FAQ to distribution
Tue Mar 28 13:52:35 2000 Phil Nelson <phil@cs.wwu.edu>
* lib/number.c, h/number.h: Moved definitions so
number.c/number.h is a stand-alone "library".
Changed definition of out_num to not reference a global.
* lib/testmul.c: updated #includes for number.h changes.
* h/{bcdefs.h,const.h,global.h,proto.h} moved to
bc where they really belong.
* bc/execute.c: Changed calls to out_num for correctness.
* dc/numeric.c: Changed calls to out_num for correctness,
include only number.h now and not all the other junk.
* configure.in, acconfig.h: Start of support for BSD libedit,
added --with-pkg for NetBSD /usr/pkg tree.
Tue Mar 28 11:20:00 2000 Phil Nelson <phil@cs.wwu.edu>
* Test/{exp.b,fact.b,jn.b,mul.b,raise.b}: Tweeks on the tests
run to do more computation and test the recursive multiply.
* bc/scan.l: Removed a printf('\r') that was unneeded.
Mon Mar 27 14:00:00 2000 Phil Nelson <phil@cs.wwu.edu>
* NEWS: Updated for 1.06.
* lib/number.c, h/number.h: Fixed bugs in recursive multiply.
Changed these files to be under the LGPL.
* Tests/jn.b: Added more tests.
* lib/Makefile.am: Only generate a timed version of number.o if
requested.
* README: Updated with information on how to generate a timed
version of number.o.
* h/version.h: Updated copyright and version number for dc.
Thu Mar 16 14:01:45 2000 Phil Nelson <phil@cs.wwu.edu>
* doc/bc.1, doc/dc.1, doc/dc.texi: Changed bug reporting address
to bug-bc@gnu.org to update with what we hope will be reality.
Tue Feb 8 08:54:19 2000 Phil Nelson <phil@cs.wwu.edu>
* doc/bc.1, bc/util.c: Removed "multiply digits"
limit due to new recursive algorithm that doesn't
have those limits.
Tue Feb 8 08:47:05 2000 Phil Nelson <phil@cs.wwu.edu>
* lib/Makefile.am, lib/testmul.c, lib/number.c, Makefile.am:
Finally got a resonable version of the program
to test the crossover between non-recursive and
recursive multiply algorithms. Added to distribution
and build process. Does increase build time by
about 10 minutes.
Wed Oct 6 13:28:59 1999 Phil Nelson <phil@cs.wwu.edu>
* lib/Makefile.am: Added rules to allow DEFSADD definitions.
Sat Oct 2 19:59:51 1999 Phil Nelson <phil@cs.wwu.edu>
* bc/libmath.b: Correctly do the cosine accuracy.
Fri Oct 1 12:41:51 1999 Phil Nelson <phil@cs.wwu.edu>
* lib/number.c: Increase accuracy of computing raise.
Also turn off use of recursive multiply routines
until furthur testing.
* bc/libmath.b: Increase accuracy of cosine.
* bc/Makefile.am: Remove -lfl from items to make.
Wed Jul 28 10:29:28 1999 Phil Nelson <phil@cs.wwu.edu>
* bc/scan.l: rl_len from char to int. (From FreeBSD
bug tracking system and Nick Hibma <nick.hibma@jrc.it>)
Tue Jun 22 08:00:28 1999 Phil Nelson <phil@cs.wwu.edu>
* lib/number.c: Rewrote bc_multiply to use a faster
algorithm. Old code not removed yet.
Mon Jun 21 03:08:02 1999 Phil Nelson <phil@cs.wwu.edu>
* h/version.h: Updated version number to 1.06.
bc/bc.y: Corrected bug in for statement, not popping.
bc/execute.c: Improved stack dump/instruction tracing.
Tue Jun 15 22:30:42 1999 Phil Nelson <phil@cs.wwu.edu>
* configure.in: Updated bc version to 1.06.
Tue Jun 15 22:27:44 1999 Phil Nelson <phil@cs.wwu.edu>
* h/bcdefs.h, h/const.h, bc/execute.c, bc/load.c, bc/storage.c,
bc/util.c: Removed segmented function storaged. Now
dynamically expands (by doubling, starting at 1024 bytes)
to allow arbitrary sized functions.
Thu Jun 10 22:33:44 1999 Phil Nelson <phil@cs.wwu.edu>
* bc/libmath.b: change scaling in computation of j(n,x) so
it correctly computes the value.
Wed Jun 10 10:10:10 1998 Release of bc-1.05a.
Fri Apr 17 10:40:59 1998 Phil Nelson <phil@cs.wwu.edu>
* bc/main.c: Enable readline only if interactive.
@ -820,4 +1041,3 @@ Tue Oct 29 10:06:32 1991 Phil Nelson (phil at cs.wwu.edu)
* Called current version 1.00.
* Submitted GNU bc-1.00 to comp.sources.reviewed

17
contrib/bc/FAQ Normal file
View File

@ -0,0 +1,17 @@
Because of frequent questions ....... here is the BC FAQ
1) Why does BC have its own arbitrary precision number routines
(found in lib/number.c) rather than using GMP?
GMP has "integers" (no digits after a decimal), "rational numbers"
(stored as 2 integers) and "floats". None of these will correctly
represent a POSIX BC number. Floats are the closest, but will not
behave correctly for many computations. For example, BC numbers have
a "scale" that represent the number of digits to represent after the
decimal point. The multiplying two of these numbers requires one to
calculate an exact number of digits after the decimal point regardless
of the number of digits in the integer part. GMP floats have a
"fixed, but arbitrary" mantissa and so multiplying two floats will end
up dropping digits BC must calculate.

View File

@ -1,9 +1,18 @@
## Process this file with automake to produce Makefile.in
SUBDIRS = lib bc dc doc
MAINTAINERCLEANFILES = aclocal.m4 config.h.in configure Makefile.in \
$(distdir).tar.gz h/number.h
dist-hook:
mkdir $(distdir)/h $(distdir)/Examples $(distdir)/Test
cp -p $(srcdir)/h/*.h $(distdir)/h
cp -p $(srcdir)/Examples/*.b $(distdir)/Examples
cp -p $(srcdir)/Test/*.b $(srcdir)/Test/*.bc $(distdir)/Test
cp -p $(srcdir)/Test/signum $(srcdir)/Test/timetest $(distdir)/Test
cp -p $(srcdir)/lib/testmul.c $(distdir)/lib
cp -p $(srcdir)/FAQ $(distdir)
timetest:
(cd lib; $(MAKE) specialnumber)

View File

@ -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,27 +62,30 @@ LEX = @LEX@
MAKEINFO = @MAKEINFO@
PACKAGE = @PACKAGE@
RANLIB = @RANLIB@
READLINELIB = @READLINELIB@
VERSION = @VERSION@
YACC = @YACC@
SUBDIRS = lib bc dc doc
MAINTAINERCLEANFILES = aclocal.m4 config.h.in configure Makefile.in $(distdir).tar.gz h/number.h
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = config.h
CONFIG_CLEAN_FILES =
DIST_COMMON = README AUTHORS COPYING ChangeLog INSTALL Makefile.am \
Makefile.in NEWS acconfig.h aclocal.m4 config.h.in configure \
configure.in install-sh missing mkinstalldirs stamp-h.in
DIST_COMMON = README ./stamp-h.in AUTHORS COPYING COPYING.LIB ChangeLog \
INSTALL Makefile.am Makefile.in NEWS acconfig.h aclocal.m4 config.h.in \
configure configure.in install-sh missing mkinstalldirs
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = tar
GZIP = --best
all: all-recursive-am all-am
GZIP_ENV = --best
all: all-redirect
.SUFFIXES:
$(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 Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@ -92,22 +95,29 @@ Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
$(ACLOCAL_M4): configure.in
cd $(srcdir) && $(ACLOCAL)
config.status: $(srcdir)/configure
config.status: $(srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
$(SHELL) ./config.status --recheck
$(srcdir)/configure: $(srcdir)/configure.in $(ACLOCAL_M4) $(CONFIGURE_DEPENDENCIES)
cd $(srcdir) && $(AUTOCONF)
config.h: stamp-h
@:
@if test ! -f $@; then \
rm -f stamp-h; \
$(MAKE) stamp-h; \
else :; fi
stamp-h: $(srcdir)/config.h.in $(top_builddir)/config.status
cd $(top_builddir) \
&& CONFIG_FILES= CONFIG_HEADERS=config.h \
$(SHELL) ./config.status
@echo timestamp > stamp-h
@echo timestamp > stamp-h 2> /dev/null
$(srcdir)/config.h.in: $(srcdir)/stamp-h.in
@if test ! -f $@; then \
rm -f $(srcdir)/stamp-h.in; \
$(MAKE) $(srcdir)/stamp-h.in; \
else :; fi
$(srcdir)/stamp-h.in: $(top_srcdir)/configure.in $(ACLOCAL_M4) acconfig.h
cd $(top_srcdir) && $(AUTOHEADER)
@echo timestamp > $(srcdir)/stamp-h.in
@echo timestamp > $(srcdir)/stamp-h.in 2> /dev/null
mostlyclean-hdr:
@ -131,41 +141,65 @@ all-recursive install-data-recursive install-exec-recursive \
installdirs-recursive install-recursive uninstall-recursive \
check-recursive installcheck-recursive info-recursive dvi-recursive:
@set fnord $(MAKEFLAGS); amf=$$2; \
dot_seen=no; \
target=`echo $@ | sed s/-recursive//`; \
list='$(SUBDIRS)'; for subdir in $$list; do \
target=`echo $@ | sed s/-recursive//`; \
echo "Making $$target in $$subdir"; \
(cd $$subdir && $(MAKE) $$target) \
if test "$$subdir" = "."; then \
dot_seen=yes; \
local_target="$$target-am"; \
else \
local_target="$$target"; \
fi; \
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
|| case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
done && test -z "$$fail"
done; \
if test "$$dot_seen" = "no"; then \
$(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
fi; test -z "$$fail"
mostlyclean-recursive clean-recursive distclean-recursive \
maintainer-clean-recursive:
@set fnord $(MAKEFLAGS); amf=$$2; \
dot_seen=no; \
rev=''; list='$(SUBDIRS)'; for subdir in $$list; do \
rev="$$subdir $$rev"; \
test "$$subdir" = "." && dot_seen=yes; \
done; \
test "$$dot_seen" = "no" && rev=". $$rev"; \
target=`echo $@ | sed s/-recursive//`; \
for subdir in $$rev; do \
target=`echo $@ | sed s/-recursive//`; \
echo "Making $$target in $$subdir"; \
(cd $$subdir && $(MAKE) $$target) \
if test "$$subdir" = "."; then \
local_target="$$target-am"; \
else \
local_target="$$target"; \
fi; \
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
|| case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
done && test -z "$$fail"
tags-recursive:
list='$(SUBDIRS)'; for subdir in $$list; do \
(cd $$subdir && $(MAKE) tags); \
test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \
done
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: tags-recursive $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SUBDIRS)'; for subdir in $$list; do \
test -f $$subdir/TAGS && tags="$$tags -i $$here/$$subdir/TAGS"; \
if test "$$subdir" = .; then :; else \
test -f $$subdir/TAGS && tags="$$tags -i $$here/$$subdir/TAGS"; \
fi; \
done; \
list='$(SOURCES) $(HEADERS)'; \
unique=`for i in $$list; do echo $$i; done | \
@ -191,29 +225,31 @@ top_distdir = $(distdir)
# tarfile.
distcheck: dist
-rm -rf $(distdir)
GZIP=$(GZIP) $(TAR) zxf $(distdir).tar.gz
GZIP=$(GZIP_ENV) $(TAR) zxf $(distdir).tar.gz
mkdir $(distdir)/=build
mkdir $(distdir)/=inst
dc_install_base=`cd $(distdir)/=inst && pwd`; \
cd $(distdir)/=build \
&& ../configure --srcdir=.. --prefix=$$dc_install_base \
&& $(MAKE) \
&& $(MAKE) dvi \
&& $(MAKE) check \
&& $(MAKE) install \
&& $(MAKE) installcheck \
&& $(MAKE) dist
&& $(MAKE) $(AM_MAKEFLAGS) \
&& $(MAKE) $(AM_MAKEFLAGS) dvi \
&& $(MAKE) $(AM_MAKEFLAGS) check \
&& $(MAKE) $(AM_MAKEFLAGS) install \
&& $(MAKE) $(AM_MAKEFLAGS) installcheck \
&& $(MAKE) $(AM_MAKEFLAGS) dist
-rm -rf $(distdir)
@echo "========================"; \
echo "$(distdir).tar.gz is ready for distribution"; \
echo "========================"
@banner="$(distdir).tar.gz is ready for distribution"; \
dashes=`echo "$$banner" | sed s/./=/g`; \
echo "$$dashes"; \
echo "$$banner"; \
echo "$$dashes"
dist: distdir
-chmod -R a+r $(distdir)
GZIP=$(GZIP) $(TAR) chozf $(distdir).tar.gz $(distdir)
GZIP=$(GZIP_ENV) $(TAR) chozf $(distdir).tar.gz $(distdir)
-rm -rf $(distdir)
dist-all: distdir
-chmod -R a+r $(distdir)
GZIP=$(GZIP) $(TAR) chozf $(distdir).tar.gz $(distdir)
GZIP=$(GZIP_ENV) $(TAR) chozf $(distdir).tar.gz $(distdir)
-rm -rf $(distdir)
distdir: $(DISTFILES)
-rm -rf $(distdir)
@ -221,78 +257,84 @@ distdir: $(DISTFILES)
-chmod 777 $(distdir)
@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
for subdir in $(SUBDIRS); do \
test -d $(distdir)/$$subdir \
|| mkdir $(distdir)/$$subdir \
|| exit 1; \
chmod 777 $(distdir)/$$subdir; \
(cd $$subdir && $(MAKE) top_distdir=../$(distdir) distdir=../$(distdir)/$$subdir distdir) \
if test "$$subdir" = .; then :; else \
test -d $(distdir)/$$subdir \
|| mkdir $(distdir)/$$subdir \
|| exit 1; \
chmod 777 $(distdir)/$$subdir; \
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir=../$(distdir) distdir=../$(distdir)/$$subdir distdir) \
|| exit 1; \
fi; \
done
$(MAKE) top_distdir="$(top_distdir)" distdir="$(distdir)" dist-hook
$(MAKE) $(AM_MAKEFLAGS) top_distdir="$(top_distdir)" distdir="$(distdir)" dist-hook
info-am:
info: info-recursive
dvi-am:
dvi: dvi-recursive
check: all-am
$(MAKE) check-recursive
check-am: all-am
check: check-recursive
installcheck-am:
installcheck: installcheck-recursive
all-recursive-am: config.h
$(MAKE) all-recursive
all-am: Makefile config.h
$(MAKE) $(AM_MAKEFLAGS) all-recursive
install-exec-am:
install-exec: install-exec-recursive
@$(NORMAL_INSTALL)
install-data-am:
install-data: install-data-recursive
@$(NORMAL_INSTALL)
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
install: install-recursive
@:
uninstall-am:
uninstall: uninstall-recursive
all-am: Makefile config.h
all-redirect: all-recursive-am
install-strip:
$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' INSTALL_SCRIPT='$(INSTALL_PROGRAM)' install
$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
installdirs: installdirs-recursive
installdirs-am:
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-am: mostlyclean-hdr mostlyclean-tags mostlyclean-generic
mostlyclean: mostlyclean-recursive
clean-am: clean-hdr clean-tags clean-generic mostlyclean-am
clean: clean-recursive
distclean-am: distclean-hdr distclean-tags distclean-generic clean-am
distclean: distclean-recursive
-rm -f config.status
maintainer-clean-am: maintainer-clean-hdr maintainer-clean-tags \
maintainer-clean-generic distclean-am
mostlyclean: mostlyclean-recursive mostlyclean-am
clean: clean-recursive clean-am
distclean: distclean-recursive distclean-am
-rm -f config.status
maintainer-clean: maintainer-clean-recursive maintainer-clean-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-recursive
-rm -f config.status
.PHONY: mostlyclean-hdr distclean-hdr clean-hdr maintainer-clean-hdr \
@ -301,11 +343,12 @@ uninstall-exec-recursive installdirs-recursive uninstalldirs-recursive \
all-recursive check-recursive installcheck-recursive info-recursive \
dvi-recursive mostlyclean-recursive distclean-recursive clean-recursive \
maintainer-clean-recursive tags tags-recursive mostlyclean-tags \
distclean-tags clean-tags maintainer-clean-tags distdir info dvi \
installcheck all-recursive-am all-am install-exec install-data install \
uninstall all installdirs mostlyclean-generic distclean-generic \
clean-generic maintainer-clean-generic clean mostlyclean distclean \
maintainer-clean
distclean-tags clean-tags maintainer-clean-tags distdir info-am info \
dvi-am dvi check check-am installcheck-am installcheck all-recursive-am \
install-exec-am install-exec install-data-am install-data install-am \
install uninstall-am uninstall all-redirect all-am all installdirs-am \
installdirs mostlyclean-generic distclean-generic clean-generic \
maintainer-clean-generic clean mostlyclean distclean maintainer-clean
dist-hook:
@ -314,6 +357,11 @@ dist-hook:
cp -p $(srcdir)/Examples/*.b $(distdir)/Examples
cp -p $(srcdir)/Test/*.b $(srcdir)/Test/*.bc $(distdir)/Test
cp -p $(srcdir)/Test/signum $(srcdir)/Test/timetest $(distdir)/Test
cp -p $(srcdir)/lib/testmul.c $(distdir)/lib
cp -p $(srcdir)/FAQ $(distdir)
timetest:
(cd lib; $(MAKE) specialnumber)
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.

View File

@ -1,4 +1,19 @@
This is GNU bc version 1.05. (And dc version 1.2)
This is GNU bc version 1.06. (And dc version 1.2)
Changes in dc from 1.2 to 1.3:
Minor bug fixes.
New multiply algorithm of bc.
Changes in bc from 1.05 to 1.06:
New multiply algoirthm and many other changes in lib/number.c
Function size now done dynamically.
Function syntax in non-posix mode allows newlines in more places.
Bug fixes:
improved computation of j(n,x).
enables readline only if interactive.
for statment bug fixed.
use int instead of char for readline char counts.
improved cosine accuracy.
Changes in dc from 1.1 to 1.2:
added !< != !> commands

View File

@ -1,3 +1,31 @@
GNU bc version 1.06:
Extra configuration options:
--with-readline tells bc to use the readline package that allows
for editing input lines when run interactive.
--with-editline tells bc to use the BSD editline package that
allows for editing input lines when run interactive.
Extra make steps:
The simple make compiles a version of bc with fixed parameters
for the recursive multiplication algorithm. The fixed parameter
is the number of digits where a sequential algorithm is used
instead of the recursive algorithm. It is set to a value that
is known good on a couple of machines. (Sparc Ultra 10, Pentium
II, 450.) I'm calling this point the crossover point.
To make a version of bc with a custom crossover point for your
machine, do the following steps:
make timetest
make
The timetest step takes a minimum of 10 minutes to complete.
-------- Original comp.sources.reviewed README --------
Program: GNU bc
@ -55,3 +83,4 @@ an executable statement unlike the quit (i.e. "if (1 == 0) quit" will
halt bc but "if (1 == 0) halt" will not halt bc.), and (h) the
addition of the special variable "last" that is assigned the value of
each print as the number is printed.
-----------------------------------------------------------------------

View File

@ -1,3 +1,3 @@
for (a=0; a<150; a++) x=e(a)
for (a=0; a<180; a+=.4) x=e(a)
x
quit

View File

@ -4,8 +4,7 @@ define f (x) {
return (f(x-1)*x)
}
"Here we go"
for (a=1; a<100; a++) b+=f(a)/a
for (a=1; a<600; a++) b=f(a)
"
"
"b=";b

View File

@ -1,6 +1,6 @@
scale = 30
for (a=0; a<5; a=a+2) {
for (b=0; b<100; b=b+10) x=j(a,b)
scale = 50
for (a=0; a<=100; a += 20) {
for (b=0; b<=300; b += 20) x=j(a,b)
x
}
x
quit

View File

@ -1,3 +1,4 @@
for (a=1; a<10000000000000000000000000000; a = a*2) x=l(a)
scale = 60
for (a=1; a<100000000000000000000000000000000000000; a = a*2) x=l(a)
x
quit

View File

@ -1,7 +1,13 @@
scale = 20
for (i=0; i<1000; i++) {
for (i=0; i<10000; i++) {
for (j=1; j<100; j++) b=i*j
}
b
for (i=0; i<10000; i++) {
for (j=1000000000000000000000000000000000000000000000000000000000000000000; \
j<1000000000000000000000000000000000000000000000000000000000000000100; \
j++) b=i*j
}
b
quit

View File

@ -1,3 +1,7 @@
for (i=0; i<1000; i++) a = 2^i;
a
for (i=3000; i<3100; i++) a = 3^i;
a
for (i=200; i<220; i++) a = (4^100)^i;
a
quit

View File

@ -2,11 +2,13 @@
#
# Time the functions.
#
BC=../bc/bc
SYSBC=/usr/bin/bc
if [ x$BC = x ] ; then
BC=../bc/bc
fi
for file in exp.b ln.b sine.b atan.b jn.b mul.b div.b raise.b sqrt.b
do
for prog in $BC $SYSBC
for prog in $BC $SYSBC $OTHERBC
do
echo Timing $file with $prog
time $prog -l $file

View File

@ -4,12 +4,21 @@
/* Package VERSION number */
#undef VERSION
/* define if the math lib is to be loaded from a file. */
#undef BC_MATH_FILE
/* VERSION number for DC target*/
#undef DC_VERSION
/* COPYRIGHT notice for DC target */
#undef DC_COPYRIGHT
/* COPYRIGHT notice for BC target */
#undef BC_COPYRIGHT
/* Define to use the readline library. */
#undef READLINE
/* Define to use the BSD libedit library. */
#undef LIBEDIT
/* Define to `size_t' if <sys/types.h> and <stddef.h> don't define. */
#undef ptrdiff_t

21
contrib/bc/aclocal.m4 vendored
View File

@ -1,7 +1,7 @@
dnl aclocal.m4 generated automatically by aclocal 1.3
dnl aclocal.m4 generated automatically by aclocal 1.4
dnl Copyright (C) 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
dnl This Makefile.in is free software; the Free Software Foundation
dnl Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
@ -20,7 +20,7 @@ dnl Usage:
dnl AM_INIT_AUTOMAKE(package,version, [no-define])
AC_DEFUN(AM_INIT_AUTOMAKE,
[AC_REQUIRE([AM_PROG_INSTALL])
[AC_REQUIRE([AC_PROG_INSTALL])
PACKAGE=[$1]
AC_SUBST(PACKAGE)
VERSION=[$2]
@ -30,8 +30,8 @@ if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then
AC_MSG_ERROR([source directory already configured; run "make distclean" there first])
fi
ifelse([$3],,
AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE")
AC_DEFINE_UNQUOTED(VERSION, "$VERSION"))
AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package])
AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package]))
AC_REQUIRE([AM_SANITY_CHECK])
AC_REQUIRE([AC_ARG_PROGRAM])
dnl FIXME This is truly gross.
@ -43,15 +43,6 @@ AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir)
AM_MISSING_PROG(MAKEINFO, makeinfo, $missing_dir)
AC_REQUIRE([AC_PROG_MAKE_SET])])
# serial 1
AC_DEFUN(AM_PROG_INSTALL,
[AC_REQUIRE([AC_PROG_INSTALL])
test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL_PROGRAM}'
AC_SUBST(INSTALL_SCRIPT)dnl
])
#
# Check to make sure that the build environment is sane.
#

View File

@ -3,46 +3,40 @@ bin_PROGRAMS = bc
bc_SOURCES = main.c bc.y scan.l execute.c load.c storage.c util.c global.c
EXTRA_DIST = bc.h fix-libmath_h libmath.b sbc.y
EXTRA_DIST = bc.h bcdefs.h const.h fix-libmath_h global.h libmath.b proto.h \
sbc.y
noinst_HEADERS = libmath.h
DISTCLEANFILES = sbc sbc.c sbc.h
MAINTAINERCLEANFILES = libmath.h bc.c bc.h
datadir = $(prefix)/@DATADIRNAME@
MAINTAINERCLEANFILES = Makefile.in libmath.h bc.c bc.h scan.c
INCLUDES = -I$(srcdir) -I$(srcdir)/../h
LDADD = ../lib/libbc.a @LEXLIB@
LIBBC = ../lib/libbc.a
LIBL = @LEXLIB@
LDADD = $(LIBBC) $(LIBL) @READLINELIB@
YFLAGS = -d
$(PROGRAMS): $(LDADD)
CFLAGS = @CFLAGS@ -Wall -funsigned-char
$(PROGRAMS): $(LIBBC)
scan.o: bc.h
global.o: libmath.h
libmath.h: libmath.b
echo \"\" > libmath.h
echo '{0}' > libmath.h
$(MAKE) fbc
./fbc -c $(srcdir)/libmath.b </dev/null >libmath.h
$(srcdir)/fix-libmath_h
rm -f ./fbc
install-data-local:
if grep -s "define BC_MATH_FILE" ../config.h; \
then $(mkinstalldirs) $(libdir); \
rm -f $(libdir)/libmath.b; \
$(INSTALL_DATA) $(srcdir)/libmath.b $(libdir); \
chmod 444 $(libdir)/libmath.b; \
else true; \
fi
fbcOBJ = main.o bc.o scan.o execute.o global.o load.o storage.o util.o
fbc: $(fbcOBJ)
$(LINK) $(fbcOBJ) $(LDADD) $(LIBS)
$(LINK) $(fbcOBJ) $(LIBBC) $(LIBL) $(READLINELIB) $(LIBS)
sbcOBJ = main.o sbc.o scan.o execute.o global.o load.o storage.o util.o
sbc.o: sbc.c
sbc: $(sbcOBJ)
$(LINK) $(sbcOBJ) $(LDADD) $(LIBS)
$(LINK) $(sbcOBJ) $(LIBBC) $(LIBL) $(READLINELIB) $(LIBS)

View File

@ -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@
@ -22,6 +22,7 @@ exec_prefix = @exec_prefix@
bindir = @bindir@
sbindir = @sbindir@
libexecdir = @libexecdir@
datadir = @datadir@
sysconfdir = @sysconfdir@
sharedstatedir = @sharedstatedir@
localstatedir = @localstatedir@
@ -31,7 +32,7 @@ mandir = @mandir@
includedir = @includedir@
oldincludedir = /usr/include
DISTDIR =
DESTDIR =
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
@ -45,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@
@ -61,6 +62,7 @@ LEX = @LEX@
MAKEINFO = @MAKEINFO@
PACKAGE = @PACKAGE@
RANLIB = @RANLIB@
READLINELIB = @READLINELIB@
VERSION = @VERSION@
YACC = @YACC@
@ -68,19 +70,23 @@ bin_PROGRAMS = bc
bc_SOURCES = main.c bc.y scan.l execute.c load.c storage.c util.c global.c
EXTRA_DIST = bc.h fix-libmath_h libmath.b sbc.y
EXTRA_DIST = bc.h bcdefs.h const.h fix-libmath_h global.h libmath.b proto.h sbc.y
noinst_HEADERS = libmath.h
DISTCLEANFILES = sbc sbc.c sbc.h
MAINTAINERCLEANFILES = libmath.h bc.c bc.h
datadir = $(prefix)/@DATADIRNAME@
MAINTAINERCLEANFILES = Makefile.in libmath.h bc.c bc.h scan.c
INCLUDES = -I$(srcdir) -I$(srcdir)/../h
LDADD = ../lib/libbc.a @LEXLIB@
LIBBC = ../lib/libbc.a
LIBL = @LEXLIB@
LDADD = $(LIBBC) $(LIBL) @READLINELIB@
YFLAGS = -d
CFLAGS = @CFLAGS@ -Wall -funsigned-char
fbcOBJ = main.o bc.o scan.o execute.o global.o load.o storage.o util.o
sbcOBJ = main.o sbc.o scan.o execute.o global.o load.o storage.o util.o
@ -101,9 +107,9 @@ bc_DEPENDENCIES = ../lib/libbc.a
bc_LDFLAGS =
LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@
LEXLIB = @LEXLIB@
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 bc.c scan.c
@ -112,15 +118,14 @@ DIST_COMMON = Makefile.am Makefile.in bc.c scan.c
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = tar
GZIP = --best
GZIP_ENV = --best
SOURCES = $(bc_SOURCES)
OBJECTS = $(bc_OBJECTS)
all: Makefile $(PROGRAMS) $(HEADERS)
all: all-redirect
.SUFFIXES:
.SUFFIXES: .S .c .l .o .s .y
$(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 bc/Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@ -142,15 +147,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:
@ -175,21 +180,25 @@ maintainer-clean-compile:
bc: $(bc_OBJECTS) $(bc_DEPENDENCIES)
@rm -f bc
$(LINK) $(bc_LDFLAGS) $(bc_OBJECTS) $(bc_LDADD) $(LIBS)
.l.c:
$(LEX) $(AM_LFLAGS) $(LFLAGS) $< && mv $(LEX_OUTPUT_ROOT).c $@
.y.c:
$(YACC) $(YFLAGS) $< && mv y.tab.c $*.c
$(YACC) $(AM_YFLAGS) $(YFLAGS) $< && mv y.tab.c $*.c
if test -f y.tab.h; then \
if cmp -s y.tab.h $*.h; then rm -f y.tab.h; else mv y.tab.h $*.h; fi; \
else :; fi
bc.h: bc.c
.l.c:
$(LEX) $(LFLAGS) $< && mv $(LEX_OUTPUT_ROOT).c $@
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=; \
@ -217,97 +226,119 @@ subdir = bc
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)
bc.o: bc.c bcdefs.h ../config.h const.h ../h/number.h global.h proto.h
execute.o: execute.c bcdefs.h ../config.h const.h ../h/number.h global.h \
proto.h
global.o: global.c bcdefs.h ../config.h const.h ../h/number.h global.h \
libmath.h
load.o: load.c bcdefs.h ../config.h const.h ../h/number.h global.h \
proto.h
main.o: main.c bcdefs.h ../config.h const.h ../h/number.h global.h \
proto.h ../h/getopt.h
scan.o: scan.c bcdefs.h ../config.h const.h ../h/number.h bc.h global.h \
proto.h
storage.o: storage.c bcdefs.h ../config.h const.h ../h/number.h global.h \
proto.h
util.o: util.c bcdefs.h ../config.h const.h ../h/number.h global.h \
proto.h
install-data: install-data-local
@$(NORMAL_INSTALL)
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: install-exec install-data all
@:
uninstall: uninstall-binPROGRAMS
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)
-test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES)
maintainer-clean-generic:
-test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES)
-test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES)
mostlyclean: mostlyclean-binPROGRAMS mostlyclean-compile \
-test -z "scanlbchbcc$(MAINTAINERCLEANFILES)" || rm -f scanl bch bcc $(MAINTAINERCLEANFILES)
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)
$(PROGRAMS): $(LIBBC)
scan.o: bc.h
global.o: libmath.h
libmath.h: libmath.b
echo \"\" > libmath.h
echo '{0}' > libmath.h
$(MAKE) fbc
./fbc -c $(srcdir)/libmath.b </dev/null >libmath.h
$(srcdir)/fix-libmath_h
rm -f ./fbc
install-data-local:
if grep -s "define BC_MATH_FILE" ../config.h; \
then $(mkinstalldirs) $(libdir); \
rm -f $(libdir)/libmath.b; \
$(INSTALL_DATA) $(srcdir)/libmath.b $(libdir); \
chmod 444 $(libdir)/libmath.b; \
else true; \
fi
fbc: $(fbcOBJ)
$(LINK) $(fbcOBJ) $(LDADD) $(LIBS)
$(LINK) $(fbcOBJ) $(LIBBC) $(LIBL) $(READLINELIB) $(LIBS)
sbc.o: sbc.c
sbc: $(sbcOBJ)
$(LINK) $(sbcOBJ) $(LDADD) $(LIBS)
$(LINK) $(sbcOBJ) $(LIBBC) $(LIBL) $(READLINELIB) $(LIBS)
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.

View File

@ -16,11 +16,13 @@
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.
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
You may contact the author by:
e-mail: phil@cs.wwu.edu
e-mail: philnelson@acm.org
us-mail: Philip A. Nelson
Computer Science Department, 9062
Western Washington University
@ -43,7 +45,7 @@
}
/* Extensions over POSIX bc.
a) NAME was LETTER. This grammer allows longer names.
a) NAME was LETTER. This grammar allows longer names.
Single letter names will still work.
b) Relational_expression allowed only one comparison.
This grammar has added boolean expressions with
@ -61,7 +63,7 @@
j) limits statement to print the processor's limits.
*/
%token <i_value> NEWLINE AND OR NOT
%token <i_value> ENDOFLINE AND OR NOT
%token <s_value> STRING NAME NUMBER
/* '-', '+' are tokens themselves */
/* '=', '+=', '-=', '*=', '/=', '%=', '^=' */
@ -79,7 +81,7 @@
/* 'warranty', 'halt', 'last', 'continue', 'print', 'limits' */
%token <i_value> Warranty, Halt, Last, Continue, Print, Limits
/* 'history' */
%token <i_value> UNARY_MINUS History
%token <i_value> UNARY_MINUS HistoryVar
/* Types of all other things. */
%type <i_value> expression return_expression named_expression opt_expression
@ -87,7 +89,7 @@
%type <a_value> opt_parameter_list opt_auto_define_list define_list
%type <a_value> opt_argument_list argument_list
%type <i_value> program input_item semicolon_list statement_list
%type <i_value> statement function statement_or_error
%type <i_value> statement function statement_or_error required_eol
/* precedence */
%left OR
@ -107,24 +109,24 @@ program : /* empty */
$$ = 0;
if (interactive && !quiet)
{
printf ("%s\n", BC_VERSION);
show_bc_version ();
welcome ();
}
}
| program input_item
;
input_item : semicolon_list NEWLINE
input_item : semicolon_list ENDOFLINE
{ run_code (); }
| function
{ run_code (); }
| error NEWLINE
| error ENDOFLINE
{
yyerrok;
init_gen ();
}
;
opt_newline : /* empty */
| NEWLINE
| ENDOFLINE
{ warn ("newline not allowed"); }
;
semicolon_list : /* empty */
@ -136,8 +138,8 @@ semicolon_list : /* empty */
statement_list : /* empty */
{ $$ = 0; }
| statement_or_error
| statement_list NEWLINE
| statement_list NEWLINE statement_or_error
| statement_list ENDOFLINE
| statement_list ENDOFLINE statement_or_error
| statement_list ';'
| statement_list ';' statement
;
@ -190,9 +192,7 @@ statement : Warranty
{ exit (0); }
| Halt
{ generate ("h"); }
| Return
{ generate ("0R"); }
| Return '(' return_expression ')'
| Return return_expression
{ generate ("R"); }
| For
{
@ -201,13 +201,12 @@ statement : Warranty
}
'(' opt_expression ';'
{
if ($4 > 1)
if ($4 & 2)
warn ("Comparison in first for expression");
if ($4 >= 0)
generate ("p");
$4 = next_label++;
if ($4 < 0)
sprintf (genstr, "N%1d:", $4);
else
sprintf (genstr, "pN%1d:", $4);
sprintf (genstr, "N%1d:", $4);
generate (genstr);
}
opt_expression ';'
@ -223,9 +222,9 @@ statement : Warranty
}
opt_expression ')'
{
if ($10 > 1)
if ($10 & 2 )
warn ("Comparison in third for expression");
if ($10 < 0)
if ($10 & 16)
sprintf (genstr, "J%1d:N%1d:", $4, $7);
else
sprintf (genstr, "pJ%1d:N%1d:", $4, $7);
@ -300,7 +299,7 @@ opt_else : /* nothing */
}
opt_newline statement
function : Define NAME '(' opt_parameter_list ')' opt_newline
'{' NEWLINE opt_auto_define_list
'{' required_eol opt_auto_define_list
{
/* Check auto list against parameter list? */
check_params ($4,$9);
@ -313,7 +312,7 @@ function : Define NAME '(' opt_parameter_list ')' opt_newline
$1 = next_label;
next_label = 1;
}
statement_list /* NEWLINE */ '}'
statement_list /* ENDOFLINE */ '}'
{
generate ("0R]");
next_label = $1;
@ -325,7 +324,7 @@ opt_parameter_list : /* empty */
;
opt_auto_define_list : /* empty */
{ $$ = NULL; }
| Auto define_list NEWLINE
| Auto define_list ENDOFLINE
{ $$ = $2; }
| Auto define_list ';'
{ $$ = $2; }
@ -349,7 +348,7 @@ opt_argument_list : /* empty */
;
argument_list : expression
{
if ($1 > 1) warn ("comparison in argument");
if ($1 & 2) warn ("comparison in argument");
$$ = nextarg (NULL,0,FALSE);
}
| NAME '[' ']'
@ -360,7 +359,7 @@ argument_list : expression
}
| argument_list ',' expression
{
if ($3 > 1) warn ("comparison in argument");
if ($3 & 2) warn ("comparison in argument");
$$ = nextarg ($1,0,FALSE);
}
| argument_list ',' NAME '[' ']'
@ -370,9 +369,18 @@ argument_list : expression
$$ = nextarg ($1,1,FALSE);
}
;
/* Expression lval meanings! (Bits mean something!)
* 0 => Top op is assignment.
* 1 => Top op is not assignment.
* 2 => Comparison is somewhere in expression.
* 4 => Expression is in parenthesis.
* 16 => Empty optional expression.
*/
opt_expression : /* empty */
{
$$ = -1;
$$ = 16;
warn ("Missing expression in for statement");
}
| expression
@ -384,8 +392,10 @@ return_expression : /* empty */
}
| expression
{
if ($1 > 1)
if ($1 & 2)
warn ("comparison in return expresion");
if (!($1 & 4))
warn ("return expression requires parenthesis");
}
;
expression : named_expression ASSIGN_OP
@ -401,7 +411,7 @@ expression : named_expression ASSIGN_OP
}
expression
{
if ($4 > 1) warn("comparison in assignment");
if ($4 & 2) warn("comparison in assignment");
if ($2 != '=')
{
sprintf (genstr, "%c", $2);
@ -426,7 +436,7 @@ expression : named_expression ASSIGN_OP
{
sprintf (genstr, "DZ%d:p1N%d:", $2, $2);
generate (genstr);
$$ = $1 | $4;
$$ = ($1 | $4) & ~4;
}
| expression OR
{
@ -442,11 +452,11 @@ expression : named_expression ASSIGN_OP
sprintf (genstr, "B%d:0J%d:N%d:1N%d:",
$2, tmplab, $2, tmplab);
generate (genstr);
$$ = $1 | $4;
$$ = ($1 | $4) & ~4;
}
| NOT expression
{
$$ = $2;
$$ = $2 & ~4;
warn("! operator");
generate ("!");
}
@ -481,37 +491,37 @@ expression : named_expression ASSIGN_OP
| expression '+' expression
{
generate ("+");
$$ = $1 | $3;
$$ = ($1 | $3) & ~4;
}
| expression '-' expression
{
generate ("-");
$$ = $1 | $3;
$$ = ($1 | $3) & ~4;
}
| expression '*' expression
{
generate ("*");
$$ = $1 | $3;
$$ = ($1 | $3) & ~4;
}
| expression '/' expression
{
generate ("/");
$$ = $1 | $3;
$$ = ($1 | $3) & ~4;
}
| expression '%' expression
{
generate ("%");
$$ = $1 | $3;
$$ = ($1 | $3) & ~4;
}
| expression '^' expression
{
generate ("^");
$$ = $1 | $3;
$$ = ($1 | $3) & ~4;
}
| '-' expression %prec UNARY_MINUS
{
generate ("n");
$$ = $2;
$$ = $2 & ~4;
}
| named_expression
{
@ -539,7 +549,7 @@ expression : named_expression ASSIGN_OP
free ($1);
}
| '(' expression ')'
{ $$ = $2 | 1; }
{ $$ = $2 | 5; }
| NAME '(' opt_argument_list ')'
{
$$ = 1;
@ -623,7 +633,7 @@ named_expression : NAME
{ $$ = 1; }
| Scale
{ $$ = 2; }
| History
| HistoryVar
{ $$ = 3;
warn ("History variable");
}
@ -633,5 +643,12 @@ named_expression : NAME
}
;
required_eol : { warn ("End of line required"); }
| ENDOFLINE
| required_eol ENDOFLINE
{ warn ("Too many end of lines"); }
;
%%

188
contrib/bc/bc/bcdefs.h Normal file
View File

@ -0,0 +1,188 @@
/* bcdefs.h: The single file to include all constants and type definitions. */
/* 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, Inc.
59 Temple Place, Suite 330
Boston, MA 02111 USA
You may contact the author by:
e-mail: philnelson@acm.org
us-mail: Philip A. Nelson
Computer Science Department, 9062
Western Washington University
Bellingham, WA 98226-9062
*************************************************************************/
/* Include the configuration file. */
#include "config.h"
/* Standard includes for all files. */
#include <stdio.h>
#include <sys/types.h>
#include <ctype.h>
#ifdef HAVE_STRINGS_H
#include <strings.h>
#else
#include <string.h>
#endif
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#if defined(LIBEDIT)
#include <histedit.h>
#endif
#if defined(READLINE)
#include <readline/readline.h>
#include <readline/history.h>
#endif
/* Include the other definitions. */
#include "const.h"
#include "number.h"
/* These definitions define all the structures used in
code and data storage. This includes the representation of
labels. The "guiding" principle is to make structures that
take a minimum of space when unused but can be built to contain
the full structures. */
/* Labels are first. Labels are generated sequentially in functions
and full code. They just "point" to a single bye in the code. The
"address" is the byte number. The byte number is used to get an
actual character pointer. */
typedef struct bc_label_group
{
long l_adrs [ BC_LABEL_GROUP ];
struct bc_label_group *l_next;
} bc_label_group;
/* Argument list. Recorded in the function so arguments can
be checked at call time. */
typedef struct arg_list
{
int av_name;
int arg_is_var; /* Extension ... variable parameters. */
struct arg_list *next;
} arg_list;
/* Each function has its own code segments and labels. There can be
no jumps between functions so labels are unique to a function. */
typedef struct
{
char f_defined; /* Is this function defined yet. */
char *f_body;
int f_body_size; /* Size of body. Power of 2. */
int f_code_size;
bc_label_group *f_label;
arg_list *f_params;
arg_list *f_autos;
} bc_function;
/* Code addresses. */
typedef struct {
int pc_func;
int pc_addr;
} program_counter;
/* Variables are "pushable" (auto) and thus we need a stack mechanism.
This is built into the variable record. */
typedef struct bc_var
{
bc_num v_value;
struct bc_var *v_next;
} bc_var;
/* bc arrays can also be "auto" variables and thus need the same
kind of stacking mechanisms. */
typedef struct bc_array_node
{
union
{
bc_num n_num [NODE_SIZE];
struct bc_array_node *n_down [NODE_SIZE];
} n_items;
} bc_array_node;
typedef struct bc_array
{
bc_array_node *a_tree;
short a_depth;
} bc_array;
typedef struct bc_var_array
{
bc_array *a_value;
char a_param;
struct bc_var_array *a_next;
} bc_var_array;
/* For the stacks, execution and function, we need records to allow
for arbitrary size. */
typedef struct estack_rec {
bc_num s_num;
struct estack_rec *s_next;
} estack_rec;
typedef struct fstack_rec {
int s_val;
struct fstack_rec *s_next;
} fstack_rec;
/* The following are for the name tree. */
typedef struct id_rec {
char *id; /* The program name. */
/* A name == 0 => nothing assigned yet. */
int a_name; /* The array variable name (number). */
int f_name; /* The function name (number). */
int v_name; /* The variable name (number). */
short balance; /* For the balanced tree. */
struct id_rec *left, *right; /* Tree pointers. */
} id_rec;
/* A list of files to process. */
typedef struct file_node {
char *name;
struct file_node *next;
} file_node;
/* Macro Definitions */
#if defined(LIBEDIT)
#define HISTORY_SIZE(n) history(hist, &histev, H_SETSIZE, n)
#define UNLIMIT_HISTORY history(hist, &histev, H_SETSIZE, INT_MAX)
#endif
#if defined(READLINE)
#define HISTORY_SIZE(n) stifle_history(n)
#define UNLIMIT_HISTORY unstifle_history()
#endif

98
contrib/bc/bc/const.h Normal file
View File

@ -0,0 +1,98 @@
/* const.h: Constants 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, Inc.
59 Temple Place, Suite 330
Boston, MA 02111 USA
You may contact the author by:
e-mail: philnelson@acm.org
us-mail: Philip A. Nelson
Computer Science Department, 9062
Western Washington University
Bellingham, WA 98226-9062
*************************************************************************/
/* Define INT_MAX and LONG_MAX if not defined. Assuming 32 bits... */
#ifndef INT_MAX
#define INT_MAX 0x7FFFFFFF
#endif
#ifndef LONG_MAX
#define LONG_MAX 0x7FFFFFFF
#endif
/* Define constants in some reasonable size. The next 4 constants are
POSIX constants. */
#ifdef BC_BASE_MAX
/* <limits.h> on a POSIX.2 system may have defined these. Override. */
# undef BC_BASE_MAX
# undef BC_SCALE_MAX
# undef BC_STRING_MAX
# undef BC_DIM_MAX
#endif
#define BC_BASE_MAX INT_MAX
#define BC_SCALE_MAX INT_MAX
#define BC_STRING_MAX INT_MAX
/* Definitions for arrays. */
#define BC_DIM_MAX 65535 /* this should be NODE_SIZE^NODE_DEPTH-1 */
#define NODE_SIZE 16 /* Must be a power of 2. */
#define NODE_MASK 0xf /* Must be NODE_SIZE-1. */
#define NODE_SHIFT 4 /* Number of 1 bits in NODE_MASK. */
#define NODE_DEPTH 4
/* Other BC limits defined but not part of POSIX. */
#define BC_LABEL_GROUP 64
#define BC_LABEL_LOG 6
#define BC_START_SIZE 1024 /* Initial code body size. */
/* Maximum number of variables, arrays and functions and the
allocation increment for the dynamic arrays. */
#define MAX_STORE 32767
#define STORE_INCR 32
/* Other interesting constants. */
#define FALSE 0
#define TRUE 1
/* for use with lookup (). */
#define SIMPLE 0
#define ARRAY 1
#define FUNCT 2
#define FUNCTDEF 3
#define EXTERN extern
#ifdef __STDC__
#define CONST const
#define VOID void
#else
#define CONST
#define VOID
#endif

View File

@ -1,7 +1,7 @@
/* execute.c - run a bc program. */
/* This file is part of GNU bc.
Copyright (C) 1991, 1992, 1993, 1994, 1997 Free Software Foundation, Inc.
Copyright (C) 1991-1994, 1997, 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
e-mail: philnelson@acm.org
us-mail: Philip A. Nelson
Computer Science Department, 9062
Western Washington University
@ -52,11 +54,7 @@ unsigned char
byte (pc)
program_counter *pc;
{
int seg, offset;
seg = pc->pc_addr >> BC_SEG_LOG;
offset = pc->pc_addr++ % BC_SEG_SIZE;
return (functions[pc->pc_func].f_body[seg][offset]);
return (functions[pc->pc_func].f_body[pc->pc_addr++]);
}
@ -81,7 +79,7 @@ execute ()
pc.pc_func = 0;
pc.pc_addr = 0;
runtime_error = FALSE;
init_num (&temp_num);
bc_init_num (&temp_num);
/* Set up the interrupt mechanism for an interactive session. */
if (interactive)
@ -105,11 +103,12 @@ execute ()
depth = 1;
while (temp != NULL)
{
printf (" %d = ", depth);
out_num (temp->s_num, 10, out_char);
printf (" %d = ", depth);
bc_out_num (temp->s_num, 10, out_char, std_only);
depth++;
temp = temp->s_next;
}
out_char ('\n');
}
}
#endif
@ -120,13 +119,13 @@ execute ()
case 'A' : /* increment array variable (Add one). */
var_name = byte(&pc);
if ((var_name & 0x80) != 0)
var_name = ((var_name << 8) & 0x7f) + byte(&pc);
var_name = ((var_name & 0x7f) << 8) + byte(&pc);
incr_array (var_name);
break;
case 'B' : /* Branch to a label if TOS != 0. Remove value on TOS. */
case 'Z' : /* Branch to a label if TOS == 0. Remove value on TOS. */
c_code = !is_zero (ex_stack->s_num);
c_code = !bc_is_zero (ex_stack->s_num);
pop ();
case 'J' : /* Jump to a label. */
label_num = byte(&pc); /* Low order bits first. */
@ -145,7 +144,7 @@ execute ()
/* Get the function number. */
new_func = byte(&pc);
if ((new_func & 0x80) != 0)
new_func = ((new_func << 8) & 0x7f) + byte(&pc);
new_func = ((new_func & 0x7f) << 8) + byte(&pc);
/* Check to make sure it is defined. */
if (!functions[new_func].f_defined)
@ -192,14 +191,14 @@ execute ()
case 'L' : /* load array variable */
var_name = byte(&pc);
if ((var_name & 0x80) != 0)
var_name = ((var_name << 8) & 0x7f) + byte(&pc);
var_name = ((var_name & 0x7f) << 8) + byte(&pc);
load_array (var_name);
break;
case 'M' : /* decrement array variable (Minus!) */
var_name = byte(&pc);
if ((var_name & 0x80) != 0)
var_name = ((var_name << 8) & 0x7f) + byte(&pc);
var_name = ((var_name & 0x7f) << 8) + byte(&pc);
decr_array (var_name);
break;
@ -245,18 +244,18 @@ execute ()
case 'S' : /* store array variable */
var_name = byte(&pc);
if ((var_name & 0x80) != 0)
var_name = ((var_name << 8) & 0x7f) + byte(&pc);
var_name = ((var_name & 0x7f ) << 8) + byte(&pc);
store_array (var_name);
break;
case 'T' : /* Test tos for zero */
c_code = is_zero (ex_stack->s_num);
c_code = bc_is_zero (ex_stack->s_num);
assign (c_code);
break;
case 'W' : /* Write the value on the top of the stack. */
case 'P' : /* Write the value on the top of the stack. No newline. */
out_num (ex_stack->s_num, o_base, out_char);
bc_out_num (ex_stack->s_num, o_base, out_char, std_only);
if (inst == 'W') out_char ('\n');
store_var (4); /* Special variable "last". */
fflush (stdout);
@ -273,14 +272,14 @@ execute ()
if (ex_stack->s_num->n_len == 1 &&
ex_stack->s_num->n_scale != 0 &&
ex_stack->s_num->n_value[0] == 0 )
int2num (&ex_stack->s_num, ex_stack->s_num->n_scale);
bc_int2num (&ex_stack->s_num, ex_stack->s_num->n_scale);
else
int2num (&ex_stack->s_num, ex_stack->s_num->n_len
bc_int2num (&ex_stack->s_num, ex_stack->s_num->n_len
+ ex_stack->s_num->n_scale);
break;
case 'S': /* Scale function. */
int2num (&ex_stack->s_num, ex_stack->s_num->n_scale);
bc_int2num (&ex_stack->s_num, ex_stack->s_num->n_scale);
break;
case 'R': /* Square Root function. */
@ -297,7 +296,7 @@ execute ()
case 'd' : /* Decrement number */
var_name = byte(&pc);
if ((var_name & 0x80) != 0)
var_name = ((var_name << 8) & 0x7f) + byte(&pc);
var_name = ((var_name & 0x7f) << 8) + byte(&pc);
decr_var (var_name);
break;
@ -307,14 +306,14 @@ execute ()
case 'i' : /* increment number */
var_name = byte(&pc);
if ((var_name & 0x80) != 0)
var_name = ((var_name << 8) & 0x7f) + byte(&pc);
var_name = ((var_name & 0x7f) << 8) + byte(&pc);
incr_var (var_name);
break;
case 'l' : /* load variable */
var_name = byte(&pc);
if ((var_name & 0x80) != 0)
var_name = ((var_name << 8) & 0x7f) + byte(&pc);
var_name = ((var_name & 0x7f) << 8) + byte(&pc);
load_var (var_name);
break;
@ -329,7 +328,7 @@ execute ()
case 's' : /* store variable */
var_name = byte(&pc);
if ((var_name & 0x80) != 0)
var_name = ((var_name << 8) & 0x7f) + byte(&pc);
var_name = ((var_name & 0x7f) << 8) + byte(&pc);
store_var (var_name);
break;
@ -355,15 +354,15 @@ execute ()
break;
case '!' : /* Negate the boolean value on top of the stack. */
c_code = is_zero (ex_stack->s_num);
c_code = bc_is_zero (ex_stack->s_num);
assign (c_code);
break;
case '&' : /* compare greater than */
if (check_stack(2))
{
c_code = !is_zero (ex_stack->s_next->s_num)
&& !is_zero (ex_stack->s_num);
c_code = !bc_is_zero (ex_stack->s_next->s_num)
&& !bc_is_zero (ex_stack->s_num);
pop ();
assign (c_code);
}
@ -372,8 +371,8 @@ execute ()
case '|' : /* compare greater than */
if (check_stack(2))
{
c_code = !is_zero (ex_stack->s_next->s_num)
|| !is_zero (ex_stack->s_num);
c_code = !bc_is_zero (ex_stack->s_next->s_num)
|| !bc_is_zero (ex_stack->s_num);
pop ();
assign (c_code);
}
@ -386,7 +385,7 @@ execute ()
pop();
pop();
push_num (temp_num);
init_num (&temp_num);
bc_init_num (&temp_num);
}
break;
@ -397,7 +396,7 @@ execute ()
pop();
pop();
push_num (temp_num);
init_num (&temp_num);
bc_init_num (&temp_num);
}
break;
@ -409,7 +408,7 @@ execute ()
pop();
pop();
push_num (temp_num);
init_num (&temp_num);
bc_init_num (&temp_num);
}
break;
@ -422,7 +421,7 @@ execute ()
pop();
pop();
push_num (temp_num);
init_num (&temp_num);
bc_init_num (&temp_num);
}
else
rt_error ("Divide by zero");
@ -432,7 +431,7 @@ execute ()
case '%' : /* remainder */
if (check_stack(2))
{
if (is_zero (ex_stack->s_num))
if (bc_is_zero (ex_stack->s_num))
rt_error ("Modulo by zero");
else
{
@ -441,7 +440,7 @@ execute ()
pop();
pop();
push_num (temp_num);
init_num (&temp_num);
bc_init_num (&temp_num);
}
}
break;
@ -451,12 +450,12 @@ execute ()
{
bc_raise (ex_stack->s_next->s_num,
ex_stack->s_num, &temp_num, scale);
if (is_zero (ex_stack->s_next->s_num) && is_neg (ex_stack->s_num))
if (bc_is_zero (ex_stack->s_next->s_num) && bc_is_neg (ex_stack->s_num))
rt_error ("divide by zero");
pop();
pop();
push_num (temp_num);
init_num (&temp_num);
bc_init_num (&temp_num);
}
break;
@ -578,7 +577,7 @@ input_char ()
}
/* Classify and preprocess the input character. */
if (isdigit(in_ch))
if (isdigit((int)in_ch))
return (in_ch - '0');
if (in_ch >= 'A' && in_ch <= 'F')
return (in_ch + 10 - 'A');
@ -608,14 +607,14 @@ push_constant (in_char, conv_base)
char negative;
/* Initialize all bc numbers */
init_num (&temp);
init_num (&result);
init_num (&mult);
build = copy_num (_zero_);
bc_init_num (&temp);
bc_init_num (&result);
bc_init_num (&mult);
build = bc_copy_num (_zero_);
negative = FALSE;
/* The conversion base. */
int2num (&mult, conv_base);
bc_int2num (&mult, conv_base);
/* Get things ready. */
in_ch = in_char();
@ -638,7 +637,7 @@ push_constant (in_char, conv_base)
in_ch = in_char();
if (in_ch < 16 && first_ch >= conv_base)
first_ch = conv_base - 1;
int2num (&build, (int) first_ch);
bc_int2num (&build, (int) first_ch);
}
/* Convert the integer part. */
@ -646,7 +645,7 @@ push_constant (in_char, conv_base)
{
if (in_ch < 16 && in_ch >= conv_base) in_ch = conv_base-1;
bc_multiply (build, mult, &result, 0);
int2num (&temp, (int) in_ch);
bc_int2num (&temp, (int) in_ch);
bc_add (result, temp, &build, 0);
in_ch = in_char();
}
@ -654,15 +653,15 @@ push_constant (in_char, conv_base)
{
in_ch = in_char();
if (in_ch >= conv_base) in_ch = conv_base-1;
free_num (&result);
free_num (&temp);
divisor = copy_num (_one_);
result = copy_num (_zero_);
bc_free_num (&result);
bc_free_num (&temp);
divisor = bc_copy_num (_one_);
result = bc_copy_num (_zero_);
digits = 0;
while (in_ch < 16)
{
bc_multiply (result, mult, &result, 0);
int2num (&temp, (int) in_ch);
bc_int2num (&temp, (int) in_ch);
bc_add (result, temp, &result, 0);
bc_multiply (divisor, mult, &divisor, 0);
digits++;
@ -678,9 +677,9 @@ push_constant (in_char, conv_base)
bc_sub (_zero_, build, &build, 0);
push_num (build);
free_num (&temp);
free_num (&result);
free_num (&mult);
bc_free_num (&temp);
bc_free_num (&result);
bc_free_num (&mult);
}
@ -738,8 +737,8 @@ push_b10_const (pc)
}
if (inchar > 9)
{
init_num (&build);
int2num (&build, inchar);
bc_init_num (&build);
bc_int2num (&build, inchar);
push_num (build);
inchar = byte(pc);
return;
@ -749,23 +748,25 @@ push_b10_const (pc)
/* Build the new number. */
if (kdigits == 0)
{
build = new_num (1,kscale);
build = bc_new_num (1,kscale);
ptr = build->n_value;
*ptr++ = 0;
}
else
{
build = new_num (kdigits,kscale);
build = bc_new_num (kdigits,kscale);
ptr = build->n_value;
}
while (inchar != ':')
{
if (inchar != '.')
if (inchar > 9)
*ptr++ = 9;
else
*ptr++ = inchar;
{
if (inchar > 9)
*ptr++ = 9;
else
*ptr++ = inchar;
}
inchar = byte(pc);
}
push_num (build);
@ -778,9 +779,10 @@ void
assign (c_code)
char c_code;
{
free_num (&ex_stack->s_num);
bc_free_num (&ex_stack->s_num);
if (c_code)
ex_stack->s_num = copy_num (_one_);
ex_stack->s_num = bc_copy_num (_one_);
else
ex_stack->s_num = copy_num (_zero_);
ex_stack->s_num = bc_copy_num (_zero_);
}

View File

@ -1,8 +1,9 @@
ed libmath.h <<EOS-EOS
1,1s/^/"/
1,\$s/\$/\\\\/
1,1s/^/{"/
1,\$s/\$/",/
2,\$s/^/"/
\$,\$d
\$,\$s/\\\\\$/"/
\$,\$s/,\$/,0}/
w
q
EOS-EOS

View File

@ -1,7 +1,7 @@
/* global.c: This defines the global variables. */
/* This file is part of GNU bc.
Copyright (C) 1991, 1992, 1993, 1994, 1997 Free Software Foundation, Inc.
Copyright (C) 1991-1994, 1997, 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
e-mail: philnelson@acm.org
us-mail: Philip A. Nelson
Computer Science Department, 9062
Western Washington University
@ -35,8 +37,6 @@
/* Define all the global variables for bc. */
#include "global.h"
#ifndef BC_MATH_FILE
CONST char libmath[] =
CONST char *libmath[] =
#include "libmath.h"
;
#endif

154
contrib/bc/bc/global.h Normal file
View File

@ -0,0 +1,154 @@
/* global.h: The global variables 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, Inc.
59 Temple Place, Suite 330
Boston, MA 02111 USA
You may contact the author by:
e-mail: philnelson@acm.org
us-mail: Philip A. Nelson
Computer Science Department, 9062
Western Washington University
Bellingham, WA 98226-9062
*************************************************************************/
/* The current break level's lable. */
EXTERN int break_label;
/* The current if statement's else label or label after else. */
EXTERN int if_label;
/* The current for statement label for continuing the loop. */
EXTERN int continue_label;
/* Next available label number. */
EXTERN int next_label;
/* Byte code character storage. Used in many places for generation of code. */
EXTERN char genstr[80];
/* Count of characters printed to the output in compile_only mode. */
EXTERN int out_count;
/* Have we generated any code since the last initialization of the code
generator. */
EXTERN char did_gen;
/* Is this run an interactive execution. (Is stdin a terminal?) */
EXTERN char interactive;
/* Just generate the byte code. -c flag. */
EXTERN int compile_only;
/* Load the standard math functions. -l flag. */
EXTERN int use_math;
/* Give a warning on use of any non-standard feature (non-POSIX). -w flag. */
EXTERN int warn_not_std;
/* Accept POSIX bc only! -s flag. */
EXTERN int std_only;
/* Don't print the banner at start up. -q flag. */
EXTERN int quiet;
/* The list of file names to process. */
EXTERN file_node *file_names;
/* The name of the current file being processed. */
EXTERN char *file_name;
/* Is the current file a named file or standard input? */
EXTERN char is_std_in;
/* global variables for the bc machine. All will be dynamic in size.*/
/* Function storage. main is (0) and functions (1-f_count) */
EXTERN bc_function *functions;
EXTERN char **f_names;
EXTERN int f_count;
/* Variable stoarge and reverse names. */
EXTERN bc_var **variables;
EXTERN char **v_names;
EXTERN int v_count;
/* Array Variable storage and reverse names. */
EXTERN bc_var_array **arrays;
EXTERN char **a_names;
EXTERN int a_count;
/* Execution stack. */
EXTERN estack_rec *ex_stack;
/* Function return stack. */
EXTERN fstack_rec *fn_stack;
/* Current ibase, obase, scale, and n_history (if needed). */
EXTERN int i_base;
EXTERN int o_base;
EXTERN int scale;
#if defined(READLINE) || defined(LIBEDIT)
EXTERN int n_history;
#endif
#if defined(LIBEDIT)
/* LIBEDIT data */
EditLine *edit;
History *hist;
HistEvent histev;
#endif
/* "Condition code" -- false (0) or true (1) */
EXTERN char c_code;
/* Records the number of the runtime error. */
EXTERN char runtime_error;
/* Holds the current location of execution. */
EXTERN program_counter pc;
/* For POSIX bc, this is just for number output, not strings. */
EXTERN int out_col;
/* Keeps track of the current number of characters per output line.
This includes the \n at the end of the line. */
EXTERN int line_size;
/* Input Line numbers and other error information. */
EXTERN int line_no;
EXTERN int had_error;
/* For larger identifiers, a tree, and how many "storage" locations
have been allocated. */
EXTERN int next_array;
EXTERN int next_func;
EXTERN int next_var;
EXTERN id_rec *name_tree;
/* For use with getopt. Do not declare them here.*/
extern int optind;
/* Access to the yy input file. Defined in scan.c. */
extern FILE *yyin;

View File

@ -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
e-mail: philnelson@acm.org
us-mail: Philip A. Nelson
Computer Science Department, 9062
Western Washington University
@ -158,10 +160,11 @@ define s(x) {
/* Cosine : cos(x) = sin(x+pi/2) */
define c(x) {
auto v;
scale += 1;
auto v, z;
z = scale;
scale = scale*1.2;
v = s(x+a(1)*2);
scale -= 1;
scale = z;
return (v/1);
}
@ -244,7 +247,7 @@ define a(x) {
- x^6/(2^6*3!*(n+1)*(n+2)*(n+3)) .... )
*/
define j(n,x) {
auto a, d, e, f, i, m, s, v, z
auto a, b, d, e, f, i, m, s, v, z
/* Make n an integer and check for negative n. */
z = scale;
@ -255,6 +258,10 @@ define j(n,x) {
if (n%2 == 1) m = 1;
}
/* save ibase */
b = ibase;
ibase = A;
/* Compute the factor of x^n/(2^n*n!) */
f = 1;
for (i=2; i<=n; i++) f = f*i;
@ -264,12 +271,13 @@ define j(n,x) {
/* Initialize the loop .*/
v = e = 1;
s = -x*x/4
scale = 1.5*z
scale = 1.5*z + length(f) - scale(f);
/* The Loop.... */
for (i=1; 1; i++) {
e = e * s / i / (n+i);
if (e == 0) {
ibase = b;
scale = z
if (m) return (-f*v/1);
return (f*v/1);

View File

@ -1,40 +1,40 @@
"@iK20:s2:p@r\
@iF1,5.6,7,8,9,10,11,12,13,14[l5:0<Z1:1s11:pl5:ns5:pN1:l2:s14:\
pK6:l14:+K.44:l5:*+s12:pl5:cS1+s2:pN2:l5:1>Z3:l9:1+s9:pl5:K2:\
/s5:pl2:1+s2:pJ2:N3:l12:s2:p1l5:+s13:pl5:s6:p1s7:pK2:s10:pN5:\
1B6:J4:N7:l10:i10:pJ5:N6:l6:l5:*s6:l7:l10:*s7:/s8:pl8:0=Z8:l9:\
0>Z9:N10:l9:d9:Z11:l13:l13:*s13:pJ10:N11:N9:l14:s2:pl11:Z12:1\
l13:/RN12:l13:1/RN8:l13:l8:+s13:pJ7:N4:0R]@r\
@iF2,5.8,9,10,11,12,13,14[l5:0{Z1:1K10:l2:^-1/RN1:l2:s14:pK6:\
l2:+s2:pK2:s9:p0s10:pN2:l5:K2:}Z3:l9:K2:*s9:pl5:cRs5:pJ2:N3:N4:\
l5:K.5:{Z5:l9:K2:*s9:pl5:cRs5:pJ4:N5:l5:1-l5:1+/s12:s13:pl12:\
l12:*s11:pK3:s10:pN7:1B8:J6:N9:l10:K2:+s10:pJ7:N8:l12:l11:*s12:\
l10:/s8:pl8:0=Z10:l9:l13:*s13:pl14:s2:pl13:1/RN10:l13:l8:+s13:\
pJ9:N6:0R]@r\
@iF3,5.8,10,11,12,15,13,14[l2:s14:pK1.1:l14:*K2:+s2:p1C4,0:s13:\
pl5:0<Z1:1s11:pl5:ns5:pN1:0s2:pl5:l13:/K2:+K4:/s12:pl5:K4:l12:\
*l13:*-s5:pl12:K2:%Z2:l5:ns5:pN2:l14:K2:+s2:pl5:s8:s13:pl5:nl5:\
*s15:pK3:s10:pN4:1B5:J3:N6:l10:K2:+s10:pJ4:N5:l8:l15:l10:l10:\
1-*/*s8:pl8:0=Z7:l14:s2:pl11:Z8:l13:n1/RN8:l13:1/RN7:l13:l8:+\
s13:pJ6:N3:0R]@r\
@iF5,5.13[l2:1+s2:pl5:1C4,0:K2:*+C3,0:s13:pl2:1-s2:pl13:1/R0R]\
@r\
@iF4,5.6,8,9,10,11,12,15,13,14[1s11:pl5:0<Z1:1ns11:pl5:ns5:pN1:\
l5:1=Z2:l2:K25:{Z3:K.7853981633974483096156608:l11:/RN3:l2:K40\
:{Z4:K.7853981633974483096156608458198757210492:l11:/RN4:l2:K\
60:{Z5:K.785398163397448309615660845819875721049292349843776455243736\
:l11:/RN5:N2:l5:K.2:=Z6:l2:K25:{Z7:K.1973955598498807583700497\
:l11:/RN7:l2:K40:{Z8:K.1973955598498807583700497651947902934475\
:l11:/RN8:l2:K60:{Z9:K.197395559849880758370049765194790293447585103787852101517688\
:l11:/RN9:N6:l2:s14:pl5:K.2:>Z10:l14:K5:+s2:pK.2:C4,0:s6:pN10:\
l14:K3:+s2:pN11:l5:K.2:>Z12:l9:1+s9:pl5:K.2:-1l5:K.2:*+/s5:pJ11:N12:\
l5:s12:s13:pl5:nl5:*s15:pK3:s10:pN14:1B15:J13:N16:l10:K2:+s10:\
pJ14:N15:l12:l15:*s12:l10:/s8:pl8:0=Z17:l14:s2:pl9:l6:*l13:+l11:\
/RN17:l13:l8:+s13:pJ16:N13:0R]@r\
@iF6,12,5.6,7,8,9,10,11,15,13,14[l2:s14:p0s2:pl12:1/s12:pl12:\
0<Z1:l12:ns12:pl12:K2:%1=Z2:1s11:pN2:N1:1s9:pK2:s10:pN4:l10:l12:\
{B5:J3:N6:l10:i10:pJ4:N5:l9:l10:*s9:pJ6:N3:K1.5:l14:*s2:pl5:l12:\
^K2:l12:^/l9:/s9:p1s8:s13:pl5:nl5:*K4:/s15:pK1.5:l14:*s2:p1s10:\
pN8:1B9:J7:N10:l10:i10:pJ8:N9:l8:l15:*l10:/l12:l10:+/s8:pl8:0\
=Z11:l14:s2:pl11:Z12:l9:nl13:*1/RN12:l9:l13:*1/RN11:l13:l8:+s13:\
pJ10:N7:0R]@r"
{"@iK20:s2:p@r",
"@iF1,5.6,7,8,9,10,11,12,13,14[l5:0<Z1:1s11:pl5:ns5:pN1:l2:s14:",
"pK6:l14:+K.44:l5:*+s12:pl5:cS1+s2:pN2:l5:1>Z3:l9:1+s9:pl5:K2:",
"/s5:pl2:1+s2:pJ2:N3:l12:s2:p1l5:+s13:pl5:s6:p1s7:pK2:s10:pN5:",
"1B6:J4:N7:l10:i10:pJ5:N6:l6:l5:*s6:l7:l10:*s7:/s8:pl8:0=Z8:l9:",
"0>Z9:N10:l9:d9:Z11:l13:l13:*s13:pJ10:N11:N9:l14:s2:pl11:Z12:1",
"l13:/RN12:l13:1/RN8:l13:l8:+s13:pJ7:N4:0R]@r",
"@iF2,5.8,9,10,11,12,13,14[l5:0{Z1:1K10:l2:^-1/RN1:l2:s14:pK6:",
"l2:+s2:pK2:s9:p0s10:pN2:l5:K2:}Z3:l9:K2:*s9:pl5:cRs5:pJ2:N3:N4:",
"l5:K.5:{Z5:l9:K2:*s9:pl5:cRs5:pJ4:N5:l5:1-l5:1+/s12:s13:pl12:",
"l12:*s11:pK3:s10:pN7:1B8:J6:N9:l10:K2:+s10:pJ7:N8:l12:l11:*s12:",
"l10:/s8:pl8:0=Z10:l9:l13:*s13:pl14:s2:pl13:1/RN10:l13:l8:+s13:",
"pJ9:N6:0R]@r",
"@iF3,5.8,10,11,12,15,13,14[l2:s14:pK1.1:l14:*K2:+s2:p1C4,0:s13:",
"pl5:0<Z1:1s11:pl5:ns5:pN1:0s2:pl5:l13:/K2:+K4:/s12:pl5:K4:l12:",
"*l13:*-s5:pl12:K2:%Z2:l5:ns5:pN2:l14:K2:+s2:pl5:s8:s13:pl5:nl5:",
"*s15:pK3:s10:pN4:1B5:J3:N6:l10:K2:+s10:pJ4:N5:l8:l15:l10:l10:",
"1-*/*s8:pl8:0=Z7:l14:s2:pl11:Z8:l13:n1/RN8:l13:1/RN7:l13:l8:+",
"s13:pJ6:N3:0R]@r",
"@iF5,5.13,14[l2:s14:pl2:K1.2:*s2:pl5:1C4,0:K2:*+C3,0:s13:pl14:",
"s2:pl13:1/R0R]@r",
"@iF4,5.6,8,9,10,11,12,15,13,14[1s11:pl5:0<Z1:1ns11:pl5:ns5:pN1:",
"l5:1=Z2:l2:K25:{Z3:K.7853981633974483096156608:l11:/RN3:l2:K40",
":{Z4:K.7853981633974483096156608458198757210492:l11:/RN4:l2:K",
"60:{Z5:K.785398163397448309615660845819875721049292349843776455243736",
":l11:/RN5:N2:l5:K.2:=Z6:l2:K25:{Z7:K.1973955598498807583700497",
":l11:/RN7:l2:K40:{Z8:K.1973955598498807583700497651947902934475",
":l11:/RN8:l2:K60:{Z9:K.197395559849880758370049765194790293447585103787852101517688",
":l11:/RN9:N6:l2:s14:pl5:K.2:>Z10:l14:K5:+s2:pK.2:C4,0:s6:pN10:",
"l14:K3:+s2:pN11:l5:K.2:>Z12:l9:1+s9:pl5:K.2:-1l5:K.2:*+/s5:pJ11:N12:",
"l5:s12:s13:pl5:nl5:*s15:pK3:s10:pN14:1B15:J13:N16:l10:K2:+s10:",
"pJ14:N15:l12:l15:*s12:l10:/s8:pl8:0=Z17:l14:s2:pl9:l6:*l13:+l11:",
"/RN17:l13:l8:+s13:pJ16:N13:0R]@r",
"@iF6,12,5.6,16,7,8,9,10,11,15,13,14[l2:s14:p0s2:pl12:1/s12:pl12:",
"0<Z1:l12:ns12:pl12:K2:%1=Z2:1s11:pN2:N1:l0:s16:pKA:s0:p1s9:pK",
"2:s10:pN4:l10:l12:{B5:J3:N6:l10:i10:pJ4:N5:l9:l10:*s9:pJ6:N3:",
"K1.5:l14:*s2:pl5:l12:^K2:l12:^/l9:/s9:p1s8:s13:pl5:nl5:*K4:/s15:",
"pK1.5:l14:*l9:cL+l9:cS-s2:p1s10:pN8:1B9:J7:N10:l10:i10:pJ8:N9:",
"l8:l15:*l10:/l12:l10:+/s8:pl8:0=Z11:l16:s0:pl14:s2:pl11:Z12:l9:",
"nl13:*1/RN12:l9:l13:*1/RN11:l13:l8:+s13:pJ10:N7:0R]@r",0}

View File

@ -1,7 +1,7 @@
/* load.c: This code "loads" code into the code segments. */
/* This file is part of GNU bc.
Copyright (C) 1991, 1992, 1993, 1994, 1997 Free Software Foundation, Inc.
Copyright (C) 1991-1994, 1997, 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
e-mail: philnelson@acm.org
us-mail: Philip A. Nelson
Computer Science Department, 9062
Western Washington University
@ -52,28 +54,29 @@ void
addbyte (byte)
char byte;
{
int seg, offset, func;
int pc;
bc_function *f;
char *new_body;
/* If there was an error, don't continue. */
if (had_error) return;
/* Calculate the segment and offset. */
seg = load_adr.pc_addr >> BC_SEG_LOG;
offset = load_adr.pc_addr++ % BC_SEG_SIZE;
func = load_adr.pc_func;
pc = load_adr.pc_addr++;
f = &functions[load_adr.pc_func];
if (seg >= BC_MAX_SEGS)
if (pc >= f->f_body_size)
{
yyerror ("Function too big.");
return;
f->f_body_size *= 2;
new_body = (char *) bc_malloc (f->f_body_size);
memcpy(new_body, f->f_body, f->f_body_size/2);
free (f->f_body);
f->f_body = new_body;
}
if (functions[func].f_body[seg] == NULL)
functions[func].f_body[seg] = (char *) bc_malloc (BC_SEG_SIZE);
/* Store the byte. */
functions[func].f_body[seg][offset] = byte;
functions[func].f_code_size++;
f->f_body[pc] = byte;
f->f_code_size++;
}
@ -132,7 +135,7 @@ long_val (str)
neg = TRUE;
(*str)++;
}
while (isdigit(**str))
while (isdigit((int)(**str)))
val = val*10 + *(*str)++ - '0';
if (neg)
@ -216,8 +219,8 @@ load_code (code)
fprintf (stderr,"Program too big.\n");
exit(1);
}
addbyte ( (char) label_no & 0xFF);
addbyte ( (char) label_no >> 8);
addbyte ( (char) (label_no & 0xFF));
addbyte ( (char) (label_no >> 8));
break;
case 'F': /* A function, get the name and initialize it. */
@ -286,7 +289,7 @@ load_code (code)
addbyte ( (char) func);
else
{
addbyte ((func >> 8) & 0xff | 0x80);
addbyte (((func >> 8) & 0xff) | 0x80);
addbyte (func & 0xff);
}
if (*str == ',') str++;
@ -319,7 +322,7 @@ load_code (code)
addbyte (vaf_name);
else
{
addbyte ((vaf_name >> 8) & 0xff | 0x80);
addbyte (((vaf_name >> 8) & 0xff) | 0x80);
addbyte (vaf_name & 0xff);
}
break;

View File

@ -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
e-mail: philnelson@acm.org
us-mail: Philip A. Nelson
Computer Science Department, 9062
Western Washington University
@ -34,22 +36,17 @@
/* 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},
@ -60,6 +57,20 @@ static struct option long_options[] =
};
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;
@ -75,7 +86,7 @@ parse_args (argc, argv)
/* 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 @@ parse_args (argc, argv)
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 @@ parse_args (argc, argv)
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 @@ main (argc, argv)
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_new_file ()
/* 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 @@ open_new_file ()
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. */

148
contrib/bc/bc/proto.h Normal file
View File

@ -0,0 +1,148 @@
/* proto.h: Prototype function definitions for "external" functions. */
/* This file is part of GNU bc.
Copyright (C) 1991-1994, 1997, 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
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, Inc.
59 Temple Place, Suite 330
Boston, MA 02111 USA
You may contact the author by:
e-mail: philnelson@acm.org
us-mail: Philip A. Nelson
Computer Science Department, 9062
Western Washington University
Bellingham, WA 98226-9062
*************************************************************************/
/* For the pc version using k&r ACK. (minix1.5 and earlier.) */
#ifdef SHORTNAMES
#define init_numbers i_numbers
#define push_constant push__constant
#define load_const in_load_const
#define yy_get_next_buffer yyget_next_buffer
#define yy_init_buffer yyinit_buffer
#define yy_last_accepting_state yylast_accepting_state
#define arglist1 arg1list
#endif
/* Include the standard library header files. */
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
/* Define the _PROTOTYPE macro if it is needed. */
#ifndef _PROTOTYPE
#ifdef __STDC__
#define _PROTOTYPE(func, args) func args
#else
#define _PROTOTYPE(func, args) func()
#endif
#endif
/* From execute.c */
_PROTOTYPE(void stop_execution, (int));
_PROTOTYPE(unsigned char byte, (program_counter *pc));
_PROTOTYPE(void execute, (void));
_PROTOTYPE(char prog_char, (void));
_PROTOTYPE(char input_char, (void));
_PROTOTYPE(void push_constant, (char (*in_char)(void), int conv_base));
_PROTOTYPE(void push_b10_const, (program_counter *pc));
_PROTOTYPE(void assign, (int c_code));
/* From util.c */
_PROTOTYPE(char *strcopyof, (char *str));
_PROTOTYPE(arg_list *nextarg, (arg_list *args, int val, int is_var));
_PROTOTYPE(char *arg_str, (arg_list *args));
_PROTOTYPE(char *call_str, (arg_list *args));
_PROTOTYPE(void free_args, (arg_list *args));
_PROTOTYPE(void check_params, (arg_list *params, arg_list *autos));
_PROTOTYPE(void init_gen, (void));
_PROTOTYPE(void generate, (char *str));
_PROTOTYPE(void run_code, (void));
_PROTOTYPE(void out_char, (int ch));
_PROTOTYPE(void out_schar, (int ch));
_PROTOTYPE(id_rec *find_id, (id_rec *tree, char *id));
_PROTOTYPE(int insert_id_rec, (id_rec **root, id_rec *new_id));
_PROTOTYPE(void init_tree, (void));
_PROTOTYPE(int lookup, (char *name, int namekind));
_PROTOTYPE(char *bc_malloc, (int));
_PROTOTYPE(void out_of_memory, (void));
_PROTOTYPE(void welcome, (void));
_PROTOTYPE(void warranty, (char *));
_PROTOTYPE(void show_bc_version, (void));
_PROTOTYPE(void limits, (void));
_PROTOTYPE(void yyerror, (char *str ,...));
_PROTOTYPE(void warn, (char *mesg ,...));
_PROTOTYPE(void rt_error, (char *mesg ,...));
_PROTOTYPE(void rt_warn, (char *mesg ,...));
/* From load.c */
_PROTOTYPE(void init_load, (void));
_PROTOTYPE(void addbyte, (int byte));
_PROTOTYPE(void def_label, (long lab));
_PROTOTYPE(long long_val, (char **str));
_PROTOTYPE(void load_code, (char *code));
/* From main.c */
_PROTOTYPE(int open_new_file, (void));
_PROTOTYPE(void new_yy_file, (FILE *file));
_PROTOTYPE(void use_quit, (int));
/* From storage.c */
_PROTOTYPE(void init_storage, (void));
_PROTOTYPE(void more_functions, (void));
_PROTOTYPE(void more_variables, (void));
_PROTOTYPE(void more_arrays, (void));
_PROTOTYPE(void clear_func, (int func ));
_PROTOTYPE(int fpop, (void));
_PROTOTYPE(void fpush, (int val ));
_PROTOTYPE(void pop, (void));
_PROTOTYPE(void push_copy, (bc_num num ));
_PROTOTYPE(void push_num, (bc_num num ));
_PROTOTYPE(char check_stack, (int depth ));
_PROTOTYPE(bc_var *get_var, (int var_name ));
_PROTOTYPE(bc_num *get_array_num, (int var_index, long index ));
_PROTOTYPE(void store_var, (int var_name ));
_PROTOTYPE(void store_array, (int var_name ));
_PROTOTYPE(void load_var, (int var_name ));
_PROTOTYPE(void load_array, (int var_name ));
_PROTOTYPE(void decr_var, (int var_name ));
_PROTOTYPE(void decr_array, (int var_name ));
_PROTOTYPE(void incr_var, (int var_name ));
_PROTOTYPE(void incr_array, (int var_name ));
_PROTOTYPE(void auto_var, (int name ));
_PROTOTYPE(void free_a_tree, (bc_array_node *root, int depth ));
_PROTOTYPE(void pop_vars, (arg_list *list ));
_PROTOTYPE(void process_params, (program_counter *pc, int func ));
/* For the scanner and parser.... */
_PROTOTYPE(int yyparse, (void));
_PROTOTYPE(int yylex, (void));
#if defined(LIBEDIT)
/* The *?*&^ prompt function */
_PROTOTYPE(char *null_prompt, (EditLine *));
#endif
/* Other things... */
#ifndef HAVE_UNISTD_H
_PROTOTYPE (int getopt, (int, char *[], CONST char *));
#endif

View File

@ -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
e-mail: philnelson@acm.org
us-mail: Philip A. Nelson
Computer Science Department, 9062
Western Washington University
@ -41,7 +43,7 @@
arg_list *a_value;
}
%token <i_value> NEWLINE AND OR NOT
%token <i_value> ENDOFLINE AND OR NOT
%token <s_value> STRING NAME NUMBER
/* '-', '+' are tokens themselves */
%token <c_value> ASSIGN_OP
@ -88,11 +90,11 @@ program : /* empty */
}
| program input_item
;
input_item : semicolon_list NEWLINE
input_item : semicolon_list ENDOFLINE
{ run_code(); }
| function
{ run_code(); }
| error NEWLINE
| error ENDOFLINE
{
yyerrok;
init_gen() ;
@ -107,8 +109,8 @@ semicolon_list : /* empty */
statement_list : /* empty */
{ $$ = 0; }
| statement
| statement_list NEWLINE
| statement_list NEWLINE statement
| statement_list ENDOFLINE
| statement_list ENDOFLINE statement
| statement_list ';'
| statement_list ';' statement
;
@ -214,7 +216,7 @@ statement : Warranty
{ $$ = 0; }
;
function : Define NAME '(' opt_parameter_list ')' '{'
NEWLINE opt_auto_define_list
ENDOFLINE opt_auto_define_list
{
check_params ($4,$8);
sprintf (genstr, "F%d,%s.%s[", lookup($2,FUNCT),
@ -225,7 +227,7 @@ function : Define NAME '(' opt_parameter_list ')' '{'
$1 = next_label;
next_label = 0;
}
statement_list NEWLINE '}'
statement_list ENDOFLINE '}'
{
generate ("0R]");
next_label = $1;
@ -242,7 +244,7 @@ parameter_list : NAME
;
opt_auto_define_list : /* empty */
{ $$ = NULL; }
| Auto define_list NEWLINE
| Auto define_list ENDOFLINE
{ $$ = $2; }
| Auto define_list ';'
{ $$ = $2; }

View File

@ -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
e-mail: philnelson@acm.org
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
{
strncpy (buf, bcel_line, max);
*result = max;
bcel_line += max;
bcel_len -= max;
}
}
#endif
#ifdef READLINE
/* Support for the readline and history libraries. This allows
nicer input on the interactive part of input. */
@ -60,15 +139,12 @@ _PROTOTYPE(int yywrap, (void));
/* Variables to help interface readline with bc. */
static char *rl_line = (char *)NULL;
static char *rl_start = (char *)NULL;
static char rl_len = 0;
static int rl_len = 0;
/* Definitions for readline access. */
extern FILE *rl_instream;
_PROTOTYPE(char *readline, (char *));
/* Needed here? */
extern FILE *yyin;
/* rl_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
rl_instream (stdin), use readline. Otherwise, just read it.
@ -94,20 +170,20 @@ rl_input (buf, result, max)
/* Do we need a new string? */
if (rl_len == 0)
{
if (rl_line)
free(rl_line);
rl_line = readline ("");
if (rl_line == NULL) {
if (rl_start)
free(rl_start);
rl_start = readline ("");
if (rl_start == NULL) {
/* end of file */
*result = 0;
rl_len = 0;
return;
}
rl_line = rl_start;
rl_len = strlen (rl_line)+1;
if (rl_len != 1)
add_history (rl_line);
rl_line[rl_len-1] = '\n';
printf ("\r");
fflush (stdout);
}
@ -121,10 +197,14 @@ rl_input (buf, result, max)
{
strncpy (buf, rl_line, max);
*result = max;
rl_line += max;
rl_len -= max;
}
}
#else
#endif
#if !defined(READLINE) && !defined(LIBEDIT)
/* MINIX returns from read with < 0 if SIGINT is encountered.
In flex, we can redefine YY_INPUT to the following. In lex, this
does nothing! */
@ -134,6 +214,7 @@ rl_input (buf, result, max)
if (errno != EINTR) \
YY_FATAL_ERROR( "read() in flex scanner failed" );
#endif
%}
DIGIT [0-9A-F]
LETTER [a-z]
@ -146,7 +227,7 @@ LETTER [a-z]
yyerror ("illegal character: #");
}
<slcomment>[^\n]* { BEGIN(INITIAL); }
<slcomment>"\n" { line_no++; BEGIN(INITIAL); return(NEWLINE); }
<slcomment>"\n" { line_no++; BEGIN(INITIAL); return(ENDOFLINE); }
define return(Define);
break return(Break);
quit return(Quit);
@ -165,8 +246,8 @@ read return(Read);
halt return(Halt);
last return(Last);
history {
#ifdef READLINE
return(History);
#if defined(READLINE) || defined(LIBEDIT)
return(HistoryVar);
#else
yylval.s_value = strcopyof(yytext); return(NAME);
#endif
@ -206,7 +287,7 @@ limits return(Limits);
}
==|\<=|\>=|\!=|"<"|">" { yylval.s_value = strcopyof(yytext); return(REL_OP); }
\+\+|-- { yylval.c_value = yytext[0]; return(INCR_DECR); }
"\n" { line_no++; return(NEWLINE); }
"\n" { line_no++; return(ENDOFLINE); }
\\\n { line_no++; /* ignore a "quoted" newline */ }
[ \t]+ { /* ignore spaces and tabs */ }
"/*" {
@ -275,7 +356,7 @@ limits return(Limits);
yyerror ("illegal character: ^%c",yytext[0] + '@');
else
if (yytext[0] > '~')
yyerror ("illegal character: \\%3d", (int) yytext[0]);
yyerror ("illegal character: \\%03o", (int) yytext[0]);
else
yyerror ("illegal character: %s",yytext);
}

View File

@ -1,7 +1,7 @@
/* storage.c: Code and data storage manipulations. This includes labels. */
/* This file is part of GNU bc.
Copyright (C) 1991, 1992, 1993, 1994, 1997 Free Software Foundation, Inc.
Copyright (C) 1991-1994, 1997, 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
e-mail: philnelson@acm.org
us-mail: Philip A. Nelson
Computer Science Department, 9062
Western Washington University
@ -56,11 +58,11 @@ init_storage ()
i_base = 10;
o_base = 10;
scale = 0;
#ifdef READLINE
n_history = -1; /* no limit. */
#if defined(READLINE) || defined(LIBEDIT)
n_history = -1;
#endif
c_code = FALSE;
init_numbers();
bc_init_numbers();
}
/* Three functions for increasing the number of functions, variables, or
@ -70,7 +72,7 @@ void
more_functions (VOID)
{
int old_count;
int indx1, indx2;
int indx;
bc_function *old_f;
bc_function *f;
char **old_names;
@ -86,19 +88,19 @@ more_functions (VOID)
f_names = (char **) bc_malloc (f_count*sizeof (char *));
/* Copy old ones. */
for (indx1 = 0; indx1 < old_count; indx1++)
for (indx = 0; indx < old_count; indx++)
{
functions[indx1] = old_f[indx1];
f_names[indx1] = old_names[indx1];
functions[indx] = old_f[indx];
f_names[indx] = old_names[indx];
}
/* Initialize the new ones. */
for (; indx1 < f_count; indx1++)
for (; indx < f_count; indx++)
{
f = &functions[indx1];
f = &functions[indx];
f->f_defined = FALSE;
for (indx2 = 0; indx2 < BC_MAX_SEGS; indx2++)
f->f_body [indx2] = NULL;
f->f_body = (char *) bc_malloc (BC_START_SIZE);
f->f_body_size = BC_START_SIZE;
f->f_code_size = 0;
f->f_label = NULL;
f->f_autos = NULL;
@ -187,26 +189,15 @@ more_arrays ()
void
clear_func (func)
char func;
int func;
{
bc_function *f;
int indx;
bc_label_group *lg;
/* Set the pointer to the function. */
f = &functions[func];
f->f_defined = FALSE;
/* Clear the code segments. */
for (indx = 0; indx < BC_MAX_SEGS; indx++)
{
if (f->f_body[indx] != NULL)
{
free (f->f_body[indx]);
f->f_body[indx] = NULL;
}
}
/* XXX restore f_body to initial size??? */
f->f_code_size = 0;
if (f->f_autos != NULL)
{
@ -242,6 +233,11 @@ fpop()
retval = temp->s_val;
free (temp);
}
else
{
retval = 0;
rt_error ("function stack underflow, contact maintainer.");
}
return (retval);
}
@ -272,7 +268,7 @@ pop ()
{
temp = ex_stack;
ex_stack = temp->s_next;
free_num (&temp->s_num);
bc_free_num (&temp->s_num);
free (temp);
}
}
@ -287,7 +283,7 @@ push_copy (num)
estack_rec *temp;
temp = (estack_rec *) bc_malloc (sizeof (estack_rec));
temp->s_num = copy_num (num);
temp->s_num = bc_copy_num (num);
temp->s_next = ex_stack;
ex_stack = temp;
}
@ -349,7 +345,7 @@ get_var (var_name)
if (var_ptr == NULL)
{
var_ptr = variables[var_name] = (bc_var *) bc_malloc (sizeof (bc_var));
init_num (&var_ptr->v_value);
bc_init_num (&var_ptr->v_value);
}
return var_ptr;
}
@ -414,7 +410,7 @@ get_array_num (var_index, index)
else
{
for (ix=0; ix < NODE_SIZE; ix++)
temp->n_items.n_num[ix] = copy_num(_zero_);
temp->n_items.n_num[ix] = bc_copy_num(_zero_);
}
a_var->a_tree = temp;
a_var->a_depth++;
@ -435,7 +431,7 @@ get_array_num (var_index, index)
temp->n_items.n_down[ix] = NULL;
else
for (ix=0; ix < NODE_SIZE; ix++)
temp->n_items.n_num[ix] = copy_num(_zero_);
temp->n_items.n_num[ix] = bc_copy_num(_zero_);
}
else
temp = temp->n_items.n_down[ix1];
@ -463,15 +459,16 @@ store_var (var_name)
var_ptr = get_var (var_name);
if (var_ptr != NULL)
{
free_num(&var_ptr->v_value);
var_ptr->v_value = copy_num (ex_stack->s_num);
bc_free_num(&var_ptr->v_value);
var_ptr->v_value = bc_copy_num (ex_stack->s_num);
}
}
else
{
/* It is a special variable... */
toobig = FALSE;
if (is_neg (ex_stack->s_num))
temp = 0;
if (bc_is_neg (ex_stack->s_num))
{
switch (var_name)
{
@ -487,7 +484,7 @@ store_var (var_name)
rt_warn ("negative scale, set to 0");
temp = 0;
break;
#ifdef READLINE
#if defined(READLINE) || defined(LIBEDIT)
case 3:
temp = -1;
break;
@ -496,8 +493,8 @@ store_var (var_name)
}
else
{
temp = num2long (ex_stack->s_num);
if (!is_zero (ex_stack->s_num) && temp == 0)
temp = bc_num2long (ex_stack->s_num);
if (!bc_is_zero (ex_stack->s_num) && temp == 0)
toobig = TRUE;
}
switch (var_name)
@ -546,21 +543,21 @@ store_var (var_name)
scale = (int) temp;
break;
#ifdef READLINE
#if defined(READLINE) || defined(LIBEDIT)
case 3:
if (toobig)
{
temp = -1;
rt_warn ("history too large, set to unlimited");
unstifle_history ();
UNLIMIT_HISTORY;
}
else
{
n_history = temp;
if (temp == -1)
unstifle_history ();
if (temp < 0)
UNLIMIT_HISTORY;
else
stifle_history (n_history);
HISTORY_SIZE(n_history);
}
#endif
}
@ -580,20 +577,20 @@ store_array (var_name)
long index;
if (!check_stack(2)) return;
index = num2long (ex_stack->s_next->s_num);
index = bc_num2long (ex_stack->s_next->s_num);
if (index < 0 || index > BC_DIM_MAX ||
(index == 0 && !is_zero(ex_stack->s_next->s_num)))
(index == 0 && !bc_is_zero(ex_stack->s_next->s_num)))
rt_error ("Array %s subscript out of bounds.", a_names[var_name]);
else
{
num_ptr = get_array_num (var_name, index);
if (num_ptr != NULL)
{
free_num (num_ptr);
*num_ptr = copy_num (ex_stack->s_num);
free_num (&ex_stack->s_next->s_num);
bc_free_num (num_ptr);
*num_ptr = bc_copy_num (ex_stack->s_num);
bc_free_num (&ex_stack->s_next->s_num);
ex_stack->s_next->s_num = ex_stack->s_num;
init_num (&ex_stack->s_num);
bc_init_num (&ex_stack->s_num);
pop();
}
}
@ -615,26 +612,26 @@ load_var (var_name)
case 0:
/* Special variable ibase. */
push_copy (_zero_);
int2num (&ex_stack->s_num, i_base);
bc_int2num (&ex_stack->s_num, i_base);
break;
case 1:
/* Special variable obase. */
push_copy (_zero_);
int2num (&ex_stack->s_num, o_base);
bc_int2num (&ex_stack->s_num, o_base);
break;
case 2:
/* Special variable scale. */
push_copy (_zero_);
int2num (&ex_stack->s_num, scale);
bc_int2num (&ex_stack->s_num, scale);
break;
#ifdef READLINE
#if defined(READLINE) || defined(LIBEDIT)
case 3:
/* Special variable history. */
push_copy (_zero_);
int2num (&ex_stack->s_num, n_history);
bc_int2num (&ex_stack->s_num, n_history);
break;
#endif
@ -660,9 +657,9 @@ load_array (var_name)
long index;
if (!check_stack(1)) return;
index = num2long (ex_stack->s_num);
index = bc_num2long (ex_stack->s_num);
if (index < 0 || index > BC_DIM_MAX ||
(index == 0 && !is_zero(ex_stack->s_num)))
(index == 0 && !bc_is_zero(ex_stack->s_num)))
rt_error ("Array %s subscript out of bounds.", a_names[var_name]);
else
{
@ -709,16 +706,16 @@ decr_var (var_name)
rt_warn ("scale can not be negative in -- ");
break;
#ifdef READLINE
#if defined(READLINE) || defined(LIBEDIT)
case 3: /* history */
n_history--;
if (n_history > 0)
stifle_history (n_history);
if (n_history >= 0)
HISTORY_SIZE(n_history);
else
{
n_history = -1;
rt_warn ("history is negative, set to unlimited");
unstifle_history ();
UNLIMIT_HISTORY;
}
#endif
@ -735,16 +732,16 @@ decr_var (var_name)
void
decr_array (var_name)
char var_name;
int var_name;
{
bc_num *num_ptr;
long index;
/* It is an array variable. */
if (!check_stack (1)) return;
index = num2long (ex_stack->s_num);
index = bc_num2long (ex_stack->s_num);
if (index < 0 || index > BC_DIM_MAX ||
(index == 0 && !is_zero (ex_stack->s_num)))
(index == 0 && !bc_is_zero (ex_stack->s_num)))
rt_error ("Array %s subscript out of bounds.", a_names[var_name]);
else
{
@ -791,16 +788,16 @@ incr_var (var_name)
rt_warn ("Scale too big in ++");
break;
#ifdef READLINE
#if defined(READLINE) || defined(LIBEDIT)
case 3: /* history */
n_history++;
if (n_history > 0)
stifle_history (n_history);
HISTORY_SIZE(n_history);
else
{
n_history = -1;
rt_warn ("history set to unlimited");
unstifle_history ();
UNLIMIT_HISTORY;
}
#endif
@ -824,9 +821,9 @@ incr_array (var_name)
long index;
if (!check_stack (1)) return;
index = num2long (ex_stack->s_num);
index = bc_num2long (ex_stack->s_num);
if (index < 0 || index > BC_DIM_MAX ||
(index == 0 && !is_zero (ex_stack->s_num)))
(index == 0 && !bc_is_zero (ex_stack->s_num)))
rt_error ("Array %s subscript out of bounds.", a_names[var_name]);
else
{
@ -858,7 +855,7 @@ auto_var (name)
ix = name;
v_temp = (bc_var *) bc_malloc (sizeof (bc_var));
v_temp->v_next = variables[ix];
init_num (&v_temp->v_value);
bc_init_num (&v_temp->v_value);
variables[ix] = v_temp;
}
else
@ -891,7 +888,7 @@ free_a_tree ( root, depth )
free_a_tree (root->n_items.n_down[ix], depth-1);
else
for (ix = 0; ix < NODE_SIZE; ix++)
free_num ( &(root->n_items.n_num[ix]));
bc_free_num ( &(root->n_items.n_num[ix]));
free (root);
}
}
@ -918,7 +915,7 @@ pop_vars (list)
if (v_temp != NULL)
{
variables[ix] = v_temp->v_next;
free_num (&v_temp->v_value);
bc_free_num (&v_temp->v_value);
free (v_temp);
}
}
@ -962,7 +959,7 @@ copy_tree (ary_node, depth)
else
for (i=0; i<NODE_SIZE; i++)
if (ary_node->n_items.n_num[i] != NULL)
res->n_items.n_num[i] = copy_num (ary_node->n_items.n_num[i]);
res->n_items.n_num[i] = bc_copy_num (ary_node->n_items.n_num[i]);
else
res->n_items.n_num[i] = NULL;
return res;
@ -1013,7 +1010,7 @@ process_params (pc, func)
v_temp = (bc_var *) bc_malloc (sizeof(bc_var));
v_temp->v_next = variables[ix];
v_temp->v_value = ex_stack->s_num;
init_num (&ex_stack->s_num);
bc_init_num (&ex_stack->s_num);
variables[ix] = v_temp;
}
else
@ -1022,7 +1019,7 @@ process_params (pc, func)
/* The variables is an array variable. */
/* Compute source index and make sure some structure exists. */
ix = (int) num2long (ex_stack->s_num);
ix = (int) bc_num2long (ex_stack->s_num);
n_temp = get_array_num (ix, 0);
/* Push a new array and Compute Destination index */

View File

@ -1,7 +1,7 @@
/* util.c: Utility routines for bc. */
/* This file is part of GNU bc.
Copyright (C) 1991, 1992, 1993, 1994, 1997 Free Software Foundation, Inc.
Copyright (C) 1991-1994, 1997, 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
e-mail: philnelson@acm.org
us-mail: Philip A. Nelson
Computer Science Department, 9062
Western Washington University
@ -308,7 +310,7 @@ run_code()
void
out_char (ch)
char ch;
int ch;
{
if (ch == '\n')
{
@ -335,7 +337,7 @@ out_char (ch)
void
out_schar (ch)
char ch;
int ch;
{
if (ch == '\n')
{
@ -620,6 +622,10 @@ lookup (name, namekind)
yyerror ("Too many variables");
exit (1);
}
yyerror ("End of util.c/lookup() reached. Please report this bug.");
exit (1);
/* not reached */
}
@ -632,6 +638,13 @@ welcome()
printf ("For details type `warranty'. \n");
}
/* Print out the version information. */
void
show_bc_version()
{
printf("%s %s\n%s\n", PACKAGE, VERSION, BC_COPYRIGHT);
}
/* Print out the warranty information. */
@ -639,19 +652,22 @@ void
warranty(prefix)
char *prefix;
{
printf ("\n%s%s\n\n", prefix, BC_VERSION);
printf ("%s%s%s%s%s%s%s%s%s%s%s",
" This program is free software; you can redistribute it and/or modify\n",
" it under the terms of the GNU General Public License as published by\n",
" the Free Software Foundation; either version 2 of the License , or\n",
" (at your option) any later version.\n\n",
" This program is distributed in the hope that it will be useful,\n",
" but WITHOUT ANY WARRANTY; without even the implied warranty of\n",
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n",
" GNU General Public License for more details.\n\n",
" You should have received a copy of the GNU General Public License\n",
" along with this program. If not, write to the Free Software\n",
" Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.\n\n");
printf ("\n%s", prefix);
show_bc_version ();
printf ("\n"
" This program is free software; you can redistribute it and/or modify\n"
" it under the terms of the GNU General Public License as published by\n"
" the Free Software Foundation; either version 2 of the License , or\n"
" (at your option) any later version.\n\n"
" This program is distributed in the hope that it will be useful,\n"
" but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
" GNU General Public License for more details.\n\n"
" You should have received a copy of the GNU General Public License\n"
" along with this program. If not, write to\n\n"
" The Free Software Foundation, Inc.\n"
" 59 Temple Place, Suite 330\n"
" Boston, MA 02111, USA.\n\n");
}
/* Print out the limits of this program. */
@ -664,8 +680,6 @@ limits()
printf ("BC_SCALE_MAX = %d\n", BC_SCALE_MAX);
printf ("BC_STRING_MAX = %d\n", BC_STRING_MAX);
printf ("MAX Exponent = %ld\n", (long) LONG_MAX);
printf ("MAX code = %ld\n", (long) BC_MAX_SEGS * (long) BC_SEG_SIZE);
printf ("multiply digits = %ld\n", (long) LONG_MAX / (long) 90);
printf ("Number of vars = %ld\n", (long) MAX_STORE);
#ifdef OLD_EQ_OP
printf ("Old assignment operatiors are valid. (=-, =+, ...)\n");
@ -808,18 +822,18 @@ rt_error (mesg, va_alist)
#endif
{
va_list args;
char error_mesg [255];
fprintf (stderr, "Runtime error (func=%s, adr=%d): ",
f_names[pc.pc_func], pc.pc_addr);
#ifndef VARARGS
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 (func=%s, adr=%d): %s\n",
f_names[pc.pc_func], pc.pc_addr, error_mesg);
fprintf (stderr, "\n");
runtime_error = TRUE;
}
@ -844,16 +858,16 @@ rt_warn (mesg, va_alist)
#endif
{
va_list args;
char error_mesg [255];
fprintf (stderr, "Runtime warning (func=%s, adr=%d): ",
f_names[pc.pc_func], pc.pc_addr);
#ifndef VARARGS
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 (func=%s, adr=%d): %s\n",
f_names[pc.pc_func], pc.pc_addr, error_mesg);
fprintf (stderr, "\n");
}

View File

@ -28,18 +28,21 @@
/* Define if lex declares yytext as a char * by default, not a char[]. */
#undef YYTEXT_POINTER
/* PACKAGE name */
#undef PACKAGE
/* VERSION number for DC target*/
#undef DC_VERSION
/* Package VERSION number */
#undef VERSION
/* COPYRIGHT notice for DC target */
#undef DC_COPYRIGHT
/* define if the math lib is to be loaded from a file. */
#undef BC_MATH_FILE
/* COPYRIGHT notice for BC target */
#undef BC_COPYRIGHT
/* Define to use the readline library. */
#undef READLINE
/* Define to use the BSD libedit library. */
#undef LIBEDIT
/* Define to `size_t' if <sys/types.h> and <stddef.h> don't define. */
#undef ptrdiff_t
@ -69,3 +72,10 @@
/* Define if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Name of package */
#undef PACKAGE
/* Version number of package */
#undef VERSION

531
contrib/bc/configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,14 @@
dnl Process this file with autoconf to produce a configure script.
AC_INIT(doc/bc.1)
AM_INIT_AUTOMAKE(bc, 1.05)
AM_INIT_AUTOMAKE("bc", "1.06")
AM_CONFIG_HEADER(config.h)
AC_DEFINE(DC_VERSION,"1.3")
AC_DEFINE_UNQUOTED(BC_COPYRIGHT, dnl
["Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc."])
AC_DEFINE_UNQUOTED(DC_COPYRIGHT, dnl
["Copyright 1994, 1997, 1998, 2000 Free Software Foundation, Inc."])
AC_PROG_CC
AC_MINIX
dnl AC_ISC_POSIX
@ -13,7 +19,6 @@ AC_PROG_INSTALL
AC_PROG_RANLIB
AC_PROG_MAKE_SET
AC_CHECK_HEADERS(stdarg.h stddef.h stdlib.h string.h limits.h unistd.h lib.h)
AC_C_CONST
AC_TYPE_SIZE_T
@ -22,53 +27,45 @@ AC_CHECK_TYPE(ptrdiff_t, size_t)
AC_FUNC_VPRINTF
AC_CHECK_FUNCS(isgraph setvbuf)
SaveCFLAGS="$CFLAGS"
CFLAGS="-g -O -I. -I$srcdir"
AC_MSG_CHECKING(if long strings are accepted by the C compiler)
AC_TRY_COMPILE([
char libmath[] =
#include "bc/libmath.h"
;
],[],AC_MSG_RESULT(yes),
AC_MSG_RESULT(no)
AC_MSG_WARN(libmath.b will not be preloaded into the executable)
if test "${prefix}" = "NONE" ; then
AC_DEFINE_UNQUOTED(BC_MATH_FILE,"/usr/local/lib/libmath.b")
else
AC_DEFINE_UNQUOTED(BC_MATH_FILE,"${prefix}/lib/libmath.b")
fi)
CFLAGS="$SaveCFLAGS"
AC_ARG_WITH(pkg,[ --with-pkg use software installed in /usr/pkg tree], [
CPPFLAGS="$CPPFLAGS -I/usr/pkg/include"
LDFLAGS="$LDFLAGS -L/usr/pkg/lib"
echo Using /usr/pkg/include and /usr/pkg/lib
])
echo $LIBS
bcrl=nA
bcle=n
AC_ARG_WITH(libedit,[ --with-libedit support fancy BSD command input
editing], [
AC_CHECK_LIB(termcap,tgetent,TERMLIB=-ltermcap)
LDSAVE=$LDFLAGS
LDFLAGS="$LDFLAGS $TERMLIB"
AC_CHECK_LIB(edit,el_gets,
[AC_CHECK_HEADER(histedit.h,
READLINELIB="-ledit $TERMLIB";bcle=y)],
READLINELIB="")
if test "$bcle" = "y"; then
echo Using the libedit library.
AC_DEFINE(LIBEDIT,1)
fi
LDFLAGS=$LDSAVE
])
bcrl=n
AC_ARG_WITH(readline,[ --with-readline support fancy command input editing], [
AC_CHECK_LIB(ncurses,tparm,TERMLIB=-lncurses,
AC_CHECK_LIB(termcap,tgetent,TERMLIB=-ltermcap))
saved_LIBS="$LIBS"
LIBS="$LIBS $TERMLIB"
AC_CHECK_LIB(termcap,tgetent,TERMLIB=-ltermcap))
LDSAVE=$LDFLAGS
LDFLAGS="$LDFLAGS $TERMLIB"
AC_CHECK_LIB(readline,readline,
[AC_CHECK_HEADER(readline/readline.h,
LIBS="$saved_LIBS -lreadline $TERMLIB";bcrl=y)],
LIBS="$saved_LIBS")
READLINELIB="-lreadline $TERMLIB";bcrl=y)],
READLINELIB="")
if test "$bcrl" = "y" ; then
echo Using the readline library.
AC_DEFINE(READLINE,1)
fi
LDFLAGS=$LDSAVE
])
echo $LIBS
dnl AC_ARG_WITH(readline,[ --with-readline support fancy command input editing], [
dnl if test "$with_readline" = "yes" ; then
dnl echo Using the readline library.
dnl AC_DEFINE(READLINE,1)
dnl LIBS="$LIBS -lreadline -ltermcap"
dnl bcrl=y
dnl else
dnl bcrl=n
dnl fi
dnl ], [
dnl bcrl=n
dnl ])
if test "$LEX" = "flex" ; then
LEX="flex -I8"
@ -78,10 +75,15 @@ else
fi
fi
if test "$bcrl" = "y" -a "$bcle" = "y" ; then
AC_MSG_ERROR(Can not use both readline and libedit. Aborting.)
fi
if test "$LEX" = "lex" -a `uname -s` = "SunOS" ; then
LEXLIB=""
echo "SunOS using lex does not have a -ll."
fi
AC_SUBST(READLINELIB)
AC_ARG_PROGRAM
AC_OUTPUT(Makefile bc/Makefile dc/Makefile doc/Makefile lib/Makefile)

View File

@ -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)

View File

@ -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)
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
install-data:
@$(NORMAL_INSTALL)
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: install-exec install-data all
@:
uninstall: uninstall-binPROGRAMS
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)

View File

@ -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. */

View File

@ -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));

View File

@ -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

View File

@ -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,

View File

@ -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

View File

@ -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);

View File

@ -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

View File

@ -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");
}

View File

@ -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;

View File

@ -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 */

View File

@ -1,8 +1,10 @@
## Process this file with automake to produce Makefile.in
info_TEXINFOS = dc.texi
info_TEXINFOS = bc.texi dc.texi
MAKEINFO = makeinfo --no-split
MAINTAINERCLEANFILES = Makefile.in
# FIXME: remove this when automake has been fixed to include these
# files automatically
EXTRA_DIST = bc.1 dc.1

View File

@ -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@
@ -61,12 +61,15 @@ CC = @CC@
LEX = @LEX@
PACKAGE = @PACKAGE@
RANLIB = @RANLIB@
READLINELIB = @READLINELIB@
VERSION = @VERSION@
YACC = @YACC@
info_TEXINFOS = dc.texi
info_TEXINFOS = bc.texi dc.texi
MAKEINFO = makeinfo --no-split
MAINTAINERCLEANFILES = Makefile.in
# FIXME: remove this when automake has been fixed to include these
# files automatically
EXTRA_DIST = bc.1 dc.1
@ -76,10 +79,9 @@ mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = ../config.h
CONFIG_CLEAN_FILES =
TEXI2DVI = texi2dvi
TEXINFO_TEX = $(srcdir)/texinfo.tex
INFO_DEPS = dc.info
DVIS = dc.dvi
TEXINFOS = dc.texi
INFO_DEPS = bc.info dc.info
DVIS = bc.dvi dc.dvi
TEXINFOS = bc.texi dc.texi
man1dir = $(mandir)/man1
MANS = $(man_MANS)
@ -90,12 +92,11 @@ DIST_COMMON = Makefile.am Makefile.in texinfo.tex
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = tar
GZIP = --best
all: Makefile $(INFO_DEPS) $(MANS)
GZIP_ENV = --best
all: all-redirect
.SUFFIXES:
.SUFFIXES: .dvi .info .ps .texi .texinfo .txi
$(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 doc/Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@ -103,6 +104,10 @@ Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
bc.info: bc.texi
bc.dvi: bc.texi
dc.info: dc.texi
dc.dvi: dc.texi
@ -115,7 +120,7 @@ DVIPS = dvips
&& $(MAKEINFO) `echo $< | sed 's,.*/,,'`
.texi.dvi:
TEXINPUTS=$(srcdir):$$TEXINPUTS \
TEXINPUTS=.:$$TEXINPUTS \
MAKEINFO='$(MAKEINFO) -I $(srcdir)' $(TEXI2DVI) $<
.texi:
@ -134,7 +139,7 @@ DVIPS = dvips
&& $(MAKEINFO) `echo $< | sed 's,.*/,,'`
.texinfo.dvi:
TEXINPUTS=$(srcdir):$$TEXINPUTS \
TEXINPUTS=.:$$TEXINPUTS \
MAKEINFO='$(MAKEINFO) -I $(srcdir)' $(TEXI2DVI) $<
.txi.info:
@ -143,7 +148,7 @@ DVIPS = dvips
&& $(MAKEINFO) `echo $< | sed 's,.*/,,'`
.txi.dvi:
TEXINPUTS=$(srcdir):$$TEXINPUTS \
TEXINPUTS=.:$$TEXINPUTS \
MAKEINFO='$(MAKEINFO) -I $(srcdir)' $(TEXI2DVI) $<
.txi:
@ -156,7 +161,8 @@ DVIPS = dvips
install-info-am: $(INFO_DEPS)
@$(NORMAL_INSTALL)
$(mkinstalldirs) $(DESTDIR)$(infodir)
@for file in $(INFO_DEPS); do \
@list='$(INFO_DEPS)'; \
for file in $$list; do \
d=$(srcdir); \
for ifile in `cd $$d && echo $$file $$file-[0-9] $$file-[0-9][0-9]`; do \
if test -f $$d/$$ifile; then \
@ -167,7 +173,8 @@ install-info-am: $(INFO_DEPS)
done
@$(POST_INSTALL)
@if $(SHELL) -c 'install-info --version | sed 1q | fgrep -s -v -i debian' >/dev/null 2>&1; then \
for file in $(INFO_DEPS); do \
list='$(INFO_DEPS)'; \
for file in $$list; do \
echo " install-info --info-dir=$(DESTDIR)$(infodir) $(DESTDIR)$(infodir)/$$file";\
install-info --info-dir=$(DESTDIR)$(infodir) $(DESTDIR)$(infodir)/$$file || :;\
done; \
@ -178,17 +185,20 @@ uninstall-info:
@if $(SHELL) -c 'install-info --version | sed 1q | fgrep -s -v -i debian' >/dev/null 2>&1; then \
ii=yes; \
else ii=; fi; \
for file in $(INFO_DEPS); do \
list='$(INFO_DEPS)'; \
for file in $$list; do \
test -z "$ii" \
|| install-info --info-dir=$(DESTDIR)$(infodir) --remove $$file; \
done
@$(NORMAL_UNINSTALL)
for file in $(INFO_DEPS); do \
list='$(INFO_DEPS)'; \
for file in $$list; do \
(cd $(DESTDIR)$(infodir) && rm -f $$file $$file-[0-9] $$file-[0-9][0-9]); \
done
dist-info: $(INFO_DEPS)
for base in $(INFO_DEPS); do \
list='$(INFO_DEPS)'; \
for base in $$list; do \
d=$(srcdir); \
for file in `cd $$d && eval echo $$base*`; do \
test -f $(distdir)/$$file \
@ -198,16 +208,18 @@ dist-info: $(INFO_DEPS)
done
mostlyclean-aminfo:
-rm -f dc.aux dc.cp dc.cps dc.dvi dc.fn dc.fns dc.ky dc.kys dc.ps \
dc.log dc.pg dc.toc dc.tp dc.tps dc.vr dc.vrs dc.op dc.tr \
dc.cv dc.cn
-rm -f bc.aux bc.cp bc.cps bc.dvi bc.fn bc.fns bc.ky bc.kys bc.ps \
bc.log bc.pg bc.toc bc.tp bc.tps bc.vr bc.vrs bc.op bc.tr \
bc.cv bc.cn dc.aux dc.cp dc.cps dc.dvi dc.fn dc.fns dc.ky \
dc.kys dc.ps dc.log dc.pg dc.toc dc.tp dc.tps dc.vr dc.vrs \
dc.op dc.tr dc.cv dc.cn
clean-aminfo:
distclean-aminfo:
maintainer-clean-aminfo:
for i in $(INFO_DEPS); do \
cd $(srcdir) && for i in $(INFO_DEPS); do \
rm -f $$i; \
if test "`echo $$i-[0-9]*`" != "$$i-[0-9]*"; then \
rm -f $$i-[0-9]*; \
@ -248,10 +260,10 @@ uninstall-man1:
done
install-man: $(MANS)
@$(NORMAL_INSTALL)
$(MAKE) install-man1
$(MAKE) $(AM_MAKEFLAGS) install-man1
uninstall-man:
@$(NORMAL_UNINSTALL)
$(MAKE) uninstall-man1
$(MAKE) $(AM_MAKEFLAGS) uninstall-man1
tags: TAGS
TAGS:
@ -263,64 +275,78 @@ subdir = doc
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
$(MAKE) top_distdir="$(top_distdir)" distdir="$(distdir)" dist-info
info: $(INFO_DEPS)
dvi: $(DVIS)
check: all
$(MAKE)
installcheck:
install-exec:
@$(NORMAL_INSTALL)
$(MAKE) $(AM_MAKEFLAGS) top_distdir="$(top_distdir)" distdir="$(distdir)" dist-info
info-am: $(INFO_DEPS)
info: info-am
dvi-am: $(DVIS)
dvi: dvi-am
check-am: all-am
check: check-am
installcheck-am:
installcheck: installcheck-am
install-exec-am:
install-exec: install-exec-am
install-data: install-info-am install-man
@$(NORMAL_INSTALL)
install: install-exec install-data all
@:
uninstall: uninstall-info uninstall-man
install-data-am: install-info-am install-man
install-data: install-data-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
install: install-am
uninstall-am: uninstall-info uninstall-man
uninstall: uninstall-am
all-am: Makefile $(INFO_DEPS) $(MANS)
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) $(DESTDIR)$(infodir) $(DESTDIR)$(mandir)/man1
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-aminfo mostlyclean-generic
mostlyclean-am: mostlyclean-aminfo mostlyclean-generic
clean: clean-aminfo clean-generic mostlyclean
mostlyclean: mostlyclean-am
distclean: distclean-aminfo distclean-generic clean
-rm -f config.status
clean-am: clean-aminfo clean-generic mostlyclean-am
maintainer-clean: maintainer-clean-aminfo maintainer-clean-generic \
distclean
clean: clean-am
distclean-am: distclean-aminfo distclean-generic clean-am
distclean: distclean-am
maintainer-clean-am: maintainer-clean-aminfo 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: install-info-am uninstall-info mostlyclean-aminfo \
distclean-aminfo clean-aminfo maintainer-clean-aminfo install-man1 \
uninstall-man1 install-man uninstall-man tags distdir info dvi \
installcheck install-exec install-data install uninstall all \
installdirs mostlyclean-generic distclean-generic clean-generic \
uninstall-man1 install-man uninstall-man 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

View File

@ -2,7 +2,7 @@
.\" bc.1 - the *roff document processor source for the bc manual
.\"
.\" This file is part of GNU bc.
.\" Copyright (C) 1991, 1992, 1993, 1994, 1997 Free Software Foundation, Inc.
.\" Copyright (C) 1991-1994, 1997, 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,24 +15,26 @@
.\" 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.
.\" 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
.\"
.\" You may contact the author by:
.\" e-mail: phil@cs.wwu.edu
.\" e-mail: philnelson@acm.org
.\" us-mail: Philip A. Nelson
.\" Computer Science Department, 9062
.\" Western Washington University
.\" Bellingham, WA 98226-9062
.\"
.\"
.TH bc 1 .\" "Command Manual" v1.04 "June 22, 1995"
.TH bc 1 .\" "Command Manual" v1.06 "Sept 12, 2000"
.SH NAME
bc - An arbitrary precision calculator language
.SH SYNTAX
\fBbc\fR [ \fB-lwsqv\fR ] [long-options] [ \fI file ...\fR ]
\fBbc\fR [ \fB-hlwsqv\fR ] [long-options] [ \fI file ...\fR ]
.SH VERSION
This man page documents GNU bc version 1.04.
This man page documents GNU bc version 1.06.
.SH DESCRIPTION
\fBbc\fR is a language that supports arbitrary precision numbers
with interactive execution of statements. There are some similarities
@ -52,25 +54,19 @@ or to be rejected. This
document describes the language accepted by this processor.
Extensions will be identified as such.
.SS OPTIONS
.IP -l
.IP "-h, --help"
Print the usage and exit.
.IP "-i, --interactive"
Force interactive mode.
.IP "-l, --mathlib"
Define the standard math library.
.IP -w
.IP "-w, --warn"
Give warnings for extensions to POSIX \fBbc\fR.
.IP -s
.IP "-s, --standard"
Process exactly the POSIX \fBbc\fR language.
.IP -q
.IP "-q, --quiet"
Do not print the normal GNU bc welcome.
.IP -v
Print the version number and copyright and quit.
.IP --mathlib
Define the standard math library.
.IP --warn
Give warnings for extensions to POSIX \fBbc\fR.
.IP --standard
Process exactly the POSIX \fBbc\fR language.
.IP --quiet
Do not print the normal GNU bc welcome.
.IP --version
.IP "-v, --version"
Print the version number and copyright and quit.
.SS NUMBERS
The most basic element in \fBbc\fR is the number. Numbers are
@ -328,8 +324,8 @@ base ten value of "obase-1". Since numbers are of arbitrary
precision, some numbers may not be printable on a single output line.
These long numbers will be split across lines using the "\e" as the
last character on a line. The maximum number of characters printed
per line is 70. Due to the interactive nature of \fBbc\fR printing
a number cause the side effect of assigning the printed value the the
per line is 70. Due to the interactive nature of \fBbc\fR, printing
a number causes the side effect of assigning the printed value to the
special variable \fBlast\fR. This allows the user to recover the
last value printed without having to retype the expression that
printed the number. Assigning to \fBlast\fR is legal and will
@ -348,7 +344,7 @@ The print statement (an extension) provides another method of output.
The "list" is a list of strings and expressions separated by commas.
Each string or expression is printed in the order of the list. No
terminating newline is printed. Expressions are evaluated and their
value is printed and assigned the the variable \fBlast\fR. Strings
value is printed and assigned to the variable \fBlast\fR. Strings
in the print statement are printed to the output and may contain
special characters. Special characters start with the backslash
character (\e). The special characters recognized by \fBbc\fR are
@ -405,7 +401,7 @@ not executed.
Return the value 0 from a function. (See the section on functions.)
.IP "\fBreturn\fR ( expression )"
Return the value of the expression from a function. (See the section on
functions.)
functions.) As an extension, the parenthesis are not required.
.SS PSEUDO STATEMENTS
These statements are not statements in the traditional sense. They are
not executed statements. Their function is performed at "compile" time.
@ -460,7 +456,7 @@ popped so that the original value (at the time of the function call)
of these variables are restored. The parameters are really auto
variables that are initialized to a value provided in the function
call. Auto variables are different than traditional local variables
in the fact that if function A calls function B, B may access function
because if function A calls function B, B may access function
A's auto variables by just using the same name, unless function B has
called them auto variables. Due to the fact that auto variables and
parameters are pushed onto a stack, \fBbc\fR supports recursive functions.
@ -481,6 +477,22 @@ constants in the function body will be converted using the value of
will be ignored during the execution of the function except for the
standard function \fBread\fR, which will always use the current value
of \fBibase\fR for conversion of numbers.
.PP
As an extension, the format of the definition has been slightly relaxed.
The standard requires the opening brace be on the same line as the
\fBdefine\fR keyword and all other parts must be on following lines.
This version of \fBbc\fR will allow any number of newlines before and
after the opening brace of the function. For example, the following
definitions are legal.
.nf
.RS
\f(CW
define d (n) { return (2*n); }
define d (n)
{ return (2*n); }
\fR
.RE
.fi
.SS MATH LIBRARY
If \fBbc\fR is invoked with the \fB-l\fR option, a math library is preloaded
and the default scale is set to 20. The math functions will calculate their
@ -594,19 +606,21 @@ define f (x) {
\fR
.RE
.fi
.SS READLINE OPTION
GNU \fBbc\fR can be compiled (via a configure option) to use the
GNU \fBreadline\fR input editor library. This allows the user
to do more editing of lines before sending them to \fBbc\fR.
It also allows for a history of previous lines typed. When this
option is selected, \fBbc\fR has one more special variable.
This special variable, \fBhistory\fR is the number of lines of
history retained. A value of -1 means that an unlimited number
of history lines are retained. This is the default value.
Setting the value of \fBhistory\fR to a positive number restricts
the number of history lines to the number given. The value of
0 disables the history feature. For more information, read the
user manuals for the GNU \fBreadline\fR and \fBhistory\fR libraries.
.SS READLINE AND LIBEDIT OPTIONS
GNU \fBbc\fR can be compiled (via a configure option) to use the GNU
\fBreadline\fR input editor library or the BSD \fBlibedit\fR library.
This allows the user to do editing of lines before sending them
to \fBbc\fR. It also allows for a history of previous lines typed.
When this option is selected, \fBbc\fR has one more special variable.
This special variable, \fBhistory\fR is the number of lines of history
retained. For \fBreadline\fR, a value of -1 means that an unlimited
number of history lines are retained. Setting the value of
\fBhistory\fR to a positive number restricts the number of history
lines to the number given. The value of 0 disables the history
feature. The default value is 100. For more information, read the
user manuals for the GNU \fBreadline\fR, \fBhistory\fR and BSD \fBlibedit\fR
libraries. One can not enable both \fBreadline\fR and \fBlibedit\fR
at the same time.
.SS DIFFERENCES
This version of
.B bc
@ -657,12 +671,17 @@ POSIX \fBbc\fR does not have a read function.
POSIX \fBbc\fR does not have a print statement .
.IP "continue statement"
POSIX \fBbc\fR does not have a continue statement.
.IP "return statement"
POSIX \fBbc\fR requires parentheses around the return expression.
.IP "array parameters"
POSIX \fBbc\fR does not (currently) support array parameters in full.
The POSIX grammar allows for arrays in function definitions, but does
not provide a method to specify an array as an actual parameter. (This
is most likely an oversight in the grammar.) Traditional implementations
of \fBbc\fR have only call by value array parameters.
.IP "function format"
POSIX \fBbc\fR requires the opening brace on the same line as the
\fBdefine\fR key word and the \fBauto\fR statement on the next line.
.IP "=+, =-, =*, =/, =%, =^"
POSIX \fBbc\fR does not require these "old style" assignment operators to
be defined. This version may allow these "old style" assignments. Use
@ -732,14 +751,6 @@ digits.
The limit on the number of characters in a string is INT_MAX characters.
.IP exponent
The value of the exponent in the raise operation (^) is limited to LONG_MAX.
.IP multiply
The multiply routine may yield incorrect results if a number
has more than LONG_MAX / 90 total digits. For 32 bit longs, this number is
23,860,929 digits.
.IP "code size"
Each function and the "main" program are limited to 16384 bytes of
compiled byte code each. This limit (BC_MAX_SEGS) can be easily changed
to have more than 16 segments of 1024 bytes.
.IP "variable names"
The current limit on the number of unique names is 32767 for each of
simple variables, arrays and functions.
@ -760,12 +771,6 @@ the user wants defined every time \fBbc\fR is run.
This should be an integer specifing the number of characters in an
output line for numbers. This includes the backslash and newline characters
for long numbers.
.SH FILES
In most installations, \fBbc\fR is completely self-contained.
Where executable size is of importance or the C compiler does
not deal with very long strings, \fBbc\fR will read
the standard math library from the file /usr/local/lib/libmath.b.
(The actual location may vary. It may be /lib/libmath.b.)
.SH DIAGNOSTICS
If any file on the command line can not be opened, \fBbc\fR will report
that the file is unavailable and terminate. Also, there are compile
@ -774,12 +779,12 @@ and run time diagnostics that should be self-explanatory.
Error recovery is not very good yet.
.PP
Email bug reports to
.BR bug-gnu-utils@prep.ai.mit.edu .
.BR bug-bc@gnu.org .
Be sure to include the word ``bc'' somewhere in the ``Subject:'' field.
.SH AUTHOR
.nf
Philip A. Nelson
phil@cs.wwu.edu
philnelson@acm.org
.fi
.SH ACKNOWLEDGEMENTS
The author would like to thank Steve Sommars (Steve.Sommars@att.com) for

1014
contrib/bc/doc/bc.texi Normal file

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@
.\" dc.1 - the *roff document processor source for the dc manual
.\"
.\" This file is part of GNU dc.
.\" 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 @@
.\" 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.
.\" 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
.\"
.TH DC 1 "1997-03-25" "GNU Project"
.ds dc \fIdc\fP
@ -24,7 +26,10 @@
.SH NAME
dc \- an arbitrary precision calculator
.SH SYNOPSIS
dc
dc [-V] [--version] [-h] [--help]
[-e scriptexpression] [--expression=scriptexpression]
[-f scriptfile] [--file=scriptfile]
[file ...]
.SH DESCRIPTION
.PP
\*(Dc is a reverse-polish desk calculator which supports
@ -52,6 +57,43 @@ as it is a binary operator for subtraction instead.
To enter two numbers in succession,
separate them with spaces or newlines.
These have no meaning as commands.
.SH OPTIONS
\*(Dc may be invoked with the following command-line options:
.TP
.B -V
.TP
.B --version
Print out the version of \*(dc that is being run and a copyright notice,
then exit.
.TP
.B -h
.TP
.B --help
Print a usage message briefly summarizing these command-line options
and the bug-reporting address,
then exit.
.TP
.B -e \fIscript\fP
.TP
.BI --expression= script
Add the commands in
.I script
to the set of commands to be run while processing the input.
.TP
.B -f \fIscript-file\fP
.TP
.BI --file= script-file
Add the commands contained in the file
.I script-file
to the set of commands to be run while processing the input.
.PP
If any command-line parameters remain after processing the above,
these parameters are interpreted as the names of input files to
be processed.
A file name of
.B -
refers to the standard input stream.
The standard input will processed if no file names are specified.
.PD
.SH
Printing Commands
@ -149,7 +191,7 @@ and any fractional part of this exponent will be ignored.
The third value popped is the base which gets exponentiated,
which should be an integer.
For small integers this is like the sequence \fBSm^Lm%\fP,
but, unlike \fB^\fP, this command will work with arbritrarily large exponents.
but, unlike \fB^\fP, this command will work with arbitrarily large exponents.
.TP
.B v
Pops one value,
@ -415,7 +457,7 @@ Miscellaneous
.TP
.B !
Will run the rest of the line as a system command.
Note that parsing of the !<, !=, and !> commands take precidence,
Note that parsing of the !<, !=, and !> commands take precedence,
so if you want to run a command starting with <, =, or > you will
need to add a space after the !.
.TP
@ -443,5 +485,4 @@ was later popped.
BUGS
.PP
Email bug reports to
.BR bug-gnu-utils@prep.ai.mit.edu .
Be sure to include the word ``dc'' somewhere in the ``Subject:'' field.
.BR bug-dc@gnu.org .

View File

@ -21,13 +21,16 @@
@syncodeindex tp fn
@ifinfo
@direntry
* dc: (dc). Arbritrary precision RPN ``Desktop Calculator''.
@end direntry
This file documents @sc{dc}, an arbitrary precision calculator.
Published by the Free Software Foundation,
675 Massachusetts Avenue,
Cambridge, MA 02139 USA
Published by the Free Software Foundation, Inc.
59 Temple Place, Suite 330
Boston, MA 02111 USA
Copyright (C) 1984, 1994, 1997, 1998 Free Software Foundation, Inc.
Copyright (C) 1984, 1994, 1997, 1998, 2000 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
@ -64,8 +67,8 @@ Copyright @copyright{} 1994, 1997, 1998 Free Software Foundation, Inc.
@sp 2
Published by the Free Software Foundation, @*
675 Massachusetts Avenue, @*
Cambridge, MA 02139 USA
59 Temple Place, Suite 330 @*
Boston, MA 02111 USA
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
@ -518,8 +521,6 @@ that was later popped.
@node Reporting bugs, , Miscellaneous, Top
@chapter Reporting bugs
Email bug reports to @code{bug-gnu-utils@@prep.ai.mit.edu}.
Be sure to include the word ``dc'' somewhere in the ``Subject:'' field.
Email bug reports to @email{bug-dc@@gnu.org}.
@contents
@bye

View File

@ -1,7 +1,6 @@
/* number.h: Arbitrary precision numbers header file. */
/* This file is part of GNU bc.
Copyright (C) 1991, 1992, 1993, 1994, 1997 Free Software Foundation, Inc.
/*
Copyright (C) 1991, 1992, 1993, 1994, 1997, 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
@ -14,11 +13,15 @@
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.
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-1307 USA.
You may contact the author by:
e-mail: phil@cs.wwu.edu
e-mail: philnelson@acm.org
us-mail: Philip A. Nelson
Computer Science Department, 9062
Western Washington University
@ -26,20 +29,29 @@
*************************************************************************/
#ifndef _NUMBER_H_
#define _NUMBER_H_
typedef enum {PLUS, MINUS} sign;
typedef struct
typedef struct bc_struct *bc_num;
typedef struct bc_struct
{
sign n_sign;
int n_len; /* The number of digits before the decimal point. */
int n_scale; /* The number of digits after the decimal point. */
int n_refs; /* The number of pointers to this number. */
char n_value[1]; /* The storage. Not zero char terminated. It is
allocated with all other fields. */
sign n_sign;
int n_len; /* The number of digits before the decimal point. */
int n_scale; /* The number of digits after the decimal point. */
int n_refs; /* The number of pointers to this number. */
bc_num n_next; /* Linked list for available list. */
char *n_ptr; /* The pointer to the actual storage.
If NULL, n_value points to the inside of
another number (bc_multiply...) and should
not be "freed." */
char *n_value; /* The number. Not zero char terminated.
May not point to the same place as n_ptr as
in the case of leading zeros generated. */
} bc_struct;
typedef bc_struct *bc_num;
/* The base used in storing the numbers in n_value above.
Currently this MUST be 10. */
@ -63,3 +75,79 @@ typedef bc_struct *bc_num;
#define TRUE 1
#define FALSE 0
#endif
#ifndef LONG_MAX
#define LONG_MAX 0x7ffffff
#endif
/* Global numbers. */
extern bc_num _zero_;
extern bc_num _one_;
extern bc_num _two_;
/* Function Prototypes */
/* Define the _PROTOTYPE macro if it is needed. */
#ifndef _PROTOTYPE
#ifdef __STDC__
#define _PROTOTYPE(func, args) func args
#else
#define _PROTOTYPE(func, args) func()
#endif
#endif
_PROTOTYPE(void bc_init_numbers, (void));
_PROTOTYPE(bc_num bc_new_num, (int length, int scale));
_PROTOTYPE(void bc_free_num, (bc_num *num));
_PROTOTYPE(bc_num bc_copy_num, (bc_num num));
_PROTOTYPE(void bc_init_num, (bc_num *num));
_PROTOTYPE(void bc_str2num, (bc_num *num, char *str, int scale));
_PROTOTYPE(char *bc_num2str, (bc_num num));
_PROTOTYPE(void bc_int2num, (bc_num *num, int val));
_PROTOTYPE(long bc_num2long, (bc_num num));
_PROTOTYPE(int bc_compare, (bc_num n1, bc_num n2));
_PROTOTYPE(char bc_is_zero, (bc_num num));
_PROTOTYPE(char bc_is_near_zero, (bc_num num, int scale));
_PROTOTYPE(char bc_is_neg, (bc_num num));
_PROTOTYPE(void bc_add, (bc_num n1, bc_num n2, bc_num *result, int scale_min));
_PROTOTYPE(void bc_sub, (bc_num n1, bc_num n2, bc_num *result, int scale_min));
_PROTOTYPE(void bc_multiply, (bc_num n1, bc_num n2, bc_num *prod, int scale));
_PROTOTYPE(int bc_divide, (bc_num n1, bc_num n2, bc_num *quot, int scale));
_PROTOTYPE(int bc_modulo, (bc_num num1, bc_num num2, bc_num *result,
int scale));
_PROTOTYPE(int bc_divmod, (bc_num num1, bc_num num2, bc_num *quot,
bc_num *rem, int scale));
_PROTOTYPE(int bc_raisemod, (bc_num base, bc_num expo, bc_num mod,
bc_num *result, int scale));
_PROTOTYPE(void bc_raise, (bc_num num1, bc_num num2, bc_num *result,
int scale));
_PROTOTYPE(int bc_sqrt, (bc_num *num, int scale));
_PROTOTYPE(void bc_out_num, (bc_num num, int o_base, void (* out_char)(int),
int leading_zero));
#endif

View File

@ -1,9 +1,26 @@
## Process this file with automake to produce Makefile.in
noinst_LIBRARIES = libbc.a
INCLUDES = -I$(srcdir) -I$(srcdir)/../h
INCLUDES = -I. -I.. -I$(srcdir)/../h
libbc_a_SOURCES = getopt.c getopt1.c vfprintf.c number.c
#libbc_LIBADD = @LIBOBJS@
#libbc_DEPENDENCIES = $(bc_LIBADD)
DEFS = @DEFS@ $(DEFSADD)
CFLAGS = @CFLAGS@ -Wall -funsigned-char
MAINTAINERCLEANFILES = Makefile.in number.c
newnumber.o: number.c muldigits.h
$(CC) $(CFLAGS) $(INCLUDES) -c -DMULDIGITS -o newnumber.o $(srcdir)/number.c
muldigits.h: testmul
@echo "The following may take up to 10 minutes."
testmul > muldigits.h
testmul: testmul.o number.o
$(CC) $(CFLAGS) -o testmul testmul.o number.o
specialnumber: newnumber.o
cp newnumber.o number.o

View File

@ -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,45 +62,49 @@ LEX = @LEX@
MAKEINFO = @MAKEINFO@
PACKAGE = @PACKAGE@
RANLIB = @RANLIB@
READLINELIB = @READLINELIB@
VERSION = @VERSION@
YACC = @YACC@
noinst_LIBRARIES = libbc.a
INCLUDES = -I$(srcdir) -I$(srcdir)/../h
INCLUDES = -I. -I.. -I$(srcdir)/../h
libbc_a_SOURCES = getopt.c getopt1.c vfprintf.c number.c
DEFS = @DEFS@ $(DEFSADD)
CFLAGS = @CFLAGS@ -Wall -funsigned-char
MAINTAINERCLEANFILES = Makefile.in number.c
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = ../config.h
CONFIG_CLEAN_FILES =
LIBRARIES = $(noinst_LIBRARIES)
DEFS = @DEFS@ -I. -I$(srcdir) -I..
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
libbc_a_LIBADD =
libbc_a_OBJECTS = getopt.o getopt1.o vfprintf.o number.o
AR = ar
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 $@
DIST_COMMON = Makefile.am Makefile.in
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = tar
GZIP = --best
GZIP_ENV = --best
SOURCES = $(libbc_a_SOURCES)
OBJECTS = $(libbc_a_OBJECTS)
all: Makefile $(LIBRARIES)
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 lib/Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@ -144,8 +148,12 @@ libbc.a: $(libbc_a_OBJECTS) $(libbc_a_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=; \
@ -173,73 +181,102 @@ subdir = lib
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:
@$(NORMAL_INSTALL)
getopt.o: getopt.c ../config.h ../h/getopt.h
getopt1.o: getopt1.c ../config.h ../h/getopt.h
number.o: number.c ../config.h ../h/number.h
vfprintf.o: vfprintf.c ../config.h
install-data:
@$(NORMAL_INSTALL)
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-exec: install-exec-am
install: install-exec install-data all
@:
uninstall:
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: uninstall-am
all-am: Makefile $(LIBRARIES)
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:
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-noinstLIBRARIES mostlyclean-compile \
mostlyclean-am: mostlyclean-noinstLIBRARIES mostlyclean-compile \
mostlyclean-tags mostlyclean-generic
clean: clean-noinstLIBRARIES clean-compile clean-tags clean-generic \
mostlyclean
mostlyclean: mostlyclean-am
distclean: distclean-noinstLIBRARIES distclean-compile distclean-tags \
distclean-generic clean
-rm -f config.status
clean-am: clean-noinstLIBRARIES clean-compile clean-tags clean-generic \
mostlyclean-am
maintainer-clean: maintainer-clean-noinstLIBRARIES \
clean: clean-am
distclean-am: distclean-noinstLIBRARIES distclean-compile \
distclean-tags distclean-generic clean-am
distclean: distclean-am
maintainer-clean-am: maintainer-clean-noinstLIBRARIES \
maintainer-clean-compile maintainer-clean-tags \
maintainer-clean-generic distclean
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-noinstLIBRARIES distclean-noinstLIBRARIES \
clean-noinstLIBRARIES maintainer-clean-noinstLIBRARIES \
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
#libbc_LIBADD = @LIBOBJS@
#libbc_DEPENDENCIES = $(bc_LIBADD)
newnumber.o: number.c muldigits.h
$(CC) $(CFLAGS) $(INCLUDES) -c -DMULDIGITS -o newnumber.o $(srcdir)/number.c
muldigits.h: testmul
@echo "The following may take up to 10 minutes."
testmul > muldigits.h
testmul: testmul.o number.o
$(CC) $(CFLAGS) -o testmul testmul.o number.o
specialnumber: newnumber.o
cp newnumber.o number.o
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.

File diff suppressed because it is too large Load Diff

244
contrib/bc/lib/testmul.c Normal file
View File

@ -0,0 +1,244 @@
/* compute the crossover for recursive and simple multiplication */
#include <stdio.h>
#include <time.h>
#include "number.h"
#ifndef VARARGS
#include <stdarg.h>
#else
#include <varargs.h>
#endif
/* from number.c ... */
extern int mul_base_digits;
/* extern int mul_small_digits; */
extern bc_num _one_;
/* global variables */
int test_n = 1000;
int test_time = 30 * CLOCKS_PER_SEC; /* 30 seconds */
/* Other things for number.c. */
int std_only;
void
out_of_memory()
{
fprintf (stderr, "Fatal error: Out of memory for malloc.\n");
exit (1);
}
/* Runtime error will print a message and stop the machine. */
#ifndef VARARGS
#ifdef __STDC__
void
rt_error (char *mesg, ...)
#else
void
rt_error (mesg)
char *mesg;
#endif
#else
void
rt_error (mesg, va_alist)
char *mesg;
#endif
{
va_list args;
char error_mesg [255];
#ifndef VARARGS
va_start (args, mesg);
#else
va_start (args);
#endif
vsprintf (error_mesg, mesg, args);
va_end (args);
fprintf (stderr, "Runtime error: %s\n", error_mesg);
}
/* A runtime warning tells of some action taken by the processor that
may change the program execution but was not enough of a problem
to stop the execution. */
#ifndef VARARGS
#ifdef __STDC__
void
rt_warn (char *mesg, ...)
#else
void
rt_warn (mesg)
char *mesg;
#endif
#else
void
rt_warn (mesg, va_alist)
char *mesg;
#endif
{
va_list args;
char error_mesg [255];
#ifndef VARARGS
va_start (args, mesg);
#else
va_start (args);
#endif
vsprintf (error_mesg, mesg, args);
va_end (args);
fprintf (stderr, "Runtime warning: %s\n", error_mesg);
}
void
out_char (int ch)
{
putchar (ch);
}
/* Time stuff !!! */
int
timeit ( bc_num a, bc_num b, int *n)
{
clock_t first;
int i, res;
bc_num c;
bc_init_num (&c);
first = clock();
*n = 0;
do {
for (i=0; i<test_n; i++)
bc_multiply(a,b,&c,0);
*n += test_n;
res = (int) (clock() - first);
} while (res < test_time);
return res;
}
int debug = 0; /* Print debugging messages? */
int main (int argc, char **argv)
{
bc_num ten, num, expo, big;
int min, max, mid;
#if 0
int smallsize;
#endif
int n1, n2;
clock_t t1, t2;
float permul1, permul2;
/* args? */
if (argc > 1)
if (strcmp (argv[1], "-d") == 0)
debug = 1;
bc_init_numbers();
bc_init_num (&ten);
bc_init_num (&num);
bc_init_num (&expo);
bc_init_num (&big);
bc_int2num (&ten, 10);
if (debug)
fprintf (stderr, "Timings are for %d multiplies\n"
"Minimum time is %d seconds\n", test_n,
test_time/CLOCKS_PER_SEC);
/* Two of the same size */
min = 10;
max = 500;
if (debug)
fprintf (stderr, "Testing numbers of the same length.\n");
while (min < max) {
mid = (min+max)/2;
if (debug) fprintf (stderr,"Checking %d...\n", mid);
bc_int2num (&expo, mid);
bc_raise (ten, expo, &num, 0);
bc_sub (num, _one_, &num, 0);
mul_base_digits = 2*mid+1;
t1 = timeit (num, num, &n1);
permul1 = (float)t1/(float)n1;
mul_base_digits = 2*mid-1;
t2 = timeit (num, num, &n2);
permul2 = (float)t2/(float)n2;
if (permul1 < permul2)
min = mid+1;
else
max = mid-1;
if (debug) {
fprintf (stderr, "n1 = %d :: n2 = %d\n", n1, n2);
fprintf (stderr, "p1 = %f :: p2 = %f\n", permul1, permul2);
}
}
if (debug)
fprintf (stderr, "Base digits crossover at %d digits\n", min);
printf ("#define MUL_BASE_DIGITS %d\n", 2*min);
#if 0
mul_base_digits = min;
/* Small one times a big one. */
smallsize = min/2;
bc_int2num (&expo, smallsize);
bc_raise (ten, expo, &big, 0);
bc_sub (num, _one_, &big, 0);
min = min / 2;
max = 500;
if (debug)
fprintf (stderr, "Testing numbers of the different length.\n");
while (min < max) {
mid = (min+max)/2;
if (debug) fprintf (stderr, "Checking %d...\n", mid);
bc_int2num (&expo, mid-smallsize);
bc_raise (ten, expo, &num, 0);
bc_sub (num, _one_, &num, 0);
mul_small_digits = mid+1;
t1 = timeit (big, num, &n1);
permul1 = (float)t1/(float)n1;
mul_small_digits = mid-1;
t2 = timeit (big, num, &n2);
permul2 = (float)t2/(float)n2;
if (permul1 < permul2)
min = mid+1;
else
max = mid-1;
if (debug) {
fprintf (stderr, "n1 = %d :: n2 = %d\n", n1, n2);
fprintf (stderr, "p1 = %f :: p2 = %f\n", permul1, permul2);
}
}
if (debug)
fprintf (stderr, "Non equal digits crossover at %d total digits\n", min);
printf ("#define MUL_SMALL_DIGITS = %d\n", min);
#endif
return 0;
}

View File

@ -4,7 +4,7 @@
#include "config.h"
#ifndef HAVE_VPRINTF
#ifndef HAVE_DOPRINT
# error need vfprintf() or doprint()
#error need vfprintf() or doprint()
#else
#ifdef HAVE_LIB_H