Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
scan.c
Go to the documentation of this file.
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/scan.c   92.3    07/30/99 10:09:59"
00038 
00039 /*
00040  *      SCAN -  Scan a string for any one of the characters in a set
00041  *              of characters.
00042  */
00043 
00044 #include <fortran.h>
00045 #include <string.h>
00046 
00047 /*
00048  * This routine assumes that an eight-bit character can occur in
00049  * a string, i.e., the characters do not have to be 7-bit ASCII
00050  * codes.  Therefore, there are 256 entries rather than 128-bit
00051  * entries.
00052  *
00053  * The word size on mips platforms assumes a default integer is
00054  * always 32 bits.  The mips platform calls the 64-bit integer
00055  * entry point.  
00056  *
00057  *  WORDS  = number of the words needed to hold a flag for each
00058  *           of 256 different characters.
00059  *  BITS = number of bits in an integer 'word'.
00060  *  MASK = number of octal bits to use from the character.
00061  *  SHIFT = number of bits to shift the character to the right.
00062  */
00063 
00064 #if defined(__mips)
00065 #define WORDS           8
00066 #define BITS            31
00067 #define MASK            07
00068 #define SHIFT           3
00069 #elif !defined(_WORD32)
00070 #define WORDS           4
00071 #define BITS            63
00072 #define MASK            03
00073 #define SHIFT           2
00074 #else                           /* this includes little endian */
00075 #define WORDS           8
00076 #define BITS            31
00077 #define MASK            07
00078 #define SHIFT           3
00079 #endif
00080 
00081 #define FOUND(a)        (mask[a & MASK] << (a >> SHIFT)) < 0
00082 
00083 _f_int
00084 _SCAN (_fcd str1, _fcd str2, _f_log *back)
00085 {
00086         char    *ptr1, *ptr2;
00087         long    len1, len2;
00088         int     bck, num;
00089         _f_int  i;
00090         _f_int  mask[WORDS];
00091 
00092 /*      Determine direction to scan     */
00093 
00094 #ifndef _UNICOS
00095         if (back != NULL && _ltob(back))
00096             bck = 1;
00097         else
00098             bck = 0;
00099 #else
00100         num = _numargs();
00101 #ifdef _ADDR64
00102         if (num == 2 * sizeof(_fcd) / sizeof(long))
00103 #else
00104         if (num == 2)
00105 #endif
00106             bck = 0;
00107         else if (back == NULL)
00108             bck = 0;
00109         else if (_ltob(back))
00110             bck = 1;
00111         else
00112             bck = 0;
00113 #endif
00114 
00115 /*      Convert Fortran character descriptor to C pointers.     */
00116 
00117         len1 = _fcdlen (str1);
00118         ptr1 = _fcdtocp (str1);
00119 
00120         len2 = _fcdlen (str2);
00121         ptr2 = _fcdtocp (str2);
00122 
00123 /*      If either string is null, return 0      */
00124 
00125         if (len1 == 0 || len2 == 0)
00126             return (0);
00127 
00128 /*
00129  *      Initialize bit map to all 0's.  Then set bit for each character in
00130  *      search string.
00131  */
00132 
00133 #ifdef _UNICOS
00134 #pragma _CRI    shortloop
00135 #endif
00136         for (i = 0; i < WORDS; i++)
00137             mask[i] = 0;
00138         for (i = 0; i < len2; i++) 
00139             mask[ptr2[i] & MASK] |= 1 << (BITS - (ptr2[i] >> SHIFT));
00140 
00141 /*
00142  *      Step through string, and return index of first element in string
00143  *      which is also in search string.
00144  */
00145         if (!bck) {
00146             for (i = 0; i < len1; i++)
00147                 if (FOUND(ptr1[i]))
00148                     return (i+1);
00149         }
00150         else {
00151             for (i = len1-1; i >= 0; i--)
00152                 if (FOUND(ptr1[i]))
00153                     return (i+1);
00154         }
00155 
00156 /*      If no characters in search string are found, return 0   */
00157 
00158         return (0);
00159 }
00160 
00161 
00162 #ifdef  _F_INT4
00163 
00164 #undef  WORDS
00165 #undef  BITS
00166 #undef  MASK
00167 #undef  SHIFT
00168 
00169 #if defined(__mips)
00170 #define WORDS           8
00171 #define BITS            31
00172 #define MASK            07
00173 #define SHIFT           3
00174 #elif !defined(_WORD32)
00175 #define WORDS           4
00176 #define BITS            63
00177 #define MASK            03
00178 #define SHIFT           2
00179 #else                                   /* includes little endian */
00180 #define WORDS           8
00181 #define BITS            31
00182 #define MASK            07
00183 #define SHIFT           3
00184 #endif
00185 
00186 _f_int4
00187 _SCAN_4 (_fcd str1, _fcd str2, _f_log *back)
00188 {
00189         char    *ptr1, *ptr2;
00190         long    len1, len2;
00191         int     bck, num;
00192 #ifdef  _CRAYMPP
00193         _f_int  i;
00194         _f_int  mask[WORDS];
00195 #else
00196         _f_int4 i;
00197         _f_int4 mask[WORDS];
00198 #endif
00199 
00200 /*      Determine direction to scan     */
00201 
00202 #ifndef _UNICOS
00203         if (back != NULL && _ltob(back))
00204             bck = 1;
00205         else
00206             bck = 0;
00207 #else
00208         num = _numargs();
00209 #ifdef _ADDR64
00210         if (num == 2 * sizeof(_fcd) / sizeof(long))
00211 #else
00212         if (num == 2)
00213 #endif
00214             bck = 0;
00215         else if (back == NULL)
00216             bck = 0;
00217         else if (_ltob(back))
00218             bck = 1;
00219         else
00220             bck = 0;
00221 #endif
00222 
00223 /*      Convert Fortran character descriptor to C pointers.     */
00224 
00225         len1 = _fcdlen (str1);
00226         ptr1 = _fcdtocp (str1);
00227 
00228         len2 = _fcdlen (str2);
00229         ptr2 = _fcdtocp (str2);
00230 
00231 /*      If either string is null, return 0      */
00232 
00233         if (len1 == 0 || len2 == 0)
00234             return (0);
00235 
00236 /*
00237  *      Initialize bit map to all 0's.  Then set bit for each character in
00238  *      search string.
00239  */
00240 
00241 #ifdef _UNICOS
00242 #pragma _CRI    shortloop
00243 #endif
00244         for (i = 0; i < WORDS; i++)
00245             mask[i] = 0;
00246         for (i = 0; i < len2; i++) 
00247             mask[ptr2[i] & MASK] |= 1 << (BITS - (ptr2[i] >> SHIFT));
00248 
00249 /*
00250  *      Step through string, and return index of first element in string
00251  *      which is also in search string.
00252  */
00253         if (!bck) {
00254             for (i = 0; i < len1; i++)
00255                 if (FOUND(ptr1[i]))
00256                     return (i+1);
00257         }
00258         else {
00259             for (i = len1-1; i >= 0; i--)
00260                 if (FOUND(ptr1[i]))
00261                     return (i+1);
00262         }
00263 
00264 /*      If no characters in search string are found, return 0   */
00265 
00266         return (0);
00267 }
00268 #endif
00269 
00270 
00271 #ifdef  _F_INT8
00272 
00273 #undef  WORDS
00274 #undef  BITS
00275 #undef  MASK
00276 #undef  SHIFT
00277 #define WORDS           8
00278 #define BITS            63
00279 #define MASK            03
00280 #define SHIFT           2
00281 
00282 _f_int8
00283 _SCAN_8 (_fcd str1, _fcd str2, _f_log *back)
00284 {
00285         char    *ptr1, *ptr2;
00286         long    len1, len2;
00287         int     bck, num;
00288         _f_int8 i;
00289         _f_int8 mask[WORDS];
00290 
00291 /*      Determine direction to scan     */
00292 
00293 #ifndef _UNICOS
00294         if (back != NULL && _ltob(back))
00295             bck = 1;
00296         else
00297             bck = 0;
00298 #else
00299         num = _numargs();
00300 #ifdef _ADDR64
00301         if (num == 2 * sizeof(_fcd) / sizeof(long))
00302 #else
00303         if (num == 2)
00304 #endif
00305             bck = 0;
00306         else if (back == NULL)
00307             bck = 0;
00308         else if (_ltob(back))
00309             bck = 1;
00310         else
00311             bck = 0;
00312 #endif
00313 
00314 /*      Convert Fortran character descriptor to C pointers.     */
00315 
00316         len1 = _fcdlen (str1);
00317         ptr1 = _fcdtocp (str1);
00318 
00319         len2 = _fcdlen (str2);
00320         ptr2 = _fcdtocp (str2);
00321 
00322 /*      If either string is null, return 0      */
00323 
00324         if (len1 == 0 || len2 == 0)
00325             return (0);
00326 
00327 /*
00328  *      Initialize bit map to all 0's.  Then set bit for each character in
00329  *      search string.
00330  */
00331 
00332 #ifdef _UNICOS
00333 #pragma _CRI    shortloop
00334 #endif
00335         for (i = 0; i < WORDS; i++)
00336             mask[i] = 0;
00337         for (i = 0; i < len2; i++) 
00338             mask[ptr2[i] & MASK] |= 1 << (BITS - (ptr2[i] >> SHIFT));
00339 
00340 /*
00341  *      Step through string, and return index of first element in string
00342  *      which is also in search string.
00343  */
00344         if (!bck) {
00345             for (i = 0; i < len1; i++)
00346                 if (FOUND(ptr1[i]))
00347                     return (i+1);
00348         }
00349         else {
00350             for (i = len1-1; i >= 0; i--)
00351                 if (FOUND(ptr1[i]))
00352                     return (i+1);
00353         }
00354 
00355 /*      If no characters in search string are found, return 0   */
00356 
00357         return (0);
00358 }
00359 #endif
00360 
00361 #ifdef  _F_INT2
00362 
00363 #undef  WORDS
00364 #undef  BITS
00365 #undef  MASK
00366 #undef  SHIFT
00367 
00368 #if     defined(__mips) || defined(_LITTLE_ENDIAN)
00369 #define WORDS           16
00370 #define BITS            15
00371 #define MASK            017
00372 #define SHIFT           4
00373 #elif   !defined(_WORD32)
00374 #define WORDS           4
00375 #define BITS            63
00376 #define MASK            03
00377 #define SHIFT           2
00378 #else
00379 #define WORDS           8
00380 #define BITS            31
00381 #define MASK            07
00382 #define SHIFT           3
00383 #endif
00384 
00385 _f_int2
00386 _SCAN_2 (_fcd str1, _fcd str2, _f_log *back)
00387 {
00388         char    *ptr1, *ptr2;
00389         long    len1, len2;
00390         int     bck, num;
00391         _f_int2 i;
00392         _f_int2 mask[WORDS];
00393 
00394 /*      Determine direction to scan     */
00395 
00396 #ifndef _UNICOS
00397         if (back != NULL && _ltob(back))
00398             bck = 1;
00399         else
00400             bck = 0;
00401 #else
00402         num = _numargs();
00403 #ifdef _ADDR64
00404         if (num == 2 * sizeof(_fcd) / sizeof(long))
00405 #else
00406         if (num == 2)
00407 #endif
00408             bck = 0;
00409         else if (back == NULL)
00410             bck = 0;
00411         else if (_ltob(back))
00412             bck = 1;
00413         else
00414             bck = 0;
00415 #endif
00416 
00417 /*      Convert Fortran character descriptor to C pointers.     */
00418 
00419         len1 = _fcdlen (str1);
00420         ptr1 = _fcdtocp (str1);
00421 
00422         len2 = _fcdlen (str2);
00423         ptr2 = _fcdtocp (str2);
00424 
00425 /*      If either string is null, return 0      */
00426 
00427         if (len1 == 0 || len2 == 0)
00428             return (0);
00429 
00430 /*
00431  *      Initialize bit map to all 0's.  Then set bit for each character in
00432  *      search string.
00433  */
00434 
00435 #ifdef _UNICOS
00436 #pragma _CRI    shortloop
00437 #endif
00438         for (i = 0; i < WORDS; i++)
00439             mask[i] = 0;
00440         for (i = 0; i < len2; i++) 
00441             mask[ptr2[i] & MASK] |= 1 << (BITS - (ptr2[i] >> SHIFT));
00442 
00443 /*
00444  *      Step through string, and return index of first element in string
00445  *      which is also in search string.
00446  */
00447         if (!bck) {
00448             for (i = 0; i < len1; i++)
00449                 if (FOUND(ptr1[i]))
00450                     return (i+1);
00451         }
00452         else {
00453             for (i = len1-1; i >= 0; i--)
00454                 if (FOUND(ptr1[i]))
00455                     return (i+1);
00456         }
00457 
00458 /*      If no characters in search string are found, return 0   */
00459 
00460         return (0);
00461 }
00462 #endif  /* _F_INT2 */
00463 
00464 #ifdef  _F_INT1
00465 
00466 #undef  WORDS
00467 #undef  BITS
00468 #undef  MASK
00469 #undef  SHIFT
00470 
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 _SCAN_1 (_fcd str1, _fcd str2, _f_log *back)
00490 {
00491         char    *ptr1, *ptr2;
00492         long    len1, len2;
00493         int     bck, num;
00494         _f_int1 i;
00495         _f_int1 mask[WORDS];
00496 
00497 /*      Determine direction to scan     */
00498 
00499 #ifndef _UNICOS
00500         if (back != NULL && _ltob(back))
00501             bck = 1;
00502         else
00503             bck = 0;
00504 #else
00505         num = _numargs();
00506 #ifdef _ADDR64
00507         if (num == 2 * sizeof(_fcd) / sizeof(long))
00508 #else
00509         if (num == 2)
00510 #endif
00511             bck = 0;
00512         else if (back == NULL)
00513             bck = 0;
00514         else if (_ltob(back))
00515             bck = 1;
00516         else
00517             bck = 0;
00518 #endif
00519 
00520 /*      Convert Fortran character descriptor to C pointers.     */
00521 
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 0      */
00529 
00530         if (len1 == 0 || len2 == 0)
00531             return (0);
00532 
00533 /*
00534  *      Initialize bit map to all 0's.  Then set bit for each character in
00535  *      search string.
00536  */
00537 
00538 #ifdef _UNICOS
00539 #pragma _CRI    shortloop
00540 #endif
00541         for (i = 0; i < WORDS; i++)
00542             mask[i] = 0;
00543         for (i = 0; i < len2; i++) 
00544             mask[ptr2[i] & MASK] |= 1 << (BITS - (ptr2[i] >> SHIFT));
00545 
00546 /*
00547  *      Step through string, and return index of first element in string
00548  *      which is also in search string.
00549  */
00550         if (!bck) {
00551             for (i = 0; i < len1; i++)
00552                 if (FOUND(ptr1[i]))
00553                     return (i+1);
00554         }
00555         else {
00556             for (i = len1-1; i >= 0; i--)
00557                 if (FOUND(ptr1[i]))
00558                     return (i+1);
00559         }
00560 
00561 /*      If no characters in search string are found, return 0   */
00562 
00563         return (0);
00564 }
00565 #endif  /* _F_INT1 */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines