X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=tools%2Flttng-gen-tp;h=03a85fcb4e6a7cb63e8172cce6f6bc8f03db1d27;hb=76ceb8db45d20fa6d2d1492e8f6877440edf71d6;hp=3f28534858b318ae326ffeac67beb5f2febc104b;hpb=db06a0a230324416a62f76bab75874065cd83e4e;p=lttng-ust.git diff --git a/tools/lttng-gen-tp b/tools/lttng-gen-tp old mode 100644 new mode 100755 index 3f285348..03a85fcb --- a/tools/lttng-gen-tp +++ b/tools/lttng-gen-tp @@ -158,9 +158,11 @@ class TemplateFile: self.text = f.read() #Remove # comments (from input and output file - self.text = re.sub("#.*$","",self.text,flags=re.MULTILINE) + removeComments = re.compile("#.*$",flags=re.MULTILINE) + self.text = removeComments.sub("",self.text) #Remove // comments - nolinecomment = re.sub("\/\/.*$","",self.text,flags=re.MULTILINE) + removeLineComment = re.compile("\/\/.*$",flags=re.MULTILINE) + nolinecomment = removeLineComment.sub("",self.text) #Remove all spaces and lines cleantext = re.sub("\s*","",nolinecomment) #Remove multine C style comments @@ -205,6 +207,8 @@ def main(argv=None): opts, args = getopt.gnu_getopt(argv[1:], "ho:a", ["help"]) except getopt.error, msg: raise Usage(msg) + if len(args) == 0: + raise Usage("No template file given") except Usage, err: print >>sys.stderr, err.msg @@ -254,28 +258,37 @@ def main(argv=None): # process arguments for arg in args: - tpl = TemplateFile(arg) - if doHeader: - if headerFilename: - curFilename = headerFilename - else: - curFilename = re.sub("\.tp$",".h",arg) - doth = HeaderFile(curFilename, tpl) - doth.write() - if doCFile: - if cFilename: - curFilename = cFilename - else: - curFilename = re.sub("\.tp$",".c",arg) - dotc = CFile(curFilename, tpl) - dotc.write() - if doObj: - if objFilename: - curFilename = objFilename - else: - curFilename = re.sub("\.tp$",".o",arg) - dotobj = ObjFile(curFilename, tpl) - dotobj.write() - + tpl = None + try: + tpl = TemplateFile(arg) + except IOError as args: + print "Cannot read input file " + args.filename + " " + args.strerror + return -1 + try: + if doHeader: + if headerFilename: + curFilename = headerFilename + else: + curFilename = re.sub("\.tp$",".h",arg) + doth = HeaderFile(curFilename, tpl) + doth.write() + if doCFile: + if cFilename: + curFilename = cFilename + else: + curFilename = re.sub("\.tp$",".c",arg) + dotc = CFile(curFilename, tpl) + dotc.write() + if doObj: + if objFilename: + curFilename = objFilename + else: + curFilename = re.sub("\.tp$",".o",arg) + dotobj = ObjFile(curFilename, tpl) + dotobj.write() + except IOError as args: + print "Cannot write output file " + args.filename + " " + args.strerror + return -1 + if __name__ == "__main__": sys.exit(main())