Mercurial > archived > louis > epitech > mq > rathaxes
view rathaxes_add_the_output_option_to_rathaxes_generate.patch @ 0:973e7bc6d13c
Add some patches to use and test rathaxes with CMake
author | Louis Opter <louis@lse.epitech.net> |
---|---|
date | Sun, 01 Jan 2012 15:31:17 +0100 |
parents | |
children |
line wrap: on
line source
# HG changeset patch # Parent 5c7b83ad7fcab2fb5f1addeeeb70ae28a6c099cf rathaxes: add a `/o' option to `rathaxes generate' to write the result to the given file diff --git a/rathaxes/compiler/rathaxes.cws b/rathaxes/compiler/rathaxes.cws --- a/rathaxes/compiler/rathaxes.cws +++ b/rathaxes/compiler/rathaxes.cws @@ -38,7 +38,11 @@ function usage() { - traceLine( "Usage: rathaxes generate (linux|openbsd|windows) file.rtx" + endl() + /* + * We use /o options because codeworker doesn't have a way to escape + * options (i.e: --)... + */ + traceLine( "Usage: rathaxes generate [/o output.c] (linux|openbsd|windows) file.rtx" + endl() + " or rathaxes rti-check (file.rti|file.rtx)" + endl() + " or rathaxes rti-register (file.rti|file.rtx)" + endl() + " or rathaxes blt-check (file.blt|file.rtx)" + endl() @@ -74,6 +78,32 @@ } } +function rtxParseGenerateOptions(argv : node, options : node) +{ + local to_remove; + foreach item in argv + { + switch (item) + { + case "/o": + local arg_key = $item.key() + 1$; + if (findElement(arg_key, argv) && charAt(argv[arg_key], 0) != "/") + { + insert options["output"] = argv[arg_key]; + pushItem to_remove = item.key(); + pushItem to_remove = arg_key; + break ; + } + error("Missing argument for option /o"); + default: + break ; + } + } + + foreach item in to_remove + removeElement(argv, item); +} + /* * First, setup the paths */ @@ -96,8 +126,16 @@ if (toLowerString(this.operation) == "generate") { - local target_os = toLowerString(_ARGS[3]); - local inputFile = _ARGS[4]; + local options; + + rtxParseGenerateOptions(_ARGS, options); + + /* + * rtxParseGenerateOptions will have messed up the keys to remove the + * options from _ARGS so use "absolute" indexes with the # notation + */ + local target_os = toLowerString(_ARGS#[3]); + local inputFile = _ARGS#[4]; if (rtxLink_LoadCache() == false) traceLine("Could not load cache. Trying to do without it..."); @@ -133,13 +171,25 @@ traceLine(RED + "[Error] Driver could not be generated." + DEFAULT_COLOR); exit(6); } - + //traceLine(BLUE + toString(this.c_tree.c_block,true) + DEFAULT_COLOR); //removeElement(this.c_tree.c_block.block, "_3_8"); //removeVariable(this.c_tree.c_block.compile); //traceLine(PURPLE + toString(this.c_tree.c_block,true) + DEFAULT_COLOR); - traceLine("Resulting code:"+cnorm2c(this.c_tree.c_block)); + /* + * This is our final code, tell cnorm2c that this is a root block, + * otherwise it will scope the whole thing inside braces. + */ + this.c_tree.c_block.type = "__root_block__"; + local code = cnorm2c(this.c_tree.c_block); + traceLine("Resulting code: " + code); + + if (findElement("output", options)) + { + traceLine("Writing to file: " + options["output"]); + saveToFile(options["output"], code + endl()); + } } else if ( toLowerString(this.operation) == "blt-check" || toLowerString(this.operation) == "blt-register")