diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2015-07-08 20:46:52 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2015-07-08 20:46:52 -0400 |
commit | fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 (patch) | |
tree | bdda434976bc09c864f2e4fa6f16ba1952b1e555 /sys/qpoe/qpparse.x | |
download | iraf-linux-fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4.tar.gz |
Initial commit
Diffstat (limited to 'sys/qpoe/qpparse.x')
-rw-r--r-- | sys/qpoe/qpparse.x | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/sys/qpoe/qpparse.x b/sys/qpoe/qpparse.x new file mode 100644 index 00000000..2bbd5cea --- /dev/null +++ b/sys/qpoe/qpparse.x @@ -0,0 +1,70 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <ctype.h> + +# QP_PARSE -- Parse a QPOE/QPIO specification into the root (poefile) name +# and event list filter expression fields. +# +# Syntax: root[filter] +# +# where the filter spec is optional. + +procedure qp_parse (qpspec, root, sz_root, filter, sz_filter) + +char qpspec[ARB] #I full event list specification +char root[sz_root] #O receives root name +int sz_root #I max chars in root name +char filter[sz_filter] #O receives filter +int sz_filter #I max chars in filter name + +int level, ip, op, ch + +begin + ip = 1 + op = 1 + + # Extract root name. The first (unescaped) [ marks the start of + # the filter field. + + for (ch=qpspec[ip]; ch != EOS && ch != '['; ch=qpspec[ip]) { + if (ch == '\\' && qpspec[ip+1] == '[') { + root[op] = '\\' + op = op + 1 + root[op] = '[' + ip = ip + 1 + } else + root[op] = ch + + op = min (sz_root, op + 1) + ip = ip + 1 + } + + root[op] = EOS + level = 0 + op = 1 + + # Extract the [] bracketed filter expression, allowing for nested + # brackets. + + for (ch=qpspec[ip]; ch != EOS; ch=qpspec[ip]) { + if (ch == '[') + level = level + 1 + else if (ch == ']') + level = level - 1 + + filter[op] = ch + op = min (sz_filter, op + 1) + + ip = ip + 1 + if (level <= 0) + break + } + + # Add closing brace if the user left it off. + if (op > 1 && ch != ']') { + filter[op] = ']' + op = min (sz_filter, op + 1) + } + + filter[op] = EOS +end |