diff --git a/arguments/unixstyle_oberon_traditional/makefile b/arguments/unixstyle_oberon_traditional/makefile new file mode 100644 index 0000000..e19e5ef --- /dev/null +++ b/arguments/unixstyle_oberon_traditional/makefile @@ -0,0 +1,11 @@ + +VOC = /opt/voc/bin/voc + + +all: + $(VOC) -m partest.Mod + + +test: + ./partest -str aaa -int 111 + ./partest -str 1 -int 111 diff --git a/arguments/unixstyle_oberon_traditional/partest.Mod b/arguments/unixstyle_oberon_traditional/partest.Mod new file mode 100644 index 0000000..b15b545 --- /dev/null +++ b/arguments/unixstyle_oberon_traditional/partest.Mod @@ -0,0 +1,63 @@ +MODULE partest; + +IMPORT Oberon, Texts; + +CONST + argStr0 = "str"; (* we only have two types of args, one string and one int *) + argInt0 = "int"; (* i. e. -str somestring -int somenumber *) + +VAR + W: Texts.Writer; (* for console output *) + S: Texts.Scanner; T: Texts.Text; +BEGIN + Texts.OpenWriter(W); + Texts.WriteString(W, "hello, world, let's see which arguments do we get"); Texts.WriteLn(W); + + (* open arguments scanner *) + Texts.OpenScanner(S, Oberon.Par.text, Oberon.Par.pos); + + WHILE ~S.eot DO + Texts.Scan(S); + + IF S.class = Texts.Char THEN (* do we get '-' sign ? *) + IF S.c = "-" THEN + Texts.Scan(S); + IF S.class = Texts.Name THEN (* we got the key *) + Texts.WriteString(W, "key: "); Texts.WriteString(W, S.s); Texts.WriteLn(W); + (* now get the value *) + IF S.s = argStr0 THEN + Texts.Scan(S); + IF S.class = Texts.Name THEN + Texts.WriteString(W, "value: "); Texts.WriteString (W, S.s); Texts.WriteLn(W); Texts.Append(Oberon.Log, W.buf); + ELSE + Texts.WriteString(W, "string expected"); Texts.WriteLn(W); + Texts.Append(Oberon.Log, W.buf); + HALT(1); + END; + ELSIF S.s = argInt0 THEN + Texts.Scan(S); + IF S.class = Texts.Int THEN + Texts.WriteString(W, "value: "); Texts.WriteInt (W, S.i, 0); Texts.WriteLn(W); Texts.Append(Oberon.Log, W.buf); + ELSE + Texts.WriteString(W, "integer expected"); Texts.WriteLn(W); + Texts.Append(Oberon.Log, W.buf); + HALT(1); + END; + END; + ELSE + (* we were expecting characters after the '-' sign *) + Texts.WriteString(W, "key name expected"); Texts. WriteLn(W); + Texts.Append(Oberon.Log, W.buf); + HALT(1); + END; + END + ELSE + Texts.WriteString(W, "key option must start with '-' sign "); Texts.WriteLn(W); + HALT(1); + END; (* if got '-' *) + Oberon.Par.pos := Texts.Pos(S); + Texts.Append(Oberon.Log, W.buf) + END; (* while *) + + +END partest. diff --git a/arguments/unixstyle_oberon_traditional/readme.md b/arguments/unixstyle_oberon_traditional/readme.md new file mode 100644 index 0000000..3365adf --- /dev/null +++ b/arguments/unixstyle_oberon_traditional/readme.md @@ -0,0 +1,47 @@ + +example shows how to implement unix style arguments parsing by using traditional oberon functions from modules Texts and Oberon. + +compile +======= + +``` +make +``` + +run +=== + +``` +make test +``` + +or type + +``` +./partest -str aaa -int 111 +``` + +that should produce the following output + +``` +hello, world, let's see which arguments do we get +key: str +value: aaa +key: int +value: 111 +``` + +``` +./partest -str 000 -int 111 +``` + +the output will be + +``` +hello, world, let's see which arguments do we get +key: str +string expected +Terminated by Halt(1). +``` + +that's all folks. diff --git a/enums_example/Days.Mod b/enums_example/Days.Mod new file mode 100644 index 0000000..8611a21 --- /dev/null +++ b/enums_example/Days.Mod @@ -0,0 +1,68 @@ +MODULE Days; + + TYPE + Day* = POINTER TO DayDesc; + DayDesc = RECORD + next, prev : Day + END; + Week = ARRAY 7 OF Day; + + VAR + sun*, mon*, tue*, wed*, thu*, fri*, sat* : Day; + week: Week; + + PROCEDURE Next*(d : Day): Day; + BEGIN + RETURN d.next + END Next; + + PROCEDURE Prev*(d: Day): Day; + BEGIN + RETURN d.prev; + END Prev; + + PROCEDURE inc(VAR j: SHORTINT); + BEGIN + IF j = 6 THEN + j := 0 + ELSE + INC(j) + END + END inc; + + PROCEDURE dec(VAR j: SHORTINT); + BEGIN + IF j = 0 THEN + j := 6 + ELSE + DEC(j) + END + END dec; + + PROCEDURE init(VAR w : Week); + VAR + i,j : SHORTINT; + BEGIN + i := 0; + REPEAT + j := i; inc(j); + w[i].next := w[j]; + j := i; dec(j); + w[i].prev := w[j]; + INC(i) + UNTIL i > 6; + END init; + +BEGIN + NEW(sun); NEW(mon); NEW(tue); NEW(wed); NEW(thu); NEW(fri); NEW(sat); + week[0] := sun; + week[1] := mon; + week[2] := tue; + week[3] := wed; + week[4] := thu; + week[5] := fri; + week[6] := sat; + + init(week); + +END Days. diff --git a/enums_example/readme.md b/enums_example/readme.md new file mode 100644 index 0000000..5459059 --- /dev/null +++ b/enums_example/readme.md @@ -0,0 +1,6 @@ + + +Example aimed to show how to survive without enumerations in Oberon. + +This way is even cooler than enumerations. (: + diff --git a/enums_example/test.Mod b/enums_example/test.Mod new file mode 100644 index 0000000..8d49b34 --- /dev/null +++ b/enums_example/test.Mod @@ -0,0 +1,22 @@ +MODULE test; + +IMPORT Days, Out; + +VAR today, yesterday, tomorrow: Days.Day; + +BEGIN + today := Days.mon; (*init*) + + yesterday := Days.Prev(today); + IF yesterday = Days.sun + THEN + Out.String("it works!"); Out.Ln + END; + tomorrow := Days.Next(today); + + IF tomorrow = Days.tue + THEN + Out.String("it works!"); Out.Ln + END; + +END test.