home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Distributions / ucb / spencer_2bsd.tar.gz / 2bsd.tar / src / pi1 / receive.c < prev    next >
C/C++ Source or Header  |  1980-02-17  |  7KB  |  441 lines

  1. /* Copyright (c) 1979 Regents of the University of California */
  2. #include "0.h"
  3. #include "send.h"
  4. #include "tree.h"
  5. /*
  6.  * Pi - Pascal interpreter code translator
  7.  *
  8.  * Bill Joy UCB February 6, 1978
  9.  */
  10.  
  11. int    fp2[DSPLYSZ];
  12. int    pin[259];    /* Unit 0 */
  13. int    ackd, acker;
  14.  
  15. #ifdef DEBUG
  16. extern    char *trnames[];
  17. #endif
  18. extern    int *spacep;
  19. extern    char printed, hadsome, *lastname, *obj;
  20.  
  21. #ifdef DEBUG
  22. char    *rnames[] {
  23.     "",
  24.     "RINIT",
  25.     "RENQ",
  26.     "RTREE",
  27.     "RTRFREE",
  28.     "RTRCHK",
  29.     "REVENIT",
  30.     "RSTRING",
  31.     "REVLAB",
  32.     "REVCNST",
  33.     "REVTBEG",
  34.     "REVTYPE",
  35.     "REVTEND",
  36.     "REVVBEG",
  37.     "REVVAR",
  38.     "REVVEND",
  39.     "REVFHDR",
  40.     "REVFFWD",
  41.     "REVFBDY",
  42.     "REVFEND",
  43.     "ROPUSH",
  44.     "ROPOP",
  45.     "ROSET",
  46.     "RKILL",
  47.     "RFINISH",
  48. };
  49. #endif
  50.  
  51. #define    getaw()        getw(pin)
  52. #define    getac()        getc(pin)
  53. #define    sgetaw()    sreloc(getaw())
  54. #define    tgetaw()    treloc(getaw())
  55.  
  56. receive()
  57. {
  58.     register int i, *ip;
  59.     register char *cp;
  60. #define TREENMAX 6    /* From tree.c */
  61.     int loctree[TREENMAX * 2], locstring[514];
  62.     int ch, j;
  63.  
  64.     for (;;) {
  65.         i = getac();
  66. #ifdef DEBUG
  67.         if (i > 0 && i <= RLAST)
  68.             dprintf("%s\t", rnames[i]);
  69.         else if (i == -1)
  70.             dprintf("EOF\t");
  71.         else
  72.             dprintf("OOPS!\t");
  73. #endif
  74.         holdderr = 1;
  75.         switch (i) {
  76.  
  77.         case RINIT:
  78.             lastname = sreloc(getaw());
  79.             obj = sreloc(getaw());
  80.             ackd = getac();
  81.             for (i = 0; i < 26; i++)
  82.                 opts[i] = getac();
  83.             efil = getac();
  84.             errfile = sreloc(getaw());
  85.             ofil = getac();
  86.             magic();
  87. #ifdef DEBUG
  88.             dprintf("RINIT\n\t");
  89.             dprintf("lastname \"%s\"\n\t", lastname);
  90.             dprintf("ackd %d\n\t", ackd);
  91.             dprintf("options: ");
  92.             for (i = 0; i < 26; i++)
  93.             if (opts[i])
  94.                 if (i == 1)
  95.                     dprintf("b%d ", opts[1]);
  96.                 else
  97.                     dprintf("%c ", i + 'a');
  98.             dprintf("\n\tefil %d\n", efil);
  99.             dprintf("\terrfile \"%s\"\n", errfile);
  100.             dprintf("\tofil %d\n", ofil);
  101. #endif
  102.             break;
  103.  
  104.         case RENQ:
  105. #ifdef DEBUG
  106.             dprintf("\tACK\n");
  107. #endif
  108.             ack();
  109.             break;
  110.  
  111.         case RTREE:
  112. #ifdef DEBUG
  113.             dprintf("%d ", toffset(spacep));
  114. #endif
  115.             i = getac();
  116.             if (i < 0 || i > T_LAST) {
  117. #ifdef DEBUG
  118.                 dprintf("\tBAD: %d\n", i);
  119. #endif
  120.                 panic("recv RTREE");
  121.                 exit(1);
  122.             }
  123.             cp = trdesc[i];
  124. #ifdef DEBUG
  125.             dprintf("\t%s:", trnames[i]);
  126. #endif
  127.             ip = loctree;
  128.             *ip++ = i;
  129.             j = 1;
  130.             while (*cp) {
  131.                 j++;
  132.                 switch (*cp++) {
  133.  
  134.                 case 's':
  135.                     cp = locstring;
  136.                     i = 512;
  137. #ifdef DEBUG
  138.                     dprintf(" \"");
  139. #endif
  140.                     while ((ch = getac()) && ch != -1) {
  141.                         if (--i == 0)
  142.                             panic("RTREE case s");
  143.                         *cp++ = ch;
  144. #ifdef DEBUG
  145.                         dprintf("%c", ch);
  146. #endif
  147.                     }
  148. #ifdef DEBUG
  149.                     dprintf("\"\n");
  150. #endif
  151.                     *cp++ = 0;
  152.                     copystr(locstring);
  153.                     goto out;
  154.  
  155.                 case 'd':
  156.                     *ip++ = getac();
  157. #ifdef DEBUG
  158.                     dprintf(" d%d", ip[-1]);
  159. #endif
  160.                     continue;
  161.  
  162.                 case 'n':
  163.                     *ip++ = getaw();
  164. #ifdef DEBUG
  165.                     dprintf(" n%d", ip[-1]);
  166. #endif
  167.                     continue;
  168.  
  169.                 case '"':
  170.                     *ip++ = sreloc(getaw());
  171. #ifdef DEBUG
  172.                     if (ip[-1] == NIL)
  173.                         dprintf(" NIL\"");
  174.                     else
  175.                         dprintf(" \"%s\"", ip[-1]);
  176. #endif
  177.                     continue;
  178.  
  179.                 case 'p':
  180.                     *ip++ = treloc(getaw());
  181. #ifdef DEBUG
  182.                     dptree(ip[-1]);
  183. #endif
  184.                     continue;
  185.                 }
  186.             }
  187. #ifdef DEBUG
  188.             dprintf("\n");
  189. #endif
  190.             treev(j, loctree);
  191. out:
  192.             break;
  193.  
  194.         case RTRCHK:
  195.             i = getaw();
  196. #ifdef DEBUG
  197.             dprintf(" %d\n", i);
  198.             if (i != toffset(spacep))
  199.                 dprintf("trchk %d, have %d\n", i, toffset(spacep));
  200. #endif
  201.             break;
  202.  
  203.         case RTRFREE:
  204. #ifdef DEBUG
  205.             dprintf("\t%d\n", toffset(spacep));
  206. #endif
  207.             trfree();
  208.             break;
  209.  
  210.         case REVTBEG:
  211. #ifdef DEBUG
  212.             dprintf("\n");
  213. #endif
  214.             typebeg();
  215.             break;
  216.  
  217.         case REVTEND:
  218. #ifdef DEBUG
  219.             dprintf("\n");
  220. #endif
  221.             typeend();
  222.             break;
  223.  
  224.         case REVVBEG:
  225. #ifdef DEBUG
  226.             dprintf("\n");
  227. #endif
  228.             varbeg();
  229.             break;
  230.  
  231.         case REVVEND:
  232. #ifdef DEBUG
  233.             dprintf("\n");
  234. #endif
  235.             varend();
  236.             break;
  237.  
  238.         case REVENIT:
  239. #ifdef DEBUG
  240.             dprintf("\n");
  241. #endif
  242.             evenit();
  243.             break;
  244.  
  245.         case RSTRING:
  246. #ifdef DEBUG
  247.             dprintf(" \"");
  248. #endif
  249.             cp = locstring;
  250.             i = 512;
  251.             while ((ch = getac()) && ch != -1) {
  252.                 if (--i == 0)
  253.                     panic("RSTRING length");
  254.                 *cp++ = ch;
  255. #ifdef DEBUG
  256.                 dprintf("%c", ch);
  257. #endif
  258.             }
  259. #ifdef DEBUG
  260.             dprintf("\"\n");
  261. #endif
  262.             *cp++ = 0;
  263.             savestr(locstring);
  264.             break;
  265.  
  266.         case REVLAB:
  267.             loctree[0] = treloc(getaw());
  268. #ifdef DEBUG
  269.             dptree(loctree[0]);
  270.             dprintf("\n");
  271. #endif
  272.             label(loctree[0]);
  273.             break;
  274.  
  275.         case REVCNST:
  276.             loctree[0] = getaw();
  277.             loctree[1] = sreloc(getaw());
  278.             loctree[2] = treloc(getaw());
  279. #ifdef DEBUG
  280.             dprintf(" %d", loctree[0]);
  281.             dprintf(" \"%s\"", loctree[1]);
  282.             dptree(loctree[2]);
  283.             dprintf("\n");
  284. #endif
  285.             const(loctree[0], loctree[1], loctree[2]);
  286.             break;
  287.  
  288.         case REVTYPE:
  289.             loctree[0] = getaw();
  290.             loctree[1] = sreloc(getaw());
  291.             loctree[2] = treloc(getaw());
  292. #ifdef DEBUG
  293.             dprintf(" %d", loctree[0]);
  294.             dprintf(" \"%s\"", loctree[1]);
  295.             dptree(loctree[2]);
  296.             dprintf("\n");
  297. #endif
  298.             type(loctree[0], loctree[1], loctree[2]);
  299.             break;
  300.  
  301.         case REVVAR:
  302.             loctree[0] = getaw();
  303.             loctree[1] = treloc(getaw());
  304.             loctree[2] = treloc(getaw());
  305. #ifdef DEBUG
  306.             dprintf(" %d", loctree[0]);
  307.             dptree(loctree[1]);
  308.             dptree(loctree[2]);
  309.             dprintf("\n");
  310. #endif
  311.             var(loctree[0], loctree[1], loctree[2]);
  312.             break;
  313.  
  314.         case REVFHDR:
  315.             loctree[0] = treloc(getaw());
  316. #ifdef DEBUG
  317.             dptree(loctree[0]);
  318.             dprintf("\n");
  319. #endif
  320.             fp2[cbn] = funchdr(loctree[0]);
  321.             break;
  322.  
  323.         case REVFBDY:
  324. #ifdef DEBUG
  325.             dprintf("\n");
  326. #endif
  327.             funcbody(fp2[cbn]);
  328.             break;
  329.  
  330.         case REVFEND:
  331.             holdderr = 0;
  332.             loctree[0] = treloc(getaw());
  333.             loctree[1] = getaw();
  334.             loctree[2] = getaw();
  335.             lastname = sreloc(getaw());
  336.             filename = sreloc(getaw());
  337.             printed = getac();
  338.             hadsome = getac();
  339. #ifdef DEBUG
  340.             dptree(loctree[0]);
  341.             dprintf(" %d", loctree[1]);
  342.             dprintf(" %d", loctree[2]);
  343.             dprintf(" lastname=%s", lastname);
  344.             dprintf(" filename=%s", filename);
  345.             dprintf(" printed=%d", printed);
  346.             dprintf(" hadsome=%d", hadsome);
  347.             dprintf("\n");
  348. #endif
  349.             funcend(fp2[cbn-1], loctree[0], loctree[1], loctree[2]);
  350.             break;
  351.  
  352.         case ROPUSH:
  353.             i = getaw();
  354.             opush(i);
  355. #ifdef DEBUG
  356.             dprintf(" %c\n", i);
  357. #endif
  358.             break;
  359.  
  360.         case ROPOP:
  361.             i = getaw();
  362.             opop(i);
  363. #ifdef DEBUG
  364.             dprintf(" %c\n", i);
  365. #endif
  366.             break;
  367.  
  368.         case ROSET:
  369.             ch = getac();
  370.             i = getaw();
  371. #ifdef DEBUG
  372.             dprintf(" %c=", ch);
  373.             dprintf("%d\n", i);
  374. #endif
  375.             opt(ch) = i;
  376.             break;
  377.  
  378.         case RKILL:
  379. #ifdef DEBUG
  380.             dprintf("I should be dead!\n");
  381. #endif
  382.             panic("RKILL");
  383.             break;
  384.  
  385.         case RFINISH:
  386. #ifdef DEBUG
  387.             dprintf("\n");
  388. #endif
  389.             magic2();
  390.             write(ackd, &eflg, 2);
  391.             break;
  392.  
  393.         case -1:
  394.             ack();
  395. #ifdef DEBUG
  396.             dprintf("\nEXIT\n");
  397. #endif
  398.             exit(0);
  399.  
  400.         default:
  401. #ifdef DEBUG
  402.             dprintf("CODE=%d\n", i);
  403. #endif
  404.             panic("rcv CODE");
  405.         }
  406.     }
  407. }
  408.  
  409. ack()
  410. {
  411.     extern Fp;
  412.     int i[3];
  413.  
  414.     i[0] = lastname;
  415.     i[1] = Fp;
  416.     i[2] = (hadsome << 8) | printed;
  417.     write(ackd, i, 6);
  418. }
  419.  
  420. #ifdef DEBUG
  421. dprintf(a1, a2, a3, a4, a5)
  422. {
  423.     if (opt('d'))
  424.         printf(a1, a2, a3, a4, a5);
  425. }
  426.  
  427. dptree(j)
  428.     int j;
  429. {
  430.     register int i;
  431.  
  432.     i = toffset(j);
  433.     if (i >= ITREE)
  434.         dprintf(" p%d", i);
  435.     else if (i == 0)
  436.         dprintf(" NIL");
  437.     else
  438.         dprintf("  \"%s\"", j);
  439. }
  440. #endif
  441.