aboutsummaryrefslogtreecommitdiff
path: root/sys/imio/imt/imxescape.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 /sys/imio/imt/imxescape.x
downloadiraf-linux-fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4.tar.gz
Initial commit
Diffstat (limited to 'sys/imio/imt/imxescape.x')
-rw-r--r--sys/imio/imt/imxescape.x74
1 files changed, 74 insertions, 0 deletions
diff --git a/sys/imio/imt/imxescape.x b/sys/imio/imt/imxescape.x
new file mode 100644
index 00000000..92750ab7
--- /dev/null
+++ b/sys/imio/imt/imxescape.x
@@ -0,0 +1,74 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include "imx.h"
+
+
+# IMX_ESCAPE -- Return a pointer to the composed file name, escaping parts
+# as needed.
+
+pointer procedure imx_escape (in, index, extname, extver, ikparams,
+ section, expr, maxch)
+
+char in[ARB] #I File image name (without kernel or image sec)
+char index[ARB] #I Range list of extension indexes
+char extname[ARB] #I Pattern for extension names
+char extver[ARB] #I Range list of extension versions
+char ikparams[ARB] #I Image kernel parameters
+char section[ARB] #I Image section
+char expr[ARB] #I Selection expression
+int maxch #I Print errors?
+
+pointer out, op
+int i, len, level
+char ch, peek, prev
+bool init_esc
+
+int strlen()
+
+define output {Memc[op]=$1;op=op+1}
+define escape {output('\\');output($1)}
+
+begin
+ len = max (SZ_LINE, strlen (in))
+ call calloc (out, max (SZ_LINE, (4*len)), TY_CHAR)
+
+ op = out
+ level = 0
+
+ init_esc = false
+ for (i=1; i <= len; i=i+1) {
+ prev = in[max(1,i)]
+ ch = in[i]
+ peek = in[i+1]
+
+ if (ch == EOS)
+ break;
+ if (ch == '[') {
+ if (prev != ']' && !init_esc) {
+ output ('%')
+ output ('%')
+ output (CH_DELIM)
+ init_esc = true
+ }
+ escape (ch)
+ level = level + 1
+ } else if (ch == ']') {
+ output (ch)
+ if (peek != '[') # closing delim
+ output ('%')
+ level = level - 1
+ } else if (ch == ',') {
+ if (level > 0)
+ output('\\')
+ if (level == 0)
+ init_esc = false
+ output (ch)
+ } else if (ch == '*')
+ escape (ch)
+ else
+ output (ch)
+ }
+ output (EOS)
+
+ return (out)
+end