=/^G show total bytes now; document may not always work
[unix-history] / usr / src / usr.bin / pascal / pxp / case.c
CommitLineData
252367af
DF
1/*
2 * Copyright (c) 1980 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 */
6
7#ifndef lint
8static char sccsid[] = "@(#)case.c 5.1 (Berkeley) %G%";
9#endif not lint
10
c125706d
PK
11/*
12 * pxp - Pascal execution profiler
13 *
14 * Bill Joy UCB
15 * Version 1.2 January 1979
16 */
17
18#include "0.h"
19#include "tree.h"
20
21/*
22 * Case statement
450f9f2e
PK
23 * r [0] T_CASE
24 * [1] lineof "case"
25 * [2] expression
26 * [3] list of cased statements:
27 * cstat [0] T_CSTAT
28 * [1] lineof ":"
29 * [2] list of constant labels
30 * [3] statement
c125706d
PK
31 */
32caseop(r)
33 int *r;
34{
35 register *cl, *cs, i;
36 struct pxcnt scnt;
450f9f2e
PK
37# ifdef RMOTHERS
38 int *othersp; /* tree where others is, or NIL */
39 int hasothers; /* 1 if others found, else 0 */
40# endif RMOTHERS
c125706d 41
450f9f2e
PK
42# ifdef RMOTHERS
43 if (rmothers) {
44 hasothers = needscaseguard(r,&othersp);
45 if (hasothers) {
46 precaseguard(r);
47 }
48 }
49# endif RMOTHERS
c125706d
PK
50 savecnt(&scnt);
51 ppkw("case");
52 ppspac();
53 rvalue(r[2], NIL);
54 ppspac();
55 ppkw("of");
56 for (cl = r[3]; cl != NIL;) {
57 cs = cl[1];
58 if (cs == NIL)
59 continue;
60 baroff();
61 ppgoin(DECL);
62 setline(cs[1]);
63 ppnl();
64 indent();
65 ppbra(NIL);
66 cs = cs[2];
67 if (cs != NIL) {
68 i = 0;
69 for (;;) {
70 gconst(cs[1]);
71 cs = cs[2];
72 if (cs == NIL)
73 break;
74 i++;
75 if (i == 7) {
76 ppsep(",");
77 ppitem();
78 i = 0;
79 } else
80 ppsep(", ");
81 }
82 } else
83 ppid("{case label list}");
84 ppket(":");
85 cs = cl[1];
86 cs = cs[3];
87 getcnt();
88 ppgoin(STAT);
89 if (cs != NIL && cs[0] == T_BLOCK) {
90 ppnl();
91 indent();
92 baron();
93 ppstbl1(cs, STAT);
94 baroff();
95 ppstbl2();
96 baron();
97 } else {
98 baron();
99 statement(cs);
100 }
101 ppgoout(STAT);
102 ppgoout(DECL);
103 cl = cl[2];
104 if (cl == NIL)
105 break;
106 ppsep(";");
107 }
108 if (rescnt(&scnt))
109 getcnt();
110 ppnl();
111 indent();
112 ppkw("end");
450f9f2e
PK
113# ifdef RMOTHERS
114 if (rmothers) {
115 if (hasothers) {
116 postcaseguard(othersp);
117 }
118 }
119# endif RMOTHERS
c125706d 120}