aboutsummaryrefslogtreecommitdiff
path: root/pkg/system/help/getoption.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 /pkg/system/help/getoption.x
downloadiraf-osx-40e5a5811c6ffce9b0974e93cdd927cbcf60c157.tar.gz
Repatch (from linux) of OSX IRAF
Diffstat (limited to 'pkg/system/help/getoption.x')
-rw-r--r--pkg/system/help/getoption.x52
1 files changed, 52 insertions, 0 deletions
diff --git a/pkg/system/help/getoption.x b/pkg/system/help/getoption.x
new file mode 100644
index 00000000..a7504531
--- /dev/null
+++ b/pkg/system/help/getoption.x
@@ -0,0 +1,52 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <ctype.h>
+include "help.h"
+
+# GET_OPTION -- Map the possibly abbreviated option string into an integer
+# option code. It is an error if the abbreviation is not unique.
+
+define EQUAL 0
+
+int procedure get_option (opstr)
+
+char opstr[ARB] # option string, always lower case
+int keycode[MAX_OPTIONS]
+int oplen, key, ip, match
+int strlen(), strncmp()
+
+string keywords "help|sources|sysdoc|alldoc|files|summary|directory|references"
+data keycode /O_HELP,O_SOURCE,O_SYSDOC,O_ALLDOC,O_FILES,O_SUMMARY,O_DIR,
+ O_REFERENCES/
+
+begin
+ oplen = strlen (opstr)
+ ip = 1
+ match = 0
+
+ # Search the keyword table. If the option string matches a keyword,
+ # it is either an exact match (oplen = keyword length) or a legal
+ # abbreviation. If an abbreviation matches two keywords it is
+ # ambiguous and an error.
+
+ for (key=1; keywords[ip] != EOS; key=key+1) {
+ if (strncmp (keywords[ip], opstr, oplen) == EQUAL) {
+ if (keywords[ip+oplen] == '|')
+ return (keycode[key]) # exact match
+ else {
+ if (match != 0)
+ call error (1, "ambiguous help option abbreviation")
+ else
+ match = key
+ }
+ }
+ repeat {
+ ip = ip + 1
+ } until (keywords[ip-1] == '|' || keywords[ip] == EOS)
+ }
+
+ if (match == 0)
+ call error (2, "unknown help option")
+ else
+ return (keycode[match])
+end