most of the code needed to handle the built-in data type specs
authorD Herring <dherring@at.tentpost.dot.com>
Tue, 5 Apr 2011 05:06:25 +0000 (01:06 -0400)
committerD Herring <dherring@at.tentpost.dot.com>
Tue, 5 Apr 2011 05:06:25 +0000 (01:06 -0400)
Makefile
open-macros.txt [new file with mode: 0644]
read-open-macros.lisp [new file with mode: 0644]

index 5b2498f..5c595d3 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -5,3 +5,8 @@ INCLUDEDIR=/mnt/samsung2tb/slack64/include
 enums.txt:
        sed -n -e '/enum .*{/,/} *H5/ p' $(INCLUDEDIR)/H*public.h | cpp | sed -e '/#/ d' -e '/^$$/ d' -e 's/[(,);=]//g' -e '/typedef/ d' -e 's/}[ \t]*//' | tr A-Z_ a-z- > $@.tmp
        mv $@.tmp $@
+
+# these should become symbol macros
+open-macros.txt:
+       grep '^#define' $(INCLUDEDIR)/H*public.h | sed -e '/\\$$/ d' -e '/_H$$/ d' -e '/define [^ \t]*(/ d' -e 's,.*#define ,,' | cpp | grep '(H5OPEN' | sed -e 's/(H5OPEN //' -e 's/)//' > $@.tmp
+       mv $@.tmp $@
diff --git a/open-macros.txt b/open-macros.txt
new file mode 100644 (file)
index 0000000..768ca61
--- /dev/null
@@ -0,0 +1,117 @@
+H5E_ERR_CLS H5E_ERR_CLS_g
+H5P_ROOT H5P_CLS_ROOT_g
+H5P_OBJECT_CREATE H5P_CLS_OBJECT_CREATE_g
+H5P_FILE_CREATE H5P_CLS_FILE_CREATE_g
+H5P_FILE_ACCESS H5P_CLS_FILE_ACCESS_g
+H5P_DATASET_CREATE H5P_CLS_DATASET_CREATE_g
+H5P_DATASET_ACCESS H5P_CLS_DATASET_ACCESS_g
+H5P_DATASET_XFER H5P_CLS_DATASET_XFER_g
+H5P_FILE_MOUNT H5P_CLS_FILE_MOUNT_g
+H5P_GROUP_CREATE H5P_CLS_GROUP_CREATE_g
+H5P_GROUP_ACCESS H5P_CLS_GROUP_ACCESS_g
+H5P_DATATYPE_CREATE H5P_CLS_DATATYPE_CREATE_g
+H5P_DATATYPE_ACCESS H5P_CLS_DATATYPE_ACCESS_g
+H5P_STRING_CREATE H5P_CLS_STRING_CREATE_g
+H5P_ATTRIBUTE_CREATE H5P_CLS_ATTRIBUTE_CREATE_g
+H5P_OBJECT_COPY H5P_CLS_OBJECT_COPY_g
+H5P_LINK_CREATE H5P_CLS_LINK_CREATE_g
+H5P_LINK_ACCESS H5P_CLS_LINK_ACCESS_g
+H5P_FILE_CREATE_DEFAULT H5P_LST_FILE_CREATE_g
+H5P_FILE_ACCESS_DEFAULT H5P_LST_FILE_ACCESS_g
+H5P_DATASET_CREATE_DEFAULT H5P_LST_DATASET_CREATE_g
+H5P_DATASET_ACCESS_DEFAULT H5P_LST_DATASET_ACCESS_g
+H5P_DATASET_XFER_DEFAULT H5P_LST_DATASET_XFER_g
+H5P_FILE_MOUNT_DEFAULT H5P_LST_FILE_MOUNT_g
+H5P_GROUP_CREATE_DEFAULT H5P_LST_GROUP_CREATE_g
+H5P_GROUP_ACCESS_DEFAULT H5P_LST_GROUP_ACCESS_g
+H5P_DATATYPE_CREATE_DEFAULT H5P_LST_DATATYPE_CREATE_g
+H5P_DATATYPE_ACCESS_DEFAULT H5P_LST_DATATYPE_ACCESS_g
+H5P_ATTRIBUTE_CREATE_DEFAULT H5P_LST_ATTRIBUTE_CREATE_g
+H5P_OBJECT_COPY_DEFAULT H5P_LST_OBJECT_COPY_g
+H5P_LINK_CREATE_DEFAULT H5P_LST_LINK_CREATE_g
+H5P_LINK_ACCESS_DEFAULT H5P_LST_LINK_ACCESS_g
+H5T_IEEE_F32BE H5T_IEEE_F32BE_g
+H5T_IEEE_F32LE H5T_IEEE_F32LE_g
+H5T_IEEE_F64BE H5T_IEEE_F64BE_g
+H5T_IEEE_F64LE H5T_IEEE_F64LE_g
+H5T_STD_I8BE H5T_STD_I8BE_g
+H5T_STD_I8LE H5T_STD_I8LE_g
+H5T_STD_I16BE H5T_STD_I16BE_g
+H5T_STD_I16LE H5T_STD_I16LE_g
+H5T_STD_I32BE H5T_STD_I32BE_g
+H5T_STD_I32LE H5T_STD_I32LE_g
+H5T_STD_I64BE H5T_STD_I64BE_g
+H5T_STD_I64LE H5T_STD_I64LE_g
+H5T_STD_U8BE H5T_STD_U8BE_g
+H5T_STD_U8LE H5T_STD_U8LE_g
+H5T_STD_U16BE H5T_STD_U16BE_g
+H5T_STD_U16LE H5T_STD_U16LE_g
+H5T_STD_U32BE H5T_STD_U32BE_g
+H5T_STD_U32LE H5T_STD_U32LE_g
+H5T_STD_U64BE H5T_STD_U64BE_g
+H5T_STD_U64LE H5T_STD_U64LE_g
+H5T_STD_B8BE H5T_STD_B8BE_g
+H5T_STD_B8LE H5T_STD_B8LE_g
+H5T_STD_B16BE H5T_STD_B16BE_g
+H5T_STD_B16LE H5T_STD_B16LE_g
+H5T_STD_B32BE H5T_STD_B32BE_g
+H5T_STD_B32LE H5T_STD_B32LE_g
+H5T_STD_B64BE H5T_STD_B64BE_g
+H5T_STD_B64LE H5T_STD_B64LE_g
+H5T_STD_REF_OBJ H5T_STD_REF_OBJ_g
+H5T_STD_REF_DSETREG H5T_STD_REF_DSETREG_g
+H5T_UNIX_D32BE H5T_UNIX_D32BE_g
+H5T_UNIX_D32LE H5T_UNIX_D32LE_g
+H5T_UNIX_D64BE H5T_UNIX_D64BE_g
+H5T_UNIX_D64LE H5T_UNIX_D64LE_g
+H5T_C_S1 H5T_C_S1_g
+H5T_FORTRAN_S1 H5T_FORTRAN_S1_g
+H5T_VAX_F32 H5T_VAX_F32_g
+H5T_VAX_F64 H5T_VAX_F64_g
+H5T_NATIVE_SCHAR H5T_NATIVE_SCHAR_g
+H5T_NATIVE_UCHAR H5T_NATIVE_UCHAR_g
+H5T_NATIVE_SHORT H5T_NATIVE_SHORT_g
+H5T_NATIVE_USHORT H5T_NATIVE_USHORT_g
+H5T_NATIVE_INT H5T_NATIVE_INT_g
+H5T_NATIVE_UINT H5T_NATIVE_UINT_g
+H5T_NATIVE_LONG H5T_NATIVE_LONG_g
+H5T_NATIVE_ULONG H5T_NATIVE_ULONG_g
+H5T_NATIVE_LLONG H5T_NATIVE_LLONG_g
+H5T_NATIVE_ULLONG H5T_NATIVE_ULLONG_g
+H5T_NATIVE_FLOAT H5T_NATIVE_FLOAT_g
+H5T_NATIVE_DOUBLE H5T_NATIVE_DOUBLE_g
+H5T_NATIVE_LDOUBLE H5T_NATIVE_LDOUBLE_g
+H5T_NATIVE_B8 H5T_NATIVE_B8_g
+H5T_NATIVE_B16 H5T_NATIVE_B16_g
+H5T_NATIVE_B32 H5T_NATIVE_B32_g
+H5T_NATIVE_B64 H5T_NATIVE_B64_g
+H5T_NATIVE_OPAQUE H5T_NATIVE_OPAQUE_g
+H5T_NATIVE_HADDR H5T_NATIVE_HADDR_g
+H5T_NATIVE_HSIZE H5T_NATIVE_HSIZE_g
+H5T_NATIVE_HSSIZE H5T_NATIVE_HSSIZE_g
+H5T_NATIVE_HERR H5T_NATIVE_HERR_g
+H5T_NATIVE_HBOOL H5T_NATIVE_HBOOL_g
+H5T_NATIVE_INT8 H5T_NATIVE_INT8_g
+H5T_NATIVE_UINT8 H5T_NATIVE_UINT8_g
+H5T_NATIVE_INT_LEAST8 H5T_NATIVE_INT_LEAST8_g
+H5T_NATIVE_UINT_LEAST8 H5T_NATIVE_UINT_LEAST8_g
+H5T_NATIVE_INT_FAST8 H5T_NATIVE_INT_FAST8_g
+H5T_NATIVE_UINT_FAST8 H5T_NATIVE_UINT_FAST8_g
+H5T_NATIVE_INT16 H5T_NATIVE_INT16_g
+H5T_NATIVE_UINT16 H5T_NATIVE_UINT16_g
+H5T_NATIVE_INT_LEAST16 H5T_NATIVE_INT_LEAST16_g
+H5T_NATIVE_UINT_LEAST16 H5T_NATIVE_UINT_LEAST16_g
+H5T_NATIVE_INT_FAST16 H5T_NATIVE_INT_FAST16_g
+H5T_NATIVE_UINT_FAST16 H5T_NATIVE_UINT_FAST16_g
+H5T_NATIVE_INT32 H5T_NATIVE_INT32_g
+H5T_NATIVE_UINT32 H5T_NATIVE_UINT32_g
+H5T_NATIVE_INT_LEAST32 H5T_NATIVE_INT_LEAST32_g
+H5T_NATIVE_UINT_LEAST32 H5T_NATIVE_UINT_LEAST32_g
+H5T_NATIVE_INT_FAST32 H5T_NATIVE_INT_FAST32_g
+H5T_NATIVE_UINT_FAST32 H5T_NATIVE_UINT_FAST32_g
+H5T_NATIVE_INT64 H5T_NATIVE_INT64_g
+H5T_NATIVE_UINT64 H5T_NATIVE_UINT64_g
+H5T_NATIVE_INT_LEAST64 H5T_NATIVE_INT_LEAST64_g
+H5T_NATIVE_UINT_LEAST64 H5T_NATIVE_UINT_LEAST64_g
+H5T_NATIVE_INT_FAST64 H5T_NATIVE_INT_FAST64_g
+H5T_NATIVE_UINT_FAST64 H5T_NATIVE_UINT_FAST64_g
diff --git a/read-open-macros.lisp b/read-open-macros.lisp
new file mode 100644 (file)
index 0000000..f2f7d9c
--- /dev/null
@@ -0,0 +1,28 @@
+#| Example:
+Given "H5T_NATIVE_INT64 H5T_NATIVE_INT64_g", expand to
+
+(cffi:defcvar (H5T_NATIVE_INT64_g "H5T_NATIVE_INT64_g" :read-only t) 'hid_t)
+(define-symbol-macro h5t-native-int64 (progn (H5open) H5T_NATIVE_INT64_g))
+|#
+
+
+(defun normalize-name (str)
+  "lowercase, with s/_/-/g."
+  (string-downcase (substitute #\- #\_ str)))
+
+(defun read-open-macros (&optional (filename "open-macros.txt"))
+  (with-open-file (file filename)
+    (do (code
+         (line (read-line file nil)
+               (read-line file nil)))
+        ((not line)
+         (cons 'progn code))
+      (let* ((pos (position #\Space line))
+             (macro (read-from-string (normalize-name (subseq line 0 pos))))
+             (varname (subseq line (1+ pos)))
+             (hidename (concatenate 'string "%" (normalize-name varname)))
+             (variable (read-from-string hidename)))
+        (setf code
+              (append code
+                      (list `(cffi:defcvar (,variable ,varname :read-only t) hid_t)
+                            `(define-symbol-macro ,macro (progn (h5open) ,variable)))))))))