home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / source / pac.lzh / pac.3 < prev    next >
Encoding:
Text File  |  1990-08-12  |  46.7 KB  |  1,672 lines

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