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/index.c 92.1 07/08/99 10:41:51" 00038 00039 /* 00040 * INDEX - Returns the starting position of a substring within 00041 * a string. 00042 */ 00043 00044 #include <fortran.h> 00045 #include <string.h> 00046 #include <stddef.h> 00047 #include <cray/portdefs.h> 00048 00049 /* 00050 * Duplicate names 00051 * 00052 * _INDEX - for f90 intrinsic when explicitly called 00053 * $INDEX - for cf77 intrinsic 00054 * INDEX - for cf77 when declared EXTERNAL (necessary to permit 00055 * passing the optional argument with cf77). 00056 * 00057 * The F90 compiler generates a call to _INDEX to process explicit 00058 * calls to the INDEX intrinsic, which have one optional argument. 00059 */ 00060 #ifdef _UNICOS 00061 #pragma _CRI duplicate _INDEX as $INDEX 00062 #pragma _CRI duplicate _INDEX as INDEX 00063 #endif 00064 00065 _f_int 00066 _INDEX( 00067 _fcd fstr1, 00068 _fcd fstr2, 00069 _f_log *fback) /* NULL if argument not passed */ 00070 { 00071 register short forward; /* Nonzero if searching forward */ 00072 register long indx; /* Position where substring located */ 00073 register long len1, len2; 00074 char *str1, *str2; 00075 00076 indx = 0; /* Assume substring not found */ 00077 forward = 1; /* Assume forward search */ 00078 00079 /* Check if backwards search */ 00080 00081 #if defined(_UNICOS) && defined(_ADDR64) 00082 if ((_numargs() > 2 * sizeof(_fcd) / sizeof(long)) && fback != NULL && 00083 _ltob(fback)) 00084 #elif defined(_UNICOS) 00085 if (_numargs() > 2 && fback != NULL && _ltob(fback)) 00086 #else 00087 if (fback != NULL && _ltob(fback)) 00088 #endif 00089 forward = 0; 00090 00091 /* Convert Fortran character descriptors to C pointers and lengths */ 00092 00093 str1 = _fcdtocp(fstr1); 00094 str2 = _fcdtocp(fstr2); 00095 00096 len1 = _fcdlen (fstr1); 00097 len2 = _fcdlen (fstr2); 00098 00099 if (len1 >= len2) { /* If string can at least hold substring */ 00100 char *offset; /* Offset of substring */ 00101 00102 if (len2 == 1 && forward) /* Optimize this common case */ 00103 offset = memchr(str1, (int) *str2, len1); 00104 else 00105 offset = forward ? 00106 strnstrn (str1, len1, str2, len2) : 00107 strnrstrn(str1, len1, str2, len2); 00108 00109 if (offset != NULL) /* If substring found */ 00110 indx = 1 + (offset - str1); 00111 00112 } 00113 00114 return ((_f_int) indx); 00115 } 00116 00117 /* 00118 * _INDEX_ - for f90 intrinsic when passed as an argument 00119 * 00120 * The implicit call to the INDEX intrinsic in these cases (through 00121 * _INDEX_) must be made with only two arguments. This minimal 00122 * support for passing INDEX as an actual argument is in Fortran 90 00123 * for upward compatibility with the Fortran 77 standard. 00124 */ 00125 _f_int 00126 _INDEX_( 00127 _fcd fstr1, 00128 _fcd fstr2) 00129 { 00130 return( _INDEX(fstr1, fstr2, NULL)); /* Only two arguments passed */ 00131 } 00132 00133 00134 #ifdef _F_INT4 00135 /* 00136 * Duplicate names 00137 * 00138 * _INDEX_4 - for f90 intrinsic when explicitly called 00139 * $INDEX_4 - for cf77 intrinsic 00140 * INDEX_4 - for cf77 when declared EXTERNAL (necessary to permit 00141 * passing the optional argument with cf77). 00142 * 00143 * The F90 compiler generates a call to _INDEX to process explicit 00144 * calls to the INDEX intrinsic, which have one optional argument. 00145 */ 00146 #ifdef _UNICOS 00147 #pragma _CRI duplicate _INDEX_4 as $INDEX_4 00148 #pragma _CRI duplicate _INDEX_4 as INDEX_4 00149 #endif 00150 00151 _f_int4 00152 _INDEX_4( 00153 _fcd fstr1, 00154 _fcd fstr2, 00155 _f_log *fback) /* NULL if argument not passed */ 00156 { 00157 register short forward; /* Nonzero if searching forward */ 00158 register long indx; /* Position where substring located */ 00159 register long len1, len2; 00160 char *str1, *str2; 00161 00162 indx = 0; /* Assume substring not found */ 00163 forward = 1; /* Assume forward search */ 00164 00165 /* Check if backwards search */ 00166 00167 #if defined(_UNICOS) && defined(_ADDR64) 00168 if ((_numargs() > 2 * sizeof(_fcd) / sizeof(long)) && fback != NULL && 00169 _ltob(fback)) 00170 #elif defined(_UNICOS) 00171 if (_numargs() > 2 && fback != NULL && _ltob(fback)) 00172 #else 00173 if (fback != NULL && _ltob(fback)) 00174 #endif 00175 forward = 0; 00176 00177 /* Convert Fortran character descriptors to C pointers and lengths */ 00178 00179 str1 = _fcdtocp(fstr1); 00180 str2 = _fcdtocp(fstr2); 00181 00182 len1 = _fcdlen (fstr1); 00183 len2 = _fcdlen (fstr2); 00184 00185 if (len1 >= len2) { /* If string can at least hold substring */ 00186 char *offset; /* Offset of substring */ 00187 00188 if (len2 == 1 && forward) /* Optimize this common case */ 00189 offset = memchr(str1, (int) *str2, len1); 00190 else 00191 offset = forward ? 00192 strnstrn (str1, len1, str2, len2) : 00193 strnrstrn(str1, len1, str2, len2); 00194 00195 if (offset != NULL) /* If substring found */ 00196 indx = 1 + (offset - str1); 00197 00198 } 00199 00200 return ((_f_int4) indx); 00201 } 00202 00203 /* 00204 * _INDEX_4_ - for f90 intrinsic when passed as an argument 00205 * 00206 * The implicit call to the INDEX_4 intrinsic in these cases (through 00207 * _INDEX_4_) must be made with only two arguments. This minimal 00208 * support for passing INDEX_4 as an actual argument is in Fortran 90 00209 * for upward compatibility with the Fortran 77 standard. 00210 */ 00211 _f_int4 00212 _INDEX_4_( 00213 _fcd fstr1, 00214 _fcd fstr2) 00215 { 00216 return( _INDEX_4(fstr1, fstr2, NULL)); /* Only two arguments passed */ 00217 } 00218 #endif 00219 00220 00221 #ifdef _F_INT8 00222 /* 00223 * Duplicate names 00224 * 00225 * _INDEX_8 - for f90 intrinsic when explicitly called 00226 * $INDEX_8 - for cf77 intrinsic 00227 * INDEX_8 - for cf77 when declared EXTERNAL (necessary to permit 00228 * passing the optional argument with cf77). 00229 * 00230 * The F90 compiler generates a call to _INDEX_8 to process explicit 00231 * calls to the INDEX intrinsic, which have one optional argument. 00232 */ 00233 #ifdef _UNICOS 00234 #pragma _CRI duplicate _INDEX_8 as $INDEX_8 00235 #pragma _CRI duplicate _INDEX_8 as INDEX_8 00236 #endif 00237 00238 _f_int8 00239 _INDEX_8( 00240 _fcd fstr1, 00241 _fcd fstr2, 00242 _f_log *fback) /* NULL if argument not passed */ 00243 { 00244 register long indx; /* Position where substring located */ 00245 register long len1, len2; 00246 register short forward; /* Nonzero if searching forward */ 00247 char *str1, *str2; 00248 00249 indx = 0; /* Assume substring not found */ 00250 forward = 1; /* Assume forward search */ 00251 00252 /* Check if backwards search */ 00253 00254 #if defined(_UNICOS) && defined(_ADDR64) 00255 if ((_numargs() > 2 * sizeof(_fcd) / sizeof(long)) && fback != NULL && 00256 _ltob(fback)) 00257 #elif defined(_UNICOS) 00258 if (_numargs() > 2 && fback != NULL && _ltob(fback)) 00259 #else 00260 if (fback != NULL && _ltob(fback)) 00261 #endif 00262 forward = 0; 00263 00264 /* Convert Fortran character descriptors to C pointers and lengths */ 00265 00266 str1 = _fcdtocp(fstr1); 00267 str2 = _fcdtocp(fstr2); 00268 00269 len1 = _fcdlen (fstr1); 00270 len2 = _fcdlen (fstr2); 00271 00272 if (len1 >= len2) { /* If string can at least hold substring */ 00273 char *offset; /* Offset of substring */ 00274 00275 if (len2 == 1 && forward) /* Optimize this common case */ 00276 offset = memchr(str1, (int) *str2, len1); 00277 else 00278 offset = forward ? 00279 strnstrn (str1, len1, str2, len2) : 00280 strnrstrn(str1, len1, str2, len2); 00281 00282 if (offset != NULL) /* If substring found */ 00283 indx = 1 + (offset - str1); 00284 00285 } 00286 00287 return ((_f_int8) indx); 00288 } 00289 00290 /* 00291 * _INDEX_8_ - for f90 intrinsic when passed as an argument 00292 * 00293 * The implicit call to the INDEX_8 intrinsic in these cases (through 00294 * _INDEX_8_) must be made with only two arguments. This minimal 00295 * support for passing INDEX as an actual argument is in Fortran 90 00296 * for upward compatibility with the Fortran 77 standard. 00297 */ 00298 _f_int8 00299 _INDEX_8_( 00300 _fcd fstr1, 00301 _fcd fstr2) 00302 { 00303 return( _INDEX_8(fstr1, fstr2, NULL)); /* Only two arguments passed */ 00304 } 00305 #endif 00306 00307 #ifdef _F_INT2 00308 /* 00309 * Duplicate names 00310 * 00311 * _INDEX_2 - for f90 intrinsic when explicitly called 00312 * 00313 * The F90 compiler generates a call to _INDEX to process explicit 00314 * calls to the INDEX intrinsic, which have one optional argument. 00315 */ 00316 _f_int2 00317 _INDEX_2( 00318 _fcd fstr1, 00319 _fcd fstr2, 00320 _f_log *fback) /* NULL if argument not passed */ 00321 { 00322 register short forward; /* Nonzero if searching forward */ 00323 register long indx; /* Position where substring located */ 00324 register long len1, len2; 00325 char *str1, *str2; 00326 00327 indx = 0; /* Assume substring not found */ 00328 forward = 1; /* Assume forward search */ 00329 00330 /* Check if backwards search */ 00331 00332 #if defined(_UNICOS) && defined(_ADDR64) 00333 if ((_numargs() > 2 * sizeof(_fcd) / sizeof(long)) && fback != NULL && 00334 _ltob(fback)) 00335 #elif defined(_UNICOS) 00336 if (_numargs() > 2 && fback != NULL && _ltob(fback)) 00337 #else 00338 if (fback != NULL && _ltob(fback)) 00339 #endif 00340 forward = 0; 00341 00342 /* Convert Fortran character descriptors to C pointers and lengths */ 00343 00344 str1 = _fcdtocp(fstr1); 00345 str2 = _fcdtocp(fstr2); 00346 00347 len1 = _fcdlen (fstr1); 00348 len2 = _fcdlen (fstr2); 00349 00350 if (len1 >= len2) { /* If string can at least hold substring */ 00351 char *offset; /* Offset of substring */ 00352 00353 if (len2 == 1 && forward) /* Optimize this common case */ 00354 offset = memchr(str1, (int) *str2, len1); 00355 else 00356 offset = forward ? 00357 strnstrn (str1, len1, str2, len2) : 00358 strnrstrn(str1, len1, str2, len2); 00359 00360 if (offset != NULL) /* If substring found */ 00361 indx = 1 + (offset - str1); 00362 00363 } 00364 00365 return ((_f_int2) indx); 00366 } 00367 00368 /* 00369 * _INDEX_2_ - for f90 intrinsic when passed as an argument 00370 * 00371 * The implicit call to the INDEX_2 intrinsic in these cases (through 00372 * _INDEX_2_) must be made with only two arguments. This minimal 00373 * support for passing INDEX_2 as an actual argument is in Fortran 90 00374 * for upward compatibility with the Fortran 77 standard. 00375 */ 00376 _f_int2 00377 _INDEX_2_( 00378 _fcd fstr1, 00379 _fcd fstr2) 00380 { 00381 return( _INDEX_2(fstr1, fstr2, NULL)); /* Only two arguments passed */ 00382 } 00383 #endif 00384 00385 #ifdef _F_INT1 00386 /* 00387 * Duplicate names 00388 * 00389 * _INDEX_1 - for f90 intrinsic when explicitly called 00390 * 00391 * The F90 compiler generates a call to _INDEX to process explicit 00392 * calls to the INDEX intrinsic, which have one optional argument. 00393 */ 00394 _f_int1 00395 _INDEX_1( 00396 _fcd fstr1, 00397 _fcd fstr2, 00398 _f_log *fback) /* NULL if argument not passed */ 00399 { 00400 register short forward; /* Nonzero if searching forward */ 00401 register long indx; /* Position where substring located */ 00402 register long len1, len2; 00403 char *str1, *str2; 00404 00405 indx = 0; /* Assume substring not found */ 00406 forward = 1; /* Assume forward search */ 00407 00408 /* Check if backwards search */ 00409 00410 #if defined(_UNICOS) && defined(_ADDR64) 00411 if ((_numargs() > 2 * sizeof(_fcd) / sizeof(long)) && fback != NULL && 00412 _ltob(fback)) 00413 #elif defined(_UNICOS) 00414 if (_numargs() > 2 && fback != NULL && _ltob(fback)) 00415 #else 00416 if (fback != NULL && _ltob(fback)) 00417 #endif 00418 forward = 0; 00419 00420 /* Convert Fortran character descriptors to C pointers and lengths */ 00421 00422 str1 = _fcdtocp(fstr1); 00423 str2 = _fcdtocp(fstr2); 00424 00425 len1 = _fcdlen (fstr1); 00426 len2 = _fcdlen (fstr2); 00427 00428 if (len1 >= len2) { /* If string can at least hold substring */ 00429 char *offset; /* Offset of substring */ 00430 00431 if (len2 == 1 && forward) /* Optimize this common case */ 00432 offset = memchr(str1, (int) *str2, len1); 00433 else 00434 offset = forward ? 00435 strnstrn (str1, len1, str2, len2) : 00436 strnrstrn(str1, len1, str2, len2); 00437 00438 if (offset != NULL) /* If substring found */ 00439 indx = 1 + (offset - str1); 00440 00441 } 00442 00443 return ((_f_int1) indx); 00444 } 00445 00446 /* 00447 * _INDEX_1_ - for f90 intrinsic when passed as an argument 00448 * 00449 * The implicit call to the INDEX_1 intrinsic in these cases (through 00450 * _INDEX_1_) must be made with only two arguments. This minimal 00451 * support for passing INDEX_1 as an actual argument is in Fortran 90 00452 * for upward compatibility with the Fortran 77 standard. 00453 */ 00454 _f_int1 00455 _INDEX_1_( 00456 _fcd fstr1, 00457 _fcd fstr2) 00458 { 00459 return( _INDEX_1(fstr1, fstr2, NULL)); /* Only two arguments passed */ 00460 } 00461 #endif