1
2
3
4
5
6
7
8
9
10
11 path: proc;
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 dcl return_ptr ptr;
78 dcl return_string char (return_len) based (return_ptr) varying;
79 dcl return_len fixed bin;
80
81 dcl arg_ptr (3) ptr;
82 dcl arg_len (3) fixed bin;
83 dcl arg1 char (arg_len (1)) based (arg_ptr (1));
84 dcl arg2 char (arg_len (2)) based (arg_ptr (2));
85 dcl arg3 char (arg_len (3)) based (arg_ptr (3));
86
87 dcl (dn, pn) char (202);
88 dcl char202 character (202) varying;
89 dcl (en, cn, who) char (32);
90 dcl b36 bit (36);
91 dcl af_sw bit (1);
92 dcl fb35 fixed bin (35);
93 dcl (i, j, colon_idx, arg_count) fixed;
94 dcl code fixed bin (35);
95
96 dcl error_table_$bad_conversion fixed binary (35) external;
97 dcl error_table_$not_act_fnc fixed bin (35) ext;
98
99 dcl cv_oct_check_ entry (char (*), fixed bin (35)) returns (fixed bin (35));
100 dcl (active_fnc_err_, active_fnc_err_$suppress_name,
101 com_err_, com_err_$suppress_name, ioa_) entry options (variable);
102 dcl cu_$af_return_arg entry (fixed bin, ptr, fixed bin, fixed bin (35));
103 dcl cu_$arg_ptr entry (fixed bin, ptr, fixed bin, fixed bin (35));
104 dcl expand_pathname_$component entry (char (*), char (*), char (*), char (*), fixed bin (35));
105 dcl get_shortest_path_ entry (char(*)) returns(char(168));
106 dcl pathname_$component_check entry (char(*), char(*), char(*), char(*), fixed bin(35));
107 dcl unique_chars_ ext entry (bit (*)) returns (char (15));
108 dcl requote_string_ entry (char(*)) returns (char(*));
109 dcl (addr, index, length, maxlength, reverse, rtrim, search, substr, unspec) builtin;
110
111
112
113
114
115 call setup ("path", "", 1, 3, "0"b);
116 go to JOIN_SP;
117
118
119
120
121
122
123 shortest_path: entry;
124
125 call setup ("shortest_path", "", 1, 3, "0"b);
126
127
128 JOIN_SP: if arg_count = 1 then go to JOIN_D;
129
130 if arg_count = 2 then call pathname_$component_check ((pn), arg2, "", pn, code);
131 else call pathname_$component_check ((pn), arg2, arg3, pn, code);
132 if code ^= 0 then call error (code, "Creating pathname.");
133 if who = "shortest_path" then return_string = rtrim (get_shortest_path_ (pn));
134 else return_string = rtrim (pn);
135 go to FINISH;
136
137
138
139
140
141
142
143 directory: dir: entry;
144
145 call setup ("directory", en, 1, 1, "1"b);
146 pn = dn;
147
148 JOIN_D: if who = "shortest_path" then return_string = rtrim (get_shortest_path_ (pn));
149 else return_string = rtrim (pn);
150
151 FINISH: if ^af_sw then call ioa_ ("^a", return_string);
152 else if who ^= "is_component_pathname" then;
153 return_string = requote_string_ ((return_string));
154
155 RETURN: return;
156
157
158
159
160
161
162
163 entry: entry;
164
165 call setup ("entry", en, 1, 1, "1"b);
166 return_string = rtrim (en);
167 go to FINISH;
168
169
170
171
172
173
174
175 component: entry;
176
177 call setup ("component", en, 1, 1, "1"b);
178 if cn ^= "" then return_string = rtrim (cn);
179 else return_string = rtrim (en);
180 go to FINISH;
181
182
183
184
185
186
187
188 is_component_pathname:
189 icpn: entry;
190
191 call setup ("is_component_pathname", en, 1, 1, "1"b);
192 if cn = "" then return_string = "false";
193 else return_string = "true";
194 go to FINISH;
195
196
197
198
199
200 entry_path:
201 entry;
202
203 call setup ("entry_path", en, 1, 1, "1"b);
204 call pathname_$component_check (dn, en, "", pn, code);
205 if code ^= 0 then call error (code, "Forming pathname.");
206 return_string = rtrim (pn);
207 go to FINISH;
208
209
210
211
212
213
214
215
216 strip: entry;
217
218 call setup ("strip", "", 1, 2, "0"b);
219 go to JOIN_R;
220
221
222
223
224
225
226 strip_component: spc:
227 entry;
228
229 call setup ("strip_component", en, 1, 2, "1"b);
230 if cn = "" then pn = en;
231 else pn = cn;
232 go to JOIN_R;
233
234
235
236
237
238
239 strip_entry: spe: entry;
240
241 call setup ("strip_entry", en, 1, 2, "1"b);
242 pn = en;
243
244 JOIN_R: if arg_count = 2 then go to TWO_ARGS;
245
246
247
248 colon_idx = index (pn, "::");
249 if colon_idx = 0
250 then j = length (pn) + 1 - search (reverse (pn), ".>");
251 else j = length (pn) + 1 -
252 index (reverse (substr (pn, colon_idx + 2)), ".");
253 if j = length (pn) + 1 | j = 1 | substr (pn, j, 1) = ">" then return_string = rtrim (pn);
254 else return_string = substr (pn, 1, j - 1);
255 go to FINISH;
256
257
258
259 TWO_ARGS: i = length (rtrim (pn));
260 return_string = rtrim (pn);
261 if i > arg_len (2) then
262 if substr (pn, i - arg_len (2)) = "." || arg2 then
263 return_string = substr (pn, 1, i - arg_len (2) - 1);
264 go to FINISH;
265
266
267
268
269
270
271
272 suffix: entry;
273
274 call setup ("suffix", en, 1, 1, "1"b);
275 if cn ^= "" then en = cn;
276 i = 33-index (reverse (en), ".");
277 if i = 33 then return_string = "";
278 else if i >= length (rtrim (en)) then return_string = "";
279 else return_string = rtrim (substr (en, i+1));
280 go to FINISH;
281
282
283
284
285
286
287
288 unique: entry;
289
290 who = "unique";
291 call cu_$af_return_arg (arg_count, return_ptr, return_len, code);
292 if code = error_table_$not_act_fnc then do;
293 af_sw = "0"b;
294 return_ptr = addr (char202);
295 return_len = 202;
296 end;
297 else af_sw = "1"b;
298 if arg_count ^= 0 then do;
299 if arg_count ^= 1 then do;
300 if af_sw then call active_fnc_err_$suppress_name
301 (0, "unique", "Usage: [unique {octal_number}]");
302 else call com_err_$suppress_name (0, "unique", "Usage: unique {octal_number}");
303 go to RETURN;
304 end;
305 call cu_$arg_ptr (1, arg_ptr (1), arg_len (1), code);
306 fb35 = cv_oct_check_ (arg1, code);
307 if code ^= 0 then do;
308 call error (error_table_$bad_conversion, (arg1));
309 end;
310 if fb35 = 0 then do;
311 return_string = "!BBBBBBBBBBBBBB";
312 go to FINISH;
313 end;
314 b36 = unspec (fb35);
315 end;
316 else b36 = ""b;
317 return_string = unique_chars_ (b36);
318 go to FINISH;
319
320
321
322
323 setup: proc (string, a_en, min_arg, max_arg, ret);
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338 dcl string char (*);
339 dcl a_en char (*);
340 dcl en char (32);
341 dcl (min_arg, max_arg) fixed bin;
342 dcl ret bit (1);
343
344 who = string;
345 call cu_$af_return_arg (arg_count, return_ptr, return_len, code);
346 if code = error_table_$not_act_fnc then do;
347 af_sw = "0"b;
348 return_ptr = addr (char202);
349 return_len = maxlength (char202);
350 end;
351 else af_sw = "1"b;
352
353 if arg_count < min_arg | arg_count > max_arg then do;
354 if af_sw then call active_fnc_err_$suppress_name (0, string,
355 "Usage: [^a ^[path^;path {string}^;path {string1 {string2}}^]]",
356 string, max_arg);
357 else call com_err_$suppress_name (0, string,
358 "Usage: ^a ^[path^;path {string}^;path {string1 {string2}}^]",
359 string, max_arg);
360 go to RETURN;
361 end;
362
363
364
365 do i = 1 to arg_count;
366 call cu_$arg_ptr (i, arg_ptr (i), arg_len (i), code);
367 if code ^= 0 then
368 BAD_ARGS: call error (code, "");
369 end;
370 call expand_pathname_$component (arg1, dn, en, cn, code);
371 if code ^= 0 then call error (code, (arg1));
372 if ^ret then do;
373 call pathname_$component_check (dn, en, cn, pn, code);
374 if code ^= 0 then call error (code, (arg1));
375 end;
376 else a_en = en;
377
378 end setup;
379
380
381
382
383 error: proc (acode, string);
384
385
386
387 dcl acode fixed bin (35), string char (*);
388
389 if af_sw then call active_fnc_err_ (acode, who, string);
390 else call com_err_ (acode, who, string);
391 go to RETURN;
392
393 end error;
394
395 end path;