hodza/BlackBox.Shkola.2014 huggingface dataset:
Obx/Mod/Fern.odc

MODULE ObxFern;
(**
	project	= "BlackBox"
	organization	= "www.oberon.ch"
	contributors	= "Oberon microsystems"
	version	= "System/Rsrc/About"
	references	= "Martin Reiser, Niklaus Wirth, Programming In Oberon, ISBN 0201565439"
	changes	= "
	- YYYYMMDD, nn, ...
	"
	issues	= "
	- ...
	"

**)

	IMPORT ObxRandom, In, Out, XYplane;

	VAR
		a1, b1, c1, d1, e1, f1, p1: REAL;
		a2, b2, c2, d2, e2, f2, p2: REAL;
		a3, b3, c3, d3, e3, f3, p3: REAL;
		a4, b4, c4, d4, e4, f4, p4: REAL;
		X, Y: REAL;
		x0: INTEGER;
		y0: INTEGER;
		e: INTEGER;
		initialized: BOOLEAN;

	PROCEDURE Draw*;
		VAR x, y: REAL; xi, eta: INTEGER; rn: REAL;
	BEGIN
		IF initialized THEN
			REPEAT
				rn := ObxRandom.Uniform();
				IF rn < p1 THEN
					x := a1 * X + b1 * Y + e1; y := c1 * X + d1 * Y + f1
				ELSIF rn < (p1 + p2) THEN
					x := a2 *X + b2 * Y + e2; y := c2 * X + d2 * Y + f2
				ELSIF rn < (p1 + p2 + p3) THEN
					x := a3 * X + b3 * Y + e3; y := c3 * X + d3 * Y + f3
				ELSE
					x := a4 * X + b4 * Y + e4; y := c4 * X + d4 * Y + f4
				END;
				X := x; xi := x0 + SHORT(SHORT(ENTIER(X * e)));
				Y := y; eta := y0 + SHORT(SHORT(ENTIER(Y * e)));
				XYplane.Dot(xi, eta, XYplane.draw)
			UNTIL "s" = XYplane.ReadKey()
		END
	END Draw;

	PROCEDURE Init*;
	BEGIN
		X := 0; Y := 0;
		initialized := FALSE;
		In.Open;
		In.Int(x0); In.Int(y0); In.Int(e);
		In.Real(a1); In.Real(a2); In.Real(a3); In.Real(a4);
		In.Real(b1); In.Real(b2); In.Real(b3); In.Real(b4);
		In.Real(c1); In.Real(c2); In.Real(c3); In.Real(c4);
		In.Real(d1); In.Real(d2); In.Real(d3); In.Real(d4);
		In.Real(e1); In.Real(e2); In.Real(e3); In.Real(e4);
		In.Real(f1); In.Real(f2); In.Real(f3); In.Real(f4);
		In.Real(p1); In.Real(p2); In.Real(p3); In.Real(p4);
		IF In.Done THEN XYplane.Open; initialized := TRUE
		ELSE Out.String("Parameter error: select a list of 31 numbers"); Out.Ln
		END
	END Init;

BEGIN
	initialized := FALSE
END ObxFern.
Obx/Mod/FileTree.odc

MODULE ObxFileTree;
(**
	project	= "BlackBox"
	organization	= "www.oberon.ch"
	contributors	= "Oberon microsystems"
	version	= "System/Rsrc/About"
	copyright	= "System/Rsrc/About"
	license	= "Docu/BB-License"
	changes	= "
	- YYYYMMDD, nn, ...
	"
	issues	= "
	- ...
	"

**)

	IMPORT Files, Converters, Views, Dialog;
		
	TYPE
		Dlg* = RECORD
			path*, currentPath: Dialog.String;
			tree*: Dialog.Tree
		END;
	
	VAR 
		dlg*: Dlg;

	PROCEDURE BuildDirTree (loc: Files.Locator; parent: Dialog.TreeNode);
		VAR l: Files.LocInfo; f: Files.FileInfo; n: Dialog.TreeNode;
	BEGIN
		l := Files.dir.LocList(loc);
		WHILE l # NIL DO (* Recursively add directories *)
			n := dlg.tree.NewChild(parent, 0, l.name$); n.ViewAsFolder(TRUE);
			BuildDirTree(loc.This(l.name$), n);
			l := l.next
		END;
		f := Files.dir.FileList(loc);
		WHILE f # NIL DO n := dlg.tree.NewChild(parent, 0, f.name$); f := f.next END
	END BuildDirTree;

	PROCEDURE ThisLocator (IN path: ARRAY OF CHAR): Files.Locator;
		VAR i, j: INTEGER; ch: CHAR; loc: Files.Locator; dir: Dialog.String;
	BEGIN
		loc := Files.dir.This(""); i := 0; ch := path[0];
		WHILE ch # 0X DO
			j := 0;
			WHILE (ch # 0X) & (ch # "/") DO dir[j] := ch; INC(j); INC(i); ch := path[i] END;
			dir[j] := 0X;
			loc := loc.This(dir);
			IF ch = "/" THEN INC(i); ch := path[i] END
		END;
		RETURN loc
	END ThisLocator;

	PROCEDURE Update*;
		VAR loc: Files.Locator; 
	BEGIN
		IF (dlg.path # "") & (dlg.path[LEN(dlg.path$) - 1] # "/") & (dlg.path[LEN(dlg.path$) - 1] # "\") THEN
			dlg.path := dlg.path + "/"
		END;
		dlg.currentPath := dlg.path$;
		dlg.tree.DeleteAll();
		loc := ThisLocator(dlg.path);
		IF loc # NIL THEN BuildDirTree(loc, NIL); Dialog.UpdateList(dlg.tree) END;
		Dialog.Update(dlg)
	END Update;

	PROCEDURE Open*;
		VAR n: Dialog.TreeNode; name, path, p: Dialog.String;
			loc: Files.Locator; fname: Files.Name; conv: Converters.Converter; v: Views.View;
	BEGIN
		n := dlg.tree.Selected();
		IF n # NIL THEN
			IF ~n.IsFolder() THEN (* a leaf node is selected *)
				n.GetName(name);
				n := dlg.tree.Parent(n); path := "";
				WHILE n # NIL DO n.GetName(p); path := p + "/" + path; n := dlg.tree.Parent(n) END;
				loc := ThisLocator(dlg.currentPath + path);
				IF loc # NIL THEN
					conv := NIL; fname := name$;
					v := Views.Old(Views.dontAsk, loc, fname, conv);
					IF v # NIL THEN Views.Open(v, loc, fname, conv) END
				ELSE Dialog.ShowStatus("file not found")
				END
			ELSIF ~n.IsExpanded() THEN n.SetExpansion(TRUE); Dialog.UpdateList(dlg.tree)
			END
		ELSE Dialog.ShowStatus("no selection")
		END
	END Open;

	PROCEDURE OpenGuard* (VAR par: Dialog.Par);
		VAR n: Dialog.TreeNode;
	BEGIN
		n := dlg.tree.Selected();
		par.disabled := (n = NIL) OR (n.IsFolder() & n.IsExpanded());
		IF (n # NIL) & ~n.IsFolder() THEN par.label := "&Open File" ELSE par.label := "&Open Folder" END
	END OpenGuard;

END ObxFileTree.
Obx/Mod/Hello0.odc

MODULE ObxHello0;
(**
	project	= "BlackBox"
	organization	= "www.oberon.ch"
	contributors	= "Oberon microsystems"
	version	= "System/Rsrc/About"
	copyright	= "System/Rsrc/About"
	license	= "Docu/BB-License"
	changes	= "
	- YYYYMMDD, nn, ...
	"
	issues	= "
	- ...
	"

**)

	IMPORT StdLog;

	PROCEDURE Do*;
	BEGIN
		StdLog.String("Hello World"); StdLog.Ln	(* write string and 0DX into log *)
	END Do;

END ObxHello0.
Obx/Mod/Hello1.odc

MODULE ObxHello1;
(**
	project	= "BlackBox"
	organization	= "www.oberon.ch"
	contributors	= "Oberon microsystems"
	version	= "System/Rsrc/About"
	copyright	= "System/Rsrc/About"
	license	= "Docu/BB-License"
	changes	= "
	- YYYYMMDD, nn, ...
	"
	issues	= "
	- ...
	"

**)

	IMPORT Views, TextModels, TextMappers, TextViews;

	PROCEDURE Do*;
		VAR t: TextModels.Model; f: TextMappers.Formatter; v: TextViews.View;
	BEGIN
		t := TextModels.dir.New();	(* create a new, empty text object *)
		f.ConnectTo(t);	(* connect a formatter to the text *)
		f.WriteString("Hello World"); f.WriteLn;	(* write a string and a 0DX into new text *) 
		v := TextViews.dir.New(t);	(* create a new text view for t *)
		Views.OpenView(v)	(* open the view in a window *)
	END Do;

END ObxHello1.
Obx/Mod/LabelLister.odc

MODULE ObxLabelLister;
(**
	project	= "BlackBox"
	organization	= "www.oberon.ch"
	contributors	= "Oberon microsystems"
	version	= "System/Rsrc/About"
	copyright	= "System/Rsrc/About"
	license	= "Docu/BB-License"
	changes	= "
	- YYYYMMDD, nn, ...
	"
	issues	= "
	- ...
	"

**)

	IMPORT Views, Controls, FormModels, FormControllers, StdLog;

	PROCEDURE List*;
		VAR c: FormControllers.Controller; rd: FormModels.Reader; v: Views.View;
	BEGIN
		c := FormControllers.Focus();
		IF c # NIL THEN
			rd := c.form.NewReader(NIL);
			rd.ReadView(v);
			WHILE v # NIL DO
				IF v IS Controls.Control THEN
					StdLog.String(v(Controls.Control).label); StdLog.Ln
				END;
				rd.ReadView(v)
			END
		END
	END List;

END ObxLabelLister.
Obx/Mod/Lookup0.odc

MODULE ObxLookup0;
(**
	project	= "BlackBox"
	organization	= "www.oberon.ch"
	contributors	= "Oberon microsystems"
	version	= "System/Rsrc/About"
	copyright	= "System/Rsrc/About"
	license	= "Docu/BB-License"
	changes	= "
	- YYYYMMDD, nn, ...
	"
	issues	= "
	- ...
	"

**)

	IMPORT TextModels, TextMappers, TextControllers, ObxPhoneDB;

	PROCEDURE Do*;
	(** use TextCmds.SelectionGuard as guard command **)
		VAR c: TextControllers.Controller; buf: TextModels.Model; from, to: INTEGER;
			s: TextMappers.Scanner; f: TextMappers.Formatter; number: ObxPhoneDB.String;
	BEGIN
		c := TextControllers.Focus();
		IF (c # NIL) & c.HasSelection() THEN
			c.GetSelection(from, to);
			s.ConnectTo(c.text);
			s.SetPos(from);
			s.Scan;
			IF s.type = TextMappers.string THEN
				buf := TextModels.CloneOf(c.text);
				f.ConnectTo(buf);
				ObxPhoneDB.LookupByName(s.string$, number);
				f.WriteString(number);
				from := s.start; to := s.Pos() - 1;	(* scanner has already read on character beyond string! *)
				c.text.Delete(from, to);							(* delete name *)
				c.text.Insert(from, buf, 0, buf.Length());	(* move phone number from buffer into text *)
				c.SetSelection(from, from + LEN(number$))	(* select the phone number *)
			END
		END
	END Do;

END ObxLookup0.
Obx/Mod/Lookup1.odc

MODULE ObxLookup1;
(**
	project	= "BlackBox"
	organization	= "www.oberon.ch"
	contributors	= "Oberon microsystems"
	version	= "System/Rsrc/About"
	copyright	= "System/Rsrc/About"
	license	= "Docu/BB-License"
	changes	= "
	- YYYYMMDD, nn, ...
	"
	issues	= "
	- ...
	"

**)

	IMPORT Stores, Models, TextModels, TextMappers, TextControllers, ObxPhoneDB;

	PROCEDURE Do*;
	(** use TextCmds.SelectionGuard as guard command **)
		VAR c: TextControllers.Controller; buf: TextModels.Model; from, to: INTEGER;
			s: TextMappers.Scanner; f: TextMappers.Formatter; number: ObxPhoneDB.String;
			script: Stores.Operation;
	BEGIN
		c := TextControllers.Focus();
		IF (c # NIL) & c.HasSelection() THEN
			c.GetSelection(from, to);
			s.ConnectTo(c.text);
			s.SetPos(from);
			s.Scan;
			IF s.type = TextMappers.string THEN
				buf := TextModels.CloneOf(c.text);
				f.ConnectTo(buf);
				ObxPhoneDB.LookupByName(s.string$, number);
				f.WriteString(number);
				from := s.start; to := s.Pos() - 1;	(* scanner has already read on character beyond string! *)
				Models.BeginScript(c.text, "#Obx:Lookup", script);
				c.text.Delete(from, to);							(* delete name *)
				c.text.Insert(from, buf, 0, buf.Length());	(* move phone number from buffer into text *)
				Models.EndScript(c.text, script);
				c.SetSelection(from, from + LEN(number$))	(* select the phone number *)
			END
		END
	END Do;

END ObxLookup1.
Obx/Mod/Open0.odc

MODULE ObxOpen0;
(**
	project	= "BlackBox"
	organization	= "www.oberon.ch"
	contributors	= "Oberon microsystems"
	version	= "System/Rsrc/About"
	copyright	= "System/Rsrc/About"
	license	= "Docu/BB-License"
	changes	= "
	- YYYYMMDD, nn, ...
	"
	issues	= "
	- ...
	"

**)

	IMPORT Files, Converters, Views, TextModels, TextMappers, TextViews;

	PROCEDURE Do*;
		VAR loc: Files.Locator; name: Files.Name; conv: Converters.Converter;
			v: Views.View; t: TextModels.Model; f: TextMappers.Formatter;
	BEGIN
		loc := NIL; name := ""; conv := NIL;	(* no defaults for Views.Old *)
		v := Views.Old(Views.ask, loc, name, conv);	(* ask user for a file and open it as a view *)
		IF (v # NIL) & (v IS TextViews.View) THEN		(* make sure it is a text view *)
			t := v(TextViews.View).ThisModel();	(* get the text view's model  *)
			f.ConnectTo(t);
			f.SetPos(t.Length());	(* set the formatter to the end of the text *)
			f.WriteString("appendix");	(* append a string *)
			Views.OpenView(v)	(* open the text view in a window *)
		END
	END Do;

END ObxOpen0.
Obx/Mod/Open1.odc

MODULE ObxOpen1;
(**
	project	= "BlackBox"
	organization	= "www.oberon.ch"
	contributors	= "Oberon microsystems"
	version	= "System/Rsrc/About"
	copyright	= "System/Rsrc/About"
	license	= "Docu/BB-License"
	changes	= "
	- YYYYMMDD, nn, ...
	"
	issues	= "
	- ...
	"

**)

	IMPORT Converters, Files, Views, TextModels, TextMappers, TextViews;

	PROCEDURE Do*;
		VAR loc: Files.Locator; name: Files.Name; conv: Converters.Converter;
			v: Views.View; t: TextModels.Model; f: TextMappers.Formatter;
			res: INTEGER;
	BEGIN
		loc := NIL; name := ""; conv := NIL;
		v := Views.Old(Views.ask, loc, name, conv);
		IF (v # NIL) & (v IS TextViews.View) THEN
			t := v(TextViews.View).ThisModel();
			f.ConnectTo(t);
			f.SetPos(t.Length());
			f.WriteString("appendix");
			Views.Register(v, Views.ask, loc, name, conv, res)	(* ask the user where to save the document *)
		END
	END Do;

END ObxOpen1.
Obx/Mod/ParCmd.odc

MODULE ObxParCmd;
(**
	project	= "BlackBox"
	organization	= "www.oberon.ch"
	contributors	= "Oberon microsystems"
	version	= "System/Rsrc/About"
	copyright	= "System/Rsrc/About"
	license	= "Docu/BB-License"
	changes	= "
	- YYYYMMDD, nn, ...
	"
	issues	= "
	- ...
	"

**)

	IMPORT Dialog, Models, Controls, TextModels, TextMappers, StdLog;

	PROCEDURE Connect (VAR s: TextMappers.Scanner; OUT done: BOOLEAN);
		VAR c: Models.Context;
	BEGIN
		done := FALSE;
		IF Controls.par # NIL THEN
			c := Controls.par.context;	(* the context of an open view is never NIL *)
			WITH c: TextModels.Context DO
				s.ConnectTo(c.ThisModel()); s.SetPos(c.Pos() + 1); s.Scan;
				done := TRUE
			ELSE
			END
		END
	END Connect;

	PROCEDURE Do0*;
		VAR s: TextMappers.Scanner; done: BOOLEAN;
	BEGIN
		Connect(s, done);
		IF done THEN
			IF s.type = TextMappers.string THEN
				StdLog.String(s.string); StdLog.Ln	(* write string after button to log *)
			END
		END
	END Do0;

	PROCEDURE Do1*;
		VAR s: TextMappers.Scanner; done: BOOLEAN; res: INTEGER;
	BEGIN
		Connect(s, done);
		IF done THEN
			IF s.type = TextMappers.string THEN
				Dialog.Call(s.string, " ", res)	(* execute string after button as a command sequence *)
			END
		END
	END Do1;

END ObxParCmd.
Obx/Mod/Patterns.odc

MODULE ObxPatterns;
(**
	project	= "BlackBox"
	organization	= "www.oberon.ch"
	contributors	= "Oberon microsystems"
	version	= "System/Rsrc/About"
	copyright	= "System/Rsrc/About"
	license	= "Docu/BB-License"
	changes	= "
	- YYYYMMDD, nn, ...
	"
	issues	= "
	- ...
	"

**)

	IMPORT Ports, Stores, Views, Properties;

	CONST minVersion = 0; maxVersion = 0;

	TYPE View = POINTER TO RECORD (Views.View) END;

	PROCEDURE (v: View) Internalize (VAR rd: Stores.Reader);
		VAR version: INTEGER;
	BEGIN
		rd.ReadVersion(minVersion, maxVersion, version)
	END Internalize;

	PROCEDURE (v: View) Externalize (VAR wr: Stores.Writer);
	BEGIN
		wr.WriteVersion(maxVersion)
	END Externalize;

	PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER);
		VAR w, h, d: INTEGER; col: INTEGER; colors: ARRAY 3 OF Ports.Color;
	BEGIN
		colors[0] := Ports.red; colors[1] := Ports.green; colors[2] := Ports.blue;
		v.context.GetSize(w, h);
		d := 4 * f.dot; col := 0;
		l := 0; t := 0; r := w; b := h;
		WHILE (r> l) & (b > t) DO
			f.DrawRect(l, t, r, b, f.dot, colors[col]);
			INC(l, d); INC(t, d); DEC(r, d); DEC(b, d); col := (col + 1) MOD 3
		END
	END Restore;

	PROCEDURE (v: View) HandlePropMsg (VAR p: Properties.Message);
		CONST min = 10 * Ports.mm; max = 160 * Ports.mm; pref = 90 * Ports.mm;
	BEGIN
		WITH p: Properties.SizePref DO	(* prevent illegal sizes *)
			IF p.w = Views.undefined THEN	(* no preference for width -> skip *)
			ELSIF p.w < min THEN p.w := min
			ELSIF p.w > max THEN p.w := max
			END;
			IF p.h = Views.undefined THEN p.h := pref
			ELSIF p.h < min THEN p.h := min
			ELSIF p.h > max THEN p.h := max
			END
		ELSE
		END
	END HandlePropMsg;

	PROCEDURE Deposit*;
		VAR v: View;
	BEGIN
		NEW(v); Views.Deposit(v)
	END Deposit;

END ObxPatterns.
Obx/Mod/PDBRep0.odc

MODULE ObxPDBRep0;
(**
	project	= "BlackBox"
	organization	= "www.oberon.ch"
	contributors	= "Oberon microsystems"
	version	= "System/Rsrc/About"
	copyright	= "System/Rsrc/About"
	license	= "Docu/BB-License"
	changes	= "
	- YYYYMMDD, nn, ...
	"
	issues	= "
	- ...
	"

**)

	IMPORT Views, TextModels, TextMappers, TextViews, ObxPhoneDB;

	PROCEDURE GenReport*;
		VAR t: TextModels.Model; f: TextMappers.Formatter; v: TextViews.View;
			i: INTEGER; name, number: ObxPhoneDB.String;
	BEGIN
		t := TextModels.dir.New();	(* create empty text carrier *)
		f.ConnectTo(t);					(* connect a formatter to the text *)
		i := 0;
		ObxPhoneDB.LookupByIndex(i, name, number);
		WHILE name # "" DO
			f.WriteString(name);		(* first string *)
			f.WriteTab;					(* tab character *)
			f.WriteString(number);	(* second string *)
			f.WriteLn;						(* carriage return *)
			INC(i);
			ObxPhoneDB.LookupByIndex(i, name, number)
		END;
		v := TextViews.dir.New(t);	(* create a text view for the text generated above *)
		Views.OpenView(v)			(* open the text view in its own window *)
	END GenReport;

END ObxPDBRep0.
Obx/Mod/PDBRep1.odc

MODULE ObxPDBRep1;
(**
	project	= "BlackBox"
	organization	= "www.oberon.ch"
	contributors	= "Oberon microsystems"
	version	= "System/Rsrc/About"
	copyright	= "System/Rsrc/About"
	license	= "Docu/BB-License"
	changes	= "
	- YYYYMMDD, nn, ...
	"
	issues	= "
	- ...
	"

**)

	IMPORT Ports, Views, TextModels, TextMappers, TextViews, ObxPhoneDB;

	PROCEDURE GenReport*;
		VAR t: TextModels.Model; f: TextMappers.Formatter; v: TextViews.View;
			i: INTEGER; name, number: ObxPhoneDB.String;
			default, green: TextModels.Attributes;
	BEGIN
		t := TextModels.dir.New();	(* create empty text carrier *)
		f.ConnectTo(t);					(* connect a formatter to the text *)
		default := f.rider.attr;	(* save old text attributes for later use *)
		green := TextModels.NewColor(default, Ports.green);	(* use green color *)
		i := 0;
		ObxPhoneDB.LookupByIndex(i, name, number);
		WHILE name # "" DO
			f.rider.SetAttr(green);	(* change current attributes of formatter's rider *)
			f.WriteString(name);		(* first string *)
			f.rider.SetAttr(default);	(* change current attributes of formatter's rider *)
			f.WriteTab;					(* tab character *)
			f.WriteString(number);	(* second string *)
			f.WriteLn;						(* carriage return *)
			INC(i);
			ObxPhoneDB.LookupByIndex(i, name, number)
		END;
		v := TextViews.dir.New(t);	(* create a text view for the text generated above *)
		Views.OpenView(v)			(* open the text view in its own window *)
	END GenReport;

END ObxPDBRep1.
Obx/Mod/PDBRep2.odc

MODULE ObxPDBRep2;
(**
	project	= "BlackBox"
	organization	= "www.oberon.ch"
	contributors	= "Oberon microsystems"
	version	= "System/Rsrc/About"
	copyright	= "System/Rsrc/About"
	license	= "Docu/BB-License"
	changes	= "
	- YYYYMMDD, nn, ...
	"
	issues	= "
	- ...
	"

**)

	IMPORT Ports, Views, TextModels, TextMappers, TextViews, TextRulers, ObxPhoneDB;

	PROCEDURE WriteRuler (VAR f:TextMappers.Formatter);
		CONST cm = 10 * Ports.mm;	(* universal units *)
		VAR ruler: TextRulers.Ruler;
	BEGIN
		ruler := TextRulers.dir.New(NIL);
		TextRulers.AddTab(ruler, 4 * cm);	(* define a tab stop, 4 cm from the left margin *)
		TextRulers.SetRight(ruler, 12 * cm);	(* set right margin *)
		f.WriteView(ruler)							(* a ruler is a view, thus can be written to the text *)
	END WriteRuler;

	PROCEDURE GenReport*;
		VAR t: TextModels.Model; f: TextMappers.Formatter; v: TextViews.View;
			i: INTEGER; name, number: ObxPhoneDB.String;
	BEGIN
		t := TextModels.dir.New();	(* create empty text carrier *)
		f.ConnectTo(t);					(* connect a formatter to the text *)
		WriteRuler(f);
		i := 0;
		ObxPhoneDB.LookupByIndex(i, name, number);
		WHILE name # "" DO
			f.WriteString(name);		(* first string *)
			f.WriteTab;					(* tab character *)
			f.WriteString(number);	(* second string *)
			f.WriteLn;						(* carriage return *)
			INC(i);
			ObxPhoneDB.LookupByIndex(i, name, number)
		END;
		v := TextViews.dir.New(t);	(* create a text view for the text generated above *)
		Views.OpenView(v)			(* open the text view in its own window *)
	END GenReport;

END ObxPDBRep2.
Obx/Mod/PDBRep3.odc

MODULE ObxPDBRep3;
(**
	project	= "BlackBox"
	organization	= "www.oberon.ch"
	contributors	= "Oberon microsystems"
	version	= "System/Rsrc/About"
	copyright	= "System/Rsrc/About"
	license	= "Docu/BB-License"
	changes	= "
	- YYYYMMDD, nn, ...
	"
	issues	= "
	- ...
	"

**)

	IMPORT Views, TextModels, TextMappers, TextViews, StdFolds, ObxPhoneDB;					

	PROCEDURE WriteOpenFold (VAR f: TextMappers.Formatter;
															IN shortForm: ARRAY OF CHAR);
		VAR fold: StdFolds.Fold; t: TextModels.Model;
	BEGIN
		t := TextModels.dir.NewFromString(shortForm);	(* convert a string into a text model *)
		fold := StdFolds.dir.New(StdFolds.expanded, "", t);
		f.WriteView(fold)
	END WriteOpenFold;

	PROCEDURE WriteCloseFold (VAR f: TextMappers.Formatter);
		VAR fold: StdFolds.Fold; len: INTEGER;
	BEGIN
		fold := StdFolds.dir.New(StdFolds.expanded, "", NIL);
		f.WriteView(fold);
		fold.Flip;	(* swap long-form text, now between the two fold views, with hidden short-form text *)
		len := f.rider.Base().Length();	(* determine the text carrier's new length *)
		f.SetPos(len)	(* position the formatter to the end of the text *)
	END WriteCloseFold;

	PROCEDURE GenReport*;
		VAR t: TextModels.Model; f: TextMappers.Formatter; v: TextViews.View;
			i: INTEGER; name, number: ObxPhoneDB.String;
	BEGIN
		t := TextModels.dir.New();	(* create empty text carrier *)
		f.ConnectTo(t);					(* connect a formatter to the text *)
		i := 0;
		ObxPhoneDB.LookupByIndex(i, name, number);
		WHILE name # "" DO
			WriteOpenFold(f, name$);	(* write left fold view into text, with name as its short-form text *)
			(* now write the long-form text *)
			f.WriteString(name);		(* first string *)
			f.WriteTab;					(* tab character *)
			f.WriteString(number);	(* second string *)
			WriteCloseFold(f);			(* write closing fold, and swap short- and long-form texts *)
			f.WriteLn;						(* carriage return *)
			INC(i);
			ObxPhoneDB.LookupByIndex(i, name, number)
		END;
		v := TextViews.dir.New(t);	(* create a text view for the text generated above *)
		Views.OpenView(v)			(* open the text view in its own window *)
	END GenReport;

END ObxPDBRep3.
Obx/Mod/PDBRep4.odc

MODULE ObxPDBRep4;
(**
	project	= "BlackBox"
	organization	= "www.oberon.ch"
	contributors	= "Oberon microsystems"
	version	= "System/Rsrc/About"
	copyright	= "System/Rsrc/About"
	license	= "Docu/BB-License"
	changes	= "
	- YYYYMMDD, nn, ...
	"
	issues	= "
	- ...
	"

**)

	IMPORT Views, TextModels, TextMappers, TextViews, StdLinks, StdLog, ObxPhoneDB;

	CONST cmdStart = "ObxPDBRep4.Log('"; cmdEnd = "')";

	PROCEDURE GenReport*;
		VAR t: TextModels.Model; f: TextMappers.Formatter; v: TextViews.View;
			i: INTEGER; name, number: ObxPhoneDB.String; link: StdLinks.Link;
			cmd: ARRAY 128 OF CHAR;
	BEGIN
		t := TextModels.dir.New();	(* create empty text carrier *)
		f.ConnectTo(t);					(* connect a formatter to the text *)
		i := 0;
		ObxPhoneDB.LookupByIndex(i, name, number);
		WHILE name # "" DO
			cmd := cmdStart + name + "    " + number + cmdEnd;
			link := StdLinks.dir.NewLink(cmd);
			f.WriteView(link);
			f.WriteString(name);		(* the string shown between the pair of link views *)
			link := StdLinks.dir.NewLink("");
			f.WriteView(link);
			f.WriteLn;						(* carriage return *)
			INC(i);
			ObxPhoneDB.LookupByIndex(i, name, number)
		END;
		v := TextViews.dir.New(t);	(* create a text view for the text generated above *)
		Views.OpenView(v)			(* open the text view in its own window *)
	END GenReport;

	PROCEDURE Log* (param: ARRAY OF CHAR);
	BEGIN
		StdLog.String(param); StdLog.Ln
	END Log;

END ObxPDBRep4.
Obx/Mod/PhoneDB.odc

MODULE ObxPhoneDB;
(**
	project	= "BlackBox"
	organization	= "www.oberon.ch"
	contributors	= "Oberon microsystems"
	version	= "System/Rsrc/About"
	copyright	= "System/Rsrc/About"
	license	= "Docu/BB-License"
	changes	= "
	- YYYYMMDD, nn, ...
	"
	issues	= "
	- ...
	"

**)

	CONST
		maxLen = 32;	(* maximum length of name/number strings *)
		maxEntries = 5;	(* maximum number of entries in the database *)

	TYPE
		String* = ARRAY maxLen OF CHAR;

		Entry = RECORD
			name, number: String
		END;

	VAR db: ARRAY maxEntries OF Entry;

	PROCEDURE LookupByIndex* (index: INTEGER; OUT name, number: String);
	BEGIN	(* given an index, return the corresponding <name, number> pair *)
		ASSERT(index >= 0);
		IF index < maxEntries THEN
			name := db[index].name; number := db[index].number
		ELSE
			name := ""; number := ""
		END
	END LookupByIndex;

	PROCEDURE LookupByName* (name: String; OUT number: String);
		VAR i: INTEGER;
	BEGIN	(* given a name, find the corresponding phone number *)
		i := 0; WHILE (i # maxEntries) & (db[i].name # name) DO INC(i) END;
		IF i # maxEntries THEN	(* name found in db[i] *)
			number := db[i].number
		ELSE	(* name not found in db[0..maxEntries-1] *)
			number := ""
		END
	END LookupByName;

	PROCEDURE LookupByNumber* (number: String; OUT name: String);
		VAR i: INTEGER;
	BEGIN	(* given a phone number, find the corresponding name *)
		i := 0; WHILE (i # maxEntries) & (db[i].number # number) DO INC(i) END;
		IF i # maxEntries THEN	(* number found in db[i] *)
			name := db[i].name
		ELSE	(* number not found in db[0..maxEntries-1] *)
			name := ""
		END
	END LookupByNumber;

BEGIN	(* initialization of database contents *)
	db[0].name := "Daffy Duck"; db[0].number := "310-555-1212";
	db[1].name := "Wile E. Coyote"; db[1].number := "408-555-1212";
	db[2].name := "Scrooge McDuck"; db[2].number := "206-555-1212";
	db[3].name := "Huey Lewis"; db[3].number := "415-555-1212";
	db[4].name := "Thomas Dewey"; db[4].number := "617-555-1212"
END ObxPhoneDB.