X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=tools%2Flttng-gen-tp;h=2f468cbb79abde4fbf580208cc4728df91af548a;hb=cb7378b3cf177d007917a82a5fe2514e2015bb26;hp=828bee6e77e72780dddbc25a5689812127353b35;hpb=e3feda7db3de3530e7c9c511536c36cccf317013;p=lttng-ust.git diff --git a/tools/lttng-gen-tp b/tools/lttng-gen-tp index 828bee6e..2f468cbb 100755 --- a/tools/lttng-gen-tp +++ b/tools/lttng-gen-tp @@ -31,12 +31,12 @@ class HeaderFile: #undef TRACEPOINT_PROVIDER #define TRACEPOINT_PROVIDER {providerName} -#undef TRACEPOINT_INCLUDE_FILE -#define TRACEPOINT_INCLUDE_FILE ./{headerFilename} +#undef TRACEPOINT_INCLUDE +#define TRACEPOINT_INCLUDE "./{headerFilename}" #ifdef __cplusplus -#extern "C"{{ -#endif /*__cplusplus */ +extern "C"{{ +#endif /* __cplusplus */ #if !defined({includeGuard}) || defined(TRACEPOINT_HEADER_MULTI_READ) @@ -52,7 +52,7 @@ class HeaderFile: #ifdef __cplusplus }} -#endif /*__cplusplus */ +#endif /* __cplusplus */ """ def __init__(self, filename, template): @@ -61,7 +61,7 @@ class HeaderFile: def write(self): outputFile = open(self.outputFilename,"w") - includeGuard = "_"+self.outputFilename.upper().replace(".","_") + includeGuard = self.outputFilename.upper().replace(".","_") outputFile.write(HeaderFile.HEADER_TPL.format(providerName=self.template.domain, includeGuard = includeGuard, @@ -222,6 +222,14 @@ def main(argv=None): outputNames.append(a) if o in ("-a",""): all = True + try: + if len(args) == 0: + raise Usage("No template file given") + + except Usage, err: + print >>sys.stderr, err.msg + print >>sys.stderr, "for help use --help" + return 2 doCFile = None doHeader = None @@ -255,29 +263,41 @@ def main(argv=None): # process arguments for arg in args: + if arg[-3:] != ".tp": + print arg + " does not end in .tp. Skipping." + continue - 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())