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