summaryrefslogtreecommitdiffstats
path: root/gtk/src/preset_to_string.c
diff options
context:
space:
mode:
authorjstebbins <[email protected]>2008-06-17 15:40:49 +0000
committerjstebbins <[email protected]>2008-06-17 15:40:49 +0000
commit8bbd36bcbe75a53b29f7cc62e5ae9d107f92eddc (patch)
treeaafba8f8091293cc3faac87f0c61460cc6017c39 /gtk/src/preset_to_string.c
parent01cf7f40ab14ce0961c5ea0c6e16580284c03945 (diff)
LinGui: Initial import
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@1517 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'gtk/src/preset_to_string.c')
-rw-r--r--gtk/src/preset_to_string.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/gtk/src/preset_to_string.c b/gtk/src/preset_to_string.c
new file mode 100644
index 000000000..e678e994b
--- /dev/null
+++ b/gtk/src/preset_to_string.c
@@ -0,0 +1,48 @@
+#include <stdio.h>
+#include <string.h>
+#include <libgen.h>
+
+#define BUF_SIZE 256
+
+void
+usage(char *cmd)
+{
+ printf("%s\n", cmd);
+ char *base = basename(cmd);
+ fprintf(stderr, "Usage: %s infile [outfile]\n", base);
+}
+
+int
+main(int argc, char *argv[])
+{
+ FILE *infile, *outfile;
+ char buffer[BUF_SIZE];
+
+ if (argc < 2 || argc > 3)
+ {
+ usage(argv[0]);
+ return 1;
+ }
+ infile = fopen(argv[1], "r");
+ if (argc < 3)
+ {
+ outfile = stdout;
+ }
+ else
+ {
+ outfile = fopen(argv[2], "w");
+ }
+ while (fgets(buffer, BUF_SIZE, infile) != NULL)
+ {
+ int len;
+ // Step on any CR LF at end of line
+ len = strlen(buffer);
+ if (buffer[len-1] == '\n' || buffer[len-1] == '\r')
+ buffer[len-1] = 0;
+ if (buffer[len-2] == '\n' || buffer[len-2] == '\r')
+ buffer[len-2] = 0;
+ fprintf(outfile, "\"%s\\n\"\n", buffer);
+ }
+ close(infile);
+ close(outfile);
+}