Subversion Repositories Kolibri OS

Rev

Rev 6647 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
7597 akron1 1
(*
2
    Copyright 2016, 2018 Anton Krotov
6613 leency 3
 
4
    This program is free software: you can redistribute it and/or modify
5
    it under the terms of the GNU Lesser General Public License as published by
6
    the Free Software Foundation, either version 3 of the License, or
7
    (at your option) any later version.
8
 
9
    This program is distributed in the hope that it will be useful,
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
    GNU Lesser General Public License for more details.
13
 
14
    You should have received a copy of the GNU Lesser General Public License
15
    along with this program.  If not, see .
16
*)
17
 
18
MODULE Args;
19
 
20
IMPORT sys := SYSTEM, KOSAPI;
21
 
22
CONST
23
 
24
  MAX_PARAM = 1024;
25
 
26
VAR
27
 
28
  Params: ARRAY MAX_PARAM, 2 OF INTEGER;
29
  argc*: INTEGER;
30
 
31
PROCEDURE GetChar(adr: INTEGER): CHAR;
32
VAR res: CHAR;
33
BEGIN
34
  sys.GET(adr, res)
35
  RETURN res
36
END GetChar;
37
 
38
PROCEDURE ParamParse;
39
VAR p, count, name: INTEGER; c: CHAR; cond: INTEGER;
40
 
7597 akron1 41
  PROCEDURE ChangeCond(A, B, C: INTEGER; c: CHAR; VAR cond: INTEGER);
6613 leency 42
  BEGIN
43
    IF (c <= 20X) & (c # 0X) THEN
44
      cond := A
45
    ELSIF c = 22X THEN
46
      cond := B
47
    ELSIF c = 0X THEN
48
      cond := 6
49
    ELSE
50
      cond := C
51
    END
52
  END ChangeCond;
53
 
54
BEGIN
55
  p := KOSAPI.GetCommandLine();
56
  name := KOSAPI.GetName();
57
  Params[0, 0] := name;
58
  WHILE GetChar(name) # 0X DO
59
    INC(name)
60
  END;
61
  Params[0, 1] := name - 1;
62
  cond := 0;
63
  count := 1;
64
  WHILE (argc < MAX_PARAM) & (cond # 6) DO
65
    c := GetChar(p);
66
    CASE cond OF
7597 akron1 67
    |0: ChangeCond(0, 4, 1, c, cond); IF cond = 1 THEN Params[count, 0] := p END
68
    |1: ChangeCond(0, 3, 1, c, cond); IF cond IN {0, 6} THEN Params[count, 1] := p - 1; INC(count) END
69
    |3: ChangeCond(3, 1, 3, c, cond); IF cond = 6 THEN Params[count, 1] := p - 1; INC(count) END
70
    |4: ChangeCond(5, 0, 5, c, cond); IF cond = 5 THEN Params[count, 0] := p END
71
    |5: ChangeCond(5, 1, 5, c, cond); IF cond = 6 THEN Params[count, 1] := p - 1; INC(count) END
6613 leency 72
    ELSE
73
    END;
74
    INC(p)
75
  END;
76
  argc := count
77
END ParamParse;
78
 
79
PROCEDURE GetArg*(n: INTEGER; VAR s: ARRAY OF CHAR);
80
VAR i, j, len: INTEGER; c: CHAR;
81
BEGIN
82
  j := 0;
6647 akron1 83
  IF n < argc THEN
6613 leency 84
    len := LEN(s) - 1;
85
    i := Params[n, 0];
86
    WHILE (j < len) & (i <= Params[n, 1]) DO
87
      c := GetChar(i);
88
      IF c # 22X THEN
7597 akron1 89
        s[j] := c;
90
        INC(j)
6613 leency 91
      END;
92
      INC(i);
93
    END;
94
  END;
95
  s[j] := 0X
96
END GetArg;
97
 
98
BEGIN
99
  ParamParse
100
END Args.