diff --git a/lang/m2/libm2/ArraySort.mod b/lang/m2/libm2/ArraySort.mod index f48162898..147ca9e60 100644 --- a/lang/m2/libm2/ArraySort.mod +++ b/lang/m2/libm2/ArraySort.mod @@ -10,7 +10,7 @@ IMPLEMENTATION MODULE ArraySort; Author: Ceriel J.H. Jacobs Version: $Header$ *) - FROM SYSTEM IMPORT ADDRESS, BYTE; (* no generics in Modula-2, sorry *) + FROM SYSTEM IMPORT ADDRESS, BYTE; (* no generics in Modula-2, sorry *) TYPE BytePtr = POINTER TO BYTE; @@ -153,4 +153,3 @@ IMPLEMENTATION MODULE ArraySort; END threewayexchange; END ArraySort. - diff --git a/lang/m2/libm2/CSP.mod b/lang/m2/libm2/CSP.mod index 46ee0b4b7..e70b23f5a 100644 --- a/lang/m2/libm2/CSP.mod +++ b/lang/m2/libm2/CSP.mod @@ -14,7 +14,7 @@ IMPLEMENTATION MODULE CSP; FROM random IMPORT Uniform; FROM SYSTEM IMPORT BYTE, ADDRESS, NEWPROCESS, TRANSFER; FROM Storage IMPORT Allocate, Deallocate; - IMPORT Traps; + FROM Traps IMPORT Message; CONST WorkSpaceSize = 1000; @@ -212,7 +212,7 @@ IMPLEMENTATION MODULE CSP; BEGIN WITH ch^ DO IF owner # NIL THEN - Traps.Message("Channel already has an owner"); + Message("Channel already has an owner"); HALT END; owner := cp @@ -251,7 +251,7 @@ IMPLEMENTATION MODULE CSP; BEGIN WITH ch^ DO IF cp # owner THEN - Traps.Message("Only owner of channel can receive from it"); + Message("Only owner of channel can receive from it"); HALT END; IF Sending(ch) THEN diff --git a/lang/m2/libm2/InOut.mod b/lang/m2/libm2/InOut.mod index 223eb9fc3..74e56af52 100644 --- a/lang/m2/libm2/InOut.mod +++ b/lang/m2/libm2/InOut.mod @@ -11,9 +11,11 @@ IMPLEMENTATION MODULE InOut ; Version: $Header$ *) - IMPORT Streams; - IMPORT Conversions; - IMPORT Traps; + IMPORT Streams; + FROM Conversions IMPORT + ConvertCardinal, ConvertInteger, + ConvertOctal, ConvertHex; + FROM Traps IMPORT Message; CONST TAB = 11C; @@ -190,7 +192,7 @@ IMPLEMENTATION MODULE InOut ; IF (int > SAFELIMITDIV10) OR ( (int = SAFELIMITDIV10) AND (chvalue > safedigit)) THEN - Traps.Message("integer too large"); + Message("integer too large"); HALT; ELSE int := 10*int + VAL(INTEGER, chvalue); @@ -203,7 +205,7 @@ IMPLEMENTATION MODULE InOut ; integ := int END; IF buf[index] > " " THEN - Traps.Message("illegal integer"); + Message("illegal integer"); HALT; END; Done := TRUE; @@ -235,7 +237,7 @@ IMPLEMENTATION MODULE InOut ; IF (int > SAFELIMITDIV10) OR ( (int = SAFELIMITDIV10) AND (chvalue > safedigit)) THEN - Traps.Message("cardinal too large"); + Message("cardinal too large"); HALT; ELSE int := 10*int + chvalue; @@ -243,7 +245,7 @@ IMPLEMENTATION MODULE InOut ; END; END; IF buf[index] > " " THEN - Traps.Message("illegal cardinal"); + Message("illegal cardinal"); HALT; END; card := int; @@ -318,7 +320,7 @@ IMPLEMENTATION MODULE InOut ; VAR buf : numbuf; BEGIN - Conversions.ConvertCardinal(card, width, buf); + ConvertCardinal(card, width, buf); WriteString(buf); END WriteCard; @@ -326,7 +328,7 @@ IMPLEMENTATION MODULE InOut ; VAR buf : numbuf; BEGIN - Conversions.ConvertInteger(int, width, buf); + ConvertInteger(int, width, buf); WriteString(buf); END WriteInt; @@ -334,7 +336,7 @@ IMPLEMENTATION MODULE InOut ; VAR buf : numbuf; BEGIN - Conversions.ConvertHex(card, width, buf); + ConvertHex(card, width, buf); WriteString(buf); END WriteHex; @@ -347,7 +349,7 @@ IMPLEMENTATION MODULE InOut ; VAR buf : numbuf; BEGIN - Conversions.ConvertOctal(card, width, buf); + ConvertOctal(card, width, buf); WriteString(buf); END WriteOct; diff --git a/lang/m2/libm2/MathLib0.mod b/lang/m2/libm2/MathLib0.mod index f3f67be6b..ba40da625 100644 --- a/lang/m2/libm2/MathLib0.mod +++ b/lang/m2/libm2/MathLib0.mod @@ -11,41 +11,41 @@ IMPLEMENTATION MODULE MathLib0; Version: $Header$ *) - IMPORT Mathlib; + IMPORT Mathlib; -PROCEDURE cos(arg: REAL): REAL; -BEGIN + PROCEDURE cos(arg: REAL): REAL; + BEGIN RETURN Mathlib.cos(arg); -END cos; + END cos; -PROCEDURE sin(arg: REAL): REAL; -BEGIN + PROCEDURE sin(arg: REAL): REAL; + BEGIN RETURN Mathlib.sin(arg); -END sin; + END sin; -PROCEDURE arctan(arg: REAL): REAL; -BEGIN + PROCEDURE arctan(arg: REAL): REAL; + BEGIN RETURN Mathlib.arctan(arg); -END arctan; + END arctan; -PROCEDURE sqrt(arg: REAL): REAL; -BEGIN + PROCEDURE sqrt(arg: REAL): REAL; + BEGIN RETURN Mathlib.sqrt(arg); -END sqrt; + END sqrt; -PROCEDURE ln(arg: REAL): REAL; -BEGIN + PROCEDURE ln(arg: REAL): REAL; + BEGIN RETURN Mathlib.ln(arg); -END ln; + END ln; -PROCEDURE exp(arg: REAL): REAL; -BEGIN + PROCEDURE exp(arg: REAL): REAL; + BEGIN RETURN Mathlib.exp(arg); -END exp; + END exp; -PROCEDURE entier(x: REAL): INTEGER; + PROCEDURE entier(x: REAL): INTEGER; VAR i: INTEGER; -BEGIN + BEGIN IF x < 0.0 THEN i := TRUNC(-x); IF FLOAT(i) = -x THEN @@ -55,15 +55,15 @@ BEGIN END; END; RETURN TRUNC(x); -END entier; + END entier; -PROCEDURE real(x: INTEGER): REAL; -BEGIN + PROCEDURE real(x: INTEGER): REAL; + BEGIN IF x < 0 THEN RETURN - FLOAT(-x); END; RETURN FLOAT(x); -END real; + END real; BEGIN END MathLib0. diff --git a/lang/m2/libm2/Mathlib.mod b/lang/m2/libm2/Mathlib.mod index c920f1ea9..31899e8d3 100644 --- a/lang/m2/libm2/Mathlib.mod +++ b/lang/m2/libm2/Mathlib.mod @@ -11,8 +11,8 @@ IMPLEMENTATION MODULE Mathlib; Version: $Header$ *) - FROM EM IMPORT FIF, FEF; - FROM Traps IMPORT Message; + FROM EM IMPORT FIF, FEF; + FROM Traps IMPORT Message; CONST OneRadianInDegrees = 57.295779513082320876798155D; diff --git a/lang/m2/libm2/PascalIO.mod b/lang/m2/libm2/PascalIO.mod index 07c11dbaf..b29049bd3 100644 --- a/lang/m2/libm2/PascalIO.mod +++ b/lang/m2/libm2/PascalIO.mod @@ -11,14 +11,16 @@ IMPLEMENTATION MODULE PascalIO; Version: $Header$ *) - IMPORT Conversions; - IMPORT Traps; - IMPORT RealConversions; - FROM Streams IMPORT Stream, StreamKind, StreamMode, StreamResult, - InputStream, OutputStream, OpenStream, CloseStream, - EndOfStream, Read, Write, StreamBuffering; - FROM Storage IMPORT Allocate; - FROM SYSTEM IMPORT ADR; + FROM Conversions IMPORT + ConvertInteger, ConvertCardinal; + FROM RealConversions IMPORT + LongRealToString, StringToLongReal; + FROM Traps IMPORT Message; + FROM Streams IMPORT Stream, StreamKind, StreamMode, StreamResult, + InputStream, OutputStream, OpenStream, CloseStream, + EndOfStream, Read, Write, StreamBuffering; + FROM Storage IMPORT Allocate; + FROM SYSTEM IMPORT ADR; TYPE charset = SET OF CHAR; btype = (Preading, Pwriting, free); @@ -46,7 +48,7 @@ IMPLEMENTATION MODULE PascalIO; WITH InputText^ DO OpenStream(stream, Filename, text, reading, result); IF result # succeeded THEN - Traps.Message("could not open input file"); + Message("could not open input file"); HALT; END; type := Preading; @@ -62,7 +64,7 @@ IMPLEMENTATION MODULE PascalIO; WITH OutputText^ DO OpenStream(stream, Filename, text, writing, result); IF result # succeeded THEN - Traps.Message("could not open output file"); + Message("could not open output file"); HALT; END; type := Pwriting; @@ -107,9 +109,9 @@ IMPLEMENTATION MODULE PascalIO; PROCEDURE Error(tp: btype); BEGIN IF tp = Preading THEN - Traps.Message("input text expected"); + Message("input text expected"); ELSE - Traps.Message("output text expected"); + Message("output text expected"); END; HALT; END Error; @@ -118,7 +120,7 @@ IMPLEMENTATION MODULE PascalIO; BEGIN ch := NextChar(InputText); IF InputText^.eof THEN - Traps.Message("unexpected EOF"); + Message("unexpected EOF"); HALT; END; InputText^.done := FALSE; @@ -218,7 +220,7 @@ IMPLEMENTATION MODULE PascalIO; IF (int < -SAFELIMITDIV10) OR ( (int = -SAFELIMITDIV10) AND (chvalue > safedigit)) THEN - Traps.Message("integer too large"); + Message("integer too large"); HALT; ELSE int := 10*int - VAL(INTEGER, chvalue); @@ -230,7 +232,7 @@ IMPLEMENTATION MODULE PascalIO; int := -int END; ELSE - Traps.Message("integer expected"); + Message("integer expected"); HALT; END; END ReadInteger; @@ -257,7 +259,7 @@ IMPLEMENTATION MODULE PascalIO; IF (card > SAFELIMITDIV10) OR ( (card = SAFELIMITDIV10) AND (chvalue > safedigit)) THEN - Traps.Message("cardinal too large"); + Message("cardinal too large"); HALT; ELSE card := 10*card + chvalue; @@ -266,7 +268,7 @@ IMPLEMENTATION MODULE PascalIO; END; END; ELSE - Traps.Message("cardinal expected"); + Message("cardinal expected"); HALT; END; END ReadCardinal; @@ -335,10 +337,10 @@ IMPLEMENTATION MODULE PascalIO; END; IF ok THEN buf[index] := 0C; - RealConversions.StringToLongReal(buf, real, ok); + StringToLongReal(buf, real, ok); END; IF NOT ok THEN - Traps.Message("Illegal real"); + Message("Illegal real"); HALT; END; END ReadLongReal; @@ -347,7 +349,7 @@ IMPLEMENTATION MODULE PascalIO; VAR buf : numbuf; BEGIN - Conversions.ConvertCardinal(card, 1, buf); + ConvertCardinal(card, 1, buf); WriteString(OutputText, buf, width); END WriteCardinal; @@ -355,7 +357,7 @@ IMPLEMENTATION MODULE PascalIO; VAR buf : numbuf; BEGIN - Conversions.ConvertInteger(int, 1, buf); + ConvertInteger(int, 1, buf); WriteString(OutputText, buf, width); END WriteInteger; @@ -383,7 +385,7 @@ IMPLEMENTATION MODULE PascalIO; width := SIZE(buf); END; IF nfrac > 0 THEN - RealConversions.LongRealToString(real, width, nfrac, buf, ok); + LongRealToString(real, width, nfrac, buf, ok); ELSE IF width < 9 THEN width := 9; END; IF real < 0.0D THEN @@ -391,7 +393,7 @@ IMPLEMENTATION MODULE PascalIO; ELSE digits := 6 - INTEGER(width); END; - RealConversions.LongRealToString(real, width, digits, buf, ok); + LongRealToString(real, width, digits, buf, ok); END; WriteString(OutputText, buf, 0); END WriteLongReal; diff --git a/lang/m2/libm2/Processes.mod b/lang/m2/libm2/Processes.mod index 594cf0b5e..152c7e640 100644 --- a/lang/m2/libm2/Processes.mod +++ b/lang/m2/libm2/Processes.mod @@ -6,11 +6,9 @@ IMPLEMENTATION MODULE Processes [1]; Version: $Header$ *) - FROM SYSTEM IMPORT ADDRESS, TSIZE, NEWPROCESS, TRANSFER; - - FROM Storage IMPORT Allocate; - - FROM Traps IMPORT Message; + FROM SYSTEM IMPORT ADDRESS, TSIZE, NEWPROCESS, TRANSFER; + FROM Storage IMPORT Allocate; + FROM Traps IMPORT Message; TYPE SIGNAL = POINTER TO ProcessDescriptor; diff --git a/lang/m2/libm2/RealInOut.mod b/lang/m2/libm2/RealInOut.mod index 3a09cf306..e2565cc2f 100644 --- a/lang/m2/libm2/RealInOut.mod +++ b/lang/m2/libm2/RealInOut.mod @@ -11,10 +11,11 @@ IMPLEMENTATION MODULE RealInOut; Version: $Header$ *) - IMPORT InOut; - IMPORT RealConversions; - IMPORT Traps; - FROM SYSTEM IMPORT WORD; + FROM InOut IMPORT ReadString, WriteString, WriteOct; + FROM Traps IMPORT Message; + FROM SYSTEM IMPORT WORD; + FROM RealConversions IMPORT + LongRealToString, StringToLongReal; CONST MAXNDIG = 32; MAXWIDTH = MAXNDIG+7; @@ -32,8 +33,8 @@ IMPLEMENTATION MODULE RealInOut; BEGIN IF ndigits > MAXWIDTH THEN ndigits := MAXWIDTH; END; IF ndigits < 10 THEN ndigits := 10; END; - RealConversions.LongRealToString(arg, ndigits, -INTEGER(ndigits - 7), buf, ok); - InOut.WriteString(buf); + LongRealToString(arg, ndigits, -INTEGER(ndigits - 7), buf, ok); + WriteString(buf); END WriteLongReal; PROCEDURE WriteFixPt(arg: REAL; n, k: CARDINAL); @@ -47,8 +48,8 @@ IMPLEMENTATION MODULE RealInOut; BEGIN IF n > MAXWIDTH THEN n := MAXWIDTH END; - RealConversions.LongRealToString(arg, n, k, buf, ok); - InOut.WriteString(buf); + LongRealToString(arg, n, k, buf, ok); + WriteString(buf); END WriteLongFixPt; PROCEDURE ReadReal(VAR x: REAL); @@ -63,10 +64,10 @@ IMPLEMENTATION MODULE RealInOut; ok: BOOLEAN; BEGIN - InOut.ReadString(Buf); - RealConversions.StringToLongReal(Buf, x, ok); + ReadString(Buf); + StringToLongReal(Buf, x, ok); IF NOT ok THEN - Traps.Message("real expected"); + Message("real expected"); HALT; END; Done := TRUE; @@ -76,8 +77,8 @@ IMPLEMENTATION MODULE RealInOut; VAR i: CARDINAL; BEGIN FOR i := 0 TO HIGH(x) DO - InOut.WriteOct(CARDINAL(x[i]), 0); - InOut.WriteString(" "); + WriteOct(CARDINAL(x[i]), 0); + WriteString(" "); END; END wroct; diff --git a/lang/m2/libm2/Semaphores.mod b/lang/m2/libm2/Semaphores.mod index c39473c41..d6c056649 100644 --- a/lang/m2/libm2/Semaphores.mod +++ b/lang/m2/libm2/Semaphores.mod @@ -13,10 +13,10 @@ IMPLEMENTATION MODULE Semaphores [1]; Quasi-concurrency implementation *) - FROM SYSTEM IMPORT ADDRESS, NEWPROCESS, TRANSFER; - FROM Storage IMPORT Allocate; - FROM random IMPORT Uniform; - FROM Traps IMPORT Message; + FROM SYSTEM IMPORT ADDRESS, NEWPROCESS, TRANSFER; + FROM Storage IMPORT Allocate; + FROM random IMPORT Uniform; + FROM Traps IMPORT Message; TYPE Sema = POINTER TO Semaphore; Processes = POINTER TO Process; diff --git a/lang/m2/libm2/Storage.mod b/lang/m2/libm2/Storage.mod index 49c089968..a416f4901 100644 --- a/lang/m2/libm2/Storage.mod +++ b/lang/m2/libm2/Storage.mod @@ -15,9 +15,9 @@ IMPLEMENTATION MODULE Storage; same size. Commonly used sizes have their own bucket. The larger ones are put in a single list. *) - FROM Unix IMPORT sbrk, ILLBREAK; - FROM SYSTEM IMPORT ADDRESS, ADR; - FROM Traps IMPORT Message; + FROM Unix IMPORT sbrk, ILLBREAK; + FROM SYSTEM IMPORT ADDRESS, ADR; + FROM Traps IMPORT Message; CONST NLISTS = 20; diff --git a/lang/m2/libm2/Streams.mod b/lang/m2/libm2/Streams.mod index 6cd36d3e3..a827d0c35 100644 --- a/lang/m2/libm2/Streams.mod +++ b/lang/m2/libm2/Streams.mod @@ -14,8 +14,11 @@ IMPLEMENTATION MODULE Streams; Implementation for Unix *) - FROM SYSTEM IMPORT BYTE, ADR; - IMPORT StripUnix, Storage, Epilogue; + FROM SYSTEM IMPORT BYTE, ADR; + FROM Epilogue IMPORT CallAtEnd; + FROM Storage IMPORT Allocate, Available; + FROM StripUnix IMPORT + open, close, lseek, read, write, creat, ioctl; CONST BUFSIZ = 1024; (* tunable *) TYPE IOB = RECORD @@ -41,10 +44,10 @@ IMPLEMENTATION MODULE Streams; stream := stream^.next; END; IF stream = NIL THEN - IF NOT Storage.Available(SIZE(IOB)) THEN + IF NOT Available(SIZE(IOB)) THEN RETURN; END; - Storage.Allocate(stream,SIZE(IOB)); + Allocate(stream,SIZE(IOB)); stream^.next := head; head := stream; END; @@ -79,17 +82,17 @@ IMPLEMENTATION MODULE Streams; buf[HIGH(filename)+2] := BYTE(0C); END; IF (mode = reading) THEN - fd := StripUnix.open(ADR(stream^.buf), 0); + fd := open(ADR(stream^.buf), 0); ELSE fd := -1; IF (mode = appending) THEN - fd := StripUnix.open(ADR(stream^.buf), 1); + fd := open(ADR(stream^.buf), 1); IF fd >= 0 THEN - IF (StripUnix.lseek(fd, 0D , 2) < 0D) THEN ; END; + IF (lseek(fd, 0D , 2) < 0D) THEN ; END; END; END; IF fd < 0 THEN - fd := StripUnix.creat(ADR(stream^.buf), 666B); + fd := creat(ADR(stream^.buf), 666B); END; END; IF fd < 0 THEN @@ -150,7 +153,7 @@ IMPLEMENTATION MODULE Streams; IF (cnt > 0) THEN cnt1 := cnt; cnt := 0; - IF StripUnix.write(fildes, ADR(buf), cnt1) < 0 THEN END; + IF write(fildes, ADR(buf), cnt1) < 0 THEN END; END; END; END FlushStream; @@ -162,7 +165,7 @@ IMPLEMENTATION MODULE Streams; IF stream^.mode # reading THEN FlushStream(stream, result); END; - IF StripUnix.close(stream^.fildes) < 0 THEN ; END; + IF close(stream^.fildes) < 0 THEN ; END; freestruct(stream); ELSE result := nostream; @@ -209,7 +212,7 @@ IMPLEMENTATION MODULE Streams; IF stream = InputStream THEN FlushLineBuffers(); END; - maxcnt := StripUnix.read(fildes, ADR(buf), bufferedcnt); + maxcnt := read(fildes, ADR(buf), bufferedcnt); cnt := 1; IF maxcnt <= 0 THEN eof := TRUE; @@ -332,7 +335,7 @@ IMPLEMENTATION MODULE Streams; RETURN; 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 result := illegaloperation; RETURN; @@ -357,7 +360,7 @@ IMPLEMENTATION MODULE Streams; s^.eof := FALSE; END; IF s^.mode = appending THEN - currpos := StripUnix.lseek(s^.fildes, 0D, 1); + currpos := lseek(s^.fildes, 0D, 1); IF currpos < 0D THEN result := illegaloperation; RETURN; @@ -367,7 +370,7 @@ IMPLEMENTATION MODULE Streams; result := illegaloperation; RETURN; END; - currpos := StripUnix.lseek(s^.fildes, position, 0); + currpos := lseek(s^.fildes, position, 0); IF currpos < 0D THEN result := illegaloperation; RETURN; @@ -383,12 +386,12 @@ IMPLEMENTATION MODULE Streams; RETURN FALSE; END; #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 #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 - 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 END isatty; @@ -440,7 +443,7 @@ IMPLEMENTATION MODULE Streams; END; END; head := InputStream; - IF Epilogue.CallAtEnd(EndIt) THEN ; END; + IF CallAtEnd(EndIt) THEN ; END; END InitStreams; BEGIN diff --git a/lang/m2/libm2/Strings.mod b/lang/m2/libm2/Strings.mod index 20e6ccce9..8ae31eea5 100644 --- a/lang/m2/libm2/Strings.mod +++ b/lang/m2/libm2/Strings.mod @@ -11,12 +11,12 @@ IMPLEMENTATION MODULE Strings; Version: $Header$ *) -PROCEDURE Assign(source: ARRAY OF CHAR; VAR dest: ARRAY OF CHAR); -(* Assign string source to dest -*) -VAR i: CARDINAL; + PROCEDURE Assign(source: ARRAY OF CHAR; VAR dest: ARRAY OF CHAR); + (* Assign string source to dest + *) + VAR i: CARDINAL; max: CARDINAL; -BEGIN + BEGIN max := HIGH(source); IF HIGH(dest) < max THEN max := HIGH(dest); END; i := 0; @@ -25,15 +25,15 @@ BEGIN INC(i); 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); -(* Insert the string substr into str, starting at str[inx]. - If inx is equal to or greater than Length(str) then substr is appended - to the end of str. -*) -VAR sublen, length, i: CARDINAL; -BEGIN + PROCEDURE Insert(substr: ARRAY OF CHAR; VAR str: ARRAY OF CHAR; inx: CARDINAL); + (* Insert the string substr into str, starting at str[inx]. + If inx is equal to or greater than Length(str) then substr is appended + to the end of str. + *) + VAR sublen, length, i: CARDINAL; + BEGIN sublen := Length(substr); IF sublen = 0 THEN RETURN; END; length := Length(str); @@ -54,16 +54,16 @@ BEGIN IF length + sublen <= HIGH(str) THEN str[length + sublen] := 0C; END; -END Insert; + END Insert; -PROCEDURE Delete(VAR str: ARRAY OF CHAR; inx, len: CARDINAL); -(* Delete len characters from str, starting at str[inx]. - If inx >= Length(str) then nothing happens. - If there are not len characters to delete, characters to the end of the - string are deleted. -*) -VAR length: CARDINAL; -BEGIN + PROCEDURE Delete(VAR str: ARRAY OF CHAR; inx, len: CARDINAL); + (* Delete len characters from str, starting at str[inx]. + If inx >= Length(str) then nothing happens. + If there are not len characters to delete, characters to the end of the + string are deleted. + *) + VAR length: CARDINAL; + BEGIN IF len = 0 THEN RETURN; END; length := Length(str); IF inx >= length THEN RETURN; END; @@ -72,14 +72,14 @@ BEGIN INC(inx); END; str[inx] := 0C; -END Delete; + END Delete; -PROCEDURE Pos(substr, str: ARRAY OF CHAR): CARDINAL; -(* Return the index into str of the first occurrence of substr. - Pos returns a value greater than HIGH(str) of no occurrence is found. -*) -VAR i, j, max, subl: CARDINAL; -BEGIN + PROCEDURE Pos(substr, str: ARRAY OF CHAR): CARDINAL; + (* Return the index into str of the first occurrence of substr. + Pos returns a value greater than HIGH(str) of no occurrence is found. + *) + VAR i, j, max, subl: CARDINAL; + BEGIN max := Length(str); subl := Length(substr); IF subl > max THEN RETURN HIGH(str) + 1; END; @@ -93,15 +93,15 @@ BEGIN IF j = subl THEN RETURN i; END; END; RETURN HIGH(str) + 1; -END Pos; + END Pos; -PROCEDURE Copy(str: ARRAY OF CHAR; - inx, len: CARDINAL; - VAR result: ARRAY OF CHAR); -(* Copy at most len characters from str into result, starting at str[inx]. -*) -VAR i: CARDINAL; -BEGIN + PROCEDURE Copy(str: ARRAY OF CHAR; + inx, len: CARDINAL; + VAR result: ARRAY OF CHAR); + (* Copy at most len characters from str into result, starting at str[inx]. + *) + VAR i: CARDINAL; + BEGIN IF Length(str) <= inx THEN RETURN END; i := 0; LOOP @@ -112,13 +112,13 @@ BEGIN INC(i); INC(inx); DEC(len); 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); -(* Concatenate two strings. -*) -VAR i, j: CARDINAL; -BEGIN + PROCEDURE Concat(s1, s2: ARRAY OF CHAR; VAR result: ARRAY OF CHAR); + (* Concatenate two strings. + *) + VAR i, j: CARDINAL; + BEGIN i := 0; WHILE (i <= HIGH(s1)) AND (s1[i] # 0C) DO IF i > HIGH(result) THEN RETURN END; @@ -133,27 +133,27 @@ BEGIN INC(j); END; IF i <= HIGH(result) THEN result[i] := 0C; END; -END Concat; + END Concat; -PROCEDURE Length(str: ARRAY OF CHAR): CARDINAL; -(* Return number of characters in str. -*) -VAR i: CARDINAL; -BEGIN + PROCEDURE Length(str: ARRAY OF CHAR): CARDINAL; + (* Return number of characters in str. + *) + VAR i: CARDINAL; + BEGIN i := 0; WHILE (i <= HIGH(str)) DO IF str[i] = 0C THEN RETURN i; END; INC(i); END; RETURN i; -END Length; + END Length; -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. -*) -VAR i: CARDINAL; + 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. + *) + VAR i: CARDINAL; max: CARDINAL; -BEGIN + BEGIN max := HIGH(s1); IF HIGH(s2) < max THEN max := HIGH(s2); END; i := 0; @@ -166,6 +166,6 @@ BEGIN IF (i <= HIGH(s1)) AND (s1[i] # 0C) THEN RETURN 1; END; IF (i <= HIGH(s2)) AND (s2[i] # 0C) THEN RETURN -1; END; RETURN 0; -END CompareStr; + END CompareStr; END Strings. diff --git a/lang/m2/libm2/Termcap.mod b/lang/m2/libm2/Termcap.mod index 01d2371ec..f1a68b0bb 100644 --- a/lang/m2/libm2/Termcap.mod +++ b/lang/m2/libm2/Termcap.mod @@ -13,9 +13,10 @@ IMPLEMENTATION MODULE Termcap; IMPORT XXTermcap; - FROM SYSTEM IMPORT ADR, ADDRESS; - FROM Unix IMPORT gtty; - FROM Arguments IMPORT GetEnv; + FROM SYSTEM IMPORT ADR, ADDRESS; + FROM Unix IMPORT gtty; + FROM Arguments IMPORT + GetEnv; TYPE STR = ARRAY[1..32] OF CHAR; STRCAP = POINTER TO STR; diff --git a/lang/m2/libm2/Terminal.mod b/lang/m2/libm2/Terminal.mod index 0ac6c61c3..7a6c0a66f 100644 --- a/lang/m2/libm2/Terminal.mod +++ b/lang/m2/libm2/Terminal.mod @@ -13,9 +13,12 @@ IMPLEMENTATION MODULE Terminal; 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; unreadch: CHAR; unread: BOOLEAN; @@ -27,7 +30,7 @@ IMPLEMENTATION MODULE Terminal; ch := unreadch; unread := FALSE ELSE - IF Unix.read(fildes, ADR(ch), 1) < 0 THEN + IF read(fildes, ADR(ch), 1) < 0 THEN ; END; END; @@ -42,25 +45,25 @@ IMPLEMENTATION MODULE Terminal; unread := FALSE ELSE #ifdef __USG - l := Unix.fcntl(fildes, (*FGETFL*) 3, 0); - IF Unix.fcntl(fildes, + l := fcntl(fildes, (*FGETFL*) 3, 0); + IF fcntl(fildes, (* FSETFL *) 4, l + (*ONDELAY*) 2) < 0 THEN ; END; - IF Unix.read(fildes, ADR(ch), 1) = 0 THEN + IF read(fildes, ADR(ch), 1) = 0 THEN ch := 0C; ELSE unreadch := ch; END; - IF Unix.fcntl(fildes, (*FSETFL*)4, l) < 0 THEN + IF fcntl(fildes, (*FSETFL*)4, l) < 0 THEN ; END; #else #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 - 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 ; END; @@ -68,7 +71,7 @@ IMPLEMENTATION MODULE Terminal; IF l = 0 THEN ch := 0C; ELSE - IF Unix.read(fildes, ADR(ch), 1) < 0 THEN + IF read(fildes, ADR(ch), 1) < 0 THEN ; END; unreadch := ch; @@ -84,7 +87,7 @@ IMPLEMENTATION MODULE Terminal; PROCEDURE Write(ch: CHAR); BEGIN - IF Unix.write(fildes, ADR(ch), 1) < 0 THEN + IF write(fildes, ADR(ch), 1) < 0 THEN ; END; END Write; @@ -106,6 +109,6 @@ IMPLEMENTATION MODULE Terminal; BEGIN tty := "/dev/tty"; - fildes := Unix.open(ADR(tty), 2); + fildes := open(ADR(tty), 2); unread := FALSE; END Terminal. diff --git a/lang/m2/libm2/Traps.mod b/lang/m2/libm2/Traps.mod index fb93b4b7e..913ee4a8d 100644 --- a/lang/m2/libm2/Traps.mod +++ b/lang/m2/libm2/Traps.mod @@ -11,17 +11,18 @@ IMPLEMENTATION MODULE Traps; Version: $Header$ *) - IMPORT EM; - IMPORT Unix; - FROM SYSTEM IMPORT ADDRESS, ADR; - FROM Arguments IMPORT Argv; + FROM EM IMPORT SIG, LINO, FILN, TRP; + FROM Unix IMPORT write; + FROM SYSTEM IMPORT ADDRESS, ADR; + FROM Arguments IMPORT + Argv; 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 EM.SIG(t); + RETURN SIG(t); END InstallTrapHandler; PROCEDURE Message(str: ARRAY OF CHAR); @@ -34,7 +35,7 @@ IMPLEMENTATION MODULE Traps; buf, buf2: ARRAY [0..255] OF CHAR; i, j: CARDINAL; BEGIN - p := EM.FILN(); + p := FILN(); IF p # NIL THEN i := 1; buf[0] := '"'; @@ -45,12 +46,12 @@ IMPLEMENTATION MODULE Traps; END; buf[i] := '"'; INC(i); - IF Unix.write(2, ADR(buf), i) < 0 THEN END; + IF write(2, ADR(buf), i) < 0 THEN END; ELSE 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; - lino := EM.LINO(); + lino := LINO(); i := 0; IF lino # 0 THEN i := 7; @@ -76,20 +77,20 @@ IMPLEMENTATION MODULE Traps; END; buf[i] := ':'; 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; WHILE (i <= HIGH(str)) AND (str[i] # 0C) DO INC(i); END; - IF Unix.write(2, ADR(str), i) < 0 THEN END; + IF write(2, ADR(str), i) < 0 THEN END; buf[0] := 12C; - IF Unix.write(2, ADR(buf), 1) < 0 THEN END; + IF write(2, ADR(buf), 1) < 0 THEN END; END Message; PROCEDURE Trap(n: INTEGER); (* cause trap number "n" to occur *) BEGIN - EM.TRP(n); + TRP(n); END Trap; END Traps. diff --git a/lang/m2/libm2/random.mod b/lang/m2/libm2/random.mod index 487b47b14..826e99f69 100644 --- a/lang/m2/libm2/random.mod +++ b/lang/m2/libm2/random.mod @@ -11,30 +11,30 @@ IMPLEMENTATION MODULE random; Version: $Header$ *) -FROM Unix IMPORT getpid, time; -TYPE index = [1..55]; + FROM Unix IMPORT getpid, time; + TYPE index = [1..55]; -VAR X: ARRAY index OF CARDINAL; + VAR X: ARRAY index OF CARDINAL; j, k: index; tm: LONGINT; -PROCEDURE Random(): CARDINAL; -BEGIN + PROCEDURE Random(): CARDINAL; + BEGIN IF k-1 <= 0 THEN k := 55; ELSE DEC(k) END; IF j-1 <= 0 THEN j := 55; ELSE DEC(j) END; X[k] := X[k] + X[j]; RETURN X[k] -END Random; + END Random; -PROCEDURE Uniform (lwb, upb: CARDINAL): CARDINAL; -BEGIN + PROCEDURE Uniform (lwb, upb: CARDINAL): CARDINAL; + BEGIN IF upb <= lwb THEN RETURN lwb; END; RETURN lwb + (Random() MOD (upb - lwb + 1)); -END Uniform; + END Uniform; -PROCEDURE StartSeed(seed: CARDINAL); -VAR v: CARDINAL; -BEGIN + PROCEDURE StartSeed(seed: CARDINAL); + VAR v: CARDINAL; + BEGIN FOR k := 1 TO 55 DO seed := 1297 * seed + 123; X[k] := seed; @@ -49,7 +49,7 @@ BEGIN END; k := 1; j := 25; -END StartSeed; + END StartSeed; BEGIN tm := time(NIL);