From 5e6e7d53fb17694c67a61855367aec95fc8c12fe Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Thu, 20 Aug 2015 16:02:16 -0400 Subject: [PATCH] contrib/objcwrapper: add the -o option to specify the output file MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- contrib/objcwrapper/src/objc_generator.nit | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/contrib/objcwrapper/src/objc_generator.nit b/contrib/objcwrapper/src/objc_generator.nit index 673e306..3b50721 100644 --- a/contrib/objcwrapper/src/objc_generator.nit +++ b/contrib/objcwrapper/src/objc_generator.nit @@ -15,8 +15,15 @@ # Code generation module objc_generator +import opts + import objc_model +redef class Sys + # Path to the output file + var opt_output = new OptionString("Output file", "-o") +end + class CodeGenerator # Merge the calls to `alloc` and `init...` in a single constructor? # @@ -34,11 +41,25 @@ class CodeGenerator var init_with_alloc = true is writable fun generator(classes: Array[nullable ObjcClass]) do + # Open specified path or stdin + var file + var path = opt_output.value + if path != null then + if path.file_extension != "nit" then + print_error "Warning: output file path does not end with '.nit'" + end + + file = new FileWriter.open(path) + else + file = stdout + end + + # Generate code for classe in classes do - var file = new FileWriter.open(classe.name + ".nit") nit_class_generator(classe, file, init_with_alloc) - file.close end + + if path != null then file.close end fun type_convertor(type_word: String): String do -- 1.7.9.5