Selaa lähdekoodia

Console interface simplified; implementations rewritten; Linux and OpenBSD implementations localized (based on Enc)

Alexander Shiryaev 12 vuotta sitten
vanhempi
commit
fc518f1960

+ 50 - 0
BlackBox/Enc/Mod/Codecs.txt

@@ -0,0 +1,50 @@
+MODULE EncCodecs;
+
+	(* THIS IS TEXT COPY OF Codecs.odc *)
+	(* DO NOT EDIT *)
+
+	(*
+			A. V. Shiryaev, 2012.10
+	*)
+
+	TYPE
+		Encoding* = ARRAY 32 OF CHAR;
+		Directory* = POINTER TO ABSTRACT RECORD END;
+		Encoder* = POINTER TO ABSTRACT RECORD END;
+		Decoder* = POINTER TO ABSTRACT RECORD END;
+
+	VAR
+		dir-: Directory;
+
+	(* Directory *)
+
+	PROCEDURE (dir: Directory) NewEncoder* (enc: Encoding): Encoder, NEW, ABSTRACT;
+	PROCEDURE (dir: Directory) NewDecoder* (enc: Encoding): Decoder, NEW, ABSTRACT;
+
+	(* Encoder *)
+
+	(* pre: fR >= 0, fLen >= 0, tW >= 0 *)
+	(* post:
+		fLen = 0: ok
+		fLen > 0: error at f[fR]
+	*)
+	PROCEDURE (e: Encoder) Encode* (IN f: ARRAY OF CHAR; VAR fR, fLen: INTEGER; VAR t: ARRAY OF SHORTCHAR; VAR tW: INTEGER), NEW, ABSTRACT;
+
+	(* Decoder *)
+
+	(* pre: d not in error state, fR >= 0, fLen >= 0, tW >= 0 *)
+	(* post:
+		fLen = 0: ok, state: d has state
+		fLen > 0: error at f[fR]
+	*)
+	PROCEDURE (d: Decoder) Decode* (IN f: ARRAY OF SHORTCHAR; VAR fR, fLen: INTEGER; VAR t: ARRAY OF CHAR; VAR tW: INTEGER; OUT state: BOOLEAN), NEW, ABSTRACT;
+
+	PROCEDURE (d: Decoder) Reset*, NEW, ABSTRACT;
+
+
+	PROCEDURE SetDir* (d: Directory);
+	BEGIN
+		dir := d
+	END SetDir;
+
+END EncCodecs.

+ 76 - 0
BlackBox/Enc/Mod/StdCodecs.txt

@@ -0,0 +1,76 @@
+MODULE EncStdCodecs;
+
+	(* THIS IS TEXT COPY OF StdCodecs.odc *)
+	(* DO NOT EDIT *)
+
+	(*
+			A. V. Shiryaev, 2012.10
+	*)
+
+	IMPORT Meta, Codecs := EncCodecs, Aliases := EncStdAliases;
+
+	TYPE
+		Directory* = POINTER TO RECORD (Codecs.Directory) END;
+
+	(* Directory *)
+
+	PROCEDURE (dir: Directory) NewEncoder* (enc: Codecs.Encoding): Codecs.Encoder;
+		VAR modName: ARRAY LEN(Codecs.Encoding) + 16 OF CHAR;
+			item: Meta.Item; ok: BOOLEAN;
+			item0: RECORD (Meta.Value)
+				fun: PROCEDURE (): Codecs.Encoder
+			END;
+			e: Codecs.Encoder;
+	BEGIN
+		e := NIL;
+		Aliases.GetModName(enc, modName, ok);
+		IF ok THEN
+			Meta.Lookup(modName, item);
+			IF item.obj = Meta.modObj THEN
+				item.Lookup("NewEncoder", item);
+				IF item.obj = Meta.procObj THEN
+					item.GetVal(item0, ok);
+					IF ok THEN
+						e := item0.fun()
+					END
+				END
+			END
+		END;
+		RETURN e
+	END NewEncoder;
+
+	PROCEDURE (dir: Directory) NewDecoder* (enc: Codecs.Encoding): Codecs.Decoder;
+		VAR modName: ARRAY LEN(Codecs.Encoding) + 16 OF CHAR;
+			item: Meta.Item; ok: BOOLEAN;
+			item0: RECORD (Meta.Value)
+				fun: PROCEDURE (): Codecs.Decoder
+			END;
+			d: Codecs.Decoder;
+	BEGIN
+		d := NIL;
+		Aliases.GetModName(enc, modName, ok);
+		IF ok THEN
+			Meta.Lookup(modName, item);
+			IF item.obj = Meta.modObj THEN
+				item.Lookup("NewDecoder", item);
+				IF item.obj = Meta.procObj THEN
+					item.GetVal(item0, ok);
+					IF ok THEN
+						d := item0.fun()
+					END
+				END
+			END
+		END;
+		RETURN d
+	END NewDecoder;
+
+
+	PROCEDURE Init;
+		VAR dir: Directory;
+	BEGIN
+		NEW(dir); Codecs.SetDir(dir)
+	END Init;
+
+BEGIN
+	Init
+END EncStdCodecs.

+ 1 - 0
BlackBox/Init-Interp.txt

@@ -1,6 +1,7 @@
 MODULE Init;
 
 	IMPORT
+		EncStdCodecs, (* EncCodecs.SetDir *)
 		HostConsole, (* Console.SetHook *)
 
 		HostFonts (* Fonts.SetHook; required for Texts *),

BIN
BlackBox/Linux/Host/Mod/Console.odc


+ 125 - 76
BlackBox/Linux/Host/Mod/Console.txt

@@ -3,109 +3,158 @@ MODULE HostConsole;
 	(* THIS IS TEXT COPY OF Console.odc *)
 	(* DO NOT EDIT *)
 
-	IMPORT
-		SYSTEM,
-		Console,
-		LinLibc;
+	(*
+		A. V. Shiryaev, 2012.10
 
-	TYPE
-		LinCons = POINTER TO RECORD (Console.Console) END;
+		Console implementation for Linux
+	*)
 
-		LinProcess = POINTER TO RECORD (Console.Process) END;
+	IMPORT SYSTEM, Console, Libc := LinLibc, Codecs := EncCodecs;
 
 	CONST
-		strLen = 1024;
+		defEnc = "ASCII";
+		defCh = '?';
+
+	TYPE
+		Cons = POINTER TO RECORD (Console.Console) END;
 
 	VAR
-		s: ARRAY strLen OF CHAR;
-		ss: ARRAY strLen OF SHORTCHAR;
-		linCons: LinCons;
-		version-: INTEGER;
-		maintainer-: ARRAY 40 OF CHAR;
+		cons: Cons;
+		e: Codecs.Encoder;
+		d: Codecs.Decoder;
 
-	PROCEDURE (cons: LinCons) ReadLn (OUT text: ARRAY OF CHAR);
+	PROCEDURE GetEnc (OUT enc: Codecs.Encoding);
+		VAR lang: Libc.PtrSTR;
+			i, j: INTEGER;
+	BEGIN
+		lang := Libc.getenv("LANG");
+		IF lang # NIL THEN
+			IF lang$ = "C" THEN
+				enc := "ASCII"
+			ELSE
+				i := 0; WHILE (lang[i] # 0X) & (lang[i] # '.') DO INC(i) END;
+				IF lang[i] # 0X THEN
+					INC(i);
+					j := 0;
+					WHILE (j < LEN(enc) - 1) & (lang[i] # 0X) DO
+						enc[j] := lang[i];
+						INC(j);
+						INC(i)
+					END;
+					IF j < LEN(enc) - 1 THEN
+						enc[j] := 0X
+					ELSE
+						enc := defEnc
+					END
+				ELSE
+					enc := defEnc
+				END
+			END
+		ELSE
+			enc := defEnc
+		END
+	END GetEnc;
+
+	PROCEDURE (cons: Cons) ReadLn (OUT s: ARRAY OF CHAR);
+		CONST
+			maxLineLen = 1023; (* without null terminating shortchar *)
 		VAR
 			i: INTEGER;
-			str: POINTER TO ARRAY [untagged] OF SHORTCHAR; 
+			str: Libc.PtrSTR;
+			ss: ARRAY maxLineLen+1 OF SHORTCHAR;
+			fR, fLen, tW: INTEGER;
+			st: BOOLEAN;
 	BEGIN
-		str := LinLibc.fgets(ss, strLen, LinLibc.stdin);
-		IF (str = NIL) THEN 
-			(* if end of file, then ss is not changed by fgets and NIL is returned. 
-			    We return an empty string here *)
-			text[0] := 0X;
-			RETURN
-		END;			
-		i := 0;
-		REPEAT
-			text[i] := ss[i];
-			INC(i)
-		UNTIL (ss[i] = 0X) OR (i = LEN(text) - 1);
-		text[i] := 0X 
+		ss[LEN(ss)-1] := 0X;
+		str := Libc.fgets(ss, LEN(ss), Libc.stdin);
+		IF (str # NIL) & (ss[LEN(ss)-1] = 0X) THEN
+			fLen := LEN(ss$);
+			IF fLen < LEN(s) THEN
+				IF d # NIL THEN
+					d.Reset;
+					fR := 0; tW := 0;
+					d.Decode(ss, fR, fLen, s, tW, st);
+					IF (fLen = 0) & ~st THEN
+						s[tW] := 0X
+					ELSE
+						s[0] := 0X
+					END
+				ELSE
+					s := ss$
+				END
+			ELSE
+				s[0] := 0X
+			END
+		ELSE
+			s[0] := 0X
+		END
 	END ReadLn;
 
-	PROCEDURE Printf;
-		VAR res: INTEGER;
+	PROCEDURE Printf (IN s: ARRAY OF CHAR; len: INTEGER);
+		CONST
+			maxShortCharsPerChar = 3; (* UTF-8 *)
+			ssLen = 128; (* >= maxShortCharsPerChar + 1 *)
+		VAR
+			ss: ARRAY ssLen OF SHORTCHAR;
+			res: INTEGER;
+			fR, fLen, tW, n: INTEGER;
 	BEGIN
-		res := LinLibc.printf(ss);
-		res := LinLibc.fflush(LinLibc.NULL)
+		fR := 0;
+		WHILE len > 0 DO
+			tW := 0;
+			IF e # NIL THEN
+				fLen := MIN(len, (LEN(ss) - 1) DIV maxShortCharsPerChar); n := fLen;
+				REPEAT
+					e.Encode(s, fR, fLen, ss, tW);
+					IF fLen # 0 THEN
+						ss[tW] := '?'; INC(tW);
+						INC(fR); DEC(fLen)
+					END
+				UNTIL fLen = 0
+			ELSE
+				fLen := MIN(len, LEN(ss) - 1); n := fLen;
+				WHILE fLen > 0 DO
+					ss[tW] := SHORT(s[fR]);
+					INC(tW);
+					INC(fR); DEC(fLen)
+				END
+			END;
+			ss[tW] := 0X;
+			res := Libc.printf(ss);
+			res := Libc.fflush(Libc.NULL);
+
+			len := len - n
+		END
 	END Printf;
 
-	PROCEDURE (cons: LinCons) WriteChar (c: CHAR);
+	PROCEDURE (cons: Cons) WriteChar (c: CHAR);
+		VAR s: ARRAY 1 OF CHAR;
 	BEGIN
 		s[0] := c;
-		s[1] := 0X;
-		ss := SHORT(s);
-		Printf()
+		Printf(s, 1)
 	END WriteChar;
 
-	PROCEDURE (cons: LinCons) WriteStr (IN text: ARRAY OF CHAR);
+	PROCEDURE (cons: Cons) WriteStr (IN text: ARRAY OF CHAR);
 	BEGIN
-		ss := SHORT(text);
-		Printf()
+		Printf(text, LEN(text$))
 	END WriteStr;
 
-	PROCEDURE (cons: LinCons) WriteLn;
+	PROCEDURE (cons: Cons) WriteLn;
 	BEGIN
-		ss[0] := 0AX;
-		ss[1] := 0X;
-		Printf()
+		Printf(0AX, 1)
 	END WriteLn;
 
-	PROCEDURE (cons: LinCons) Open;
-	BEGIN
-	END Open;
-
-	PROCEDURE (cons: LinCons) Close;
-	BEGIN
-	END Close;
-
-	PROCEDURE (cons: LinCons) CreateProcess (cmdLine: ARRAY OF CHAR): Console.Process;
-	BEGIN
-		(*	needs coding	*)
-		RETURN NIL
-	END CreateProcess;
-
-	PROCEDURE (cons: LinCons) CommandLine (OUT cmdLine: ARRAY OF CHAR);
-	BEGIN
-
-	END CommandLine;
-
-	PROCEDURE (p: LinProcess) Terminate;
-	BEGIN
-		(*	needs coding	*)
-	END Terminate;
-
-	PROCEDURE Maintainer;
-	BEGIN
-		version := 303;
-		maintainer := "A.Thomas"
-	END Maintainer;
-
 	PROCEDURE Init;
+		VAR enc: Codecs.Encoding;
 	BEGIN
-		Maintainer;
-		NEW(linCons);
-		Console.SetConsole(linCons)
+		IF Codecs.dir # NIL THEN
+			GetEnc(enc);
+			e := Codecs.dir.NewEncoder(enc);
+			d := Codecs.dir.NewDecoder(enc)
+		END;
+
+		NEW(cons);
+		Console.SetConsole(cons)
 	END Init;
 
 BEGIN

BIN
BlackBox/Linux/libBB0.so


BIN
BlackBox/OpenBSD/Host/Mod/Console.odc


+ 125 - 76
BlackBox/OpenBSD/Host/Mod/Console.txt

@@ -3,109 +3,158 @@ MODULE HostConsole;
 	(* THIS IS TEXT COPY OF Console.odc *)
 	(* DO NOT EDIT *)
 
-	IMPORT
-		SYSTEM,
-		Console,
-		LinLibc;
+	(*
+		A. V. Shiryaev, 2012.10
 
-	TYPE
-		LinCons = POINTER TO RECORD (Console.Console) END;
+		Console implementation for OpenBSD
+	*)
 
-		LinProcess = POINTER TO RECORD (Console.Process) END;
+	IMPORT SYSTEM, Console, Libc := LinLibc, Codecs := EncCodecs;
 
 	CONST
-		strLen = 1024;
+		defEnc = "ASCII";
+		defCh = '?';
+
+	TYPE
+		Cons = POINTER TO RECORD (Console.Console) END;
 
 	VAR
-		s: ARRAY strLen OF CHAR;
-		ss: ARRAY strLen OF SHORTCHAR;
-		linCons: LinCons;
-		version-: INTEGER;
-		maintainer-: ARRAY 40 OF CHAR;
+		cons: Cons;
+		e: Codecs.Encoder;
+		d: Codecs.Decoder;
 
-	PROCEDURE (cons: LinCons) ReadLn (OUT text: ARRAY OF CHAR);
+	PROCEDURE GetEnc (OUT enc: Codecs.Encoding);
+		VAR lang: Libc.PtrSTR;
+			i, j: INTEGER;
+	BEGIN
+		lang := Libc.getenv("LANG");
+		IF lang # NIL THEN
+			IF lang$ = "C" THEN
+				enc := "ASCII"
+			ELSE
+				i := 0; WHILE (lang[i] # 0X) & (lang[i] # '.') DO INC(i) END;
+				IF lang[i] # 0X THEN
+					INC(i);
+					j := 0;
+					WHILE (j < LEN(enc) - 1) & (lang[i] # 0X) DO
+						enc[j] := lang[i];
+						INC(j);
+						INC(i)
+					END;
+					IF j < LEN(enc) - 1 THEN
+						enc[j] := 0X
+					ELSE
+						enc := defEnc
+					END
+				ELSE
+					enc := defEnc
+				END
+			END
+		ELSE
+			enc := defEnc
+		END
+	END GetEnc;
+
+	PROCEDURE (cons: Cons) ReadLn (OUT s: ARRAY OF CHAR);
+		CONST
+			maxLineLen = 1023; (* without null terminating shortchar *)
 		VAR
 			i: INTEGER;
-			str: POINTER TO ARRAY [untagged] OF SHORTCHAR; 
+			str: Libc.PtrSTR;
+			ss: ARRAY maxLineLen+1 OF SHORTCHAR;
+			fR, fLen, tW: INTEGER;
+			st: BOOLEAN;
 	BEGIN
-		str := LinLibc.fgets(ss, strLen, SYSTEM.ADR(LinLibc.__sF[0])); (* Shiryaev A. V.: OpenBSD *)
-		IF (str = NIL) THEN 
-			(* if end of file, then ss is not changed by fgets and NIL is returned. 
-			    We return an empty string here *)
-			text[0] := 0X;
-			RETURN
-		END;			
-		i := 0;
-		REPEAT
-			text[i] := ss[i];
-			INC(i)
-		UNTIL (ss[i] = 0X) OR (i = LEN(text) - 1);
-		text[i] := 0X 
+		ss[LEN(ss)-1] := 0X;
+		str := Libc.fgets(ss, LEN(ss), SYSTEM.ADR(Libc.__sF[0]) (* stdin *));
+		IF (str # NIL) & (ss[LEN(ss)-1] = 0X) THEN
+			fLen := LEN(ss$);
+			IF fLen < LEN(s) THEN
+				IF d # NIL THEN
+					d.Reset;
+					fR := 0; tW := 0;
+					d.Decode(ss, fR, fLen, s, tW, st);
+					IF (fLen = 0) & ~st THEN
+						s[tW] := 0X
+					ELSE
+						s[0] := 0X
+					END
+				ELSE
+					s := ss$
+				END
+			ELSE
+				s[0] := 0X
+			END
+		ELSE
+			s[0] := 0X
+		END
 	END ReadLn;
 
-	PROCEDURE Printf;
-		VAR res: INTEGER;
+	PROCEDURE Printf (IN s: ARRAY OF CHAR; len: INTEGER);
+		CONST
+			maxShortCharsPerChar = 3; (* UTF-8 *)
+			ssLen = 128; (* >= maxShortCharsPerChar + 1 *)
+		VAR
+			ss: ARRAY ssLen OF SHORTCHAR;
+			res: INTEGER;
+			fR, fLen, tW, n: INTEGER;
 	BEGIN
-		res := LinLibc.printf(ss);
-		res := LinLibc.fflush(LinLibc.NULL)
+		fR := 0;
+		WHILE len > 0 DO
+			tW := 0;
+			IF e # NIL THEN
+				fLen := MIN(len, (LEN(ss) - 1) DIV maxShortCharsPerChar); n := fLen;
+				REPEAT
+					e.Encode(s, fR, fLen, ss, tW);
+					IF fLen # 0 THEN
+						ss[tW] := '?'; INC(tW);
+						INC(fR); DEC(fLen)
+					END
+				UNTIL fLen = 0
+			ELSE
+				fLen := MIN(len, LEN(ss) - 1); n := fLen;
+				WHILE fLen > 0 DO
+					ss[tW] := SHORT(s[fR]);
+					INC(tW);
+					INC(fR); DEC(fLen)
+				END
+			END;
+			ss[tW] := 0X;
+			res := Libc.printf(ss);
+			res := Libc.fflush(Libc.NULL);
+
+			len := len - n
+		END
 	END Printf;
 
-	PROCEDURE (cons: LinCons) WriteChar (c: CHAR);
+	PROCEDURE (cons: Cons) WriteChar (c: CHAR);
+		VAR s: ARRAY 1 OF CHAR;
 	BEGIN
 		s[0] := c;
-		s[1] := 0X;
-		ss := SHORT(s);
-		Printf()
+		Printf(s, 1)
 	END WriteChar;
 
-	PROCEDURE (cons: LinCons) WriteStr (IN text: ARRAY OF CHAR);
+	PROCEDURE (cons: Cons) WriteStr (IN text: ARRAY OF CHAR);
 	BEGIN
-		ss := SHORT(text);
-		Printf()
+		Printf(text, LEN(text$))
 	END WriteStr;
 
-	PROCEDURE (cons: LinCons) WriteLn;
+	PROCEDURE (cons: Cons) WriteLn;
 	BEGIN
-		ss[0] := 0AX;
-		ss[1] := 0X;
-		Printf()
+		Printf(0AX, 1)
 	END WriteLn;
 
-	PROCEDURE (cons: LinCons) Open;
-	BEGIN
-	END Open;
-
-	PROCEDURE (cons: LinCons) Close;
-	BEGIN
-	END Close;
-
-	PROCEDURE (cons: LinCons) CreateProcess (cmdLine: ARRAY OF CHAR): Console.Process;
-	BEGIN
-		(*	needs coding	*)
-		RETURN NIL
-	END CreateProcess;
-
-	PROCEDURE (cons: LinCons) CommandLine (OUT cmdLine: ARRAY OF CHAR);
-	BEGIN
-
-	END CommandLine;
-
-	PROCEDURE (p: LinProcess) Terminate;
-	BEGIN
-		(*	needs coding	*)
-	END Terminate;
-
-	PROCEDURE Maintainer;
-	BEGIN
-		version := 303;
-		maintainer := "A.Thomas"
-	END Maintainer;
-
 	PROCEDURE Init;
+		VAR enc: Codecs.Encoding;
 	BEGIN
-		Maintainer;
-		NEW(linCons);
-		Console.SetConsole(linCons)
+		IF Codecs.dir # NIL THEN
+			GetEnc(enc);
+			e := Codecs.dir.NewEncoder(enc);
+			d := Codecs.dir.NewDecoder(enc)
+		END;
+
+		NEW(cons);
+		Console.SetConsole(cons)
 	END Init;
 
 BEGIN

BIN
BlackBox/OpenBSD/libBB0.so


BIN
BlackBox/System/Mod/Console.odc


+ 20 - 65
BlackBox/System/Mod/Console.txt

@@ -1,35 +1,33 @@
 MODULE Console;
 
-	(* THIS IS TEXT COPY OF OpenBUGS System/Mod/Console.odc *)
+	(* THIS IS TEXT COPY OF Console.odc *)
 	(* DO NOT EDIT *)
 
+	(*
+		A. V. Shiryaev, 2012.10
+
+		Interface based on OpenBUGS Console
+	*)
+
 	TYPE
 		Console* = POINTER TO ABSTRACT RECORD END;
 
-		Process* = POINTER TO ABSTRACT RECORD END;
-
 	VAR
-		cons-, stdCon-: Console;
-		version-: INTEGER;
-		maintainer-: ARRAY 40 OF CHAR;
-
-	PROCEDURE (console: Console) WriteStr- (IN text: ARRAY OF CHAR), NEW, ABSTRACT;
-
-	PROCEDURE (console: Console) WriteChar- (c: CHAR), NEW, ABSTRACT;
-
-	PROCEDURE (console: Console) WriteLn-, NEW, ABSTRACT;
+		cons: Console;
 
-	PROCEDURE (console: Console) ReadLn- (OUT text: ARRAY OF CHAR), NEW, ABSTRACT;
+	(* Console *)
 
-	PROCEDURE (console: Console) Open-, NEW, ABSTRACT;
+	PROCEDURE (c: Console) WriteStr- (IN s: ARRAY OF CHAR), NEW, ABSTRACT;
+	PROCEDURE (c: Console) WriteChar- (ch: CHAR), NEW, ABSTRACT;
+	PROCEDURE (c: Console) WriteLn-, NEW, ABSTRACT;
 
-	PROCEDURE (console: Console) Close-, NEW, ABSTRACT;
+	(*
+		post:
+			s = "": end of input or input error
+			s # "": line with end of line postfix
+	*)
+	PROCEDURE (c: Console) ReadLn- (OUT s: ARRAY OF CHAR), NEW, ABSTRACT;
 
-	PROCEDURE (console: Console) CreateProcess- (cmdLine: ARRAY OF CHAR): Process, NEW, ABSTRACT;
-
-	PROCEDURE (console: Console) CommandLine- (OUT cmdLine: ARRAY OF CHAR), NEW, ABSTRACT;
-
-	PROCEDURE (p: Process) Terminate-, NEW, ABSTRACT;
 
 	PROCEDURE WriteStr* (IN text: ARRAY OF CHAR);
 	BEGIN
@@ -51,53 +49,10 @@ MODULE Console;
 		cons.ReadLn(text)
 	END ReadLn;
 
-	PROCEDURE Open*;
-	BEGIN
-		cons.Open
-	END Open;
-
-	PROCEDURE Close*;
-	BEGIN
-		cons.Close
-	END Close;
 
-	PROCEDURE CreateProcess* (cmdLine: ARRAY OF CHAR): Process;
-		VAR
-			p: Process;
+	PROCEDURE SetConsole* (c: Console);
 	BEGIN
-		p := cons.CreateProcess(cmdLine);
-		RETURN p
-	END CreateProcess;
-
-	PROCEDURE CommandLine* (OUT cmdLine: ARRAY OF CHAR);
-	BEGIN
-		cons.CommandLine(cmdLine)
-	END CommandLine;
-
-	PROCEDURE TerminateProcess* (p: Process);
-	BEGIN
-		p.Terminate
-	END TerminateProcess;
-
-	PROCEDURE SetConsole* (console: Console);
-	BEGIN
-		cons := console;
-		IF stdCon = NIL THEN stdCon := console END
+		cons := c
 	END SetConsole;
 
-	PROCEDURE Maintainer;
-	BEGIN
-		version := 310;
-		maintainer := "A.Thomas"
-	END Maintainer;
-
-	PROCEDURE Init;
-	BEGIN
-		Maintainer;
-		cons := NIL;
-		stdCon := NIL
-	END Init;
-
-BEGIN
-	Init
 END Console.

BIN
BlackBox/Windows/Host/Mod/Console.odc


+ 8 - 45
BlackBox/Windows/Host/Mod/Console.txt

@@ -1,18 +1,19 @@
 MODULE HostConsole;
 
-	(* THISIS TEXT COPY OF Console.odc *)
+	(* THIS IS TEXT COPY OF Console.odc *)
 	(* DO NOT EDIT *)
 
-	IMPORT
-		SYSTEM,
-		Console,
-		WinApi;
+	(*
+		A. V. Shiryaev, 2012.10
+
+		Console implementation for Windows
+	*)
+
+	IMPORT SYSTEM, Console, WinApi;
 
 	TYPE
 		Cons = POINTER TO RECORD (Console.Console) END;
 
-		Process = POINTER TO RECORD (Console.Process) END;
-
 	CONST
 		inBufLen = 128; (* > 0 *)
 
@@ -25,9 +26,6 @@ MODULE HostConsole;
 		inBuf: ARRAY [untagged] inBufLen OF SHORTCHAR;
 			inBufW, inBufR: INTEGER; (* 0 <= inBufR <= inBufW <= inBufLen *)
 
-		version-: INTEGER;
-		maintainer-: ARRAY 40 OF CHAR;
-
 	PROCEDURE (cons: Cons) ReadLn (OUT text: ARRAY OF CHAR);
 		VAR
 			W: INTEGER;
@@ -102,44 +100,9 @@ MODULE HostConsole;
 		Print(0DX + 0AX, 2)
 	END WriteLn;
 
-	PROCEDURE (cons: Cons) Open;
-		VAR res: WinApi.BOOL;
-	BEGIN
-		res := WinApi.AllocConsole()
-	END Open;
-
-	PROCEDURE (cons: Cons) Close;
-		VAR res: WinApi.BOOL;
-	BEGIN
-		res := WinApi.FreeConsole()
-	END Close;
-
-	PROCEDURE (cons: Cons) CreateProcess (cmdLine: ARRAY OF CHAR): Console.Process;
-	BEGIN
-		(*	needs coding	*)
-		RETURN NIL
-	END CreateProcess;
-
-	PROCEDURE (cons: Cons) CommandLine (OUT cmdLine: ARRAY OF CHAR);
-	BEGIN
-
-	END CommandLine;
-
-	PROCEDURE (p: Process) Terminate;
-	BEGIN
-		(*	needs coding	*)
-	END Terminate;
-
-	PROCEDURE Maintainer;
-	BEGIN
-		version := 303;
-		maintainer := "A.V.Shiryaev"
-	END Maintainer;
-
 	PROCEDURE Init;
 		VAR res: WinApi.BOOL;
 	BEGIN
-		Maintainer;
 		NEW(cons);
 
 		res := WinApi.AllocConsole(); (* Open console on module load time *)

+ 79 - 0
BlackBox/build

@@ -12,6 +12,7 @@ Dev0Compiler.Compile('System/Mod', 'Strings.txt')
 Dev0Compiler.Compile('System/Mod', 'Meta.txt')
 Dev0Compiler.Compile('System/Mod', 'Dialog.txt')
 
+Dev0Compiler.Compile('Enc/Mod', 'Codecs.txt')
 Dev0Compiler.Compile('Host/Mod', 'Files.txt')
 Dev0Compiler.Compile('Host/Mod', 'Console.txt')
 
@@ -101,6 +102,9 @@ Dev0Compiler.Compile('', 'HostWindows.txt')
 Dev0Compiler.Compile('Host/Mod', 'Dates.txt')
 Dev0Compiler.Compile('', 'HostTextConv.txt')
 
+Dev0Compiler.Compile('Enc/Mod', 'StdAliases.txt')
+Dev0Compiler.Compile('Enc/Mod', 'StdCodecs.txt')
+
 Dev0Compiler.Compile('Cons/Mod', 'Interp.txt')
 
 Dev0Compiler.Compile('', 'Init-Interp.txt')
@@ -117,3 +121,78 @@ DevCompiler.CompileThis XhtmlEntitySets XhtmlWriters XhtmlStdFileWriters XhtmlTe
 
 DevCompiler.CompileThis ObxHello0 ObxPi ObxRandom ObxTrap
 DATA
+
+# Enc
+./run-BlackBox <<DATA
+# DevCompiler.CompileThis EncCodecs
+# ConsCompiler.Compile('Enc/Mod', 'StdAliases.txt')
+# DevCompiler.CompileThis EncStdCodecs
+DevCompiler.CompileThis EncStdMap_ascii EncStdMap_utf_8
+
+ConsCompiler.Compile('Enc/Mod', 'StdMap_atarist.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_cp037.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_cp1026.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_cp1140.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_cp1250.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_cp1251.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_cp1252.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_cp1253.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_cp1254.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_cp1255.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_cp1256.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_cp1257.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_cp1258.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_cp424.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_cp437.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_cp500.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_cp720.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_cp737.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_cp775.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_cp850.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_cp852.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_cp855.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_cp856.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_cp857.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_cp858.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_cp860.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_cp861.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_cp862.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_cp863.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_cp864.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_cp865.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_cp866.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_cp869.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_cp874.txt')
+#ConsCompiler.Compile('Enc/Mod', 'StdMap_cp936.txt')
+#ConsCompiler.Compile('Enc/Mod', 'StdMap_cp949.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_georgian_academy.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_georgian_ps.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_hp_roman8.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_iso8859_1.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_iso8859_2.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_iso8859_3.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_iso8859_4.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_iso8859_5.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_iso8859_6.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_iso8859_7.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_iso8859_8.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_iso8859_9.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_iso8859_10.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_iso8859_11.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_iso8859_13.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_iso8859_14.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_iso8859_15.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_iso8859_16.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_koi8_r.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_koi8_u.txt')
+#ConsCompiler.Compile('Enc/Mod', 'StdMap_kps9566.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_kz1048.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_mac_centraleurope.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_mac_cyrillic.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_mac_greek.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_mac_iceland.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_mac_roman.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_mac_turkish.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_ptcp154.txt')
+ConsCompiler.Compile('Enc/Mod', 'StdMap_viscii.txt')
+DATA

+ 2 - 1
BlackBox/build-dev0

@@ -27,6 +27,7 @@ Dev0Compiler.Compile('Dev0/Mod', 'Compiler.txt')
 Dev0Compiler.Compile('Dev0/Mod', 'ElfLinker16.txt')
 Dev0Compiler.Compile('Dev0/Mod', 'Linker.txt')
 
+Dev0Compiler.Compile('Enc/Mod', 'Codecs.txt')
 Dev0Compiler.Compile('Host/Mod', 'Files.txt')
 Dev0Compiler.Compile('Host/Mod', 'Console.txt')
 
@@ -37,5 +38,5 @@ Dev0Compiler.Compile('Std/Mod', 'Interpreter.txt')
 
 Dev0Compiler.Compile('Dev0/Mod', 'Interp.txt')
 
-Dev0ElfLinker.LinkDll('libBB0.so := Kernel+ Console Math Strings HostConsole Files HostFiles Dev0CPM Dev0CPT Dev0CPS Dev0CPH Dev0CPB Dev0CPP Dev0CPE Dev0CPL486 Dev0CPC486 Dev0CPV486 Dev0Compiler Dev0ElfLinker Dev0Linker Dialog Meta Views StdInterpreter Dev0Interp')
+Dev0ElfLinker.LinkDll('libBB0.so := Kernel+ EncCodecs Console Math Strings HostConsole Files HostFiles Dev0CPM Dev0CPT Dev0CPS Dev0CPH Dev0CPB Dev0CPP Dev0CPE Dev0CPL486 Dev0CPC486 Dev0CPV486 Dev0Compiler Dev0ElfLinker Dev0Linker Dialog Meta Views StdInterpreter Dev0Interp')
 DATA

+ 7 - 8
README

@@ -34,7 +34,6 @@ Files:
 		OpenBUGS:
 			Dev/Mod/ElfLinker16.odc
 			Dev/Docu/ElfLinker.odc
-			System/Mod/Console.odc
 			Docu/OpenBUGS-License.odc
 		http://forum.oberoncore.ru/viewtopic.php?f=34&t=1159&sid=3e82517160caa46c64331178c1b61e95:
 			{Linux,OpenBSD}/Lin/Mod/Kernel_so_init.odc
@@ -72,13 +71,6 @@ Files:
 			OpenBUGS Lin/Mod/linHostFiles.odc:
 				Kernel.cmdLine support:
 					str := "" -> str := Kernel.cmdLine$
-		OpenBSD/Host/Mod/Console.odc:
-			OpenBUGS Lin/Mod/Console.odc:
-				stdin -> SYSTEM.ADR(__sF[0])
-		Linux/Host/Mod/Console.odc:
-			OpenBUGS Lin/Mod/Console.odc
-		Windows/Host/Mod/Console.odc:
-			OpenBUGS Lin/Mod/Console.odc ported to Windows
 		OpenBSD/Lin/Mod/Libc.txt:
 			OpenBUGS Lin/Mod/Libc.odc:
 				OpenBSD-specific
@@ -104,6 +96,13 @@ Files:
 			BlackBox 1.6-rc6 Host/Mod/TextConv.odc:
 				Windows-specific converters removed
 	new:
+		Console:
+			System/Mod/Console.odc: Console interface
+			Linux/Host/Mod/Console.odc: Console implementation for Linux
+			OpenBSD/Host/Mod/Console.odc:
+				Linux/Host/Mod/Console.odc: stdin -> SYSTEM.ADR(__sF[0]) (OpenBSD-specific)
+			Windows/Host/Mod/Console.odc:
+				Console implementation for Windows
 		Cons/Mod
 			Interp.odc: console interpreter
 			Compiler.odc: console interface to Dev compiler

+ 1 - 4
TODO

@@ -3,7 +3,7 @@ By priority:
 		BB_PRIMARY_DIR
 		BB_SECONDARY_DIR (instead of /USE)
 
-	cleanup Console
+	non-blocking Console
 
 	ConsCompiler:
 		interface similar to DevCompiler
@@ -18,9 +18,6 @@ By priority:
 		command line: do not use
 		env variables:
 			decode (encoding = current locale encoding)
-		HostConsole:
-			encode on printf, encoding = current locale encoding
-			decode on Read, encoding = current locale encoding
 		filenames:
 			HostFiles:
 				store encoded (ARRAY OF SHORTCHAR), encoding = currect locale encoding