summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-bin-strip/tools/mruby-strip
diff options
context:
space:
mode:
authortake_cheeze <[email protected]>2014-02-28 00:36:08 +0900
committertake_cheeze <[email protected]>2014-02-28 00:36:08 +0900
commit1266ab6500d57f0457645c511c4051798f676156 (patch)
treeeee3bbed9db6ac3da049bb3e242f8f89abcd3414 /mrbgems/mruby-bin-strip/tools/mruby-strip
parentd1526b0409a31667de95fbc3b0da23a62ca8bfea (diff)
downloadmruby-1266ab6500d57f0457645c511c4051798f676156.tar.gz
mruby-1266ab6500d57f0457645c511c4051798f676156.zip
add mruby-strip tool to strip irep's debug info
Diffstat (limited to 'mrbgems/mruby-bin-strip/tools/mruby-strip')
-rw-r--r--mrbgems/mruby-bin-strip/tools/mruby-strip/mruby-strip.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/mrbgems/mruby-bin-strip/tools/mruby-strip/mruby-strip.c b/mrbgems/mruby-bin-strip/tools/mruby-strip/mruby-strip.c
new file mode 100644
index 000000000..dee3e0cd6
--- /dev/null
+++ b/mrbgems/mruby-bin-strip/tools/mruby-strip/mruby-strip.c
@@ -0,0 +1,58 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "mruby.h"
+#include "mruby/irep.h"
+#include "mruby/dump.h"
+
+int
+main(int argc, char **argv)
+{
+ int i, dump_result;
+ FILE **files;
+ mrb_irep **ireps;
+ mrb_state *mrb;
+
+ if (argc <= 1) {
+ fprintf(stderr, "no files to strip\n");
+ return EXIT_FAILURE;
+ }
+
+ files = (FILE**)malloc(sizeof(FILE*) * argc);
+ for (i = 1; i < argc; ++i) {
+ files[i] = fopen(argv[i], "rb");
+
+ if (!files[i]) {
+ fprintf(stderr, "can't open file %s\n", argv[i]);
+ return EXIT_FAILURE;
+ }
+ }
+
+ mrb = mrb_open();
+
+ ireps = (mrb_irep**)malloc(sizeof(mrb_irep*) * argc);
+ for (i = 1; i < argc; ++i) {
+ ireps[i] = mrb_read_irep_file(mrb, files[i]);
+ if (!ireps[i]) {
+ fprintf(stderr, "can't read irep file %s\n", argv[i]);
+ return EXIT_FAILURE;
+ }
+ fclose(files[i]);
+ files[i] = fopen(argv[i], "wb");
+ if (!ireps[i]) {
+ fprintf(stderr, "can't reopen irep file %s\n", argv[i]);
+ return EXIT_FAILURE;
+ }
+ }
+
+ for (i = 1; i < argc; ++i) {
+ /* debug flag must be alway false */
+ dump_result = mrb_dump_irep_binary(mrb, ireps[i], FALSE, files[i]);
+ if (dump_result != MRB_DUMP_OK) {
+ fprintf(stderr, "error occur when dumping %s", argv[i]);
+ return EXIT_FAILURE;
+ }
+ }
+
+ mrb_close(mrb);
+ return EXIT_SUCCESS;
+}