Skip to content

Commit 69565e0

Browse files
author
jackjansen
committed
Interface to Apple Help Manager.
git-svn-id: http://svn.python.org/projects/python/trunk@28380 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent c5e05ea commit 69565e0

3 files changed

Lines changed: 255 additions & 0 deletions

File tree

Mac/Modules/ah/_AHmodule.c

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
2+
/* =========================== Module _AH =========================== */
3+
4+
#include "Python.h"
5+
6+
7+
8+
#ifdef _WIN32
9+
#include "pywintoolbox.h"
10+
#else
11+
#include "macglue.h"
12+
#include "pymactoolbox.h"
13+
#endif
14+
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)
21+
22+
23+
#ifdef WITHOUT_FRAMEWORKS
24+
#include <AppleHelp.h>
25+
#else
26+
#include <Carbon/Carbon.h>
27+
#endif
28+
29+
30+
static PyObject *Ah_Error;
31+
32+
static PyObject *Ah_AHSearch(PyObject *_self, PyObject *_args)
33+
{
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;
48+
}
49+
50+
static PyObject *Ah_AHGotoMainTOC(PyObject *_self, PyObject *_args)
51+
{
52+
PyObject *_res = NULL;
53+
OSStatus _err;
54+
AHTOCType toctype;
55+
if (!PyArg_ParseTuple(_args, "s",
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;
63+
}
64+
65+
static PyObject *Ah_AHGotoPage(PyObject *_self, PyObject *_args)
66+
{
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;
84+
}
85+
86+
static PyObject *Ah_AHLookupAnchor(PyObject *_self, PyObject *_args)
87+
{
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;
102+
}
103+
104+
static PyObject *Ah_AHRegisterHelpBook(PyObject *_self, PyObject *_args)
105+
{
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;
117+
}
118+
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}
131+
};
132+
133+
134+
135+
136+
void init_AH(void)
137+
{
138+
PyObject *m;
139+
PyObject *d;
140+
141+
142+
143+
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;
150+
}
151+
152+
/* ========================= End module _AH ========================= */
153+

Mac/Modules/ah/ahscan.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Scan an Apple header file, generating a Python file of generator calls.
2+
3+
import sys
4+
import os
5+
from bgenlocations import TOOLBOXDIR, BGENDIR
6+
sys.path.append(BGENDIR)
7+
from scantools import Scanner_OSX
8+
9+
LONG = "AppleHelp"
10+
SHORT = "ah"
11+
OBJECT = "NOTUSED"
12+
13+
def main():
14+
input = LONG + ".h"
15+
output = SHORT + "gen.py"
16+
defsoutput = TOOLBOXDIR + LONG + ".py"
17+
scanner = MyScanner(input, output, defsoutput)
18+
scanner.scan()
19+
scanner.close()
20+
print "=== Testing definitions output code ==="
21+
execfile(defsoutput, {}, {})
22+
print "=== Done scanning and generating, now importing the generated code... ==="
23+
exec "import " + SHORT + "support"
24+
print "=== Done. It's up to you to compile it now! ==="
25+
26+
class MyScanner(Scanner_OSX):
27+
28+
def destination(self, type, name, arglist):
29+
classname = "Function"
30+
listname = "functions"
31+
if arglist:
32+
t, n, m = arglist[0]
33+
# This is non-functional today
34+
if t == OBJECT and m == "InMode":
35+
classname = "Method"
36+
listname = "methods"
37+
return classname, listname
38+
39+
def makeblacklistnames(self):
40+
return [
41+
]
42+
43+
def makeblacklisttypes(self):
44+
return [
45+
]
46+
47+
def makerepairinstructions(self):
48+
return [
49+
]
50+
51+
if __name__ == "__main__":
52+
main()

Mac/Modules/ah/ahsupport.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# This script generates a Python interface for an Apple Macintosh Manager.
2+
# It uses the "bgen" package to generate C code.
3+
# The function specifications are generated by scanning the mamager's header file,
4+
# using the "scantools" package (customized for this particular manager).
5+
6+
import string
7+
8+
# Declarations that change for each manager
9+
MACHEADERFILE = 'AppleHelp.h' # The Apple header file
10+
MODNAME = '_AH' # The name of the module
11+
12+
# The following is *usually* unchanged but may still require tuning
13+
MODPREFIX = 'Ah' # The prefix for module-wide routines
14+
INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
15+
OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
16+
17+
from macsupport import *
18+
19+
# Create the type objects
20+
AHTOCType = Type("AHTOCType", "s")
21+
22+
includestuff = includestuff + """
23+
#ifdef WITHOUT_FRAMEWORKS
24+
#include <AppleHelp.h>
25+
#else
26+
#include <Carbon/Carbon.h>
27+
#endif
28+
29+
"""
30+
31+
# From here on it's basically all boiler plate...
32+
33+
# Create the generator groups and link them
34+
module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
35+
36+
# Create the generator classes used to populate the lists
37+
Function = OSErrFunctionGenerator
38+
39+
# Create and populate the lists
40+
functions = []
41+
execfile(INPUTFILE)
42+
43+
# add the populated lists to the generator groups
44+
# (in a different wordl the scan program would generate this)
45+
for f in functions: module.add(f)
46+
47+
# generate output (open the output file as late as possible)
48+
SetOutputFileName(OUTPUTFILE)
49+
module.generate()
50+

0 commit comments

Comments
 (0)