mirror of
https://github.com/vishapoberon/oberonbyexample.git
synced 2026-04-06 05:12:25 +00:00
post rebranding
This commit is contained in:
parent
4169aecd5b
commit
95b512baf4
66 changed files with 716 additions and 15 deletions
11
examples/arguments/unixstyle_oberon_traditional/makefile
Normal file
11
examples/arguments/unixstyle_oberon_traditional/makefile
Normal file
|
|
@ -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
|
||||
63
examples/arguments/unixstyle_oberon_traditional/partest.Mod
Normal file
63
examples/arguments/unixstyle_oberon_traditional/partest.Mod
Normal file
|
|
@ -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.
|
||||
|
|
@ -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.
|
||||
47
examples/arguments/unixstyle_oberon_traditional/readme.md
Normal file
47
examples/arguments/unixstyle_oberon_traditional/readme.md
Normal file
|
|
@ -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.
|
||||
Loading…
Add table
Add a link
Reference in a new issue