openfile(): Go back to opening the files in text mode. This undoes
[python/dscho.git] / Mac / Modules / ah / _AHmodule.c
blobcf6907640790a7c9fe04371ca374086cd8f1d490
2 /* =========================== Module _AH =========================== */
4 #include "Python.h"
8 #ifdef _WIN32
9 #include "pywintoolbox.h"
10 #else
11 #include "macglue.h"
12 #include "pymactoolbox.h"
13 #endif
15 /* Macro to test whether a weak-loaded CFM function exists */
16 #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
17 PyErr_SetString(PyExc_NotImplementedError, \
18 "Not available in this shared library/OS version"); \
19 return NULL; \
20 }} while(0)
23 #ifdef WITHOUT_FRAMEWORKS
24 #include <AppleHelp.h>
25 #else
26 #include <Carbon/Carbon.h>
27 #endif
30 static PyObject *Ah_Error;
32 static PyObject *Ah_AHSearch(PyObject *_self, PyObject *_args)
34 PyObject *_res = NULL;
35 OSStatus _err;
36 CFStringRef bookname;
37 CFStringRef query;
38 if (!PyArg_ParseTuple(_args, "O&O&",
39 CFStringRefObj_Convert, &bookname,
40 CFStringRefObj_Convert, &query))
41 return NULL;
42 _err = AHSearch(bookname,
43 query);
44 if (_err != noErr) return PyMac_Error(_err);
45 Py_INCREF(Py_None);
46 _res = Py_None;
47 return _res;
50 static PyObject *Ah_AHGotoMainTOC(PyObject *_self, PyObject *_args)
52 PyObject *_res = NULL;
53 OSStatus _err;
54 AHTOCType toctype;
55 if (!PyArg_ParseTuple(_args, "h",
56 &toctype))
57 return NULL;
58 _err = AHGotoMainTOC(toctype);
59 if (_err != noErr) return PyMac_Error(_err);
60 Py_INCREF(Py_None);
61 _res = Py_None;
62 return _res;
65 static PyObject *Ah_AHGotoPage(PyObject *_self, PyObject *_args)
67 PyObject *_res = NULL;
68 OSStatus _err;
69 CFStringRef bookname;
70 CFStringRef path;
71 CFStringRef anchor;
72 if (!PyArg_ParseTuple(_args, "O&O&O&",
73 CFStringRefObj_Convert, &bookname,
74 CFStringRefObj_Convert, &path,
75 CFStringRefObj_Convert, &anchor))
76 return NULL;
77 _err = AHGotoPage(bookname,
78 path,
79 anchor);
80 if (_err != noErr) return PyMac_Error(_err);
81 Py_INCREF(Py_None);
82 _res = Py_None;
83 return _res;
86 static PyObject *Ah_AHLookupAnchor(PyObject *_self, PyObject *_args)
88 PyObject *_res = NULL;
89 OSStatus _err;
90 CFStringRef bookname;
91 CFStringRef anchor;
92 if (!PyArg_ParseTuple(_args, "O&O&",
93 CFStringRefObj_Convert, &bookname,
94 CFStringRefObj_Convert, &anchor))
95 return NULL;
96 _err = AHLookupAnchor(bookname,
97 anchor);
98 if (_err != noErr) return PyMac_Error(_err);
99 Py_INCREF(Py_None);
100 _res = Py_None;
101 return _res;
104 static PyObject *Ah_AHRegisterHelpBook(PyObject *_self, PyObject *_args)
106 PyObject *_res = NULL;
107 OSStatus _err;
108 FSRef appBundleRef;
109 if (!PyArg_ParseTuple(_args, "O&",
110 PyMac_GetFSRef, &appBundleRef))
111 return NULL;
112 _err = AHRegisterHelpBook(&appBundleRef);
113 if (_err != noErr) return PyMac_Error(_err);
114 Py_INCREF(Py_None);
115 _res = Py_None;
116 return _res;
119 static PyMethodDef Ah_methods[] = {
120 {"AHSearch", (PyCFunction)Ah_AHSearch, 1,
121 PyDoc_STR("(CFStringRef bookname, CFStringRef query) -> None")},
122 {"AHGotoMainTOC", (PyCFunction)Ah_AHGotoMainTOC, 1,
123 PyDoc_STR("(AHTOCType toctype) -> None")},
124 {"AHGotoPage", (PyCFunction)Ah_AHGotoPage, 1,
125 PyDoc_STR("(CFStringRef bookname, CFStringRef path, CFStringRef anchor) -> None")},
126 {"AHLookupAnchor", (PyCFunction)Ah_AHLookupAnchor, 1,
127 PyDoc_STR("(CFStringRef bookname, CFStringRef anchor) -> None")},
128 {"AHRegisterHelpBook", (PyCFunction)Ah_AHRegisterHelpBook, 1,
129 PyDoc_STR("(FSRef appBundleRef) -> None")},
130 {NULL, NULL, 0}
136 void init_AH(void)
138 PyObject *m;
139 PyObject *d;
144 m = Py_InitModule("_AH", Ah_methods);
145 d = PyModule_GetDict(m);
146 Ah_Error = PyMac_GetOSErrException();
147 if (Ah_Error == NULL ||
148 PyDict_SetItemString(d, "Error", Ah_Error) != 0)
149 return;
152 /* ========================= End module _AH ========================= */