summaryrefslogtreecommitdiffstats
path: root/gtk/src/quotestring.py
diff options
context:
space:
mode:
authorjstebbins <[email protected]>2009-03-27 18:55:28 +0000
committerjstebbins <[email protected]>2009-03-27 18:55:28 +0000
commit2987e4805cfc9c0229d20d639eeb45fc75ff3ef0 (patch)
treec8330acfc78d6c1e3cacfb09953dae29afcedf30 /gtk/src/quotestring.py
parentd3b4fff719db9df364a7a08f8e2d627db497bfe2 (diff)
LinGui:
- rewrite tool that creates a quoted string from a file in python resulting string is suitable for use as a C char* - create_resources, remove redundant code from cut/past error git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@2280 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'gtk/src/quotestring.py')
-rw-r--r--gtk/src/quotestring.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/gtk/src/quotestring.py b/gtk/src/quotestring.py
new file mode 100644
index 000000000..ee6acb36c
--- /dev/null
+++ b/gtk/src/quotestring.py
@@ -0,0 +1,63 @@
+#! /usr/bin/python
+
+import re
+import getopt
+import sys
+
+def usage():
+ print >> sys.stderr, (
+ "Usage: %s <input> [output]\n"
+ "Summary:\n"
+ " Creates a quoted string suitable for inclusion in a C char*\n\n"
+ "Options:\n"
+ " <input> Input file to quote\n"
+ " <output> Output quoted string [stdout]\n"
+ % sys.argv[0]
+ )
+
+def main():
+ global inc_list
+
+ OPTS = ""
+ try:
+ opts, args = getopt.gnu_getopt(sys.argv[1:], OPTS)
+ except getopt.GetoptError, err:
+ print >> sys.stderr, str(err)
+ usage()
+ sys.exit(2)
+
+ for o, a in opts:
+ usage()
+ assert False, "unhandled option"
+
+ if len(args) > 2 or len(args) < 1:
+ usage()
+ sys.exit(2)
+
+ try:
+ infile = open(args[0])
+ except Exception, err:
+ print >> sys.stderr, ( "Error: %s" % str(err) )
+ sys.exit(1)
+
+ if len(args) > 1:
+ try:
+ outfile = open(args[1], "w")
+ except Exception, err:
+ print >> sys.stderr, ( "Error: %s" % str(err))
+ sys.exit(1)
+ else:
+ outfile = sys.stdout
+
+ ss = infile.read()
+ ss = re.sub("\"", "\\\"", ss)
+ pattern = re.compile("$", re.M)
+ # the replacement string below seems a bit strange, but it seems to be
+ # the only way to get the litteral chars '\' 'n' inserted into the string
+ ss = re.sub(pattern, "\\\\n\"", ss)
+ pattern = re.compile("^", re.M)
+ ss = re.sub(pattern, "\"", ss)
+ outfile.write(ss)
+
+main()
+