summaryrefslogtreecommitdiffhomepage
path: root/tools/xpcat
diff options
context:
space:
mode:
authorJon <[email protected]>2012-05-02 20:46:09 -0400
committerJon <[email protected]>2012-05-22 10:50:28 -0400
commit9f89da6eef2c830db6fc3abb08fe755ae7ce9b6c (patch)
treed1feb367d93853b5f05ce2bbed2171a561631b31 /tools/xpcat
parentb5dcb7128d7d235b66b4d9be879d26364dd1e3e9 (diff)
downloadmruby-9f89da6eef2c830db6fc3abb08fe755ae7ce9b6c.tar.gz
mruby-9f89da6eef2c830db6fc3abb08fe755ae7ce9b6c.zip
Add native and cross compiling CMake build support
Diffstat (limited to 'tools/xpcat')
-rw-r--r--tools/xpcat/CMakeLists.txt5
-rw-r--r--tools/xpcat/xpcat.c69
2 files changed, 74 insertions, 0 deletions
diff --git a/tools/xpcat/CMakeLists.txt b/tools/xpcat/CMakeLists.txt
new file mode 100644
index 000000000..bb4d326f5
--- /dev/null
+++ b/tools/xpcat/CMakeLists.txt
@@ -0,0 +1,5 @@
+# build tools/xpcat internal executable
+
+add_executable(xpcat xpcat.c)
+
+# vim: ts=2 sts=2 sw=2 et
diff --git a/tools/xpcat/xpcat.c b/tools/xpcat/xpcat.c
new file mode 100644
index 000000000..c9d1abe73
--- /dev/null
+++ b/tools/xpcat/xpcat.c
@@ -0,0 +1,69 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static void
+usage(const char *program)
+{
+ printf("Usage: %s -o outputfile FILE...\n", program);
+}
+
+int
+main(int argc, char *argv[])
+{
+ int i, ch;
+ const char *output = NULL;
+ FILE *infile = NULL;
+ FILE *outfile = NULL;
+
+ if (argc < 4) {
+ usage(argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ for (i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "-o") == 0) {
+ i++;
+ if (i < argc)
+ output = argv[i];
+ else
+ return EXIT_FAILURE;
+ }
+ }
+
+ if (output) {
+ outfile = fopen(output, "wb");
+ if (!outfile) {
+ fprintf(stderr, "[ERROR] unable to open output file: %s\n", output);
+ return EXIT_FAILURE;
+ }
+ setbuf(outfile, NULL);
+
+ for (i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "-o") == 0) { i++; continue; }
+
+ infile = fopen(argv[i], "rb");
+ if (!infile) {
+ fprintf(stderr, "[ERROR] unable to open input file: %s\n", argv[i]);
+ return EXIT_FAILURE;
+ }
+ setbuf(infile, NULL);
+
+ while ((ch = getc(infile)) != EOF) {
+ if (putc(ch, outfile) == EOF) {
+ fprintf(stderr, "[ERROR] error writing output file: %s\n", output);
+ return EXIT_FAILURE;
+ }
+ }
+
+ fclose(infile);
+ }
+ }
+
+done:
+ fclose(outfile);
+
+ return EXIT_SUCCESS;
+}
+
+/* vim: set ts=2 sts=2 sw=2 et: */