summaryrefslogtreecommitdiff
path: root/support/rnototex/argops.pas
blob: 8123892abf2344393c591c52e9e610acbf76fc74 (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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
{	MODULE FOR LIST AND TREE OPERATIONS ARGUMENTS }
{	RANDALL VENHOLA JULY 8, 1987                  }
                                                       

[INHERIT('SCREENHANDLERS','UTILITYOPS'), environment('argops')]

MODULE ARGOPS;

CONST

   maxchars = 31;              {# of chars in arg literal }
   maxargsinarray = 30;      {for conversion to an array of args}
   indexofunknowntexcommand = 0;

TYPE

   pckstr = VARYING [ maxchars ] of char;

   comparisons = (notvalid, lessthan, equal, greaterthan);

   setofcomparisons = set of comparisons;

   argtype = ( dsrverb, int, signedint, stylespecifier,
	    textpckstr, character, quotedpckstr, nulltype);

   setofargtype = set of argtype;

           argument =  record 
	                 source            : pckstr;                       
	                 isgeneralization : boolean;
 	                 texindex         : integer;
                         class             : setofargtype
	               end;        

   argarray = array[1..maxargsinarray] of argument;

                            
            

[GLOBAL] FUNCTION argliteral( arg : argument; smooth : boolean ) : pckstr;

var 
  s : pckstr;         
  i,j, firstchar, lastchar : integer;
  ch : char;

 procedure findfirstchar( s : pckstr; var firstchar : integer);
 begin
    firstchar := 1;
    while (firstchar < s.length) and (s.body[firstchar] <= blank) do
      firstchar := firstchar + 1
 end;  

 procedure findlastchar( s : pckstr; var lastchar : integer );
 begin
   lastchar := s.length;
   while (lastchar > 1) and (s.body[lastchar] <= blank) do
      lastchar := lastchar - 1
 end;
                                                           
begin       
   if smooth then
   begin
     findfirstchar( arg.source, firstchar);
     findlastchar( arg.source, lastchar);
     j := 0;        
     for i := firstchar to lastchar do
     begin  
       ch := arg.source.body[i];
       if ch < blank then ch := blank;
       if ch in ['a'..'z'] then ch := chr(ord(ch) - ord(blank));
       j := j + 1;
       s.body[j] := ch
     end;                                                       
     if (j = 1) and (s.body[1] = blank) then
       s.length := 0
     else
       s.length := j             
   end
   else
     s := arg.source;    
   argliteral := s
end;
          

    


[GLOBAL] FUNCTION pckstrisgeneralization( s : pckstr ) : boolean;
  label
    routineexit;
  var
    flag : boolean;
  begin
     flag := false;
     if s = '[N]' then
     begin
       flag := true;
       goto routineexit
     end;
     if s = '[C]' then
     begin
       flag := true;
       goto routineexit
     end;
     if s = '[Y]' then
     begin
       flag := true;
       goto routineexit
     end;
     if s = '[T]' then
     begin
       flag := true;
       goto routineexit
     end;
     if s = '[Q]' then
     begin
       flag := true;
       goto routineexit                                      
     end;      
     routineexit : pckstrisgeneralization := flag
end;            


    
     
[GLOBAL] FUNCTION argisgeneralization( arg : argument ) : boolean;
begin
   argisgeneralization := arg.isgeneralization
end;
   
          


[GLOBAL] FUNCTION textualmatch( arg1, arg2 : argument) : boolean;                                           
begin
   textualmatch := false;
   if (arg1.source = '[T]') and (textpckstr in arg2.class) then
	textualmatch := true
   else
      if (arg2.source = '[T]') and (textpckstr in arg1.class) then
	textualmatch := true
end;



        
[GLOBAL] FUNCTION compareargs( leftarg, rightarg : argument ) : comparisons;
label
  routineexit;
var
  lefts, rights : pckstr;
  equalpckstrs : boolean;
  comp : comparisons;       

  procedure greaterorlessthancompare;
  begin
     if lefts < rights then
       comp := lessthan
     else              
      comp := greaterthan
  end;
                                                
  procedure checktexindex;
  begin
     if (leftarg.texindex  = indexofunknowntexcommand) or
        (rightarg.texindex = indexofunknowntexcommand) then
         comp := equal
     else
	if leftarg.texindex = rightarg.texindex then
	  comp := equal
	else
           greaterorlessthancompare
  end;

begin                        
   if textualmatch( leftarg, rightarg) then
   begin
     comp := equal;
     goto routineexit
   end;
   if (leftarg.class = [nulltype]) or (rightarg.class = [nulltype]) then
   begin
      comp := equal;
      goto routineexit
   end;
   lefts := argliteral(leftarg, TRUE);
   rights := argliteral(rightarg, TRUE);
   equalpckstrs := (lefts = rights);
   comp := notvalid;
   if leftarg.class * rightarg.class <> [] then
   begin                              
     if equalpckstrs then                            
        comp := equal
     else  
        if (leftarg.isgeneralization) or (rightarg.isgeneralization) then
          checktexindex
        else
          greaterorlessthancompare
   end
   else
     greaterorlessthancompare;
   routineexit : compareargs := comp
end;      




[GLOBAL] FUNCTION argtexindex( arg : argument ) : integer;    
begin
   argtexindex := arg.texindex
end;
                                                              
          


[GLOBAL] FUNCTION argclass( arg : argument ) : setofargtype;
begin
   argclass := arg.class
end;




[GLOBAL] PROCEDURE initarg( var arg : argument; classification : setofargtype;
                   lit : pckstr; index : integer; general : boolean );
begin
   arg.source            := lit;
   arg.class             := classification;
   arg.texindex         := index;
   arg.isgeneralization := general
end;


                         

[GLOBAL] PROCEDURE reassignargclass( var arg : argument; newclass : setofargtype);
begin
   arg.class := newclass
end;                                            
    



[GLOBAL] PROCEDURE reassignargtexindex( var arg : argument; newindex:integer);
begin
  arg.texindex := newindex
end;

                                   

[GLOBAL] PROCEDURE reassignarggeneralization( var arg : argument;general:boolean);
begin
   arg.isgeneralization := general
end;




[GLOBAL] PROCEDURE appendchartoarg( ch : char; var arg : argument );
begin
  if arg.source.length = maxchars then                              
      warningmessage('appendchartoarg','argument too long')   
  else
  begin
    arg.source.length := arg.source.length + 1;
    arg.source.body[arg.source.length] := ch
  end
end;




[GLOBAL] PROCEDURE extractintegerfromargument( arg : argument; var successful : boolean;
	                               var int : integer;
	                               var signed : boolean );
var                                    
  s  : pckstr;
begin
   s := argliteral( arg, TRUE);
   readv( s, int, error := continue );
   if statusv <> 0 then
     successful := false
   else
   begin
      successful := true;
      signed := (s.body[1] = '+') or (s.body[1] = '-')
   end
end;



END.