aboutsummaryrefslogtreecommitdiff
path: root/pkg/xtools/xttxtfio.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 /pkg/xtools/xttxtfio.x
downloadiraf-osx-40e5a5811c6ffce9b0974e93cdd927cbcf60c157.tar.gz
Repatch (from linux) of OSX IRAF
Diffstat (limited to 'pkg/xtools/xttxtfio.x')
-rw-r--r--pkg/xtools/xttxtfio.x71
1 files changed, 71 insertions, 0 deletions
diff --git a/pkg/xtools/xttxtfio.x b/pkg/xtools/xttxtfio.x
new file mode 100644
index 00000000..88296670
--- /dev/null
+++ b/pkg/xtools/xttxtfio.x
@@ -0,0 +1,71 @@
+define TXT_MAXFD 64 # Maximum FD for stropen.
+
+
+# XT_TXTOPEN -- Open a READ_ONLY text file which is possibly compiled into a
+# procedure.
+#
+# This is used to allow text files to be incorported in binaries but still use
+# FIO. The text file must be compiled into a program which is linked with
+# into the binary (see txtcompile). A file name of the form proc:nnnn, where
+# nnnn is a number returned by locpr, calls the procedure which is expected to
+# allocate a string buffer. In this case the string buffer is opened with
+# stropen. Any other file name is opened as a READ_ONLY TEXT_FILE with
+# normal FIO.
+
+int procedure xt_txtopen (fname)
+
+char fname[ARB] #I File name or proc:nnnn reference
+int fd #R Null to open and non-null to close
+
+int ip, procptr, strncmp(), ctoi(), open(), stropen()
+pointer strbuf
+errchk zcall1, open, stropen
+
+int firsttime
+data firsttime/YES/
+
+pointer buf[TXT_MAXFD]
+common /xttxtn_com/ buf
+
+begin
+ # Make sure array of string buffer pointers is initialized.
+ if (firsttime==YES) {
+ call aclri (buf, TXT_MAXFD)
+ firsttime = NO
+ }
+
+ # Determine type of open to use.
+ if (strncmp (fname, "proc:", 5) == 0) {
+ ip = 1
+ if (ctoi (fname[6], ip, procptr) == 0)
+ call error (1, "xt_txtopen: bad file specification")
+ call zcall1 (procptr, strbuf)
+ fd = stropen (Memc[strbuf], ARB, READ_ONLY)
+ if (fd > TXT_MAXFD) {
+ call close (fd)
+ call mfree (strbuf, TY_CHAR)
+ call error (1, "xt_txtopen: Too many file descriptors")
+ }
+ buf[fd] = strbuf
+ } else
+ fd = open (fname, READ_ONLY, TEXT_FILE)
+
+ return (fd)
+end
+
+
+# XT_TXTCLOSE -- Close procedure.
+
+procedure xt_txtclose (fd)
+
+int fd #O Null to open and non-null to close
+
+pointer buf[TXT_MAXFD]
+common /xttxtn_com/ buf
+
+begin
+ # Close file descriptor.
+ call close (fd); fd = NULL
+ if (fd <= TXT_MAXFD)
+ call mfree (buf[fd], TY_CHAR)
+end