Debian Codegraph @

libsrc/os/vms/osc.c

raw
1 /* @(#)osc.c 19.1 (ES0-DMD) 02/25/03 13:56:11 */
2 /*===========================================================================
3 Copyright (C) 1995 European Southern Observatory (ESO)
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of
8 the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public
16 License along with this program; if not, write to the Free
17 Software Foundation, Inc., 675 Massachusetss Ave, Cambridge,
18 MA 02139, USA.
19
20 Corresponding concerning ESO-MIDAS should be addressed as follows:
21 Internet e-mail: [email protected]
22 Postal address: European Southern Observatory
23 Data Management Division
24 Karl-Schwarzschild-Strasse 2
25 D 85748 Garching bei Muenchen
26 GERMANY
27 ===========================================================================*/
28
29 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30 .TYPE Module
31 .NAME osc
32 .LANGUAGE C
33 .AUTHOR IPG-ESO Garching
34 .CATEGORY Host operating system interfaces. Character functions.
35 .ENVIRONMENT *** VAX/VMS Version ***
36 .COMMENTS
37 Provide character manipulation host services.
38 The routines return all length or indices.
39 Routines are optimized for long strings.
40 .VERSION 1.0 28-Jan-1988 Definition. F. Ochsenbein
41 .VERSION 1.1 05-Sep-1989: Changed some `unclever' macros...
42 ------------------------------------------------------------*/
43
44 #include <osdefos.h>
45 #include <macrogen.h>
46
47 MID_EXTERN int oserror;
48 MID_EXTERN int vmserror;
49
50 #include <ssdef.h> /* System */
51 #include <errno.h> /* System */
52 #include <descrip.h> /* System */
53 typedef struct dsc$descriptor descript;
54
55 # define CMAX 0xffff /* Maximal length */
56 # define L dsc$w_length
57 # define S dsc$a_pointer
58 # define InitDescript(text) \
59 {sizeof(text)-1, DSC$K_DTYPE_T, DSC$K_CLASS_S,text}
60 # define void_string \
61 {0, DSC$K_DTYPE_T, DSC$K_CLASS_S, NULL_PTR(char)}
62 # define SET_STRING(dsc,str,l) dsc.S = (char *)str, dsc.L = l \
63 /* Set address & length of a string */
64
65 #define FINISH goto FIN
66 #define RETURN(x) FIN: return(x)
67
68 #define ___ 0x00
69 #define _U_ 0x01 /* UPPER-case letter A...Z */
70 #define _L_ 0x02 /* lower-case letter a...z */
71 #define _D_ 0x04 /* digit 0...9 */
72 #define _S_ 0x08 /* space */
73 #define _P_ 0x10 /* punctuation */
74 #define _C_ 0x20 /* control character */
75 #define _X_ 0x40 /* hexa digit */
76 #define _B_ 0x80 /* blank */
77
78 /*==========================================================================
79 * Attributes of ASCII characters
80 *==========================================================================*/
81
82 /* Attributes of ASCII characters */
83 MID_GLOBAL unsigned char main_ascii[256] = /* ASCII attributes */
84 { /* UPP|low|dig|sp |pun|ctr|hex|bl
85 * | | | | | | | */
86 ___|___|___|___|___|_C_|___|___, /* NUL */
87 ___|___|___|___|___|_C_|___|___, /* SOH */
88 ___|___|___|___|___|_C_|___|___, /* STX */
89 ___|___|___|___|___|_C_|___|___, /* ETX */
90 ___|___|___|___|___|_C_|___|___, /* EOT */
91 ___|___|___|___|___|_C_|___|___, /* ENQ */
92 ___|___|___|___|___|_C_|___|___, /* ACK */
93 ___|___|___|___|___|_C_|___|___, /* BEL */
94 ___|___|___|___|___|_C_|___|___, /* BS */
95 ___|___|___|_S_|___|_C_|___|___, /* HTab */
96 ___|___|___|_S_|___|_C_|___|___, /* LF */
97 ___|___|___|_S_|___|_C_|___|___, /* VTab */
98 ___|___|___|_S_|___|_C_|___|___, /* FF */
99 ___|___|___|_S_|___|_C_|___|___, /* CR */
100 ___|___|___|___|___|_C_|___|___, /* SO */
101 ___|___|___|___|___|_C_|___|___, /* SI */
102 ___|___|___|___|___|_C_|___|___, /* DLE */
103 ___|___|___|___|___|_C_|___|___, /* DC1 */
104 ___|___|___|___|___|_C_|___|___, /* DC2 */
105 ___|___|___|___|___|_C_|___|___, /* DC3 */
106 ___|___|___|___|___|_C_|___|___, /* DC4 */
107 ___|___|___|___|___|_C_|___|___, /* NAK */
108 ___|___|___|___|___|_C_|___|___, /* SYN */
109 ___|___|___|___|___|_C_|___|___, /* ETB */
110 ___|___|___|___|___|_C_|___|___, /* CAN */
111 ___|___|___|___|___|_C_|___|___, /* EM */
112 ___|___|___|___|___|_C_|___|___, /* SUB */
113 ___|___|___|___|___|_C_|___|___, /* ESC */
114 ___|___|___|___|___|_C_|___|___, /* FS */
115 ___|___|___|___|___|_C_|___|___, /* GS */
116 ___|___|___|___|___|_C_|___|___, /* RS */
117 ___|___|___|___|___|_C_|___|___, /* US */
118 ___|___|___|_S_|___|___|___|_B_, /* sp */
119 ___|___|___|___|_P_|___|___|___, /* ! */
120 ___|___|___|___|_P_|___|___|___, /* " */
121 ___|___|___|___|_P_|___|___|___, /* # */
122 ___|___|___|___|_P_|___|___|___, /* $ */
123 ___|___|___|___|_P_|___|___|___, /* % */
124 ___|___|___|___|_P_|___|___|___, /* & */
125 ___|___|___|___|_P_|___|___|___, /* ' */
126 ___|___|___|___|_P_|___|___|___, /* ( */
127 ___|___|___|___|_P_|___|___|___, /* ) */
128 ___|___|___|___|_P_|___|___|___, /* * */
129 ___|___|___|___|_P_|___|___|___, /* + */
130 ___|___|___|___|_P_|___|___|___, /* , */
131 ___|___|___|___|_P_|___|___|___, /* - */
132 ___|___|___|___|_P_|___|___|___, /* . */
133 ___|___|___|___|_P_|___|___|___, /* / */
134 ___|___|_D_|___|___|___|_X_|___, /* 0 */
135 ___|___|_D_|___|___|___|_X_|___, /* 1 */
136 ___|___|_D_|___|___|___|_X_|___, /* 2 */
137 ___|___|_D_|___|___|___|_X_|___, /* 3 */
138 ___|___|_D_|___|___|___|_X_|___, /* 4 */
139 ___|___|_D_|___|___|___|_X_|___, /* 5 */
140 ___|___|_D_|___|___|___|_X_|___, /* 6 */
141 ___|___|_D_|___|___|___|_X_|___, /* 7 */
142 ___|___|_D_|___|___|___|_X_|___, /* 8 */
143 ___|___|_D_|___|___|___|_X_|___, /* 9 */
144 ___|___|___|___|_P_|___|___|___, /* : */
145 ___|___|___|___|_P_|___|___|___, /* ; */
146 ___|___|___|___|_P_|___|___|___, /* < */
147 ___|___|___|___|_P_|___|___|___, /* = */
148 ___|___|___|___|_P_|___|___|___, /* > */
149 ___|___|___|___|_P_|___|___|___, /* ? */
150 ___|___|___|___|_P_|___|___|___, /* @ */
151 _U_|___|___|___|___|___|_X_|___, /* A */
152 _U_|___|___|___|___|___|_X_|___, /* B */
153 _U_|___|___|___|___|___|_X_|___, /* C */
154 _U_|___|___|___|___|___|_X_|___, /* D */
155 _U_|___|___|___|___|___|_X_|___, /* E */
156 _U_|___|___|___|___|___|_X_|___, /* F */
157 _U_|___|___|___|___|___|___|___, /* G */
158 _U_|___|___|___|___|___|___|___, /* H */
159 _U_|___|___|___|___|___|___|___, /* I */
160 _U_|___|___|___|___|___|___|___, /* J */
161 _U_|___|___|___|___|___|___|___, /* K */
162 _U_|___|___|___|___|___|___|___, /* L */
163 _U_|___|___|___|___|___|___|___, /* M */
164 _U_|___|___|___|___|___|___|___, /* N */
165 _U_|___|___|___|___|___|___|___, /* O */
166 _U_|___|___|___|___|___|___|___, /* P */
167 _U_|___|___|___|___|___|___|___, /* Q */
168 _U_|___|___|___|___|___|___|___, /* R */
169 _U_|___|___|___|___|___|___|___, /* S */
170 _U_|___|___|___|___|___|___|___, /* T */
171 _U_|___|___|___|___|___|___|___, /* U */
172 _U_|___|___|___|___|___|___|___, /* V */
173 _U_|___|___|___|___|___|___|___, /* W */
174 _U_|___|___|___|___|___|___|___, /* X */
175 _U_|___|___|___|___|___|___|___, /* Y */
176 _U_|___|___|___|___|___|___|___, /* Z */
177 ___|___|___|___|_P_|___|___|___, /* [ */
178 ___|___|___|___|_P_|___|___|___, /* \ */
179 ___|___|___|___|_P_|___|___|___, /* ] */
180 ___|___|___|___|_P_|___|___|___, /* ^ */
181 ___|___|___|___|_P_|___|___|___, /* _ */
182 ___|___|___|___|_P_|___|___|___, /* ` */
183 ___|_L_|___|___|___|___|_X_|___, /* a */
184 ___|_L_|___|___|___|___|_X_|___, /* b */
185 ___|_L_|___|___|___|___|_X_|___, /* c */
186 ___|_L_|___|___|___|___|_X_|___, /* d */
187 ___|_L_|___|___|___|___|_X_|___, /* e */
188 ___|_L_|___|___|___|___|_X_|___, /* f */
189 ___|_L_|___|___|___|___|___|___, /* g */
190 ___|_L_|___|___|___|___|___|___, /* h */
191 ___|_L_|___|___|___|___|___|___, /* i */
192 ___|_L_|___|___|___|___|___|___, /* j */
193 ___|_L_|___|___|___|___|___|___, /* k */
194 ___|_L_|___|___|___|___|___|___, /* l */
195 ___|_L_|___|___|___|___|___|___, /* m */
196 ___|_L_|___|___|___|___|___|___, /* n */
197 ___|_L_|___|___|___|___|___|___, /* o */
198 ___|_L_|___|___|___|___|___|___, /* p */
199 ___|_L_|___|___|___|___|___|___, /* q */
200 ___|_L_|___|___|___|___|___|___, /* r */
201 ___|_L_|___|___|___|___|___|___, /* s */
202 ___|_L_|___|___|___|___|___|___, /* t */
203 ___|_L_|___|___|___|___|___|___, /* u */
204 ___|_L_|___|___|___|___|___|___, /* v */
205 ___|_L_|___|___|___|___|___|___, /* w */
206 ___|_L_|___|___|___|___|___|___, /* x */
207 ___|_L_|___|___|___|___|___|___, /* y */
208 ___|_L_|___|___|___|___|___|___, /* z */
209 ___|___|___|___|_P_|___|___|___, /* { */
210 ___|___|___|___|_P_|___|___|___, /* | */
211 ___|___|___|___|_P_|___|___|___, /* } */
212 ___|___|___|___|_P_|___|___|___, /* ~ */
213 ___|___|___|___|___|_C_|___|___, /* DEL */
214
215 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x8. */
216 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x9. */
217 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xA. */
218 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xB. */
219 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xC. */
220 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xD. */
221 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xE. */
222 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* 0xF. */
223 };
224
225 /*==========================================================================
226 * Copy memory to memory
227 *==========================================================================*/
228
229 int oscopy(dest, source, len)
230 /*++++++++++++++++++++++++++++++
231 .PURPOSE Copies second array of bytes into first one,
232 taking care of possible overlay.
233 .RETURNS Length (3rd argument)
234 .REMARKS Uses LIB$MOVC3. No length limit.
235 ----------------------------------------------*/
236 char *dest; /* OUT: pointer to destination string */
237 char *source; /* IN: pointer to source string */
238 int len; /* IN: length of source (and destination) strings */
239 {
240 static unsigned short int length;
241 register char *p, *q, *qe;
242
243 if (len < 1) FINISH;
244 if (dest == source) FINISH; /* same location */
245
246 qe = dest + len;
247 if ((dest < source) || (dest >= (source+len))) /* forwards */
248 {
249 for (p = source, q = dest; q < qe; )
250 { length = MIN(qe-q, CMAX);
251 LIB$MOVC3(&length, p, q);
252 p += length, q += length;
253 }
254 }
255 else /* backwards */
256 { for (q = qe, p = source + len; p > source;)
257 {
258 length = MIN(q-dest, CMAX);
259 p -= length, q -= length;
260 LIB$MOVC3(&length, p, q);
261 }
262 }
263
264 RETURN(len);
265 }
266
267 /*==========================================================================*/
268 int oscopuc(dest, source, len, escape)
269 /*++++++++++++++++++++++++++++++
270 .PURPOSE Copies second array of bytes into first one,
271 stopping when escape is found or the source string i exhausted.
272 The destination string INCLUDES on return the escape character.
273 .RETURNS Number of copied characters, EXCLUDING the escape char if it
274 was copied.
275 .REMARKS No test about possible overlapping strings (result is unpredictable
276 if strings overlap). VMS version uses LIB$MOVTUC and is limited
277 to 65535 bytes.
278 ----------------------------------------------*/
279 char *dest; /* OUT: pointer to destination string */
280 char *source; /* IN: pointer to source string */
281 int len; /* IN: length of source (and destination) strings */
282 char escape; /* IN: stopping char */
283 {
284 static char escape_char;
285 register int luc;
286 MID_RSTATIC char tuc[256] = {0,1,2,3,4,5,6,7,8,9,
287 10,11,12,13,14,15,16,17,18,19,
288 20,21,22,23,24,25,26,27,28,29,
289 30,31,32,33,34,35,36,37,38,39,
290 40,41,42,43,44,45,46,47,48,49,
291 50,51,52,53,54,55,56,57,58,59,
292 60,61,62,63,64,65,66,67,68,69,
293 70,71,72,73,74,75,76,77,78,79,
294 80,81,82,83,84,85,86,87,88,89,
295 90,91,92,93,94,95,96,97,98,99,
296 100,101,102,103,104,105,106,107,108,109,
297 110,111,112,113,114,115,116,117,118,119,
298 120,121,122,123,124,125,126,127,128,129,
299 130,131,132,133,134,135,136,137,138,139,
300 140,141,142,143,144,145,146,147,148,149,
301 150,151,152,153,154,155,156,157,158,159,
302 160,161,162,163,164,165,166,167,168,169,
303 170,171,172,173,174,175,176,177,178,179,
304 180,181,182,183,184,185,186,187,188,189,
305 190,191,192,193,194,195,196,197,198,199,
306 200,201,202,203,204,205,206,207,208,209,
307 210,211,212,213,214,215,216,217,218,219,
308 220,221,222,223,224,225,226,227,228,229,
309 230,231,232,233,234,235,236,237,238,239,
310 240,241,242,243,244,245,246,247,248,249,
311 250,251,252,253,254,255} ;
312 static descript sdv_table = {256, DSC$K_DTYPE_T, DSC$K_CLASS_S, tuc};
313 static descript sdv_esc = { 1, DSC$K_DTYPE_T, DSC$K_CLASS_S,
314 &escape_char};
315 static descript sdv_in = void_string;
316 static descript sdv_out = void_string;
317
318 escape_char = escape;
319
320 sdv_in.S = source; sdv_in.L = MIN(len, CMAX);
321 sdv_out.S = dest ; sdv_out.L = sdv_in.L;
322 luc = LIB$MOVTUC(&sdv_in, &sdv_esc, &sdv_table, &sdv_out);
323 if ((luc > 0) && (luc <= len))
324 *(dest + --luc) = escape_char;
325 else luc = len;
326
327 return(luc);
328 }
329
330 /*==========================================================================*/
331 int oscfill(dest, len, fill)
332 /*++++++++++++++++++++++++++++++
333 .PURPOSE Initialize a block of memory with fill character.
334 .RETURNS The length (2nd argument)
335 .REMARKS VMS version uses LIB$MOVC5
336 ----------------------------------------------*/
337 char *dest; /* MOD: buffer to set to zero */
338 int len; /* IN: length of buffer */
339 char fill; /* IN: The fill character */
340 {
341 static unsigned short int length ;
342 static unsigned short int zero = 0 ;
343 register char *p, *pe;
344 static char fill_char ;
345
346 if (len < 1) FINISH;
347 fill_char = fill;
348
349 for (p = dest, pe = dest + len; p < pe; p += length)
350 { length = MIN(pe-p, CMAX);
351 LIB$MOVC5(&zero, 0, &fill_char, &length, p); /* Source is null */
352 }
353
354 RETURN(len);
355 }
356
357 /*==========================================================================*/
358 int oscloc(str, len, fill)
359 /*++++++++++++++++++++++++++++++
360 .PURPOSE Retrieve position of a specified character
361 .RETURNS The index from 0 to (len-1) if found, len if not found.
362 .REMARKS VMS version uses LIB$LOCC
363 ----------------------------------------------*/
364 char *str; /* IN: string to scan */
365 int len; /* IN: length of string */
366 char fill; /* IN: The character to look for */
367 {
368 register char *p;
369
370 register char *pe;
371 register int index;
372 static char fill_char;
373 static descript sdv_c = { 1, DSC$K_DTYPE_T, DSC$K_CLASS_S, &fill_char};
374 static descript sdv_str = void_string;
375
376 sdv_c.L = 1, fill_char = fill;
377 for (p = str, pe = str+len; p < pe; p += sdv_str.L)
378 { sdv_str.L = MIN(pe-p, CMAX);
379 sdv_str.S = p;
380 index = LIB$LOCC(&sdv_c,&sdv_str);
381 if (index) return(--index);
382 }
383 p = pe;
384
385 RETURN(p-str);
386 }
387
388 /*==========================================================================*/
389 int oscbloc(str, len, fill)
390 /*++++++++++++++++++++++++++++++
391 .PURPOSE Retrieve position of a specified character, in BACKWARDS direction
392 .RETURNS The index from 0 to (len-1) if found, -1 if not found.
393 .REMARKS
394 ----------------------------------------------*/
395 char *str; /* IN: string to scan */
396 int len; /* IN: length of string */
397 char fill; /* IN: The character to look for */
398 {
399 register char *p;
400
401 for (p = str+len; p > str; )
402 if (*(--p) == fill) FINISH;
403 --p;
404
405 RETURN(p-str);
406 }
407
408 /*==========================================================================*/
409 int oscskip(str, len, fill)
410 /*++++++++++++++++++++++++++++++
411 .PURPOSE Retrieve position of first character that differs from fill.
412 .RETURNS The index from 0 to (len-1) if found, len if all characters
413 are identical to fill.
414 .REMARKS VMS version uses LIB$SKPC
415 ----------------------------------------------*/
416 char *str; /* IN: string to scan */
417 int len; /* IN: length of string */
418 char fill; /* IN: The character to look for */
419 {
420 register char *p, *pe;
421 register int index;
422 static char fill_char;
423 static descript sdv_c = { 1, DSC$K_DTYPE_T, DSC$K_CLASS_S, &fill_char};
424 static descript sdv_str = void_string;
425
426 sdv_c.L = 1, fill_char = fill;
427 for (p = str, pe = str+len; p < pe; p += sdv_str.L)
428 { sdv_str.L = MIN(pe-p, CMAX);
429 sdv_str.S = p;
430 index = LIB$SKPC(&sdv_c,&sdv_str);
431 if (index) return(--index);
432 }
433 p = pe;
434
435 RETURN(p-str);
436 }
437
438 /*==========================================================================*/
439 int oscbskip(str, len, fill)
440 /*++++++++++++++++++++++++++++++
441 .PURPOSE Retrieve position of first character different from fill,
442 starting from the END of the string.
443 .RETURNS The index from 0 to (len-1) if found, -1 if all characters
444 are identical to fill.
445 .REMARKS
446 ----------------------------------------------*/
447 char *str; /* IN: string to scan */
448 int len; /* IN: length of string */
449 char fill; /* IN: The character to look for */
450 {
451 register char *p;
452
453 for (p = str+len; p > str; )
454 if (*(--p) != fill) FINISH;
455 --p;
456
457 RETURN(p-str);
458 }
459
460 /*==========================================================================*/
461 int oscspan(str, len, mask, table)
462 /*++++++++++++++++++++++++++++++
463 .PURPOSE Span char, i.e. locate first non-flagged char. A non-flagged
464 char `c' is such that (table[c]&mask) is zero.
465 .RETURNS The index from 0 to (len-1) if found, len if all characters
466 are flagged.
467 .REMARKS VMS version uses LIB$SPANC
468 ----------------------------------------------*/
469 unsigned char *str; /* IN: string to scan */
470 int len; /* IN: length of string */
471 unsigned char mask; /* IN: AND operation to perform on table */
472 unsigned char *table; /* IN: The table (256 bytes) */
473 {
474 register unsigned char *p, *pe;
475 register int index;
476 static unsigned char local_mask;
477 static descript sdv_str = void_string;
478
479 local_mask = mask;
480 for (p = str, pe = str+len; p < pe; p += sdv_str.L)
481 { sdv_str.L = MIN(pe-p, CMAX);
482 sdv_str.S = (char *)p;
483 index = LIB$SPANC(&sdv_str,table,&local_mask);
484 if (index) return(--index);
485 }
486 p = pe;
487
488 RETURN(p-str);
489 }
490
491 /*==========================================================================*/
492 int oscbspan(str, len, mask, table)
493 /*++++++++++++++++++++++++++++++
494 .PURPOSE Span char, i.e. locate first non-flagged char, starting from the
495 END of the string. A non-flagged
496 char `c' is such that (table[c]&mask) is zero.
497 .RETURNS The index from 0 to (len-1) if found, -1 if all characters
498 are flagged.
499 .REMARKS
500 ----------------------------------------------*/
501 unsigned char *str; /* IN: string to scan */
502 int len; /* IN: length of string */
503 unsigned char mask; /* IN: AND operation to perform on table */
504 unsigned char *table; /* IN: The table (256 bytes) */
505 {
506 register unsigned char *p;
507
508 for (p = str+len; p > str; )
509 if (!(table[*(--p)]&mask)) FINISH;
510 --p;
511
512 RETURN(p-str);
513 }
514
515 /*==========================================================================*/
516 int oscscan(str, len, mask, table)
517 /*++++++++++++++++++++++++++++++
518 .PURPOSE Scan char, i.e. locate first flagged char. A flagged
519 char `c' is such that (table[c]&mask) differs from zero.
520 .RETURNS The index from 0 to (len-1) if found, len if all characters
521 are non-flagged.
522 .REMARKS VMS version uses LIB$SCANC
523 ----------------------------------------------*/
524 unsigned char *str; /* IN: string to scan */
525 int len; /* IN: length of string */
526 unsigned char mask; /* IN: AND operation to perform on table */
527 unsigned char *table; /* IN: The table (256 bytes) */
528 {
529 register unsigned char *p, *pe;
530 register int index;
531 static unsigned char local_mask;
532 static descript sdv_str = void_string;
533
534 local_mask = mask;
535 for (p = str, pe = str+len; p < pe; p += sdv_str.L)
536 { sdv_str.L = MIN(pe-p, CMAX);
537 sdv_str.S = (char *)p;
538 index = LIB$SCANC(&sdv_str,table,&local_mask);
539 if (index) return(--index);
540 }
541 p = pe;
542
543 RETURN(p-str);
544 }
545
546 /*==========================================================================*/
547 int oscbscan(str, len, mask, table)
548 /*++++++++++++++++++++++++++++++
549 .PURPOSE Span char, i.e. locate first flagged char, starting from the
550 END of the string. A flagged
551 char `c' is such that (table[c]&mask) differs from zero.
552 .RETURNS The index from 0 to (len-1) if found, -1 if all characters
553 are non-flagged.
554 .REMARKS
555 ----------------------------------------------*/
556 unsigned char *str; /* IN: string to scan */
557 int len; /* IN: length of string */
558 unsigned char mask; /* IN: AND operation to perform on table */
559 unsigned char *table; /* IN: The table (256 bytes) */
560 {
561 register unsigned char *p;
562
563 for (p = str+len; p > str; )
564 if (table[*(--p)]&mask) FINISH;
565 --p;
566
567 RETURN(p-str);
568 }
569
570 /*==========================================================================*/
571 int oscomp(str1, str2, len)
572 /*++++++++++++++++++++++++++++++
573 .PURPOSE Compare two strings of equal length.
574 .RETURNS Sign of (str1-str2), i.e. 0 for identical strings, negative number
575 if str1<str2, positive number if str1>str2.
576 .REMARKS VMS version uses STR$COMPARE
577 ----------------------------------------------*/
578 unsigned char *str1; /* IN: string to compare */
579 unsigned char *str2; /* IN: second string */
580 int len; /* IN: length of strings */
581 {
582 register unsigned char *p, *pe;
583 register int index;
584 static descript sdv1 = void_string;
585 static descript sdv2 = void_string;
586
587 index = 0;
588 for (p = str1, pe = str1+len; p < pe; p += sdv1.L, str2 += sdv2.L)
589 { sdv1.S = (char *)p; sdv1.L = MIN(pe-p, CMAX);
590 sdv2.S = (char *)str2; sdv2.L = sdv1.L;
591 if (index = STR$COMPARE(&sdv1,&sdv2)) break;
592 }
593
594 RETURN(index);
595 }
596
597 /*==========================================================================*/
598 int osccomp(str1, str2, len)
599 /*++++++++++++++++++++++++++++++
600 .PURPOSE Compare two strings of equal length, case insensitive.
601 .RETURNS Sign of (str1-str2), i.e. 0 for identical strings, negative number
602 if str1<str2, positive number if str1>str2.
603 .REMARKS VMS version uses STR$CASE_BLIND_COMPARE
604 ----------------------------------------------*/
605 unsigned char *str1; /* IN: string to compare */
606 unsigned char *str2; /* IN: second string */
607 int len; /* IN: length of strings */
608 {
609 register unsigned char *p, *pe;
610 register int index;
611 static descript sdv1 = void_string;
612 static descript sdv2 = void_string;
613
614 index = 0;
615 for (p = str1, pe = str1+len; p < pe; p += sdv1.L, str2 += sdv2.L)
616 { sdv1.S = (char *)p; sdv1.L = MIN(pe-p, CMAX);
617 sdv2.S = (char *)str2; sdv2.L = sdv1.L;
618 if (index = STR$CASE_BLIND_COMPARE(&sdv1,&sdv2)) break;
619 }
620 RETURN(index);
621 }
622
623 /*==========================================================================*/
624 int oscindex(str1, len1, str2, len2)
625 /*++++++++++++++++++++++++++++++
626 .PURPOSE Find the starting position in str1 of str2.
627 .RETURNS The index of str2 in str1, or len if str2 not found.
628 .REMARKS VMS version uses LIB$MATCHC
629 ----------------------------------------------*/
630 unsigned char *str1; /* IN: string to compare */
631 int len1; /* IN: length of str1 */
632 unsigned char *str2; /* IN: second string */
633 int len2; /* IN: length of str2 */
634 {
635 register unsigned char *p, *pe;
636 register int index;
637 static descript sdv1 = void_string;
638 static descript sdv2 = void_string;
639
640 SET_STRING(sdv2, str2, len2);
641
642 for (p = str1, pe = str1+len1; p < pe; p += sdv1.L)
643 { sdv1.S = (char *)p; sdv1.L = MIN(pe-p, CMAX);
644 index = LIB$MATCHC(&sdv2,&sdv1);
645 if (index) return(--index);
646 }
647 p = pe;
648
649 RETURN(p-str1);
650 }
651
652 /*==========================================================================*/
653 int osctr(dest, source, len, table)
654 /*++++++++++++++++++++++++++++++
655 .PURPOSE Translate a string according to a table, i.e. replace each
656 character `c' by table[`c'].
657 .RETURNS Length (3rd argument)
658 .REMARKS VMS version uses LIB$MOVTC. Strings may overlap.
659 ----------------------------------------------*/
660 unsigned char *dest; /* OUT: destination string */
661 unsigned char *source; /* IN: source string */
662 int len; /* IN: length of source (and destination) strings */
663 unsigned char *table; /* IN: Translation table (256 bytes) */
664 {
665 register unsigned char *p, *qe, *q;
666 static char fill_char;
667 static descript sdv_fill = { 1, DSC$K_DTYPE_T, DSC$K_CLASS_S,
668 &fill_char};
669 static descript sdv_in = void_string;
670 static descript sdv_out = void_string;
671 static descript sdv_table = void_string;
672
673 SET_STRING(sdv_table, table, 256);
674
675 qe = dest + len;
676
677 if ((dest < source) || (dest >= (source+len))) /* forwards */
678 { for (p = source, q = dest; q < qe; )
679 {
680 sdv_out.S = (char *)q; sdv_out.L = MIN(qe-q, CMAX);
681 sdv_in.S = (char *)p; sdv_in.L = sdv_out.L;
682 LIB$MOVTC(&sdv_in, &sdv_fill, &sdv_table, &sdv_out);
683 p += sdv_in.L, q += sdv_in.L;
684 }
685 } else /* backwards */
686 { for (q = qe, p = source + len; p > source;)
687 *(--q) = table[*(--p)];
688 }
689
690 RETURN(len);
691 }
692