1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
/* =========================== Module _AH =========================== */
#include "Python.h"
#ifdef _WIN32
#include "pywintoolbox.h"
#else
#include "macglue.h"
#include "pymactoolbox.h"
#endif
/* Macro to test whether a weak-loaded CFM function exists */
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
PyErr_SetString(PyExc_NotImplementedError, \
"Not available in this shared library/OS version"); \
return NULL; \
}} while(0)
#ifdef WITHOUT_FRAMEWORKS
#include <AppleHelp.h>
#else
#include <Carbon/Carbon.h>
#endif
static PyObject *Ah_Error;
static PyObject *Ah_AHSearch(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSStatus _err;
CFStringRef bookname;
CFStringRef query;
if (!PyArg_ParseTuple(_args, "O&O&",
CFStringRefObj_Convert, &bookname,
CFStringRefObj_Convert, &query))
return NULL;
_err = AHSearch(bookname,
query);
if (_err != noErr) return PyMac_Error(_err);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *Ah_AHGotoMainTOC(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSStatus _err;
AHTOCType toctype;
if (!PyArg_ParseTuple(_args, "s",
&toctype))
return NULL;
_err = AHGotoMainTOC(toctype);
if (_err != noErr) return PyMac_Error(_err);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *Ah_AHGotoPage(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSStatus _err;
CFStringRef bookname;
CFStringRef path;
CFStringRef anchor;
if (!PyArg_ParseTuple(_args, "O&O&O&",
CFStringRefObj_Convert, &bookname,
CFStringRefObj_Convert, &path,
CFStringRefObj_Convert, &anchor))
return NULL;
_err = AHGotoPage(bookname,
path,
anchor);
if (_err != noErr) return PyMac_Error(_err);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *Ah_AHLookupAnchor(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSStatus _err;
CFStringRef bookname;
CFStringRef anchor;
if (!PyArg_ParseTuple(_args, "O&O&",
CFStringRefObj_Convert, &bookname,
CFStringRefObj_Convert, &anchor))
return NULL;
_err = AHLookupAnchor(bookname,
anchor);
if (_err != noErr) return PyMac_Error(_err);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *Ah_AHRegisterHelpBook(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSStatus _err;
FSRef appBundleRef;
if (!PyArg_ParseTuple(_args, "O&",
PyMac_GetFSRef, &appBundleRef))
return NULL;
_err = AHRegisterHelpBook(&appBundleRef);
if (_err != noErr) return PyMac_Error(_err);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyMethodDef Ah_methods[] = {
{"AHSearch", (PyCFunction)Ah_AHSearch, 1,
PyDoc_STR("(CFStringRef bookname, CFStringRef query) -> None")},
{"AHGotoMainTOC", (PyCFunction)Ah_AHGotoMainTOC, 1,
PyDoc_STR("(AHTOCType toctype) -> None")},
{"AHGotoPage", (PyCFunction)Ah_AHGotoPage, 1,
PyDoc_STR("(CFStringRef bookname, CFStringRef path, CFStringRef anchor) -> None")},
{"AHLookupAnchor", (PyCFunction)Ah_AHLookupAnchor, 1,
PyDoc_STR("(CFStringRef bookname, CFStringRef anchor) -> None")},
{"AHRegisterHelpBook", (PyCFunction)Ah_AHRegisterHelpBook, 1,
PyDoc_STR("(FSRef appBundleRef) -> None")},
{NULL, NULL, 0}
};
void init_AH(void)
{
PyObject *m;
PyObject *d;
m = Py_InitModule("_AH", Ah_methods);
d = PyModule_GetDict(m);
Ah_Error = PyMac_GetOSErrException();
if (Ah_Error == NULL ||
PyDict_SetItemString(d, "Error", Ah_Error) != 0)
return;
}
/* ========================= End module _AH ========================= */
|