9 "Usage: %s <input> [output]\n"
11 " Creates a quoted string suitable for inclusion in a C char*\n\n"
13 " <input> Input file to quote\n"
14 " <output> Output quoted string [stdout]\n"
23 opts, args = getopt.gnu_getopt(sys.argv[1:], OPTS)
24 except getopt.GetoptError, err:
25 print >> sys.stderr, str(err)
31 assert False, "unhandled option"
33 if len(args) > 2 or len(args) < 1:
38 infile = open(args[0])
39 except Exception, err:
40 print >> sys.stderr, ( "Error: %s" % str(err) )
45 outfile = open(args[1], "w")
46 except Exception, err:
47 print >> sys.stderr, ( "Error: %s" % str(err))
53 ss = re.sub("\"", "\\\"", ss)
54 pattern = re.compile("$", re.M)
55 # the replacement string below seems a bit strange, but it seems to be
56 # the only way to get the litteral chars '\' 'n' inserted into the string
57 ss = re.sub(pattern, "\\\\n\"", ss)
58 pattern = re.compile("^", re.M)
59 ss = re.sub(pattern, "\"", ss)