summaryrefslogtreecommitdiff
path: root/system/base/unknown/src/command handler
blob: 3e06280996f00de956515ce0664ac6cbefc52399 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
 
PACKET command handler DEFINES                (* Autor: J.Liedtke *)
                                              (* Stand:  29.02.82 *)
       command handler ,
       do command ,
       command error ,
       set command :
 
 
LET esc          = ""27"" ,
    esc k        = ""27"k" ,
    cr lf        = ""4""13""10"" ,
    command pre  = ""4""13"      " ,
    command post =    ""13""10"      " ,
 
    tag type = 1 ,
    texttype = 4 ,
    eof type = 7 ;
 
 
TEXT VAR command line := "" ,
         previous command line := "" ,
         symbol ,
         procedure ,
         pattern ,
         error note := "" ;
 
INT VAR  symbol type ,
         allowed type := 0 ;
 
 
PROC set command (TEXT CONST command, INT CONST type) :

  param position (0) ;
  command line := command ;
  allowed type := type
 
ENDPROC set command ;
 
PROC do command :
 
  do (command line)

ENDPROC do command ;

 
PROC command handler ( TEXT CONST command list,
                       INT VAR command index, number of params,
                       TEXT VAR param 1, param 2,
                       TEXT CONST command text ) :
 
prepare and get command ;
command handler (command list,command index,number of params,param1,param2).
 
prepare and get command :
  set line nr (0) ;
  error protocoll ;
  get command from console .
 
error protocoll :
  IF is error
    THEN put error ;
         clear error
    ELSE command line := "" ;
  FI .
 
get command from console :
  INT VAR x, y;
  out (crlf) ;
  get cursor (x, y) ;
  cursor (x, y) ;
  REP
    out (command pre) ;
    out (command text) ;
    out (command post) ;
    editget command
  UNTIL command line <> "" PER ;
  param position (LENGTH command line) ;
  out (command post) .
 
editget command :
  feldaudit ("") ;
  feldlernmodus (FALSE) ;
  REP
    feldtabulator ("") ;
    feldseparator (esc) ;
    editget (command line) ;
    ignore halt errors during editget ;
    IF feldzeichen = esc k
      THEN command line := previous command line
      ELSE previous command line := command line ;
           LEAVE editget command
    FI
  PER .

ignore halt errors during editget :
  IF is error
    THEN clear error
  FI .

ENDPROC command handler ;
 
PROC command handler ( TEXT CONST command list,
                       INT VAR command index, number of params,
                       TEXT VAR param 1, param 2) :
 
  scan (command line) ;
  next symbol ;
  IF pos (command list, symbol) > 0
    THEN procedure name ;
         parameter list pack option ;
         nothing else in command line ;
         decode command
    ELSE impossible command
  FI .
 
procedure name :
  IF symbol type = tag type OR symbol = "?"
    THEN procedure := symbol ;
         next symbol
    ELSE error ("incorrect procedure name")
  FI .
 
parameter list pack option :
  number of params := 0 ;
  param 1 := "" ;
  param 2 := "" ;
  IF symbol = "("
    THEN next symbol ;
         parameter list ;
         IF symbol <> ")"
           THEN error (") expected")
         FI
  ELIF symbol type <> eof type
    THEN error ("( expected")
  FI .
 
parameter list :
  parameter (param 1, number of params) ;
  IF symbol = ","
    THEN next symbol ;
         parameter (param 2, number of params) ;
  FI ;
  IF symbol <> ")"
    THEN error (") expected")
  FI .
 
nothing else in command line :
  next symbol ;
  IF symbol <> ""
    THEN error ("command too complex")
  FI .

decode command :
  command index := index (command list, procedure, number of params) .
 
impossible command :
  command index := 0 .
 
ENDPROC command handler ;
 
PROC parameter (TEXT VAR param, INT VAR number of params) :
 
  IF symbol type = text type OR symbol type = allowed type
    THEN param := symbol ;
         number of params INCR 1 ;
         next symbol
    ELSE error ("parameter is no text denoter ("" missing!)")
  FI
 
ENDPROC parameter ;
 
INT PROC index (TEXT CONST list, procedure, INT CONST params) :
 
  pattern := procedure ;
  pattern CAT ":" ;
  INT CONST index pos := pos (list, pattern) ;
  IF procedure name found
    THEN get colon pos ;
         get dot pos ;
         get end pos ;
         get command index ;
         get param index ;
         IF param index >= 0
           THEN command index + param index
           ELSE - command index
         FI
    ELSE 0
  FI .
 
procedure name found :
  index pos > 0  AND  (list SUB index pos - 1) <= "9"  .
 
get param index :
  INT CONST param index :=
            pos (list, text (params), dot pos, end pos) - dot pos - 1 .
 
get command index :
  INT CONST command index :=
            int ( subtext (list, colon pos + 1, dot pos - 1) ) .
 
get colon pos :
  INT CONST colon pos := pos (list, ":", index pos) .
 
get dot pos :
  INT CONST dot pos := pos (list, ".", index pos) .
 
get end pos :
  INT CONST end pos := dot pos + 4 .
 
ENDPROC index ;
 
PROC error (TEXT CONST message) :
 
  error note := message ;
  scan ("") ;
  procedure := "-"
 
ENDPROC error ;
 
PROC command error :

  disable stop ;
  IF error note <> ""
    THEN errorstop (error note) ;
         error note := ""
  FI ;
  enable stop

ENDPROC command error ;


PROC next symbol :
 
  next symbol (symbol, symbol type)
 
ENDPROC next symbol ;
 
iNDPACKET command handler ;