diff options
author | Joe Hunkeler <jhunkeler@gmail.com> | 2015-08-11 16:51:37 -0400 |
---|---|---|
committer | Joe Hunkeler <jhunkeler@gmail.com> | 2015-08-11 16:51:37 -0400 |
commit | 40e5a5811c6ffce9b0974e93cdd927cbcf60c157 (patch) | |
tree | 4464880c571602d54f6ae114729bf62a89518057 /sys/fmtio/strsearch.x | |
download | iraf-osx-40e5a5811c6ffce9b0974e93cdd927cbcf60c157.tar.gz |
Repatch (from linux) of OSX IRAF
Diffstat (limited to 'sys/fmtio/strsearch.x')
-rw-r--r-- | sys/fmtio/strsearch.x | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/sys/fmtio/strsearch.x b/sys/fmtio/strsearch.x new file mode 100644 index 00000000..e3006ed8 --- /dev/null +++ b/sys/fmtio/strsearch.x @@ -0,0 +1,55 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +# STRSEARCH -- Search a string for a substring. This is the simplest and +# fastest member of the pattern matching family. A significant increase in +# efficiency will result if this procedure is used to search for substrings +# that do not use any metacharacters. + +int procedure strsearch (str, patstr) + +char str[ARB] # string to be searched +char patstr[ARB] # substring to search for + +int first_char, ch +int ip, patlen +bool strse1() + +begin + # The null pattern matches any string. + if (patstr[1] == EOS) + return (1) + + first_char = patstr[1] + + do ip = 1, ARB { + ch = str[ip] + if (ch == EOS) + break + if (ch == first_char) + if (strse1 (str[ip], patstr, patlen)) + return (ip + patlen) + } + + return (0) +end + + +# STRSE1 -- Internal routine which compares a substring of the first string +# with the pattern string. STREQ cannot be used because it does not give a +# match unless the two strings have the same length. + +bool procedure strse1 (str, patstr, patlen) + +char str[ARB] +char patstr[ARB] +int patlen +int ip + +begin + do ip = 1, ARB + if (patstr[ip] == EOS || str[ip] != patstr[ip]) + break + + patlen = ip - 1 + return (patstr[ip] == EOS) +end |