Initial checkin.
[getdate-python] / module.c
diff --git a/module.c b/module.c
new file mode 100644 (file)
index 0000000..8683d7d
--- /dev/null
+++ b/module.c
@@ -0,0 +1,29 @@
+#include <Python.h>
+#include "getdate.h"
+
+static PyObject *meth_getdate(PyObject *me, PyObject *arg, PyObject *kw)
+{
+  time_t now, t;
+  int tnow = -1;
+  char *p;
+  static char *kwlist[] = { "string", "now", 0 };
+
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "s|i:getdate", kwlist,
+                                  &p, &tnow))
+    return (0);
+  if (tnow != -1) now = tnow;
+  if ((t = get_date(p, (tnow == -1) ? 0 : &now)) == (time_t)-1) {
+    PyErr_SetString(PyExc_SyntaxError, "Bad time string");
+    return (0);
+  }
+  return (PyInt_FromLong(t));
+}
+
+static PyMethodDef methods[] = {
+  { "getdate", (PyCFunction)meth_getdate, METH_VARARGS | METH_KEYWORDS,
+    "getdate(STRING, now = time.time()) -> TIME" },
+  { 0 }
+};
+
+void initgetdate(void) { Py_InitModule("getdate", methods); }
+