home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / unix / volume26 / calc / part06 < prev    next >
Encoding:
Text File  |  1992-05-09  |  52.7 KB  |  1,686 lines

  1. Newsgroups: comp.sources.unix
  2. From: dbell@pdact.pd.necisa.oz.au (David I. Bell)
  3. Subject: v26i032: CALC - An arbitrary precision C-like calculator, Part06/21
  4. Sender: unix-sources-moderator@pa.dec.com
  5. Approved: vixie@pa.dec.com
  6.  
  7. Submitted-By: dbell@pdact.pd.necisa.oz.au (David I. Bell)
  8. Posting-Number: Volume 26, Issue 32
  9. Archive-Name: calc/part06
  10.  
  11. #! /bin/sh
  12. # This is a shell archive.  Remove anything before this line, then unpack
  13. # it by saving it into a file and typing "sh file".  To overwrite existing
  14. # files, type "sh file -c".  You can also feed this as standard input via
  15. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  16. # will see the following message at the end:
  17. #        "End of archive 6 (of 21)."
  18. # Contents:  Makefile calc.h help/builtin token.c
  19. # Wrapped by dbell@elm on Tue Feb 25 15:21:01 1992
  20. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  21. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  22.   echo shar: Will not clobber existing file \"'Makefile'\"
  23. else
  24. echo shar: Extracting \"'Makefile'\" \(13308 characters\)
  25. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  26. X#
  27. X# Copyright (c) 1992 David I. Bell and Landon Curt Noll
  28. X# Permission is granted to use, distribute, or modify this source,
  29. X# provided that this copyright notice remains intact.
  30. X#
  31. X# Arbitrary precision calculator.
  32. X#
  33. X# calculator by David I. Bell
  34. X# makefile by Landon Curt Noll
  35. X
  36. X##############################################################################
  37. X#-=-=-=-=-=-=-=-=- You may want to change some values below -=-=-=-=-=-=-=-=-#
  38. X##############################################################################
  39. X
  40. X# Determine the type of varargs that you want to use
  41. X#
  42. X#    VARARG value      meaning
  43. X#    ------------      -------
  44. X#    (nothing)      let the makefile guess at what you need
  45. X#    STDARG              you have ANSI C and /usr/include/stdarg.h
  46. X#    VARARGS              you have /usr/include/varargs.h
  47. X#    SIMULATE_STDARG   use simulated ./stdarg.h
  48. X#
  49. X# Try defining VARARG to be nothing.  The makefile will look for the
  50. X# needed .h files, trying for stdarg.h first.
  51. X#
  52. XVARARG=
  53. X#VARARG= STDARG
  54. X#VARARG= VARARGS
  55. X#VARARG= SIMULATE_STDARG
  56. X
  57. X# If your system does not have a vsprintf() function, you could be in trouble.
  58. X#
  59. X#    vsprintf(stream, format, ap)
  60. X#
  61. X# This function works like sprintf except that the 3rd arg is a va_list
  62. X# strarg (or varargs) list.
  63. X#
  64. X# If you have vsprintf, then define VSPRINTF to be an empty string.
  65. X# Some old BSD systems do not have vsprintf().  If you do not have vsprintf()
  66. X# then define VSPRINTF to be -DVSPRINTF and hope for the best.
  67. X#
  68. XVSPRINTF=
  69. X#VSPRINTF= -DVSPRINTF
  70. X
  71. X# Determine the byte order of your machine
  72. X#
  73. X#    Big Endian:    -DBIG_ENDIAN        Amdahl, 68000, Pyramid, Mips, ...
  74. X#    Little Endian:    -DLITTLE_ENDIAN        Vax, 32000, 386, 486, ...
  75. X#
  76. XENDIAN= -DBIG_ENDIAN
  77. X#ENDIAN= -DLITTLE_ENDIAN
  78. X
  79. X# Determine whether to use the standard UNIX malloc or the alternative one
  80. X# included with the calculator.  On some machines, the alternative malloc
  81. X# may be faster.  It also can help to debug malloc problems.  Define
  82. X# -DUNIX_MALLOC to use the standard UNIX malloc routines.
  83. X#
  84. X# If in doubt, use the MALLOC= -DUNIX_MALLOC line.
  85. X#
  86. XMALLOC= -DUNIX_MALLOC
  87. X#MALLOC=
  88. X
  89. X# where to install binary files
  90. X#
  91. XBINDIR= /usr/local/bin
  92. X
  93. X# where to install the lib/*.calc files
  94. X#
  95. XLIBDIR= /usr/local/lib/calc
  96. X
  97. X# where to install help files
  98. X#
  99. X# The ${LIBDIR}/help is where the help files will be installed.
  100. X#
  101. XHELPDIR= ${LIBDIR}/help
  102. X
  103. X# where man pages are installed
  104. X#
  105. XMANDIR=/usr/local/man/man1
  106. X#MANDIR=/usr/man/man1
  107. X#MANDIR=/usr/share/man/man1
  108. X#MANDIR=/usr/man/u_man/man1
  109. X
  110. X# If the $CALCPATH environment variable is not defined, then the following
  111. X# path will be search for calc lib routines.
  112. X#
  113. XCALCPATH= .:./lib:~/lib:${LIBDIR}
  114. X
  115. X# If the $CALCRC environment variable is not defined, then the following
  116. X# path will be search for calc lib routines.
  117. X#
  118. XCALCRC= ${LIBDIR}/startup:~/.calcrc
  119. X
  120. X# If $PAGER is not set, use this program to display a help file
  121. X#
  122. X#CALCPAGER= less
  123. XCALCPAGER= more
  124. X#CALCPAGER= pg
  125. X#CALCPAGER= cat
  126. X
  127. X# Compile debug options
  128. X#
  129. X# Select -O, or empty string, if you don't want to debug
  130. XDEBUG= -O
  131. X#DEBUG= -g
  132. X#DEBUG= -gx
  133. X#DEBUG= -WM,-g
  134. X#DEBUG=
  135. X
  136. X# On systems that have dynamic shared libs, you want want to disable them
  137. X# for faster calc startup.
  138. X#
  139. XNO_SHARED=
  140. X#NO_SHARED= -dn
  141. X
  142. X# Some systems (System V based mostly) allow 'mkdir -p' to make a directory
  143. X# and any needed parent directories.  If you system has 'mkdir -p', then
  144. X# leave the definition below, otherwise define MKDIR to be just 'mkdir'
  145. X# or simply ensure that ${LIBDIR}, ${BINDIR} and ${HELPDIR} exist before
  146. X# you do an install.
  147. X#
  148. XMKDIR=mkdir -p
  149. X#MKDIR=mkdir
  150. X
  151. X# If you are running an an classic BSD system, then you may not have
  152. X# the following functions:
  153. X#
  154. X#    memcpy()    strchr()    memset()
  155. X#
  156. X# If you do not have these functions, define OLD_BSD to be -DOLD_BSD,
  157. X# otherwise define OLD_BSD to be an empty string.
  158. X#
  159. X# BSD-like systems such an SunOS 4.x have these functions and thus don't 
  160. X# need OLD_BSD.  If you don't know, try using the empty string and if
  161. X# you get complaints, try -DOLD_BSD.
  162. X#
  163. X#OLD_BSD= -DOLD_BSD
  164. XOLD_BSD=
  165. X
  166. X##############################################################################
  167. X#-=-=-=-=-=-=-=-=- Be careful if you change something below -=-=-=-=-=-=-=-=-#
  168. X##############################################################################
  169. X
  170. X# standard utilities used during make
  171. X#
  172. XSHELL= /bin/sh
  173. XMAKE= make
  174. XLINT= lint
  175. XCC= cc
  176. XCTAGS= ctags
  177. X
  178. X# -b: ignore break; that are not reachable
  179. X# -s: print lint problems one per line
  180. X# -F: produce full path names for files
  181. X#
  182. XLINTFLAGS= -b -s -F
  183. X#LINTFLAGS=
  184. X
  185. X# the calc source files
  186. X#
  187. XCALCSRC= addop.c alloc.c calc.c codegen.c comfunc.c commath.c config.c \
  188. X    const.c file.c func.c input.c io.c label.c listfunc.c matfunc.c obj.c \
  189. X    opcodes.c qfunc.c qmath.c qmod.c qtrans.c string.c symbol.c token.c \
  190. X    value.c version.c zfunc.c zmath.c zmod.c zmul.c
  191. X
  192. X# we build these .o files for calc
  193. X#
  194. XCALCOBJS= addop.o alloc.o calc.o codegen.o comfunc.o commath.o config.o \
  195. X    const.o file.o func.o input.o io.o label.o listfunc.o matfunc.o obj.o \
  196. X    opcodes.o qfunc.o qmath.o qmod.o qtrans.o string.o symbol.o token.o \
  197. X    value.o version.o zfunc.o zmath.o zmod.o zmul.o
  198. X
  199. X# we build these .h files during the make
  200. X#
  201. XBUILD_H_SRC= config.h have_malloc.h have_stdlib.h have_string.h args.h
  202. X
  203. X# The code program is not part of the calc distribution, don't worry
  204. X# if you do not have it.
  205. X#
  206. XCODEOBJS= code.o io_code.o qfunc.o qmath_code.o zfunc.o zmath.o zmul.o zmod.o
  207. X
  208. X# we build these .c files during the make
  209. X#
  210. XBUILD_CODE_SRC= io_code.c qmath_code.c
  211. X
  212. XCFLAGS= ${DEBUG} ${MALLOC} ${ENDIAN} ${OLD_BSD} ${VSPRINTF}
  213. X
  214. Xall: calc
  215. X
  216. Xcalc: ${CALCOBJS}
  217. X    ${CC} ${CFLAGS} ${CALCOBJS} -o calc ${NO_SHARED}
  218. X
  219. Xconfig.h: Makefile
  220. X    rm -f config.h
  221. X    @echo '    forming config.h'
  222. X    @echo '/*' > config.h
  223. X    @echo ' * DO NOT EDIT -- generated by the Makefile' >> config.h
  224. X    @echo ' */' >> config.h
  225. X    @echo '' >> config.h
  226. X    @echo '/* the default :-separated search path */' >> config.h
  227. X    @echo '#ifndef DEFAULTCALCPATH' >> config.h
  228. X    @echo '#define DEFAULTCALCPATH "${CALCPATH}"' >> config.h
  229. X    @echo '#endif /* DEFAULTCALCPATH */' >> config.h
  230. X    @echo '' >> config.h
  231. X    @echo '/* the default :-separated startup file list */' >> config.h
  232. X    @echo '#ifndef DEFAULTCALCRC' >> config.h
  233. X    @echo '#define DEFAULTCALCRC "${CALCRC}"' >> config.h
  234. X    @echo '#endif /* DEFAULTCALCRC */' >> config.h
  235. X    @echo '' >> config.h
  236. X    @echo '/* the location of the help directory */' >> config.h
  237. X    @echo '#ifndef HELPDIR' >> config.h
  238. X    @echo '#define HELPDIR "${HELPDIR}"' >> config.h
  239. X    @echo '#endif /* HELPDIR */' >> config.h
  240. X    @echo '' >> config.h
  241. X    @echo '/* the default pager to use */' >> config.h
  242. X    @echo '#ifndef DEFAULTCALCPAGER' >> config.h
  243. X    @echo '#define DEFAULTCALCPAGER "${CALCPAGER}"' >> config.h
  244. X    @echo '#endif /* DEFAULTCALCPAGER */' >> config.h
  245. X    @echo '    config.h formed'
  246. X
  247. Xhave_malloc.h: Makefile
  248. X    rm -f have_malloc.h
  249. X    @echo '    forming have_malloc.h'
  250. X    @echo '/*' > have_malloc.h
  251. X    @echo ' * DO NOT EDIT -- generated by the Makefile' >> have_malloc.h
  252. X    @echo ' */' >> have_malloc.h
  253. X    @echo '' >> have_malloc.h
  254. X    @echo '/* do we have /usr/include/malloc.h? */' > have_malloc.h
  255. X    -@if [ -r /usr/include/malloc.h ]; then \
  256. X        echo '#define HAVE_MALLOC_H  /* yes */' >> have_malloc.h; \
  257. X    else \
  258. X        echo '#undef HAVE_MALLOC_H   /* no */' >> have_malloc.h; \
  259. X    fi
  260. X    @echo '    have_malloc.h formed'
  261. X
  262. Xhave_stdlib.h: Makefile
  263. X    rm -f have_stdlib.h
  264. X    @echo '    forming have_stdlib.h'
  265. X    @echo '/*' > have_stdlib.h
  266. X    @echo ' * DO NOT EDIT -- generated by the Makefile' >> have_stdlib.h
  267. X    @echo ' */' >> have_stdlib.h
  268. X    @echo '' >> have_stdlib.h
  269. X    @echo '/* do we have /usr/include/stdlib.h? */' > have_stdlib.h
  270. X    -@if [ -r /usr/include/stdlib.h ]; then \
  271. X        echo '#define HAVE_STDLIB_H  /* yes */' >> have_stdlib.h; \
  272. X    else \
  273. X        echo '#undef HAVE_STDLIB_H   /* no */' >> have_stdlib.h; \
  274. X    fi
  275. X    @echo '    have_stdlib.h formed'
  276. X
  277. Xhave_string.h: Makefile
  278. X    rm -f have_string.h
  279. X    @echo '    forming have_string.h'
  280. X    @echo '/*' > have_string.h
  281. X    @echo ' * DO NOT EDIT -- generated by the Makefile' >> have_string.h
  282. X    @echo ' */' >> have_string.h
  283. X    @echo '' >> have_string.h
  284. X    @echo '/* do we have /usr/include/string.h? */' > have_string.h
  285. X    -@if [ -r /usr/include/string.h ]; then \
  286. X        echo '#define HAVE_STRING_H  /* yes */' >> have_string.h; \
  287. X    else \
  288. X        echo '#undef HAVE_STRING_H   /* no */' >> have_string.h; \
  289. X    fi
  290. X    @echo '    have_string.h formed'
  291. X
  292. Xargs.h: Makefile
  293. X    rm -f args.h
  294. X    @echo '    forming args.h'
  295. X    @echo '/*' > args.h
  296. X    @echo ' * DO NOT EDIT -- generated by the Makefile' >> args.h
  297. X    @echo ' */' >> args.h
  298. X    @echo '' >> args.h
  299. X    @echo '/* what sort of variable args do we have? */' > args.h
  300. X    -@if [ ! -z "${VARARG}" ]; then \
  301. X        echo '#define ${VARARG}' >> args.h; \
  302. X    elif [ -r /usr/include/stdarg.h ]; then \
  303. X        echo '#define STDARG' >> args.h; \
  304. X    elif [ -r /usr/include/varargs.h ]; then \
  305. X        echo '#define VARARGS' >> args.h; \
  306. X    else \
  307. X        echo '#define SIMULATE_STDARG' >> args.h; \
  308. X    fi
  309. X    @echo '    args.h formed'
  310. X
  311. Xhelp/full: help/Makefile
  312. X    cd help; ${MAKE} -f Makefile HELPDIR=${HELPDIR} full
  313. X
  314. Xlint: ${BUILD_H_SRC} ${CALCSRC} lint.sed
  315. X    ${LINT} ${LINTFLAGS} ${CFLAGS} ${CALCSRC} | sed -f lint.sed
  316. X
  317. Xtags: ${CALCSRC}
  318. X    ${CTAGS} ${CALCSRC}
  319. X
  320. Xclean:
  321. X    rm -f ${CALCOBJS} ${CODEOBJS}
  322. X    cd help; ${MAKE} -f Makefile clean
  323. X
  324. Xclobber:
  325. X    rm -f ${CALCOBJS} ${CODEOBJS}
  326. X    rm -f tags calc code ${BUILD_CODE_SRC}
  327. X    rm -f ${BUILD_H_SRC}
  328. X    cd help; ${MAKE} -f Makefile clobber
  329. X
  330. Xinstall: all calc.1
  331. X    -@if [ ! -d ${LIBDIR} ]; then \
  332. X        echo "    ${MKDIR} ${LIBDIR}"; \
  333. X        ${MKDIR} ${LIBDIR}; \
  334. X    fi
  335. X    -@if [ ! -d ${HELPDIR} ]; then \
  336. X        echo "    ${MKDIR} ${HELPDIR}"; \
  337. X        ${MKDIR} ${HELPDIR}; \
  338. X    fi
  339. X    -@if [ ! -d ${BINDIR} ]; then \
  340. X        echo "    ${MKDIR} ${BINDIR}"; \
  341. X        ${MKDIR} ${BINDIR}; \
  342. X    fi
  343. X    chmod 0755 calc
  344. X    cp calc ${BINDIR}
  345. X    cd help; ${MAKE} -f Makefile HELPDIR=${HELPDIR} install
  346. X    cd lib; ${MAKE} -f Makefile LIBDIR=${LIBDIR} install
  347. X    -chmod 0444 calc.1
  348. X    -cp calc.1 ${MANDIR}
  349. X    @# The code program is not part of the calc distribution, don't worry
  350. X    @# if you do not have it.
  351. X    -@if [ -f code ]; then \
  352. X        echo "    chmod +x code"; \
  353. X        chmod +x code; \
  354. X        echo "    cp code ${BINDIR}"; \
  355. X        cp code ${BINDIR}; \
  356. X    fi
  357. X
  358. X# The code program is not part of the calc distribution, don't worry
  359. X# if you do not have it.
  360. X#
  361. Xcode: ${CODEOBJS}
  362. X    ${CC} ${CFLAGS} ${CODEOBJS} -o code ${NO_SHARED}
  363. Xio_code.o: calc.h math.h alloc.h have_string.h have_stdlib.h have_malloc.h \
  364. X    func.h opcodes.h config.h token.h symbol.h io_code.c
  365. X    ${CC} ${CFLAGS} -DCODE io_code.c -c
  366. Xqmath_code.o: calc.h math.h alloc.h have_string.h have_stdlib.h have_malloc.h \
  367. X    func.h opcodes.h config.h token.h symbol.h qmath_code.c
  368. X    ${CC} ${CFLAGS} -DCODE qmath_code.c -c
  369. Xio_code.c: io.c
  370. X    rm -f io_code.c
  371. X    cp io.c io_code.c
  372. Xqmath_code.c: qmath.c
  373. X    rm -f qmath_code.c
  374. X    cp qmath.c qmath_code.c
  375. Xcode.o: stdarg.h args.h math.h have_malloc.h Makefile
  376. X    ${CC} ${CFLAGS} -DCODE code.c -c
  377. X
  378. X# make depend stuff
  379. X#
  380. Xaddop.o: calc.h math.h alloc.h have_string.h have_stdlib.h \
  381. X    have_malloc.h opcodes.h string.h func.h token.h label.h symbol.h
  382. Xalloc.o: alloc.h have_string.h have_stdlib.h
  383. Xcalc.o: calc.h math.h alloc.h have_string.h have_stdlib.h \
  384. X    have_malloc.h func.h opcodes.h config.h token.h symbol.h
  385. Xcodegen.o: calc.h math.h alloc.h have_string.h have_stdlib.h \
  386. X    have_malloc.h token.h symbol.h label.h opcodes.h string.h \
  387. X    func.h config.h
  388. Xcomfunc.o: calc.h math.h alloc.h have_string.h have_stdlib.h \
  389. X    have_malloc.h
  390. Xcommath.o: math.h alloc.h have_string.h have_stdlib.h have_malloc.h
  391. Xconfig.o: calc.h math.h alloc.h have_string.h have_stdlib.h \
  392. X    have_malloc.h
  393. Xconst.o: calc.h math.h alloc.h have_string.h have_stdlib.h have_malloc.h
  394. Xfile.o: stdarg.h args.h calc.h math.h alloc.h have_string.h have_stdlib.h \
  395. X    have_malloc.h have_string.h
  396. Xfunc.o: calc.h math.h alloc.h have_string.h have_stdlib.h \
  397. X    have_malloc.h opcodes.h token.h func.h string.h
  398. Xinput.o: calc.h math.h alloc.h have_string.h have_stdlib.h \
  399. X    have_malloc.h config.h func.h
  400. Xio.o: stdarg.h args.h math.h alloc.h have_string.h have_stdlib.h \
  401. X    have_malloc.h Makefile
  402. Xlabel.o: calc.h math.h alloc.h have_string.h have_stdlib.h \
  403. X    have_malloc.h token.h label.h string.h opcodes.h func.h
  404. Xlistfunc.o: calc.h math.h alloc.h have_string.h have_stdlib.h \
  405. X    have_malloc.h
  406. Xmatfunc.o: calc.h math.h alloc.h have_string.h have_stdlib.h \
  407. X    have_malloc.h
  408. Xobj.o: calc.h math.h alloc.h have_string.h have_stdlib.h have_malloc.h \
  409. X    opcodes.h func.h symbol.h string.h
  410. Xopcodes.o: stdarg.h args.h calc.h math.h alloc.h have_string.h have_stdlib.h \
  411. X    have_malloc.h have_string.h opcodes.h func.h symbol.h Makefile
  412. Xqfunc.o: math.h alloc.h have_string.h have_stdlib.h have_malloc.h
  413. Xqmath.o: math.h alloc.h have_string.h have_stdlib.h have_malloc.h
  414. Xqmod.o: math.h alloc.h have_string.h have_stdlib.h have_malloc.h
  415. Xqtrans.o: math.h alloc.h have_string.h have_stdlib.h have_malloc.h
  416. Xstring.o: calc.h math.h alloc.h have_string.h have_stdlib.h \
  417. X    have_malloc.h string.h
  418. Xsymbol.o: calc.h math.h alloc.h have_string.h have_stdlib.h \
  419. X    have_malloc.h token.h symbol.h string.h opcodes.h func.h
  420. Xtoken.o: stdarg.h args.h calc.h math.h alloc.h have_string.h have_stdlib.h \
  421. X    have_malloc.h have_string.h token.h string.h Makefile
  422. Xvalue.o: calc.h math.h alloc.h have_string.h have_stdlib.h \
  423. X    have_malloc.h opcodes.h func.h symbol.h
  424. Xzfunc.o: math.h alloc.h have_string.h have_stdlib.h have_malloc.h
  425. Xzmath.o: math.h alloc.h have_string.h have_stdlib.h have_malloc.h
  426. Xzmod.o: math.h alloc.h have_string.h have_stdlib.h have_malloc.h
  427. Xzmul.o: math.h alloc.h have_string.h have_stdlib.h have_malloc.h
  428. END_OF_FILE
  429. if test 13308 -ne `wc -c <'Makefile'`; then
  430.     echo shar: \"'Makefile'\" unpacked with wrong size!
  431. fi
  432. # end of 'Makefile'
  433. fi
  434. if test -f 'calc.h' -a "${1}" != "-c" ; then 
  435.   echo shar: Will not clobber existing file \"'calc.h'\"
  436. else
  437. echo shar: Extracting \"'calc.h'\" \(11561 characters\)
  438. sed "s/^X//" >'calc.h' <<'END_OF_FILE'
  439. X/*
  440. X * Copyright (c) 1992 David I. Bell
  441. X * Permission is granted to use, distribute, or modify this source,
  442. X * provided that this copyright notice remains intact.
  443. X *
  444. X * Definitions for calculator program.
  445. X */
  446. X
  447. X#include <stdio.h>
  448. X#include <setjmp.h>
  449. X#include "math.h"
  450. X
  451. X
  452. X/*
  453. X * Configuration definitions
  454. X */
  455. X#define    CALCPATH    "CALCPATH"    /* environment variable for files */
  456. X#define    CALCRC        "CALCRC"    /* environment variable for startup */
  457. X#define    HOME        "HOME"        /* environment variable for home dir */
  458. X#define    PAGER        "PAGER"        /* environment variable for help */
  459. X#define    SHELL        "SHELL"        /* environment variable for shell */
  460. X#define DEFAULTCALCHELP    "help"        /* help file that -h prints */
  461. X#define DEFAULTSHELL    "sh"        /* default shell to use */
  462. X#define    CALCEXT        ".cal"    /* extension for files read in */
  463. X#define    PATHSIZE    1024    /* maximum length of path name */
  464. X#define    HOMECHAR    '~'    /* char which indicates home directory */
  465. X#define DOTCHAR        '.'    /* char which indicates current directory */
  466. X#define    PATHCHAR    '/'    /* char which separates path components */
  467. X#define    LISTCHAR    ':'    /* char which separates paths in a list */
  468. X#define    MAXCMD        1024    /* maximum length of command invocation */
  469. X#define    MAXERROR    512    /* maximum length of error message string */
  470. X
  471. X#define    SYMBOLSIZE    256    /* maximum symbol name size */
  472. X#define    MAXINDICES    20    /* maximum number of indices for objects */
  473. X#define    MAXLABELS    100    /* maximum number of user labels in function */
  474. X#define    MAXOBJECTS    10    /* maximum number of object types */
  475. X#define MAXDIM        4    /* maximum number of dimensions in matrices */
  476. X#define    MAXSTRING    1024    /* maximum size of string constant */
  477. X#define    MAXSTACK    1000    /* maximum depth of evaluation stack */
  478. X#define    MAXFILES    20    /* maximum number of opened files */
  479. X#define PROMPT1        "> "    /* normal prompt */
  480. X#define PROMPT2        ">> "    /* prompt when inside multi-line input */
  481. X
  482. X
  483. X#define    TRACE_NORMAL    0x00    /* normal trace flags */
  484. X#define    TRACE_OPCODES    0x01    /* trace every opcode */
  485. X#define    TRACE_NODEBUG    0x02    /* suppress debugging opcodes */
  486. X#define    TRACE_MAX    0x03    /* maximum value for trace flag */
  487. X
  488. X#define DISPLAY_DEFAULT 20    /* default digits for float display */
  489. X#define EPSILON_DEFAULT "1e-20"    /* allowed error for float calculations */
  490. X#define MAXPRINT_DEFAULT 16    /* default number of elements printed */
  491. X#define USUAL_ELEMENTS    4    /* usual number of elements for object */
  492. X
  493. X#define ABORT_NONE    0    /* abort not needed yet */
  494. X#define ABORT_STATEMENT    1    /* abort on statement boundary */
  495. X#define ABORT_OPCODE    2    /* abort on any opcode boundary */
  496. X#define ABORT_MATH    3    /* abort on any math operation */
  497. X#define ABORT_NOW    4    /* abort right away */
  498. X
  499. X#define CONFIG_MODE    1    /* types of configuration parameters */
  500. X#define CONFIG_DISPLAY    2
  501. X#define CONFIG_EPSILON    3
  502. X#define CONFIG_TRACE    4
  503. X#define CONFIG_MAXPRINT    5
  504. X#define    CONFIG_MUL2    6
  505. X#define    CONFIG_SQ2    7
  506. X#define    CONFIG_POW2    8
  507. X#define    CONFIG_REDC2    9
  508. X
  509. X
  510. X/*
  511. X * Flags to modify results from the printvalue routine.
  512. X * These flags are OR'd together.
  513. X */
  514. X#define    PRINT_NORMAL    0x00    /* print in normal manner */
  515. X#define    PRINT_SHORT    0x01    /* print in short format (no elements) */
  516. X#define    PRINT_UNAMBIG    0x02    /* print in non-ambiguous manner */
  517. X
  518. X
  519. X/*
  520. X * Definition of values of various types.
  521. X */
  522. Xtypedef struct value VALUE;
  523. Xtypedef struct object OBJECT;
  524. Xtypedef struct matrix MATRIX;
  525. Xtypedef struct list LIST;
  526. Xtypedef    long FILEID;
  527. X
  528. X
  529. Xstruct value {
  530. X    short v_type;            /* type of value */
  531. X    short v_subtype;        /* other data related to some types */
  532. X    union {
  533. X        long vv_int;        /* small integer value */
  534. X        FILEID vv_file;        /* id of opened file */
  535. X        NUMBER *vv_num;        /* arbitrary sized numeric value */
  536. X        COMPLEX *vv_com;    /* complex number */
  537. X        VALUE *vv_addr;        /* address of variable value */
  538. X        MATRIX *vv_mat;        /* address of matrix */
  539. X        LIST *vv_list;        /* address of list */
  540. X        OBJECT *vv_obj;        /* address of object */
  541. X        char *vv_str;        /* string value */
  542. X    } v_union;
  543. X};
  544. X
  545. X
  546. X/*
  547. X * For ease in referencing
  548. X */
  549. X#define v_int    v_union.vv_int
  550. X#define    v_file    v_union.vv_file
  551. X#define v_num    v_union.vv_num
  552. X#define v_com    v_union.vv_com
  553. X#define v_addr    v_union.vv_addr
  554. X#define v_str    v_union.vv_str
  555. X#define v_mat    v_union.vv_mat
  556. X#define    v_list    v_union.vv_list
  557. X#define v_obj    v_union.vv_obj
  558. X#define    v_valid    v_union.vv_int
  559. X
  560. X
  561. X/*
  562. X * Value types.
  563. X */
  564. X#define V_NULL    0    /* null value */
  565. X#define V_INT    1    /* normal integer */
  566. X#define V_NUM    2    /* number */
  567. X#define V_COM    3    /* complex number */
  568. X#define V_ADDR    4    /* address of variable value */
  569. X#define V_STR    5    /* address of string */
  570. X#define V_MAT    6    /* address of matrix structure */
  571. X#define    V_LIST    7    /* address of list structure */
  572. X#define V_OBJ    8    /* address of object structure */
  573. X#define    V_FILE    9    /* opened file id */
  574. X#define V_MAX    9    /* highest legal value */
  575. X
  576. X#define V_STRLITERAL    0    /* string subtype for literal str */
  577. X#define V_STRALLOC    1    /* string subtype for allocated str */
  578. X
  579. X#define TWOVAL(a,b) ((a) * (V_MAX+1) + (b))    /* for switch of two values */
  580. X
  581. X
  582. X/*
  583. X * Structure of a matrix.
  584. X */
  585. Xstruct matrix {
  586. X    long m_dim;        /* dimension of matrix */
  587. X    long m_size;        /* total number of elements */
  588. X    long m_min[MAXDIM];    /* minimum bound for indices */
  589. X    long m_max[MAXDIM];    /* maximum bound for indices */
  590. X    VALUE m_table[1];    /* actually varying length table */
  591. X};
  592. X
  593. X#define matsize(n) (sizeof(MATRIX) - sizeof(VALUE) + ((n) * sizeof(VALUE)))
  594. X
  595. X
  596. X/*
  597. X * List definitions.
  598. X * An individual list element.
  599. X */
  600. Xtypedef struct listelem LISTELEM;
  601. Xstruct listelem {
  602. X    LISTELEM *e_next;    /* next element in list (or NULL) */
  603. X    LISTELEM *e_prev;    /* previous element in list (or NULL) */
  604. X    VALUE e_value;        /* value of this element */
  605. X};
  606. X
  607. X
  608. X/*
  609. X * Structure for a list of elements.
  610. X */
  611. Xstruct list {
  612. X    LISTELEM *l_first;    /* first list element (or NULL) */
  613. X    LISTELEM *l_last;    /* last list element (or NULL) */
  614. X    LISTELEM *l_cache;    /* cached list element (or NULL) */
  615. X    long l_cacheindex;    /* index of cached element (or undefined) */
  616. X    long l_count;        /* total number of elements in the list */
  617. X};
  618. X
  619. Xextern void insertlistfirst(), insertlistlast(), insertlistmiddle();
  620. Xextern void removelistfirst(), removelistlast(), removelistmiddle();
  621. Xextern void listfree(), listprint();
  622. Xextern long listsearch(), listrsearch();
  623. Xextern BOOL listcmp();
  624. Xextern VALUE *listindex();
  625. Xextern LIST *listalloc(), *listcopy();
  626. X
  627. X
  628. X/*
  629. X * Object actions.
  630. X */
  631. X#define OBJ_PRINT    0    /* print the value */
  632. X#define OBJ_ONE        1    /* create the multiplicative identity */
  633. X#define OBJ_TEST    2    /* test a value for "zero" */
  634. X#define OBJ_ADD        3    /* add two values */
  635. X#define OBJ_SUB        4    /* subtrace one value from another */
  636. X#define OBJ_NEG        5    /* negate a value */
  637. X#define OBJ_MUL        6    /* multiply two values */
  638. X#define OBJ_DIV        7    /* divide one value by another */
  639. X#define OBJ_INV        8    /* invert a value */
  640. X#define OBJ_ABS        9    /* take absolute value of value */
  641. X#define OBJ_NORM    10    /* take the norm of a value */
  642. X#define OBJ_CONJ    11    /* take the conjugate of a value */
  643. X#define OBJ_POW        12    /* take the power function */
  644. X#define OBJ_SGN        13    /* return the sign of a value */
  645. X#define OBJ_CMP        14    /* compare two values for equality */
  646. X#define OBJ_REL        15    /* compare two values for inequality */
  647. X#define OBJ_QUO        16    /* integer quotient of values */
  648. X#define OBJ_MOD        17    /* remainder of division of values */
  649. X#define OBJ_INT        18    /* integer part of */
  650. X#define OBJ_FRAC    19    /* fractional part of */
  651. X#define OBJ_INC        20    /* increment by one */
  652. X#define OBJ_DEC        21    /* decrement by one */
  653. X#define OBJ_SQUARE    22    /* square value */
  654. X#define OBJ_SCALE    23    /* scale by power of two */
  655. X#define OBJ_SHIFT    24    /* shift left (or right) by number of bits */
  656. X#define OBJ_ROUND    25    /* round to specified decimal places */
  657. X#define OBJ_BROUND    26    /* round to specified binary places */
  658. X#define OBJ_ROOT    27    /* take nth root of value */
  659. X#define OBJ_SQRT    28    /* take square root of value */
  660. X#define OBJ_MAXFUNC    28    /* highest function */
  661. X
  662. X
  663. X/*
  664. X * Definition of an object type.
  665. X * This is actually a varying sized structure.
  666. X */
  667. Xtypedef struct {
  668. X    char *name;            /* name of object */
  669. X    int count;            /* number of elements defined */
  670. X    int actions[OBJ_MAXFUNC+1];    /* function indices for actions */
  671. X    int elements[1];        /* element indexes (MUST BE LAST) */
  672. X} OBJECTACTIONS;
  673. X
  674. X#define objectactionsize(elements) \
  675. X    (sizeof(OBJECTACTIONS) + ((elements) - 1) * sizeof(int))
  676. X
  677. X
  678. X/*
  679. X * Structure of an object.
  680. X * This is actually a varying sized structure.
  681. X * However, there are always at least USUAL_ELEMENTS values in the object.
  682. X */
  683. Xstruct object {
  684. X    OBJECTACTIONS *o_actions;    /* action table for this object */
  685. X    VALUE o_table[USUAL_ELEMENTS];    /* object values (MUST BE LAST) */
  686. X};
  687. X
  688. X#define objectsize(elements) \
  689. X    (sizeof(OBJECT) + ((elements) - USUAL_ELEMENTS) * sizeof(VALUE))
  690. X
  691. X
  692. X/*
  693. X * File ids corresponding to standard in, out, error, and when not in use.
  694. X */
  695. X#define    FILEID_STDIN    0
  696. X#define    FILEID_STDOUT    1
  697. X#define    FILEID_STDERR    2
  698. X#define    FILEID_NONE    -1
  699. X
  700. X
  701. X/*
  702. X * Common definitions
  703. X */
  704. Xextern long maxprint;        /* number of elements to print */
  705. Xextern int abortlevel;        /* current level of aborts */
  706. Xextern BOOL inputwait;        /* TRUE if in a terminal input wait */
  707. Xextern FLAG traceflags;        /* tracing flags */
  708. Xextern VALUE *stack;        /* execution stack */
  709. Xextern jmp_buf jmpbuf;        /* for errors */
  710. X
  711. Xextern char *calcpath;        /* $CALCPATH or default */
  712. Xextern char *calcrc;        /* $CALCRC or default */
  713. Xextern char *home;        /* $HOME or default */
  714. Xextern char *shell;        /* $SHELL or default */
  715. X
  716. X/*
  717. X * Functions.
  718. X */
  719. Xextern MATRIX *matadd(), *matsub(), *matmul(), *matneg();
  720. Xextern MATRIX *matalloc(), *matcopy(), *matsquare(), *matinv();
  721. Xextern MATRIX *matscale(), *matmulval(), *matpowi(), *matconj(), *matquoval();
  722. Xextern MATRIX *matmodval(), *matint(), *matfrac(), *matround(), *matbround();
  723. Xextern MATRIX *mattrans(), *matcross(), *matshift();
  724. Xextern BOOL mattest(), matcmp();
  725. Xextern long matsearch(), matrsearch();
  726. Xextern VALUE matdet(), matdot();
  727. Xextern void matfill(), matfree(), matprint();
  728. X
  729. X#if 0
  730. Xextern BOOL matisident();
  731. X#endif
  732. X
  733. Xextern OBJECT *objcopy(), *objalloc();
  734. Xextern VALUE objcall();
  735. Xextern void objfree();
  736. Xextern void objuncache();
  737. Xextern int addelement();
  738. Xextern int defineobject();
  739. Xextern int checkobject();
  740. Xextern void showobjfuncs();
  741. Xextern int findelement();
  742. Xextern int objoffset();
  743. X
  744. Xextern void freevalue(), copyvalue(), negvalue(), addvalue(), subvalue();
  745. Xextern void mulvalue(), squarevalue(), invertvalue(), roundvalue();
  746. Xextern void broundvalue(), intvalue(), fracvalue(), incvalue(), decvalue();
  747. Xextern void conjvalue(), sqrtvalue(), rootvalue(), absvalue(), normvalue();
  748. Xextern void shiftvalue(), scalevalue(), powivalue(), powervalue();
  749. Xextern void divvalue(), quovalue(), modvalue(), printvalue();
  750. Xextern BOOL testvalue(), comparevalue();
  751. Xextern FLAG relvalue();
  752. X
  753. Xextern FILEID openid(), indexid();
  754. Xextern BOOL validid(), errorid(), eofid(), closeid();
  755. Xextern int getcharid();
  756. Xextern void idprintf(), printid(), flushid(), readid();
  757. X
  758. Xextern FILE *f_open();
  759. Xextern int openstring();
  760. Xextern int openterminal();
  761. Xextern int opensearchfile();
  762. Xextern int nextchar();
  763. Xextern void reread();
  764. X
  765. Xextern VALUE builtinfunc();
  766. Xextern NUMBER *constvalue();
  767. Xextern long addnumber(), addqconstant();
  768. Xextern long linenumber();
  769. Xextern char *builtinname();
  770. Xextern char *inputname();
  771. Xextern BOOL inputisterminal();
  772. Xextern void resetinput();
  773. Xextern char *nextline();
  774. Xextern void calculate();
  775. Xextern void initstack();
  776. Xextern int dumpop();
  777. Xextern void version();        /* print version string */
  778. Xextern void runrcfiles();
  779. Xextern void getcommands();
  780. Xextern void givehelp();
  781. Xextern void setprompt();
  782. X
  783. Xextern void getconfig();
  784. Xextern void setconfig();
  785. Xextern int configtype();
  786. X
  787. X#ifdef VARARGS
  788. Xvoid error();
  789. X#else
  790. X# ifdef __STDC__
  791. Xvoid error(char *, ...);
  792. X# else
  793. Xvoid error();
  794. X# endif
  795. X#endif
  796. X
  797. X
  798. X/* END CODE */
  799. END_OF_FILE
  800. if test 11561 -ne `wc -c <'calc.h'`; then
  801.     echo shar: \"'calc.h'\" unpacked with wrong size!
  802. fi
  803. # end of 'calc.h'
  804. fi
  805. if test -f 'help/builtin' -a "${1}" != "-c" ; then 
  806.   echo shar: Will not clobber existing file \"'help/builtin'\"
  807. else
  808. echo shar: Extracting \"'help/builtin'\" \(12708 characters\)
  809. sed "s/^X//" >'help/builtin' <<'END_OF_FILE'
  810. XBuiltin functions
  811. X
  812. X    There is a large number of built-in functions.  Many of the
  813. X    functions work on several types of arguments, whereas some only
  814. X    work for the correct types (e.g., numbers or strings).  In the
  815. X    following description, this is indicated by whether or not the
  816. X    description refers to values or numbers.  This display is generated
  817. X    by the 'show builtins' command.
  818. X
  819. X        Name    Args    Description
  820. X
  821. X        abs       1-2    absolute value within accuracy b
  822. X        acos      1-2    arccosine of a within accuracy b
  823. X        acosh     1-2    hyperbolic arccosine of a within accuracy b
  824. X        append    2      append value to end of list
  825. X        appr      1-2    approximate a with simpler fraction to within b
  826. X        arg       1-2    argument (the angle) of complex number
  827. X        asin      1-2    arcsine of a within accuracy b
  828. X        asinh     1-2    hyperbolic arcsine of a within accuracy b
  829. X        atan      1-2    arctangent of a within accuracy b
  830. X        atan2     2-3    angle to point (b,a) within accuracy c
  831. X        atanh     1-2    hyperbolic arctangent of a within accuracy b
  832. X        avg       1+     arithmetic mean of values
  833. X        bround    1-2    round value a to b number of binary places
  834. X        btrunc    1-2    truncate a to b number of binary places
  835. X        ceil      1      smallest integer greater than or equal to number
  836. X        cfappr    1-2    approximate a within accuracy b using
  837. X                continued fractions
  838. X        cfsim     1      simplify number using continued fractions
  839. X        char      1      character corresponding to integer value
  840. X        cmp       2      compare values returning -1, 0, or 1
  841. X        comb      2      combinatorial number a!/b!(a-b)!
  842. X        config    1-2    set or read configuration value
  843. X        conj      1      complex conjugate of value
  844. X        cos       1-2    cosine of value a within accuracy b
  845. X        cosh      1-2    hyperbolic cosine of a within accuracy b
  846. X        cp        2      cross product of two vectors
  847. X        delete    2      delete element from list a at position b
  848. X        den       1      denominator of fraction
  849. X        det       1      determinant of matrix
  850. X        digit     2      digit at specified decimal place of number
  851. X        digits    1      number of digits in number
  852. X        dp        2      dot product of two vectors
  853. X        epsilon   0-1    set or read allowed error for real calculations
  854. X        eval      1      evaluate expression from string to value
  855. X        exp       1-2    exponential of value a within accuracy b
  856. X        fcnt      2      count of times one number divides another
  857. X        fib       1      Fibonacci number F(n)
  858. X        frem      2      number with all occurrence of factor removed
  859. X        fact      1      factorial
  860. X        fclose    1      close file
  861. X        feof      1      whether EOF reached for file
  862. X        ferror    1      whether error occurred for file
  863. X        fflush    1      flush output to file
  864. X        fgetc     1      read next char from file
  865. X        fgetline  1      read next line from file
  866. X        files     0-1    return opened file or max number of opened files
  867. X        floor     1      greatest integer less than or equal to number
  868. X        fopen     2      open file name a in mode b
  869. X        fprintf   2+     print formatted output to opened file
  870. X        frac      1      fractional part of value
  871. X        gcd       1+     greatest common divisor
  872. X        gcdrem    2      a divided repeatedly by gcd with b
  873. X        highbit   1      high bit number in base 2 representation
  874. X        hmean     1+     harmonic mean of values
  875. X        hypot     2-3    hypotenuse of right triangle within accuracy c
  876. X        ilog      2      integral log of one number with another
  877. X        ilog10    1      integral log of a number base 10
  878. X        ilog2     1      integral log of a number base 2
  879. X        im        1      imaginary part of complex number
  880. X        insert    3      insert value c into list a at position b
  881. X        int       1      integer part of value
  882. X        inverse   1      multiplicative inverse of value
  883. X        iroot     2      integer b'th root of a
  884. X        iseven    1      whether a value is an even integer
  885. X        isfile    1      whether a value is a file
  886. X        isint     1      whether a value is an integer
  887. X        islist    1      whether a value is a list
  888. X        ismat     1      whether a value is a matrix
  889. X        ismult    2      whether a is a multiple of b
  890. X        isnull    1      whether a value is the null value
  891. X        isnum     1      whether a value is a number
  892. X        isobj     1      whether a value is an object
  893. X        isodd     1      whether a value is an odd integer
  894. X        isqrt     1      integer part of square root
  895. X        isreal    1      whether a value is a real number
  896. X        isset     2      whether bit b of abs(a) (in base 2) is set
  897. X        isstr     1      whether a value is a string
  898. X        isrel     2      whether two numbers are relatively prime
  899. X        issimple  1      whether value is a simple type
  900. X        issq      1      whether or not number is a square
  901. X        istype    2      whether the type of a is same as the type of b
  902. X        jacobi    2      -1 => a is not quadratic residue mod b
  903. X                 1 => b is composite, or a is quad residue of b
  904. X        lcm       1+     least common multiple
  905. X        lcmfact   1      lcm of all integers up till number
  906. X        lfactor   2      lowest prime factor of a in first b primes
  907. X        list      0+     create list of specified values
  908. X        ln        1-2    natural logarithm of value a within accuracy b
  909. X        lowbit    1      low bit number in base 2 representation
  910. X        ltol      1-2    leg-to-leg of unit right triangle
  911. X                     (sqrt(1 - a^2))
  912. X        matdim    1      number of dimensions of matrix
  913. X        matfill   2-3    fill matrix with value b (value c on diagonal)
  914. X        matmax    2      maximum index of matrix a dim b
  915. X        matmin    2      minimum index of matrix a dim b
  916. X        mattrans  1      transpose of matrix
  917. X        max       1+     maximum value
  918. X        meq       3      whether a and b are equal modulo c
  919. X        min       1+     minimum value
  920. X        minv      2      inverse of a modulo b
  921. X        mmin      2      a mod b value with smallest abs value
  922. X        mne       3      whether a and b are not equal modulo c
  923. X        near      2-3    sign of (abs(a-b) - c)
  924. X        norm      1      norm of a value (square of absolute value)
  925. X        null      0      null value
  926. X        num       1      numerator of fraction
  927. X        ord       1      integer corresponding to character value
  928. X        param     1      value of parameter n (or parameter count if
  929. X                     n is zero)
  930. X        perm      2      permutation number a!/(a-b)!
  931. X        pfact     1      product of primes up till number
  932. X        pi        0-1    value of pi accurate to within epsilon
  933. X        places    1      places after decimal point (-1 if infinite)
  934. X        pmod      3      mod of a power (a ^ b (mod c))
  935. X        polar     2-3    complex value of polar coordinate
  936. X                     (a * exp(b*1i))
  937. X        poly      2+     (a1,a2,...,an,x) = a1*x^n+a2*x^(n-1)+...+an
  938. X        pop       1      pop value from front of list
  939. X        power     2-3    value a raised to the power b within accuracy c
  940. X        ptest     2      probabilistic primality test
  941. X        printf    1+     print formatted output to stdout
  942. X        prompt    1      prompt for input line using value a
  943. X        push      2      push value onto front of list
  944. X        quomod    4      set c and d to quotient and remainder of a divided by b
  945. X        rcin      2      convert normal number a to REDC number mod b
  946. X        rcmul     3      multiply REDC numbers a and b mod c
  947. X        rcout     2      convert REDC number a mod b to normal number
  948. X        rcpow     3      raise REDC number a to power b mod c
  949. X        rcsq      2      square REDC number a mod b
  950. X        re        1      real part of complex number
  951. X        remove    1      remove value from end of list
  952. X        root      2-3    value a taken to the b'th root within accuracy c
  953. X        round     1-2    round value a to b number of decimal places
  954. X        rsearch   2-3    reverse search matrix or list for value b
  955. X                     starting at index c
  956. X        runtime   0      user mode cpu time in seconds
  957. X        scale     2      scale value up or down by a power of two
  958. X        search    2-3    search matrix or list for value b starting at
  959. X                     index c
  960. X        sgn       1      sign of value (-1, 0, 1)
  961. X        sin       1-2    sine of value a within accuracy b
  962. X        sinh      1-2    hyperbolic sine of a within accuracy b
  963. X        size      1      total number of elements in value
  964. X        sqrt      1-2    square root of value a within accuracy b
  965. X        ssq       1+     sum of squares of values
  966. X        str       1      simple value converted to string
  967. X        strcat    1+     concatenate strings together
  968. X        strlen    1      length of string
  969. X        strprintf 1+     return formatted output as a string
  970. X        substr    3      substring of a from position b for c chars
  971. X        swap      2      swap values of variables a and b
  972. X                     (can be dangerous)
  973. X        tan       1-2    tangent of a within accuracy b
  974. X        tanh      1-2    hyperbolic tangent of a within accuracy b
  975. X        trunc     1-2    truncate a to b number of decimal places
  976. X        xor       1+     logical xor
  977. X
  978. X
  979. X    The config function sets or reads the value of a configuration
  980. X    parameter.  The first argument is a string which names the parameter
  981. X    to be set or read.  If only one argument is given, then the current
  982. X    value of the named parameter is returned.  If two arguments are given,
  983. X    then the named parameter is set to the value of the second argument,
  984. X    and the old value of the parameter is returned.  Therefore you can
  985. X    change a parameter and restore its old value later.  The possible
  986. X    parameters are explained in the next section.
  987. X
  988. X    The scale function multiplies or divides a number by a power of 2.
  989. X    This is used for fractional calculations, unlike the << and >>
  990. X    operators, which are only defined for integers.  For example,
  991. X    scale(6, -3) is 3/4.
  992. X
  993. X    The quomod function is used to obtain both the quotient and remainder
  994. X    of a division in one operation.  The first two arguments a and b are
  995. X    the numbers to be divided.  The last two arguments c and d are two
  996. X    variables which will be assigned the quotient and remainder.  For
  997. X    nonnegative arguments, the results are equivalent to computing a//b
  998. X    and a%b.  If a is negative and the remainder is nonzero, then the
  999. X    quotient will be one less than a//b.  This makes the following three
  1000. X    properties always hold:  The quotient c is always an integer.  The
  1001. X    remainder d is always 0 <= d < b.  The equation a = b * c + d always
  1002. X    holds.  This function returns 0 if there is no remainder, and 1 if
  1003. X    there is a remainder.  For examples, quomod(10, 3, x, y) sets x to 3,
  1004. X    y to 1, and returns the value 1, and quomod(-4, 3.14159, x, y) sets x
  1005. X    to -2, y to 2.28318, and returns the value 1.
  1006. X
  1007. X    The eval function accepts a string argument and evaluates the
  1008. X    expression represented by the string and returns its value.
  1009. X    The expression can include function calls and variable references.
  1010. X    For example, eval("fact(3) + 7") returns 13.  When combined with
  1011. X    the prompt function, this allows the calculator to read values from
  1012. X    the user.  For example, x=eval(prompt("Number: ")) sets x to the
  1013. X    value input by the user.
  1014. X
  1015. X    The digit and isset functions return individual digits of a number,
  1016. X    either in base 10 or in base 2, where the lowest digit of a number
  1017. X    is at digit position 0.  For example, digit(5678, 3) is 5, and
  1018. X    isset(0b1000100, 2) is 1.  Negative digit positions indicate places
  1019. X    to the right of the decimal or binary point, so that for example,
  1020. X    digit(3.456, -1) is 4.
  1021. X
  1022. X    The ptest function is a primality testing function.  The first
  1023. X    argument is the suspected prime to be tested.  The second argument
  1024. X    is an iteration count.  The function returns 0 if the number is
  1025. X    definitely not prime, and 1 is the number is probably prime.  The
  1026. X    chance of a number which is probably prime being actually composite
  1027. X    is less than 1/4 raised to the power of the iteration count.  For
  1028. X    example, for a random number p, ptest(p, 10) incorrectly returns 1
  1029. X    less than once in every million numbers, and you will probably never
  1030. X    find a number where ptest(p, 20) gives the wrong answer.
  1031. X
  1032. X    The functions rcin, rcmul, rcout, rcpow, and rcsq are used to
  1033. X    perform modular arithmetic calculations for large odd numbers
  1034. X    faster than the usual methods.  To do this, you first use the
  1035. X    rcin function to convert all input values into numbers which are
  1036. X    in a format called REDC format.  Then you use rcmul, rcsq, and
  1037. X    rcpow to multiply such numbers together to produce results also
  1038. X    in REDC format.  Finally, you use rcout to convert a number in
  1039. X    REDC format back to a normal number.  The addition, subtraction,
  1040. X    negation, and equality comparison between REDC numbers are done
  1041. X    using the normal modular methods.  For example, to calculate the
  1042. X    value 13 * 17 + 1 (mod 11), you could use:
  1043. X
  1044. X        p = 11;
  1045. X        t1 = rcin(13, p);
  1046. X        t2 = rcin(17, p);
  1047. X        t3 = rcin(1, p);
  1048. X        t4 = rcmul(t1, t2, p);
  1049. X        t5 = (t4 + t3) % p;
  1050. X        answer = rcout(t5, p);
  1051. X
  1052. X    The swap function exchanges the values of two variables without
  1053. X    performing copies.  For example, after:
  1054. X
  1055. X        x = 17;
  1056. X        y = 19;
  1057. X        swap(x, y);
  1058. X
  1059. X    then x is 19 and y is 17.  This function should not be used to
  1060. X    swap a value which is contained within another one.  If this is
  1061. X    done, then some memory will be lost.  For example, the following
  1062. X    should not be done:
  1063. X
  1064. X        mat x[5];
  1065. X        swap(x, x[0]);
  1066. END_OF_FILE
  1067. if test 12708 -ne `wc -c <'help/builtin'`; then
  1068.     echo shar: \"'help/builtin'\" unpacked with wrong size!
  1069. fi
  1070. # end of 'help/builtin'
  1071. fi
  1072. if test -f 'token.c' -a "${1}" != "-c" ; then 
  1073.   echo shar: Will not clobber existing file \"'token.c'\"
  1074. else
  1075. echo shar: Extracting \"'token.c'\" \(12074 characters\)
  1076. sed "s/^X//" >'token.c' <<'END_OF_FILE'
  1077. X/*
  1078. X * Copyright (c) 1992 David I. Bell
  1079. X * Permission is granted to use, distribute, or modify this source,
  1080. X * provided that this copyright notice remains intact.
  1081. X *
  1082. X * Read input file characters into tokens
  1083. X */
  1084. X
  1085. X#include "stdarg.h"
  1086. X#include "calc.h"
  1087. X#include "token.h"
  1088. X#include "string.h"
  1089. X
  1090. X
  1091. X#define isletter(ch)    ((((ch) >= 'a') && ((ch) <= 'z')) || \
  1092. X                (((ch) >= 'A') && ((ch) <= 'Z')))
  1093. X#define isdigit(ch)    (((ch) >= '0') && ((ch) <= '9'))
  1094. X#define issymbol(ch)    (isletter(ch) || isdigit(ch) || ((ch) == '_'))
  1095. X
  1096. X
  1097. X/*
  1098. X * Current token.
  1099. X */
  1100. Xstatic struct {
  1101. X    short t_type;        /* type of token */
  1102. X    char *t_str;        /* string value or symbol name */
  1103. X    long t_numindex;    /* index of numeric value */
  1104. X} curtoken;
  1105. X
  1106. X
  1107. Xstatic BOOL rescan;        /* TRUE to reread current token */
  1108. Xstatic BOOL newlines;        /* TRUE to return newlines as tokens */
  1109. Xstatic BOOL allsyms;        /* TRUE if always want a symbol token */
  1110. Xstatic STRINGHEAD strings;    /* list of constant strings */
  1111. Xstatic char *numbuf;        /* buffer for numeric tokens */
  1112. Xstatic long numbufsize;        /* current size of numeric buffer */
  1113. X
  1114. Xlong errorcount;        /* number of compilation errors */
  1115. X
  1116. X
  1117. X/*
  1118. X * Table of keywords
  1119. X */
  1120. Xstruct keyword {
  1121. X    char *k_name;    /* keyword name */
  1122. X    int k_token;    /* token number */
  1123. X};
  1124. X
  1125. Xstatic struct keyword keywords[] = {
  1126. X    "if",        T_IF,
  1127. X    "else",        T_ELSE,
  1128. X    "for",        T_FOR,
  1129. X    "while",    T_WHILE,
  1130. X    "do",        T_DO,
  1131. X    "continue",    T_CONTINUE,
  1132. X    "break",    T_BREAK,
  1133. X    "goto",        T_GOTO,
  1134. X    "return",    T_RETURN,
  1135. X    "local",    T_LOCAL,
  1136. X    "global",    T_GLOBAL,
  1137. X    "print",    T_PRINT,
  1138. X    "switch",    T_SWITCH,
  1139. X    "case",        T_CASE,
  1140. X    "default",    T_DEFAULT,
  1141. X    "quit",        T_QUIT,
  1142. X    "exit",        T_QUIT,
  1143. X    "define",    T_DEFINE,
  1144. X    "read",        T_READ,
  1145. X    "show",        T_SHOW,
  1146. X    "help",        T_HELP,
  1147. X    "write",    T_WRITE,
  1148. X    "mat",        T_MAT,
  1149. X    "obj",        T_OBJ,
  1150. X    NULL,        0
  1151. X};
  1152. X
  1153. X
  1154. Xstatic void eatcomment(), eatstring();
  1155. Xstatic int eatsymbol(), eatnumber();
  1156. X
  1157. X
  1158. X/*
  1159. X * Initialize all token information.
  1160. X */
  1161. Xvoid
  1162. Xinittokens()
  1163. X{
  1164. X    initstr(&strings);
  1165. X    newlines = FALSE;
  1166. X    allsyms = FALSE;
  1167. X    rescan = FALSE;
  1168. X    setprompt(PROMPT1);
  1169. X}
  1170. X
  1171. X
  1172. Xvoid
  1173. Xtokenmode(flag)
  1174. X{
  1175. X    newlines = FALSE;
  1176. X    allsyms = FALSE;
  1177. X    if (flag & TM_NEWLINES)
  1178. X        newlines = TRUE;
  1179. X    if (flag & TM_ALLSYMS)
  1180. X        allsyms = TRUE;
  1181. X    setprompt(newlines ? PROMPT1 : PROMPT2);
  1182. X}
  1183. X
  1184. X
  1185. X/*
  1186. X * Routine to read in the next token from the input stream.
  1187. X * The type of token is returned as a value.  If the token is a string or
  1188. X * symbol name, information is saved so that the value can be retrieved.
  1189. X */
  1190. Xint
  1191. Xgettoken()
  1192. X{
  1193. X    int ch;            /* current input character */
  1194. X    int type;        /* token type */
  1195. X
  1196. X    if (rescan) {        /* rescanning */
  1197. X        rescan = FALSE;
  1198. X        return curtoken.t_type;
  1199. X    }
  1200. X    curtoken.t_str = NULL;
  1201. X    curtoken.t_numindex = 0;
  1202. X    type = T_NULL;
  1203. X    while (type == T_NULL) {
  1204. X        ch = nextchar();
  1205. X        if (allsyms && ((ch!=' ') && (ch!=';') && (ch!='"') && (ch!='\n'))) {
  1206. X            reread();
  1207. X            type = eatsymbol();
  1208. X            break;
  1209. X        }
  1210. X        switch (ch) {
  1211. X        case ' ':
  1212. X        case '\t':
  1213. X        case '\0':
  1214. X            break;
  1215. X        case '\n':
  1216. X            if (newlines)
  1217. X                type = T_NEWLINE;
  1218. X            break;
  1219. X        case EOF: type = T_EOF; break;
  1220. X        case '{': type = T_LEFTBRACE; break;
  1221. X        case '}': type = T_RIGHTBRACE; break;
  1222. X        case '(': type = T_LEFTPAREN; break;
  1223. X        case ')': type = T_RIGHTPAREN; break;
  1224. X        case '[': type = T_LEFTBRACKET; break;
  1225. X        case ']': type = T_RIGHTBRACKET; break;
  1226. X        case ';': type = T_SEMICOLON; break;
  1227. X        case ':': type = T_COLON; break;
  1228. X        case ',': type = T_COMMA; break;
  1229. X        case '?': type = T_QUESTIONMARK; break;
  1230. X        case '"':
  1231. X        case '\'':
  1232. X            type = T_STRING;
  1233. X            eatstring(ch);
  1234. X            break;
  1235. X        case '^':
  1236. X            switch (nextchar()) {
  1237. X                case '=': type = T_POWEREQUALS; break;
  1238. X                default: type = T_POWER; reread();
  1239. X            }
  1240. X            break;
  1241. X        case '=':
  1242. X            switch (nextchar()) {
  1243. X                case '=': type = T_EQ; break;
  1244. X                default: type = T_ASSIGN; reread();
  1245. X            }
  1246. X            break;
  1247. X        case '+':
  1248. X            switch (nextchar()) {
  1249. X                case '+': type = T_PLUSPLUS; break;
  1250. X                case '=': type = T_PLUSEQUALS; break;
  1251. X                default: type = T_PLUS; reread();
  1252. X            }
  1253. X            break;
  1254. X        case '-':
  1255. X            switch (nextchar()) {
  1256. X                case '-': type = T_MINUSMINUS; break;
  1257. X                case '=': type = T_MINUSEQUALS; break;
  1258. X                default: type = T_MINUS; reread();
  1259. X            }
  1260. X            break;
  1261. X        case '*':
  1262. X            switch (nextchar()) {
  1263. X                case '=': type = T_MULTEQUALS; break;
  1264. X                case '*':
  1265. X                    switch (nextchar()) {
  1266. X                        case '=': type = T_POWEREQUALS; break;
  1267. X                        default: type = T_POWER; reread();
  1268. X                    }
  1269. X                    break;
  1270. X                default: type = T_MULT; reread();
  1271. X            }
  1272. X            break;
  1273. X        case '/':
  1274. X            switch (nextchar()) {
  1275. X                case '/':
  1276. X                    switch (nextchar()) {
  1277. X                        case '=': type = T_SLASHSLASHEQUALS; break;
  1278. X                        default: reread(); type = T_SLASHSLASH; break;
  1279. X                    }
  1280. X                    break;
  1281. X                case '=': type = T_DIVEQUALS; break;
  1282. X                case '*': eatcomment(); break;
  1283. X                default: type = T_DIV; reread();
  1284. X            }
  1285. X            break;
  1286. X        case '%':
  1287. X            switch (nextchar()) {
  1288. X                case '=': type = T_MODEQUALS; break;
  1289. X                default: type = T_MOD; reread();
  1290. X            }
  1291. X            break;
  1292. X        case '<':
  1293. X            switch (nextchar()) {
  1294. X                case '=': type = T_LE; break;
  1295. X                case '<':
  1296. X                    switch (nextchar()) {
  1297. X                        case '=': type = T_LSHIFTEQUALS; break;
  1298. X                        default:  reread(); type = T_LEFTSHIFT; break;
  1299. X                    }
  1300. X                    break;
  1301. X                default: type = T_LT; reread();
  1302. X            }
  1303. X            break;
  1304. X        case '>':
  1305. X            switch (nextchar()) {
  1306. X                case '=': type = T_GE; break;
  1307. X                case '>':
  1308. X                    switch (nextchar()) {
  1309. X                        case '=': type = T_RSHIFTEQUALS; break;
  1310. X                        default:  reread(); type = T_RIGHTSHIFT; break;
  1311. X                    }
  1312. X                    break;
  1313. X                default: type = T_GT; reread();
  1314. X            }
  1315. X            break;
  1316. X        case '&':
  1317. X            switch (nextchar()) {
  1318. X                case '&': type = T_ANDAND; break;
  1319. X                case '=': type = T_ANDEQUALS; break;
  1320. X                default: type = T_AND; reread(); break;
  1321. X            }
  1322. X            break;
  1323. X        case '|':
  1324. X            switch (nextchar()) {
  1325. X                case '|': type = T_OROR; break;
  1326. X                case '=': type = T_OREQUALS; break;
  1327. X                default: type = T_OR; reread(); break;
  1328. X            }
  1329. X            break;
  1330. X        case '!':
  1331. X            switch (nextchar()) {
  1332. X                case '=': type = T_NE; break;
  1333. X                default: type = T_NOT; reread(); break;
  1334. X            }
  1335. X            break;
  1336. X        case '\\':
  1337. X            switch (nextchar()) {
  1338. X                case '\n': setprompt(PROMPT2); break;
  1339. X                default: scanerror(T_NULL, "Unknown token character '%c'", ch);
  1340. X            }
  1341. X            break;
  1342. X        default:
  1343. X            if (isletter(ch)) {
  1344. X                reread();
  1345. X                type = eatsymbol();
  1346. X                break;
  1347. X            }
  1348. X            if (isdigit(ch) || (ch == '.')) {
  1349. X                reread();
  1350. X                type = eatnumber();
  1351. X                break;
  1352. X            }
  1353. X            scanerror(T_NULL, "Unknown token character '%c'", ch);
  1354. X        }
  1355. X    }
  1356. X    curtoken.t_type = (short)type;
  1357. X    return type;
  1358. X}
  1359. X
  1360. X
  1361. X/*
  1362. X * Continue to eat up a comment string.
  1363. X * The leading slash-asterisk has just been scanned at this point.
  1364. X */
  1365. Xstatic void
  1366. Xeatcomment()
  1367. X{
  1368. X    int ch;
  1369. X
  1370. X    for (;;) {
  1371. X        ch = nextchar();
  1372. X        if (ch == '*') {
  1373. X            ch = nextchar();
  1374. X            if (ch == '/')
  1375. X                return;
  1376. X            reread();
  1377. X        }
  1378. X        if ((ch == EOF) || (ch == '\0') ||
  1379. X            (newlines && (ch == '\n') && inputisterminal())) {
  1380. X                reread();
  1381. X                scanerror(T_NULL, "Unterminated comment");
  1382. X                return;
  1383. X        }
  1384. X    }
  1385. X}
  1386. X
  1387. X
  1388. X/*
  1389. X * Read in a string and add it to the literal string pool.
  1390. X * The leading single or double quote has been read in at this point.
  1391. X */
  1392. Xstatic void
  1393. Xeatstring(quotechar)
  1394. X{
  1395. X    register char *cp;    /* current character address */
  1396. X    int ch;            /* current character */
  1397. X    char buf[MAXSTRING+1];    /* buffer for string */
  1398. X
  1399. X    cp = buf;
  1400. X    for (;;) {
  1401. X        ch = nextchar();
  1402. X        switch (ch) {
  1403. X            case '\0':
  1404. X            case EOF:
  1405. X            case '\n':
  1406. X                reread();
  1407. X                scanerror(T_NULL, "Unterminated string constant");
  1408. X                *cp = '\0';
  1409. X                curtoken.t_str = addliteral(buf);
  1410. X                return;
  1411. X
  1412. X            case '\\':
  1413. X                ch = nextchar();
  1414. X                switch (ch) {
  1415. X                    case 'n': ch = '\n'; break;
  1416. X                    case 'r': ch = '\r'; break;
  1417. X                    case 't': ch = '\t'; break;
  1418. X                    case 'b': ch = '\b'; break;
  1419. X                    case 'f': ch = '\f'; break;
  1420. X                    case '\n':
  1421. X                        setprompt(PROMPT2);
  1422. X                        continue;
  1423. X                    case EOF:
  1424. X                        reread();
  1425. X                        continue;
  1426. X                }
  1427. X                *cp++ = (char)ch;
  1428. X                break;
  1429. X
  1430. X            case '"':
  1431. X            case '\'':
  1432. X                if (ch == quotechar) {
  1433. X                    *cp = '\0';
  1434. X                    curtoken.t_str = addliteral(buf);
  1435. X                    return;
  1436. X                }
  1437. X                /* fall into default case */
  1438. X
  1439. X            default:
  1440. X                *cp++ = (char)ch;
  1441. X        }
  1442. X    }
  1443. X}
  1444. X
  1445. X
  1446. X/*
  1447. X * Read in a symbol name which may or may not be a keyword.
  1448. X * If allsyms is set, keywords are not looked up and almost all chars
  1449. X * will be accepted for the symbol.  Returns the type of symbol found.
  1450. X */
  1451. Xstatic int
  1452. Xeatsymbol()
  1453. X{
  1454. X    register struct keyword *kp;    /* pointer to current keyword */
  1455. X    register char *cp;        /* current character pointer */
  1456. X    int ch;                /* current character */
  1457. X    int cc;                /* character count */
  1458. X    static char buf[SYMBOLSIZE+1];    /* temporary buffer */
  1459. X
  1460. X    cp = buf;
  1461. X    cc = SYMBOLSIZE;
  1462. X    if (allsyms) {
  1463. X        for (;;) {
  1464. X            ch = nextchar();
  1465. X            if ((ch == ' ') || (ch == ';') || (ch == '\n'))
  1466. X                break;
  1467. X            if (cc-- > 0)
  1468. X                *cp++ = (char)ch;
  1469. X        }
  1470. X        reread();
  1471. X        *cp = '\0';
  1472. X        if (cc < 0)
  1473. X            scanerror(T_NULL, "Symbol too long");
  1474. X        curtoken.t_str = buf;
  1475. X        return T_SYMBOL;
  1476. X    }
  1477. X    for (;;) {
  1478. X        ch = nextchar();
  1479. X        if (!issymbol(ch))
  1480. X            break;
  1481. X        if (cc-- > 0)
  1482. X            *cp++ = (char)ch;
  1483. X    }
  1484. X    reread();
  1485. X    *cp = '\0';
  1486. X    if (cc < 0)
  1487. X        scanerror(T_NULL, "Symbol too long");
  1488. X    for (kp = keywords; kp->k_name; kp++)
  1489. X        if (strcmp(kp->k_name, buf) == 0)
  1490. X            return kp->k_token;
  1491. X    curtoken.t_str = buf;
  1492. X    return T_SYMBOL;
  1493. X}
  1494. X
  1495. X
  1496. X/*
  1497. X * Read in and remember a possibly numeric constant value.
  1498. X * The constant is inserted into a constant table so further uses
  1499. X * of the same constant will not take more memory.  This can also
  1500. X * return just a period, which is used for element accesses and for
  1501. X * the old numeric value.
  1502. X */
  1503. Xstatic int
  1504. Xeatnumber()
  1505. X{
  1506. X    register char *cp;    /* current character pointer */
  1507. X    long len;        /* parsed size of number */
  1508. X    long res;        /* result of parsing number */
  1509. X
  1510. X    if (numbufsize == 0) {
  1511. X        numbuf = (char *)malloc(128+1);
  1512. X        if (numbuf == NULL)
  1513. X            error("Cannot allocate number buffer");
  1514. X        numbufsize = 128;
  1515. X    }
  1516. X    cp = numbuf;
  1517. X    len = 0;
  1518. X    for (;;) {
  1519. X        if (len >= numbufsize) {
  1520. X            cp = (char *)realloc(numbuf, numbufsize + 1001);
  1521. X            if (cp == NULL)
  1522. X                error("Cannot reallocate number buffer");
  1523. X            numbuf = cp;
  1524. X            numbufsize += 1000;
  1525. X            cp = &numbuf[len];
  1526. X        }
  1527. X        *cp = nextchar();
  1528. X        *(++cp) = '\0';
  1529. X        if ((numbuf[0] == '.') && isletter(numbuf[1])) {
  1530. X            reread();
  1531. X            return T_PERIOD;
  1532. X        }
  1533. X        res = qparse(numbuf, QPF_IMAG);
  1534. X        if (res < 0) {
  1535. X            reread();
  1536. X            scanerror(T_NULL, "Badly formatted number");
  1537. X            curtoken.t_numindex = addnumber("0");
  1538. X            return T_NUMBER;
  1539. X        }
  1540. X        if (res != ++len)
  1541. X            break;
  1542. X    }
  1543. X    cp[-1] = '\0';
  1544. X    reread();
  1545. X    if ((numbuf[0] == '.') && (numbuf[1] == '\0')) {
  1546. X        curtoken.t_numindex = 0;
  1547. X        return T_OLDVALUE;
  1548. X    }
  1549. X    cp -= 2;
  1550. X    res = T_NUMBER;
  1551. X    if ((*cp == 'i') || (*cp == 'I')) {
  1552. X        *cp = '\0';
  1553. X        res = T_IMAGINARY;
  1554. X    }
  1555. X    curtoken.t_numindex = addnumber(numbuf);
  1556. X    return res;
  1557. X}
  1558. X
  1559. X
  1560. X/*
  1561. X * Return the string value of the current token.
  1562. X */
  1563. Xchar *
  1564. Xtokenstring()
  1565. X{
  1566. X    return curtoken.t_str;
  1567. X}
  1568. X
  1569. X
  1570. X/*
  1571. X * Return the constant index of a numeric token.
  1572. X */
  1573. Xlong
  1574. Xtokennumber()
  1575. X{
  1576. X    return curtoken.t_numindex;
  1577. X}
  1578. X
  1579. X
  1580. X/*
  1581. X * Push back the token just read so that it will be seen again.
  1582. X */
  1583. Xvoid
  1584. Xrescantoken()
  1585. X{
  1586. X    rescan = TRUE;
  1587. X}
  1588. X
  1589. X
  1590. X/*
  1591. X * Describe an error message.
  1592. X * Then skip to the next specified token (or one more powerful).
  1593. X */
  1594. X#ifdef VARARGS
  1595. X# define VA_ALIST skip, fmt, va_alist
  1596. X# define VA_DCL int skip; char *fmt; va_dcl
  1597. X#else
  1598. X# ifdef __STDC__
  1599. X#  define VA_ALIST int skip, char *fmt, ...
  1600. X#  define VA_DCL
  1601. X# else
  1602. X#  define VA_ALIST skip, fmt
  1603. X#  define VA_DCL int skip; char *fmt;
  1604. X# endif
  1605. X#endif
  1606. X/*VARARGS*/
  1607. Xvoid
  1608. Xscanerror(VA_ALIST)
  1609. X    VA_DCL
  1610. X{
  1611. X    va_list ap;
  1612. X    char *name;        /* name of file with error */
  1613. X    char buf[MAXERROR+1];
  1614. X
  1615. X    errorcount++;
  1616. X    name = inputname();
  1617. X    if (name)
  1618. X        fprintf(stderr, "\"%s\", line %ld: ", name, linenumber());
  1619. X#ifdef VARARGS
  1620. X    va_start(ap);
  1621. X#else
  1622. X    va_start(ap, fmt);
  1623. X#endif
  1624. X    vsprintf(buf, fmt, ap);
  1625. X    va_end(ap);
  1626. X    fprintf(stderr, "%s\n", buf);
  1627. X    switch (skip) {
  1628. X        case T_NULL:
  1629. X            return;
  1630. X        case T_COMMA:
  1631. X            rescan = TRUE;
  1632. X            for (;;) {
  1633. X                switch (gettoken()) {
  1634. X                case T_NEWLINE:
  1635. X                case T_SEMICOLON:
  1636. X                case T_LEFTBRACE:
  1637. X                case T_RIGHTBRACE:
  1638. X                case T_EOF:
  1639. X                case T_COMMA:
  1640. X                    rescan = TRUE;
  1641. X                    return;
  1642. X                }
  1643. X            }
  1644. X        default:
  1645. X            fprintf(stderr, "Unknown skip token for scanerror\n");
  1646. X            /* fall into semicolon case */
  1647. X            /*FALLTHRU*/
  1648. X        case T_SEMICOLON:
  1649. X            rescan = TRUE;
  1650. X            for (;;) switch (gettoken()) {
  1651. X                case T_NEWLINE:
  1652. X                case T_SEMICOLON:
  1653. X                case T_LEFTBRACE:
  1654. X                case T_RIGHTBRACE:
  1655. X                case T_EOF:
  1656. X                    rescan = TRUE;
  1657. X                    return;
  1658. X            }
  1659. X    }
  1660. X}
  1661. X
  1662. X/* END CODE */
  1663. END_OF_FILE
  1664. if test 12074 -ne `wc -c <'token.c'`; then
  1665.     echo shar: \"'token.c'\" unpacked with wrong size!
  1666. fi
  1667. # end of 'token.c'
  1668. fi
  1669. echo shar: End of archive 6 \(of 21\).
  1670. cp /dev/null ark6isdone
  1671. MISSING=""
  1672. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ; do
  1673.     if test ! -f ark${I}isdone ; then
  1674.     MISSING="${MISSING} ${I}"
  1675.     fi
  1676. done
  1677. if test "${MISSING}" = "" ; then
  1678.     echo You have unpacked all 21 archives.
  1679.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1680. else
  1681.     echo You still need to unpack the following archives:
  1682.     echo "        " ${MISSING}
  1683. fi
  1684. ##  End of shell archive.
  1685. exit 0
  1686.