aboutsummaryrefslogtreecommitdiff
path: root/sys/qpoe/qpexpand.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/qpoe/qpexpand.x
downloadiraf-osx-40e5a5811c6ffce9b0974e93cdd927cbcf60c157.tar.gz
Repatch (from linux) of OSX IRAF
Diffstat (limited to 'sys/qpoe/qpexpand.x')
-rw-r--r--sys/qpoe/qpexpand.x60
1 files changed, 60 insertions, 0 deletions
diff --git a/sys/qpoe/qpexpand.x b/sys/qpoe/qpexpand.x
new file mode 100644
index 00000000..9be19a36
--- /dev/null
+++ b/sys/qpoe/qpexpand.x
@@ -0,0 +1,60 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include "qpoe.h"
+
+# QP_EXPANDTEXT -- Copy a statement to the output, breaking it up into tokens
+# and expanding any macro references in the process. This is used to resolve
+# macro references which might otherwise be repeatedly expanded, or which it
+# might not be possible to expand if this is left to some future time when
+# the referenced macros are no longer defined.
+
+int procedure qp_expandtext (qp, s1, s2, maxch)
+
+pointer qp #I QPOE descriptor
+char s1[ARB] #I input string containing macros
+char s2[maxch] #O output string buffer
+int maxch #I max chars out
+
+pointer sp, tokbuf, in
+int token, op, otop
+int gstrcpy(), qp_gettok()
+pointer qp_opentext()
+
+begin
+ call smark (sp)
+ call salloc (tokbuf, SZ_TOKBUF, TY_CHAR)
+
+ # Open input text for macro expanded token input.
+ in = qp_opentext (qp, s1)
+ otop = maxch + 1
+ op = 1
+
+ # Copy tokens to the output, inserting a space after every token.
+ repeat {
+ token = qp_gettok (in, Memc[tokbuf], SZ_TOKBUF)
+ if (token != EOF) {
+ if (token == TOK_STRING) {
+ s2[op] = '"'
+ op = min (otop, op + 1)
+ }
+ op = op + gstrcpy (Memc[tokbuf], s2[op], otop-op)
+ if (token == TOK_STRING) {
+ s2[op] = '"'
+ op = min (otop, op + 1)
+ }
+ s2[op] = ' '; op = min (otop, op + 1)
+ if (op >= otop)
+ break
+ }
+ } until (token == EOF)
+
+ # Cancel the trailing blank and add the EOS.
+ if (op > 1 && op < otop)
+ op = op - 1
+ s2[op] = EOS
+
+ call qp_closetext (in)
+ call sfree (sp)
+
+ return (op - 1)
+end