aboutsummaryrefslogtreecommitdiff
path: root/pkg/xtools/inlfit/inlstrext.x
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2015-07-08 20:46:52 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2015-07-08 20:46:52 -0400
commitfa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 (patch)
treebdda434976bc09c864f2e4fa6f16ba1952b1e555 /pkg/xtools/inlfit/inlstrext.x
downloadiraf-linux-fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4.tar.gz
Initial commit
Diffstat (limited to 'pkg/xtools/inlfit/inlstrext.x')
-rw-r--r--pkg/xtools/inlfit/inlstrext.x47
1 files changed, 47 insertions, 0 deletions
diff --git a/pkg/xtools/inlfit/inlstrext.x b/pkg/xtools/inlfit/inlstrext.x
new file mode 100644
index 00000000..b2b071d9
--- /dev/null
+++ b/pkg/xtools/inlfit/inlstrext.x
@@ -0,0 +1,47 @@
+include <ctype.h>
+
+# INLSTREXT - Extract a word (delimited substring) from a string.
+# The input string is scanned from the given initial value until one
+# of the delimiters is found. The delimiters are not included in the
+# output word.
+# Leading white spaces in a word may be optionally skipped. White
+# spaces are skipped before looking at the delimiters string, so it's
+# possible to remove leading white spaces and use them as delimiters
+# at the same time.
+# The value returned is the number of characters in the output string.
+# Upon return, the pointer is located at the begining of the next word.
+
+int procedure inlstrext (str, ip, dict, skip, outstr, maxch)
+
+char str[ARB] # input string
+int ip # pointer into input string
+char dict[ARB] # dictionary of delimiters
+int skip # skip leading white spaces ?
+char outstr[ARB] # extracted word
+int maxch # max number of chars
+
+int op
+int stridx()
+
+begin
+ # Skip leading white spaces
+ if (skip == YES) {
+ while (IS_WHITE (str[ip]))
+ ip = ip + 1
+ }
+
+ # Process input string
+ for (op=1; str[ip] != EOS && op <= maxch; op=op+1)
+ if (stridx (str[ip], dict) == 0) {
+ outstr[op] = str[ip]
+ ip = ip + 1
+ } else {
+ repeat {
+ ip = ip + 1
+ } until (stridx (str[ip], dict) == 0 || str[ip] == EOS)
+ break
+ }
+
+ outstr[op] = EOS
+ return (op - 1)
+end