r := 0;
WHILE len > i DO str[r] := ' '; INC(r); DEC(len); END;
WHILE i > 0 DO str[r] := tmp[i-1]; DEC(i); INC(r); END;
- IF r <= HIGH(str) THEN str[r] := 0C; END;
+ WHILE r <= HIGH(str) DO
+ str[r] := 0C;
+ INC(r);
+ END;
END ConvertNum;
PROCEDURE ConvertOctal(num, len: CARDINAL; VAR str: ARRAY OF CHAR);
is no mechanism to have some code executed when the program finishes.
This module is a feeble attempt at solving this problem.
*)
- PROCEDURE CallAtEnd(p: PROC);
+ PROCEDURE CallAtEnd(p: PROC): BOOLEAN;
(* Add procedure "p" to the list of procedures that must be executed when
the program finishes.
When the program finishes, these procedures are executed in the order in
which they were added to the list.
+ This procedure returns FALSE when there are too many procedures to be
+ called (the list has a fixed size).
*)
END Epilogue.
str[i] := ' ';
END;
ind1 := CARDINAL(width);
- IF (ind1+1) <= HIGH(str) THEN str[ind1+1] := 0C; END;
+ IF (ind1+1) <= HIGH(str) THEN
+ FOR ind1 := ind1+1 TO HIGH(str) DO
+ str[ind1] := 0C;
+ END;
+ END;
END;
END LongRealToString;
{ M2_NORESULT, "no RETURN from procedure function"},
{ M2_UOVFL, "cardinal overflow"},
{ M2_FORCH, "Warning: FOR-loop control variable was changed in the body"},
- { M2_ENDPROCS, "too many procedures to be called on program termination"},
{ -1, 0}
};
-#define MAXPROCS 20
-#include <m2_traps.h>
+#define MAXPROCS 16
static int callindex;
static int (*proclist[MAXPROCS])();
int (*p)();
{
if (callindex >= MAXPROCS) {
- TRP(M2_ENDPROCS);
+ return 0;
}
else {
proclist[callindex++] = p;
}
+ return 1;
}
_halt()