aboutsummaryrefslogtreecommitdiff
path: root/sys/fmtio/strdic.x
diff options
context:
space:
mode:
authorJoe Hunkeler <jhunkeler@gmail.com>2015-08-11 16:51:37 -0400
committerJoe Hunkeler <jhunkeler@gmail.com>2015-08-11 16:51:37 -0400
commit40e5a5811c6ffce9b0974e93cdd927cbcf60c157 (patch)
tree4464880c571602d54f6ae114729bf62a89518057 /sys/fmtio/strdic.x
downloadiraf-osx-40e5a5811c6ffce9b0974e93cdd927cbcf60c157.tar.gz
Repatch (from linux) of OSX IRAF
Diffstat (limited to 'sys/fmtio/strdic.x')
-rw-r--r--sys/fmtio/strdic.x73
1 files changed, 73 insertions, 0 deletions
diff --git a/sys/fmtio/strdic.x b/sys/fmtio/strdic.x
new file mode 100644
index 00000000..3da4a71b
--- /dev/null
+++ b/sys/fmtio/strdic.x
@@ -0,0 +1,73 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <ctype.h>
+
+# STRDIC -- Search a dictionary string for a match with an input string.
+# The input string may be an abbreviation of a dictionary entry, however,
+# it is an error if the abbreviation is not unique. The entries in the
+# dictionary string are separated by a delimiter character which is the first
+# character of the dictionary string. The full name of the matched dictionary
+# entry found is returned in out_str; the function value is the word index of
+# the dictionary entry. The output string may be the same as the input string.
+
+int procedure strdic (in_str, out_str, maxchars, dict)
+
+char in_str[ARB] # Input string, always lower case
+char out_str[ARB] # Output string as found in dictionary
+int maxchars # Maximum length of output string
+char dict[ARB] # Dictionary string
+
+char ch, fch
+int start, len, ip, i, match, entry
+int strlen(), strncmp()
+
+begin
+ if (dict[1] == EOS)
+ return (0)
+
+ for (i=1; IS_WHITE (in_str[i]); i=i+1)
+ ;
+
+ start = i
+ match = 0
+ ip = 2
+ len = strlen (in_str[start])
+ fch = in_str[start]
+
+ # Search the dictionary string. If the input string matches a
+ # dictionary entry it is either an exact match (len = dictionary
+ # entry length) or a legal abbreviation. If an abbreviation
+ # matches two entries it is ambiguous and an error.
+
+ for (entry=1; dict[ip] != EOS; entry=entry+1) {
+ if (dict[ip] == fch) {
+ if (strncmp (dict[ip], in_str[start], len) == 0) {
+ for (i=1; i <= maxchars; i=i+1) {
+ ch = dict[ip+i-1]
+ if ((ch == dict[1]) || (ch == EOS))
+ break
+ out_str[i] = ch
+ }
+ out_str[i] = EOS
+
+ if ((dict[ip+len] == dict[1]) || (dict[ip+len] == EOS))
+ return (entry) # exact match
+ else {
+ # If we already have a match and the new match is not
+ # exact, then the abbreviation is ambiguous.
+
+ if (match != 0)
+ return (0)
+ else
+ match = entry
+ }
+ }
+ }
+
+ repeat {
+ ip = ip + 1
+ } until (dict[ip-1] == dict[1] || dict[ip] == EOS)
+ }
+
+ return (match)
+end