aboutsummaryrefslogtreecommitdiff
path: root/sys/mwcs/mwrefstr.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/mwcs/mwrefstr.x
downloadiraf-osx-40e5a5811c6ffce9b0974e93cdd927cbcf60c157.tar.gz
Repatch (from linux) of OSX IRAF
Diffstat (limited to 'sys/mwcs/mwrefstr.x')
-rw-r--r--sys/mwcs/mwrefstr.x55
1 files changed, 55 insertions, 0 deletions
diff --git a/sys/mwcs/mwrefstr.x b/sys/mwcs/mwrefstr.x
new file mode 100644
index 00000000..07385976
--- /dev/null
+++ b/sys/mwcs/mwrefstr.x
@@ -0,0 +1,55 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include "mwcs.h"
+
+# MW_REFSTR -- Search the string buffer for the named string and return the
+# string offset if found, otherwise enter the new string and return its
+# offset. This is used to avoid storing the same string many times, but
+# use of this technique means that string data cannot be modified once
+# entered.
+
+int procedure mw_refstr (mw, str)
+
+pointer mw #I pointer to MWCS descriptor
+char str[ARB] #I string to be referenced or entered
+
+bool match
+pointer sbuf, btop, ip
+int nchars, off, ch, i
+int strlen(), mw_allocs()
+errchk mw_allocs
+
+begin
+ sbuf = MI_SBUF(mw)
+ btop = sbuf + MI_SBUFLEN(mw)
+ nchars = strlen (str)
+
+ # Search the string buffer for the given string.
+ match = false
+ if (sbuf != NULL)
+ for (ip=sbuf; !match && ip < btop; ) {
+ match = true
+ do i = 1, btop-ip {
+ ch = Memc[ip+i-1]
+ if (i <= nchars)
+ if (ch != str[i])
+ match = false
+ if (ch == EOS) {
+ if (!match)
+ ip = ip + i
+ break
+ }
+ }
+ if (ch != EOS)
+ break
+ }
+
+ # Add the string if not found.
+ if (!match) {
+ off = mw_allocs (mw, nchars)
+ call strcpy (str, S(mw,off), nchars)
+ } else
+ off = ip - sbuf + 1
+
+ return (off)
+end