ovsdb-idl: Make it possible to write data through the IDL.
[sliver-openvswitch.git] / ovsdb / ovsdb-idlc.in
1 #! @PYTHON@
2
3 import getopt
4 import re
5 import sys
6
7 sys.path.insert(0, "@abs_top_srcdir@/ovsdb")
8 import simplejson as json
9
10 argv0 = sys.argv[0]
11
12 class Error(Exception):
13     def __init__(self, msg):
14         Exception.__init__(self)
15         self.msg = msg
16
17 def getMember(json, name, validTypes, description, default=None):
18     if name in json:
19         member = json[name]
20         if type(member) not in validTypes:
21             raise Error("%s: type mismatch for '%s' member"
22                         % (description, name))
23         return member
24     return default
25
26 def mustGetMember(json, name, expectedType, description):
27     member = getMember(json, name, expectedType, description)
28     if member == None:
29         raise Error("%s: missing '%s' member" % (description, name))
30     return member
31
32 class DbSchema:
33     def __init__(self, name, comment, tables, idlPrefix, idlHeader):
34         self.name = name
35         self.comment = comment
36         self.tables = tables
37         self.idlPrefix = idlPrefix
38         self.idlHeader = idlHeader
39
40     @staticmethod
41     def fromJson(json):
42         name = mustGetMember(json, 'name', [unicode], 'database')
43         comment = getMember(json, 'comment', [unicode], 'database')
44         tablesJson = mustGetMember(json, 'tables', [dict], 'database')
45         tables = {}
46         for name, tableJson in tablesJson.iteritems():
47             tables[name] = TableSchema.fromJson(tableJson, "%s table" % name)
48         idlPrefix = mustGetMember(json, 'idlPrefix', [unicode], 'database')
49         idlHeader = mustGetMember(json, 'idlHeader', [unicode], 'database')
50         return DbSchema(name, comment, tables, idlPrefix, idlHeader)
51
52     def toJson(self):
53         d = {"name": self.name,
54              "tables": {}}
55         for name, table in self.tables.iteritems():
56             d["tables"][name] = table.toJson()
57         if self.comment != None:
58             d["comment"] = self.comment
59         return d
60
61 class TableSchema:
62     def __init__(self, comment, columns):
63         self.comment = comment
64         self.columns = columns
65
66     @staticmethod
67     def fromJson(json, description):
68         comment = getMember(json, 'comment', [unicode], description)
69         columnsJson = mustGetMember(json, 'columns', [dict], description)
70         columns = {}
71         for name, json in columnsJson.iteritems():
72             columns[name] = ColumnSchema.fromJson(
73                 json, "column %s in %s" % (name, description))
74         return TableSchema(comment, columns)
75
76     def toJson(self):
77         d = {"columns": {}}
78         for name, column in self.columns.iteritems():
79             d["columns"][name] = column.toJson()
80         if self.comment != None:
81             d["comment"] = self.comment
82         return d
83
84 class ColumnSchema:
85     def __init__(self, comment, type, persistent):
86         self.comment = comment
87         self.type = type
88         self.persistent = persistent
89
90     @staticmethod
91     def fromJson(json, description):
92         comment = getMember(json, 'comment', [unicode], description)
93         type = Type.fromJson(mustGetMember(json, 'type', [dict, unicode],
94                                            description),
95                              'type of %s' % description)
96         ephemeral = getMember(json, 'ephemeral', [True,False], description)
97         persistent = ephemeral != True
98         return ColumnSchema(comment, type, persistent)
99
100     def toJson(self):
101         d = {"type": self.type.toJson()}
102         if self.persistent == False:
103             d["ephemeral"] = True
104         if self.comment != None:
105             d["comment"] = self.comment
106         return d
107
108 class Type:
109     def __init__(self, key, keyRefTable=None, value=None, valueRefTable=None,
110                  min=1, max=1):
111         self.key = key
112         self.keyRefTable = keyRefTable
113         self.value = value
114         self.valueRefTable = valueRefTable
115         self.min = min
116         self.max = max
117     
118     @staticmethod
119     def fromJson(json, description):
120         if type(json) == unicode:
121             return Type(json)
122         else:
123             key = mustGetMember(json, 'key', [unicode], description)
124             keyRefTable = getMember(json, 'keyRefTable', [unicode], description)
125             value = getMember(json, 'value', [unicode], description)
126             valueRefTable = getMember(json, 'valueRefTable', [unicode], description)
127             min = getMember(json, 'min', [int], description, 1)
128             max = getMember(json, 'max', [int, unicode], description, 1)
129             return Type(key, keyRefTable, value, valueRefTable, min, max)
130
131     def toJson(self):
132         if self.value == None and self.min == 1 and self.max == 1:
133             return self.key
134         else:
135             d = {"key": self.key}
136             if self.value != None:
137                 d["value"] = self.value
138             if self.min != 1:
139                 d["min"] = self.min
140             if self.max != 1:
141                 d["max"] = self.max
142             return d
143
144 def parseSchema(filename):
145     file = open(filename, "r")
146     s = ""
147     for line in file:
148         if not line.startswith('//'):
149             s += line
150     return DbSchema.fromJson(json.loads(s))
151
152 def cBaseType(prefix, type, refTable=None):
153     if type == 'uuid' and refTable:
154         return "struct %s%s *" % (prefix, refTable.lower())
155     else:
156         return {'integer': 'int64_t ',
157                 'real': 'double ',
158                 'uuid': 'struct uuid ',
159                 'boolean': 'bool ',
160                 'string': 'char *'}[type]
161
162 def cCopyType(dst, src, type, refTable=None):
163     if type == 'uuid' and refTable:
164         return "%s = %s->header_.uuid;" % (dst, src)
165     elif type == 'string':
166         return "%s = xstrdup(%s);" % (dst, src)
167     else:
168         return "%s = %s;" % (dst, src)
169
170 def typeIsOptionalPointer(type):
171     return (type.min == 0 and type.max == 1 and not type.value
172             and (type.key == 'string'
173                  or (type.key == 'uuid' and type.keyRefTable)))
174
175 def cDeclComment(type):
176     if type.min == 1 and type.max == 1 and type.key == "string":
177         return "\t/* Always nonnull. */"
178     else:
179         return ""
180
181 def cMembers(prefix, columnName, column):
182     type = column.type
183     if type.min == 1 and type.max == 1:
184         singleton = True
185         pointer = ''
186     else:
187         singleton = False
188         if typeIsOptionalPointer(type):
189             pointer = ''
190         else:
191             pointer = '*'
192
193     if type.value:
194         key = {'name': "key_%s" % columnName,
195                'type': cBaseType(prefix, type.key, type.keyRefTable) + pointer,
196                'comment': ''}
197         value = {'name': "value_%s" % columnName,
198                  'type': (cBaseType(prefix, type.value, type.valueRefTable)
199                           + pointer),
200                  'comment': ''}
201         members = [key, value]
202     else:
203         m = {'name': columnName,
204              'type': cBaseType(prefix, type.key, type.keyRefTable) + pointer,
205              'comment': cDeclComment(type)}
206         members = [m]
207
208     if not singleton and not typeIsOptionalPointer(type):
209         members.append({'name': 'n_%s' % columnName,
210                         'type': 'size_t ',
211                         'comment': ''})
212     return members
213
214 def printCIDLHeader(schema):
215     prefix = schema.idlPrefix
216     print '''\
217 /* Generated automatically -- do not modify!    -*- buffer-read-only: t -*- */
218
219 #ifndef %(prefix)sIDL_HEADER
220 #define %(prefix)sIDL_HEADER 1
221
222 #include <stdbool.h>
223 #include <stddef.h>
224 #include <stdint.h>
225 #include "ovsdb-idl-provider.h"
226 #include "uuid.h"''' % {'prefix': prefix.upper()}
227     for tableName, table in schema.tables.iteritems():
228         print
229         print "/* %s table. */" % tableName
230         structName = "%s%s" % (prefix, tableName.lower())
231         print "struct %s {" % structName
232         print "\tstruct ovsdb_idl_row header_;"
233         for columnName, column in table.columns.iteritems():
234             print "\n\t/* %s column. */" % columnName
235             for member in cMembers(prefix, columnName, column):
236                 print "\t%(type)s%(name)s;%(comment)s" % member
237         print '''\
238 };
239
240 const struct %(s)s *%(s)s_first(const struct ovsdb_idl *);
241 const struct %(s)s *%(s)s_next(const struct %(s)s *);
242 #define %(S)s_FOR_EACH(ROW, IDL) for ((ROW) = %(s)s_first(IDL); (ROW); (ROW) = %(s)s_next(ROW))
243
244 void %(s)s_delete(const struct %(s)s *);
245 struct %(s)s *%(s)s_insert(struct ovsdb_idl_txn *);
246 ''' % {'s': structName, 'S': structName.upper()}
247
248         for columnName, column in table.columns.iteritems():
249             print 'void %(s)s_verify_%(c)s(const struct %(s)s *);' % {'s': structName, 'c': columnName}
250
251         print
252         for columnName, column in table.columns.iteritems():
253
254             print 'void %(s)s_set_%(c)s(const struct %(s)s *,' % {'s': structName, 'c': columnName},
255             args = ['%(type)s%(name)s' % member for member
256                     in cMembers(prefix, columnName, column)]
257             print '%s);' % ', '.join(args)
258
259     print "\nextern struct ovsdb_idl_class %sidl_class;" % prefix
260     print "\n#endif /* %(prefix)sIDL_HEADER */" % {'prefix': prefix.upper()}
261
262 def printEnum(members):
263     if len(members) == 0:
264         return
265
266     print "\nenum {";
267     for member in members[:-1]:
268         print "    %s," % member
269     print "    %s" % members[-1]
270     print "};"
271
272 def printCIDLSource(schema):
273     prefix = schema.idlPrefix
274     print '''\
275 /* Generated automatically -- do not modify!    -*- buffer-read-only: t -*- */
276
277 #include <config.h>
278 #include %s
279 #include <limits.h>
280 #include "ovsdb-data.h"''' % schema.idlHeader
281
282     # Table indexes.
283     printEnum(["%sTABLE_%s" % (prefix.upper(), tableName.upper()) for tableName in schema.tables] + ["%sN_TABLES" % prefix.upper()])
284     print "\nstatic struct ovsdb_idl_table_class %stable_classes[%sN_TABLES];" % (prefix, prefix.upper())
285
286     # Cast functions.
287     for tableName, table in schema.tables.iteritems():
288         structName = "%s%s" % (prefix, tableName.lower())
289         print '''
290 static struct %(s)s *
291 %(s)s_cast(struct ovsdb_idl_row *row)
292 {
293     return row ? CONTAINER_OF(row, struct %(s)s, header_) : NULL;
294 }\
295 ''' % {'s': structName}
296
297
298     for tableName, table in schema.tables.iteritems():
299         structName = "%s%s" % (prefix, tableName.lower())
300         print "\f"
301         if table.comment != None:
302             print "/* %s table (%s). */" % (tableName, table.comment)
303         else:
304             print "/* %s table. */" % (tableName)
305
306         # Column indexes.
307         printEnum(["%s_COL_%s" % (structName.upper(), columnName.upper())
308                    for columnName in table.columns]
309                   + ["%s_N_COLUMNS" % structName.upper()])
310
311         print "\nstatic struct ovsdb_idl_column %s_columns[];" % structName
312
313         # Parse function.
314         print '''
315 static void
316 %s_parse(struct ovsdb_idl_row *row_)
317 {
318     struct %s *row = %s_cast(row_);
319     const struct ovsdb_datum *datum;
320     size_t i UNUSED;
321
322     memset(row_ + 1, 0, sizeof *row - sizeof *row_);''' % (structName, structName, structName)
323
324
325         for columnName, column in table.columns.iteritems():
326             type = column.type
327             refKey = type.key == "uuid" and type.keyRefTable
328             refValue = type.value == "uuid" and type.valueRefTable
329             print
330             print "    datum = &row_->old[%s_COL_%s];" % (structName.upper(), columnName.upper())
331             if type.value:
332                 keyVar = "row->key_%s" % columnName
333                 valueVar = "row->value_%s" % columnName
334             else:
335                 keyVar = "row->%s" % columnName
336                 valueVar = None
337
338             if (type.min == 1 and type.max == 1) or typeIsOptionalPointer(type):
339                 print "    if (datum->n >= 1) {"
340                 if not refKey:
341                     print "        %s = datum->keys[0].%s;" % (keyVar, type.key)
342                 else:
343                     print "        %s = %s%s_cast(ovsdb_idl_get_row_arc(row_, &%stable_classes[%sTABLE_%s], &datum->keys[0].uuid));" % (keyVar, prefix, type.keyRefTable.lower(), prefix, prefix.upper(), type.keyRefTable.upper())
344
345                 if valueVar:
346                     if refValue:
347                         print "        %s = datum->values[0].%s;" % (valueVar, type.value)
348                     else:
349                         print "        %s = %s%s_cast(ovsdb_idl_get_row_arc(row_, &%stable_classes[%sTABLE_%s], &datum->values[0].uuid));" % (valueVar, prefix, type.valueRefTable.lower(), prefix, prefix.upper(), type.valueRefTable.upper())
350                 if (not typeIsOptionalPointer(type) and
351                     (type.key == "string" or type.value == "string")):
352                     print "    } else {"
353                     if type.key == "string":
354                         print "        %s = \"\";" % keyVar
355                     if type.value == "string":
356                         print "        %s = \"\";" % valueVar
357                 print "    }"
358
359             else:
360                 if type.max != 'unlimited':
361                     nMax = "MIN(%d, datum->n)" % type.max
362                 else:
363                     nMax = "datum->n"
364                 print "    for (i = 0; i < %s; i++) {" % nMax
365                 refs = []
366                 if refKey:
367                     print "        struct %s%s *keyRow = %s%s_cast(ovsdb_idl_get_row_arc(row_, &%stable_classes[%sTABLE_%s], &datum->keys[i].uuid));" % (prefix, type.keyRefTable.lower(), prefix, type.keyRefTable.lower(), prefix, prefix.upper(), type.keyRefTable.upper())
368                     keySrc = "keyRow"
369                     refs.append('keyRow')
370                 else:
371                     keySrc = "datum->keys[i].%s" % type.key
372                 if refValue:
373                     print "        struct %s%s *valueRow = %s%s_cast(ovsdb_idl_get_row_arc(row_, &%stable_classes[%sTABLE_%s], &datum->values[i].uuid));" % (prefix, type.valueRefTable.lower(), prefix, type.valueRefTable.lower(), prefix, prefix.upper(), type.valueRefTable.upper())
374                     valueSrc = "valueRow"
375                     refs.append('valueRow')
376                 elif valueVar:
377                     valueSrc = "datum->values[i].%s" % type.value
378                 if refs:
379                     print "        if (%s) {" % ' && '.join(refs)
380                     indent = "            "
381                 else:
382                     indent = "        "
383                 print "%sif (!row->n_%s) {" % (indent, columnName)
384                 print "%s    %s = xmalloc(%s * sizeof *%s);" % (indent, keyVar, nMax, keyVar)
385                 if valueVar:
386                     print "%s    %s = xmalloc(%s * sizeof %s);" % (indent, valueVar, nMax, valueVar)
387                 print "%s}" % indent
388                 print "%s%s[row->n_%s] = %s;" % (indent, keyVar, columnName, keySrc)
389                 if valueVar:
390                     print "%s%s[row->n_%s] = %s;" % (indent, valueVar, columnName, valueSrc)
391                 print "%srow->n_%s++;" % (indent, columnName)
392                 if refs:
393                     print "        }"
394                 print "    }"
395         print "}"
396
397         # Unparse function.
398         nArrays = 0
399         for columnName, column in table.columns.iteritems():
400             type = column.type
401             if (type.min != 1 or type.max != 1) and not typeIsOptionalPointer(type):
402                 if not nArrays:
403                     print '''
404 static void
405 %s_unparse(struct ovsdb_idl_row *row_)
406 {
407     struct %s *row = %s_cast(row_);
408 ''' % (structName, structName, structName)
409                 if type.value:
410                     keyVar = "row->key_%s" % columnName
411                     valueVar = "row->value_%s" % columnName
412                 else:
413                     keyVar = "row->%s" % columnName
414                     valueVar = None
415                 print "    free(%s);" % keyVar
416                 if valueVar:
417                     print "    free(%s);" % valueVar
418                 nArrays += 1
419         if not nArrays:
420             print '''
421 static void
422 %s_unparse(struct ovsdb_idl_row *row UNUSED)
423 {''' % (structName)
424         print "}"
425
426         # First, next functions.
427         print '''
428 const struct %(s)s *
429 %(s)s_first(const struct ovsdb_idl *idl)
430 {
431     return %(s)s_cast(ovsdb_idl_first_row(idl, &%(p)stable_classes[%(P)sTABLE_%(T)s]));
432 }
433
434 const struct %(s)s *
435 %(s)s_next(const struct %(s)s *row)
436 {
437     return %(s)s_cast(ovsdb_idl_next_row(&row->header_));
438 }''' % {'s': structName,
439         'p': prefix,
440         'P': prefix.upper(),
441         'T': tableName.upper()}
442
443         print '''
444 void
445 %(s)s_delete(const struct %(s)s *row_)
446 {
447     struct %(s)s *row = (struct %(s)s *) row_;
448     ovsdb_idl_txn_delete(&row->header_);
449 }
450
451 struct %(s)s *
452 %(s)s_insert(struct ovsdb_idl_txn *txn)
453 {
454     return %(s)s_cast(ovsdb_idl_txn_insert(txn, &%(p)stable_classes[%(P)sTABLE_%(T)s]));
455 }
456 ''' % {'s': structName,
457        'p': prefix,
458        'P': prefix.upper(),
459        'T': tableName.upper()}
460
461         # Verify functions.
462         for columnName, column in table.columns.iteritems():
463             print '''
464 void
465 %(s)s_verify_%(c)s(const struct %(s)s *row)
466 {
467     ovsdb_idl_txn_verify(&row->header_, &%(s)s_columns[%(S)s_COL_%(C)s]);
468 }''' % {'s': structName,
469         'S': structName.upper(),
470         'c': columnName,
471         'C': columnName.upper()}
472
473         # Set functions.
474         for columnName, column in table.columns.iteritems():
475             type = column.type
476             print '\nvoid'
477             members = cMembers(prefix, columnName, column)
478             keyVar = members[0]['name']
479             nVar = None
480             valueVar = None
481             if type.value:
482                 valueVar = members[1]['name']
483                 if len(members) > 2:
484                     nVar = members[2]['name']
485             else:
486                 if len(members) > 1:
487                     nVar = members[1]['name']
488             print '%(s)s_set_%(c)s(const struct %(s)s *row_, %(args)s)' % \
489                 {'s': structName, 'c': columnName,
490                  'args': ', '.join(['%(type)s%(name)s' % m for m in members])}
491             print "{"
492             print "    struct %(s)s *row = (struct %(s)s *) row_;" % {'s': structName}
493             print "    struct ovsdb_datum datum;"
494             if type.min == 1 and type.max == 1:
495                 print
496                 print "    datum.n = 1;"
497                 print "    datum.keys = xmalloc(sizeof *datum.keys);"
498                 print "    %s" % cCopyType("datum.keys[0].%s" % type.key, keyVar, type.key, type.keyRefTable)
499                 if type.value:
500                     print "    datum.values = xmalloc(sizeof *datum.values);"
501                     print "    %s" % cCopyType("datum.values[0].%s" % type.value, valueVar, type.value, type.valueRefTable)
502                 else:
503                     print "    datum.values = NULL;"
504             elif typeIsOptionalPointer(type):
505                 print
506                 print "    if (%s) {" % keyVar
507                 print "        datum.n = 1;"
508                 print "        datum.keys = xmalloc(sizeof *datum.keys);"
509                 print "        %s" % cCopyType("datum.keys[0].%s" % type.key, keyVar, type.key, type.keyRefTable)
510                 print "    } else {"
511                 print "        datum.n = 0;"
512                 print "        datum.keys = NULL;"
513                 print "    }"
514                 print "    datum.values = NULL;"
515             else:
516                 print "    size_t i;"
517                 print
518                 print "    datum.n = %s;" % nVar
519                 print "    datum.keys = xmalloc(%s * sizeof *datum.keys);" % nVar
520                 if type.value:
521                     print "    datum.values = xmalloc(%s * sizeof *datum.values);" % nVar
522                 else:
523                     print "    datum.values = NULL;"
524                 print "    for (i = 0; i < %s; i++) {" % nVar
525                 print "        %s" % cCopyType("datum.keys[i].%s" % type.key, "%s[i]" % keyVar, type.key, type.keyRefTable)
526                 if type.value:
527                     print "        %s" % cCopyType("datum.values[i].%s" % type.value, "%s[i]" % valueVar, type.value, type.valueRefTable)
528                 print "    }"
529             print "    ovsdb_idl_txn_write(&row->header_, &%(s)s_columns[%(S)s_COL_%(C)s], &datum);" \
530                 % {'s': structName,
531                    'S': structName.upper(),
532                    'C': columnName.upper()}
533             print "}"
534
535         # Table columns.
536         print "\nstatic struct ovsdb_idl_column %s_columns[%s_N_COLUMNS] = {" % (
537             structName, structName.upper())
538         for columnName, column in table.columns.iteritems():
539             type = column.type
540             
541             if type.value:
542                 valueTypeName = type.value.upper()
543             else:
544                 valueTypeName = "VOID"
545             if type.max == "unlimited":
546                 max = "UINT_MAX"
547             else:
548                 max = type.max
549             print "    {\"%s\", {OVSDB_TYPE_%s, OVSDB_TYPE_%s, %d, %s}}," % (
550                 columnName, type.key.upper(), valueTypeName,
551                 type.min, max)
552         print "};"
553
554     # Table classes.
555     print "\f"
556     print "static struct ovsdb_idl_table_class %stable_classes[%sN_TABLES] = {" % (prefix, prefix.upper())
557     for tableName, table in schema.tables.iteritems():
558         structName = "%s%s" % (prefix, tableName.lower())
559         print "    {\"%s\"," % tableName
560         print "     %s_columns, ARRAY_SIZE(%s_columns)," % (
561             structName, structName)
562         print "     sizeof(struct %s)," % structName
563         print "     %s_parse," % structName
564         print "     %s_unparse}," % structName
565     print "};"
566
567     # IDL class.
568     print "\nstruct ovsdb_idl_class %sidl_class = {" % prefix
569     print "    %stable_classes, ARRAY_SIZE(%stable_classes)" % (prefix, prefix)
570     print "};"
571
572 def ovsdb_escape(string):
573     def escape(match):
574         c = match.group(0)
575         if c == '\0':
576             raise Error("strings may not contain null bytes")
577         elif c == '\\':
578             return '\\\\'
579         elif c == '\n':
580             return '\\n'
581         elif c == '\r':
582             return '\\r'
583         elif c == '\t':
584             return '\\t'
585         elif c == '\b':
586             return '\\b'
587         elif c == '\a':
588             return '\\a'
589         else:
590             return '\\x%02x' % ord(c)
591     return re.sub(r'["\\\000-\037]', escape, string)
592
593 def printOVSDBSchema(schema):
594     json.dump(schema.toJson(), sys.stdout, sort_keys=True, indent=2)
595
596 def usage():
597     print """\
598 %(argv0)s: ovsdb schema compiler
599 usage: %(argv0)s [OPTIONS] ACTION SCHEMA
600 where SCHEMA is the ovsdb schema to read (in JSON format).
601
602 One of the following actions must specified:
603   validate                    validate schema without taking any other action
604   c-idl-header                print C header file for IDL
605   c-idl-source                print C source file for IDL implementation
606   ovsdb-schema                print ovsdb parseable schema
607
608 The following options are also available:
609   -h, --help                  display this help message
610   -V, --version               display version information\
611 """ % {'argv0': argv0}
612     sys.exit(0)
613
614 if __name__ == "__main__":
615     try:
616         try:
617             options, args = getopt.gnu_getopt(sys.argv[1:], 'hV',
618                                               ['help',
619                                                'version'])
620         except getopt.GetoptError, geo:
621             sys.stderr.write("%s: %s\n" % (argv0, geo.msg))
622             sys.exit(1)
623             
624         optKeys = [key for key, value in options]
625         if '-h' in optKeys or '--help' in optKeys:
626             usage()
627         elif '-V' in optKeys or '--version' in optKeys:
628             print "ovsdb-idlc (Open vSwitch) @VERSION@"
629             sys.exit(0)
630
631         if len(args) != 2:
632             sys.stderr.write("%s: exactly two non-option arguments are "
633                              "required (use --help for help)\n" % argv0)
634             sys.exit(1)
635
636         action, inputFile = args
637         schema = parseSchema(inputFile)
638         if action == 'validate':
639             pass
640         elif action == 'ovsdb-schema':
641             printOVSDBSchema(schema)
642         elif action == 'c-idl-header':
643             printCIDLHeader(schema)
644         elif action == 'c-idl-source':
645             printCIDLSource(schema)
646         else:
647             sys.stderr.write(
648                 "%s: unknown action '%s' (use --help for help)\n" %
649                 (argv0, action))
650             sys.exit(1)
651     except Error, e:
652         sys.stderr.write("%s: %s\n" % (argv0, e.msg))
653         sys.exit(1)
654
655 # Local variables:
656 # mode: python
657 # End: