* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
static char sccsid
[] = "@(#)rmothers.c 5.1 (Berkeley) 6/5/85";
/* and the rest of the file */
* translate extended case statements to pascal (for tex).
* don knuth should know better. enough said.
* extended case statements have the form:
* label1,label2,...: statement1;
* which i am going to translate to:
* if expression in [ label1,label2,...] then
* label1,label2,...: statement1;
* which has the effect that the expression will be evaluated twice.
* i've looked very briefly at all cases in tex and
* they seem to be variables or pure functions.
* for simplicity i'm assuming that the others is the last labeled
* statement, and that no other labels appear with the label others.
* this appears correct from the tex82 documentation.
* given a case statement tree and the address of an others pointer,
* amputate the others statement from the case statement tree
* and hang it on the the others pointer.
* [3] list of cased statements:
* [2] list of constant labels
needscaseguard(r
, otherspp
)
for (cutpointer
= &r
[3], statlistp
= r
[3];
cutpointer
= &statlistp
[2], statlistp
= statlistp
[2]) {
lstatementp
= statlistp
[1];
lablistp
= lstatementp
[2];
/* only look at the first label */
label
[0] == T_ID
&& !strcmp(label
[1],"others")) {
*otherspp
= lstatementp
[3];
if (statlistp
[2] != NIL
) {
panic("others not last case");
if (lablistp
[2] != NIL
) {
panic("others not only case label");
for (statlistp
= r
[3]; statlistp
!= NIL
; statlistp
= statlistp
[2]) {
lstatementp
= statlistp
[1];
for (lablistp
= lstatementp
[2];lablistp
!= NIL
;lablistp
= lablistp
[2]) {
* given an others statement, hang it on the else branch of the guard.
* this will print a call to the routine ``null''.
* but it has to be checked first, or we will indirect through
* NIL to check the statement type.
if (othersp
[0] == T_BLOCK
) {