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

  1. Newsgroups: comp.sources.misc
  2. keywords: Not For SunOS 3.x
  3. subject: v14i041: pac - the ultimate UNIX calculator, part 3 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 41
  8. Submitted-by: istvan@hhb.UUCP (Istvan Mohos)
  9. Archive-name: pac/part03
  10.  
  11. ==============================CUT HERE==============================
  12. #!/bin/sh
  13. # This is part 03 of a multipart archive
  14. if touch 2>&1 | fgrep '[-amc]' > /dev/null
  15.  then TOUCH=touch
  16.  else TOUCH=true
  17. fi
  18. # ============= conv.c ==============
  19. echo "x - extracting conv.c (Text)"
  20. sed 's/^X//' << 'SHAR_EOF' > conv.c &&
  21. X/* conv.c */
  22. X/**********************************************************************
  23. X*    File Name     : conv.c
  24. X*    Function      : user conversion routines of pac
  25. X*                  : Recursion is too big a task to fit the framework
  26. X*                  :  (i.e. defining 'to foo' as 'to {to foo}' brings
  27. X*                  :  up all sorts of control problems).  To simplify,
  28. X*                  :  only numerical expressions and binary operands
  29. X*                  :  are permitted, in a single statement (no ';').
  30. X*                  : 
  31. X*    Author        : Istvan Mohos, 1987
  32. X***********************************************************************/
  33. X
  34. X
  35. X#include "defs.h"
  36. X#define CONVMAP
  37. X#include "maps.h"
  38. X#undef CONVMAP
  39. X
  40. Xshow_uconv()
  41. X{
  42. X    register ri;
  43. X    static char *fid = "show_uconv";
  44. X
  45. X    _TR
  46. X    if (Convsel < CENTER)
  47. X        Topconv = 0;
  48. X    else if (Convsel >= Convcount - CENTER)
  49. X        Topconv = Convcount - (2 * CENTER);
  50. X    else
  51. X        Topconv = Convsel - CENTER + 1;
  52. X
  53. X    for (ri = 0; ri < FITCONV; ri++) {
  54. X        mvaddstr(ri + TOP+1, CONVLEFT, Convlist[ri + Topconv][0]);
  55. X        addch(' ');
  56. X        mvaddstr(ri + TOP+1, KEYLEFT, Convlist[ri + Topconv][1]);
  57. X    }
  58. X
  59. X    standout();
  60. X    for (ri = 0; ri < FITCONV; ri++)
  61. X        mvaddch(UTOP + ri, RBOUND, ' ');
  62. X
  63. X    mvaddstr(TOP+1 + Convsel - Topconv, CONVLEFT, Convlist[Convsel][0]);
  64. X    standend();
  65. X    TR_
  66. X}
  67. X
  68. Xsetup_uconv()
  69. X{
  70. X    register char *rc;
  71. X    register int ri;
  72. X    static char *fid = "setup_uconv";
  73. X
  74. X    _TR
  75. X    Convhsiz = Convcount * (FROMTOSIZ + KEYSIZ);
  76. X    for (ri = 0; ri < Convcount; ri++)
  77. X        Convhsiz += strlen(Convlist[ri][2]) + 1; /* conv string + \n */
  78. X    if ((Convhom = calloc(Convhsiz, 1)) == ZERO)
  79. X        fatal("calloc error in setup_uconv");
  80. X
  81. X    /* move static defs to dynamically alterable Convhom buffer */
  82. X    for (rc = Convhom, ri = 0; ri < Convcount; ri++) {
  83. X        strcpy(rc, Convlist[ri][0]);
  84. X        rc += FROMTOSIZ;
  85. X        strcpy(rc, Convlist[ri][1]);
  86. X        rc += KEYSIZ;
  87. X        strcpy(rc, Convlist[ri][2]);
  88. X        while (*rc++ != '\0');
  89. X    }
  90. X    realign_conv();
  91. X    TR_
  92. X}
  93. X
  94. Xconv_id(c_ptr)
  95. Xchar *c_ptr;
  96. X{
  97. X    int inlist_val, under;
  98. X    static char *fid = "conv_id";
  99. X
  100. X    _TR
  101. X    if ((inlist_val = spacefill(c_ptr, 3)) != -1)
  102. X        inlist_val = keysearch(Tokbuf, Convcount, &under);
  103. X    TR_
  104. X    return(inlist_val);
  105. X}
  106. X
  107. Xkeysearch (key, max, under)
  108. Xregister char *key;
  109. Xint max, *under;
  110. X{
  111. X    register int guess, mid, lo = 0, hi;
  112. X    static char *fid = "keysearch";
  113. X
  114. X    _TR
  115. X    hi = max - 1;
  116. X    while (lo <= hi) {
  117. X        mid = (lo + hi) >> 1;
  118. X        if ((guess = strcmp(key, Convlist[mid][1])) < 0)
  119. X            hi = mid - 1;
  120. X        else if (guess > 0)
  121. X            lo = mid + 1;
  122. X        else {
  123. X            TR_
  124. X            return(mid);
  125. X        }
  126. X    }
  127. X    *under = lo;
  128. X    TR_
  129. X    return (-1);
  130. X}
  131. X
  132. Xnewconv()
  133. X{
  134. X    int c;
  135. X    int lbound;
  136. X    char calbuf[LINEMAX];
  137. X    int pyp, pxp;
  138. X    int ri;
  139. X    register int rj;
  140. X    register char *rc;
  141. X    static char *fid = "newconv";
  142. X
  143. X    _TR
  144. X    CYX;
  145. X    rc = calbuf;
  146. X    for (ri = UTOP; ri <= UBOT; ri++)
  147. X        for (rj = ULEFT; rj <= URIGHT; rj++)
  148. X            *rc++ = stdscr->_y[ri][rj];
  149. X
  150. X    mvaddstr(UTOP, ULEFT, Sp44);
  151. X    mvaddstr(UTOP + 1, ULEFT, Sp44);
  152. X    mvaddstr(UTOP + 2, ULEFT, Sp44);
  153. X
  154. X    if (Convcount == 255) {
  155. X        mvaddstr(UTOP, ULEFT,
  156. X            "SELECT:   ...full...    Remove     Change  _");
  157. X        lbound = ULEFT + strlen(
  158. X            "SELECT:   ...full...    Remove     Change  ");
  159. X
  160. X        while((c = ledit(ZERO,c_sel_map,UTOP,lbound,lbound,0,0,0)
  161. X            | 32) != 'r' && c != 'c');
  162. X    }
  163. X    else if (Convcount == 22) {
  164. X        mvaddstr(UTOP, ULEFT,
  165. X            "SELECT:     Install   ...low...    Change  _");
  166. X        lbound = ULEFT + strlen(
  167. X            "SELECT:     Install   ...low...    Change  ");
  168. X
  169. X        while((c = ledit(ZERO,c_sel_map,UTOP,lbound,lbound,0,0,0)
  170. X            | 32) != 'i' && c != 'c');
  171. X    }
  172. X    else {
  173. X        mvaddstr(UTOP, ULEFT,
  174. X            "SELECT:     Install     Remove     Change  _");
  175. X        lbound = ULEFT + strlen(
  176. X            "SELECT:     Install     Remove     Change  ");
  177. X
  178. X        while((c = ledit(ZERO,c_sel_map,UTOP,lbound,lbound,0,0,0)
  179. X            | 32) != 'i' && c != 'r' && c != 'c');
  180. X    }
  181. X
  182. X    mvaddstr(UTOP, ULEFT, Sp44);
  183. X    mvaddstr(UTOP + 1, ULEFT, Sp44);
  184. X    mvaddstr(UTOP + 2, ULEFT, Sp44);
  185. X
  186. X    switch(c) {
  187. X        case 'i':
  188. X            addnew(specify(pyp, pxp));
  189. X            break;
  190. X
  191. X        case 'r':
  192. X            remove(celect());
  193. X            break;
  194. X
  195. X        case 'c':
  196. X            remove(celect());
  197. X            addnew(specify(pyp, pxp));
  198. X            break;
  199. X    }
  200. X
  201. X    rc = calbuf;
  202. X    for (ri = UTOP; ri <= UBOT; ri++)
  203. X        for (rj = ULEFT; rj <= URIGHT; rj++)
  204. X            mvaddch(ri, rj, *rc++);
  205. X
  206. X    PYX;
  207. X    pfresh();
  208. X    TR_
  209. X}
  210. X
  211. Xcelect()
  212. X{
  213. X    int lbound, rbound;
  214. X    char *c_key;
  215. X    int keylen, old_id, dummy;
  216. X    static char *fid = "celect";
  217. X
  218. X    _TR
  219. X    clear_wline(UTOP, ULEFT, URIGHT, 0, 3);
  220. X    c_key = "   ";
  221. X    mvaddstr(UTOP, ULEFT,
  222. X        "ENTER OLD 'TO' SEARCH KEY:   [");
  223. X    lbound = ULEFT + strlen(
  224. X        "ENTER OLD 'TO' SEARCH KEY:   [");
  225. X    rbound = lbound + 2;
  226. X    mvaddstr(UTOP, rbound + 1, "]");
  227. X
  228. X    old_id = -1;
  229. X    while (old_id == -1) {
  230. X        mvaddstr(UTOP, lbound, c_key);
  231. X    
  232. X
  233. X        ledit(&K_buf[0], c_ed_map, UTOP, lbound, rbound, 0, 1, 1);
  234. X        /* stripping surrounding spaces */
  235. X
  236. X        if(!*K_buf)
  237. X            continue;
  238. X        keylen = strlen(K_buf);
  239. X        if (keylen < 3)
  240. X            K_buf[2] = ' ';
  241. X        else if (*(K_buf+1) == ' ')
  242. X            *(K_buf+1) = '_'; /* turn embedded space into _ */
  243. X        if (keylen < 2)
  244. X            K_buf[1] = ' ';
  245. X        old_id = keysearch(K_buf, Convcount, &dummy);
  246. X    }
  247. X    TR_
  248. X    return(old_id);
  249. X}
  250. X
  251. Xspecify(pyp, pxp)
  252. Xint pyp, pxp;
  253. X{
  254. X    int lbound, rbound;
  255. X    char *c_label, *c_key;
  256. X    int neednewkey = 1, keylen, insert;
  257. X    static char *fid = "specify";
  258. X
  259. X    _TR
  260. X    clear_wline(UTOP, ULEFT, URIGHT, 0, 3);
  261. X    while (neednewkey) {
  262. X        c_key = "   ";
  263. X        mvaddstr(UTOP + 1, ULEFT,
  264. X            "ENTER NEW 'TO' SEARCH KEY:   [");
  265. X        lbound = ULEFT + strlen(
  266. X            "ENTER NEW 'TO' SEARCH KEY:   [");
  267. X        mvaddstr(UTOP + 1, lbound, c_key);
  268. X        rbound = lbound + 2;
  269. X        mvaddstr(UTOP + 1, rbound + 1, "]");
  270. X    
  271. X
  272. X        ledit(&K_buf[0], c_ed_map, UTOP+1, lbound, rbound, 0, 1, 1);
  273. X        /* stripping surrounding spaces */
  274. X
  275. X        if (keylen = strlen(K_buf)) {
  276. X            if (keylen < 3)
  277. X                K_buf[2] = ' ';
  278. X            else if (*(K_buf+1) == ' ')
  279. X                *(K_buf+1) = '_'; /* turn emmbedded space into _ */
  280. X            if (keylen < 2)
  281. X                K_buf[1] = ' ';
  282. X        }
  283. X        else
  284. X            continue;
  285. X        if (keysearch(K_buf, Convcount, &insert) == -1)
  286. X            neednewkey = FALSE;
  287. X        /* if it did find it, the proposed new key is a duplicate,
  288. X           and is disallowed */
  289. X    }
  290. X
  291. X    c_label = "             ";
  292. X    mvaddstr(UTOP + 2, ULEFT, "ENTER 'CONVERSIONS' LABEL:   [");
  293. X    lbound = ULEFT + strlen( "ENTER 'CONVERSIONS' LABEL:   [");
  294. X    mvaddstr(UTOP + 2, lbound, c_label);
  295. X    rbound = lbound + 12;
  296. X    mvaddstr(UTOP + 2, rbound + 1, "]");
  297. X
  298. X
  299. X    ledit(&L_buf[0], c_ed_map, UTOP+2, lbound, rbound, 0, 0, 1);
  300. X
  301. X    mvaddstr(UTOP, ULEFT, Sp44);
  302. X    mvaddstr(UTOP + 1, ULEFT, Sp44);
  303. X    mvaddstr(UTOP + 2, ULEFT, Sp44);
  304. X
  305. X    mvaddstr(UTOP, ULEFT,
  306. X        "COMPLETE THE EQUATION USING THE BACKSLASH \\");
  307. X    mvaddstr(UTOP + 1, ULEFT,
  308. X        "CHARACTER TO REPRESENT THE 'FROM' QUANTITY.");
  309. X    mvaddstr(UTOP + 2, ULEFT,
  310. X        "CONSTANTS ARE INTERPRETED IN DECIMAL RADIX.");
  311. X
  312. X    Basq[EDITREQ] = Bb[EDITREQ];
  313. X    update();  /* this returns to the original coordinates,
  314. X                  but does'nt pfresh */
  315. X
  316. Xenter_conv:
  317. X
  318. X    ledit(&Eq_buf[0], eq_ed_map, BOT, FBOUND, RBOUND, 1, 1, 1);
  319. X
  320. X    if (verify_uconv())
  321. X        goto enter_conv;
  322. X
  323. X    Basq[EDITREQ] = ZERO;
  324. X    PYX;
  325. X    update();
  326. X    pfresh();
  327. X    TR_
  328. X    return(insert);
  329. X}
  330. X
  331. Xrealign_conv()
  332. X{
  333. X    register int ri;
  334. X    register char *rc;
  335. X    static char *fid = "realign_conv";
  336. X
  337. X    _TR
  338. X    for (rc = Convhom, ri = 0; ri < Convcount; ri++) {
  339. X        Convlist[ri][0] = rc; /* ptr to first word of conversion */
  340. X        rc += FROMTOSIZ;         /* buffer pointer to second word */
  341. X        Convlist[ri][1] = rc; /* ptr to 2nd word of conversion */
  342. X        rc += KEYSIZ;            /* buffer pointer to conv string */
  343. X        Convlist[ri][2] = rc; /* ptr to conversion string */
  344. X        while (*rc++ != '\0');   /* find next conversion in buffer */
  345. X    }
  346. X    TR_
  347. X}
  348. X
  349. Xremove(old_id)
  350. Xint old_id;
  351. X{
  352. X/*
  353. X   malloc Convhsiz size temp buffer;
  354. X   copy Convhom into temp until old_id conversion;
  355. X   skip (do not copy) old_id conversion;
  356. X   copy rest of Convhom into temp;
  357. X   free Convhom;
  358. X   assign Convhom pointer to temp;
  359. X   decrement Convcount;
  360. X   adjust Convhsiz;
  361. X   realign Convlist pointers along new buffer;
  362. X*/
  363. X
  364. X    char *Tmp;
  365. X    register char *tp;
  366. X    unsigned rmsiz;
  367. X    register int ri;
  368. X    static char *fid = "remove";
  369. X
  370. X    _TR
  371. X    if ((Tmp = malloc(Convhsiz)) == ZERO)
  372. X        fatal("malloc error in remove");
  373. X    tp = Tmp;
  374. X
  375. X    for (ri = 0; ri < old_id; ri++) {
  376. X        strcpy(tp, Convlist[ri][0]);
  377. X        tp += FROMTOSIZ;
  378. X        strcpy(tp, Convlist[ri][1]);
  379. X        tp += KEYSIZ;
  380. X        strcpy(tp, Convlist[ri][2]);
  381. X        while (*tp++ != '\0');
  382. X    }
  383. X    rmsiz = FROMTOSIZ + KEYSIZ + strlen(Convlist[ri][2]) + 1; 
  384. X    for (ri = old_id + 1; ri < Convcount; ri++) {
  385. X        strcpy(tp, Convlist[ri][0]);
  386. X        tp += FROMTOSIZ;
  387. X        strcpy(tp, Convlist[ri][1]);
  388. X        tp += KEYSIZ;
  389. X        strcpy(tp, Convlist[ri][2]);
  390. X        while (*tp++ != '\0');
  391. X    }
  392. X    free(Convhom);
  393. X    Convhom = Tmp;
  394. X    --Convcount;
  395. X    Convhsiz -= rmsiz;
  396. X    realign_conv();
  397. X    if (Convsel > old_id)
  398. X        --Convsel;
  399. X    else if (Convsel == old_id)
  400. X        Convsel = CONVSEL;
  401. X    show_uconv();
  402. X    TR_
  403. X}
  404. X
  405. Xaddnew(insert)
  406. Xint insert;
  407. X{
  408. X/*
  409. X   Malloc new buffer, to hold Convhom + size of new conversion.
  410. X   Copy Convhom into new buffer, until the alphabetic ordering
  411. X       of KEYs reaches the new KEY.
  412. X   Insert new conversion in new buffer.
  413. X   Finish copying old conversions from Convhom to new buffer.
  414. X   Free Convhom.
  415. X   Assign Convhom (pointer) to new buffer.
  416. X   Increment Convcount.
  417. X   adjust Convhsiz;
  418. X   Realign Convlist pointers along new buffer.
  419. X*/
  420. X
  421. X    char *Tmp;
  422. X    register char *tp;
  423. X    unsigned addsiz;
  424. X    register int ri;
  425. X    static char *fid = "addnew";
  426. X
  427. X    _TR
  428. X    addsiz = FROMTOSIZ + KEYSIZ + strlen(Eq_buf) + 1; 
  429. X    if ((Tmp = malloc(Convhsiz + addsiz)) == ZERO)
  430. X        fatal("malloc error in addnew");
  431. X    tp = Tmp;
  432. X
  433. X    for (ri = 0; ri < insert; ri++) {
  434. X        strcpy(tp, Convlist[ri][0]);
  435. X        tp += FROMTOSIZ;
  436. X        strcpy(tp, Convlist[ri][1]);
  437. X        tp += KEYSIZ;
  438. X        strcpy(tp, Convlist[ri][2]);
  439. X        while (*tp++ != '\0');
  440. X    }
  441. X    strcpy(tp, L_buf);
  442. X    tp += FROMTOSIZ;
  443. X    strcpy(tp, K_buf);
  444. X    tp += KEYSIZ;
  445. X    strcpy(tp, Eq_buf);
  446. X    while (*tp++ != '\0');
  447. X    for (ri = insert; ri < Convcount; ri++) {
  448. X        strcpy(tp, Convlist[ri][0]);
  449. X        tp += FROMTOSIZ;
  450. X        strcpy(tp, Convlist[ri][1]);
  451. X        tp += KEYSIZ;
  452. X        strcpy(tp, Convlist[ri][2]);
  453. X        while (*tp++ != '\0');
  454. X    }
  455. X    free(Convhom);
  456. X    Convhom = Tmp;
  457. X    ++Convcount;
  458. X    Convhsiz += addsiz;
  459. X    realign_conv();
  460. X    Convsel = insert;
  461. X    show_uconv();
  462. X    TR_
  463. X}
  464. X
  465. Xverify_uconv()
  466. X{
  467. X    static char *fid = "verify_uconv";
  468. X
  469. X    _TR
  470. X    if (strlen(Eq_buf) == 0) {
  471. X        strcpy(Eq_buf, "\\");
  472. X        TR_
  473. X        return(0);
  474. X    }
  475. X
  476. X    TR_
  477. X    return(0);
  478. X}
  479. X
  480. X/* the routine that interprets the user keyword TO */
  481. Xconv_usr()
  482. X{
  483. X    char *ctab, *cb, cbuf[LINEMAX];
  484. X    char hardbuf[LINEMAX];
  485. X    int ri;
  486. X    int sav_ibase;
  487. X    static char *fid = "conv_usr";
  488. X
  489. X    _TR
  490. X    e_syntax();
  491. X    e_divby0();
  492. X    e_exponent();
  493. X    e_bcexec();
  494. X
  495. X    if (!Bc_error) {
  496. X        sav_ibase = Ibase;
  497. X        Ibase = 10;
  498. X        conv_bc(Mainbuf, ZERO, 0, 0);
  499. X        *(Convbuf + DIGMAX + 2) = '\0';
  500. X        ri = strlen(Convbuf);
  501. X        Ibase = sav_ibase;
  502. X    
  503. X        cb = cbuf;
  504. X        strcpy(cb, "ibase=A;");
  505. X        cb += strlen(cb);
  506. X    
  507. X        ctab = Convlist[Convsel][2];
  508. X        sprintf(Bb[CONVREQ] + BUFSTOP, ctab);
  509. X        rev_clear(Bb[CONVREQ] + TITSIZ);
  510. X        Basq[CONVREQ] = Bb[CONVREQ];
  511. X        update();
  512. X    
  513. X        if ( Hc != -1 && Hf != FXTER) {
  514. X            if (Hf == FVER)
  515. X                sprintf(hardbuf, "TO %s: %s\n", Convlist[Convsel][1], ctab);
  516. X            else
  517. X                sprintf(hardbuf, "TO %s\n", Convlist[Convsel][1]);
  518. X            if ((write(Hc, hardbuf, strlen(hardbuf))) !=
  519. X                strlen(hardbuf))
  520. X                fatal("hardcopy write");
  521. X        }
  522. X    
  523. X        while (*ctab != '\0') {
  524. X            if (*ctab == '\\') {
  525. X                strcpy(cb, Convbuf);
  526. X                cb += ri;
  527. X                ctab++;
  528. X            }
  529. X            else
  530. X                *cb++ = *ctab++;
  531. X        }
  532. X        sprintf(cb, ";ibase=%d\n", Ibase);
  533. X        if (write(A_write[1], cbuf, strlen(cbuf)) == -1)
  534. X            fatal("main pipe write");
  535. X        clear_accwin();
  536. X        wait_main_pipe();
  537. X    }
  538. X    if (Autoconv == DISA)
  539. X        Do_conv = FALSE;
  540. X    TR_
  541. X}
  542. X
  543. SHAR_EOF
  544. $TOUCH -am 0221163890 conv.c &&
  545. chmod 0644 conv.c ||
  546. echo "restore of conv.c failed"
  547. set `wc -c conv.c`;Wc_c=$1
  548. if test "$Wc_c" != "13160"; then
  549.     echo original size 13160, current size $Wc_c
  550. fi
  551. # ============= convbase.c ==============
  552. echo "x - extracting convbase.c (Text)"
  553. sed 's/^X//' << 'SHAR_EOF' > convbase.c &&
  554. X/* convbase.c */
  555. X/**********************************************************************
  556. X*    File Name     : convbase.c
  557. X*    Function      : use second bc pipe for conversion between radices
  558. X*    Author        : Istvan Mohos, 1987
  559. X***********************************************************************/
  560. X
  561. X#include "defs.h"
  562. X#include "toktab.h"
  563. X#define INTERMAP
  564. X#include "maps.h"
  565. X#undef INTERMAP
  566. X
  567. Xchar *
  568. Xsubstivar(found, token, ib)
  569. Xchar *token;
  570. Xint found, ib;
  571. X{ 
  572. X    static char res[PIPEMAX];
  573. X    static struct stk_cell *sr = &Stk[0];
  574. X    static char *fid = "substivar";
  575. X    char *ret = res;
  576. X    int tokval;
  577. X
  578. X    _TR
  579. X    if (found == -1) {
  580. X        if (token == ZERO) {
  581. X            TR_
  582. X            return(ZERO);
  583. X        }
  584. X        tokval = lookup(token);
  585. X    }
  586. X    else
  587. X        tokval = found;
  588. X
  589. X    switch(tokval) {
  590. X        case H_:
  591. X        case I_:
  592. X        case J_:
  593. X        case K_:
  594. X        case L_:
  595. X        case M_:
  596. X        case N_:
  597. X        case O_:
  598. X        case P_:
  599. X        case Q_:
  600. X        case R_:
  601. X        case S_:
  602. X        case T_:
  603. X        case U_:
  604. X        case V_:
  605. X        case W_:
  606. X            onereg(*token - 'g');
  607. X            conv_bc(Onebuf, res, 1, ib);
  608. X            break;
  609. X
  610. Xcase PI: conv_bc("3.1415926535897932384626433832795028841971693993751",
  611. X                    res, 10, ib); break;
  612. Xcase ASTRO:     conv_bc("149504200", res, 10, ib); break;
  613. X                    /* km */
  614. Xcase AMASS:     conv_bc(".00000000000000000000000165975",
  615. X                    res, 10, ib); break; /* grams */
  616. Xcase AVOGADRO:  conv_bc("602502000000000000000000",
  617. X                    res, 10, ib); break; /* per g mole */
  618. Xcase BOLTZMANN: conv_bc(".000000000000000138040", res, 10, ib); break;
  619. X                    /* erg/Kelvin */
  620. Xcase ECHARGE:   conv_bc(".000000000160202", res, 10, ib); break;
  621. X                    /* esu */
  622. Xcase CHROMA:    conv_bc("1.0594631", res, 10, ib); break;
  623. Xcase EMASS:     conv_bc(".000000000000000000000000000910820",
  624. X                    res, 10, ib); break; /* grams */
  625. Xcase EULER:     conv_bc(".577216", res, 10, ib); break;
  626. Xcase FARADAY:   conv_bc("96521900", res, 10, ib); break;
  627. X                    /* C/kmole */
  628. Xcase G_:        conv_bc("9.80665", res, 10, ib); break;
  629. X                    /* m/s2 */
  630. Xcase GAS:       conv_bc("83169600", res, 10, ib); break;
  631. X                    /* erg/g mole Kelvin */
  632. Xcase GRAVITY:   conv_bc(".00000000006673", res, 10, ib); break;
  633. X                    /* N m2/kg2 */
  634. Xcase HEAT:      conv_bc("4.1855", res, 10, ib); break;
  635. X                    /* J/cal */
  636. Xcase LIGHT:     conv_bc("299792.50", res, 10, ib); break;
  637. X                    /* km/sec */
  638. Xcase LIGHTYEAR: conv_bc("9460530000000", res, 10, ib); break;
  639. X                    /* km */
  640. Xcase MOONMASS:  conv_bc("73430000000000000000000", res, 10, ib); break;
  641. X                    /* kg */
  642. Xcase SUNMASS:   conv_bc("1987000000000000000000000000000",
  643. X                    res, 10, ib); break; /* kg */
  644. Xcase EARTHMASS: conv_bc("5976500000000000000000000",
  645. X                    res, 10, ib); break; /* kg */
  646. Xcase NATURAL:   conv_bc("2.7182818284590452353602874713526",
  647. X                    res, 10, ib); break;
  648. Xcase NMASS:     conv_bc(".00000000000000000000000167465",
  649. X                    res, 10, ib); break; /* grams */
  650. Xcase PARSEC:    conv_bc("30837450000000", res, 10, ib); break;
  651. X                    /* km */
  652. Xcase PARALLAX:  conv_bc("8.794", res, 10, ib); break;
  653. X                    /* " */
  654. Xcase PLANCK:    conv_bc(".00000000000000000000000000662491",
  655. X                    res, 10, ib); break; /* erg sec */
  656. Xcase PMASS:     conv_bc(".00000000000000000000000167235",
  657. X                    res, 10, ib); break; /* grams */
  658. Xcase MOONRAD:   conv_bc("1738000", res, 10, ib); break;
  659. X                    /* meters */
  660. Xcase SUNRAD:    conv_bc("696500000", res, 10, ib); break;
  661. X                    /* meters */
  662. Xcase EARTHRAD:  conv_bc("6378388", res, 10, ib); break;
  663. X                    /* meters */
  664. Xcase RYDBERG:   conv_bc("10973732.8", res, 10, ib); break;
  665. X                    /* per meter */
  666. Xcase SOUND:     conv_bc("340.505", res, 10, ib); break;
  667. X                    /* meters/sec: 331.4 + (.607 * Celsius) */
  668. Xcase STEFAN:    conv_bc(".000000056693", res, 10, ib); break;
  669. X                    /* J/m2 Kelvin4 sec */
  670. Xcase TOMOON:    conv_bc("384400", res, 10, ib); break;
  671. X                    /* km */
  672. Xcase TOSUN:     conv_bc("149500000", res, 10, ib); break;
  673. X                    /* km */
  674. Xcase WIEN:      conv_bc(".289778", res, 10, ib); break;
  675. X                    /* cm Kelvin */
  676. X
  677. Xcase MILLI:     conv_bc(".001", res, 10, ib); break;
  678. Xcase MICRO:     conv_bc(".000001", res, 10, ib); break;
  679. Xcase NANO:      conv_bc(".000000001", res, 10, ib); break;
  680. Xcase PICO:      conv_bc(".000000000001", res, 10, ib); break;
  681. Xcase FEMTO:     conv_bc(".000000000000001", res, 10, ib); break;
  682. Xcase ATTO:      conv_bc(".000000000000000001", res, 10, ib); break;
  683. Xcase KILO:      conv_bc("1000", res, 10, ib); break;
  684. Xcase MEGA:      conv_bc("1000000", res, 10, ib); break;
  685. Xcase GIGA:      conv_bc("1000000000", res, 10, ib); break;
  686. Xcase TERA:      conv_bc("1000000000000", res, 10, ib); break;
  687. Xcase PETA:      conv_bc("1000000000000000", res, 10, ib); break;
  688. Xcase EXA:       conv_bc("1000000000000000000", res, 10, ib); break;
  689. X
  690. X        case X_LOWER:
  691. X        case X_UPPER:
  692. X            sprintf(res, "%s", sixteen[Ibase]);
  693. X            break;
  694. X
  695. X        case BACKSLASH:
  696. X            conv_bc(sr->cell, res, 1, ib);
  697. X            break;
  698. X
  699. X        case NOTINLIST:    /* presumably a digit string */
  700. X            upcase(token);
  701. X            ret = token;
  702. X            break;
  703. X
  704. X        default: /* token in list, but is not variable or constant */
  705. X            ret = Convbuf;   /* just to warn the caller */
  706. X            break;
  707. X    }
  708. X    TR_
  709. X    return(ret);
  710. X}
  711. X
  712. X/* translate frombuf number string in frombase radix,
  713. X   to string in tobuf in tobase radix.
  714. X
  715. X   If frombase and tobase are identical no conversion is done;
  716. X   buffer is simply copied.
  717. X   Otherwise, conv_pipe's ibase is set to the frombase radix,
  718. X   conv_pipe's obase is set to tobase, and the frombuf
  719. X   string is executed through conv_pipe.
  720. X
  721. X   If frombase is 0, Lastob is taken as frombase.
  722. X   If frombase is -1, Ibase is taken as frombase.
  723. X   If frombase is 1, frombase is deduced from the first character
  724. X       of frombuf in stack string format.
  725. X
  726. X   If tobuf is ZERO, result goes to Convbuf.  Else tobuf must
  727. X   be at least PIPEMAX long.
  728. X*/
  729. X
  730. Xconv_bc(frombuf, tobuf, frombase, tobase)
  731. Xchar *frombuf, *tobuf;
  732. Xint frombase, tobase;
  733. X{
  734. X    int value, maxchars;
  735. X    int charcount = 0;
  736. X    register char *bptr, *toasc_p;
  737. X    static char *fid = "conv_bc";
  738. X
  739. X    _TR
  740. X    bptr = frombuf;
  741. X    if (tobase == 0)
  742. X        tobase = Ibase;
  743. X    maxchars = strlen(frombuf);
  744. X    if (tobuf == ZERO)
  745. X        tobuf = Convbuf;
  746. X
  747. X    switch (frombase) {
  748. X        case 1:
  749. X            charcount = 1;
  750. X            value = *bptr & 127; /* ascii value of passed radix label */
  751. X            for (toasc_p = Base_str + 16;; toasc_p--) {
  752. X                if (*toasc_p == value) {
  753. X                    frombase = toasc_p - Base_str;
  754. X                    break;
  755. X                }
  756. X            }
  757. X            while ((*++bptr & 127) == ' ') /* get to digit string */
  758. X                ++charcount;
  759. X            break;
  760. X
  761. X        case -1:
  762. X            frombase = Ibase;
  763. X            break;
  764. X
  765. X        case 0:
  766. X            frombase = Lastob;
  767. X            break;
  768. X
  769. X        default:
  770. X            break;
  771. X
  772. X    }
  773. X
  774. X    if (frombase == tobase) {
  775. X        toasc_p = tobuf;
  776. X        while(charcount++ < maxchars)
  777. X            if ((*bptr & 127) != ' ')
  778. X                *toasc_p++ = *bptr++ & 127;
  779. X            else
  780. X                ++bptr;
  781. X        *toasc_p = '\0';
  782. X    }
  783. X    else {
  784. X        sprintf(Mop, "ibase=A;obase=%d;ibase=%d\n", tobase, frombase);
  785. X        toasc_p = &Mop[strlen(Mop)];
  786. X        while(charcount++ < maxchars)
  787. X            *toasc_p++ = *bptr++ & 127;
  788. X        *toasc_p++ = '\n';
  789. X        *toasc_p = '\0';
  790. X        if (write (B_write[1], Mop, strlen(Mop)) == -1)
  791. X            fatal("wait_conv_pipe write");
  792. X        wait_conv_pipe(tobuf);
  793. X    }
  794. X    TR_
  795. X}
  796. X
  797. SHAR_EOF
  798. $TOUCH -am 0221163890 convbase.c &&
  799. chmod 0644 convbase.c ||
  800. echo "restore of convbase.c failed"
  801. set `wc -c convbase.c`;Wc_c=$1
  802. if test "$Wc_c" != "7993"; then
  803.     echo original size 7993, current size $Wc_c
  804. fi
  805. # ============= display.c ==============
  806. echo "x - extracting display.c (Text)"
  807. sed 's/^X//' << 'SHAR_EOF' > display.c &&
  808. X/* display.c */
  809. X/**********************************************************************
  810. X*    File Name     : display.c
  811. X*    Function      : calculator, stack, status window displays of pac
  812. X*    Author        : Istvan Mohos, 1987
  813. X***********************************************************************/
  814. X
  815. X#include "defs.h"
  816. X
  817. X/* display Mainbuf after wait_main_pipe:
  818. X   trim Mainbuf; reformat Mainbuf data in Rebuf, Tmpbuf */
  819. Xdisplay_accum(showflag)
  820. Xint showflag;
  821. X{
  822. X    int zerofill;
  823. X    int dp_at = -1;
  824. X    register int ri;
  825. X    register char *dpptr;
  826. X    char *tpt;
  827. X    int tmpsiz, readsiz;
  828. X    int noint = 0;
  829. X    struct stk_cell *sr = &Stk[0];
  830. X    static char *fid = "display_accum";
  831. X
  832. X    _TR
  833. X    Bc_error = 0;
  834. X    Negative = Too_big = Has_dp = FALSE;
  835. X    e_syntax();
  836. X    e_divby0();
  837. X    e_exponent();
  838. X    e_bcexec();
  839. X
  840. X    if (*Mainbuf == '-')
  841. X        Negative = TRUE;
  842. X
  843. X    dpptr = Mainbuf;
  844. X    if (*dpptr == '.') 
  845. X        noint = 1;
  846. X    ri = 0;
  847. X    while (*dpptr != '\0') { /* wait_pipe changed last newline to \0 */
  848. X        ++ri;
  849. X        if (*dpptr++ == '.') {
  850. X            tpt = dpptr + Precision +1;
  851. X            *tpt = '\0';  /* cut overenthusiastic bc digits */
  852. X            if (tpt == dpptr + strlen(dpptr)) {
  853. X                if (round(Mainbuf, Mainbuf+strlen(Mainbuf))) {
  854. X                    ++dpptr; /* decimal point shifted 1 byte to right */
  855. X                    ++ri;
  856. X                }
  857. X            }
  858. X            Has_dp = TRUE;
  859. X            dp_at = ri;
  860. X        }
  861. X    }
  862. X    if (Has_dp) {               /* trailing zero suppression */
  863. X        while (*--dpptr == '0') {
  864. X            *dpptr = '\0';
  865. X            --ri;
  866. X        }
  867. X        if (*dpptr == '.') {
  868. X            if (noint) {
  869. X                *dpptr = '0';
  870. X                pac_err("underflow");
  871. X            }
  872. X            else {
  873. X                *dpptr = '\0';
  874. X                --ri;
  875. X            }
  876. X            Has_dp = FALSE;
  877. X        }
  878. X    }
  879. X    readsiz = ri;
  880. X
  881. X    if ((strlen(Mainbuf) - Negative - Has_dp) > DIGMAX) {
  882. X        Too_big = TRUE;
  883. X        if (dp_at >= ACCUMAX)
  884. X            Has_dp = FALSE;
  885. X        e_overflow();  /* this error leaves oversize number in buffer */
  886. X        readsiz = DIGMAX + Negative + Has_dp;
  887. X        Mainbuf[readsiz] = '\0';
  888. X    }
  889. X
  890. X    sprintf(sr->cell, "%c %-*.*s", *(Base_str + Obase),
  891. X        STACKMAX-2, STACKMAX-2, Mainbuf);
  892. X
  893. X    if(Justify == JL) {
  894. X        strcpy(Rebuf, Mainbuf);
  895. X        strcat(Rebuf, Sp44);
  896. X        Rebuf[ACCUMAX] = '\0';
  897. X        display(Rebuf);
  898. X    }
  899. X    else if (Justify == JR) {
  900. X        strcpy(Rebuf, Sp44);
  901. X        strcpy(&Rebuf[ACCUMAX - readsiz], Mainbuf);
  902. X        Rebuf[ACCUMAX] = '\0';
  903. X        display(Rebuf);
  904. X    }
  905. X    else {   /* JF */
  906. X        strcpy(Tmpbuf, Mainbuf);
  907. X        if (!Too_big) {
  908. X            if (Has_dp) {
  909. X                strcat(Tmpbuf, Fix32);
  910. X                zerofill = Precision - (readsiz - dp_at);
  911. X                Tmpbuf[readsiz + zerofill] = '\0';
  912. X            }
  913. X            else
  914. X                sprintf(&Tmpbuf[readsiz], ".%.*s", Precision, Fix32);
  915. X        }
  916. X        Tmpbuf[DIGMAX + Negative + Has_dp] = '\0';
  917. X        tmpsiz = strlen(Tmpbuf);
  918. X        strcpy(Rebuf, Sp44);
  919. X        strcpy(&Rebuf[ACCUMAX - tmpsiz], Tmpbuf);
  920. X        display(Rebuf);
  921. X    }
  922. X
  923. X    if ((Stack == ENA) && Painted) {
  924. X        pushstack(1);
  925. X        stack_reg(1, 0);
  926. X    }
  927. X    move(CY=UTOP, CX=ULEFT);
  928. X    if (showflag)
  929. X        pfresh();
  930. X    TR_
  931. X}
  932. X
  933. X/* break up long digit string with spaces, for formatted display */
  934. Xdisplay(source)
  935. Xchar *source;
  936. X{
  937. X    char backward[MYBUF];
  938. X    register ri;
  939. X    register char *from, *to;
  940. X    char *numstart, *frommark, *tomark;
  941. X    int inlen, tail, group, int_digs;
  942. X    static char *fid = "display";
  943. X    
  944. X    _TR
  945. X    if (Format == DISA) {
  946. X        mvaddstr(ACCUM,ULEFT,source);
  947. X        if (Hc != -1 && !Hide) {
  948. X            if ((write(Hc, source, strlen(source))) !=
  949. X                strlen(source))
  950. X                fatal("hardcopy accumulator write");
  951. X            if ((write(Hc, "\n", 1)) != 1)
  952. X                fatal("hardcopy accumulator write");
  953. X        }
  954. X    }
  955. X    else {
  956. X        switch(Obase) {
  957. X        case 2:
  958. X            group = 8;
  959. X            break;
  960. X        case 8:
  961. X        case 10:
  962. X            group = 3;
  963. X            break;
  964. X        case 16:
  965. X        default:
  966. X            group = 4;
  967. X            break;
  968. X        }
  969. X        inlen = strlen(source);
  970. X        from = numstart = source;
  971. X        while ((*numstart == ' ') || (*numstart == '-')) {
  972. X                ++numstart;
  973. X                ++from;
  974. X        }
  975. X        if (*numstart == '.')
  976. X            numstart = ZERO;        /* bc does not prepend 0 before . */
  977. X
  978. X        while (*from != '.' && *from != ' ' && *from != '\0')
  979. X            ++from;                 /* stop on dot, space or null */
  980. X
  981. X        if (from == source + inlen)        /* no fraction */
  982. X            to = &backward[MYBUF - 1];     /* end of source: '\0' */
  983. X        else {
  984. X            tail = source - from + inlen;  /* on (include) dec. point */
  985. X            to = &backward[MYBUF - 1 - tail - (tail-2)/group];
  986. X
  987. X            frommark = from;
  988. X            tomark = to;
  989. X            *to++ = *from++;
  990. X            for (ri = 0; ++ri < tail;) {
  991. X                *to++ = *from++;
  992. X                if ((ri % group == 0) && (*from != ' '))
  993. X                    *to++ = Separator;
  994. X            }
  995. X            from = frommark;
  996. X            to = tomark;
  997. X        }
  998. X        backward[MYBUF - 1] = '\0';
  999. X
  1000. X        if (numstart != ZERO) {
  1001. X            --to;
  1002. X            --from;                        /* back to last int digit */
  1003. X            int_digs = from - numstart;    /* one more, really */
  1004. X            for (ri = 0; ++ri <= int_digs;) {
  1005. X                *to-- = *from--;
  1006. X                if (ri % group == 0)
  1007. X                    *to-- = Separator;
  1008. X            }
  1009. X            *to = *from;                   /* first integer digit */
  1010. X        }
  1011. X        if (Negative)
  1012. X            *--to = *--from;
  1013. X
  1014. X        if (Justify == JL) {
  1015. X            strcpy(Tmpbuf, to);
  1016. X            strcat(Tmpbuf, Sp44);
  1017. X            Tmpbuf[ACCUMAX] = '\0';
  1018. X            mvaddstr(ACCUM,ULEFT, Tmpbuf);
  1019. X            if (Hc != -1 && !Hide) {
  1020. X            if ((write(Hc, Tmpbuf, strlen(Tmpbuf))) !=
  1021. X                strlen(Tmpbuf))
  1022. X                fatal("hardcopy justified left write");
  1023. X            if ((write(Hc, "\n", 1)) != 1)
  1024. X                fatal("hardcopy justified left write");
  1025. X            }
  1026. X        }
  1027. X        else {
  1028. X            for (ri = from - source + 1; --ri;)
  1029. X                *to-- = *from--;
  1030. X            *to = *from;          /* to avoid indexing neg. address */
  1031. X            to = &backward[MYBUF - 1 - ACCUMAX];
  1032. X            mvaddstr(ACCUM,ULEFT, to);
  1033. X            if (Hc != -1 && !Hide) {
  1034. X                if ((write(Hc, to, strlen(to))) != strlen(to))
  1035. X                    fatal("justified right write");
  1036. X                if ((write(Hc, "\n", 1)) != 1)
  1037. X                    fatal("justified right write");
  1038. X            }
  1039. X        }
  1040. X    }
  1041. X    TR_
  1042. X}
  1043. X
  1044. X/* flag values:
  1045. X   2)     write to Main pipe, clear_accwin, display_accum.  The user
  1046. X          input string is assumed to have completed processing.
  1047. X   1)     write to Main pipe, clear_accwin, display_accum only if
  1048. X          Show is ENA.  (Some functions may withold the current
  1049. X          result from the stack, by temporarily disabling Stack.)
  1050. X          The operation always results in a new value from bc, and
  1051. X          in the clearing of the input string up to the currently
  1052. X          scanned token.
  1053. X   0)     write control info to main pipe, redraw Status window.
  1054. X          This is a one-way  write to bc, no data is returned in
  1055. X          the pipe; the accumulator and Lastob contents stay intact.
  1056. X          Error bar under accum does get cleared.
  1057. X*/
  1058. X
  1059. Xshow_result(flag)
  1060. Xint flag;
  1061. X{
  1062. X    int Ubuflen, Controlbuflen;
  1063. X    static char *fid = "show_result";
  1064. X
  1065. X    _TR
  1066. X    if (flag) {
  1067. X        if ((Ubuflen = strlen(Ubuf)) != 0) {
  1068. X            if (!(Ubuflen == 2 && Ubuf[0] == ';')) {
  1069. X                if (Ubuf[Ubuflen - 1] != '\n')
  1070. X                    Ubuf[Ubuflen++] = '\n';
  1071. X
  1072. X#ifdef DEBUG
  1073. Xfprintf(Dfp, "Ubuf to A_write: %*.*s<<<\n",Ubuflen, Ubuflen, Ubuf);
  1074. X#endif
  1075. X
  1076. X                if (write(A_write[1], Ubuf, Ubuflen) == -1)
  1077. X                    fatal("ubuf to main pipe write");
  1078. X                clear_accwin();
  1079. X                wait_main_pipe();
  1080. X
  1081. X#ifdef DEBUG
  1082. Xfprintf(Dfp, "Mainbuf read: %s<<<\n", Mainbuf);
  1083. X#endif
  1084. X
  1085. X                Lastob = Obase;
  1086. X
  1087. X                if (Do_conv) {
  1088. X                    Titlq[TALYREQ] = ZERO;
  1089. X                    show_uconv();
  1090. X                    conv_usr();
  1091. X                }
  1092. X
  1093. X                if (Show == ENA || flag > 1)
  1094. X                    display_accum(1);
  1095. X                else
  1096. X                    display_accum(0);
  1097. X            }
  1098. X            Ubuf[0] = '\0';
  1099. X        }
  1100. X    }
  1101. X    else {
  1102. X        if ((Controlbuflen = strlen(Controlbuf)) != 0) {
  1103. X            if (Controlbuf[Controlbuflen - 1] != '\n')
  1104. X                Controlbuf[Controlbuflen++] = '\n';
  1105. X
  1106. X#ifdef DEBUG
  1107. Xfprintf(Dfp, "Control to A_write: %*.*s<<<\n", Controlbuflen,
  1108. X    Controlbuflen, Controlbuf);
  1109. X#endif
  1110. X
  1111. X            if (write(A_write[1], Controlbuf, Controlbuflen) == -1)
  1112. X                fatal("controlbuf to main pipe write");
  1113. X        }
  1114. X        show_stat();
  1115. X        Controlbuf[0] = '\0';
  1116. X        move(CY=UTOP, CX=ULEFT);
  1117. X        pfresh();
  1118. X    }
  1119. X    TR_
  1120. X}
  1121. X
  1122. Xshow_stat()
  1123. X{
  1124. X    static char *statstr = "  23456789ABCDEFX";
  1125. X    register int cur_y = STATY;
  1126. X    int pyp, pxp;
  1127. X    static char *fid = "show_stat";
  1128. X
  1129. X    _TR
  1130. X    CYX;
  1131. X    standout();
  1132. X    mvaddstr(STATY - 1, STATMSG - 1, "    GLOBALS     ");
  1133. X    standend();
  1134. X
  1135. X    move(cur_y++, STATMSG);
  1136. X    printw("    ibase %c   " , statstr[Ibase]);
  1137. X
  1138. X    move(cur_y++, STATMSG);
  1139. X    printw("    obase %c   " , statstr[Obase]);
  1140. X
  1141. X    mvaddstr(cur_y++, STATMSG, (Staybase == ENA) ?  " staybase on  " 
  1142. X                                                :  " staybase off " );
  1143. X
  1144. X
  1145. X    move(cur_y++, STATMSG);
  1146. X    printw("precision %d  " , Precision);
  1147. X
  1148. X    mvaddstr(cur_y++, STATMSG, (Autoconv == ENA) ?  " autoconv on  " 
  1149. X                                                :  " autoconv off " );
  1150. X
  1151. X    if (Format == COMMA_)
  1152. X        mvaddstr(cur_y++, STATMSG,  "   format ',' " );
  1153. X    else if (Format == DISA)
  1154. X        mvaddstr(cur_y++, STATMSG,  "   format off " );
  1155. X    else /* SPACE_ */
  1156. X        mvaddstr(cur_y++, STATMSG,  "   format ' ' " );
  1157. X
  1158. X    if (Hf == FVER)
  1159. X        mvaddstr(cur_y++, STATMSG,  " hardform ver " );
  1160. X    else if (Hf == FTER)
  1161. X        mvaddstr(cur_y++, STATMSG,  " hardform te  " );
  1162. X    else
  1163. X        mvaddstr(cur_y++, STATMSG,  " hardform xt  " );
  1164. X
  1165. X    if (Justify == JF)
  1166. X        mvaddstr(cur_y++, STATMSG,  "  justify fix " );
  1167. X    else if (Justify == JR)
  1168. X        mvaddstr(cur_y++, STATMSG,  "  justify ri  " );
  1169. X    else
  1170. X        mvaddstr(cur_y++, STATMSG,  "  justify le  " );
  1171. X
  1172. X    mvaddstr(cur_y++, STATMSG, (Stack == ENA) ?  "    stack on  " 
  1173. X                                             :  "    stack off " );
  1174. X    mvaddstr(cur_y++, STATMSG, (Autotime == ENA) ?  " autotime on  " 
  1175. X                                             :  " autotime off " );
  1176. X    Statopts = 0;
  1177. X
  1178. X    PYX;
  1179. X    pfresh();
  1180. X    TR_
  1181. X}
  1182. X
  1183. Xshow_param()
  1184. X{
  1185. X    register int cur_y = STATY;
  1186. X    int pyp, pxp;
  1187. X    static char *fid = "show_param";
  1188. X
  1189. X    _TR
  1190. X    CYX;
  1191. X    standout();
  1192. X    mvaddstr(STATY - 1, STATMSG - 1, " STAT  OPTIONS  ");
  1193. X    standend();
  1194. X
  1195. X    mvaddstr(cur_y++, STATMSG, "ib   2 --- 16 ");
  1196. X    mvaddstr(cur_y++, STATMSG, "ob   2 --- 16 ");
  1197. X    mvaddstr(cur_y++, STATMSG, "sb     off|on ");
  1198. X    mvaddstr(cur_y++, STATMSG, "pr   0 --- 32 ");
  1199. X    mvaddstr(cur_y++, STATMSG, "au     off|on ");
  1200. X    mvaddstr(cur_y++, STATMSG, "fo  sp|off|cm ");
  1201. X    mvaddstr(cur_y++, STATMSG, "hf  te|ver|xt ");
  1202. X    mvaddstr(cur_y++, STATMSG, "ju  le|fix|ri ");
  1203. X    mvaddstr(cur_y++, STATMSG, "st     off|on ");
  1204. X    mvaddstr(cur_y++, STATMSG, "at     off|on ");
  1205. X
  1206. X    Statopts = 1;
  1207. X    PYX;
  1208. X    pfresh();
  1209. X    TR_
  1210. X}
  1211. X
  1212. SHAR_EOF
  1213. $TOUCH -am 0221163890 display.c &&
  1214. chmod 0644 display.c ||
  1215. echo "restore of display.c failed"
  1216. set `wc -c display.c`;Wc_c=$1
  1217. if test "$Wc_c" != "11737"; then
  1218.     echo original size 11737, current size $Wc_c
  1219. fi
  1220. # ============= error.c ==============
  1221. echo "x - extracting error.c (Text)"
  1222. sed 's/^X//' << 'SHAR_EOF' > error.c &&
  1223. X/* error.c */
  1224. X/**********************************************************************
  1225. X*    File Name     : error.c
  1226. X*    Function      : handling of error messages
  1227. X*    Author        : Istvan Mohos, 1987
  1228. X***********************************************************************/
  1229. X
  1230. X#include "defs.h"
  1231. X
  1232. Xe_syntax()
  1233. X{
  1234. X    static char *fid = "e_syntax";
  1235. X
  1236. X    _TR
  1237. X    if (strncmp(Mainbuf, "syntax error", 12) == 0) {
  1238. X        if (write(A_write[1], "0\n", 2) == -1)
  1239. X            fatal("error recovery to main pipe write");
  1240. X        /* read back a zero, so next error won't hang bc pipe */
  1241. X        wait_main_pipe();
  1242. X        standout();
  1243. X        move(MSG, MSGLEFT);
  1244. X        printw("bc: syntax error                 ");
  1245. X        if (Hc != -1 && Hf == FVER)
  1246. X            if ((write(Hc, "ERROR: syntax\n", 14)) != 14)
  1247. X                fatal("error recovery hardcopy write");
  1248. X        standend();
  1249. X        Bc_error = E_SYNTAX;
  1250. X    }
  1251. XTR_
  1252. X}
  1253. X
  1254. Xe_bcexec()
  1255. X{
  1256. X    static char *fid = "e_bcexec";
  1257. X
  1258. X    _TR
  1259. X    if (strncmp(Mainbuf, "save:args", 9) == 0) {
  1260. X        if (write(A_write[1], "0\n", 2) == -1)
  1261. X            fatal("error recovery to main pipe write");
  1262. X        /* read back a zero, so next error won't hang bc pipe */
  1263. X        wait_main_pipe();
  1264. X        standout();
  1265. X        move(MSG, MSGLEFT);
  1266. X        printw("bc: bc calculator failure        ");
  1267. X        if (Hc != -1 && Hf == FVER)
  1268. X            if ((write(Hc, "ERROR: bcexec\n", 14)) != 14)
  1269. X                fatal("error recovery hardcopy write");
  1270. X        standend();
  1271. X        Bc_error = E_BCEXEC;
  1272. X    }
  1273. XTR_
  1274. X}
  1275. X
  1276. Xe_divby0()
  1277. X{
  1278. X    static char *fid = "e_divby0";
  1279. X
  1280. X    _TR
  1281. X    if (strncmp(Mainbuf, "divide by 0", 11) == 0) {
  1282. X        Mainbuf[0] = '0';
  1283. X        Mainbuf[1] = '\0';
  1284. X        standout();
  1285. X        move(MSG, MSGLEFT);
  1286. X        printw("bc: divide by 0 error            ");
  1287. X        if (Hc != -1 && Hf == FVER)
  1288. X            if ((write(Hc, "ERROR: divide by 0\n", 19)) != 19)
  1289. X                fatal("divby0 hardcopy write");
  1290. X        standend();
  1291. X        Bc_error = E_DIVBY0;
  1292. X    }
  1293. XTR_
  1294. X}
  1295. X
  1296. Xe_exponent()
  1297. X{
  1298. X    static char *fid = "e_exponent";
  1299. X
  1300. X    _TR
  1301. X    if (strncmp(Mainbuf, "exp not an integer", 18) == 0) {
  1302. X        Mainbuf[0] = '0';
  1303. X        Mainbuf[1] = '\0';
  1304. X        standout();
  1305. X        move(MSG, MSGLEFT);
  1306. X        printw("bc: non-integer exponent error   ");
  1307. X        if (Hc != -1 && Hf == FVER)
  1308. X            if ((write(Hc, "ERROR: exponent not integer\n", 28)) != 28)
  1309. X                fatal("non-int exponent hardcopy write");
  1310. X        standend();
  1311. X        Bc_error = E_EXPONENT;
  1312. X    }
  1313. X    else if (strncmp(Mainbuf, "exp too big", 11) == 0) {
  1314. X        if (write(A_write[1], "0\n", 2) == -1)
  1315. X            fatal("exp2big main pipe write");
  1316. X        /* read back a zero, so next error won't hang bc pipe */
  1317. X        wait_main_pipe();
  1318. X        Mainbuf[0] = '0';
  1319. X        Mainbuf[1] = '\0';
  1320. X        standout();
  1321. X        move(MSG, MSGLEFT);
  1322. X        printw("bc: exponent too big error       ");
  1323. X        if (Hc != -1 && Hf == FVER)
  1324. X            if ((write(Hc, "ERROR: exponent too big\n", 24)) !=  24)
  1325. X                fatal("exp2big hardcopy write");
  1326. X        standend();
  1327. X        Bc_error = E_EXPONENT;
  1328. X    }
  1329. XTR_
  1330. X}
  1331. X
  1332. Xe_overflow()
  1333. X{
  1334. X    static char *fid = "e_overflow";
  1335. X
  1336. X    _TR
  1337. X    if (Has_dp == FALSE) { /* don't really care if some digits beyond
  1338. X                              the dp fall off, in this case */
  1339. X        standout();
  1340. X        move(MSG, MSGLEFT);
  1341. X        printw(" panel overflow: 32 digits max.  ");
  1342. X        if (Hc != -1 && Hf == FVER)
  1343. X            if ((write(Hc, "ERROR: overflow\n", 16)) !=  16)
  1344. X                fatal("overflow hardcopy write");
  1345. X        standend();
  1346. X        Bc_error = E_OVERFLOW;
  1347. X    }
  1348. XTR_
  1349. X}
  1350. X
  1351. Xpac_err(message)
  1352. Xchar *message;
  1353. X{ 
  1354. X    char msg[35];
  1355. X    static char *fid = "pac_err";
  1356. X
  1357. X    _TR
  1358. X    strcpy(msg, Sp34); 
  1359. X    if (strlen(message) > 22)
  1360. X        *(message + 22) = '\0';
  1361. X    sprintf(msg, "pac error: %-*s", 22, message);
  1362. X    standout();
  1363. X    move(MSG, MSGLEFT);
  1364. X    printw(msg);
  1365. X    standend();
  1366. X    pfresh();
  1367. XTR_
  1368. X}
  1369. X
  1370. SHAR_EOF
  1371. $TOUCH -am 0221163890 error.c &&
  1372. chmod 0644 error.c ||
  1373. echo "restore of error.c failed"
  1374. set `wc -c error.c`;Wc_c=$1
  1375. if test "$Wc_c" != "3940"; then
  1376.     echo original size 3940, current size $Wc_c
  1377. fi
  1378. # ============= file.c ==============
  1379. echo "x - extracting file.c (Text)"
  1380. sed 's/^X//' << 'SHAR_EOF' > file.c &&
  1381. X/* file.c */
  1382. X/**********************************************************************
  1383. X*    File Name     : file.c
  1384. X*    Function      : file i/o of pac: rc, hardcopies, debug files
  1385. X*    Author        : Istvan Mohos, 1987
  1386. X***********************************************************************/
  1387. X
  1388. X#include "defs.h"
  1389. X#define FILEMAP
  1390. X#include "maps.h"
  1391. X#undef FILEMAP
  1392. X
  1393. X#define RCMIN  (STACKDEEP * (STACKMAX + 1) + 53) /* minimum count */
  1394. Xread_rc()
  1395. X{
  1396. X    char rcbuf[PIPEMAX];
  1397. X    register char *rc = rcbuf;
  1398. X    static char *fid = "read_rc";
  1399. X
  1400. X    _TR
  1401. X    if (read(Rcfd, rc, RCMIN) < RCMIN) {
  1402. X        mvaddstr(2,4,"Rcerr after RCMIN");
  1403. X        pfresh();
  1404. X        Rcerr = TRUE;
  1405. X        TR_
  1406. X        return;
  1407. X    }
  1408. X    if ((Format = *rc++ -48)!=COMMA_ && Format!=SPACE_ && Format!=DISA)
  1409. X        Format = FORM_DFLT;
  1410. X    (Format == COMMA_) ? (Separator = ',') : (Separator = ' ');
  1411. X
  1412. X    if ((Hf = *rc++ -48) != FVER && Hf != FTER && Hf != FXTER)
  1413. X        Hf = HF_DFLT;
  1414. X    if ((Ibase = *rc++ -48) < 2 || Ibase > 16)
  1415. X        Ibase = IB_DFLT;
  1416. X    if ((Justify = *rc++ -48) != JL && Justify != JF && Justify != JR)
  1417. X        Justify = JUS_DFLT;
  1418. X    if ((Obase = *rc++ -48) < 2 || Obase > 16)
  1419. X        Obase = OB_DFLT;
  1420. X    if ((Precision = *rc++ -48) < 0 || Precision > 32)
  1421. X        Precision = PREC_DFLT;
  1422. X    if ((Autotime = *rc++ -48) != ENA && Autotime != DISA)
  1423. X        Autotime = DISA;
  1424. X    if ((Stack = *rc++ -48) != ENA && Stack != DISA)
  1425. X        Stack = STACK_DFLT;
  1426. X    if ((Staybase = *rc++ -48) != ENA && Staybase != DISA)
  1427. X        Staybase = SB_DFLT;
  1428. X    if ((Convcount = atoi(rc)) > 255 || Convcount < CONVCOUNT) {
  1429. X        mvaddstr(2,4,"Rcerr at Convcount");
  1430. X        pfresh();
  1431. X        Rcerr = TRUE;
  1432. X        TR_
  1433. X        return;
  1434. X    }
  1435. X    rc += 4;
  1436. X    if ((Convsel = atoi(rc)) < 0 || Convsel > Convcount -1)
  1437. X        Convsel = CONVSEL;
  1438. X    rc += 4;
  1439. X    if ((Convhsiz = atoi(rc)) < 1) {
  1440. X        mvaddstr(2,4,"Rcerr after Convhsiz");
  1441. X        pfresh();
  1442. X        Rcerr = TRUE;
  1443. X        TR_
  1444. X        return;
  1445. X    }
  1446. X    rc += 6;
  1447. X    if ((Amt = atof(rc)) < 0.)
  1448. X        Amt = 0.;
  1449. X    rc += 14;
  1450. X    if ((Years = atof(rc)) < 0.)
  1451. X        Years = 0.;
  1452. X    rc += 8;
  1453. X    if ((Rate = atof(rc)) < 0.)
  1454. X        Rate = 0.;
  1455. X    rc += 8;
  1456. X
  1457. X    fill_stack(rc);
  1458. X
  1459. X    if ((Convhom = malloc(Convhsiz)) == ZERO)
  1460. X        fatal("malloc error at read_rc");
  1461. X
  1462. X    if (read(Rcfd, Convhom, (int)Convhsiz) != Convhsiz) {
  1463. X        mvaddstr(2,4,"Rcerr after Convhom");
  1464. X        pfresh();
  1465. X        Rcerr = TRUE;
  1466. X        TR_
  1467. X        return;
  1468. X    }
  1469. X
  1470. X    for (rc = Convhom + Convhsiz; --rc > Convhom;)
  1471. X        if (*rc == '\n')
  1472. X            *rc = 0;
  1473. X    realign_conv();
  1474. X    TR_
  1475. X}
  1476. X
  1477. Xwrite_rc()
  1478. X{
  1479. X    char rcbuf[PIPEMAX];
  1480. X    register char *rc = rcbuf;
  1481. X    static char *fid = "write_rc";
  1482. X
  1483. X    _TR
  1484. X    if (Home != ZERO && !Dontsave) {
  1485. X        if ((Rcfd = open(Rcfile, O_WRONLY | O_CREAT, 0600)) != -1) {
  1486. X
  1487. X            *rc++ = Format +48;
  1488. X            *rc++ = Hf +48;
  1489. X            *rc++ = Ibase +48;
  1490. X            *rc++ = Justify +48;
  1491. X            *rc++ = Obase +48;
  1492. X            *rc++ = Precision +48;
  1493. X            *rc++ = Autotime +48;
  1494. X            *rc++ = Stack +48;
  1495. X            *rc++ = Staybase +48;
  1496. X            sprintf(rc, "%3d;%3d;%5d\n", Convcount, Convsel, Convhsiz);
  1497. X            rc += 14;
  1498. X            sprintf(rc, "%13.2f", Amt);
  1499. X            rc += 13;
  1500. X            *rc++ = ';'; /* printf too generous on overflow*/
  1501. X            sprintf(rc, "%7.3f", Years);
  1502. X            rc += 7;
  1503. X            *rc++ = ';';
  1504. X            sprintf(rc, "%7.3f", Rate);
  1505. X            rc += 7;
  1506. X            *rc++ = '\n';
  1507. X
  1508. X            save_stack(rc, 0);
  1509. X
  1510. X            if ((write(Rcfd, rcbuf, RCMIN)) != RCMIN)
  1511. X                fatal("pacrc stack write");
  1512. X
  1513. X            for (rc = Convhom + Convhsiz; --rc > Convhom;)
  1514. X                if (*rc == '\0')
  1515. X                    *rc = '\n';
  1516. X            if ((write(Rcfd, Convhom, (int)Convhsiz)) != (int)Convhsiz)
  1517. X                fatal("pacrc conv write");
  1518. X
  1519. X            close(Rcfd);
  1520. X       }
  1521. X    }
  1522. X    TR_
  1523. X}
  1524. X
  1525. X#ifdef DESIGN
  1526. Xread_scr(name)        /* read screen image from named file */
  1527. Xchar *name;
  1528. X{
  1529. X    FILE *fp;
  1530. X    register rx, ry;
  1531. X    static char *fid = "read_scr";
  1532. X
  1533. X    _TR
  1534. X    if ((fp = fopen(name, "r")) != NULL) {
  1535. X        for (ry = 0; ry < LINES; ry++)
  1536. X            for (rx=0; rx < COLS-1; rx++)
  1537. X                stdscr->_y[ry][rx] = fgetc(fp);
  1538. X        fclose(fp);
  1539. X    }
  1540. X    TR_
  1541. X}
  1542. X
  1543. Xwrite_scr(name, rf)
  1544. Xchar *name;
  1545. Xint rf;
  1546. X{
  1547. X    FILE *fp;
  1548. X    register rx, ry;
  1549. X    static char *fid = "write_scr";
  1550. X
  1551. X    _TR
  1552. X    if ((fp = fopen(name, "w")) == NULL)
  1553. X        Status = 1, fatal("write image");
  1554. X    if (rf)
  1555. X        for (ry = 0; ry < LINES; ry++)
  1556. X            for (rx=0; rx < COLS-1; rx++)
  1557. X                putc(stdscr->_y[ry][rx] & 0377, fp);
  1558. X    else
  1559. X        for (ry = 0; ry < LINES; ry++) {
  1560. X            for (rx=0; rx < COLS-1; rx++)
  1561. X                putc(stdscr->_y[ry][rx] & 127, fp);
  1562. X            putc('\n', fp);
  1563. X        }
  1564. X    fclose(fp);
  1565. X    TR_
  1566. X}
  1567. X#endif
  1568. X
  1569. Xhard(fnum)
  1570. Xint fnum;
  1571. X{
  1572. X    int newlev;
  1573. X    int pyp, pxp;
  1574. X    int *whichfile, *whichfd;
  1575. X    char *np;
  1576. X    char *whichname;
  1577. X    char namebuf[TITSIZ + 1];
  1578. X    char spaceless[TITSIZ + 1];
  1579. X    static char *fid = "hard";
  1580. X
  1581. X    _TR
  1582. X    if (fnum) {
  1583. X        whichname = Totname;
  1584. X        whichfd = &Tc;
  1585. X        if (*(whichfile = &Totcopy) == ENA)
  1586. X            newlev = TOTLREQ;
  1587. X        else if (*whichfile == AP)
  1588. X            newlev = TAPPREQ;
  1589. X        else {
  1590. X            newlev = TALYREQ;
  1591. X            Basq[TOTLREQ] = ZERO;
  1592. X            Basq[TAPPREQ] = ZERO;
  1593. X        }
  1594. X    }
  1595. X    else {
  1596. X        whichname = Hardname;
  1597. X        whichfd = &Hc;
  1598. X        if (*(whichfile = &Hardcopy) == ENA)
  1599. X            newlev = FILEREQ;
  1600. X        else if (*whichfile == AP)
  1601. X            newlev = POSTREQ;
  1602. X        else {
  1603. X            newlev = 0;
  1604. X            Basq[FILEREQ] = ZERO;
  1605. X            Basq[POSTREQ] = ZERO;
  1606. X        }
  1607. X    }
  1608. X    Basq[newlev] = Bb[newlev];
  1609. X    Basq[EDITREQ] = Bb[newlev];
  1610. X    CYX;  /* to save the caller's coordinates */
  1611. X    update();  /* this returns to the original coordinates,
  1612. X                  but does'nt pfresh */
  1613. X    
  1614. X    if (*whichfile == ENA || *whichfile == AP) {
  1615. X
  1616. Xredo:
  1617. X
  1618. X        ledit(namebuf, f_ed_map, BOT, FBOUND, RBOUND, 1, 1, 0);
  1619. X
  1620. X        if (strlen(namebuf) == 0) {
  1621. X            strcpy(spaceless, whichname);
  1622. X            for (np = spaceless; *np > 32; np++);
  1623. X            *np = '\0';
  1624. X            standout();
  1625. X            mvaddstr(BOT, FBOUND, whichname);
  1626. X            standend();
  1627. X            pfresh();
  1628. X        }
  1629. X        else {
  1630. X            strcpy(whichname, namebuf);
  1631. X            strcpy(spaceless, namebuf);
  1632. X        }
  1633. X
  1634. X        if (*whichfile == ENA) {
  1635. X            if ((*whichfd = open(spaceless,
  1636. X            O_WRONLY | O_CREAT | O_TRUNC, 0644)) == -1) {
  1637. X                standout();
  1638. X                mvaddstr(BOT, ULEFT, "can't access:");
  1639. X                standend();
  1640. X                pfresh();
  1641. X                goto redo;
  1642. X            }
  1643. X        }
  1644. X        else if ((*whichfd = open(spaceless,
  1645. X            O_WRONLY | O_APPEND | O_CREAT, 0644)) == -1) {
  1646. X                standout();
  1647. X                mvaddstr(BOT, ULEFT, "can't access:");
  1648. X                standend();
  1649. X                pfresh();
  1650. X                goto redo;
  1651. X        }
  1652. X        /* make a copy of name in alternate buffer also */
  1653. X        if (*whichfile == AP) {
  1654. X            strcpy(Bb[newlev - 1] + BUFSTOP, whichname);
  1655. X            rev_clear(Bb[newlev - 1] + TITSIZ);
  1656. X        }
  1657. X        else {
  1658. X            strcpy(Bb[newlev + 1] + BUFSTOP, whichname);
  1659. X            rev_clear(Bb[newlev + 1] + TITSIZ);
  1660. X        }
  1661. X        strcpy(Bb[newlev] + BUFSTOP, whichname);
  1662. X        rev_clear(Bb[newlev] + TITSIZ);
  1663. X        Basq[EDITREQ] = ZERO;
  1664. X    }
  1665. X    PYX;
  1666. X    update();
  1667. X    pfresh();
  1668. X    TR_
  1669. X}
  1670. SHAR_EOF
  1671. $TOUCH -am 0221163890 file.c &&
  1672. chmod 0644 file.c ||
  1673. echo "restore of file.c failed"
  1674. set `wc -c file.c`;Wc_c=$1
  1675. if test "$Wc_c" != "7596"; then
  1676.     echo original size 7596, current size $Wc_c
  1677. fi
  1678. echo "End of part 3, continue with part 4"
  1679. exit 0
  1680.  
  1681.