summaryrefslogtreecommitdiffstats
path: root/fitsy++/var.C
diff options
context:
space:
mode:
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);
+}
+
+
+