Open64 (mfef90, whirl2f, and IR tools)
TAG: version-openad; SVN changeset: 916
|
00001 /* 00002 00003 Copyright (C) 2000, 2001 Silicon Graphics, Inc. All Rights Reserved. 00004 00005 This program is free software; you can redistribute it and/or modify it 00006 under the terms of version 2.1 of the GNU Lesser General Public License 00007 as published by the Free Software Foundation. 00008 00009 This program is distributed in the hope that it would be useful, but 00010 WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00012 00013 Further, this software is distributed without any warranty that it is 00014 free of the rightful claim of any third person regarding infringement 00015 or the like. Any license provided herein, whether implied or 00016 otherwise, applies only to this software file. Patent licenses, if 00017 any, provided herein do not apply to combinations of this program with 00018 other software, or any other product whatsoever. 00019 00020 You should have received a copy of the GNU Lesser General Public 00021 License along with this program; if not, write the Free Software 00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, 00023 USA. 00024 00025 Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pky, 00026 Mountain View, CA 94043, or: 00027 00028 http://www.sgi.com 00029 00030 For further information regarding this notice, see: 00031 00032 http://oss.sgi.com/projects/GenInfo/NoticeExplan 00033 00034 */ 00035 00036 00037 #pragma ident "@(#) libfi/char/verify.c 92.2 07/30/99 10:09:59" 00038 00039 /* 00040 * VERIFY - Verify that a set of characters contains all the 00041 * characters in a string by identifying the position 00042 * of the first character in a string of characters that 00043 * does not appear in a given set of characters. 00044 */ 00045 00046 #include <fortran.h> 00047 #include <string.h> 00048 00049 /* 00050 * This routine assumes that an eight-bit character can occur in 00051 * a string, i.e., the characters do not have to be 7-bit ASCII 00052 * codes. Therefore, there are 256 entries rather than 128-bit 00053 * entries. 00054 * 00055 * The word size on mips platforms assumes a default integer is 00056 * always 32 bits. 00057 */ 00058 00059 #if defined(__mips) 00060 #define WORDS 8 00061 #define BITS 31 00062 #define MASK 07 00063 #define SHIFT 3 00064 #elif !defined(_WORD32) 00065 #define WORDS 4 00066 #define BITS 63 00067 #define MASK 03 00068 #define SHIFT 2 00069 #else /* includes little endian */ 00070 #define WORDS 8 00071 #define BITS 31 00072 #define MASK 07 00073 #define SHIFT 3 00074 #endif 00075 00076 #define FOUND(a) (mask[a & MASK] << (a >> SHIFT)) >= 0 00077 00078 _f_int 00079 _VERIFY (_fcd str1, _fcd str2, _f_log *back) 00080 { 00081 char *ptr1, *ptr2; 00082 _f_int len1, len2; 00083 int num; 00084 _f_int bck; 00085 _f_int i; 00086 _f_int mask[WORDS]; 00087 00088 /* Determine direction of search */ 00089 00090 #ifndef _UNICOS 00091 if (back != NULL && _ltob(back)) 00092 bck = 1; 00093 else 00094 bck = 0; 00095 #else 00096 num = _numargs(); 00097 #ifdef _ADDR64 00098 if (num == 2 * sizeof(_fcd) / sizeof(long)) 00099 #else 00100 if (num == 2) 00101 #endif 00102 bck = 0; 00103 else if (back == NULL) 00104 bck = 0; 00105 else if (_ltob(back)) 00106 bck = 1; 00107 else 00108 bck = 0; 00109 #endif 00110 00111 /* Convert Fortran character descriptors to C pointers */ 00112 len1 = (_f_int) _fcdlen (str1); 00113 ptr1 = _fcdtocp (str1); 00114 00115 len2 = (_f_int) _fcdlen (str2); 00116 ptr2 = _fcdtocp (str2); 00117 00118 /* If either string is null, return */ 00119 00120 if (len1 == 0) 00121 return (0); 00122 if (len2 == 0) { 00123 if (bck == 1) 00124 return (len1); 00125 else 00126 return (1); 00127 } 00128 00129 /* Initialize mask and set bit for each character in search string */ 00130 00131 #ifdef _UNICOS 00132 #pragma _CRI shortloop 00133 #endif 00134 for (i = 0; i < WORDS; i++) 00135 mask[i] = 0; 00136 for (i = 0; i < len2; i++) 00137 mask[ptr2[i] & MASK] |= 1 << (BITS - (ptr2[i] >> SHIFT)); 00138 00139 /* 00140 * Step through string. When a character which is not in the 00141 * search string is found, return that index. 00142 */ 00143 if (!bck) { 00144 for (i = 0; i < len1; i++) 00145 if (FOUND(ptr1[i])) 00146 return (i+1); 00147 } 00148 else { 00149 for (i = len1-1; i >= 0; i--) 00150 if (FOUND(ptr1[i])) 00151 return (i+1); 00152 } 00153 00154 /* If all characters are part of search string, return 0 */ 00155 00156 return (0); 00157 } 00158 00159 00160 #ifdef _F_INT4 00161 00162 #undef WORDS 00163 #undef BITS 00164 #undef MASK 00165 #undef SHIFT 00166 #if defined(__mips) 00167 #define WORDS 8 00168 #define BITS 31 00169 #define MASK 07 00170 #define SHIFT 3 00171 #elif !defined(_WORD32) 00172 #define WORDS 4 00173 #define BITS 63 00174 #define MASK 03 00175 #define SHIFT 2 00176 #else /* includes little endian */ 00177 #define WORDS 8 00178 #define BITS 31 00179 #define MASK 07 00180 #define SHIFT 3 00181 #endif 00182 00183 _f_int4 00184 _VERIFY_4 (_fcd str1, _fcd str2, _f_log *back) 00185 { 00186 char *ptr1, *ptr2; 00187 _f_int4 len1, len2; 00188 int num; 00189 _f_int bck; 00190 _f_int4 i; 00191 long mask[WORDS]; 00192 00193 /* Determine direction of search */ 00194 00195 #ifndef _UNICOS 00196 if (back != NULL && _ltob(back)) 00197 bck = 1; 00198 else 00199 bck = 0; 00200 #else 00201 num = _numargs(); 00202 #ifdef _ADDR64 00203 if (num == 2 * sizeof(_fcd) / sizeof(long)) 00204 #else 00205 if (num == 2) 00206 #endif 00207 bck = 0; 00208 else if (back == NULL) 00209 bck = 0; 00210 else if (_ltob(back)) 00211 bck = 1; 00212 else 00213 bck = 0; 00214 #endif 00215 00216 /* Convert Fortran character descriptors to C pointers */ 00217 len1 = (_f_int4) _fcdlen (str1); 00218 ptr1 = _fcdtocp (str1); 00219 00220 len2 = (_f_int4) _fcdlen (str2); 00221 ptr2 = _fcdtocp (str2); 00222 00223 /* If either string is null, return */ 00224 00225 if (len1 == 0) 00226 return (0); 00227 if (len2 == 0) { 00228 if (bck == 1) 00229 return (len1); 00230 else 00231 return (1); 00232 } 00233 00234 /* Initialize mask and set bit for each character in search string */ 00235 00236 #ifdef _UNICOS 00237 #pragma _CRI shortloop 00238 #endif 00239 for (i = 0; i < WORDS; i++) 00240 mask[i] = 0; 00241 for (i = 0; i < len2; i++) 00242 mask[ptr2[i] & MASK] |= 1 << (BITS - (ptr2[i] >> SHIFT)); 00243 00244 /* 00245 * Step through string. When a character which is not in the 00246 * search string is found, return that index. 00247 */ 00248 if (!bck) { 00249 for (i = 0; i < len1; i++) 00250 if (FOUND(ptr1[i])) 00251 return (i+1); 00252 } 00253 else { 00254 for (i = len1-1; i >= 0; i--) 00255 if (FOUND(ptr1[i])) 00256 return (i+1); 00257 } 00258 00259 /* If all characters are part of search string, return 0 */ 00260 00261 return (0); 00262 } 00263 #endif 00264 00265 00266 #ifdef _F_INT8 00267 00268 #undef WORDS 00269 #undef BITS 00270 #undef MASK 00271 #undef SHIFT 00272 #define WORDS 4 00273 #define BITS 63 00274 #define MASK 03 00275 #define SHIFT 2 00276 00277 _f_int8 00278 _VERIFY_8 (_fcd str1, _fcd str2, _f_log *back) 00279 { 00280 char *ptr1, *ptr2; 00281 _f_int8 len1, len2; 00282 int num; 00283 _f_int bck; 00284 _f_int8 i; 00285 long mask[WORDS]; 00286 00287 /* Determine direction of search */ 00288 00289 #ifndef _UNICOS 00290 if (back != NULL && _ltob(back)) 00291 bck = 1; 00292 else 00293 bck = 0; 00294 #else 00295 num = _numargs(); 00296 #ifdef _ADDR64 00297 if (num == 2 * sizeof(_fcd) / sizeof(long)) 00298 #else 00299 if (num == 2) 00300 #endif 00301 bck = 0; 00302 else if (back == NULL) 00303 bck = 0; 00304 else if (_ltob(back)) 00305 bck = 1; 00306 else 00307 bck = 0; 00308 #endif 00309 00310 /* Convert Fortran character descriptors to C pointers */ 00311 len1 = (_f_int8) _fcdlen (str1); 00312 ptr1 = _fcdtocp (str1); 00313 00314 len2 = (_f_int8)_fcdlen (str2); 00315 ptr2 = _fcdtocp (str2); 00316 00317 /* If either string is null, return */ 00318 00319 if (len1 == 0) 00320 return (0); 00321 if (len2 == 0) { 00322 if (bck == 1) 00323 return (len1); 00324 else 00325 return (1); 00326 } 00327 00328 /* Initialize mask and set bit for each character in search string */ 00329 00330 #ifdef _UNICOS 00331 #pragma _CRI shortloop 00332 #endif 00333 for (i = 0; i < WORDS; i++) 00334 mask[i] = 0; 00335 for (i = 0; i < len2; i++) 00336 mask[ptr2[i] & MASK] |= 1 << (BITS - (ptr2[i] >> SHIFT)); 00337 00338 /* 00339 * Step through string. When a character which is not in the 00340 * search string is found, return that index. 00341 */ 00342 if (!bck) { 00343 for (i = 0; i < len1; i++) 00344 if (FOUND(ptr1[i])) 00345 return (i+1); 00346 } 00347 else { 00348 for (i = len1-1; i >= 0; i--) 00349 if (FOUND(ptr1[i])) 00350 return (i+1); 00351 } 00352 00353 /* If all characters are part of search string, return 0 */ 00354 00355 return (0); 00356 } 00357 #endif 00358 00359 00360 #ifdef _F_INT2 00361 00362 #undef WORDS 00363 #undef BITS 00364 #undef MASK 00365 #undef SHIFT 00366 #if defined(__mips) || defined(_LITTLE_ENDIAN) 00367 #define WORDS 16 00368 #define BITS 15 00369 #define MASK 017 00370 #define SHIFT 4 00371 #elif !defined(_WORD32) 00372 #define WORDS 4 00373 #define BITS 63 00374 #define MASK 03 00375 #define SHIFT 2 00376 #else 00377 #define WORDS 8 00378 #define BITS 31 00379 #define MASK 07 00380 #define SHIFT 3 00381 #endif 00382 00383 _f_int2 00384 _VERIFY_2 (_fcd str1, _fcd str2, _f_log *back) 00385 { 00386 char *ptr1, *ptr2; 00387 _f_int2 len1, len2; 00388 int num; 00389 _f_int bck; 00390 _f_int2 i; 00391 long mask[WORDS]; 00392 00393 /* Determine direction of search */ 00394 00395 #ifndef _UNICOS 00396 if (back != NULL && _ltob(back)) 00397 bck = 1; 00398 else 00399 bck = 0; 00400 #else 00401 num = _numargs(); 00402 #ifdef _ADDR64 00403 if (num == 2 * sizeof(_fcd) / sizeof(long)) 00404 #else 00405 if (num == 2) 00406 #endif 00407 bck = 0; 00408 else if (back == NULL) 00409 bck = 0; 00410 else if (_ltob(back)) 00411 bck = 1; 00412 else 00413 bck = 0; 00414 #endif 00415 00416 /* Convert Fortran character descriptors to C pointers */ 00417 len1 = (_f_int2) _fcdlen (str1); 00418 ptr1 = _fcdtocp (str1); 00419 00420 len2 = (_f_int2) _fcdlen (str2); 00421 ptr2 = _fcdtocp (str2); 00422 00423 /* If either string is null, return */ 00424 00425 if (len1 == 0) 00426 return (0); 00427 if (len2 == 0) { 00428 if (bck == 1) 00429 return (len1); 00430 else 00431 return (1); 00432 } 00433 00434 /* Initialize mask and set bit for each character in search string */ 00435 00436 #ifdef _UNICOS 00437 #pragma _CRI shortloop 00438 #endif 00439 for (i = 0; i < WORDS; i++) 00440 mask[i] = 0; 00441 for (i = 0; i < len2; i++) 00442 mask[ptr2[i] & MASK] |= 1 << (BITS - (ptr2[i] >> SHIFT)); 00443 00444 /* 00445 * Step through string. When a character which is not in the 00446 * search string is found, return that index. 00447 */ 00448 if (!bck) { 00449 for (i = 0; i < len1; i++) 00450 if (FOUND(ptr1[i])) 00451 return (i+1); 00452 } 00453 else { 00454 for (i = len1-1; i >= 0; i--) 00455 if (FOUND(ptr1[i])) 00456 return (i+1); 00457 } 00458 00459 /* If all characters are part of search string, return 0 */ 00460 00461 return (0); 00462 } 00463 #endif 00464 00465 #ifdef _F_INT1 00466 00467 #undef WORDS 00468 #undef BITS 00469 #undef MASK 00470 #undef SHIFT 00471 #if defined(__mips) || defined(_LITTLE_ENDIAN) 00472 #define WORDS 32 00473 #define BITS 7 00474 #define MASK 037 00475 #define SHIFT 5 00476 #elif !defined(_WORD32) 00477 #define WORDS 4 00478 #define BITS 63 00479 #define MASK 03 00480 #define SHIFT 2 00481 #else 00482 #define WORDS 8 00483 #define BITS 31 00484 #define MASK 07 00485 #define SHIFT 3 00486 #endif 00487 00488 _f_int1 00489 _VERIFY_1 (_fcd str1, _fcd str2, _f_log *back) 00490 { 00491 char *ptr1, *ptr2; 00492 _f_int1 len1, len2; 00493 int num; 00494 _f_int bck; 00495 _f_int1 i; 00496 long mask[WORDS]; 00497 00498 /* Determine direction of search */ 00499 00500 #ifndef _UNICOS 00501 if (back != NULL && _ltob(back)) 00502 bck = 1; 00503 else 00504 bck = 0; 00505 #else 00506 num = _numargs(); 00507 #ifdef _ADDR64 00508 if (num == 2 * sizeof(_fcd) / sizeof(long)) 00509 #else 00510 if (num == 2) 00511 #endif 00512 bck = 0; 00513 else if (back == NULL) 00514 bck = 0; 00515 else if (_ltob(back)) 00516 bck = 1; 00517 else 00518 bck = 0; 00519 #endif 00520 00521 /* Convert Fortran character descriptors to C pointers */ 00522 len1 = (_f_int1) _fcdlen (str1); 00523 ptr1 = _fcdtocp (str1); 00524 00525 len2 = (_f_int1) _fcdlen (str2); 00526 ptr2 = _fcdtocp (str2); 00527 00528 /* If either string is null, return */ 00529 00530 if (len1 == 0) 00531 return (0); 00532 if (len2 == 0) { 00533 if (bck == 1) 00534 return (len1); 00535 else 00536 return (1); 00537 } 00538 00539 /* Initialize mask and set bit for each character in search string */ 00540 00541 #ifdef _UNICOS 00542 #pragma _CRI shortloop 00543 #endif 00544 for (i = 0; i < WORDS; i++) 00545 mask[i] = 0; 00546 for (i = 0; i < len2; i++) 00547 mask[ptr2[i] & MASK] |= 1 << (BITS - (ptr2[i] >> SHIFT)); 00548 00549 /* 00550 * Step through string. When a character which is not in the 00551 * search string is found, return that index. 00552 */ 00553 if (!bck) { 00554 for (i = 0; i < len1; i++) 00555 if (FOUND(ptr1[i])) 00556 return (i+1); 00557 } 00558 else { 00559 for (i = len1-1; i >= 0; i--) 00560 if (FOUND(ptr1[i])) 00561 return (i+1); 00562 } 00563 00564 /* If all characters are part of search string, return 0 */ 00565 00566 return (0); 00567 } 00568 #endif