From ee8cfd3043984e223512891f73aba3a28df7a1bf Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Mon, 14 Apr 2014 12:44:20 +0200 Subject: [PATCH] scilab: new option -gwid to generate gateway xml file --- Source/Modules/scilab.cxx | 66 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/Source/Modules/scilab.cxx b/Source/Modules/scilab.cxx index 6f97c861d..07b65a2c6 100644 --- a/Source/Modules/scilab.cxx +++ b/Source/Modules/scilab.cxx @@ -18,11 +18,13 @@ static const char *usage = (char *) "\ Scilab options (available with -scilab)\n\ -addcflag - Additional compilation flag to include in build script\n\ - -addldflag - Additional link flag to include in build script\n\ + -addldflag - Additional link flag to include in build script\n\ -addsrc - Additional comma separated source to include in build script\n\ - -vbl - Sets the build verbose (default 0)\n\ + -vbl - Sets the build verbose (default 0)\n\ -buildflags - Uses a Scilab script in to set build flags\n\ - -nobuilder - Do not generate builder script\n\n"; + -nobuilder - Do not generate builder script\n\ + -gwid - Gateway ID \n\n" + ; static const char *SWIG_CREATE_VARIABLES_FUNCTION_NAME = "SWIG_CreateScilabVariables"; @@ -48,6 +50,11 @@ protected: String *verboseBuildLevel; String *buildFlagsScript; + File *gatewayXMLFile; + String *gatewayXML; + String *gatewayID; + int primitiveID; + bool generateBuilder; bool extraWarning; public: @@ -64,6 +71,7 @@ public: verboseBuildLevel = NULL; buildFlagsScript = NULL; generateBuilder = true; + gatewayID = NULL; extraWarning = false; /* Manage command line arguments */ @@ -105,6 +113,11 @@ public: Swig_mark_arg(argIndex); generateBuilder = false; } + else if (strcmp(argv[argIndex], "-gwid") == 0) { + Swig_mark_arg(argIndex); + gatewayID = NewString(argv[argIndex + 1]); + Swig_mark_arg(argIndex + 1); + } else if (strcmp(argv[argIndex], "-Wextra") == 0) { extraWarning = true; } @@ -128,6 +141,9 @@ public: SWIG_typemap_lang("scilab"); allow_overloading(); + + gatewayXML = NULL; + gatewayXMLFile = NULL; } /* ------------------------------------------------------------------------ @@ -169,6 +185,12 @@ public: startBuilderCode(moduleName, outputFilename); } + // Create gateway XML file if specified + if (gatewayID) { + createGatewayXMLFile(moduleName); + primitiveID = 1; + } + // Module initialization function String *moduleInitFunctionName = NewString(""); Printf(moduleInitFunctionName, "%s_Init", moduleName); @@ -216,6 +238,11 @@ public: Dump(variablesCode, beginSection); Wrapper_pretty_print(initSection, beginSection); + // Save gateway XML file + if (gatewayXMLFile) { + saveGatewayXMLFile(); + } + /* Cleanup files */ Delete(runtimeSection); Delete(headerSection); @@ -447,6 +474,10 @@ public: addFunctionInBuilder(functionName, wrapperName); } + if (gatewayID) { + Printf(gatewayXML, "\n", gatewayID, primitiveID++, functionName); + } + /* tidy up */ Delete(overloadedName); Delete(wrapperName); @@ -795,6 +826,35 @@ public: Delete(builderFile); } + void createGatewayXMLFile(String *moduleName) { + String *gatewayXMLFilename = NewStringf("%s_gateway.xml", moduleName); + gatewayXMLFile = NewFile(gatewayXMLFilename, "w", SWIG_output_files()); + if (!gatewayXMLFile) { + FileErrorDisplay(gatewayXMLFilename); + SWIG_exit(EXIT_FAILURE); + } + + gatewayXML = NewString(""); + Printf(gatewayXML, "\n"); + Printf(gatewayXML, "\n", moduleName); + Printf(gatewayXML, "\n"); + } + + void saveGatewayXMLFile() { + Printv(gatewayXML, "\n"); + Printv(gatewayXMLFile, gatewayXML, NIL); + Delete(gatewayXMLFile); + } + /* ----------------------------------------------------------------------- * addFunctionInBuilder(): add a new function wrapper in builder.sce file * ----------------------------------------------------------------------- */