]> git.saurik.com Git - wxWidgets.git/blame - src/stc/gen_iface.py
fix for root behavior under MSW
[wxWidgets.git] / src / stc / gen_iface.py
CommitLineData
f97d84a6
RD
1#!/bin/env python
2#----------------------------------------------------------------------------
3# Name: gen_iface.py
4# Purpose: Generate stc.h and stc.cpp from the info in Scintilla.iface
5#
6# Author: Robin Dunn
7#
8# Created: 5-Sept-2000
9# RCS-ID: $Id$
10# Copyright: (c) 2000 by Total Control Software
11# Licence: wxWindows license
12#----------------------------------------------------------------------------
13
14
65ec6247 15import sys, string, re, os
f97d84a6
RD
16from fileinput import FileInput
17
18
65ec6247
RD
19IFACE = os.path.abspath('./scintilla/include/Scintilla.iface')
20H_TEMPLATE = os.path.abspath('./stc.h.in')
21CPP_TEMPLATE = os.path.abspath('./stc.cpp.in')
22H_DEST = os.path.abspath('../../include/wx/stc/stc.h')
23CPP_DEST = os.path.abspath('./stc.cpp')
f97d84a6
RD
24
25
26# Value prefixes to convert
27valPrefixes = [('SCI_', ''),
28 ('SC_', ''),
37d62433 29 ('SCN_', None), # just toss these out...
f97d84a6
RD
30 ('SCEN_', None),
31 ('SCE_', ''),
32 ('SCLEX_', 'LEX_'),
33 ('SCK_', 'KEY_'),
34 ('SCFIND_', 'FIND_'),
35 ('SCWS_', 'WS_'),
36]
37
60869eaf 38# Message function values that should have a CMD_ constant as well
f97d84a6
RD
39cmdValues = [ (2300, 2350), 2011, 2013, (2176, 2180) ]
40
41
42# Map some generic typenames to wx types, using return value syntax
43retTypeMap = {
44 'position': 'int',
45 'string': 'wxString',
46 'colour': 'wxColour',
47 }
48
49# Map some generic typenames to wx types, using parameter syntax
50paramTypeMap = {
51 'position': 'int',
52 'string': 'const wxString&',
53 'colour': 'const wxColour&',
54 'keymod': 'int',
55}
56
57# Map of method info that needs tweaked. Either the name needs changed, or
58# the method definition/implementation. Tuple items are:
59#
60# 1. New method name. None to skip the method, 0 to leave the
61# default name.
62# 2. Method definition for the .h file, 0 to leave alone
63# 3. Method implementation for the .cpp file, 0 to leave alone.
64# 4. tuple of Doc string lines, or 0 to leave alone.
65#
66methodOverrideMap = {
67 'AddText' : (0,
68 'void %s(const wxString& text);',
69
70 '''void %s(const wxString& text) {
71 SendMsg(%s, text.Len(), (long)text.c_str());''',
72 0),
73
74 'AddStyledText' : (0,
75 'void %s(const wxString& text);',
76
77 '''void %s(const wxString& text) {
78 SendMsg(%s, text.Len(), (long)text.c_str());''',
79 0),
80
81 'GetViewWS' : ( 'GetViewWhiteSpace', 0, 0, 0),
82 'SetViewWS' : ( 'SetViewWhiteSpace', 0, 0, 0),
83
84 'GetStyledText' : (0,
85 'wxString %s(int startPos, int endPos);',
86
87 '''wxString %s(int startPos, int endPos) {
88 wxString text;
89 int len = endPos - startPos;
abb69c6c 90 if (!len) return "";
f97d84a6 91 TextRange tr;
abb69c6c 92 tr.lpstrText = text.GetWriteBuf(len*2);
f97d84a6
RD
93 tr.chrg.cpMin = startPos;
94 tr.chrg.cpMax = endPos;
95 SendMsg(%s, 0, (long)&tr);
96 text.UngetWriteBuf(len*2);
97 return text;''',
98
99 ('Retrieve a buffer of cells.',)),
100
101
102 'PositionFromPoint' : (0,
103 'int %s(wxPoint pt);',
104
105 '''int %s(wxPoint pt) {
106 return SendMsg(%s, pt.x, pt.y);''',
107
108 0),
109
110 'GetCurLine' : (0,
8de28db9 111 '#ifdef SWIG\n wxString %s(int* OUTPUT);\n#else\n wxString GetCurLine(int* linePos=NULL);\n#endif',
f97d84a6
RD
112
113 '''wxString %s(int* linePos) {
114 wxString text;
115 int len = LineLength(GetCurrentLine());
8de28db9
RD
116 if (!len) {
117 if (linePos) *linePos = 0;
118 return "";
119 }
120 // Need an extra byte because SCI_GETCURLINE writes a null to the string
121 char* buf = text.GetWriteBuf(len+1);
122
123 int pos = SendMsg(%s, len+1, (long)buf);
abb69c6c 124 text.UngetWriteBuf(len);
f97d84a6
RD
125 if (linePos) *linePos = pos;
126
127 return text;''',
128
129 0),
130
131 'SetUsePalette' : (None, 0,0,0),
132
133 'MarkerSetFore' : ('MarkerSetForeground', 0, 0, 0),
134 'MarkerSetBack' : ('MarkerSetBackground', 0, 0, 0),
135
136 'MarkerDefine' : (0,
137 '''void %s(int markerNumber, int markerSymbol,
138 const wxColour& foreground = wxNullColour,
139 const wxColour& background = wxNullColour);''',
140
141 '''void %s(int markerNumber, int markerSymbol,
142 const wxColour& foreground,
143 const wxColour& background) {
144
145 SendMsg(%s, markerNumber, markerSymbol);
146 if (foreground.Ok())
147 MarkerSetForeground(markerNumber, foreground);
148 if (background.Ok())
149 MarkerSetBackground(markerNumber, background);''',
150
151 ('Set the symbol used for a particular marker number,',
152 'and optionally the for and background colours.')),
153
154 'SetMarginTypeN' : ('SetMarginType', 0, 0, 0),
155 'GetMarginTypeN' : ('GetMarginType', 0, 0, 0),
156 'SetMarginWidthN' : ('SetMarginWidth', 0, 0, 0),
157 'GetMarginWidthN' : ('GetMarginWidth', 0, 0, 0),
158 'SetMarginMaskN' : ('SetMarginMask', 0, 0, 0),
159 'GetMarginMaskN' : ('GetMarginMask', 0, 0, 0),
160 'SetMarginSensitiveN' : ('SetMarginSensitive', 0, 0, 0),
161 'GetMarginSensitiveN' : ('GetMarginSensitive', 0, 0, 0),
162
163 'StyleSetFore' : ('StyleSetForeground', 0, 0, 0),
164 'StyleSetBack' : ('StyleSetBackground', 0, 0, 0),
165 'SetSelFore' : ('SetSelForeground', 0, 0, 0),
166 'SetSelBack' : ('SetSelBackground', 0, 0, 0),
167 'SetCaretFore' : ('SetCaretForeground', 0, 0, 0),
168 'StyleSetFont' : ('StyleSetFaceName', 0, 0, 0),
169
170 # need to fix this to map between wx and scintilla encoding flags, leave it out for now...
171 'StyleSetCharacterSet' : (None, 0, 0, 0),
172
173 'AssignCmdKey' : ('CmdKeyAssign',
174 'void %s(int key, int modifiers, int cmd);',
175
176 '''void %s(int key, int modifiers, int cmd) {
177 SendMsg(%s, MAKELONG(key, modifiers), cmd);''',
178
179 0),
180
181 'ClearCmdKey' : ('CmdKeyClear',
182 'void %s(int key, int modifiers);',
183
184 '''void %s(int key, int modifiers) {
185 SendMsg(%s, MAKELONG(key, modifiers));''',
186
187 0),
188
189 'ClearAllCmdKeys' : ('CmdKeyClearAll', 0, 0, 0),
190
191
192 'SetStylingEx' : ('SetStyleBytes',
193 'void %s(int length, char* styleBytes);',
194
195 '''void %s(int length, char* styleBytes) {
196 SendMsg(%s, length, (long)styleBytes);''',
197
198 0),
199
200
201 'IndicSetStyle' : ('IndicatorSetStyle', 0, 0, 0),
202 'IndicGetStyle' : ('IndicatorGetStyle', 0, 0, 0),
203 'IndicSetFore' : ('IndicatorSetForeground', 0, 0, 0),
204 'IndicGetFore' : ('IndicatorGetForeground', 0, 0, 0),
205
206 'AutoCShow' : ('AutoCompShow', 0, 0, 0),
207 'AutoCCancel' : ('AutoCompCancel', 0, 0, 0),
208 'AutoCActive' : ('AutoCompActive', 0, 0, 0),
209 'AutoCPosStart' : ('AutoCompPosStart', 0, 0, 0),
210 'AutoCComplete' : ('AutoCompComplete', 0, 0, 0),
211 'AutoCStops' : ('AutoCompStops', 0, 0, 0),
212 'AutoCSetSeparator' : ('AutoCompSetSeparator', 0, 0, 0),
213 'AutoCGetSeparator' : ('AutoCompGetSeparator', 0, 0, 0),
214 'AutoCSelect' : ('AutoCompSelect', 0, 0, 0),
215 'AutoCSetCancelAtStart' : ('AutoCompSetCancelAtStart', 0, 0, 0),
216 'AutoCGetCancelAtStart' : ('AutoCompGetCancelAtStart', 0, 0, 0),
217 'AutoCSetFillUps' : ('AutoCompSetFillUps', 0, 0, 0),
218 'AutoCSetChooseSingle' : ('AutoCompSetChooseSingle', 0, 0, 0),
219 'AutoCGetChooseSingle' : ('AutoCompGetChooseSingle', 0, 0, 0),
220 'AutoCSetIgnoreCase' : ('AutoCompSetIgnoreCase', 0, 0, 0),
221 'AutoCGetIgnoreCase' : ('AutoCompGetIgnoreCase', 0, 0, 0),
65ec6247
RD
222 'AutoCSetAutoHide' : ('AutoCompSetAutoHide', 0, 0, 0),
223 'AutoCGetAutoHide' : ('AutoCompGetAutoHide', 0, 0, 0),
224
f97d84a6
RD
225
226 'SetHScrollBar' : ('SetUseHorizontalScrollBar', 0, 0, 0),
227 'GetHScrollBar' : ('GetUseHorizontalScrollBar', 0, 0, 0),
228
229 'GetCaretFore' : ('GetCaretForeground', 0, 0, 0),
230
231 'GetUsePalette' : (None, 0, 0, 0),
232
233 'FindText' : (0,
234 '''int %s(int minPos, int maxPos,
235 const wxString& text,
236 bool caseSensitive, bool wholeWord);''',
237 '''int %s(int minPos, int maxPos,
238 const wxString& text,
239 bool caseSensitive, bool wholeWord) {
240 TextToFind ft;
241 int flags = 0;
242
243 flags |= caseSensitive ? SCFIND_MATCHCASE : 0;
244 flags |= wholeWord ? SCFIND_WHOLEWORD : 0;
245 ft.chrg.cpMin = minPos;
246 ft.chrg.cpMax = maxPos;
247 ft.lpstrText = (char*)text.c_str();
248
249 return SendMsg(%s, flags, (long)&ft);''',
250 0),
251
252 'FormatRange' : (0,
253 '''int %s(bool doDraw,
254 int startPos,
255 int endPos,
256 wxDC* draw,
257 wxDC* target, // Why does it use two? Can they be the same?
258 wxRect renderRect,
259 wxRect pageRect);''',
260 ''' int %s(bool doDraw,
261 int startPos,
262 int endPos,
263 wxDC* draw,
264 wxDC* target, // Why does it use two? Can they be the same?
265 wxRect renderRect,
266 wxRect pageRect) {
267 RangeToFormat fr;
268
269 fr.hdc = draw;
270 fr.hdcTarget = target;
271 fr.rc.top = renderRect.GetTop();
272 fr.rc.left = renderRect.GetLeft();
273 fr.rc.right = renderRect.GetRight();
274 fr.rc.bottom = renderRect.GetBottom();
275 fr.rcPage.top = pageRect.GetTop();
276 fr.rcPage.left = pageRect.GetLeft();
277 fr.rcPage.right = pageRect.GetRight();
278 fr.rcPage.bottom = pageRect.GetBottom();
279 fr.chrg.cpMin = startPos;
280 fr.chrg.cpMax = endPos;
281
282 return SendMsg(%s, doDraw, (long)&fr);''',
283 0),
284
285
286 'GetLine' : (0,
287 'wxString %s(int line);',
288
289 '''wxString %s(int line) {
290 wxString text;
291 int len = LineLength(line);
abb69c6c 292 if (!len) return "";
afc2b641 293 char* buf = text.GetWriteBuf(len);
f97d84a6
RD
294
295 int pos = SendMsg(%s, line, (long)buf);
abb69c6c 296 text.UngetWriteBuf(len);
f97d84a6
RD
297
298 return text;''',
299
300 ('Retrieve the contents of a line.',)),
301
302 'SetSel' : ('SetSelection', 0, 0, 0),
303 'GetSelText' : ('GetSelectedText',
304 'wxString %s();',
305
306 '''wxString %s() {
307 wxString text;
308 int start;
309 int end;
310
311 GetSelection(&start, &end);
312 int len = end - start;
abb69c6c
RD
313 if (!len) return "";
314 char* buff = text.GetWriteBuf(len);
f97d84a6
RD
315
316 SendMsg(%s, 0, (long)buff);
abb69c6c 317 text.UngetWriteBuf(len);
f97d84a6
RD
318 return text;''',
319
320 ('Retrieve the selected text.',)),
321
322 'GetTextRange' : (0,
323 'wxString %s(int startPos, int endPos);',
324
325 '''wxString %s(int startPos, int endPos) {
326 wxString text;
327 int len = endPos - startPos;
abb69c6c
RD
328 if (!len) return "";
329 char* buff = text.GetWriteBuf(len);
f97d84a6
RD
330 TextRange tr;
331 tr.lpstrText = buff;
332 tr.chrg.cpMin = startPos;
333 tr.chrg.cpMax = endPos;
334
335 SendMsg(%s, 0, (long)&tr);
abb69c6c 336 text.UngetWriteBuf(len);
f97d84a6
RD
337 return text;''',
338
339 ('Retrieve a range of text.',)),
340
341 'PointXFromPosition' : (None, 0, 0, 0),
342 'PointYFromPosition' : (None, 0, 0, 0),
343
344 'ScrollCaret' : ('EnsureCaretVisible', 0, 0, 0),
345 'ReplaceSel' : ('ReplaceSelection', 0, 0, 0),
346 'Null' : (None, 0, 0, 0),
347
348 'GetText' : (0,
349 'wxString %s();',
350
351 '''wxString %s() {
352 wxString text;
8de28db9
RD
353 int len = GetTextLength();
354 char* buff = text.GetWriteBuf(len+1); // leave room for the null...
f97d84a6 355
8de28db9
RD
356 SendMsg(%s, len+1, (long)buff);
357 text.UngetWriteBuf(len);
f97d84a6
RD
358 return text;''',
359
360 ('Retrieve all the text in the document.', )),
361
362 'GetDirectFunction' : (None, 0, 0, 0),
363 'GetDirectPointer' : (None, 0, 0, 0),
364
365 'CallTipPosStart' : ('CallTipPosAtStart', 0, 0, 0),
366 'CallTipSetHlt' : ('CallTipSetHighlight', 0, 0, 0),
367 'CallTipSetBack' : ('CallTipSetBackground', 0, 0, 0),
368
369
65ec6247
RD
370 'ReplaceTarget' : (0,
371 'int %s(const wxString& text);',
372
373 '''
374 int %s(const wxString& text) {
375 return SendMsg(%s, text.Len(), (long)text.c_str());
376 ''',
377
378 0),
379
380 'ReplaceTargetRE' : (0,
381 'int %s(const wxString& text);',
382
383 '''
384 int %s(const wxString& text) {
385 return SendMsg(%s, text.Len(), (long)text.c_str());
386 ''',
387
388 0),
389
390 'SearchInTarget' : (0,
391 'int %s(const wxString& text);',
392
393 '''
394 int %s(const wxString& text) {
395 return SendMsg(%s, text.Len(), (long)text.c_str());
396 ''',
397
398 0),
399
400
401
f97d84a6
RD
402 # Remove all methods that are key commands since they can be
403 # executed with CmdKeyExecute
404 'LineDown' : (None, 0, 0, 0),
405 'LineDownExtend' : (None, 0, 0, 0),
406 'LineUp' : (None, 0, 0, 0),
407 'LineUpExtend' : (None, 0, 0, 0),
408 'CharLeft' : (None, 0, 0, 0),
409 'CharLeftExtend' : (None, 0, 0, 0),
410 'CharRight' : (None, 0, 0, 0),
411 'CharRightExtend' : (None, 0, 0, 0),
412 'WordLeft' : (None, 0, 0, 0),
413 'WordLeftExtend' : (None, 0, 0, 0),
414 'WordRight' : (None, 0, 0, 0),
415 'WordRightExtend' : (None, 0, 0, 0),
416 'Home' : (None, 0, 0, 0),
417 'HomeExtend' : (None, 0, 0, 0),
418 'LineEnd' : (None, 0, 0, 0),
419 'LineEndExtend' : (None, 0, 0, 0),
420 'DocumentStart' : (None, 0, 0, 0),
421 'DocumentStartExtend' : (None, 0, 0, 0),
422 'DocumentEnd' : (None, 0, 0, 0),
423 'DocumentEndExtend' : (None, 0, 0, 0),
424 'PageUp' : (None, 0, 0, 0),
425 'PageUpExtend' : (None, 0, 0, 0),
426 'PageDown' : (None, 0, 0, 0),
427 'PageDownExtend' : (None, 0, 0, 0),
428 'EditToggleOvertype' : (None, 0, 0, 0),
429 'Cancel' : (None, 0, 0, 0),
430 'DeleteBack' : (None, 0, 0, 0),
431 'Tab' : (None, 0, 0, 0),
432 'BackTab' : (None, 0, 0, 0),
433 'NewLine' : (None, 0, 0, 0),
434 'FormFeed' : (None, 0, 0, 0),
435 'VCHome' : (None, 0, 0, 0),
436 'VCHomeExtend' : (None, 0, 0, 0),
437 'ZoomIn' : (None, 0, 0, 0),
438 'ZoomOut' : (None, 0, 0, 0),
439 'DelWordLeft' : (None, 0, 0, 0),
440 'DelWordRight' : (None, 0, 0, 0),
441 'LineCut' : (None, 0, 0, 0),
442 'LineDelete' : (None, 0, 0, 0),
443 'LineTranspose' : (None, 0, 0, 0),
444 'LowerCase' : (None, 0, 0, 0),
445 'UpperCase' : (None, 0, 0, 0),
446 'LineScrollDown' : (None, 0, 0, 0),
447 'LineScrollUp' : (None, 0, 0, 0),
448
449
450 'GetDocPointer' : (0,
451 'void* %s();',
452 '''void* %s() {
453 return (void*)SendMsg(%s);''',
454 0),
455
456 'SetDocPointer' : (0,
457 'void %s(void* docPointer);',
458 '''void %s(void* docPointer) {
65ec6247 459 SendMsg(%s, 0, (long)docPointer);''',
f97d84a6
RD
460 0),
461
462 'CreateDocument' : (0,
463 'void* %s();',
464 '''void* %s() {
465 return (void*)SendMsg(%s);''',
466 0),
467
468 'AddRefDocument' : (0,
469 'void %s(void* docPointer);',
470 '''void %s(void* docPointer) {
471 SendMsg(%s, (long)docPointer);''',
472 0),
473
474 'ReleaseDocument' : (0,
475 'void %s(void* docPointer);',
476 '''void %s(void* docPointer) {
477 SendMsg(%s, (long)docPointer);''',
478 0),
479
480 'GrabFocus' : (None, 0, 0, 0),
8de28db9
RD
481 'SetFocus' : ('SetSTCFocus', 0, 0, 0),
482 'GetFocus' : ('GetSTCFocus', 0, 0, 0),
483
f97d84a6
RD
484
485 '' : ('', 0, 0, 0),
486
487 }
488
489#----------------------------------------------------------------------------
490
491def processIface(iface, h_tmplt, cpp_tmplt, h_dest, cpp_dest):
492 curDocStrings = []
493 values = []
494 methods = []
495
496 # parse iface file
497 fi = FileInput(iface)
498 for line in fi:
499 line = line[:-1]
500 if line[:2] == '##' or line == '':
501 #curDocStrings = []
502 continue
503
504 op = line[:4]
505 if line[:2] == '# ': # a doc string
506 curDocStrings.append(line[2:])
507
508 elif op == 'val ':
509 parseVal(line[4:], values, curDocStrings)
510 curDocStrings = []
511
512 elif op == 'fun ' or op == 'set ' or op == 'get ':
513 parseFun(line[4:], methods, curDocStrings, values)
514 curDocStrings = []
515
516 elif op == 'cat ':
517 if string.strip(line[4:]) == 'Deprecated':
518 break # skip the rest of the file
519
520 elif op == 'evt ':
521 pass
522
523 else:
524 print '***** Unknown line type: ', line
525
526
527 # process templates
528 data = {}
529 data['VALUES'] = processVals(values)
530 defs, imps = processMethods(methods)
531 data['METHOD_DEFS'] = defs
532 data['METHOD_IMPS'] = imps
533
534 # get template text
535 h_text = open(h_tmplt).read()
536 cpp_text = open(cpp_tmplt).read()
537
538 # do the substitutions
539 h_text = h_text % data
540 cpp_text = cpp_text % data
541
542 # write out destination files
543 open(h_dest, 'w').write(h_text)
544 open(cpp_dest, 'w').write(cpp_text)
545
546
547
548#----------------------------------------------------------------------------
549
550def processVals(values):
551 text = []
552 for name, value, docs in values:
553 if docs:
554 text.append('')
555 for x in docs:
556 text.append('// ' + x)
557 text.append('#define %s %s' % (name, value))
558 return string.join(text, '\n')
559
560#----------------------------------------------------------------------------
561
562def processMethods(methods):
563 defs = []
564 imps = []
565
566 for retType, name, number, param1, param2, docs in methods:
567 retType = retTypeMap.get(retType, retType)
568 params = makeParamString(param1, param2)
569
570 name, theDef, theImp, docs = checkMethodOverride(name, number, docs)
571
572 if name is None:
573 continue
574
575 # Build the method definition for the .h file
576 if docs:
577 defs.append('')
578 for x in docs:
579 defs.append(' // ' + x)
580 if not theDef:
581 theDef = ' %s %s(%s);' % (retType, name, params)
582 defs.append(theDef)
583
584 # Build the method implementation string
585 if docs:
586 imps.append('')
587 for x in docs:
588 imps.append('// ' + x)
589 if not theImp:
590 theImp = '%s wxStyledTextCtrl::%s(%s) {\n ' % (retType, name, params)
591
592 if retType == 'wxColour':
593 theImp = theImp + 'long c = '
594 elif retType != 'void':
595 theImp = theImp + 'return '
596 theImp = theImp + 'SendMsg(%s, %s, %s)' % (number,
597 makeArgString(param1),
598 makeArgString(param2))
599 if retType == 'bool':
600 theImp = theImp + ' != 0'
601 if retType == 'wxColour':
602 theImp = theImp + ';\n return wxColourFromLong(c)'
603
604 theImp = theImp + ';\n}'
605 imps.append(theImp)
606
607
608 return string.join(defs, '\n'), string.join(imps, '\n')
609
610
611#----------------------------------------------------------------------------
612
613def checkMethodOverride(name, number, docs):
614 theDef = theImp = None
615 if methodOverrideMap.has_key(name):
616 item = methodOverrideMap[name]
617
618 if item[0] != 0:
619 name = item[0]
620 if item[1] != 0:
621 theDef = ' ' + (item[1] % name)
622 if item[2] != 0:
623 theImp = item[2] % ('wxStyledTextCtrl::'+name, number) + '\n}'
624 if item[3] != 0:
625 docs = item[3]
626
627 return name, theDef, theImp, docs
628
629#----------------------------------------------------------------------------
630
631def makeArgString(param):
632 if not param:
633 return '0'
634
635 typ, name = param
636
637 if typ == 'string':
638 return '(long)%s.c_str()' % name
639 if typ == 'colour':
640 return 'wxColourAsLong(%s)' % name
641
642 return name
643
644#----------------------------------------------------------------------------
645
646def makeParamString(param1, param2):
647 def doOne(param):
648 if param:
649 aType = paramTypeMap.get(param[0], param[0])
650 return aType + ' ' + param[1]
651 else:
652 return ''
653
654 st = doOne(param1)
655 if st and param2:
656 st = st + ', '
657 st = st + doOne(param2)
658 return st
659
660
661#----------------------------------------------------------------------------
662
663def parseVal(line, values, docs):
664 name, val = string.split(line, '=')
665
666 # remove prefixes such as SCI, etc.
667 for old, new in valPrefixes:
668 lo = len(old)
669 if name[:lo] == old:
670 if new is None:
671 return
672 name = new + name[lo:]
673
674 # add it to the list
675 values.append( ('wxSTC_' + name, val, docs) )
676
677#----------------------------------------------------------------------------
678
679funregex = re.compile(r'\s*([a-zA-Z0-9_]+)' # <ws>return type
680 '\s+([a-zA-Z0-9_]+)=' # <ws>name=
681 '([0-9]+)' # number
682 '\(([ a-zA-Z0-9_]*),' # (param,
683 '([ a-zA-Z0-9_]*)\)') # param)
684
685def parseFun(line, methods, docs, values):
686 def parseParam(param):
687 param = string.strip(param)
688 if param == '':
689 param = None
690 else:
691 param = tuple(string.split(param))
692 return param
693
694 mo = funregex.match(line)
695 if mo is None:
696 print "***** Line doesn't match! : " + line
697
698 retType, name, number, param1, param2 = mo.groups()
699
700 param1 = parseParam(param1)
701 param2 = parseParam(param2)
702
703 # Special case. For the key command functionss we want a value defined too
704 num = string.atoi(number)
705 for v in cmdValues:
706 if (type(v) == type(()) and v[0] <= num < v[1]) or v == num:
707 parseVal('CMD_%s=%s' % (string.upper(name), number), values, ())
708
709 #if retType == 'void' and not param1 and not param2:
710
711 methods.append( (retType, name, number, param1, param2, tuple(docs)) )
712
713
714#----------------------------------------------------------------------------
715
716
717def main(args):
718 # TODO: parse command line args to replace default input/output files???
719
720 # Now just do it
721 processIface(IFACE, H_TEMPLATE, CPP_TEMPLATE, H_DEST, CPP_DEST)
722
723
724
725if __name__ == '__main__':
726 main(sys.argv)
727
728#----------------------------------------------------------------------------
729