home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume14 / pac / part01 next >
Encoding:
Text File  |  1990-08-03  |  48.3 KB  |  1,237 lines

  1. Newsgroups: comp.sources.misc
  2. keywords: Not For SunOS 3.x
  3. subject: v14i039: pac - the ultimate UNIX calculator, part 1 of 5
  4. From: istvan@hhb.UUCP (Istvan Mohos)
  5. Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  6.  
  7. Posting-number: Volume 14, Issue 39
  8. Submitted-by: istvan@hhb.UUCP (Istvan Mohos)
  9. Archive-name: pac/part01
  10.  
  11. The panel calculator "pac" (posted to comp.sources.misc in 5 parts)
  12. has been dubbed "the ultimate on-screen calculator for UNIX" by the
  13. network monitor of The C User's Journal (Volume 7, Number 8).  Major
  14. features include:
  15.  
  16. o   16 cells nonvolatile memory (checkbook balance, phone numbers, etc.)
  17. o   asynchronous real-time clock
  18. o   separate checkbook balancer window (for summing lists of numbers)
  19. o   ASCII to decimal to octal to hex translation (find out what ^M is)
  20. o   22 predefined conversions (metric, temperature, etc.)
  21. o   user-definable, non-volatile conversions (dollar to yen, etc.)
  22. o   compound interest/mortgage payment solver (play the "what if?" game)
  23. o   amortization schedule (monthly payment list) file writer
  24. o   function help window (type "help" or just "?" or "help [subject]")
  25. o   optional automatic calculator session recording to files
  26. o   trigonometric functions
  27. o   number base conversions (independent in/out bases, between 2 and 16)
  28. o   programmable precision: btw 0 and 32 digits past the decimal point
  29. o   bitwise AND, OR, NOT, XOR, TWOSCOMP
  30. o   fully automatic and accessible push/pop stack memory
  31. o   pi, planck, parallax, parsec... 30 math/physical constants in all
  32. o   macro tokens from "atto" to "exa" (for ex: "356 micro + 125 milli")
  33. o   predefined percent calculations (for ex: "65.7 p[ercent]of 290")
  34.  
  35. For its engine, "pac" uses interprocess pipes to the "bc" calculator.
  36. The posted source has been successfully compiled and tested on:
  37. Pyramid 90x, VAX 11-785, Apollo Domain-IX, Sun SPARCstation 1,
  38. AT&T 6300+, Xenix286, DEC 8600.
  39. "pac" will NOT work on SunOS 3.x systems due to bugs in SunOS "curses".
  40.  
  41. ==============================CUT HERE==============================
  42. #!/bin/sh
  43. # This is a shell archive (shar 3.21)
  44. # made 07/25/1990 19:26 UTC by istvan@istvan
  45. # Source directory /rand/istvan/pac
  46. #
  47. # existing files WILL be overwritten
  48. #
  49. # This shar contains:
  50. # length  mode       name
  51. # ------ ---------- ------------------------------------------
  52. #   1635 -rw-r--r-- Relnotes
  53. #  27117 -rw-r--r-- pac.man
  54. #    382 -rw-r--r-- README
  55. #    881 -rw-r--r-- makefile
  56. #  13508 -rw-r--r-- defs.h
  57. #  14314 -rw-r--r-- maps.h
  58. #   7256 -rw-r--r-- toktab.h
  59. #   7762 -rw-r--r-- amort.c
  60. #   6366 -rw-r--r-- atoi.c
  61. #   5666 -rw-r--r-- bitwise.c
  62. #  13160 -rw-r--r-- conv.c
  63. #   7993 -rw-r--r-- convbase.c
  64. #  11737 -rw-r--r-- display.c
  65. #   3940 -rw-r--r-- error.c
  66. #   7596 -rw-r--r-- file.c
  67. #   7333 -rw-r--r-- help.c
  68. #    871 -rw-r--r-- ierror.c
  69. #  23768 -rw-r--r-- interpret.c
  70. #   6967 -rw-r--r-- ledit.c
  71. #   3586 -rw-r--r-- onlay.c
  72. #   6229 -rw-r--r-- pac.c
  73. #   5676 -rw-r--r-- pactok.c
  74. #   1805 -rw-r--r-- pipes.c
  75. #   3746 -rw-r--r-- stack.c
  76. #   3735 -rw-r--r-- system.c
  77. #   3249 -rw-r--r-- time.c
  78. #   8736 -rw-r--r-- total.c
  79. #     48 -rw-r--r-- version.c
  80. #   4228 -rw-r--r-- work.c
  81. #
  82. if touch 2>&1 | fgrep '[-amc]' > /dev/null
  83.  then TOUCH=touch
  84.  else TOUCH=true
  85. fi
  86. # ============= Relnotes ==============
  87. echo "x - extracting Relnotes (Text)"
  88. sed 's/^X//' << 'SHAR_EOF' > Relnotes &&
  89. XPac is a slightly overambitious visual calculator for Unix systems.
  90. XIn spite of its minor structural problems, pac is the
  91. X"everything you ever wanted in a calculator" calculator, providing:
  92. X
  93. Xo   16 cells nonvolatile memory (checkbook balance, phone numbers, etc.)
  94. Xo   asynchronous real-time clock
  95. Xo   separate checkbook balancer window (for summing lists of numbers)
  96. Xo   ASCII to decimal to octal to hex translation (find out what ^M is)
  97. Xo   22 predefined conversions (metric, temperature, etc.)
  98. Xo   user-definable, non-volatile conversions (dollar to yen, etc.)
  99. Xo   compound interest/mortgage payment solver (play the "what if?" game)
  100. Xo   amortization schedule (monthly payment list) file writer
  101. Xo   function help window (type "help" or just "?" or "help [subject]")
  102. Xo   optional automatic calculator session recording to files
  103. Xo   trigonometric functions
  104. Xo   number base conversions (independent in/out bases, between 2 and 16)
  105. Xo   programmable precision: btw 0 and 32 digits past the decimal point
  106. Xo   bitwise AND, OR, NOT, XOR, TWOSCOMP
  107. Xo   fully automatic and accessible push/pop stack memory
  108. Xo   pi, planck, parallax, parsec... 30 math/physical constants in all
  109. Xo   macro tokens from "atto" to "exa" (for ex: "356 micro + 125 milli")
  110. Xo   predefined percent calculations (for ex: "65.7 p[ercent]of 290")
  111. X
  112. XThe pac process forks pipes to the 'bc' Unix calculator.
  113. XThe posted source has been successfully compiled and tested on:
  114. XPyramid 90x, VAX 11-785, Apollo Domain-IX, Sun SPARCstation 1,
  115. XAT&T 6300+, Xenix286, DEC 8600.
  116. X
  117. XPac will NOT work on Sun2 or Sun3 computers due to insoluble problems
  118. Xin their implementation of "curses".
  119. X
  120. SHAR_EOF
  121. $TOUCH -am 0221175390 Relnotes &&
  122. chmod 0644 Relnotes ||
  123. echo "restore of Relnotes failed"
  124. set `wc -c Relnotes`;Wc_c=$1
  125. if test "$Wc_c" != "1635"; then
  126.     echo original size 1635, current size $Wc_c
  127. fi
  128. # ============= pac.man ==============
  129. echo "x - extracting pac.man (Text)"
  130. sed 's/^X//' << 'SHAR_EOF' > pac.man &&
  131. X.TH PAC 1 ""
  132. X.UC 4
  133. X.SH NAME
  134. X.nh
  135. X\fBpac\fR - panel calculator
  136. X.SH SYNOPSIS
  137. X.B pac
  138. X.SH DESCRIPTION
  139. X\fBpac\fR is an interactive calculator,
  140. Xresembling a ``panel'' or ``page'' editor.
  141. XThe interface is simple: the user enters
  142. Xnumbers and arithmetic operators, \fBpac\fR displays the result.
  143. XAlternate capabilities to the CALCULATOR include an
  144. XASCII to decimal to octal to hexadecimal converter ATOI,
  145. Xa checkbook balancer TOTAL,
  146. Xa loan payment and amortization program LOAN, an
  147. Xeditor for the expandable ``conversions data base'' NEWCONVERSION,
  148. Xtime of day CLOCK; as well as session recording to files.
  149. XOperating the alternate capabilities is intuitively obvious
  150. Xand is helped along by the format of the display.
  151. X.LP
  152. XThe \fBpac\fR panel is a screen 23 lines by 78 characters,
  153. Xpartitioned by inverse video borders into
  154. Xsubwindows.  The CALCULATOR
  155. Xis a rectangle 4 lines deep by 44 characters wide,
  156. Xlocated in the upper left corner of the panel,
  157. Xsimulating a hand-held calculator: echoing numbers and
  158. Xoperators typed to the first three
  159. Xlines, displaying the evaluated result
  160. Xin the fourth line upon \fIRETURN\fR.  Control characters,
  161. Xshown along the borders as first characters of mnemonics,
  162. Xprovide immediate state switching to and from alternate tools.
  163. X.SH LINE EDITING
  164. XA selected function comes to life with the cursor
  165. Xin the home position of a subwindow managed by the function.
  166. XThe user directs input to this portion of the screen under the
  167. Xcontrol of a primitive line editor.
  168. X.LP
  169. XNormally the typed characters are echoed and contribute to
  170. Xthe input string.  Characters which the
  171. Xtool is not equipped to deal with are not echoed, and are ignored
  172. Xby the editor.  Control characters (also not echoed)
  173. Xselect alternate tools, or
  174. Xprovide exit from the program.  A number of keys are commands to
  175. Xthe line editor only, allowing cursor positioning and input correction.
  176. XThe editor keys and their effect may vary slightly,
  177. Xdepending on the currently active \fBpac\fR tool.
  178. X.LP
  179. XThe first character echoed to a line,
  180. Xnormally erases the previous input string.
  181. XIn the CALCULATOR function, the line editing \fI=\fR key
  182. Xrestores the old input string for editing.  A string beginning
  183. Xwith the \fI#\fR character is considered a comment.
  184. XComments are helpful if the user is recording the session, or
  185. Xfor annotating scripts.
  186. XAnother line editing character specific to the CALCULATOR
  187. Xwindow is the pipe (|), which
  188. Xbrings the cursor to the left edge of the following window line.
  189. X.LP
  190. XIf the input string reaches the
  191. Xright line boundary, additional characters overwrite the rightmost
  192. Xcharacter, except in the CALCULATOR function where the three lines of
  193. Xthe input window conceptually form a single string.
  194. XTyping \fIRETURN\fR triggers the interpretation of the input string.
  195. XRegardless of the cursor position at the time of \fIRETURN\fR,
  196. Xall data on the line is evaluated.  If the user did not type
  197. Xcharacters prior to \fIRETURN\fR, a repeat of the previous string,
  198. Xor a tool-specific default string is the assumed input.
  199. X.LP
  200. XA summary of the edit keys is always visible in an inverse video bar
  201. Xrunning vertically in the center of the screen.
  202. XEditing characters include \fIDELETE\fR and \fIBACKSPACE\fR,
  203. Xboth of which delete characters
  204. Xunder the cursor and move bytes at the right of the cursor
  205. Xto the left.
  206. X.LP
  207. X\fIControl-C\fR in the CALCULATOR function, \fISPACE\fR in the
  208. Xcheckbook balancer function, clear a line from the cursor to
  209. Xits end; in the checkbook balancer function a \fIControl-C\fR
  210. Xclears (zeroes) the entire window.
  211. XStraight brackets \fI[  ]\fR move the
  212. Xthe cursor non-destructively to the left or right.
  213. XIn the CALCULATOR function, curly braces \fI{  }\fR move the cursor
  214. Xto the line above or below, while
  215. Xthe ``greater than''
  216. Xsign \fI>\fR switches to \fIinsert mode\fR:
  217. Xcharacters already to the right of the
  218. Xcursor are pushed further to the right with each new character added.
  219. XThe ``less than'' sign \fI<\fR, the \fIESCAPE\fR key or a
  220. X\fIRETURN\fR end the \fIinsert mode\fR.
  221. X.SH CALCULATOR OPERATION
  222. XInput begins at the top left byte of the CALCULATOR window,
  223. Xand may consist of multiple statements separated
  224. Xby semicolons.  After \fIRETURN\fR, the input is broken down
  225. Xto a list of tokens.
  226. XCompound tokens contain one or more alphanumeric characters,
  227. Xunderscores and periods; simple tokens are single,
  228. Xnon-alphanumeric characters from the set:
  229. X.LP
  230. X.RS
  231. X; % + - * / ^ ( ) \\ ' ? ! #
  232. X.RE
  233. X.LP
  234. XA subset of simple tokens are the math operators
  235. X\fI%\fR, \fI+\fR or \fI-\fR, \fI*\fR or \fI/\fR, \fI^\fR
  236. X(in increasing order of operator precedence).
  237. XThe percent sign stands for the ``modulo'' operation, the asterisk
  238. Xstands for multiplication, the circumflex for exponentiation.
  239. XOnly integer exponents are allowed.
  240. X.LP
  241. XTokens are delimited by commas or spaces, by the appearance of the
  242. Xnext simple token, or by the end of the input line.
  243. X.LP
  244. XNumbers are a subset of compound tokens, formed entirely from
  245. Xthe digits 0-9, the hexadecimal digits a-f or A-F, and the
  246. Xperiod character.
  247. X.LP
  248. XDuring parsing, commas and spaces are removed, and successive
  249. Xnumbers are concatenated to form a single number.
  250. X.LP
  251. XThe resulting token list is passed to the interpreter, which
  252. Xevaluates each token in a normal, left-to-right sequence.
  253. XA \fBpac\fR lookup table is searched for a match to the token.
  254. XA match proves the token to be a \fBpac\fR control word, processed
  255. Ximmediately.  This preprocessing may affect other tokens to
  256. Xthe left or right of the control word; and in most cases the
  257. Xaffected tokens (including the control word) are replaced
  258. Xby a single number.
  259. X.LP
  260. XIf the token does not match a control word, any lower case a-f
  261. Xcharacters of the token are upcased.
  262. X.LP
  263. XFrom the interpreter, the string
  264. Xis passed to the \fBbc\fR calculator
  265. Xthrough an inter-process pipe.
  266. XBc evaluates the math expression,
  267. Xand returns the result to \fBpac\fR for
  268. Xformatting and display.  \fBpac\fR
  269. Xprints the result in the fourth (bottom)
  270. Xline of the CALCULATOR window.
  271. X.LP
  272. XThe \fIprecision\fR variable controls
  273. Xthe number of digits printed to the right of a decimal point.  This
  274. Xvariable can be set with the \fIprecision n\fR  or 
  275. X\fIpr n\fR command; n values may range from 0 to 32.
  276. XResults with greater than \fIprecision\fR fractional digits
  277. Xare rounded.  Fractions too small to show up within the
  278. Xprecision range cause an underflow error.  User selectable number
  279. Xformatting and justification controls the final
  280. Xappearance of the result.
  281. X.LP
  282. XExamples of CALCULATOR input:
  283. X.LP
  284. X.nf
  285. X.RS
  286. X.ta \w'(998 \fImicro\fR + .000002)\fImega\fR'u+2n
  287. X77+88+99 - 66/(3 * 2)
  288. X4.5  *  \fIpi\fR    ---  using the constant \fIpi\fR
  289. X12.785 + \fIs\fR    ---  add 12.785 and stack variable \fIs\fR
  290. X12.785 + \fIs\fR; \fIsto j\fR    ---  as above; copy result into \fIj\fR
  291. Xf + a    ---  add hex numbers (dec15 + dec10)
  292. X\fIp\fR + \fIq\fR    ---  add stack variables \fIp\fR and \fIq\fR
  293. X3.3^4    ---  the fourth power of 3.3
  294. X27^ (-3)    ---  1 / 19683
  295. X7! - 99    ---  factorial of 7, minus 99
  296. X(-5) * 40    ---  using the unary minus
  297. X(998 \fImicro\fR + .000002)\fImega\fR    ---  1000
  298. X32/(16/(8/(4/(\fIm\fR * 2/\fIm\fR))))    ---  8 (if stack variable \fIm\fR not equal 0)
  299. X+10    ---  add 10 to the previous result
  300. X-10    ---  subtract 10 from the previous result
  301. X- 60 / 3    ---  subtract 20 from the previous result
  302. X* 5    ---  multiply previous result by 5
  303. X.RE
  304. X.fi
  305. X.LP
  306. X\fBpac\fR stores results as digit strings, on 17 lines of screen
  307. Xdisplay.  Each of the strings is a \fBpac\fR variable.
  308. XThe first of these strings, CURRES,
  309. Xis the result shown in the CALCULATOR window.
  310. XCURRES is updated continuously and is
  311. Xthe result of the most recently evaluated expression.  This value
  312. Xcan be referenced by the \fI\\\fR (backslash) character:
  313. X\fI9 + \\\fR adds CURRES and 9.  Any operator that unsuccessfully
  314. Xlooks for an operand to its left, will automatically reference
  315. XCURRES
  316. X(as in the last four ``Examples of CALCULATOR input'' above).
  317. XSyntax errors clear CURRES to zero.
  318. X.LP
  319. XThe other 16 strings constitute the \fIuser stack\fR,
  320. Xa rectangular area directly below the CALCULATOR window.
  321. XThe 16 lines of the stack are
  322. Xlabeled by the letters \fIh\fR to \fIw\fR
  323. Xin the left inverse video border.
  324. XThese labels are also \fBpac\fR tokens, and can be input to
  325. Xthe CALCULATOR instead of typing the string contained in a stack cell.
  326. XNew results are automatically ``pushed'' on the stack, unless the
  327. X\fBpac\fR command \fIstack off\fR prohibits this.
  328. X.LP
  329. X\fBpac\fR key words for explicitly
  330. Xmanipulating stack contents are
  331. X\fIclr\fR, \fIdup\fR, \fIpop\fR, \fIpll\fR, \fIpsh\fR,
  332. X\fIsto\fR, \fIswp\fR.
  333. XThese operators can be input to the CALCULATOR regardless
  334. Xof whether the stack is \fIon\fR or \fIoff\fR.
  335. XA stack operator normally references the single-character
  336. Xstack label immediately following the operator.
  337. XFor example, \fIpop m\fR removes the number contained in \fIm\fR,
  338. Xand moves all stack strings located below \fIm\fR up one position;
  339. X\fIclr p\fR substitutes the number in stack cell \fIp\fR with zero.
  340. XIf a stack label is not given,
  341. XCURRES is the subject of the stack operation, except that \fIclr\fR,
  342. Xreplaces the value of each stack variable with 0.
  343. X.LP
  344. XThe \fBpac\fR keyword \fIibase\fR (abbreviated version: \fIib\fR)
  345. Xfollowed by an integer or a variable in the range of 2 through 16,
  346. Xcan select an input base other than decimal.
  347. XThe command
  348. X.LP
  349. X.RS
  350. X\fIib\fR 2; 1011 0100 0010
  351. X.RE
  352. X.LP
  353. Xas an example, results in
  354. Xthe decimal display of ``2882''.
  355. X.LP
  356. XThe effect of the \fIib\fR command lasts from the time it was
  357. Xfirst encountered in the input, to the end of the
  358. Xinput string; then \fBpac\fR automatically
  359. Xreverts to the original input base.
  360. XTo permanently change the input base,
  361. Xthe command \fIstaybase on\fR
  362. X(abbreviated version: \fIsb\fR) should be issued.
  363. XThe effect of \fIstaybase on\fR lasts until
  364. Xa \fIstaybase off\fR commands cancels it.
  365. XOutput radix is similarly controlled by the \fIobase n\fR
  366. X(or \fIob n\fR) command for n values 2-16; and
  367. X\fIstaybase\fR effects the permanence of input
  368. Xand output radices in tandem.
  369. X.LP
  370. XSome useful CALCULATOR operators are:
  371. X.RS
  372. X.TP "\\w'the conversion operator\ \ 'u
  373. Xthe bitwise operations
  374. X\fIand or xor not twoscomp\fR (abbr.:\fItc\fR)
  375. X.TP
  376. Xthe percent operations
  377. X\fIpplus pminus pdiff pversus pequal pof\fR (abbr.: \fIpp pm pd pv pe po\fR)
  378. X.TP
  379. Xthe conversion operator
  380. X\fIto\fR
  381. X.RE
  382. X.LP
  383. XExamples:
  384. X.LP
  385. X.nf
  386. X.ta 3i +1.5i
  387. XBinary AND of 9999 and 122:    9999 \fIand\fR 122    ---  10
  388. XBinary NOT of 9999 in 16 bit wide field:    9999 \fInot\fR 16    ---  55536
  389. XAdd 6.5 percent to 3500:    3500 \fIpplus\fR 6.5    ---  3727.5
  390. XPercentage increase from 3300 to 3500:    3300 \fIpdiff\fR 3500    ---  6.06
  391. XIf 4778 is 100%, what % is 2389:    4778 \fIpversus\fR 2389    ---  50
  392. XWhat is 75% of 4000:    75 \fIpof\fR 4000    ---  3000
  393. XIf 40% of a sum is 50, what is the sum:    40 \fIpequal\fR 50    ---  125
  394. XConvert 1225 inches to centimeters:    1225 \fIto cm\fR    ---  3111.5
  395. X.fi
  396. X.LP
  397. XThe \fBpac\fR tokens
  398. X\fIsin\fR(x), \fIcos\fR(x), \fIexp\fR(x), \fIlog\fR(x), \fIarct\fR(x)
  399. Xare used as substitutes for the \fBbc\fR
  400. X``s(x), c(x), e(x), l(x), a(x)'' functions, respectively.
  401. XInput values and results are radians.
  402. X.SH CALCULATOR ENVIRONMENT
  403. XEnvironment control operators are used to customize
  404. Xthe CALCULATOR to the user's liking.
  405. XAs with the other \fBpac\fR tokens, a certain redundancy is apparent
  406. Xin naming the variables: two-character abbreviations are
  407. Xgenerally accepted as input tokens.
  408. X.LP
  409. XWhen exiting \fBpac\fR, an attempt is made to
  410. Xwrite a
  411. X``.pacrc'' file in the user's home\fR directory, unless the
  412. X\fIdontsave\fR command expressly forbids this.  In the .pacrc
  413. Xfile, \fBpac\fR keeps a record of the current panel environment.  The
  414. Xfile also contains the sixteen stack strings, and the
  415. Xup-to-date ``units conversions list'' described under
  416. XEDITING THE CONVERSIONS LIST, with any modifications
  417. Xeffected by the user. Subsequent calls to
  418. X\fBpac\fR begin by reading and resetting internal parameters
  419. Xfrom the file data.
  420. X.LP
  421. XTo the right of the stack, the narrower GLOBALS window lists the
  422. Xenvironment control operators and their current values.
  423. XThe state-switching \fIControl-G\fR character
  424. Xoverlays the GLOBALS window with a STATUS OPTIONS window, which
  425. Xshows the abbreviated name of each control operator token, followed
  426. Xby the values that this operator may assume.
  427. XA second \fIControl-G\fR toggles the STATUS OPTIONS
  428. Xwindow display back to GLOBALS,
  429. Xunless the execution of a CALCULATOR string has already caused
  430. Xthe re-display of the GLOBALS window.
  431. X.LP
  432. XThe variables \fIjustify\fR, \fIformat\fR,
  433. X\fIhardform\fR, and \fIautotime\fR
  434. Xcontrol the format of the \fBpac\fR display screen, and control
  435. Xthe format of the file records.
  436. XThe command \fIjustify left\fR
  437. X(abbreviated: \fIju le\fR) instructs \fBpac\fR
  438. Xto position the leftmost digit of the
  439. Xresult in the bottom leftmost position of the CALCULATOR window.
  440. XConversely, \fIjustify right\fR
  441. X(abbreviated: \fIju ri\fR) specifies that the rightmost digit of the
  442. Xresult be placed in the bottom rightmost
  443. XCALCULATOR window position.
  444. XAs a special case of \fIjustify right\fR,
  445. X\fIjustify fix\fR outputs the result
  446. Xin a fixed decimal point format.  In fixed
  447. Xjustification, the number of digits displayed to
  448. Xthe right of the decimal point is constant: the value of the
  449. X\fIprecision\fR variable (0 through 32).
  450. XThe \fIformat space\fR or \fIformat comma\fR
  451. X(abbreviated: \fIsp\fR and \fIcm\fR)
  452. Xcommand specifies that CURRES values are
  453. Xto be displayed with spaces or commas respectively,
  454. Xbetween groups of digits;
  455. Xthis makes it easier to read long strings.
  456. X.LP
  457. XThe \fIhardform\fR command controls the format of a
  458. Xrecording file which can be opened for writing with the \fIControl-F\fR
  459. X(File)
  460. Xcharacter, or for appending with the \fIControl-P\fR
  461. X(Postpend)
  462. Xcharacter.  The user is prompted for a file name; ``hardcopy'' is the
  463. Xdefault.  Having opened the file, a new
  464. X\fIControl-F\fR or \fIControl-P\fR will close it, otherwise the file
  465. Xwill record calculator transactions until the exit from \fBpac\fR.
  466. XThe command \fIhardform verbose\fR (abbreviated: \fIver\fR) resets
  467. Xto the default file output format, saving
  468. Xboth input and results, with
  469. Xrecords separated by horizontal lines of dashes.
  470. XThe commands \fIhardform terse\fR
  471. X(\fIte\fR) and \fIhardform xterse\fR (\fIxt\fR) specify
  472. Xsuccessively denser session recording.
  473. X.LP
  474. XThe command: \fIautoconv\fR automatically applies the selected
  475. Xunit conversion formula to each new evaluation (CURRES)
  476. Xprior to displaying the result.  For example, a list of dollar figures
  477. Xmay be converted to pounds just by entering each dollar value.
  478. X.LP
  479. XThe macro command: \fIinit\fR resets the format, hardform,
  480. Xibase, obase, justify, precision, stack, staybase, and
  481. Xautoconv parameters to their default values.
  482. X.LP
  483. XThe special combination \fIhelp [token]\fR
  484. X(or its abbreviated form \fI? [token]\fR)
  485. Xoverlays the stack area with a portion of the token list,
  486. Xhighlighting the selected token.  To the right of each
  487. Xtoken  of the list, a very brief summary
  488. Xof the token action is printed.  Stack display
  489. Xresumes at the first subsequent stack activity.
  490. X.SH ASCII CONVERSIONS
  491. XDirectly to the right of the CALCULATOR window, a small rectangle
  492. Xprovides immediate conversion between ASCII characters and their
  493. Xdecimal, octal, or hexadecimal values, on a per-character basis.
  494. XThe window is titled ATOI, and initially contains the following prompts:
  495. X.LP
  496. X.RS
  497. X.nf
  498. X^ A  asc
  499. X^ D  dec
  500. X^ O  oct
  501. X^ X  hex
  502. X.RE
  503. X.fi
  504. X.LP
  505. XThe characters preceded by the caret \fI^\fR stand for the control
  506. Xcharacters which cause temporary
  507. Xtransition from the CALCULATOR state
  508. Xto the ATOI window.  \fIControl-A\fR prompts the user to enter
  509. Xany character on the top line of the ATOI window,
  510. Xand immediately displays the decimal, octal,
  511. Xand hex equivalents of this character beneath the input.
  512. XContext then returns to the CALCULATOR.
  513. X\fIControl-D\fR similarly, prompts for a decimal value
  514. Xin the top line, in the 0-127 range.  Following a \fIRETURN\fR,
  515. Xthe ASCII equivalent of the decimal
  516. Xvalue, as well as the octal and hexadecimal versions are printed.
  517. X\fIControl-O\fR prompts for an octal number
  518. Xbetween \\000 and \\177; \fIControl-X\fR
  519. Xprompts for a hexadecimal value between 0x0 and 0x7f.
  520. XValues out of the
  521. XASCII range are ignored, and the cursor stays on the first
  522. Xline of the ATOI window until a legal value is selected.
  523. X.SH AMORTIZATION
  524. X\fIControl-L\fR (LOAN) changes context and moves the cursor
  525. Xto the loan amortization window below ATOI.
  526. XA second \fIControl-L\fR returns the user to the previous context.
  527. XThe top three lines of the LOAN window are labeled
  528. X``AMT'', ``%'', and ``YRS'' in the inverse video border to the
  529. Xleft.  The user is expected to input a decimal string
  530. Xas the ``loan amount'' (principal)
  531. Xon the ``AMT'' line, an amortization (percent) rate in the second line,
  532. Xand the life term of the loan (in years) on the third line.
  533. XUp to two digits past the decimal point are significant
  534. Xfor both the principal and the life term values,
  535. Xthree digits past the decimal point are significant for
  536. Xthe percent rate.
  537. X.LP
  538. XWhen all
  539. Xthree lines contain non-zero values, the monthly payment on the proposed
  540. Xloan is immediately displayed in the fourth line of the window, and the
  541. Xcursor wraps back to the first line.  The user can now
  542. Xrepeatedly adjust the amount, rate, or term values in an infinite loop,
  543. Xby simply
  544. Xtyping over the old values.  Each change causes an immediate update of
  545. Xthe monthly payment figure.
  546. X.LP
  547. XTo dump the actual monthly amortization schedule to a file,
  548. X\fIControl-B\fR
  549. Xmoves the cursor to the last line of the LOAN window, where the
  550. Xmonth/year date of the first payment is entered; then the user is
  551. Xprompted for a file name on the bottom of the screen.  The amortization
  552. Xfile creation involves substantial floating point math and string
  553. Xformatting, and takes a few seconds to complete.
  554. X.LP
  555. XThe author has gleaned the amortization algorithm from
  556. Xexamining actual bank loan printouts.
  557. XWhile the \fBpac\fR method duplicates
  558. Xthe bank samples exactly, different methods of rounding
  559. Xmay possibly be employed by other lending institutions, resulting in
  560. Xminor discrepancies between the two sets of figures.
  561. X.SH CHECKBOOK BALANCER
  562. XCashier's lists, checkbook tallies, score keeping, and
  563. Xa number of book keeping activities involve entering and summing
  564. Xvalues in columnar format.
  565. X\fIControl-T\fR switches \fBpac\fR to the TOTAL window
  566. Xdirectly overlaying the CONVERSIONS list.
  567. XInitially, the TOTAL window consists of 19 lines
  568. Xof zero values, and a bottom ``total'' line.
  569. XThe lines are labeled in the
  570. Xright inverse video border by the lower case letters \fIa\fR through
  571. X\fIs\fR, and the ``total''
  572. Xline is labeled by \fIt\fR.  As the
  573. Xuser types in decimal values (followed by \fIRETURN\fR)
  574. Xthe cursor advances to the next lower line, and the entered values are
  575. Xautomatically summed to ``total''.
  576. X.LP
  577. XAt each \fIRETURN\fR, the most recently typed value is re-formatted
  578. Xright justified, with the number of fractional digits
  579. Xdictated by the user environment'
  580. Xprecision value.  Negative values
  581. Xare subtracted from the total.  The line may also
  582. Xcontain a single \fI*\fR or \fI@\fR character, to effect
  583. Xprice multiplication by item count.  As an example, ``64 @ 9.17''
  584. Xis immediately converted to ``586.88''.
  585. X.LP
  586. XWhen nineteen items have already been entered and the cursor is
  587. Xin line \fIs\fR, the input window wipes
  588. Xitself clean and copies the current total
  589. Xto the top line.  The cursor is then positioned at the beginning of the
  590. Xsecond line, and the entry process can continue indefinitely.  It is
  591. Xconvenient to refer to this paging
  592. Xevent as a ``subtotal''.  At subtotal,
  593. Xas well as at the exit from the TOTAL function,
  594. Xthe current total is pushed into stack cell \fIh\fR (the top
  595. Xvisible element of the user stack on the left side).  If the user stack
  596. Xis \fIon\fR, its elements are shifted down one line, potentially
  597. Xretaining a sequence of subtotal values.  The calculator
  598. XCURRES value
  599. Xis not affected by subtotals; the user must explicitly reference the
  600. Xappropriate stack cells to transfer values to the
  601. XCALCULATOR window for input.
  602. X.LP
  603. XSimilarly to the ``hardcopy''
  604. Xfile used for keeping an automatic record of CALCULATOR
  605. Xactivities, a separate ``hardtotal'' file may be opened
  606. Xfor \fIwrite\fR or \fIappend\fR
  607. Xwhile the checkbook balancer is active.
  608. X``Hardtotal'' is supplied as the default file name, unless
  609. Xthe user types in another name.
  610. XThe file continues receiving snapshots of the entire TOTAL window at
  611. Xevery subtotal (except receiving only the subtotal values
  612. Xif the \fBpac\fR \fIhardform\fR variable is set to \fIxterse\fR),
  613. Xand a final snapshot on exit from the TOTAL window.
  614. X.LP
  615. XTOTAL interprets decimal numbers only. In
  616. Xaddition to digits, \fI+ - * @\fR and the normal line editing
  617. Xcharacters, the TOTAL line editor also accepts
  618. Xthe letters \fIa\fR through \fIt\fR and \fIA\fR through \fIT\fR.
  619. XThe lower case letters cause the value in the corresponding line to
  620. Xbe replicated in the line of the cursor
  621. X(\fIt\fR replicates the current total).  Upper case 
  622. Xalphabetics \fIA\fR through \fIS\fR relocate the cursor
  623. Xto the line labeled by the corresponding
  624. Xlower case letter; input then continues from this line.
  625. XWhen the cursor is relocated this way, the digit string
  626. Xalready in the line is not cleared; the new input will be
  627. Xprepended to it.  A space typed clears the line from the cursor
  628. Xto its end.
  629. XUpper case \fIT\fR forces a stack push of the current total,
  630. Xand the snapshot of the window written to an open ``hardtotal'' file.
  631. XThe \fI#\fR character
  632. Xis again a comment delimiter,
  633. Xsignaling the editor to ignore it and any further input
  634. Xuntil the \fIRETURN\fR.
  635. XA second \fIControl-T\fR provides return to the previous context.  A
  636. X``hardtotal''
  637. Xfile may be explicitly closed prior to exiting TOTAL, or
  638. Xit may be left open, awaiting recording of further TOTAL activities.
  639. XEven after exiting TOTAL, the window remains visible over the
  640. XCONVERSIONS list until a CALCULATOR conversion takes place.
  641. X.SH EDITING THE CONVERSIONS LIST
  642. XUnit conversion operations of the CALCULATOR
  643. Xare based on a conversions data base, shadowed from a static list
  644. Xinto dynamically allocated memory at initialization, and
  645. Xmodifiable by the user.
  646. XThe NEWCONVERSION editor for the conversions database
  647. Xis entered with a \fIControl-N\fR,
  648. Xtypically to add new conversions defined by the user,
  649. Xbut occasionally to remove existing conversions, or to alter current
  650. Xconversion factors.
  651. X\fBpac\fR conversions are unidirectional,
  652. Xconverting from units \fIA\fR to units \fIB\fR.
  653. XSeparate conversions must be defined to convert from dollars to
  654. Xpounds, and from pounds to dollars, for example.
  655. XAn altered exchange rate between the dollar and the
  656. Xpound may prompt the user to update the dollar-to-pound
  657. Xand pound-to-dollar formulae.
  658. X.LP
  659. XEditing the conversions data base begins in a temporary window
  660. Xoverlaying the CALCULATOR window.
  661. XThe user is prompted to select between adding, removing
  662. Xor altering a conversion.  Next the user enters a key
  663. Xup to three characters long.
  664. X.LP
  665. XIf the removal or the alteration
  666. Xof an existing conversion is selected,
  667. Xthe ``conversion keys list'' is searched for a matching key;
  668. Xthe key may be re-entered on error until a match is found.  When
  669. Xchanging an already existing conversion, the user enters a new key
  670. X(up to three bytes long) as the altered key value.
  671. XFor the pound-to-dollar conversion, let's assume the key \fIus\fR.
  672. XA new conversion key is inserted in
  673. Xthe key list in alphabetical order.
  674. XA thirteen characters long reference label is typed in next (typically
  675. Xa ``from-units to-units'' pair), as a visual
  676. Xreminder of the meaning of the key.  In our example, this may simply be
  677. X\fIpound  dollar\fR.
  678. X.LP
  679. XThe new formula is entered at the bottom inverse video
  680. Xbar.  The character set of the formula is limited to
  681. Xdigits, math operators \fI+ - * / ^ %\fR,
  682. Xdecimal point, left and right parentheses,
  683. Xand the backslash character \fI\\\fR.
  684. XNormal line editing characters may be
  685. Xused to correct errors.  All numbers are assumed to be decimal.
  686. XGiven the exchange rate of 1.75 dollars to the pound,
  687. Xthe ``X pounds = Y dollars'' equation could be stated as
  688. X``Y = X * 1.75'' and entered as
  689. X.LP
  690. X.RS
  691. X\\ * 1.75
  692. X.RE
  693. X.LP
  694. Xinto the data base.  When the formula is invoked in a later
  695. XCALCULATOR conversion such as ``900 \fIto us\fR'',
  696. Xthe backslash standing for X in the solution, will be substituted by
  697. X``900'', followed by the multiplication by the constant to get
  698. Xthe new (converted) value.  Though the conversion list
  699. Xis stored in decimal format,
  700. Xduring calculations the constant strings are
  701. Xautomatically re-cast into the input radix in effect.
  702. XThe converse operation: dollars to pounds, would have a different key,
  703. Xa different label, and the following conversion formula:
  704. X.LP
  705. X.RS
  706. X\\ / 1.75
  707. X.RE
  708. X.LP
  709. XMore complex formulae are feasible; the formula need not start with a
  710. Xbackslash; multiple backslashes may occur.
  711. XHaving finished with the editing of the conversion, the most recently
  712. Xadded conversion is shown selected in the center
  713. Xof the CONVERSIONS window.  Context reverts to the calling tool.
  714. X.SH CLOCK
  715. X\fIControl-K\fR installs a date/hour/minute clock in the
  716. Xright corner of the top inverse video border.
  717. XTime is kept in a twelve-hour format; a period
  718. Xfollowing the minutes denotes PM.  The clock operates asynchronously
  719. Xand without affecting the rest of the program.  A second \fIControl-K\fR
  720. Xturns off the clock.
  721. XThe \fBpac\fR environment variable \fIautotime\fR may be enabled,
  722. Xwith the effect that the clock appears automatically on entry to
  723. Xthe program.
  724. X.SH EXIT
  725. X\fIControl-E\fR resets
  726. Xthe terminal to cooked mode, writes the .pacrc file
  727. X(containing the \fBpac\fR environment variables, stack, and the
  728. Xconversion list) in the user's HOME directory;
  729. Xand returns the user to the shell.
  730. XThe cursor is moved to the line below the \fBpac\fR screen.
  731. XFrom the CALCULATOR function, either \fIquit\fR or \fIexit\fR
  732. Xhas the same effect.  The action of the
  733. X\fITAB\fR character (\fIControl-I\fR)
  734. Xor the equivalent token \fIbye\fR
  735. Xis different in that the CALCULATOR stack is
  736. Xcleared (all 0 values are saved in the .pacrc file), and
  737. Xthe screen is cleared as well.
  738. X.SH BUGS
  739. XPhysical constants are defined to a few digits of precision only,
  740. Xnot to the 32 digits maximum capability of the calculator.
  741. XThere is
  742. Xno guarantee as to the accuracy of the constant definitions;
  743. Xthe program must be re-compiled to make improvements or changes.
  744. X.LP
  745. XParentheses are passed through the preprocessor to \fBbc\fR
  746. Xinstead of being handled immediately.  For this reason,
  747. Xone should avoid using \fBpac\fR operators (multi-byte non-numeric
  748. Xwords, and the factorial operator \fI!\fR) inside open
  749. Xparentheses.  Also, logical (bit) and percent operators should not
  750. Xdirectly precede a left parenthesis.
  751. X.LP
  752. XThese same \fBpac\fR operators may force partial evaluations of the
  753. Xinput string, often changing CURRES faster than it is possible
  754. Xto visually update the result.  Explicit use of the CURRES token
  755. X\fIBACKSLASH\fR is therefore discouraged, except during the
  756. Xediting of conversion formulae.
  757. X.LP
  758. XThough \fBpac\fR traps error messages from \fBbc\fR, if the operating
  759. Xsystem is running with a broken or incorrectly compiled/linked
  760. X\fBbc\fR, the buggy executable may ``surprize'' the \fBpac\fR
  761. Xprocess by deadlocking the pipes.
  762. X.LP
  763. XDue to its interactive nature, \fBpac\fR is not optimized for speed;
  764. Xshell scripts are slow.
  765. SHAR_EOF
  766. $TOUCH -am 0725152590 pac.man &&
  767. chmod 0644 pac.man ||
  768. echo "restore of pac.man failed"
  769. set `wc -c pac.man`;Wc_c=$1
  770. if test "$Wc_c" != "27117"; then
  771.     echo original size 27117, current size $Wc_c
  772. fi
  773. # ============= README ==============
  774. echo "x - extracting README (Text)"
  775. sed 's/^X//' << 'SHAR_EOF' > README &&
  776. X
  777. XIf you are running under sysV, make with the -DREALUNIX flag.
  778. XVersion.c is created by the makefile, it is ok to loose it.
  779. XThe target terminal must have at least 80 columns and 24 lines.
  780. X
  781. XIf the shell complains about printer problems in response to the
  782. X'pac' command, it has found the printer accounting /etc/pac instead.
  783. X
  784. XThe man pages are in "pac.man", use "troff -man" to print.
  785. SHAR_EOF
  786. $TOUCH -am 0221163890 README &&
  787. chmod 0644 README ||
  788. echo "restore of README failed"
  789. set `wc -c README`;Wc_c=$1
  790. if test "$Wc_c" != "382"; then
  791.     echo original size 382, current size $Wc_c
  792. fi
  793. # ============= makefile ==============
  794. echo "x - extracting makefile (Text)"
  795. sed 's/^X//' << 'SHAR_EOF' > makefile &&
  796. X#
  797. XCC=/bin/cc
  798. X
  799. X# for bsd:
  800. XCFLAGS=-O
  801. XLFLAGS=-ltermlib
  802. XMFLAGS=
  803. X
  804. X# for sysV:
  805. X# CFLAGS=-O -DREALUNIX
  806. X# LFLAGS=
  807. X# MFLAGS=
  808. X
  809. X# for AT&T 6300+:
  810. X# CFLAGS=-Ml -s -DREALUNIX
  811. X# LFLAGS=
  812. X# MFLAGS=-Ml -s
  813. X
  814. X# for Xenix286 (contributed by Mark Seiffert --- rex!mgse!marks):
  815. X# CFLAGS=-M2el -Ox -DREALUNIX -LARGE
  816. X# LFLAGS=-F 5000 -s
  817. X# MFLAGS=-M2el
  818. X
  819. X#.SILENT:
  820. X
  821. Xall: version pac
  822. X
  823. Xversion:
  824. X    @/bin/rm -f version.c
  825. X    @echo 'char *version = "'`date`'";' > version.c
  826. X
  827. XNONE=ierror.o version.o
  828. XBOTH=convbase.o interpret.o
  829. XTABS=pactok.o bitwise.o help.o
  830. XMAPS=amort.o atoi.o conv.o file.o pac.o total.o
  831. XDEFS=display.o error.o ledit.o onlay.o pipes.o stack.o system.o time.o work.o
  832. X
  833. Xpac: ${NONE} ${BOTH} ${DEFS} ${MAPS} ${TABS}
  834. X    ${CC} ${MFLAGS} ${NONE} ${BOTH} ${DEFS} ${MAPS} ${TABS} \
  835. X    -lcurses ${LFLAGS} -lm -o pac
  836. X
  837. X${BOTH}: defs.h maps.h toktab.h
  838. X${TABS}: defs.h toktab.h
  839. X${MAPS}: defs.h maps.h
  840. X${DEFS}: defs.h
  841. SHAR_EOF
  842. $TOUCH -am 0725152590 makefile &&
  843. chmod 0644 makefile ||
  844. echo "restore of makefile failed"
  845. set `wc -c makefile`;Wc_c=$1
  846. if test "$Wc_c" != "881"; then
  847.     echo original size 881, current size $Wc_c
  848. fi
  849. # ============= defs.h ==============
  850. echo "x - extracting defs.h (Text)"
  851. sed 's/^X//' << 'SHAR_EOF' > defs.h &&
  852. X/* defs.h */
  853. X/**********************************************************************
  854. X*    File Name     : defs.h
  855. X*    Function      : definitions, declarations
  856. X*                  :    this header is included in all .c files of pac
  857. X*    Author        : Istvan Mohos, 1987
  858. X***********************************************************************/
  859. X
  860. X#include <curses.h>
  861. X#ifdef REALUNIX
  862. X#include <fcntl.h>
  863. X#else
  864. X#include <sys/file.h>
  865. X#endif
  866. X#include <ctype.h>
  867. X#include <signal.h>
  868. X#include <math.h>
  869. X
  870. X#ifdef TRACE
  871. X#define _TR   if (Trace) fprintf(Tf,">%s%s\n",&Ttabs[Tlev--],fid);
  872. X#define TR_   if (Trace) fprintf(Tf,"<%s%s\n",&Ttabs[++Tlev],fid);
  873. X#else
  874. X#define _TR
  875. X#define TR_
  876. X#endif
  877. X
  878. X#define ZERO  (char *)0
  879. X
  880. X#define LBOUND    1            /* left (inverse) edge of screen */
  881. X#define RBOUND    78           /* right (inverse) edge of screen */
  882. X#define TOP       1            /* top (inverse) edge of screen */
  883. X#define BOT       23           /* bottom (inverse) edge of screen */
  884. X#define UTOP      (TOP + 1)    /* user top of calculator window */
  885. X#define UBOT      (TOP + 3)    /* user bottom of calculator window */
  886. X#define ACCUM     (TOP + 4)    /* result line under calculator window */
  887. X#define ACCUMAX   44           /* max calculator,result width */
  888. X#define URIGHT    46           /* right user boundary of calculator */
  889. X#define DIGMAX    32           /* max calculator (numeric) digits */
  890. X#define ULEFT     3            /* left user calculator boundary */
  891. X#define MSG       (TOP + 5)    /* vertical location of error message */
  892. X#define MSGLEFT   4            /* left boundary of error message */
  893. X#define STACKLEFT 3            /* left boundary of stack (base) */
  894. X#define STACKTOP  (TOP + 6)    /* upper boundary of stack */
  895. X#define STACKBOT  (TOP + 21)   /* lower boundary of stack */
  896. X#define STACKMAX  36           /* max stack width (including base) */
  897. X#define STACKDEEP 16           /* max number of stack cells */
  898. X#define MYBUF    300           /* scratch display buffer */
  899. X
  900. X#define ATOIX      50          /* leftmost char printed into ATOI */
  901. X#define AMTY       7           /* vert location of loan AMT */
  902. X#define PRCY       8           /* percent */
  903. X#define YRY        9           /* years */
  904. X#define PAYY      10           /* payment */
  905. X#define DATY      11           /* start date */
  906. X#define LOANX      44          /* leftmost char printed into LOAN */
  907. X#define LOANSIZ    13          /* max width of LOAN line */
  908. X#define LOANR      (LOANX + LOANSIZ - 1)
  909. X#define STATMSG    44          /* leftmost char printed into STATUS */
  910. X#define STATX      54          /* left edge of 3 char status flag */
  911. X#define STATY      (TOP + 12)  /* ver location of first status string */
  912. X
  913. X                               /* status defaults */
  914. X#define PREC_DFLT  2           /* precision (# of digits past dp) */
  915. X#define IB_DFLT    10          /* input base */
  916. X#define OB_DFLT    10          /* output base */
  917. X#define DISA       0
  918. X#define ENA        1
  919. X#define AP         2
  920. X#define STACK_DFLT ENA         /* new result gets pushed on stack */
  921. X#define COMMA_      1
  922. X#define SPACE_      2
  923. X#define FORM_DFLT  SPACE_       /* put commas or spaces in numbers */
  924. X#define ED_DFLT    ENA         /* unimplemented */
  925. X#define JL         0
  926. X#define JF         1
  927. X#define JR         2
  928. X#define JUS_DFLT   JR          /* right, left, or fixed dp on right */
  929. X#define SB_DFLT    DISA        /* radix change effects current string */
  930. X#define SHOW_DFLT  DISA        /* don't pfresh until done */
  931. X#define FVER       0
  932. X#define FTER       1
  933. X#define FXTER      2
  934. X#define HF_DFLT    FVER        /* file dump verbose, terse or xterse */
  935. X
  936. X#define REGLEFT    3           /* leftmost char of stack cell (base) */
  937. X#define CONVLEFT   60          /* leftmost char of CONV. labels */
  938. X#define KEYLEFT    74          /* leftmost char of CONV. 3 char key */
  939. X#define FITCONV    (BOT - TOP - 1) /* max conv strings visible */
  940. X#define CONVCOUNT  24          /* number of predefined conversions */
  941. X#define FROMTOSIZ  14          /* conv. label size + \0 */
  942. X#define KEYSIZ     4           /* conv key size + \0 */
  943. X#define CONVMAX    (FROMTOSIZ + KEYSIZ - 1) /* conv string window siz */
  944. X#define CENTER     11          /* non_curses pos. in conv window */
  945. X#define CONVSEL    (CENTER - 1)/* original (default) selection */
  946. X
  947. X#define TREQ       2           /* update requests to print top line */
  948. X#define BREQ       9           /* update requests to print bottom line */
  949. X#define MSGLEN    13
  950. X#define FBOUND    (ULEFT + MSGLEN) /* where the screen fname starts */
  951. X#define BUFSTOP   (FBOUND - ULEFT) /* where fname starts in buffer */
  952. X#define TITSIZ    (RBOUND - ULEFT + 1)
  953. X#define TALYREQ    1
  954. X#define FILEREQ    2
  955. X#define POSTREQ    3
  956. X#define TOTLREQ    4
  957. X#define TAPPREQ    5
  958. X#define LOANREQ    6
  959. X#define CONVREQ    7
  960. X#define EDITREQ    8
  961. X
  962. X#define NOTINLIST -1           /* not recognized by pac tokenizer */
  963. X#define PIPEMAX   4096         /* guaranteed min size by UNIX */
  964. X#define WINLINE   81           /* max screen line + \0 */
  965. X#define LINEMAX   256          /* rough line size */
  966. X
  967. X#define INIT        0          /* prior to curses, to die properly */
  968. X
  969. X#define CYX       pyp=CY, pxp=CX
  970. X#define PYX       move(CY=pyp, CX=pxp)
  971. X/* all functions must return cursor to starting CY, CX coordinates */
  972. X
  973. X#define E_SYNTAX    1          /* bc errors */
  974. X#define E_DIVBY0    2
  975. X#define E_EXPONENT  3
  976. X#define E_OVERFLOW  4
  977. X#define E_BCEXEC    5
  978. X
  979. Xstruct stk_cell {
  980. X    char cell[STACKMAX + 1];
  981. X    struct stk_cell *link;
  982. X};
  983. X
  984. Xstruct stk_cell *find();
  985. Xchar *pactok();                /* seems to be missing in 4.2BSD */
  986. Xchar *bitwise();
  987. Xchar *substivar();
  988. Xchar *numform();
  989. Xchar *getenv();
  990. Xchar *calloc(), *malloc();
  991. Xchar *ctime();
  992. Xchar *strcat(), *strncat(), *strcpy(), *strncpy();
  993. Xchar *gets();
  994. XFILE *fopen();
  995. Xdouble atof();                    /* amortization variables */
  996. Xlong time(), lseek();
  997. Xunsigned alarm();
  998. Xint  go_away();
  999. Xint  cdate();
  1000. X
  1001. X#ifdef MAIN                    /* globals are defined in pac.c,
  1002. X                                  declared as externs elsewhere */
  1003. X
  1004. XFILE *Tf = NULL;
  1005. XFILE *Dfp = NULL;
  1006. Xchar *Home, Rcfile[LINEMAX];      /* pac environment */
  1007. Xint  Rcfd, Rcerr;
  1008. X
  1009. Xchar *Cb[] = {
  1010. X"pac          PANEL CALCULATOR                    ATOI    ",
  1011. X"pac          PANEL CALCULATOR                    ATOI    "
  1012. X};
  1013. Xchar *Sb[] = {
  1014. X"pac          PANEL CALCULATOR                    ATOI     CONVERSIONS  TO   ",
  1015. X"pac          PANEL CALCULATOR                    ATOI          TOTAL        "
  1016. X};
  1017. Xchar *Titlq[TREQ];
  1018. Xchar *Basq[BREQ];
  1019. Xchar *Bb[] = {
  1020. X"TAB bye  <CTRL> Exit Redraw File Postpend Klock Globals Loan Newconv Total  ",
  1021. X"<CTRL> File Postpend Toggle_back  copy: a...t  up_down: A...S  transfer: T  ",
  1022. X"file  write: hardcopy                                                       ",
  1023. X"file  contd: hardcopy                                                       ",
  1024. X"total write: hardtotal                                                      ",
  1025. X"total contd: hardtotal                                                      ",
  1026. X"amort write: hardamort                                                      ",
  1027. X"new  value =                                                                ",
  1028. X"new formula:                                                                "
  1029. X};
  1030. Xchar *Hardname =
  1031. X"hardcopy                                                       ";
  1032. Xchar *Totname =
  1033. X"hardtotal                                                      ";
  1034. Xchar *Amortname =
  1035. X"hardamort                                                      ";
  1036. X
  1037. Xchar Spreadbuf[PIPEMAX * 2];      /* expand user input for tokenizing */
  1038. Xchar Tokbuf[PIPEMAX];             /* strcomp against key list */
  1039. Xchar Mainbuf[PIPEMAX];            /* Mainbuf (result) from bc */
  1040. Xchar Convbuf[PIPEMAX];            /* converter result from bc */
  1041. Xchar Ubuf[PIPEMAX];               /* unrecognized tokens, to bc */
  1042. Xchar Controlbuf[PIPEMAX];         /* recognized tokens effect control */
  1043. Xchar *Tokp[PIPEMAX], *Last;       /* Spreadbuf pointers */
  1044. Xchar Rebuf[PIPEMAX];              /* work buffers */
  1045. Xchar Tmpbuf[PIPEMAX];
  1046. Xchar Mop[PIPEMAX];
  1047. Xchar Uwin_copy[(UBOT - UTOP + 1) * (URIGHT - ULEFT + 1)];
  1048. X
  1049. Xint Context   = INIT;             /* initial status values */
  1050. Xint Justify   = JUS_DFLT;
  1051. Xint Format    = FORM_DFLT;
  1052. Xint Stack     = STACK_DFLT;
  1053. Xint Hide      = 0;
  1054. Xint Dontsave  = 0;
  1055. Xint Clockstat = DISA;
  1056. Xint Show      = SHOW_DFLT;
  1057. Xint Autotime  = DISA;             /* no clock until user asks */
  1058. Xint Hf        = HF_DFLT;
  1059. Xint Ibase     = IB_DFLT;
  1060. Xint Obase     = OB_DFLT;
  1061. Xint Oldib     = IB_DFLT;
  1062. Xint Oldob     = OB_DFLT;
  1063. Xint Lastob    = OB_DFLT;
  1064. Xint Staybase  = DISA;
  1065. Xint Precision = PREC_DFLT;
  1066. Xint Edhelp    = ED_DFLT;
  1067. Xint Autoconv  = DISA;              /* Autoconverter feature */
  1068. Xint Convcount = CONVCOUNT;
  1069. Xint Convsel   = CONVSEL;
  1070. Xint Hardcopy  = DISA;
  1071. Xint Totcopy   = DISA;
  1072. Xint Painted   = FALSE;            /* don't push init vals on Stack */
  1073. X
  1074. Xdouble Amt;
  1075. Xdouble Years;
  1076. Xdouble Rate;
  1077. Xdouble Pymt;
  1078. Xdouble Showpymt;
  1079. Xdouble Intrst;
  1080. Xdouble I_mo;
  1081. Xdouble Months;
  1082. X
  1083. Xint Negative;
  1084. Xint Too_big;
  1085. Xint Has_dp;
  1086. X
  1087. Xchar *Base_str = "$$23456789 bcdefx";  /* formatting aids */
  1088. Xchar *Sp44 = "                                            ";
  1089. Xchar *Sp34 = "                                  ";
  1090. Xchar *Sp13 = "             ";
  1091. Xchar *Fix32 = "00000000000000000000000000000000";
  1092. Xchar *Emptycell = "  0                                 ";
  1093. X
  1094. Xchar Separator = ' ';             /* must agree with FORM_DFLT */
  1095. X
  1096. Xint A_ret = 0;
  1097. Xint B_ret = 0;
  1098. Xint A_write[2], A_read[2];        /* main bc process pipes */
  1099. Xint Nread;                        /* main bc process globals */
  1100. Xint B_write[2], B_read[2];        /* bc converter process pipes */
  1101. Xint Hc = -1;                      /* Hardcopy file fd */
  1102. Xint Tc = -1;                      /* Total file fd */
  1103. Xint Tqlev = 0;
  1104. Xchar *Thisyear;
  1105. Xint Do_conv, O_conv;              /* activate selected conv function */
  1106. Xint Convread;                     /* bc converter process */
  1107. Xint Topconv;                      /* top conversion of conv vindow */
  1108. Xchar *Convhom;                    /* conv malloc pointer */
  1109. Xchar Eq_buf[WINLINE];             /* new conv string input by user */
  1110. Xchar K_buf[KEYSIZ];               /* 3 char new key input by user */
  1111. Xchar L_buf[FROMTOSIZ];            /* new conv label input by user */
  1112. Xunsigned int Convhsiz;
  1113. X
  1114. X                                  /* predefined user conversions */
  1115. Xchar *Convlist[256][3] = {
  1116. X{"km2      acre", "acr", "\\*247.1"},
  1117. X{"gram avoir_oz", "av ", "\\*.035274"},
  1118. X{"fahr. celsius", "c  ", "(\\-32)*.55555555555555555555555555555555"},
  1119. X{"fluid_oz   cc", "cc ", "\\*29.573"},
  1120. X{"inch       cm", "cm ", "\\*2.54"},
  1121. X{"radian degree", "deg", "\\*57.295779513082321"},
  1122. X{"celsius fahr.", "f  ", "\\*1.8+32"},
  1123. X{"meter    foot", "ft ", "\\*3.2808"},
  1124. X{"avoir_oz gram", "g  ", "\\*28.3495"},
  1125. X{"liter  gallon", "gal", "\\*.26418"},
  1126. X{"cm       inch", "in ", "\\*.3937"},
  1127. X{"inversion    ", "inv", "1/\\"},
  1128. X{"pound      kg", "kg ", "\\*.45359"},
  1129. X{"mile       km", "km ", "\\*1.6093"},
  1130. X{"acre      km2", "km2", "\\*.004046"},
  1131. X{"kg      pound", "lb ", "\\*2.2046"},
  1132. X{"gallon  liter", "lit", "\\*3.7854"},
  1133. X{"foot    meter", "m  ", "\\*.3048"},
  1134. X{"km       mile", "mi ", "\\*.6214"},
  1135. X{"mile nautical", "nau", "\\*.8689784566"},
  1136. X{"nautical mile", "nmi", "\\*1.150776515"},
  1137. X{"cc   fluid_oz", "oz ", "\\*.03381"},
  1138. X{"degree radian", "rad", "\\*.01745329251994329"},
  1139. X{"sentinel     ", "|||", "1"}};        /* sentinel; do not remove */
  1140. X
  1141. Xint Status;                            /* exit for fatal */
  1142. Xint CX, CY;                            /* global cursor control */
  1143. Xchar Onebuf[STACKMAX + 1];             /* temp store for 1 stack cell */
  1144. Xint Statopts;                          /* Status display window flag */
  1145. Xstruct stk_cell Stk[STACKDEEP + 1];
  1146. Xint Bc_error;
  1147. Xint Trace;
  1148. Xint Tlev;
  1149. Xchar Ttabs[] = {"\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"};
  1150. Xint (*Save_sig[8])();
  1151. Xchar ierbuf[256];
  1152. X
  1153. X#else
  1154. X
  1155. Xextern FILE *Tf;
  1156. Xextern FILE *Dfp;
  1157. Xextern char *Titlq[];
  1158. Xextern char *Basq[];
  1159. Xextern char *Cb[], *Sb[];
  1160. Xextern char *Bb[];
  1161. Xextern char Spreadbuf[];
  1162. Xextern char Tokbuf[];
  1163. Xextern char Controlbuf[];
  1164. Xextern char *Tokp[], *Last;
  1165. Xextern int Negative, Too_big, Has_dp;
  1166. Xextern char Rebuf[];
  1167. Xextern char Tmpbuf[];
  1168. Xextern char Mop[];
  1169. Xextern char Uwin_copy[];
  1170. X
  1171. Xextern int Context;
  1172. Xextern int Justify;
  1173. Xextern int Format, Stack, Hide, Dontsave;
  1174. X
  1175. Xextern int  Ibase, Obase, Oldib, Oldob, Lastob, Staybase, Precision;
  1176. Xextern int  Show, Clockstat, Autotime;
  1177. Xextern char *Base_str;
  1178. Xextern int  CX, CY;
  1179. Xextern char Ubuf[], Mainbuf[], Convbuf[];
  1180. Xextern char *Sp44, *Sp34, *Sp13, *Fix32, *Emptycell;
  1181. Xextern char Separator;
  1182. Xextern int  A_write[], A_read[], A_ret, Nread;
  1183. Xextern int  B_write[], B_read[], B_ret, Convread;
  1184. Xextern int  Status, Painted;
  1185. Xextern char *Home, Rcfile[];
  1186. Xextern int  Rcfd, Rcerr;
  1187. Xextern char Onebuf[STACKMAX + 1];
  1188. Xextern int  Hardcopy, Hc, Hf;
  1189. Xextern char *Hardname;
  1190. Xextern char *Amortname;
  1191. Xextern char *Totname;
  1192. Xextern int  Totcopy, Tc, Tqlev;
  1193. Xextern int  Autoconv;
  1194. Xextern int  Convcount;
  1195. Xextern int  Convsel;
  1196. Xextern int  Do_conv, O_conv;
  1197. Xextern int  Topconv;
  1198. Xextern char *Convlist[][3];
  1199. Xextern char *Convhom;
  1200. Xextern char *Thisyear;
  1201. Xextern char Eq_buf[];
  1202. Xextern char K_buf[], L_buf[];
  1203. Xextern unsigned int Convhsiz;
  1204. Xextern int  Statopts;
  1205. Xextern struct stk_cell Stk[];
  1206. Xextern int  Edhelp;
  1207. Xextern int  Bc_error;
  1208. Xextern int  Trace;
  1209. Xextern int  Tlev;
  1210. Xextern char Ttabs[];
  1211. X
  1212. Xextern double atof();
  1213. Xextern double Amt;
  1214. Xextern double Years;
  1215. Xextern double Rate;
  1216. Xextern double Pymt;
  1217. Xextern double Showpymt;
  1218. Xextern double Intrst;
  1219. Xextern double I_mo;
  1220. Xextern double Months;
  1221. X
  1222. Xextern int (*Save_sig[])();
  1223. Xextern char ierbuf[];
  1224. X
  1225. X#endif
  1226. SHAR_EOF
  1227. $TOUCH -am 0221163890 defs.h &&
  1228. chmod 0644 defs.h ||
  1229. echo "restore of defs.h failed"
  1230. set `wc -c defs.h`;Wc_c=$1
  1231. if test "$Wc_c" != "13508"; then
  1232.     echo original size 13508, current size $Wc_c
  1233. fi
  1234. echo "End of part 1, continue with part 2"
  1235. exit 0
  1236.  
  1237.