Lay-out changes and made IMPORTS more specific

This commit is contained in:
ceriel 1991-03-05 13:47:08 +00:00
parent ac83fe3815
commit 3a715f5479
16 changed files with 217 additions and 207 deletions

View file

@ -153,4 +153,3 @@ IMPLEMENTATION MODULE ArraySort;
END threewayexchange; END threewayexchange;
END ArraySort. END ArraySort.

View file

@ -14,7 +14,7 @@ IMPLEMENTATION MODULE CSP;
FROM random IMPORT Uniform; FROM random IMPORT Uniform;
FROM SYSTEM IMPORT BYTE, ADDRESS, NEWPROCESS, TRANSFER; FROM SYSTEM IMPORT BYTE, ADDRESS, NEWPROCESS, TRANSFER;
FROM Storage IMPORT Allocate, Deallocate; FROM Storage IMPORT Allocate, Deallocate;
IMPORT Traps; FROM Traps IMPORT Message;
CONST WorkSpaceSize = 1000; CONST WorkSpaceSize = 1000;
@ -212,7 +212,7 @@ IMPLEMENTATION MODULE CSP;
BEGIN BEGIN
WITH ch^ DO WITH ch^ DO
IF owner # NIL THEN IF owner # NIL THEN
Traps.Message("Channel already has an owner"); Message("Channel already has an owner");
HALT HALT
END; END;
owner := cp owner := cp
@ -251,7 +251,7 @@ IMPLEMENTATION MODULE CSP;
BEGIN BEGIN
WITH ch^ DO WITH ch^ DO
IF cp # owner THEN IF cp # owner THEN
Traps.Message("Only owner of channel can receive from it"); Message("Only owner of channel can receive from it");
HALT HALT
END; END;
IF Sending(ch) THEN IF Sending(ch) THEN

View file

@ -12,8 +12,10 @@ IMPLEMENTATION MODULE InOut ;
*) *)
IMPORT Streams; IMPORT Streams;
IMPORT Conversions; FROM Conversions IMPORT
IMPORT Traps; ConvertCardinal, ConvertInteger,
ConvertOctal, ConvertHex;
FROM Traps IMPORT Message;
CONST TAB = 11C; CONST TAB = 11C;
@ -190,7 +192,7 @@ IMPLEMENTATION MODULE InOut ;
IF (int > SAFELIMITDIV10) OR IF (int > SAFELIMITDIV10) OR
( (int = SAFELIMITDIV10) AND ( (int = SAFELIMITDIV10) AND
(chvalue > safedigit)) THEN (chvalue > safedigit)) THEN
Traps.Message("integer too large"); Message("integer too large");
HALT; HALT;
ELSE ELSE
int := 10*int + VAL(INTEGER, chvalue); int := 10*int + VAL(INTEGER, chvalue);
@ -203,7 +205,7 @@ IMPLEMENTATION MODULE InOut ;
integ := int integ := int
END; END;
IF buf[index] > " " THEN IF buf[index] > " " THEN
Traps.Message("illegal integer"); Message("illegal integer");
HALT; HALT;
END; END;
Done := TRUE; Done := TRUE;
@ -235,7 +237,7 @@ IMPLEMENTATION MODULE InOut ;
IF (int > SAFELIMITDIV10) OR IF (int > SAFELIMITDIV10) OR
( (int = SAFELIMITDIV10) AND ( (int = SAFELIMITDIV10) AND
(chvalue > safedigit)) THEN (chvalue > safedigit)) THEN
Traps.Message("cardinal too large"); Message("cardinal too large");
HALT; HALT;
ELSE ELSE
int := 10*int + chvalue; int := 10*int + chvalue;
@ -243,7 +245,7 @@ IMPLEMENTATION MODULE InOut ;
END; END;
END; END;
IF buf[index] > " " THEN IF buf[index] > " " THEN
Traps.Message("illegal cardinal"); Message("illegal cardinal");
HALT; HALT;
END; END;
card := int; card := int;
@ -318,7 +320,7 @@ IMPLEMENTATION MODULE InOut ;
VAR VAR
buf : numbuf; buf : numbuf;
BEGIN BEGIN
Conversions.ConvertCardinal(card, width, buf); ConvertCardinal(card, width, buf);
WriteString(buf); WriteString(buf);
END WriteCard; END WriteCard;
@ -326,7 +328,7 @@ IMPLEMENTATION MODULE InOut ;
VAR VAR
buf : numbuf; buf : numbuf;
BEGIN BEGIN
Conversions.ConvertInteger(int, width, buf); ConvertInteger(int, width, buf);
WriteString(buf); WriteString(buf);
END WriteInt; END WriteInt;
@ -334,7 +336,7 @@ IMPLEMENTATION MODULE InOut ;
VAR VAR
buf : numbuf; buf : numbuf;
BEGIN BEGIN
Conversions.ConvertHex(card, width, buf); ConvertHex(card, width, buf);
WriteString(buf); WriteString(buf);
END WriteHex; END WriteHex;
@ -347,7 +349,7 @@ IMPLEMENTATION MODULE InOut ;
VAR VAR
buf : numbuf; buf : numbuf;
BEGIN BEGIN
Conversions.ConvertOctal(card, width, buf); ConvertOctal(card, width, buf);
WriteString(buf); WriteString(buf);
END WriteOct; END WriteOct;

View file

@ -13,39 +13,39 @@ IMPLEMENTATION MODULE MathLib0;
IMPORT Mathlib; IMPORT Mathlib;
PROCEDURE cos(arg: REAL): REAL; PROCEDURE cos(arg: REAL): REAL;
BEGIN BEGIN
RETURN Mathlib.cos(arg); RETURN Mathlib.cos(arg);
END cos; END cos;
PROCEDURE sin(arg: REAL): REAL; PROCEDURE sin(arg: REAL): REAL;
BEGIN BEGIN
RETURN Mathlib.sin(arg); RETURN Mathlib.sin(arg);
END sin; END sin;
PROCEDURE arctan(arg: REAL): REAL; PROCEDURE arctan(arg: REAL): REAL;
BEGIN BEGIN
RETURN Mathlib.arctan(arg); RETURN Mathlib.arctan(arg);
END arctan; END arctan;
PROCEDURE sqrt(arg: REAL): REAL; PROCEDURE sqrt(arg: REAL): REAL;
BEGIN BEGIN
RETURN Mathlib.sqrt(arg); RETURN Mathlib.sqrt(arg);
END sqrt; END sqrt;
PROCEDURE ln(arg: REAL): REAL; PROCEDURE ln(arg: REAL): REAL;
BEGIN BEGIN
RETURN Mathlib.ln(arg); RETURN Mathlib.ln(arg);
END ln; END ln;
PROCEDURE exp(arg: REAL): REAL; PROCEDURE exp(arg: REAL): REAL;
BEGIN BEGIN
RETURN Mathlib.exp(arg); RETURN Mathlib.exp(arg);
END exp; END exp;
PROCEDURE entier(x: REAL): INTEGER; PROCEDURE entier(x: REAL): INTEGER;
VAR i: INTEGER; VAR i: INTEGER;
BEGIN BEGIN
IF x < 0.0 THEN IF x < 0.0 THEN
i := TRUNC(-x); i := TRUNC(-x);
IF FLOAT(i) = -x THEN IF FLOAT(i) = -x THEN
@ -55,15 +55,15 @@ BEGIN
END; END;
END; END;
RETURN TRUNC(x); RETURN TRUNC(x);
END entier; END entier;
PROCEDURE real(x: INTEGER): REAL; PROCEDURE real(x: INTEGER): REAL;
BEGIN BEGIN
IF x < 0 THEN IF x < 0 THEN
RETURN - FLOAT(-x); RETURN - FLOAT(-x);
END; END;
RETURN FLOAT(x); RETURN FLOAT(x);
END real; END real;
BEGIN BEGIN
END MathLib0. END MathLib0.

View file

@ -11,9 +11,11 @@ IMPLEMENTATION MODULE PascalIO;
Version: $Header$ Version: $Header$
*) *)
IMPORT Conversions; FROM Conversions IMPORT
IMPORT Traps; ConvertInteger, ConvertCardinal;
IMPORT RealConversions; FROM RealConversions IMPORT
LongRealToString, StringToLongReal;
FROM Traps IMPORT Message;
FROM Streams IMPORT Stream, StreamKind, StreamMode, StreamResult, FROM Streams IMPORT Stream, StreamKind, StreamMode, StreamResult,
InputStream, OutputStream, OpenStream, CloseStream, InputStream, OutputStream, OpenStream, CloseStream,
EndOfStream, Read, Write, StreamBuffering; EndOfStream, Read, Write, StreamBuffering;
@ -46,7 +48,7 @@ IMPLEMENTATION MODULE PascalIO;
WITH InputText^ DO WITH InputText^ DO
OpenStream(stream, Filename, text, reading, result); OpenStream(stream, Filename, text, reading, result);
IF result # succeeded THEN IF result # succeeded THEN
Traps.Message("could not open input file"); Message("could not open input file");
HALT; HALT;
END; END;
type := Preading; type := Preading;
@ -62,7 +64,7 @@ IMPLEMENTATION MODULE PascalIO;
WITH OutputText^ DO WITH OutputText^ DO
OpenStream(stream, Filename, text, writing, result); OpenStream(stream, Filename, text, writing, result);
IF result # succeeded THEN IF result # succeeded THEN
Traps.Message("could not open output file"); Message("could not open output file");
HALT; HALT;
END; END;
type := Pwriting; type := Pwriting;
@ -107,9 +109,9 @@ IMPLEMENTATION MODULE PascalIO;
PROCEDURE Error(tp: btype); PROCEDURE Error(tp: btype);
BEGIN BEGIN
IF tp = Preading THEN IF tp = Preading THEN
Traps.Message("input text expected"); Message("input text expected");
ELSE ELSE
Traps.Message("output text expected"); Message("output text expected");
END; END;
HALT; HALT;
END Error; END Error;
@ -118,7 +120,7 @@ IMPLEMENTATION MODULE PascalIO;
BEGIN BEGIN
ch := NextChar(InputText); ch := NextChar(InputText);
IF InputText^.eof THEN IF InputText^.eof THEN
Traps.Message("unexpected EOF"); Message("unexpected EOF");
HALT; HALT;
END; END;
InputText^.done := FALSE; InputText^.done := FALSE;
@ -218,7 +220,7 @@ IMPLEMENTATION MODULE PascalIO;
IF (int < -SAFELIMITDIV10) OR IF (int < -SAFELIMITDIV10) OR
( (int = -SAFELIMITDIV10) AND ( (int = -SAFELIMITDIV10) AND
(chvalue > safedigit)) THEN (chvalue > safedigit)) THEN
Traps.Message("integer too large"); Message("integer too large");
HALT; HALT;
ELSE ELSE
int := 10*int - VAL(INTEGER, chvalue); int := 10*int - VAL(INTEGER, chvalue);
@ -230,7 +232,7 @@ IMPLEMENTATION MODULE PascalIO;
int := -int int := -int
END; END;
ELSE ELSE
Traps.Message("integer expected"); Message("integer expected");
HALT; HALT;
END; END;
END ReadInteger; END ReadInteger;
@ -257,7 +259,7 @@ IMPLEMENTATION MODULE PascalIO;
IF (card > SAFELIMITDIV10) OR IF (card > SAFELIMITDIV10) OR
( (card = SAFELIMITDIV10) AND ( (card = SAFELIMITDIV10) AND
(chvalue > safedigit)) THEN (chvalue > safedigit)) THEN
Traps.Message("cardinal too large"); Message("cardinal too large");
HALT; HALT;
ELSE ELSE
card := 10*card + chvalue; card := 10*card + chvalue;
@ -266,7 +268,7 @@ IMPLEMENTATION MODULE PascalIO;
END; END;
END; END;
ELSE ELSE
Traps.Message("cardinal expected"); Message("cardinal expected");
HALT; HALT;
END; END;
END ReadCardinal; END ReadCardinal;
@ -335,10 +337,10 @@ IMPLEMENTATION MODULE PascalIO;
END; END;
IF ok THEN IF ok THEN
buf[index] := 0C; buf[index] := 0C;
RealConversions.StringToLongReal(buf, real, ok); StringToLongReal(buf, real, ok);
END; END;
IF NOT ok THEN IF NOT ok THEN
Traps.Message("Illegal real"); Message("Illegal real");
HALT; HALT;
END; END;
END ReadLongReal; END ReadLongReal;
@ -347,7 +349,7 @@ IMPLEMENTATION MODULE PascalIO;
VAR VAR
buf : numbuf; buf : numbuf;
BEGIN BEGIN
Conversions.ConvertCardinal(card, 1, buf); ConvertCardinal(card, 1, buf);
WriteString(OutputText, buf, width); WriteString(OutputText, buf, width);
END WriteCardinal; END WriteCardinal;
@ -355,7 +357,7 @@ IMPLEMENTATION MODULE PascalIO;
VAR VAR
buf : numbuf; buf : numbuf;
BEGIN BEGIN
Conversions.ConvertInteger(int, 1, buf); ConvertInteger(int, 1, buf);
WriteString(OutputText, buf, width); WriteString(OutputText, buf, width);
END WriteInteger; END WriteInteger;
@ -383,7 +385,7 @@ IMPLEMENTATION MODULE PascalIO;
width := SIZE(buf); width := SIZE(buf);
END; END;
IF nfrac > 0 THEN IF nfrac > 0 THEN
RealConversions.LongRealToString(real, width, nfrac, buf, ok); LongRealToString(real, width, nfrac, buf, ok);
ELSE ELSE
IF width < 9 THEN width := 9; END; IF width < 9 THEN width := 9; END;
IF real < 0.0D THEN IF real < 0.0D THEN
@ -391,7 +393,7 @@ IMPLEMENTATION MODULE PascalIO;
ELSE ELSE
digits := 6 - INTEGER(width); digits := 6 - INTEGER(width);
END; END;
RealConversions.LongRealToString(real, width, digits, buf, ok); LongRealToString(real, width, digits, buf, ok);
END; END;
WriteString(OutputText, buf, 0); WriteString(OutputText, buf, 0);
END WriteLongReal; END WriteLongReal;

View file

@ -7,9 +7,7 @@ IMPLEMENTATION MODULE Processes [1];
*) *)
FROM SYSTEM IMPORT ADDRESS, TSIZE, NEWPROCESS, TRANSFER; FROM SYSTEM IMPORT ADDRESS, TSIZE, NEWPROCESS, TRANSFER;
FROM Storage IMPORT Allocate; FROM Storage IMPORT Allocate;
FROM Traps IMPORT Message; FROM Traps IMPORT Message;
TYPE SIGNAL = POINTER TO ProcessDescriptor; TYPE SIGNAL = POINTER TO ProcessDescriptor;

View file

@ -11,10 +11,11 @@ IMPLEMENTATION MODULE RealInOut;
Version: $Header$ Version: $Header$
*) *)
IMPORT InOut; FROM InOut IMPORT ReadString, WriteString, WriteOct;
IMPORT RealConversions; FROM Traps IMPORT Message;
IMPORT Traps;
FROM SYSTEM IMPORT WORD; FROM SYSTEM IMPORT WORD;
FROM RealConversions IMPORT
LongRealToString, StringToLongReal;
CONST MAXNDIG = 32; CONST MAXNDIG = 32;
MAXWIDTH = MAXNDIG+7; MAXWIDTH = MAXNDIG+7;
@ -32,8 +33,8 @@ IMPLEMENTATION MODULE RealInOut;
BEGIN BEGIN
IF ndigits > MAXWIDTH THEN ndigits := MAXWIDTH; END; IF ndigits > MAXWIDTH THEN ndigits := MAXWIDTH; END;
IF ndigits < 10 THEN ndigits := 10; END; IF ndigits < 10 THEN ndigits := 10; END;
RealConversions.LongRealToString(arg, ndigits, -INTEGER(ndigits - 7), buf, ok); LongRealToString(arg, ndigits, -INTEGER(ndigits - 7), buf, ok);
InOut.WriteString(buf); WriteString(buf);
END WriteLongReal; END WriteLongReal;
PROCEDURE WriteFixPt(arg: REAL; n, k: CARDINAL); PROCEDURE WriteFixPt(arg: REAL; n, k: CARDINAL);
@ -47,8 +48,8 @@ IMPLEMENTATION MODULE RealInOut;
BEGIN BEGIN
IF n > MAXWIDTH THEN n := MAXWIDTH END; IF n > MAXWIDTH THEN n := MAXWIDTH END;
RealConversions.LongRealToString(arg, n, k, buf, ok); LongRealToString(arg, n, k, buf, ok);
InOut.WriteString(buf); WriteString(buf);
END WriteLongFixPt; END WriteLongFixPt;
PROCEDURE ReadReal(VAR x: REAL); PROCEDURE ReadReal(VAR x: REAL);
@ -63,10 +64,10 @@ IMPLEMENTATION MODULE RealInOut;
ok: BOOLEAN; ok: BOOLEAN;
BEGIN BEGIN
InOut.ReadString(Buf); ReadString(Buf);
RealConversions.StringToLongReal(Buf, x, ok); StringToLongReal(Buf, x, ok);
IF NOT ok THEN IF NOT ok THEN
Traps.Message("real expected"); Message("real expected");
HALT; HALT;
END; END;
Done := TRUE; Done := TRUE;
@ -76,8 +77,8 @@ IMPLEMENTATION MODULE RealInOut;
VAR i: CARDINAL; VAR i: CARDINAL;
BEGIN BEGIN
FOR i := 0 TO HIGH(x) DO FOR i := 0 TO HIGH(x) DO
InOut.WriteOct(CARDINAL(x[i]), 0); WriteOct(CARDINAL(x[i]), 0);
InOut.WriteString(" "); WriteString(" ");
END; END;
END wroct; END wroct;

View file

@ -15,7 +15,10 @@ IMPLEMENTATION MODULE Streams;
*) *)
FROM SYSTEM IMPORT BYTE, ADR; FROM SYSTEM IMPORT BYTE, ADR;
IMPORT StripUnix, Storage, Epilogue; FROM Epilogue IMPORT CallAtEnd;
FROM Storage IMPORT Allocate, Available;
FROM StripUnix IMPORT
open, close, lseek, read, write, creat, ioctl;
CONST BUFSIZ = 1024; (* tunable *) CONST BUFSIZ = 1024; (* tunable *)
TYPE IOB = RECORD TYPE IOB = RECORD
@ -41,10 +44,10 @@ IMPLEMENTATION MODULE Streams;
stream := stream^.next; stream := stream^.next;
END; END;
IF stream = NIL THEN IF stream = NIL THEN
IF NOT Storage.Available(SIZE(IOB)) THEN IF NOT Available(SIZE(IOB)) THEN
RETURN; RETURN;
END; END;
Storage.Allocate(stream,SIZE(IOB)); Allocate(stream,SIZE(IOB));
stream^.next := head; stream^.next := head;
head := stream; head := stream;
END; END;
@ -79,17 +82,17 @@ IMPLEMENTATION MODULE Streams;
buf[HIGH(filename)+2] := BYTE(0C); buf[HIGH(filename)+2] := BYTE(0C);
END; END;
IF (mode = reading) THEN IF (mode = reading) THEN
fd := StripUnix.open(ADR(stream^.buf), 0); fd := open(ADR(stream^.buf), 0);
ELSE ELSE
fd := -1; fd := -1;
IF (mode = appending) THEN IF (mode = appending) THEN
fd := StripUnix.open(ADR(stream^.buf), 1); fd := open(ADR(stream^.buf), 1);
IF fd >= 0 THEN IF fd >= 0 THEN
IF (StripUnix.lseek(fd, 0D , 2) < 0D) THEN ; END; IF (lseek(fd, 0D , 2) < 0D) THEN ; END;
END; END;
END; END;
IF fd < 0 THEN IF fd < 0 THEN
fd := StripUnix.creat(ADR(stream^.buf), 666B); fd := creat(ADR(stream^.buf), 666B);
END; END;
END; END;
IF fd < 0 THEN IF fd < 0 THEN
@ -150,7 +153,7 @@ IMPLEMENTATION MODULE Streams;
IF (cnt > 0) THEN IF (cnt > 0) THEN
cnt1 := cnt; cnt1 := cnt;
cnt := 0; cnt := 0;
IF StripUnix.write(fildes, ADR(buf), cnt1) < 0 THEN END; IF write(fildes, ADR(buf), cnt1) < 0 THEN END;
END; END;
END; END;
END FlushStream; END FlushStream;
@ -162,7 +165,7 @@ IMPLEMENTATION MODULE Streams;
IF stream^.mode # reading THEN IF stream^.mode # reading THEN
FlushStream(stream, result); FlushStream(stream, result);
END; END;
IF StripUnix.close(stream^.fildes) < 0 THEN ; END; IF close(stream^.fildes) < 0 THEN ; END;
freestruct(stream); freestruct(stream);
ELSE ELSE
result := nostream; result := nostream;
@ -209,7 +212,7 @@ IMPLEMENTATION MODULE Streams;
IF stream = InputStream THEN IF stream = InputStream THEN
FlushLineBuffers(); FlushLineBuffers();
END; END;
maxcnt := StripUnix.read(fildes, ADR(buf), bufferedcnt); maxcnt := read(fildes, ADR(buf), bufferedcnt);
cnt := 1; cnt := 1;
IF maxcnt <= 0 THEN IF maxcnt <= 0 THEN
eof := TRUE; eof := TRUE;
@ -332,7 +335,7 @@ IMPLEMENTATION MODULE Streams;
RETURN; RETURN;
END; END;
IF (s^.mode # reading) THEN FlushStream(s, result); END; IF (s^.mode # reading) THEN FlushStream(s, result); END;
position := StripUnix.lseek(s^.fildes, 0D, 1); position := lseek(s^.fildes, 0D, 1);
IF position < 0D THEN IF position < 0D THEN
result := illegaloperation; result := illegaloperation;
RETURN; RETURN;
@ -357,7 +360,7 @@ IMPLEMENTATION MODULE Streams;
s^.eof := FALSE; s^.eof := FALSE;
END; END;
IF s^.mode = appending THEN IF s^.mode = appending THEN
currpos := StripUnix.lseek(s^.fildes, 0D, 1); currpos := lseek(s^.fildes, 0D, 1);
IF currpos < 0D THEN IF currpos < 0D THEN
result := illegaloperation; result := illegaloperation;
RETURN; RETURN;
@ -367,7 +370,7 @@ IMPLEMENTATION MODULE Streams;
result := illegaloperation; result := illegaloperation;
RETURN; RETURN;
END; END;
currpos := StripUnix.lseek(s^.fildes, position, 0); currpos := lseek(s^.fildes, position, 0);
IF currpos < 0D THEN IF currpos < 0D THEN
result := illegaloperation; result := illegaloperation;
RETURN; RETURN;
@ -383,12 +386,12 @@ IMPLEMENTATION MODULE Streams;
RETURN FALSE; RETURN FALSE;
END; END;
#ifdef __USG #ifdef __USG
RETURN StripUnix.ioctl(stream^.fildes, INTEGER(ORD('T') * 256 + 1), ADR(buf)) >= 0; RETURN ioctl(stream^.fildes, INTEGER(ORD('T') * 256 + 1), ADR(buf)) >= 0;
#else #else
#ifdef __BSD4_2 #ifdef __BSD4_2
RETURN StripUnix.ioctl(stream^.fildes, INTEGER(ORD('t') * 256 + 8 + 6*65536 + 40000000H), ADR(buf)) >= 0; RETURN ioctl(stream^.fildes, INTEGER(ORD('t') * 256 + 8 + 6*65536 + 40000000H), ADR(buf)) >= 0;
#else #else
RETURN StripUnix.ioctl(stream^.fildes, INTEGER(ORD('t') * 256 + 8), ADR(buf)) >= 0; RETURN ioctl(stream^.fildes, INTEGER(ORD('t') * 256 + 8), ADR(buf)) >= 0;
#endif #endif
#endif #endif
END isatty; END isatty;
@ -440,7 +443,7 @@ IMPLEMENTATION MODULE Streams;
END; END;
END; END;
head := InputStream; head := InputStream;
IF Epilogue.CallAtEnd(EndIt) THEN ; END; IF CallAtEnd(EndIt) THEN ; END;
END InitStreams; END InitStreams;
BEGIN BEGIN

View file

@ -11,12 +11,12 @@ IMPLEMENTATION MODULE Strings;
Version: $Header$ Version: $Header$
*) *)
PROCEDURE Assign(source: ARRAY OF CHAR; VAR dest: ARRAY OF CHAR); PROCEDURE Assign(source: ARRAY OF CHAR; VAR dest: ARRAY OF CHAR);
(* Assign string source to dest (* Assign string source to dest
*) *)
VAR i: CARDINAL; VAR i: CARDINAL;
max: CARDINAL; max: CARDINAL;
BEGIN BEGIN
max := HIGH(source); max := HIGH(source);
IF HIGH(dest) < max THEN max := HIGH(dest); END; IF HIGH(dest) < max THEN max := HIGH(dest); END;
i := 0; i := 0;
@ -25,15 +25,15 @@ BEGIN
INC(i); INC(i);
END; END;
IF i < HIGH(dest) THEN dest[i] := 0C; END; IF i < HIGH(dest) THEN dest[i] := 0C; END;
END Assign; END Assign;
PROCEDURE Insert(substr: ARRAY OF CHAR; VAR str: ARRAY OF CHAR; inx: CARDINAL); PROCEDURE Insert(substr: ARRAY OF CHAR; VAR str: ARRAY OF CHAR; inx: CARDINAL);
(* Insert the string substr into str, starting at str[inx]. (* Insert the string substr into str, starting at str[inx].
If inx is equal to or greater than Length(str) then substr is appended If inx is equal to or greater than Length(str) then substr is appended
to the end of str. to the end of str.
*) *)
VAR sublen, length, i: CARDINAL; VAR sublen, length, i: CARDINAL;
BEGIN BEGIN
sublen := Length(substr); sublen := Length(substr);
IF sublen = 0 THEN RETURN; END; IF sublen = 0 THEN RETURN; END;
length := Length(str); length := Length(str);
@ -54,16 +54,16 @@ BEGIN
IF length + sublen <= HIGH(str) THEN IF length + sublen <= HIGH(str) THEN
str[length + sublen] := 0C; str[length + sublen] := 0C;
END; END;
END Insert; END Insert;
PROCEDURE Delete(VAR str: ARRAY OF CHAR; inx, len: CARDINAL); PROCEDURE Delete(VAR str: ARRAY OF CHAR; inx, len: CARDINAL);
(* Delete len characters from str, starting at str[inx]. (* Delete len characters from str, starting at str[inx].
If inx >= Length(str) then nothing happens. If inx >= Length(str) then nothing happens.
If there are not len characters to delete, characters to the end of the If there are not len characters to delete, characters to the end of the
string are deleted. string are deleted.
*) *)
VAR length: CARDINAL; VAR length: CARDINAL;
BEGIN BEGIN
IF len = 0 THEN RETURN; END; IF len = 0 THEN RETURN; END;
length := Length(str); length := Length(str);
IF inx >= length THEN RETURN; END; IF inx >= length THEN RETURN; END;
@ -72,14 +72,14 @@ BEGIN
INC(inx); INC(inx);
END; END;
str[inx] := 0C; str[inx] := 0C;
END Delete; END Delete;
PROCEDURE Pos(substr, str: ARRAY OF CHAR): CARDINAL; PROCEDURE Pos(substr, str: ARRAY OF CHAR): CARDINAL;
(* Return the index into str of the first occurrence of substr. (* Return the index into str of the first occurrence of substr.
Pos returns a value greater than HIGH(str) of no occurrence is found. Pos returns a value greater than HIGH(str) of no occurrence is found.
*) *)
VAR i, j, max, subl: CARDINAL; VAR i, j, max, subl: CARDINAL;
BEGIN BEGIN
max := Length(str); max := Length(str);
subl := Length(substr); subl := Length(substr);
IF subl > max THEN RETURN HIGH(str) + 1; END; IF subl > max THEN RETURN HIGH(str) + 1; END;
@ -93,15 +93,15 @@ BEGIN
IF j = subl THEN RETURN i; END; IF j = subl THEN RETURN i; END;
END; END;
RETURN HIGH(str) + 1; RETURN HIGH(str) + 1;
END Pos; END Pos;
PROCEDURE Copy(str: ARRAY OF CHAR; PROCEDURE Copy(str: ARRAY OF CHAR;
inx, len: CARDINAL; inx, len: CARDINAL;
VAR result: ARRAY OF CHAR); VAR result: ARRAY OF CHAR);
(* Copy at most len characters from str into result, starting at str[inx]. (* Copy at most len characters from str into result, starting at str[inx].
*) *)
VAR i: CARDINAL; VAR i: CARDINAL;
BEGIN BEGIN
IF Length(str) <= inx THEN RETURN END; IF Length(str) <= inx THEN RETURN END;
i := 0; i := 0;
LOOP LOOP
@ -112,13 +112,13 @@ BEGIN
INC(i); INC(inx); DEC(len); INC(i); INC(inx); DEC(len);
END; END;
IF i <= HIGH(result) THEN result[i] := 0C; END; IF i <= HIGH(result) THEN result[i] := 0C; END;
END Copy; END Copy;
PROCEDURE Concat(s1, s2: ARRAY OF CHAR; VAR result: ARRAY OF CHAR); PROCEDURE Concat(s1, s2: ARRAY OF CHAR; VAR result: ARRAY OF CHAR);
(* Concatenate two strings. (* Concatenate two strings.
*) *)
VAR i, j: CARDINAL; VAR i, j: CARDINAL;
BEGIN BEGIN
i := 0; i := 0;
WHILE (i <= HIGH(s1)) AND (s1[i] # 0C) DO WHILE (i <= HIGH(s1)) AND (s1[i] # 0C) DO
IF i > HIGH(result) THEN RETURN END; IF i > HIGH(result) THEN RETURN END;
@ -133,27 +133,27 @@ BEGIN
INC(j); INC(j);
END; END;
IF i <= HIGH(result) THEN result[i] := 0C; END; IF i <= HIGH(result) THEN result[i] := 0C; END;
END Concat; END Concat;
PROCEDURE Length(str: ARRAY OF CHAR): CARDINAL; PROCEDURE Length(str: ARRAY OF CHAR): CARDINAL;
(* Return number of characters in str. (* Return number of characters in str.
*) *)
VAR i: CARDINAL; VAR i: CARDINAL;
BEGIN BEGIN
i := 0; i := 0;
WHILE (i <= HIGH(str)) DO WHILE (i <= HIGH(str)) DO
IF str[i] = 0C THEN RETURN i; END; IF str[i] = 0C THEN RETURN i; END;
INC(i); INC(i);
END; END;
RETURN i; RETURN i;
END Length; END Length;
PROCEDURE CompareStr(s1, s2: ARRAY OF CHAR): INTEGER; PROCEDURE CompareStr(s1, s2: ARRAY OF CHAR): INTEGER;
(* Compare two strings, return -1 if s1 < s2, 0 if s1 = s2, and 1 if s1 > s2. (* Compare two strings, return -1 if s1 < s2, 0 if s1 = s2, and 1 if s1 > s2.
*) *)
VAR i: CARDINAL; VAR i: CARDINAL;
max: CARDINAL; max: CARDINAL;
BEGIN BEGIN
max := HIGH(s1); max := HIGH(s1);
IF HIGH(s2) < max THEN max := HIGH(s2); END; IF HIGH(s2) < max THEN max := HIGH(s2); END;
i := 0; i := 0;
@ -166,6 +166,6 @@ BEGIN
IF (i <= HIGH(s1)) AND (s1[i] # 0C) THEN RETURN 1; END; IF (i <= HIGH(s1)) AND (s1[i] # 0C) THEN RETURN 1; END;
IF (i <= HIGH(s2)) AND (s2[i] # 0C) THEN RETURN -1; END; IF (i <= HIGH(s2)) AND (s2[i] # 0C) THEN RETURN -1; END;
RETURN 0; RETURN 0;
END CompareStr; END CompareStr;
END Strings. END Strings.

View file

@ -15,7 +15,8 @@ IMPLEMENTATION MODULE Termcap;
IMPORT XXTermcap; IMPORT XXTermcap;
FROM SYSTEM IMPORT ADR, ADDRESS; FROM SYSTEM IMPORT ADR, ADDRESS;
FROM Unix IMPORT gtty; FROM Unix IMPORT gtty;
FROM Arguments IMPORT GetEnv; FROM Arguments IMPORT
GetEnv;
TYPE STR = ARRAY[1..32] OF CHAR; TYPE STR = ARRAY[1..32] OF CHAR;
STRCAP = POINTER TO STR; STRCAP = POINTER TO STR;

View file

@ -13,9 +13,12 @@ IMPLEMENTATION MODULE Terminal;
Implementation for Unix. Implementation for Unix.
*) *)
IMPORT Unix;
FROM SYSTEM IMPORT ADR; FROM SYSTEM IMPORT ADR;
#ifdef __USG
FROM Unix IMPORT read, write, open, fcntl;
#else
FROM Unix IMPORT read, write, open, ioctl;
#endif
VAR fildes: INTEGER; VAR fildes: INTEGER;
unreadch: CHAR; unreadch: CHAR;
unread: BOOLEAN; unread: BOOLEAN;
@ -27,7 +30,7 @@ IMPLEMENTATION MODULE Terminal;
ch := unreadch; ch := unreadch;
unread := FALSE unread := FALSE
ELSE ELSE
IF Unix.read(fildes, ADR(ch), 1) < 0 THEN IF read(fildes, ADR(ch), 1) < 0 THEN
; ;
END; END;
END; END;
@ -42,25 +45,25 @@ IMPLEMENTATION MODULE Terminal;
unread := FALSE unread := FALSE
ELSE ELSE
#ifdef __USG #ifdef __USG
l := Unix.fcntl(fildes, (*FGETFL*) 3, 0); l := fcntl(fildes, (*FGETFL*) 3, 0);
IF Unix.fcntl(fildes, IF fcntl(fildes,
(* FSETFL *) 4, (* FSETFL *) 4,
l + (*ONDELAY*) 2) < 0 THEN l + (*ONDELAY*) 2) < 0 THEN
; ;
END; END;
IF Unix.read(fildes, ADR(ch), 1) = 0 THEN IF read(fildes, ADR(ch), 1) = 0 THEN
ch := 0C; ch := 0C;
ELSE ELSE
unreadch := ch; unreadch := ch;
END; END;
IF Unix.fcntl(fildes, (*FSETFL*)4, l) < 0 THEN IF fcntl(fildes, (*FSETFL*)4, l) < 0 THEN
; ;
END; END;
#else #else
#ifdef __BSD4_2 #ifdef __BSD4_2
IF Unix.ioctl(fildes, INTEGER(ORD('f')*256+127+4*65536+40000000H), ADR(l)) < 0 THEN IF ioctl(fildes, INTEGER(ORD('f')*256+127+4*65536+40000000H), ADR(l)) < 0 THEN
#else #else
IF Unix.ioctl(fildes, INTEGER(ORD('f')*256+127), ADR(l)) < 0 THEN IF ioctl(fildes, INTEGER(ORD('f')*256+127), ADR(l)) < 0 THEN
#endif #endif
; ;
END; END;
@ -68,7 +71,7 @@ IMPLEMENTATION MODULE Terminal;
IF l = 0 THEN IF l = 0 THEN
ch := 0C; ch := 0C;
ELSE ELSE
IF Unix.read(fildes, ADR(ch), 1) < 0 THEN IF read(fildes, ADR(ch), 1) < 0 THEN
; ;
END; END;
unreadch := ch; unreadch := ch;
@ -84,7 +87,7 @@ IMPLEMENTATION MODULE Terminal;
PROCEDURE Write(ch: CHAR); PROCEDURE Write(ch: CHAR);
BEGIN BEGIN
IF Unix.write(fildes, ADR(ch), 1) < 0 THEN IF write(fildes, ADR(ch), 1) < 0 THEN
; ;
END; END;
END Write; END Write;
@ -106,6 +109,6 @@ IMPLEMENTATION MODULE Terminal;
BEGIN BEGIN
tty := "/dev/tty"; tty := "/dev/tty";
fildes := Unix.open(ADR(tty), 2); fildes := open(ADR(tty), 2);
unread := FALSE; unread := FALSE;
END Terminal. END Terminal.

View file

@ -11,17 +11,18 @@ IMPLEMENTATION MODULE Traps;
Version: $Header$ Version: $Header$
*) *)
IMPORT EM; FROM EM IMPORT SIG, LINO, FILN, TRP;
IMPORT Unix; FROM Unix IMPORT write;
FROM SYSTEM IMPORT ADDRESS, ADR; FROM SYSTEM IMPORT ADDRESS, ADR;
FROM Arguments IMPORT Argv; FROM Arguments IMPORT
Argv;
PROCEDURE InstallTrapHandler(t: TrapHandler): TrapHandler; PROCEDURE InstallTrapHandler(t: TrapHandler): TrapHandler;
(* Install a new trap handler, and return the previous one. (* Install a new trap handler, and return the previous one.
Parameter of trap handler is the trap number. Parameter of trap handler is the trap number.
*) *)
BEGIN BEGIN
RETURN EM.SIG(t); RETURN SIG(t);
END InstallTrapHandler; END InstallTrapHandler;
PROCEDURE Message(str: ARRAY OF CHAR); PROCEDURE Message(str: ARRAY OF CHAR);
@ -34,7 +35,7 @@ IMPLEMENTATION MODULE Traps;
buf, buf2: ARRAY [0..255] OF CHAR; buf, buf2: ARRAY [0..255] OF CHAR;
i, j: CARDINAL; i, j: CARDINAL;
BEGIN BEGIN
p := EM.FILN(); p := FILN();
IF p # NIL THEN IF p # NIL THEN
i := 1; i := 1;
buf[0] := '"'; buf[0] := '"';
@ -45,12 +46,12 @@ IMPLEMENTATION MODULE Traps;
END; END;
buf[i] := '"'; buf[i] := '"';
INC(i); INC(i);
IF Unix.write(2, ADR(buf), i) < 0 THEN END; IF write(2, ADR(buf), i) < 0 THEN END;
ELSE ELSE
l := Argv(0, buf); l := Argv(0, buf);
IF Unix.write(2, ADR(buf), l-1) < 0 THEN END; IF write(2, ADR(buf), l-1) < 0 THEN END;
END; END;
lino := EM.LINO(); lino := LINO();
i := 0; i := 0;
IF lino # 0 THEN IF lino # 0 THEN
i := 7; i := 7;
@ -76,20 +77,20 @@ IMPLEMENTATION MODULE Traps;
END; END;
buf[i] := ':'; buf[i] := ':';
buf[i+1] := ' '; buf[i+1] := ' ';
IF Unix.write(2, ADR(buf), i+2) < 0 THEN END; IF write(2, ADR(buf), i+2) < 0 THEN END;
i := 0; i := 0;
WHILE (i <= HIGH(str)) AND (str[i] # 0C) DO WHILE (i <= HIGH(str)) AND (str[i] # 0C) DO
INC(i); INC(i);
END; END;
IF Unix.write(2, ADR(str), i) < 0 THEN END; IF write(2, ADR(str), i) < 0 THEN END;
buf[0] := 12C; buf[0] := 12C;
IF Unix.write(2, ADR(buf), 1) < 0 THEN END; IF write(2, ADR(buf), 1) < 0 THEN END;
END Message; END Message;
PROCEDURE Trap(n: INTEGER); PROCEDURE Trap(n: INTEGER);
(* cause trap number "n" to occur *) (* cause trap number "n" to occur *)
BEGIN BEGIN
EM.TRP(n); TRP(n);
END Trap; END Trap;
END Traps. END Traps.

View file

@ -11,30 +11,30 @@ IMPLEMENTATION MODULE random;
Version: $Header$ Version: $Header$
*) *)
FROM Unix IMPORT getpid, time; FROM Unix IMPORT getpid, time;
TYPE index = [1..55]; TYPE index = [1..55];
VAR X: ARRAY index OF CARDINAL; VAR X: ARRAY index OF CARDINAL;
j, k: index; j, k: index;
tm: LONGINT; tm: LONGINT;
PROCEDURE Random(): CARDINAL; PROCEDURE Random(): CARDINAL;
BEGIN BEGIN
IF k-1 <= 0 THEN k := 55; ELSE DEC(k) END; IF k-1 <= 0 THEN k := 55; ELSE DEC(k) END;
IF j-1 <= 0 THEN j := 55; ELSE DEC(j) END; IF j-1 <= 0 THEN j := 55; ELSE DEC(j) END;
X[k] := X[k] + X[j]; X[k] := X[k] + X[j];
RETURN X[k] RETURN X[k]
END Random; END Random;
PROCEDURE Uniform (lwb, upb: CARDINAL): CARDINAL; PROCEDURE Uniform (lwb, upb: CARDINAL): CARDINAL;
BEGIN BEGIN
IF upb <= lwb THEN RETURN lwb; END; IF upb <= lwb THEN RETURN lwb; END;
RETURN lwb + (Random() MOD (upb - lwb + 1)); RETURN lwb + (Random() MOD (upb - lwb + 1));
END Uniform; END Uniform;
PROCEDURE StartSeed(seed: CARDINAL); PROCEDURE StartSeed(seed: CARDINAL);
VAR v: CARDINAL; VAR v: CARDINAL;
BEGIN BEGIN
FOR k := 1 TO 55 DO FOR k := 1 TO 55 DO
seed := 1297 * seed + 123; seed := 1297 * seed + 123;
X[k] := seed; X[k] := seed;
@ -49,7 +49,7 @@ BEGIN
END; END;
k := 1; k := 1;
j := 25; j := 25;
END StartSeed; END StartSeed;
BEGIN BEGIN
tm := time(NIL); tm := time(NIL);