summaryrefslogtreecommitdiffstats
path: root/fitsy/var.C
diff options
context:
space:
mode:
authorWilliam Joye <wjoye@cfa.harvard.edu>2020-03-23 20:10:08 (GMT)
committerWilliam Joye <wjoye@cfa.harvard.edu>2020-03-23 20:10:08 (GMT)
commit42027570f57b484414d4e87f19e9c26aed5bb71d (patch)
tree4ce4812d4a348d147cf3d388106272101ccffc2a /fitsy/var.C
parent1ea3cd7a5f436d8baa13fb53007773dcee637bd1 (diff)
downloadblt-42027570f57b484414d4e87f19e9c26aed5bb71d.zip
blt-42027570f57b484414d4e87f19e9c26aed5bb71d.tar.gz
blt-42027570f57b484414d4e87f19e9c26aed5bb71d.tar.bz2
libutil
Diffstat (limited to 'fitsy/var.C')
-rw-r--r--fitsy/var.C53
1 files changed, 53 insertions, 0 deletions
diff --git a/fitsy/var.C b/fitsy/var.C
new file mode 100644
index 0000000..4cf1041
--- /dev/null
+++ b/fitsy/var.C
@@ -0,0 +1,53 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include <tcl.h>
+
+#include "var.h"
+
+FitsVar::FitsVar(Tcl_Interp* interp, const char* var, const char* fn)
+{
+ parse(fn);
+ if (!valid_)
+ return;
+
+ // reset
+ valid_ =0;
+
+ obj = Tcl_GetVar2Ex(interp, (char*)var, NULL,
+ TCL_GLOBAL_ONLY | TCL_LEAVE_ERR_MSG);
+ if (!obj)
+ return;
+
+ // just in case
+ Tcl_ConvertToType(interp, obj, Tcl_GetObjType("bytearray"));
+
+ typedef struct ByteArray {
+ int used; /* The number of bytes used in the byte
+ * array. */
+ int allocated; /* The amount of space actually allocated
+ * minus 1 byte. */
+ unsigned char bytes[4]; /* The array of bytes. The actual size of
+ * this field depends on the 'allocated' field
+ * above. */
+ } ByteArray;
+
+ ByteArray* ba = (ByteArray*)(obj->internalRep.otherValuePtr);
+ mapsize_ = ba->used;
+ mapdata_ = (char*)ba->bytes;
+
+ Tcl_IncrRefCount(obj);
+
+ // so far, so good
+ valid_ = 1;
+}
+
+FitsVar::~FitsVar()
+{
+ if (obj)
+ Tcl_DecrRefCount(obj);
+}
+
+
+