summaryrefslogtreecommitdiff
path: root/support/rnototex/iniops.pas
blob: 055cf3ef286c4084d0bfefd8bc25ef63ea3a9fb5 (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
{   	INI FILE MODULE FOR RNO TO TEX CONVERSION           }
{ 	RANDALL VENHOLA JULY 7, 1987                        }
               
[INHERIT('UTILITYOPS','BASICFILEOPS','ARGOPS',
         'TREEANDLISTOPS','SCREENHANDLERS'), environment('iniops')]

MODULE INIOPS;


                           
[GLOBAL] PROCEDURE readarglistfromini( var ini : text; var index : integer;
	                          var list : arglist );
const
  iniseparator = '$';
var
  s : pckstr;
  done : boolean;
  gotten : boolean;
  arg : argument;
  inserted : boolean;

  function endofline : boolean;
  begin
    if eof(ini) then
       endofline := true
    else
       begin
         if eoln(ini) then
            endofline := true
         else
           begin
             if ini^ = blank then
                endofline := true
             else
                endofline := false
           end
       end
  end;
                     
  function atseparator : boolean;
  begin
    atseparator := (ini^ = iniseparator)
  end;

  procedure readpckstr( var s : pckstr; var gotten : boolean );
  var
    ch : char; 
    done : boolean;
    charindex : integer;
  begin
    s.body := blank;
    done := false;
    charindex := 0;
    repeat
        if endofline then
            done := true
        else
          if atseparator then
             done := true
          else
             if charindex = maxchars then
             begin
	        warningmessage('readini','ini file argument size overflow');
                done := true                                              
             end
	     else
             begin
                read(ini, ch);
                charindex := charindex + 1;
                s.body[charindex] := ch
             end;
         s.length := charindex
    until done;
    gotten := charindex > 0;
    if atseparator then read(ini, ch)                      
  end;
  
  procedure readindex(var index : integer; var gotten : boolean );
  const
    ndigits = 3;
  var
    count : integer;
    ch    : char;
  begin
    gotten := true;
    count := 0;
    index := 0;
    repeat
        if endofline then
            gotten := false
        else
          if count < ndigits then
          begin
             read(ini, ch);                   
             count := count + 1;
             if ch in ['0'..'9'] then
                index := index*10 + ord(ch) - ord('0')
             else
             begin
	        warningmessage('readini','bad index digits in INI');
	        gotten := false                                   
             end
          end
     until (not gotten) or (count = ndigits);
     if (gotten) and (not eof(ini)) then read(ini, ch)
  end;

  procedure pckstrtoarg( s : pckstr; index : integer; var arg : argument);
  label
      routineexit;
  begin
     initarg(arg, [dsrverb], s, index, false );        
     if s = '[N]' then
     begin
       reassignargclass(arg, [int,signedint,nulltype]);
       reassignarggeneralization(arg, true);
       goto routineexit
     end;
     if s = '[Y]' then
     begin
       reassignargclass(arg, [stylespecifier]);
       reassignarggeneralization(arg, true);
       goto routineexit
     end;
     if s = '[T]' then
     begin            
       reassignargclass(arg, [textpckstr,character,nulltype]);
       reassignarggeneralization(arg, true);
       goto routineexit
     end;
     if s = '[C]' then
     begin
       reassignargclass(arg, [character,nulltype]);
       reassignarggeneralization(arg, true);
       goto routineexit
     end;                  
     if s = '[Q]' then
     begin
       reassignargclass(arg, [quotedpckstr,nulltype]);
       reassignarggeneralization(arg, true);
       goto routineexit
     end;
     routineexit : nullstatement
  end;         
  
begin {readarglistfromini}
  list := nulllist;
  readindex(index, gotten );
  if gotten then                                              
  begin         
    if index < 1 then      
      warningmessage('readini','bad INI index value');
    repeat
       readpckstr(s, gotten );
       if gotten then        
       begin
         pckstrtoarg(s, index, arg );
         appendargonlist(list, arg);
       end                                             
    until not gotten;
    if arglistlength(list) = 0 then
       warningmessage('readini','empty argument list in INI file')
  end  
  else
  begin
    index := indexofunknowntexcommand;
    warningmessage('readini','could not read index from INI file')
  end;                        
  if not eof(ini) then
    readln(ini)
end;  
         




                   
[GLOBAL] PROCEDURE setuptree( var ini : text; var tree : argtree );
var 
   list : arglist;
   index : integer;
begin  
    openinifile( ini );
    tree := nulltree;
    while not eof(ini) do
    begin          
       readarglistfromini( ini, index, list);

       {   ***** ttywritestring(' index read = ');
                 ttywriteint(index);
                 ttywriteln;                   *****      }

       insertlistintotree( list, tree )
    end;
    closeinifile( ini )
end;
    
    
                                      
END.