| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright (c) 2005 Niels Provos <provos@citi.umich.edu> | 3 # Copyright (c) 2005 Niels Provos <provos@citi.umich.edu> |
| 4 # All rights reserved. | 4 # All rights reserved. |
| 5 # | 5 # |
| 6 # Generates marshaling code based on libevent. | 6 # Generates marshaling code based on libevent. |
| 7 | 7 |
| 8 import sys | 8 import sys |
| 9 import re | 9 import re |
| 10 | 10 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 self.PrintIdented(file, ' ', dcl) | 80 self.PrintIdented(file, ' ', dcl) |
| 81 print >>file, '};\n' | 81 print >>file, '};\n' |
| 82 | 82 |
| 83 print >>file, 'struct %s {' % self._name | 83 print >>file, 'struct %s {' % self._name |
| 84 print >>file, ' struct %s_access_ *base;\n' % self._name | 84 print >>file, ' struct %s_access_ *base;\n' % self._name |
| 85 for entry in self._entries: | 85 for entry in self._entries: |
| 86 dcl = entry.Declaration() | 86 dcl = entry.Declaration() |
| 87 self.PrintIdented(file, ' ', dcl) | 87 self.PrintIdented(file, ' ', dcl) |
| 88 print >>file, '' | 88 print >>file, '' |
| 89 for entry in self._entries: | 89 for entry in self._entries: |
| 90 print >>file, ' uint8_t %s_set;' % entry.Name() | 90 print >>file, ' ev_uint8_t %s_set;' % entry.Name() |
| 91 print >>file, '};\n' | 91 print >>file, '};\n' |
| 92 | 92 |
| 93 print >>file, \ | 93 print >>file, \ |
| 94 """struct %(name)s *%(name)s_new(void); | 94 """struct %(name)s *%(name)s_new(void); |
| 95 void %(name)s_free(struct %(name)s *); | 95 void %(name)s_free(struct %(name)s *); |
| 96 void %(name)s_clear(struct %(name)s *); | 96 void %(name)s_clear(struct %(name)s *); |
| 97 void %(name)s_marshal(struct evbuffer *, const struct %(name)s *); | 97 void %(name)s_marshal(struct evbuffer *, const struct %(name)s *); |
| 98 int %(name)s_unmarshal(struct %(name)s *, struct evbuffer *); | 98 int %(name)s_unmarshal(struct %(name)s *, struct evbuffer *); |
| 99 int %(name)s_complete(struct %(name)s *); | 99 int %(name)s_complete(struct %(name)s *); |
| 100 void evtag_marshal_%(name)s(struct evbuffer *, uint32_t, | 100 void evtag_marshal_%(name)s(struct evbuffer *, ev_uint32_t, |
| 101 const struct %(name)s *); | 101 const struct %(name)s *); |
| 102 int evtag_unmarshal_%(name)s(struct evbuffer *, uint32_t, | 102 int evtag_unmarshal_%(name)s(struct evbuffer *, ev_uint32_t, |
| 103 struct %(name)s *);""" % { 'name' : self._name } | 103 struct %(name)s *);""" % { 'name' : self._name } |
| 104 | 104 |
| 105 | 105 |
| 106 # Write a setting function of every variable | 106 # Write a setting function of every variable |
| 107 for entry in self._entries: | 107 for entry in self._entries: |
| 108 self.PrintIdented(file, '', entry.AssignDeclaration( | 108 self.PrintIdented(file, '', entry.AssignDeclaration( |
| 109 entry.AssignFuncName())) | 109 entry.AssignFuncName())) |
| 110 self.PrintIdented(file, '', entry.GetDeclaration( | 110 self.PrintIdented(file, '', entry.GetDeclaration( |
| 111 entry.GetFuncName())) | 111 entry.GetFuncName())) |
| 112 if entry.Array(): | 112 if entry.Array(): |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 if entry.Optional(): | 202 if entry.Optional(): |
| 203 print >>file, ' }' | 203 print >>file, ' }' |
| 204 | 204 |
| 205 print >>file, '}\n' | 205 print >>file, '}\n' |
| 206 | 206 |
| 207 # Unmarshaling | 207 # Unmarshaling |
| 208 print >>file, ('int\n' | 208 print >>file, ('int\n' |
| 209 '%(name)s_unmarshal(struct %(name)s *tmp, ' | 209 '%(name)s_unmarshal(struct %(name)s *tmp, ' |
| 210 ' struct evbuffer *evbuf)\n' | 210 ' struct evbuffer *evbuf)\n' |
| 211 '{\n' | 211 '{\n' |
| 212 ' uint32_t tag;\n' | 212 ' ev_uint32_t tag;\n' |
| 213 ' while (EVBUFFER_LENGTH(evbuf) > 0) {\n' | 213 ' while (EVBUFFER_LENGTH(evbuf) > 0) {\n' |
| 214 ' if (evtag_peek(evbuf, &tag) == -1)\n' | 214 ' if (evtag_peek(evbuf, &tag) == -1)\n' |
| 215 ' return (-1);\n' | 215 ' return (-1);\n' |
| 216 ' switch (tag) {\n' | 216 ' switch (tag) {\n' |
| 217 ) % { 'name' : self._name } | 217 ) % { 'name' : self._name } |
| 218 for entry in self._entries: | 218 for entry in self._entries: |
| 219 print >>file, ' case %s:\n' % self.EntryTagName(entry) | 219 print >>file, ' case %s:\n' % self.EntryTagName(entry) |
| 220 if not entry.Array(): | 220 if not entry.Array(): |
| 221 print >>file, ( | 221 print >>file, ( |
| 222 ' if (tmp->%s_set)\n' | 222 ' if (tmp->%s_set)\n' |
| (...skipping 30 matching lines...) Expand all Loading... |
| 253 file, ' ', | 253 file, ' ', |
| 254 entry.CodeComplete('msg')) | 254 entry.CodeComplete('msg')) |
| 255 print >>file, ( | 255 print >>file, ( |
| 256 ' return (0);\n' | 256 ' return (0);\n' |
| 257 '}\n' ) | 257 '}\n' ) |
| 258 | 258 |
| 259 # Complete message unmarshaling | 259 # Complete message unmarshaling |
| 260 print >>file, ( | 260 print >>file, ( |
| 261 'int\n' | 261 'int\n' |
| 262 'evtag_unmarshal_%(name)s(struct evbuffer *evbuf, ' | 262 'evtag_unmarshal_%(name)s(struct evbuffer *evbuf, ' |
| 263 'uint32_t need_tag, struct %(name)s *msg)\n' | 263 'ev_uint32_t need_tag, struct %(name)s *msg)\n' |
| 264 '{\n' | 264 '{\n' |
| 265 ' uint32_t tag;\n' | 265 ' ev_uint32_t tag;\n' |
| 266 ' int res = -1;\n' | 266 ' int res = -1;\n' |
| 267 '\n' | 267 '\n' |
| 268 ' struct evbuffer *tmp = evbuffer_new();\n' | 268 ' struct evbuffer *tmp = evbuffer_new();\n' |
| 269 '\n' | 269 '\n' |
| 270 ' if (evtag_unmarshal(evbuf, &tag, tmp) == -1' | 270 ' if (evtag_unmarshal(evbuf, &tag, tmp) == -1' |
| 271 ' || tag != need_tag)\n' | 271 ' || tag != need_tag)\n' |
| 272 ' goto error;\n' | 272 ' goto error;\n' |
| 273 '\n' | 273 '\n' |
| 274 ' if (%(name)s_unmarshal(msg, tmp) == -1)\n' | 274 ' if (%(name)s_unmarshal(msg, tmp) == -1)\n' |
| 275 ' goto error;\n' | 275 ' goto error;\n' |
| 276 '\n' | 276 '\n' |
| 277 ' res = 0;\n' | 277 ' res = 0;\n' |
| 278 '\n' | 278 '\n' |
| 279 ' error:\n' | 279 ' error:\n' |
| 280 ' evbuffer_free(tmp);\n' | 280 ' evbuffer_free(tmp);\n' |
| 281 ' return (res);\n' | 281 ' return (res);\n' |
| 282 '}\n' ) % { 'name' : self._name } | 282 '}\n' ) % { 'name' : self._name } |
| 283 | 283 |
| 284 # Complete message marshaling | 284 # Complete message marshaling |
| 285 print >>file, ( | 285 print >>file, ( |
| 286 'void\n' | 286 'void\n' |
| 287 'evtag_marshal_%(name)s(struct evbuffer *evbuf, uint32_t tag, ' | 287 'evtag_marshal_%(name)s(struct evbuffer *evbuf, ev_uint32_t tag, ' |
| 288 'const struct %(name)s *msg)\n' | 288 'const struct %(name)s *msg)\n' |
| 289 '{\n' | 289 '{\n' |
| 290 ' struct evbuffer *_buf = evbuffer_new();\n' | 290 ' struct evbuffer *_buf = evbuffer_new();\n' |
| 291 ' assert(_buf != NULL);\n' | 291 ' assert(_buf != NULL);\n' |
| 292 ' evbuffer_drain(_buf, -1);\n' | 292 ' evbuffer_drain(_buf, -1);\n' |
| 293 ' %(name)s_marshal(_buf, msg);\n' | 293 ' %(name)s_marshal(_buf, msg);\n' |
| 294 ' evtag_marshal(evbuf, tag, EVBUFFER_DATA(_buf), ' | 294 ' evtag_marshal(evbuf, tag, EVBUFFER_DATA(_buf), ' |
| 295 'EVBUFFER_LENGTH(_buf));\n' | 295 'EVBUFFER_LENGTH(_buf));\n' |
| 296 ' evbuffer_free(_buf);\n' | 296 ' evbuffer_free(_buf);\n' |
| 297 '}\n' ) % { 'name' : self._name } | 297 '}\n' ) % { 'name' : self._name } |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 'optional and array around line %d' ) % ( | 439 'optional and array around line %d' ) % ( |
| 440 self._name, self.LineCount() ) | 440 self._name, self.LineCount() ) |
| 441 sys.exit(1) | 441 sys.exit(1) |
| 442 | 442 |
| 443 class EntryBytes(Entry): | 443 class EntryBytes(Entry): |
| 444 def __init__(self, type, name, tag, length): | 444 def __init__(self, type, name, tag, length): |
| 445 # Init base class | 445 # Init base class |
| 446 Entry.__init__(self, type, name, tag) | 446 Entry.__init__(self, type, name, tag) |
| 447 | 447 |
| 448 self._length = length | 448 self._length = length |
| 449 self._ctype = 'uint8_t' | 449 self._ctype = 'ev_uint8_t' |
| 450 | 450 |
| 451 def GetDeclaration(self, funcname): | 451 def GetDeclaration(self, funcname): |
| 452 code = [ 'int %s(struct %s *, %s **);' % ( | 452 code = [ 'int %s(struct %s *, %s **);' % ( |
| 453 funcname, self._struct.Name(), self._ctype ) ] | 453 funcname, self._struct.Name(), self._ctype ) ] |
| 454 return code | 454 return code |
| 455 | 455 |
| 456 def AssignDeclaration(self, funcname): | 456 def AssignDeclaration(self, funcname): |
| 457 code = [ 'int %s(struct %s *, const %s *);' % ( | 457 code = [ 'int %s(struct %s *, const %s *);' % ( |
| 458 funcname, self._struct.Name(), self._ctype ) ] | 458 funcname, self._struct.Name(), self._ctype ) ] |
| 459 return code | 459 return code |
| 460 | 460 |
| 461 def Declaration(self): | 461 def Declaration(self): |
| 462 dcl = ['uint8_t %s_data[%s];' % (self._name, self._length)] | 462 dcl = ['ev_uint8_t %s_data[%s];' % (self._name, self._length)] |
| 463 | 463 |
| 464 return dcl | 464 return dcl |
| 465 | 465 |
| 466 def CodeGet(self): | 466 def CodeGet(self): |
| 467 name = self._name | 467 name = self._name |
| 468 code = [ 'int', | 468 code = [ 'int', |
| 469 '%s_%s_get(struct %s *msg, %s **value)' % ( | 469 '%s_%s_get(struct %s *msg, %s **value)' % ( |
| 470 self._struct.Name(), name, | 470 self._struct.Name(), name, |
| 471 self._struct.Name(), self._ctype), | 471 self._struct.Name(), self._ctype), |
| 472 '{', | 472 '{', |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 self._name, self.LineCount() ) | 526 self._name, self.LineCount() ) |
| 527 sys.exit(1) | 527 sys.exit(1) |
| 528 | 528 |
| 529 Entry.Verify(self) | 529 Entry.Verify(self) |
| 530 | 530 |
| 531 class EntryInt(Entry): | 531 class EntryInt(Entry): |
| 532 def __init__(self, type, name, tag): | 532 def __init__(self, type, name, tag): |
| 533 # Init base class | 533 # Init base class |
| 534 Entry.__init__(self, type, name, tag) | 534 Entry.__init__(self, type, name, tag) |
| 535 | 535 |
| 536 self._ctype = 'uint32_t' | 536 self._ctype = 'ev_uint32_t' |
| 537 | 537 |
| 538 def CodeUnmarshal(self, buf, tag_name, var_name): | 538 def CodeUnmarshal(self, buf, tag_name, var_name): |
| 539 code = ['if (evtag_unmarshal_int(%s, %s, &%s->%s_data) == -1) {' % ( | 539 code = ['if (evtag_unmarshal_int(%s, %s, &%s->%s_data) == -1) {' % ( |
| 540 buf, tag_name, var_name, self._name), | 540 buf, tag_name, var_name, self._name), |
| 541 ' event_warnx("%%s: failed to unmarshal %s", __func__);' % ( | 541 ' event_warnx("%%s: failed to unmarshal %s", __func__);' % ( |
| 542 self._name ), | 542 self._name ), |
| 543 ' return (-1);', | 543 ' return (-1);', |
| 544 '}' ] | 544 '}' ] |
| 545 return code | 545 return code |
| 546 | 546 |
| 547 def CodeMarshal(self, buf, tag_name, var_name): | 547 def CodeMarshal(self, buf, tag_name, var_name): |
| 548 code = ['evtag_marshal_int(%s, %s, %s->%s_data);' % ( | 548 code = ['evtag_marshal_int(%s, %s, %s->%s_data);' % ( |
| 549 buf, tag_name, var_name, self._name)] | 549 buf, tag_name, var_name, self._name)] |
| 550 return code | 550 return code |
| 551 | 551 |
| 552 def Declaration(self): | 552 def Declaration(self): |
| 553 dcl = ['uint32_t %s_data;' % self._name] | 553 dcl = ['ev_uint32_t %s_data;' % self._name] |
| 554 | 554 |
| 555 return dcl | 555 return dcl |
| 556 | 556 |
| 557 def CodeNew(self, name): | 557 def CodeNew(self, name): |
| 558 code = ['%s->%s_data = 0;' % (name, self._name)] | 558 code = ['%s->%s_data = 0;' % (name, self._name)] |
| 559 return code | 559 return code |
| 560 | 560 |
| 561 class EntryString(Entry): | 561 class EntryString(Entry): |
| 562 def __init__(self, type, name, tag): | 562 def __init__(self, type, name, tag): |
| 563 # Init base class | 563 # Init base class |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 def Declaration(self): | 745 def Declaration(self): |
| 746 dcl = ['%s %s_data;' % (self._ctype, self._name)] | 746 dcl = ['%s %s_data;' % (self._ctype, self._name)] |
| 747 | 747 |
| 748 return dcl | 748 return dcl |
| 749 | 749 |
| 750 class EntryVarBytes(Entry): | 750 class EntryVarBytes(Entry): |
| 751 def __init__(self, type, name, tag): | 751 def __init__(self, type, name, tag): |
| 752 # Init base class | 752 # Init base class |
| 753 Entry.__init__(self, type, name, tag) | 753 Entry.__init__(self, type, name, tag) |
| 754 | 754 |
| 755 self._ctype = 'uint8_t *' | 755 self._ctype = 'ev_uint8_t *' |
| 756 | 756 |
| 757 def GetDeclaration(self, funcname): | 757 def GetDeclaration(self, funcname): |
| 758 code = [ 'int %s(struct %s *, %s *, uint32_t *);' % ( | 758 code = [ 'int %s(struct %s *, %s *, ev_uint32_t *);' % ( |
| 759 funcname, self._struct.Name(), self._ctype ) ] | 759 funcname, self._struct.Name(), self._ctype ) ] |
| 760 return code | 760 return code |
| 761 | 761 |
| 762 def AssignDeclaration(self, funcname): | 762 def AssignDeclaration(self, funcname): |
| 763 code = [ 'int %s(struct %s *, const %s, uint32_t);' % ( | 763 code = [ 'int %s(struct %s *, const %s, ev_uint32_t);' % ( |
| 764 funcname, self._struct.Name(), self._ctype ) ] | 764 funcname, self._struct.Name(), self._ctype ) ] |
| 765 return code | 765 return code |
| 766 | 766 |
| 767 def CodeAssign(self): | 767 def CodeAssign(self): |
| 768 name = self._name | 768 name = self._name |
| 769 code = [ 'int', | 769 code = [ 'int', |
| 770 '%s_%s_assign(struct %s *msg, ' | 770 '%s_%s_assign(struct %s *msg, ' |
| 771 'const %s value, uint32_t len)' % ( | 771 'const %s value, ev_uint32_t len)' % ( |
| 772 self._struct.Name(), name, | 772 self._struct.Name(), name, |
| 773 self._struct.Name(), self._ctype), | 773 self._struct.Name(), self._ctype), |
| 774 '{', | 774 '{', |
| 775 ' if (msg->%s_data != NULL)' % name, | 775 ' if (msg->%s_data != NULL)' % name, |
| 776 ' free (msg->%s_data);' % name, | 776 ' free (msg->%s_data);' % name, |
| 777 ' msg->%s_data = malloc(len);' % name, | 777 ' msg->%s_data = malloc(len);' % name, |
| 778 ' if (msg->%s_data == NULL)' % name, | 778 ' if (msg->%s_data == NULL)' % name, |
| 779 ' return (-1);', | 779 ' return (-1);', |
| 780 ' msg->%s_set = 1;' % name, | 780 ' msg->%s_set = 1;' % name, |
| 781 ' msg->%s_length = len;' % name, | 781 ' msg->%s_length = len;' % name, |
| 782 ' memcpy(msg->%s_data, value, len);' % name, | 782 ' memcpy(msg->%s_data, value, len);' % name, |
| 783 ' return (0);', | 783 ' return (0);', |
| 784 '}' ] | 784 '}' ] |
| 785 return code | 785 return code |
| 786 | 786 |
| 787 def CodeGet(self): | 787 def CodeGet(self): |
| 788 name = self._name | 788 name = self._name |
| 789 code = [ 'int', | 789 code = [ 'int', |
| 790 '%s_%s_get(struct %s *msg, %s *value, uint32_t *plen)' % ( | 790 '%s_%s_get(struct %s *msg, %s *value, ev_uint32_t *plen)' % ( |
| 791 self._struct.Name(), name, | 791 self._struct.Name(), name, |
| 792 self._struct.Name(), self._ctype), | 792 self._struct.Name(), self._ctype), |
| 793 '{', | 793 '{', |
| 794 ' if (msg->%s_set != 1)' % name, | 794 ' if (msg->%s_set != 1)' % name, |
| 795 ' return (-1);', | 795 ' return (-1);', |
| 796 ' *value = msg->%s_data;' % name, | 796 ' *value = msg->%s_data;' % name, |
| 797 ' *plen = msg->%s_length;' % name, | 797 ' *plen = msg->%s_length;' % name, |
| 798 ' return (0);', | 798 ' return (0);', |
| 799 '}' ] | 799 '}' ] |
| 800 return code | 800 return code |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 '%s->%s_length = 0;' % (name, self._name) ] | 841 '%s->%s_length = 0;' % (name, self._name) ] |
| 842 return code | 842 return code |
| 843 | 843 |
| 844 def CodeFree(self, name): | 844 def CodeFree(self, name): |
| 845 code = ['if (%s->%s_data != NULL)' % (name, self._name), | 845 code = ['if (%s->%s_data != NULL)' % (name, self._name), |
| 846 ' free (%s->%s_data); ' % (name, self._name)] | 846 ' free (%s->%s_data); ' % (name, self._name)] |
| 847 | 847 |
| 848 return code | 848 return code |
| 849 | 849 |
| 850 def Declaration(self): | 850 def Declaration(self): |
| 851 dcl = ['uint8_t *%s_data;' % self._name, | 851 dcl = ['ev_uint8_t *%s_data;' % self._name, |
| 852 'uint32_t %s_length;' % self._name] | 852 'ev_uint32_t %s_length;' % self._name] |
| 853 | 853 |
| 854 return dcl | 854 return dcl |
| 855 | 855 |
| 856 class EntryArray(Entry): | 856 class EntryArray(Entry): |
| 857 def __init__(self, entry): | 857 def __init__(self, entry): |
| 858 # Init base class | 858 # Init base class |
| 859 Entry.__init__(self, entry._type, entry._name, entry._tag) | 859 Entry.__init__(self, entry._type, entry._name, entry._tag) |
| 860 | 860 |
| 861 self._entry = entry | 861 self._entry = entry |
| 862 self._refname = entry._refname | 862 self._refname = entry._refname |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1311 '#include <stdint.h>\n' | 1311 '#include <stdint.h>\n' |
| 1312 '#endif\n' ) | 1312 '#endif\n' ) |
| 1313 | 1313 |
| 1314 for statement in headerdirect: | 1314 for statement in headerdirect: |
| 1315 pre += '%s\n' % statement | 1315 pre += '%s\n' % statement |
| 1316 if headerdirect: | 1316 if headerdirect: |
| 1317 pre += '\n' | 1317 pre += '\n' |
| 1318 | 1318 |
| 1319 pre += ( | 1319 pre += ( |
| 1320 '#define EVTAG_HAS(msg, member) ((msg)->member##_set == 1)\n' | 1320 '#define EVTAG_HAS(msg, member) ((msg)->member##_set == 1)\n' |
| 1321 '#ifdef __GNUC__\n' |
| 1321 '#define EVTAG_ASSIGN(msg, member, args...) ' | 1322 '#define EVTAG_ASSIGN(msg, member, args...) ' |
| 1322 '(*(msg)->base->member##_assign)(msg, ## args)\n' | 1323 '(*(msg)->base->member##_assign)(msg, ## args)\n' |
| 1323 '#define EVTAG_GET(msg, member, args...) ' | 1324 '#define EVTAG_GET(msg, member, args...) ' |
| 1324 '(*(msg)->base->member##_get)(msg, ## args)\n' | 1325 '(*(msg)->base->member##_get)(msg, ## args)\n' |
| 1326 '#else\n' |
| 1327 '#define EVTAG_ASSIGN(msg, member, ...) ' |
| 1328 '(*(msg)->base->member##_assign)(msg, ## __VA_ARGS__)\n' |
| 1329 '#define EVTAG_GET(msg, member, ...) ' |
| 1330 '(*(msg)->base->member##_get)(msg, ## __VA_ARGS__)\n' |
| 1331 '#endif\n' |
| 1325 '#define EVTAG_ADD(msg, member) (*(msg)->base->member##_add)(msg)\n' | 1332 '#define EVTAG_ADD(msg, member) (*(msg)->base->member##_add)(msg)\n' |
| 1326 '#define EVTAG_LEN(msg, member) ((msg)->member##_length)\n' | 1333 '#define EVTAG_LEN(msg, member) ((msg)->member##_length)\n' |
| 1327 ) | 1334 ) |
| 1328 | 1335 |
| 1329 return pre | 1336 return pre |
| 1330 | 1337 |
| 1331 | 1338 |
| 1332 def HeaderPostamble(name): | 1339 def HeaderPostamble(name): |
| 1333 guard = GuardName(name) | 1340 guard = GuardName(name) |
| 1334 return '#endif /* %s */' % guard | 1341 return '#endif /* %s */' % guard |
| 1335 | 1342 |
| 1336 def BodyPreamble(name): | 1343 def BodyPreamble(name): |
| 1337 global _NAME | 1344 global _NAME |
| 1338 global _VERSION | 1345 global _VERSION |
| 1339 | 1346 |
| 1340 header_file = '.'.join(name.split('.')[:-1]) + '.gen.h' | 1347 header_file = '.'.join(name.split('.')[:-1]) + '.gen.h' |
| 1341 | 1348 |
| 1342 pre = ( '/*\n' | 1349 pre = ( '/*\n' |
| 1343 ' * Automatically generated from %s\n' | 1350 ' * Automatically generated from %s\n' |
| 1344 ' * by %s/%s. DO NOT EDIT THIS FILE.\n' | 1351 ' * by %s/%s. DO NOT EDIT THIS FILE.\n' |
| 1345 ' */\n\n' ) % (name, _NAME, _VERSION) | 1352 ' */\n\n' ) % (name, _NAME, _VERSION) |
| 1346 pre += ( '#include <sys/types.h>\n' | 1353 pre += ( '#include <sys/types.h>\n' |
| 1354 '#ifdef _EVENT_HAVE_SYS_TIME_H\n' |
| 1347 '#include <sys/time.h>\n' | 1355 '#include <sys/time.h>\n' |
| 1356 '#endif\n' |
| 1348 '#include <stdlib.h>\n' | 1357 '#include <stdlib.h>\n' |
| 1349 '#include <string.h>\n' | 1358 '#include <string.h>\n' |
| 1350 '#include <assert.h>\n' | 1359 '#include <assert.h>\n' |
| 1351 '#include <event.h>\n\n' ) | 1360 '#define EVENT_NO_STRUCT\n' |
| 1361 '#include <event.h>\n\n' |
| 1362 '#ifdef _EVENT___func__\n' |
| 1363 '#define __func__ _EVENT___func__\n' |
| 1364 '#endif\n' ) |
| 1352 | 1365 |
| 1353 for statement in cppdirect: | 1366 for statement in cppdirect: |
| 1354 pre += '%s\n' % statement | 1367 pre += '%s\n' % statement |
| 1355 | 1368 |
| 1356 pre += '\n#include "%s"\n\n' % header_file | 1369 pre += '\n#include "%s"\n\n' % header_file |
| 1357 | 1370 |
| 1358 pre += 'void event_err(int eval, const char *fmt, ...);\n' | 1371 pre += 'void event_err(int eval, const char *fmt, ...);\n' |
| 1359 pre += 'void event_warn(const char *fmt, ...);\n' | 1372 pre += 'void event_warn(const char *fmt, ...);\n' |
| 1360 pre += 'void event_errx(int eval, const char *fmt, ...);\n' | 1373 pre += 'void event_errx(int eval, const char *fmt, ...);\n' |
| 1361 pre += 'void event_warnx(const char *fmt, ...);\n\n' | 1374 pre += 'void event_warnx(const char *fmt, ...);\n\n' |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1401 | 1414 |
| 1402 print >>sys.stderr, '... creating "%s"' % impl_file | 1415 print >>sys.stderr, '... creating "%s"' % impl_file |
| 1403 impl_fp = open(impl_file, 'w') | 1416 impl_fp = open(impl_file, 'w') |
| 1404 print >>impl_fp, BodyPreamble(filename) | 1417 print >>impl_fp, BodyPreamble(filename) |
| 1405 for entry in entities: | 1418 for entry in entities: |
| 1406 entry.PrintCode(impl_fp) | 1419 entry.PrintCode(impl_fp) |
| 1407 impl_fp.close() | 1420 impl_fp.close() |
| 1408 | 1421 |
| 1409 if __name__ == '__main__': | 1422 if __name__ == '__main__': |
| 1410 main(sys.argv) | 1423 main(sys.argv) |
| OLD | NEW |