]> git.saurik.com Git - wxWidgets.git/blame - src/stc/gen_iface.py
Add wxStyledTextCtrl::SelectNone() to the template header file too.
[wxWidgets.git] / src / stc / gen_iface.py
CommitLineData
3a38f8c1 1#!/usr/bin/env python
f97d84a6
RD
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
526954c5 11# Licence: wxWindows licence
f97d84a6
RD
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')
9e96e16f
RD
24if len(sys.argv) > 1 and sys.argv[1] == '--wxpython':
25 DOCSTR_DEST = os.path.abspath('../../../wxPython/src/_stc_gendocs.i')
26else:
27 DOCSTR_DEST = '/dev/null'
f97d84a6
RD
28
29
30# Value prefixes to convert
31valPrefixes = [('SCI_', ''),
32 ('SC_', ''),
37d62433 33 ('SCN_', None), # just toss these out...
f97d84a6 34 ('SCEN_', None),
9e96e16f 35 ('SC_EFF', None),
f97d84a6
RD
36 ('SCE_', ''),
37 ('SCLEX_', 'LEX_'),
38 ('SCK_', 'KEY_'),
39 ('SCFIND_', 'FIND_'),
40 ('SCWS_', 'WS_'),
41]
42
c26dba42 43# Message function values that should have a CMD_ constant generated
7e0c58e9 44cmdValues = [ 2011,
2b5f62a0
VZ
45 2013,
46 (2176, 2180),
7e0c58e9 47 (2300, 2349),
2b5f62a0
VZ
48 (2390, 2393),
49 (2395, 2396),
9e730a78
RD
50 2404,
51 (2413, 2416),
8e54aaed 52 (2426, 2442),
c26dba42 53 (2450, 2455),
7e0c58e9 54 2518,
54173563
RD
55 (2619, 2621),
56 (2628, 2629)
2b5f62a0 57 ]
f97d84a6
RD
58
59
c26dba42 60# Should a funciton be also generated for the CMDs?
713a0408 61FUNC_FOR_CMD = 1
c26dba42
RD
62
63
f97d84a6
RD
64# Map some generic typenames to wx types, using return value syntax
65retTypeMap = {
66 'position': 'int',
67 'string': 'wxString',
68 'colour': 'wxColour',
69 }
70
71# Map some generic typenames to wx types, using parameter syntax
72paramTypeMap = {
73 'position': 'int',
74 'string': 'const wxString&',
75 'colour': 'const wxColour&',
76 'keymod': 'int',
77}
78
79# Map of method info that needs tweaked. Either the name needs changed, or
80# the method definition/implementation. Tuple items are:
81#
82# 1. New method name. None to skip the method, 0 to leave the
83# default name.
84# 2. Method definition for the .h file, 0 to leave alone
85# 3. Method implementation for the .cpp file, 0 to leave alone.
86# 4. tuple of Doc string lines, or 0 to leave alone.
87#
88methodOverrideMap = {
89 'AddText' : (0,
90 'void %s(const wxString& text);',
91
92 '''void %s(const wxString& text) {
0bcbf72b
VZ
93 const wxWX2MBbuf buf = wx2stc(text);
94 SendMsg(%s, wx2stclen(text, buf), (sptr_t)(const char*)buf);''',
f97d84a6
RD
95 0),
96
97 'AddStyledText' : (0,
10ef30eb 98 'void %s(const wxMemoryBuffer& data);',
f97d84a6 99
10ef30eb 100 '''void %s(const wxMemoryBuffer& data) {
b796ba39 101 SendMsg(%s, data.GetDataLen(), (sptr_t)data.GetData());''',
f97d84a6
RD
102 0),
103
41a499cd
RD
104 'AppendText' : (0,
105 'void %s(const wxString& text);',
106
107 '''void %s(const wxString& text) {
0bcbf72b
VZ
108 const wxWX2MBbuf buf = wx2stc(text);
109 SendMsg(%s, wx2stclen(text, buf), (sptr_t)(const char*)buf);''',
41a499cd
RD
110 0),
111
f97d84a6
RD
112 'GetViewWS' : ( 'GetViewWhiteSpace', 0, 0, 0),
113 'SetViewWS' : ( 'SetViewWhiteSpace', 0, 0, 0),
114
9e730a78
RD
115 'GetCharAt' :
116 ( 0, 0,
8e0945da 117 '''int %s(int pos) const {
9e730a78
RD
118 return (unsigned char)SendMsg(%s, pos, 0);''',
119 0),
120
121 'GetStyleAt' :
122 ( 0, 0,
8e0945da 123 '''int %s(int pos) const {
9e730a78
RD
124 return (unsigned char)SendMsg(%s, pos, 0);''',
125 0),
126
127 'GetStyledText' :
128 (0,
129 'wxMemoryBuffer %s(int startPos, int endPos);',
130
131 '''wxMemoryBuffer %s(int startPos, int endPos) {
132 wxMemoryBuffer buf;
133 if (endPos < startPos) {
134 int temp = startPos;
135 startPos = endPos;
136 endPos = temp;
137 }
138 int len = endPos - startPos;
139 if (!len) return buf;
140 TextRange tr;
141 tr.lpstrText = (char*)buf.GetWriteBuf(len*2+1);
142 tr.chrg.cpMin = startPos;
143 tr.chrg.cpMax = endPos;
b796ba39 144 len = SendMsg(%s, 0, (sptr_t)&tr);
9e730a78
RD
145 buf.UngetWriteBuf(len);
146 return buf;''',
147
148 ('Retrieve a buffer of cells.',)),
149
150
151 'PositionFromPoint' :
152 (0,
2bfca191 153 'int %s(wxPoint pt) const;',
9e730a78 154
2bfca191 155 '''int %s(wxPoint pt) const {
9e730a78
RD
156 return SendMsg(%s, pt.x, pt.y);''',
157 0),
158
159 'GetCurLine' :
160 (0,
161 '#ifdef SWIG\n wxString %s(int* OUTPUT);\n#else\n wxString GetCurLine(int* linePos=NULL);\n#endif',
162
163 '''wxString %s(int* linePos) {
164 int len = LineLength(GetCurrentLine());
165 if (!len) {
166 if (linePos) *linePos = 0;
167 return wxEmptyString;
168 }
169
170 wxMemoryBuffer mbuf(len+1);
171 char* buf = (char*)mbuf.GetWriteBuf(len+1);
172
b796ba39 173 int pos = SendMsg(%s, len+1, (sptr_t)buf);
9e730a78
RD
174 mbuf.UngetWriteBuf(len);
175 mbuf.AppendByte(0);
176 if (linePos) *linePos = pos;
177 return stc2wx(buf);''',
178
179 0),
f97d84a6
RD
180
181 'SetUsePalette' : (None, 0,0,0),
182
183 'MarkerSetFore' : ('MarkerSetForeground', 0, 0, 0),
184 'MarkerSetBack' : ('MarkerSetBackground', 0, 0, 0),
54173563 185 'MarkerSetBackSelected' : ('MarkerSetBackgroundSelected', 0,0,0),
f97d84a6 186
9e96e16f
RD
187 'MarkerSymbolDefined' : ('GetMarkerSymbolDefined', 0, 0, 0),
188
9e730a78
RD
189 'MarkerDefine' :
190 (0,
191 '''void %s(int markerNumber, int markerSymbol,
192 const wxColour& foreground = wxNullColour,
193 const wxColour& background = wxNullColour);''',
194
195 '''void %s(int markerNumber, int markerSymbol,
196 const wxColour& foreground,
197 const wxColour& background) {
198
199 SendMsg(%s, markerNumber, markerSymbol);
f2b09926 200 if (foreground.IsOk())
9e730a78 201 MarkerSetForeground(markerNumber, foreground);
f2b09926 202 if (background.IsOk())
9e730a78
RD
203 MarkerSetBackground(markerNumber, background);''',
204
205 ('Set the symbol used for a particular marker number,',
206 'and optionally the fore and background colours.')),
207
208
209 'MarkerDefinePixmap' :
210 ('MarkerDefineBitmap',
211 '''void %s(int markerNumber, const wxBitmap& bmp);''',
212 '''void %s(int markerNumber, const wxBitmap& bmp) {
213 // convert bmp to a xpm in a string
214 wxMemoryOutputStream strm;
215 wxImage img = bmp.ConvertToImage();
e45b3f17
RD
216 if (img.HasAlpha())
217 img.ConvertAlphaToMask();
9e730a78
RD
218 img.SaveFile(strm, wxBITMAP_TYPE_XPM);
219 size_t len = strm.GetSize();
220 char* buff = new char[len+1];
221 strm.CopyTo(buff, len);
222 buff[len] = 0;
b796ba39 223 SendMsg(%s, markerNumber, (sptr_t)buff);
9e730a78
RD
224 delete [] buff;
225 ''',
226 ('Define a marker from a bitmap',)),
f97d84a6 227
f97d84a6
RD
228
229 'SetMarginTypeN' : ('SetMarginType', 0, 0, 0),
230 'GetMarginTypeN' : ('GetMarginType', 0, 0, 0),
231 'SetMarginWidthN' : ('SetMarginWidth', 0, 0, 0),
232 'GetMarginWidthN' : ('GetMarginWidth', 0, 0, 0),
233 'SetMarginMaskN' : ('SetMarginMask', 0, 0, 0),
234 'GetMarginMaskN' : ('GetMarginMask', 0, 0, 0),
235 'SetMarginSensitiveN' : ('SetMarginSensitive', 0, 0, 0),
236 'GetMarginSensitiveN' : ('GetMarginSensitive', 0, 0, 0),
54173563
RD
237 'SetMarginCursorN' : ('SetMarginCursor', 0, 0, 0),
238 'GetMarginCursorN' : ('GetMarginCursor', 0, 0, 0),
239
9e96e16f
RD
240 'MarginGetText' :
241 (0,
242 'wxString %s(int line) const;',
243
244 '''wxString %s(int line) const {
245 long msg = %s;
246 long len = SendMsg(msg, line, 0);
247
248 wxMemoryBuffer mbuf(len+1);
249 char* buf = (char*)mbuf.GetWriteBuf(len+1);
250 SendMsg(msg, line, (sptr_t)buf);
251 mbuf.UngetWriteBuf(len);
252 mbuf.AppendByte(0);
253 return stc2wx(buf);''',
254 0),
255
256 'MarginGetStyles' :
257 (0,
258 'wxString %s(int line) const;',
259
260 '''wxString %s(int line) const {
261 long msg = %s;
262 long len = SendMsg(msg, line, 0);
263
264 wxMemoryBuffer mbuf(len+1);
265 char* buf = (char*)mbuf.GetWriteBuf(len+1);
266 SendMsg(msg, line, (sptr_t)buf);
267 mbuf.UngetWriteBuf(len);
268 mbuf.AppendByte(0);
269 return stc2wx(buf);''',
270 0),
271
272 'SetAdditionalSelFore' : ('SetAdditionalSelForeground', 0, 0, 0),
273 'SetAdditionalSelBack' : ('SetAdditionalSelBackground', 0, 0, 0),
274 'SetAdditionalCaretFore' : ('SetAdditionalCaretForeground', 0, 0, 0),
275 'GetAdditionalCaretFore' : ('GetAdditionalCaretForeground', 0, 0, 0),
276
277 'AnnotationGetText' :
278 (0,
279 'wxString %s(int line) const;',
280
281 '''wxString %s(int line) const {
282 long msg = %s;
283 long len = SendMsg(msg, line, 0);
284
285 wxMemoryBuffer mbuf(len+1);
286 char* buf = (char*)mbuf.GetWriteBuf(len+1);
287 SendMsg(msg, line, (sptr_t)buf);
288 mbuf.UngetWriteBuf(len);
289 mbuf.AppendByte(0);
290 return stc2wx(buf);''',
291 0),
292
293 'AnnotationGetStyles' :
294 (0,
295 'wxString %s(int line) const;',
296
297 '''wxString %s(int line) const {
298 long msg = %s;
299 long len = SendMsg(msg, line, 0);
300
301 wxMemoryBuffer mbuf(len+1);
302 char* buf = (char*)mbuf.GetWriteBuf(len+1);
303 SendMsg(msg, line, (sptr_t)buf);
304 mbuf.UngetWriteBuf(len);
305 mbuf.AppendByte(0);
306 return stc2wx(buf);''',
307 0),
7e0c58e9
RD
308
309 'StyleGetFore' : ('StyleGetForeground', 0, 0, 0),
310 'StyleGetBack' : ('StyleGetBackground', 0, 0, 0),
f97d84a6
RD
311 'StyleSetFore' : ('StyleSetForeground', 0, 0, 0),
312 'StyleSetBack' : ('StyleSetBackground', 0, 0, 0),
313 'SetSelFore' : ('SetSelForeground', 0, 0, 0),
314 'SetSelBack' : ('SetSelBackground', 0, 0, 0),
315 'SetCaretFore' : ('SetCaretForeground', 0, 0, 0),
591e2d8e 316 'StyleGetFont' :
7e0c58e9
RD
317 ('StyleGetFaceName',
318 'wxString %s(int style);',
319 '''wxString %s(int style) {
320 long msg = %s;
321 long len = SendMsg(msg, style, 0);
322 wxMemoryBuffer mbuf(len+1);
323 char* buf = (char*)mbuf.GetWriteBuf(len+1);
b796ba39 324 SendMsg(msg, style, (sptr_t)buf);
7e0c58e9
RD
325 mbuf.UngetWriteBuf(len);
326 mbuf.AppendByte(0);
327 return stc2wx(buf);''',
328 ('Get the font facename of a style',)),
f97d84a6 329 'StyleSetFont' : ('StyleSetFaceName', 0, 0, 0),
3727c043 330 'StyleSetCharacterSet' : (None, 0, 0, 0),
591e2d8e 331
9e730a78
RD
332 'AssignCmdKey' :
333 ('CmdKeyAssign',
334 'void %s(int key, int modifiers, int cmd);',
f97d84a6 335
9e730a78
RD
336 '''void %s(int key, int modifiers, int cmd) {
337 SendMsg(%s, MAKELONG(key, modifiers), cmd);''',
338 0),
f97d84a6 339
f97d84a6 340
9e730a78
RD
341 'ClearCmdKey' :
342 ('CmdKeyClear',
343 'void %s(int key, int modifiers);',
f97d84a6 344
9e730a78
RD
345 '''void %s(int key, int modifiers) {
346 SendMsg(%s, MAKELONG(key, modifiers));''',
347 0),
f97d84a6
RD
348
349 'ClearAllCmdKeys' : ('CmdKeyClearAll', 0, 0, 0),
350
351
9e730a78
RD
352 'SetStylingEx' :
353 ('SetStyleBytes',
354 'void %s(int length, char* styleBytes);',
f97d84a6 355
9e730a78 356 '''void %s(int length, char* styleBytes) {
b796ba39 357 SendMsg(%s, length, (sptr_t)styleBytes);''',
9e730a78 358 0),
f97d84a6
RD
359
360
9e96e16f
RD
361 'IndicSetAlpha' : ('IndicatorSetAlpha', 0, 0, 0),
362 'IndicGetAlpha' : ('IndicatorGetAlpha', 0, 0, 0),
54173563
RD
363 'IndicSetOutlineAlpha' : ('IndicatorSetOutlineAlpha', 0, 0, 0),
364 'IndicGetOutlineAlpha' : ('IndicatorGetOutlineAlpha', 0, 0, 0),
f97d84a6
RD
365 'IndicSetStyle' : ('IndicatorSetStyle', 0, 0, 0),
366 'IndicGetStyle' : ('IndicatorGetStyle', 0, 0, 0),
367 'IndicSetFore' : ('IndicatorSetForeground', 0, 0, 0),
368 'IndicGetFore' : ('IndicatorGetForeground', 0, 0, 0),
7e0c58e9
RD
369 'IndicSetUnder': ('IndicatorSetUnder', 0, 0, 0),
370 'IndicGetUnder': ('IndicatorGetUnder', 0, 0, 0),
591e2d8e 371
f114b858
RD
372 'SetWhitespaceFore' : ('SetWhitespaceForeground', 0, 0, 0),
373 'SetWhitespaceBack' : ('SetWhitespaceBackground', 0, 0, 0),
374
f97d84a6
RD
375 'AutoCShow' : ('AutoCompShow', 0, 0, 0),
376 'AutoCCancel' : ('AutoCompCancel', 0, 0, 0),
377 'AutoCActive' : ('AutoCompActive', 0, 0, 0),
378 'AutoCPosStart' : ('AutoCompPosStart', 0, 0, 0),
379 'AutoCComplete' : ('AutoCompComplete', 0, 0, 0),
380 'AutoCStops' : ('AutoCompStops', 0, 0, 0),
381 'AutoCSetSeparator' : ('AutoCompSetSeparator', 0, 0, 0),
382 'AutoCGetSeparator' : ('AutoCompGetSeparator', 0, 0, 0),
383 'AutoCSelect' : ('AutoCompSelect', 0, 0, 0),
384 'AutoCSetCancelAtStart' : ('AutoCompSetCancelAtStart', 0, 0, 0),
385 'AutoCGetCancelAtStart' : ('AutoCompGetCancelAtStart', 0, 0, 0),
386 'AutoCSetFillUps' : ('AutoCompSetFillUps', 0, 0, 0),
387 'AutoCSetChooseSingle' : ('AutoCompSetChooseSingle', 0, 0, 0),
388 'AutoCGetChooseSingle' : ('AutoCompGetChooseSingle', 0, 0, 0),
389 'AutoCSetIgnoreCase' : ('AutoCompSetIgnoreCase', 0, 0, 0),
390 'AutoCGetIgnoreCase' : ('AutoCompGetIgnoreCase', 0, 0, 0),
65ec6247
RD
391 'AutoCSetAutoHide' : ('AutoCompSetAutoHide', 0, 0, 0),
392 'AutoCGetAutoHide' : ('AutoCompGetAutoHide', 0, 0, 0),
1a2fb4cd
RD
393 'AutoCSetDropRestOfWord' : ('AutoCompSetDropRestOfWord', 0,0,0),
394 'AutoCGetDropRestOfWord' : ('AutoCompGetDropRestOfWord', 0,0,0),
9e730a78
RD
395 'AutoCGetTypeSeparator' : ('AutoCompGetTypeSeparator', 0, 0, 0),
396 'AutoCSetTypeSeparator' : ('AutoCompSetTypeSeparator', 0, 0, 0),
8e54aaed 397 'AutoCGetCurrent' : ('AutoCompGetCurrent', 0, 0, 0),
9e96e16f 398 'AutoCGetCurrentText' : (None, 0, 0, 0),
1e9bafca
RD
399 'AutoCSetMaxWidth' : ('AutoCompSetMaxWidth', 0, 0, 0),
400 'AutoCGetMaxWidth' : ('AutoCompGetMaxWidth', 0, 0, 0),
401 'AutoCSetMaxHeight' : ('AutoCompSetMaxHeight', 0, 0, 0),
402 'AutoCGetMaxHeight' : ('AutoCompGetMaxHeight', 0, 0, 0),
403 'AutoCGetMaxHeight' : ('AutoCompGetMaxHeight', 0, 0, 0),
54173563
RD
404 'AutoCSetCaseInsensitiveBehaviour' : ('AutoCompSetCaseInsensitiveBehaviour', 0, 0, 0),
405 'AutoCGetCaseInsensitiveBehaviour' : ('AutoCompGetCaseInsensitiveBehaviour', 0, 0, 0),
591e2d8e 406
9e730a78
RD
407 'RegisterImage' :
408 (0,
409 '''void %s(int type, const wxBitmap& bmp);''',
410 '''void %s(int type, const wxBitmap& bmp) {
411 // convert bmp to a xpm in a string
412 wxMemoryOutputStream strm;
413 wxImage img = bmp.ConvertToImage();
e45b3f17
RD
414 if (img.HasAlpha())
415 img.ConvertAlphaToMask();
9e730a78
RD
416 img.SaveFile(strm, wxBITMAP_TYPE_XPM);
417 size_t len = strm.GetSize();
418 char* buff = new char[len+1];
419 strm.CopyTo(buff, len);
420 buff[len] = 0;
b796ba39 421 SendMsg(%s, type, (sptr_t)buff);
9e730a78
RD
422 delete [] buff;
423 ''',
424 ('Register an image for use in autocompletion lists.',)),
425
426
427 'ClearRegisteredImages' : (0, 0, 0,
428 ('Clear all the registered images.',)),
65ec6247 429
f97d84a6
RD
430
431 'SetHScrollBar' : ('SetUseHorizontalScrollBar', 0, 0, 0),
432 'GetHScrollBar' : ('GetUseHorizontalScrollBar', 0, 0, 0),
433
9e730a78
RD
434 'SetVScrollBar' : ('SetUseVerticalScrollBar', 0, 0, 0),
435 'GetVScrollBar' : ('GetUseVerticalScrollBar', 0, 0, 0),
436
f97d84a6
RD
437 'GetCaretFore' : ('GetCaretForeground', 0, 0, 0),
438
439 'GetUsePalette' : (None, 0, 0, 0),
440
9e730a78
RD
441 'FindText' :
442 (0,
443 '''int %s(int minPos, int maxPos, const wxString& text, int flags=0);''',
444
445 '''int %s(int minPos, int maxPos,
446 const wxString& text,
447 int flags) {
448 TextToFind ft;
449 ft.chrg.cpMin = minPos;
450 ft.chrg.cpMax = maxPos;
0bcbf72b 451 const wxWX2MBbuf buf = wx2stc(text);
9e730a78
RD
452 ft.lpstrText = (char*)(const char*)buf;
453
b796ba39 454 return SendMsg(%s, flags, (sptr_t)&ft);''',
9e730a78
RD
455 0),
456
457 'FormatRange' :
458 (0,
459 '''int %s(bool doDraw,
460 int startPos,
461 int endPos,
462 wxDC* draw,
591e2d8e 463 wxDC* target,
9e730a78
RD
464 wxRect renderRect,
465 wxRect pageRect);''',
466 ''' int %s(bool doDraw,
467 int startPos,
468 int endPos,
469 wxDC* draw,
591e2d8e 470 wxDC* target,
9e730a78
RD
471 wxRect renderRect,
472 wxRect pageRect) {
473 RangeToFormat fr;
474
475 if (endPos < startPos) {
476 int temp = startPos;
477 startPos = endPos;
478 endPos = temp;
479 }
480 fr.hdc = draw;
481 fr.hdcTarget = target;
482 fr.rc.top = renderRect.GetTop();
483 fr.rc.left = renderRect.GetLeft();
484 fr.rc.right = renderRect.GetRight();
485 fr.rc.bottom = renderRect.GetBottom();
486 fr.rcPage.top = pageRect.GetTop();
487 fr.rcPage.left = pageRect.GetLeft();
488 fr.rcPage.right = pageRect.GetRight();
489 fr.rcPage.bottom = pageRect.GetBottom();
490 fr.chrg.cpMin = startPos;
491 fr.chrg.cpMax = endPos;
492
b796ba39 493 return SendMsg(%s, doDraw, (sptr_t)&fr);''',
9e730a78
RD
494 0),
495
496
497 'GetLine' :
498 (0,
2bfca191 499 'wxString %s(int line) const;',
9e730a78 500
2bfca191 501 '''wxString %s(int line) const {
9e730a78
RD
502 int len = LineLength(line);
503 if (!len) return wxEmptyString;
504
505 wxMemoryBuffer mbuf(len+1);
506 char* buf = (char*)mbuf.GetWriteBuf(len+1);
b796ba39 507 SendMsg(%s, line, (sptr_t)buf);
9e730a78
RD
508 mbuf.UngetWriteBuf(len);
509 mbuf.AppendByte(0);
510 return stc2wx(buf);''',
511
512 ('Retrieve the contents of a line.',)),
f97d84a6 513
fa70ec2b 514 'SetSel' : (None, 0,0,0), #'SetSelection', 0, 0, 0),
9e730a78
RD
515
516 'GetSelText' :
517 ('GetSelectedText',
518 'wxString %s();',
519
520 '''wxString %s() {
6094165c 521 const int len = SendMsg(SCI_GETSELTEXT, 0, (sptr_t)0);
9e730a78
RD
522 if (!len) return wxEmptyString;
523
3d7a4fe8 524 wxMemoryBuffer mbuf(len+2);
9e730a78 525 char* buf = (char*)mbuf.GetWriteBuf(len+1);
b796ba39 526 SendMsg(%s, 0, (sptr_t)buf);
9e730a78
RD
527 mbuf.UngetWriteBuf(len);
528 mbuf.AppendByte(0);
529 return stc2wx(buf);''',
530
531 ('Retrieve the selected text.',)),
532
533
534 'GetTextRange' :
535 (0,
536 'wxString %s(int startPos, int endPos);',
537
538 '''wxString %s(int startPos, int endPos) {
539 if (endPos < startPos) {
540 int temp = startPos;
541 startPos = endPos;
542 endPos = temp;
543 }
544 int len = endPos - startPos;
545 if (!len) return wxEmptyString;
546 wxMemoryBuffer mbuf(len+1);
547 char* buf = (char*)mbuf.GetWriteBuf(len);
548 TextRange tr;
549 tr.lpstrText = buf;
550 tr.chrg.cpMin = startPos;
551 tr.chrg.cpMax = endPos;
b796ba39 552 SendMsg(%s, 0, (sptr_t)&tr);
9e730a78
RD
553 mbuf.UngetWriteBuf(len);
554 mbuf.AppendByte(0);
555 return stc2wx(buf);''',
556
557 ('Retrieve a range of text.',)),
f97d84a6
RD
558
559 'PointXFromPosition' : (None, 0, 0, 0),
560 'PointYFromPosition' : (None, 0, 0, 0),
561
562 'ScrollCaret' : ('EnsureCaretVisible', 0, 0, 0),
563 'ReplaceSel' : ('ReplaceSelection', 0, 0, 0),
564 'Null' : (None, 0, 0, 0),
565
9e730a78
RD
566 'GetText' :
567 (0,
93578927 568 'wxString %s() const;',
f97d84a6 569
93578927 570 '''wxString %s() const {
9e730a78
RD
571 int len = GetTextLength();
572 wxMemoryBuffer mbuf(len+1); // leave room for the null...
573 char* buf = (char*)mbuf.GetWriteBuf(len+1);
b796ba39 574 SendMsg(%s, len+1, (sptr_t)buf);
9e730a78
RD
575 mbuf.UngetWriteBuf(len);
576 mbuf.AppendByte(0);
577 return stc2wx(buf);''',
f97d84a6 578
9e730a78 579 ('Retrieve all the text in the document.', )),
f97d84a6
RD
580
581 'GetDirectFunction' : (None, 0, 0, 0),
582 'GetDirectPointer' : (None, 0, 0, 0),
583
9e730a78
RD
584 'CallTipPosStart' : ('CallTipPosAtStart', 0, 0, 0),
585 'CallTipSetHlt' : ('CallTipSetHighlight', 0, 0, 0),
586 'CallTipSetBack' : ('CallTipSetBackground', 0, 0, 0),
587 'CallTipSetFore' : ('CallTipSetForeground', 0, 0, 0),
588 'CallTipSetForeHlt' : ('CallTipSetForegroundHighlight', 0, 0, 0),
589
590 'SetHotspotActiveFore' : ('SetHotspotActiveForeground', 0, 0, 0),
591 'SetHotspotActiveBack' : ('SetHotspotActiveBackground', 0, 0, 0),
7e0c58e9
RD
592 'GetHotspotActiveFore' : ('GetHotspotActiveForeground', 0, 0, 0),
593 'GetHotspotActiveBack' : ('GetHotspotActiveBackground', 0, 0, 0),
591e2d8e 594
6a93571d
RD
595 'GetCaretLineBack' : ('GetCaretLineBackground', 0, 0, 0),
596 'SetCaretLineBack' : ('SetCaretLineBackground', 0, 0, 0),
9e730a78
RD
597
598 'ReplaceTarget' :
599 (0,
600 'int %s(const wxString& text);',
601
602 '''
603 int %s(const wxString& text) {
0bcbf72b
VZ
604 const wxWX2MBbuf buf = wx2stc(text);
605 return SendMsg(%s, wx2stclen(text, buf), (sptr_t)(const char*)buf);''',
9e730a78
RD
606 0),
607
608 'ReplaceTargetRE' :
609 (0,
610 'int %s(const wxString& text);',
611
612 '''
613 int %s(const wxString& text) {
0bcbf72b
VZ
614 const wxWX2MBbuf buf = wx2stc(text);
615 return SendMsg(%s, wx2stclen(text, buf), (sptr_t)(const char*)buf);''',
9e730a78
RD
616 0),
617
618 'SearchInTarget' :
619 (0,
620 'int %s(const wxString& text);',
621
622 '''
623 int %s(const wxString& text) {
0bcbf72b
VZ
624 const wxWX2MBbuf buf = wx2stc(text);
625 return SendMsg(%s, wx2stclen(text, buf), (sptr_t)(const char*)buf);''',
9e730a78
RD
626 0),
627
a33203cb
RD
628 # not sure what to do about these yet
629 'TargetAsUTF8' : ( None, 0, 0, 0),
630 'SetLengthForEncode' : ( None, 0, 0, 0),
631 'EncodedFromUTF8' : ( None, 0, 0, 0),
1e9bafca
RD
632
633
634 'GetProperty' :
635 (0,
636 'wxString %s(const wxString& key);',
637
638 '''wxString %s(const wxString& key) {
b796ba39 639 int len = SendMsg(SCI_GETPROPERTY, (sptr_t)(const char*)wx2stc(key), 0);
1e9bafca
RD
640 if (!len) return wxEmptyString;
641
642 wxMemoryBuffer mbuf(len+1);
643 char* buf = (char*)mbuf.GetWriteBuf(len+1);
b796ba39 644 SendMsg(%s, (uptr_t)(const char*)wx2stc(key), (sptr_t)buf);
1e9bafca
RD
645 mbuf.UngetWriteBuf(len);
646 mbuf.AppendByte(0);
647 return stc2wx(buf);''',
648 ("Retrieve a 'property' value previously set with SetProperty.",)),
649
650 'GetPropertyExpanded' :
651 (0,
652 'wxString %s(const wxString& key);',
653
654 '''wxString %s(const wxString& key) {
b796ba39 655 int len = SendMsg(SCI_GETPROPERTYEXPANDED, (uptr_t)(const char*)wx2stc(key), 0);
1e9bafca
RD
656 if (!len) return wxEmptyString;
657
658 wxMemoryBuffer mbuf(len+1);
659 char* buf = (char*)mbuf.GetWriteBuf(len+1);
b796ba39 660 SendMsg(%s, (uptr_t)(const char*)wx2stc(key), (sptr_t)buf);
1e9bafca
RD
661 mbuf.UngetWriteBuf(len);
662 mbuf.AppendByte(0);
663 return stc2wx(buf);''',
664 ("Retrieve a 'property' value previously set with SetProperty,",
665 "with '$()' variable replacement on returned buffer.")),
666
667 'GetPropertyInt' : (0, 0, 0,
668 ("Retrieve a 'property' value previously set with SetProperty,",
669 "interpreted as an int AFTER any '$()' variable replacement.")),
670
9e730a78
RD
671
672 'GetDocPointer' :
673 (0,
674 'void* %s();',
675 '''void* %s() {
676 return (void*)SendMsg(%s);''',
677 0),
678
679 'SetDocPointer' :
680 (0,
681 'void %s(void* docPointer);',
682 '''void %s(void* docPointer) {
b796ba39 683 SendMsg(%s, 0, (sptr_t)docPointer);''',
9e730a78
RD
684 0),
685
686 'CreateDocument' :
687 (0,
688 'void* %s();',
689 '''void* %s() {
690 return (void*)SendMsg(%s);''',
691 0),
692
693 'AddRefDocument' :
694 (0,
695 'void %s(void* docPointer);',
696 '''void %s(void* docPointer) {
b796ba39 697 SendMsg(%s, 0, (sptr_t)docPointer);''',
9e730a78
RD
698 0),
699
700 'ReleaseDocument' :
701 (0,
702 'void %s(void* docPointer);',
703 '''void %s(void* docPointer) {
b796ba39 704 SendMsg(%s, 0, (sptr_t)docPointer);''',
9e730a78
RD
705 0),
706
707 'SetCodePage' :
708 (0,
709 0,
710 '''void %s(int codePage) {
2b5f62a0
VZ
711#if wxUSE_UNICODE
712 wxASSERT_MSG(codePage == wxSTC_CP_UTF8,
713 wxT("Only wxSTC_CP_UTF8 may be used when wxUSE_UNICODE is on."));
714#else
715 wxASSERT_MSG(codePage != wxSTC_CP_UTF8,
716 wxT("wxSTC_CP_UTF8 may not be used when wxUSE_UNICODE is off."));
717#endif
9e730a78
RD
718 SendMsg(%s, codePage);''',
719 ("Set the code page used to interpret the bytes of the document as characters.",) ),
2b5f62a0
VZ
720
721
722 'GrabFocus' : (None, 0, 0, 0),
88a8b04e 723
c26dba42 724 # Rename some that would otherwise hide the wxWindow methods
2b5f62a0
VZ
725 'SetFocus' : ('SetSTCFocus', 0, 0, 0),
726 'GetFocus' : ('GetSTCFocus', 0, 0, 0),
88a8b04e
RD
727 'SetCursor' : ('SetSTCCursor', 0, 0, 0),
728 'GetCursor' : ('GetSTCCursor', 0, 0, 0),
2b5f62a0 729
9e730a78
RD
730 'LoadLexerLibrary' : (None, 0,0,0),
731
7e0c58e9
RD
732 'SetPositionCache' : ('SetPositionCacheSize', 0, 0, 0),
733 'GetPositionCache' : ('GetPositionCacheSize', 0, 0, 0),
734
9e96e16f
RD
735 'GetLexerLanguage' : (None, 0, 0, 0),
736 'SetFontQuality' : (None, 0, 0, 0),
737 'GetFontQuality' : (None, 0, 0, 0),
738 'SetSelection' : (None, 0, 0, 0),
739
740 'GetCharacterPointer' : (0,
54173563
RD
741 'const char* %s() const;',
742 'const char* %s() const {\n'
9e96e16f
RD
743 ' return (const char*)SendMsg(%s, 0, 0);',
744 0),
745
54173563
RD
746 'GetRangePointer' : (0,
747 'const char* %s(int position, int rangeLength) const;',
748 'const char* %s(int position, int rangeLength) const {\n'
749 ' return (const char*)SendMsg(%s, position, rangeLength);',
750 0),
751
9e730a78 752
9b01abb8
RD
753 'GetWordChars' :
754 (0,
755 'wxString %s() const;',
756
757 '''wxString %s() const {
758 int msg = %s;
c4bdd822 759 int len = SendMsg(msg, 0, (sptr_t)NULL);
9b01abb8
RD
760 if (!len) return wxEmptyString;
761
762 wxMemoryBuffer mbuf(len+1);
763 char* buf = (char*)mbuf.GetWriteBuf(len+1);
54173563 764 SendMsg(msg, 0, (sptr_t)buf);
9b01abb8
RD
765 mbuf.UngetWriteBuf(len);
766 mbuf.AppendByte(0);
767 return stc2wx(buf);''',
768
769 ('Get the set of characters making up words for when moving or selecting by word.',)),
770
771 'GetTag' :
772 (0,
773 'wxString %s(int tagNumber) const;',
774
775 '''wxString %s(int tagNumber) const {
776 int msg = %s;
c4bdd822 777 int len = SendMsg(msg, tagNumber, (sptr_t)NULL);
9b01abb8
RD
778 if (!len) return wxEmptyString;
779
780 wxMemoryBuffer mbuf(len+1);
781 char* buf = (char*)mbuf.GetWriteBuf(len+1);
782 SendMsg(msg, tagNumber, (sptr_t)buf);
783 mbuf.UngetWriteBuf(len);
784 mbuf.AppendByte(0);
785 return stc2wx(buf);''',
786 0),
787
788 'GetWhitespaceChars' :
789 (0,
790 'wxString %s() const;',
791
792 '''wxString %s() const {
793 int msg = %s;
c4bdd822 794 int len = SendMsg(msg, 0, (sptr_t)NULL);
9b01abb8
RD
795 if (!len) return wxEmptyString;
796
797 wxMemoryBuffer mbuf(len+1);
798 char* buf = (char*)mbuf.GetWriteBuf(len+1);
54173563 799 SendMsg(msg, 0, (sptr_t)buf);
9b01abb8
RD
800 mbuf.UngetWriteBuf(len);
801 mbuf.AppendByte(0);
802 return stc2wx(buf);''',
803 0),
804
805
806 'GetPunctuationChars' :
807 (0,
808 'wxString %s() const;',
809
810 '''wxString %s() const {
811 int msg = %s;
c4bdd822 812 int len = SendMsg(msg, 0, (sptr_t)NULL);
9b01abb8
RD
813 if (!len) return wxEmptyString;
814
815 wxMemoryBuffer mbuf(len+1);
816 char* buf = (char*)mbuf.GetWriteBuf(len+1);
54173563 817 SendMsg(msg, 0, (sptr_t)buf);
9b01abb8
RD
818 mbuf.UngetWriteBuf(len);
819 mbuf.AppendByte(0);
820 return stc2wx(buf);''',
821 0),
822
823
824 'PropertyNames' :
825 (0,
826 'wxString %s() const;',
827
828 '''wxString %s() const {
829 int msg = %s;
c4bdd822 830 int len = SendMsg(msg, 0, (sptr_t)NULL);
9b01abb8
RD
831 if (!len) return wxEmptyString;
832
833 wxMemoryBuffer mbuf(len+1);
834 char* buf = (char*)mbuf.GetWriteBuf(len+1);
54173563 835 SendMsg(msg, 0, (sptr_t)buf);
9b01abb8
RD
836 mbuf.UngetWriteBuf(len);
837 mbuf.AppendByte(0);
838 return stc2wx(buf);''',
839 0),
840
841
842
843 'DescribeProperty' :
844 (0,
845 'wxString %s(const wxString& name) const;',
846
847 '''wxString %s(const wxString& name) const {
848 int msg = %s;
c4bdd822 849 int len = SendMsg(msg, (sptr_t)(const char*)wx2stc(name), (sptr_t)NULL);
9b01abb8
RD
850 if (!len) return wxEmptyString;
851
852 wxMemoryBuffer mbuf(len+1);
853 char* buf = (char*)mbuf.GetWriteBuf(len+1);
854 SendMsg(msg, (sptr_t)(const char*)wx2stc(name), (sptr_t)buf);
855 mbuf.UngetWriteBuf(len);
856 mbuf.AppendByte(0);
857 return stc2wx(buf);''',
858 0),
859
860
861
862 'DescribeKeyWordSets' :
863 (0,
864 'wxString %s() const;',
865
866 '''wxString %s() const {
867 int msg = %s;
c4bdd822 868 int len = SendMsg(msg, 0, (sptr_t)NULL);
9b01abb8
RD
869 if (!len) return wxEmptyString;
870
871 wxMemoryBuffer mbuf(len+1);
872 char* buf = (char*)mbuf.GetWriteBuf(len+1);
54173563 873 SendMsg(msg, 0, (sptr_t)buf);
9b01abb8
RD
874 mbuf.UngetWriteBuf(len);
875 mbuf.AppendByte(0);
876 return stc2wx(buf);''',
877 0),
54173563
RD
878
879
880 'MarkerDefineRGBAImage' :
881 (0,
882 'void %s(int markerNumber, const unsigned char* pixels);',
883 '''void %s(int markerNumber, const unsigned char* pixels) {
884 SendMsg(%s, markerNumber, (sptr_t)pixels);''',
885 0),
886
887
888 'RegisterRGBAImage' :
889 (0,
890 'void %s(int type, const unsigned char* pixels);',
891 '''void %s(int type, const unsigned char* pixels) {
892 SendMsg(%s, type, (sptr_t)pixels);''',
893 0),
9b01abb8
RD
894
895
54173563
RD
896 # I think these are only available on the native OSX backend, so
897 # don't add them to the wx API...
898 'FindIndicatorShow' : (None, 0,0,0),
899 'FindIndicatorFlash' : (None, 0,0,0),
900 'FindIndicatorHide' : (None, 0,0,0),
901
902 'CreateLoader' :
903 (0,
904 'void* %s(int bytes) const;',
905 """void* %s(int bytes) const {
906 return (void*)(sptr_t)SendMsg(%s, bytes); """,
907 0),
9b01abb8 908
54173563
RD
909 'PrivateLexerCall' :
910 (0,
911 'void* %s(int operation, void* pointer);',
912 """void* %s(int operation, void* pointer) {
913 return (void*)(sptr_t)SendMsg(%s, operation, (sptr_t)pointer); """,
914 0),
915
f97d84a6
RD
916 '' : ('', 0, 0, 0),
917
918 }
919
2bfca191
VZ
920# all Scintilla getters are transformed into const member of wxSTC class but
921# some non-getter methods are also logically const and this set contains their
922# names (notice that it's useless to include here methods manually overridden
923# above)
713a0408 924constNonGetterMethods = (
2bfca191
VZ
925 'LineFromPosition',
926 'PositionFromLine',
927 'LineLength',
7d6d76d0 928 'CanPaste',
93578927
VZ
929 'CanRedo',
930 'CanUndo',
713a0408 931)
2bfca191 932
f97d84a6
RD
933#----------------------------------------------------------------------------
934
f2ccce28 935def processIface(iface, h_tmplt, cpp_tmplt, h_dest, cpp_dest, docstr_dest):
f97d84a6
RD
936 curDocStrings = []
937 values = []
938 methods = []
2b5f62a0 939 cmds = []
f97d84a6
RD
940
941 # parse iface file
942 fi = FileInput(iface)
943 for line in fi:
944 line = line[:-1]
945 if line[:2] == '##' or line == '':
946 #curDocStrings = []
947 continue
948
949 op = line[:4]
950 if line[:2] == '# ': # a doc string
951 curDocStrings.append(line[2:])
952
953 elif op == 'val ':
954 parseVal(line[4:], values, curDocStrings)
955 curDocStrings = []
956
957 elif op == 'fun ' or op == 'set ' or op == 'get ':
8e0945da 958 parseFun(line[4:], methods, curDocStrings, cmds, op == 'get ')
f97d84a6
RD
959 curDocStrings = []
960
961 elif op == 'cat ':
016a3d4c 962 if line[4:].strip() == 'Deprecated':
f97d84a6
RD
963 break # skip the rest of the file
964
965 elif op == 'evt ':
966 pass
967
a834585d
RD
968 elif op == 'enu ':
969 pass
970
971 elif op == 'lex ':
972 pass
973
f97d84a6 974 else:
016a3d4c 975 print('***** Unknown line type: %s' % line)
f97d84a6
RD
976
977
978 # process templates
979 data = {}
980 data['VALUES'] = processVals(values)
2b5f62a0 981 data['CMDS'] = processVals(cmds)
f2ccce28 982 defs, imps, docstrings = processMethods(methods)
f97d84a6
RD
983 data['METHOD_DEFS'] = defs
984 data['METHOD_IMPS'] = imps
985
986 # get template text
987 h_text = open(h_tmplt).read()
988 cpp_text = open(cpp_tmplt).read()
989
990 # do the substitutions
991 h_text = h_text % data
992 cpp_text = cpp_text % data
993
994 # write out destination files
995 open(h_dest, 'w').write(h_text)
996 open(cpp_dest, 'w').write(cpp_text)
f2ccce28 997 open(docstr_dest, 'w').write(docstrings)
f97d84a6
RD
998
999
1000
713a0408 1001def joinWithNewLines(values):
016a3d4c 1002 return '\n'.join(values)
713a0408 1003
f97d84a6
RD
1004#----------------------------------------------------------------------------
1005
1006def processVals(values):
1007 text = []
1008 for name, value, docs in values:
1009 if docs:
1010 text.append('')
1011 for x in docs:
1012 text.append('// ' + x)
1013 text.append('#define %s %s' % (name, value))
713a0408 1014 return joinWithNewLines(text)
f97d84a6
RD
1015
1016#----------------------------------------------------------------------------
1017
1018def processMethods(methods):
1019 defs = []
1020 imps = []
f2ccce28 1021 dstr = []
f97d84a6 1022
8e0945da 1023 for retType, name, number, param1, param2, docs, is_const in methods:
f97d84a6
RD
1024 retType = retTypeMap.get(retType, retType)
1025 params = makeParamString(param1, param2)
1026
1027 name, theDef, theImp, docs = checkMethodOverride(name, number, docs)
1028
1029 if name is None:
1030 continue
1031
f2ccce28
RD
1032 # Build docstrings
1033 st = 'DocStr(wxStyledTextCtrl::%s,\n' \
713a0408 1034 '"%s", "");\n' % (name, joinWithNewLines(docs))
f2ccce28 1035 dstr.append(st)
8e0945da 1036
f97d84a6
RD
1037 # Build the method definition for the .h file
1038 if docs:
1039 defs.append('')
1040 for x in docs:
1041 defs.append(' // ' + x)
1042 if not theDef:
8e0945da
VZ
1043 theDef = ' %s %s(%s)' % (retType, name, params)
1044 if is_const:
1045 theDef = theDef + ' const'
1046 theDef = theDef + ';'
f97d84a6
RD
1047 defs.append(theDef)
1048
1049 # Build the method implementation string
1050 if docs:
1051 imps.append('')
1052 for x in docs:
1053 imps.append('// ' + x)
1054 if not theImp:
8e0945da
VZ
1055 theImp = '%s wxStyledTextCtrl::%s(%s)' % (retType, name, params)
1056 if is_const:
1057 theImp = theImp + ' const'
1058 theImp = theImp + '\n{\n '
f97d84a6
RD
1059 if retType == 'wxColour':
1060 theImp = theImp + 'long c = '
1061 elif retType != 'void':
1062 theImp = theImp + 'return '
1063 theImp = theImp + 'SendMsg(%s, %s, %s)' % (number,
1064 makeArgString(param1),
1065 makeArgString(param2))
1066 if retType == 'bool':
1067 theImp = theImp + ' != 0'
1068 if retType == 'wxColour':
1069 theImp = theImp + ';\n return wxColourFromLong(c)'
1070
1071 theImp = theImp + ';\n}'
1072 imps.append(theImp)
1073
1074
713a0408 1075 return joinWithNewLines(defs), joinWithNewLines(imps), joinWithNewLines(dstr)
f97d84a6
RD
1076
1077
1078#----------------------------------------------------------------------------
1079
1080def checkMethodOverride(name, number, docs):
1081 theDef = theImp = None
016a3d4c 1082 if name in methodOverrideMap:
f97d84a6
RD
1083 item = methodOverrideMap[name]
1084
c13219d6
RD
1085 try:
1086 if item[0] != 0:
1087 name = item[0]
1088 if item[1] != 0:
1089 theDef = ' ' + (item[1] % name)
1090 if item[2] != 0:
1091 theImp = item[2] % ('wxStyledTextCtrl::'+name, number) + '\n}'
1092 if item[3] != 0:
1093 docs = item[3]
1094 except:
016a3d4c 1095 print("************* " + name)
c13219d6 1096 raise
f97d84a6
RD
1097
1098 return name, theDef, theImp, docs
1099
1100#----------------------------------------------------------------------------
1101
1102def makeArgString(param):
1103 if not param:
1104 return '0'
1105
1106 typ, name = param
1107
1108 if typ == 'string':
b796ba39 1109 return '(sptr_t)(const char*)wx2stc(%s)' % name
f97d84a6
RD
1110 if typ == 'colour':
1111 return 'wxColourAsLong(%s)' % name
1112
1113 return name
1114
1115#----------------------------------------------------------------------------
1116
1117def makeParamString(param1, param2):
1118 def doOne(param):
1119 if param:
1120 aType = paramTypeMap.get(param[0], param[0])
1121 return aType + ' ' + param[1]
1122 else:
1123 return ''
1124
1125 st = doOne(param1)
1126 if st and param2:
1127 st = st + ', '
1128 st = st + doOne(param2)
1129 return st
1130
1131
1132#----------------------------------------------------------------------------
1133
1134def parseVal(line, values, docs):
016a3d4c 1135 name, val = line.split('=')
f97d84a6
RD
1136
1137 # remove prefixes such as SCI, etc.
1138 for old, new in valPrefixes:
1139 lo = len(old)
1140 if name[:lo] == old:
1141 if new is None:
1142 return
1143 name = new + name[lo:]
1144
1145 # add it to the list
1146 values.append( ('wxSTC_' + name, val, docs) )
1147
1148#----------------------------------------------------------------------------
1149
1150funregex = re.compile(r'\s*([a-zA-Z0-9_]+)' # <ws>return type
1151 '\s+([a-zA-Z0-9_]+)=' # <ws>name=
1152 '([0-9]+)' # number
1153 '\(([ a-zA-Z0-9_]*),' # (param,
9e96e16f 1154 '([ a-zA-Z0-9_]*),*\)') # param)
f97d84a6 1155
8e0945da 1156def parseFun(line, methods, docs, values, is_const):
f97d84a6 1157 def parseParam(param):
016a3d4c 1158 param = param.strip()
f97d84a6
RD
1159 if param == '':
1160 param = None
1161 else:
016a3d4c 1162 param = tuple(param.split())
f97d84a6
RD
1163 return param
1164
1165 mo = funregex.match(line)
1166 if mo is None:
016a3d4c 1167 print("***** Line doesn't match! : %s" % line)
f97d84a6
RD
1168
1169 retType, name, number, param1, param2 = mo.groups()
1170
1171 param1 = parseParam(param1)
1172 param2 = parseParam(param2)
1173
2b5f62a0 1174 # Special case. For the key command functions we want a value defined too
016a3d4c 1175 num = int(number)
f97d84a6 1176 for v in cmdValues:
2b5f62a0 1177 if (type(v) == type(()) and v[0] <= num <= v[1]) or v == num:
016a3d4c 1178 parseVal('CMD_%s=%s' % (name.upper(), number), values, docs)
591e2d8e 1179
c26dba42
RD
1180 # if we are not also doing a function for CMD values, then
1181 # just return, otherwise fall through to the append blow.
1182 if not FUNC_FOR_CMD:
1183 return
591e2d8e 1184
2bfca191
VZ
1185 methods.append( (retType, name, number, param1, param2, tuple(docs),
1186 is_const or name in constNonGetterMethods) )
f97d84a6
RD
1187
1188
1189#----------------------------------------------------------------------------
1190
1191
1192def main(args):
1193 # TODO: parse command line args to replace default input/output files???
1194
591e2d8e 1195 if not os.path.exists(IFACE):
016a3d4c 1196 print('Please run this script from src/stc subdirectory.')
591e2d8e
VZ
1197 sys.exit(1)
1198
f97d84a6 1199 # Now just do it
f2ccce28 1200 processIface(IFACE, H_TEMPLATE, CPP_TEMPLATE, H_DEST, CPP_DEST, DOCSTR_DEST)
f97d84a6
RD
1201
1202
1203
1204if __name__ == '__main__':
1205 main(sys.argv)
1206
1207#----------------------------------------------------------------------------
1208