summaryrefslogtreecommitdiff
path: root/xdelta3/xdelta3-python.h
diff options
context:
space:
mode:
Diffstat (limited to 'xdelta3/xdelta3-python.h')
-rwxr-xr-xxdelta3/xdelta3-python.h86
1 files changed, 86 insertions, 0 deletions
diff --git a/xdelta3/xdelta3-python.h b/xdelta3/xdelta3-python.h
new file mode 100755
index 0000000..cfd6095
--- /dev/null
+++ b/xdelta3/xdelta3-python.h
@@ -0,0 +1,86 @@
1/* xdelta 3 - delta compression tools and library
2 * Copyright (C) 2003 and onward. Joshua P. MacDonald
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19#include "Python.h"
20
21static PyObject *pyxd3_error;
22
23/* spam: xdelta3.main([string,list,...]) */
24PyObject *xdelta3_main_cmdline (PyObject *self, PyObject *args)
25{
26 int ret, i, nargs;
27 char **argv = NULL;
28 int argc = 0;
29 PyObject *result = NULL;
30 PyObject *o;
31
32 if (! PyArg_ParseTuple (args, "O", &o)
33 || ! PyList_Check (o))
34 {
35 goto cleanup;
36 }
37
38 argc = PyList_Size (o);
39 nargs = argc + 2;
40
41 if (! (argv = malloc (sizeof(argv[0]) * nargs)))
42 {
43 PyErr_NoMemory ();
44 goto cleanup;
45 }
46 memset (argv, 0, sizeof(argv[0]) * nargs);
47
48 for (i = 1; i < nargs-1; i += 1)
49 {
50 char *ps;
51 PyObject *s;
52 if ((s = PyList_GetItem (o, i-1)) == NULL) { goto cleanup; }
53 ps = PyString_AsString (s);
54 argv[i] = ps;
55 }
56
57 ret = xd3_main_cmdline (argc+1, argv);
58
59 if (ret == 0)
60 {
61 result = Py_BuildValue ("i", ret);
62 }
63 else
64 {
65 PyErr_SetString (pyxd3_error, "failed :(");
66 }
67 cleanup:
68 if (argv)
69 {
70 free (argv);
71 }
72 return result;
73}
74static PyMethodDef xdelta3_methods[] = {
75 { "main", xdelta3_main_cmdline, METH_VARARGS, "xdelta3 main()" },
76 { NULL, NULL }
77};
78
79DL_EXPORT(void) initxdelta3 (void)
80{
81 PyObject *m, *d;
82 m = Py_InitModule ("xdelta3", xdelta3_methods);
83 d = PyModule_GetDict (m);
84 pyxd3_error = PyErr_NewException ("xdelta3.error", NULL, NULL);
85 PyDict_SetItemString (d, "error", pyxd3_error);
86}