ack/lang/m2/libm2/Traps.mod

97 lines
2 KiB
Modula-2
Raw Permalink Normal View History

1988-02-19 15:54:01 +00:00
(*
(c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
See the copyright notice in the ACK home directory, in the file "Copyright".
*)
1987-08-19 18:07:01 +00:00
(*$R-*)
1987-06-26 15:59:52 +00:00
IMPLEMENTATION MODULE Traps;
1988-02-19 15:54:01 +00:00
(*
Module: Facility for handling traps
Author: Ceriel J.H. Jacobs
1994-06-24 14:02:31 +00:00
Version: $Id$
1988-02-19 15:54:01 +00:00
*)
FROM EM IMPORT SIG, LINO, FILN, TRP;
FROM Unix IMPORT write;
FROM SYSTEM IMPORT ADDRESS, ADR;
FROM Arguments IMPORT
Argv;
1987-06-26 15:59:52 +00:00
PROCEDURE InstallTrapHandler(t: TrapHandler): TrapHandler;
(* Install a new trap handler, and return the previous one.
Parameter of trap handler is the trap number.
*)
BEGIN
RETURN SIG(t);
1987-06-26 15:59:52 +00:00
END InstallTrapHandler;
PROCEDURE Message(str: ARRAY OF CHAR);
(* Write message "str" on standard error, preceeded by filename and
linenumber if possible
*)
VAR p: POINTER TO CHAR;
1987-06-26 15:59:52 +00:00
l: CARDINAL;
1988-04-29 14:38:36 +00:00
lino: INTEGER;
1987-06-26 15:59:52 +00:00
buf, buf2: ARRAY [0..255] OF CHAR;
i, j: CARDINAL;
BEGIN
p := FILN();
1987-06-26 15:59:52 +00:00
IF p # NIL THEN
i := 1;
buf[0] := '"';
1987-06-26 15:59:52 +00:00
WHILE p^ # 0C DO
buf[i] := p^;
INC(i);
1987-06-26 15:59:52 +00:00
p := ADDRESS(p) + 1;
END;
buf[i] := '"';
INC(i);
IF write(2, ADR(buf), i) < 0 THEN END;
1987-06-26 15:59:52 +00:00
ELSE
l := Argv(0, buf);
IF write(2, ADR(buf), l-1) < 0 THEN END;
1987-06-26 15:59:52 +00:00
END;
lino := LINO();
1987-06-26 15:59:52 +00:00
i := 0;
IF lino # 0 THEN
i := 7;
buf[0] := ','; buf[1] := ' ';
buf[2] := 'l'; buf[3] := 'i'; buf[4] := 'n'; buf[5] := 'e';
buf[6] := ' ';
1987-06-26 15:59:52 +00:00
IF lino < 0 THEN
buf[7] := '-';
i := 8;
1987-06-26 15:59:52 +00:00
lino := - lino;
END;
j := 0;
REPEAT
buf2[j] := CHR(CARDINAL(lino) MOD 10 + ORD('0'));
lino := lino DIV 10;
INC(j);
UNTIL lino = 0;
WHILE j > 0 DO
DEC(j);
buf[i] := buf2[j];
INC(i);
END;
END;
buf[i] := ':';
buf[i+1] := ' ';
IF write(2, ADR(buf), i+2) < 0 THEN END;
1987-06-26 15:59:52 +00:00
i := 0;
WHILE (i <= HIGH(str)) AND (str[i] # 0C) DO
INC(i);
END;
IF write(2, ADR(str), i) < 0 THEN END;
1987-06-26 15:59:52 +00:00
buf[0] := 12C;
IF write(2, ADR(buf), 1) < 0 THEN END;
1987-06-26 15:59:52 +00:00
END Message;
PROCEDURE Trap(n: INTEGER);
(* cause trap number "n" to occur *)
BEGIN
TRP(n);
1987-06-26 15:59:52 +00:00
END Trap;
END Traps.