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

  1. /* Copyright (c) 1979 Regents of the University of California */
  2. #
  3. /*
  4.  * pxp - Pascal execution profiler
  5.  *
  6.  * Bill Joy UCB
  7.  * Version 1.2 January 1979
  8.  */
  9.  
  10. #include "0.h"
  11. #include "tree.h"
  12.  
  13. /*
  14.  * Case statement
  15.  */
  16. caseop(r)
  17.     int *r;
  18. {
  19.     register *cl, *cs, i;
  20.     struct pxcnt scnt;
  21.  
  22.     savecnt(&scnt);
  23.     ppkw("case");
  24.     ppspac();
  25.     rvalue(r[2], NIL);
  26.     ppspac();
  27.     ppkw("of");
  28.     for (cl = r[3]; cl != NIL;) {
  29.         cs = cl[1];
  30.         if (cs == NIL)
  31.             continue;
  32.         baroff();
  33.         ppgoin(DECL);
  34.         setline(cs[1]);
  35.         ppnl();
  36.         indent();
  37.         ppbra(NIL);
  38.         cs = cs[2];
  39.         if (cs != NIL) {
  40.             i = 0;
  41.             for (;;) {
  42.                 gconst(cs[1]);
  43.                 cs = cs[2];
  44.                 if (cs == NIL)
  45.                     break;
  46.                 i++;
  47.                 if (i == 7) {
  48.                     ppsep(",");
  49.                     ppitem();
  50.                     i = 0;
  51.                 } else
  52.                     ppsep(", ");
  53.             }
  54.         } else
  55.             ppid("{case label list}");
  56.         ppket(":");
  57.         cs = cl[1];
  58.         cs = cs[3];
  59.         getcnt();
  60.         ppgoin(STAT);
  61.         if (cs != NIL && cs[0] == T_BLOCK) {
  62.             ppnl();
  63.             indent();
  64.             baron();
  65.             ppstbl1(cs, STAT);
  66.             baroff();
  67.             ppstbl2();
  68.             baron();
  69.         } else {
  70.             baron();
  71.             statement(cs);
  72.         }
  73.         ppgoout(STAT);
  74.         ppgoout(DECL);
  75.         cl = cl[2];
  76.         if (cl == NIL)
  77.             break;
  78.         ppsep(";");
  79.     }
  80.     if (rescnt(&scnt))
  81.         getcnt();
  82.     ppnl();
  83.     indent();
  84.     ppkw("end");
  85. }
  86.