/*--------------------------------------------------------------------------*/ BOOL Set_SCI_PATH(char *DefaultPath) { BOOL bOK = FALSE; char *ShortPath = NULL; /* to be sure that it's unix 8.3 format */ /* c:/progra~1/scilab-5.0 */ ShortPath = getshortpathname(DefaultPath, &bOK); if (ShortPath) { char env[PATH_MAX + 1 + 10]; AntislashToSlash(ShortPath, ShortPath); sprintf (env, "SCI=%s", ShortPath); setSCI(ShortPath); if (ShortPath) { FREE(ShortPath); ShortPath = NULL; } if (_putenv (env)) { bOK = FALSE; } else { bOK = TRUE; } } return bOK; }
/*--------------------------------------------------------------------------*/ char *GetXmlFileEncoding(const char *filename) { #define DEFAULT_ENCODING "UTF-8" char *encoding = NULL; xmlDocPtr doc = NULL; BOOL bConvert = FALSE; char *shortfilename = getshortpathname((char*)filename,&bConvert); /* default */ encoding = strdup(DEFAULT_ENCODING); if (shortfilename) { doc = xmlParseFile (filename); FREE(shortfilename); shortfilename = NULL; if (doc) { if (doc->encoding) { if (encoding) {FREE(encoding);encoding=NULL;} encoding = strdup((char*)doc->encoding); } } xmlFreeDoc (doc); } return encoding; }
/*--------------------------------------------------------------------------*/ void putenvTMPDIR(const char *_sci_tmpdir) { char *ShortPath = NULL; char *CopyOfDefaultPath = NULL; /* to be sure that it's unix 8.3 format */ /* c:/progra~1/scilab-5.0 */ BOOL bConvertOK = FALSE; ShortPath = getshortpathname(_sci_tmpdir, &bConvertOK); //GetShortPathName(_sci_path,ShortPath,PATH_MAX); CopyOfDefaultPath = new char[strlen(_sci_tmpdir) + 1]; AntislashToSlash(ShortPath, CopyOfDefaultPath); setenvc("TMPDIR", ShortPath); delete[] CopyOfDefaultPath; FREE(ShortPath); }
/*--------------------------------------------------------------------------*/ JavaVMOption * getJvmOptions(char *SCI_PATH, char *filename_xml_conf, int *size_JavaVMOption) { if ( FileExist(filename_xml_conf) ) { JavaVMOption *jvm_options = NULL; char *encoding = GetXmlFileEncoding(filename_xml_conf); /* Don't care about line return / empty line */ xmlKeepBlanksDefault(0); /* check if the XML file has been encoded with utf8 (unicode) or not */ if (stricmp("utf-8", encoding) == 0) { xmlDocPtr doc = NULL; xmlXPathContextPtr xpathCtxt = NULL; xmlXPathObjectPtr xpathObj = NULL; char *jvm_option_string = NULL; char *xpath_query = NULL; int indice = 0; { BOOL bConvert = FALSE; char *shortfilename_xml_conf = getshortpathname(filename_xml_conf, &bConvert); if (shortfilename_xml_conf) { doc = xmlParseFile (shortfilename_xml_conf); FREE(shortfilename_xml_conf); shortfilename_xml_conf = NULL; } } if (doc == NULL) { fprintf(stderr, _("Error: Could not parse file %s.\n"), filename_xml_conf); FREE(encoding); encoding = NULL; *size_JavaVMOption = 0; return NULL; } xpathCtxt = xmlXPathNewContext(doc); /* Retrieve all nodes without the os tag + only the one from our operating system */ #define XPATH_QUERY "//jvm_options/option[not(@os)] | //jvm_options/option[@os='%s']" xpath_query = (char *)MALLOC(sizeof(char) * ((int)strlen(XPATH_QUERY) + (int)strlen(OSNAME) + 1)); sprintf(xpath_query, XPATH_QUERY, OSNAME); xpathObj = xmlXPathEval((const xmlChar*)xpath_query, xpathCtxt); FREE(xpath_query); if (xpathObj && xpathObj->nodesetval->nodeMax) { /* the Xpath has been understood and there are node */ int i; char *heapSize = getJavaHeapSize(); for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) { xmlAttrPtr attrib = xpathObj->nodesetval->nodeTab[i]->properties; /* Get the properties of <option> */ while (attrib != NULL) { /* loop until when have read all the attributes */ if (xmlStrEqual (attrib->name, (const xmlChar*) "value")) { /* we found the tag name */ const char *str = (const char*)attrib->children->content; if (strstr(str, "-Xmx") == str && heapSize) { jvm_option_string = os_strdup(heapSize); } else { jvm_option_string = os_strdup(str); } } attrib = attrib->next; } if ( (jvm_option_string) && (strlen(jvm_option_string) > 0) ) { char *option_string_path_separator = NULL; char *option_string_sci_path = NULL; option_string_path_separator = strsub(jvm_option_string, "$PATH_SEPARATOR", PATH_SEPARATOR); option_string_sci_path = strsub(option_string_path_separator, "$SCILAB", SCI_PATH); if (option_string_path_separator) { FREE(option_string_path_separator); } jvm_options = (JavaVMOption *)REALLOC(jvm_options, sizeof(JavaVMOption) * (indice + 1)); jvm_options[indice].optionString = option_string_sci_path; indice++; } if (jvm_option_string) { FREE(jvm_option_string); jvm_option_string = NULL; } } FREE(heapSize); } if (xpathObj) { xmlXPathFreeObject(xpathObj); } if (xpathCtxt) { xmlXPathFreeContext(xpathCtxt); } xmlFreeDoc (doc); /* xmlCleanupParser is called in * modules/core/src/c/TerminateCore.c * since it needs to be done only once. */ if (getenv("SCI_JAVA_ENABLE_HEADLESS") != NULL) { /* When Scilab is built from a virtual machine, it needs * an X11 server / input * This is only called by "make doc" by the SCI/Makefile.am */ #define HEADLESS "-Djava.awt.headless=true" jvm_options = (JavaVMOption *)REALLOC(jvm_options, sizeof(JavaVMOption) * (indice + 1)); jvm_options[indice].optionString = MALLOC((strlen(HEADLESS) + 1) * sizeof(char)); strcpy(jvm_options[indice].optionString, HEADLESS); indice++; #undef HEADLESS } FREE(encoding); encoding = NULL; *size_JavaVMOption = indice; return jvm_options; } else { fprintf(stderr, _("Error: Not a valid configuration file %s (encoding not '%s') Encoding '%s' found.\n"), filename_xml_conf, "utf-8", encoding); } FREE(encoding); encoding = NULL; } return NULL; }
static BOOL defineSCIHOME(void) { #define BASEDIR "Scilab" int ierr = 0; int buflen = PATH_MAX; int iflag = 0; char USERPATHSCILAB[PATH_MAX]; char USERHOMESYSTEM[PATH_MAX]; char *SHORTUSERHOMESYSTEM = NULL; BOOL bConverted = FALSE; C2F(getenvc)(&ierr, "APPDATA", USERHOMESYSTEM, &buflen, &iflag); /* if APPDATA not found we try with USERPROFILE */ if (ierr) { C2F(getenvc)(&ierr, "USERPROFILE", USERHOMESYSTEM, &buflen, &iflag); } /* convert long path to short path format : remove some special characters */ SHORTUSERHOMESYSTEM = getshortpathname(USERHOMESYSTEM, &bConverted); if (SHORTUSERHOMESYSTEM) { if (!isdir(SHORTUSERHOMESYSTEM)) { /* last chance, we try to get default all users profile */ C2F(getenvc)(&ierr, "ALLUSERSPROFILE", USERHOMESYSTEM, &buflen, &iflag); if (ierr) { FREE(SHORTUSERHOMESYSTEM); SHORTUSERHOMESYSTEM = NULL; return FALSE; } /* convert long path to short path format : remove some special characters */ SHORTUSERHOMESYSTEM = getshortpathname(USERHOMESYSTEM, &bConverted); if ( (!SHORTUSERHOMESYSTEM) || (!isdir(SHORTUSERHOMESYSTEM)) ) { if (SHORTUSERHOMESYSTEM) { FREE(SHORTUSERHOMESYSTEM); SHORTUSERHOMESYSTEM = NULL; } return FALSE; } } } else { if (SHORTUSERHOMESYSTEM) { FREE(SHORTUSERHOMESYSTEM); SHORTUSERHOMESYSTEM = NULL; } return FALSE; } /* checks that directory exists */ strcpy(USERHOMESYSTEM, SHORTUSERHOMESYSTEM); if (SHORTUSERHOMESYSTEM) { FREE(SHORTUSERHOMESYSTEM); SHORTUSERHOMESYSTEM = NULL; } /* Set SCIHOME environment variable */ snprintf(USERPATHSCILAB, sizeof(USERPATHSCILAB), "%s%s%s", USERHOMESYSTEM, DIR_SEPARATOR, BASEDIR); snprintf(SCIHOMEPATH, sizeof(SCIHOMEPATH), "%s%s%s", USERPATHSCILAB, DIR_SEPARATOR, SCI_VERSION_STRING); /* creates directory if it does not exists */ if (!isdir(SCIHOMEPATH)) { if (!isdir(USERPATHSCILAB)) { createdirectory(USERPATHSCILAB); } if (createdirectory(SCIHOMEPATH)) { return TRUE; } } else { return TRUE; } return FALSE; }
/*--------------------------------------------------------------------------*/ BOOL LoadClasspath(char *xmlfilename) { BOOL bOK = FALSE; BOOL errorOnLoad = FALSE; if ( FileExist(xmlfilename) ) { char *encoding = GetXmlFileEncoding(xmlfilename); /* Don't care about line return / empty line */ xmlKeepBlanksDefault(0); /* check if the XML file has been encoded with utf8 (unicode) or not */ if ( stricmp("utf-8", encoding) == 0 ) { xmlXPathContextPtr xpathCtxt = NULL; xmlXPathObjectPtr xpathObj = NULL; char *classpath = NULL; char *load = ""; typeOfLoad eLoad = STARTUP; const char *currentMode = getScilabModeString(); /* Xpath Query : * Retrieve all the path which are not disabled in our mode */ #define XPATH "//classpaths/path[not(@disableUnderMode='%s')]" char * XPath = (char*)MALLOC(sizeof(char) * (strlen(XPATH) + strlen(currentMode) - 2 + 1)); /* -2 = strlen(%s) */ sprintf(XPath, XPATH, currentMode); { BOOL bConvert = FALSE; char *shortxmlfilename = getshortpathname(xmlfilename, &bConvert); if (shortxmlfilename) { ClassPathxmlDocPtr = xmlParseFile (shortxmlfilename); FREE(shortxmlfilename); shortxmlfilename = NULL; } } if (ClassPathxmlDocPtr == NULL) { fprintf(stderr, _("Error: could not parse file %s\n"), xmlfilename); if (encoding) { FREE(encoding); encoding = NULL; } return bOK; } xpathCtxt = xmlXPathNewContext(ClassPathxmlDocPtr); xpathObj = xmlXPathEval((const xmlChar*)XPath, xpathCtxt); if (xpathObj && xpathObj->nodesetval->nodeMax) { /* the Xpath has been understood and there are node */ int i; for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) { xmlAttrPtr attrib = xpathObj->nodesetval->nodeTab[i]->properties; /* Get the properties of <path> */ while (attrib != NULL) { /* loop until when have read all the attributes */ if (xmlStrEqual (attrib->name, (const xmlChar*) "value")) { /* we found the tag value */ classpath = (char*)attrib->children->content; } if (xmlStrEqual (attrib->name, (const xmlChar*) "load")) { /* we found the tag load */ load = (char*)attrib->children->content; /* By default, it is startup */ if (stricmp(load, "background") == 0) { eLoad = BACKGROUND; } else { if (stricmp(load, "onuse") == 0) { eLoad = ONUSE; } } } else { eLoad = STARTUP; } attrib = attrib->next; } if ( (classpath) && (strlen(classpath) > 0) && (strncmp(classpath, "@", 1) != 0) ) /* If it starts by a @ that means it hasn't been able to find it... which is normal... for example with the documentation */ { #define KEYWORDSCILAB "$SCILAB" char *sciPath = getSCI(); char *FullClasspath = NULL; if (strncmp(classpath, KEYWORDSCILAB, strlen(KEYWORDSCILAB)) == 0) { FullClasspath = (char*)MALLOC(sizeof(char) * (strlen(sciPath) + strlen(classpath) + 1)); if (FullClasspath) { strcpy(FullClasspath, sciPath); strcat(FullClasspath, &classpath[strlen(KEYWORDSCILAB)]); } } else { FullClasspath = os_strdup(classpath); } if (FullClasspath) { if (!addToClasspath(FullClasspath, eLoad)) { errorOnLoad = TRUE; } FREE(FullClasspath); FullClasspath = NULL; } if (sciPath) { FREE(sciPath); sciPath = NULL; } classpath = NULL; } } bOK = TRUE; } else { fprintf(stderr, _("Wrong format for %s.\n"), xmlfilename); } if (xpathObj) { xmlXPathFreeObject(xpathObj); } if (xpathCtxt) { xmlXPathFreeContext(xpathCtxt); } if (XPath) { FREE(XPath); XPath = NULL; } } else { fprintf(stderr, _("Error : Not a valid classpath file %s (encoding not 'utf-8') Encoding '%s' found\n"), xmlfilename, encoding); } if (encoding) { FREE(encoding); encoding = NULL; } } else { fprintf(stderr, _("Warning: could not find classpath declaration file %s.\n"), xmlfilename); } if (errorOnLoad) { fprintf(stderr, _("Some problems during the loading of the Java libraries occurred.\nThis could lead to inconsistent behaviours.\nPlease check SCI/etc/classpath.xml.\n")); } return bOK; }
/*--------------------------------------------------------------------------*/ static struct gateway_struct *readGatewayXmlFile(char *filenameXml) { struct gateway_struct *gateway = NULL; char *encoding = GetXmlFileEncoding(filenameXml); /* Don't care about line return / empty line */ xmlKeepBlanksDefault(0); /* check if the XML file has been encoded with utf8 (unicode) or not */ if ( (strcmp("utf-8", encoding) != 0) || (strcmp("UTF-8", encoding) == 0) ) { xmlDocPtr doc = NULL; xmlXPathContextPtr xpathCtxt = NULL; xmlXPathObjectPtr xpathObj = NULL; int GATEWAY_ID = 0; int PRIMITIVE_ID = 0; char *PRIMITIVE_NAME = NULL; { BOOL bConvert = FALSE; char *shortfilenameXml = getshortpathname(filenameXml, &bConvert); if (shortfilenameXml) { doc = xmlParseFile (shortfilenameXml); FREE(shortfilenameXml); shortfilenameXml = NULL; } } if (doc == NULL) { fprintf(stderr, _("Error: could not parse file %s\n"), filenameXml); if (encoding) { FREE(encoding); encoding = NULL; } return NULL; } gateway = (struct gateway_struct *)MALLOC(sizeof(struct gateway_struct)); if (gateway == NULL) { fprintf(stderr, _("Error: Memory allocation.\n")); if (encoding) { FREE(encoding); encoding = NULL; } return NULL; } else { gateway->dimLists = 0; gateway->gatewayIdList = NULL; gateway->primitivesList = NULL; gateway->primiviteIdList = NULL; } xpathCtxt = xmlXPathNewContext(doc); xpathObj = xmlXPathEval((const xmlChar*)"//GATEWAY/PRIMITIVE", xpathCtxt); if (xpathObj && xpathObj->nodesetval->nodeMax) { /* the Xpath has been understood and there are node */ int i; for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) { xmlAttrPtr attrib = xpathObj->nodesetval->nodeTab[i]->properties; /* Get the properties of <PRIMITIVE> */ while (attrib != NULL) { /* loop until when have read all the attributes */ if (xmlStrEqual (attrib->name, (const xmlChar*) "gatewayId")) { /* we found the tag gatewayId */ const char *str = (const char*)attrib->children->content; GATEWAY_ID = atoi(str); } else if (xmlStrEqual (attrib->name, (const xmlChar*)"primitiveId")) { /* we found the tag primitiveId */ const char *str = (const char*)attrib->children->content; PRIMITIVE_ID = atoi(str); } else if (xmlStrEqual (attrib->name, (const xmlChar*)"primitiveName")) { /* we found the tag primitiveName */ const char *str = (const char*)attrib->children->content; PRIMITIVE_NAME = strdup(str); } attrib = attrib->next; } if ( (GATEWAY_ID != 0) && (PRIMITIVE_ID != 0) && (PRIMITIVE_NAME) ) { if (strlen(PRIMITIVE_NAME) > 0) { gateway->dimLists++; if (gateway->gatewayIdList) { gateway->gatewayIdList = (int*)REALLOC(gateway->gatewayIdList, sizeof(int*)*gateway->dimLists); } else { gateway->gatewayIdList = (int*)MALLOC(sizeof(int) * gateway->dimLists); } if (gateway->primitivesList) { gateway->primitivesList = (char **)REALLOC(gateway->primitivesList, sizeof(char**)*gateway->dimLists); } else { gateway->primitivesList = (char **)MALLOC(sizeof(char*)*gateway->dimLists); } if (gateway->primiviteIdList) { gateway->primiviteIdList = (int*)REALLOC(gateway->primiviteIdList, sizeof(int*)*gateway->dimLists); } else { gateway->primiviteIdList = (int*)MALLOC(sizeof(int) * gateway->dimLists); } if (gateway->gatewayIdList) { gateway->gatewayIdList[gateway->dimLists - 1] = GATEWAY_ID; } if (gateway->primitivesList) { gateway->primitivesList[gateway->dimLists - 1] = strdup(PRIMITIVE_NAME); } if (gateway->primiviteIdList) { gateway->primiviteIdList[gateway->dimLists - 1] = PRIMITIVE_ID; } } } if (PRIMITIVE_NAME) { FREE(PRIMITIVE_NAME); PRIMITIVE_NAME = NULL; } GATEWAY_ID = 0; PRIMITIVE_ID = 0; } } else { fprintf(stderr, _("Error: Not a valid gateway file %s (should start with <GATEWAY> and contain <PRIMITIVE gatewayId='' primitiveId='' primitiveName=''>)\n"), filenameXml); } if (xpathObj) { xmlXPathFreeObject(xpathObj); } if (xpathCtxt) { xmlXPathFreeContext(xpathCtxt); } xmlFreeDoc (doc); } else { fprintf(stderr, _("Error: Not a valid gateway file %s (encoding not 'utf-8') Encoding '%s' found\n"), filenameXml, encoding); } if (encoding) { FREE(encoding); encoding = NULL; } return gateway; }
/*--------------------------------------------------------------------------*/ static void *DaemonOpenTCLsci(void* in) /* Checks if tcl/tk has already been initialised and if not */ /* initialise it. It must find the tcl script */ { char *SciPath = NULL; char *SciPathShort = NULL; char *TkScriptpathShort = NULL; BOOL tkStarted = FALSE; BOOL bOK = FALSE; char TkScriptpath[PATH_MAX]; char MyCommand[2048]; /* @TODO: Check for buffer overflow */ #ifndef _MSC_VER DIR *tmpdir = NULL; #endif FILE *tmpfile2 = NULL; SciPath = GetSciPath(); /* test SCI validity */ if (SciPath == NULL) { sciprint(_("The SCI environment variable is not set.\nTCL initialisation failed !\n")); } SciPathShort = getshortpathname(SciPath, &bOK); #ifdef TCL_MAJOR_VERSION #ifdef TCL_MINOR_VERSION #if TCL_MAJOR_VERSION >= 8 #if TCL_MINOR_VERSION > 0 Tcl_FindExecutable(" "); #endif #endif #endif #endif #ifdef _MSC_VER strcpy(TkScriptpath, SciPathShort); strcat(TkScriptpath, "/modules/tclsci/tcl/TK_Scilab.tcl"); TkScriptpathShort = getshortpathname(TkScriptpath, &bOK); tmpfile2 = fopen(TkScriptpathShort, "r"); if (tmpfile2 == NULL) { sciprint(_("Unable to find Tcl initialisation scripts.\nCheck your SCI environment variable.\nTcl initialisation failed !")); } else { fclose(tmpfile2); } #else tmpdir = opendir(SciPathShort); if (tmpdir == NULL) { sciprint(_("The SCI environment variable is not set.\nTcl initialisation failed !\n")); } else { closedir(tmpdir); } strcpy(TkScriptpath, SciPathShort); strcat(TkScriptpath, "/modules/tclsci/tcl/TK_Scilab.tcl"); TkScriptpathShort = getshortpathname(TkScriptpath, &bOK); tmpfile2 = fopen(TkScriptpathShort, "r"); if (tmpfile2 == NULL) { sciprint(_("Unable to find Tcl initialisation scripts.\nCheck your SCI environment variable.\nTcl initialisation failed !")); } else { fclose(tmpfile2); } #endif /* _MSC_VER */ if (getTclInterp() == NULL) { releaseTclInterp(); initTclInterp(); #ifdef _MSC_VER /* Initialize TCL_LIBRARY & TK_LIBRARY variables environment */ /* Windows only */ SetTclTkEnvironment(SciPathShort); #endif if ( getTclInterp() == NULL ) { Scierror(999, _("Tcl Error: Unable to create Tcl interpreter (Tcl_CreateInterp).\n")); } releaseTclInterp(); if ( Tcl_Init(getTclInterp()) == TCL_ERROR) { releaseTclInterp(); Scierror(999, _("Tcl Error: Error during the Tcl initialization (Tcl_Init): %s\n"), Tcl_GetStringResult(getTclInterp())); } releaseTclInterp(); if (getenv("SCI_DISABLE_TK") == NULL) { /* When SCI_DISABLE_TK is set in the env disable the TK init * process. It is causing issues when Scilab is * used through ssh. */ if ( Tk_Init(getTclInterp()) == TCL_ERROR) { releaseTclInterp(); Scierror(999, _("Tcl Error: Error during the TK initialization (Tk_Init): %s\n"), Tcl_GetStringResult(getTclInterp())); } else { tkStarted = TRUE; } releaseTclInterp(); } sprintf(MyCommand, "set SciPath \"%s\";", SciPathShort); if ( Tcl_Eval(getTclInterp(), MyCommand) == TCL_ERROR ) { releaseTclInterp(); Scierror(999, _("Tcl Error: Error during the Scilab/Tcl init process. Could not set SciPath: %s\n"), Tcl_GetStringResult(getTclInterp())); } releaseTclInterp(); Tcl_CreateCommand(getTclInterp(), "ScilabEval", TCL_EvalScilabCmd, (ClientData)1, NULL); releaseTclInterp(); } if (TKmainWindow == NULL && tkStarted) { TKmainWindow = Tk_MainWindow(getTclInterp()); releaseTclInterp(); Tk_GeometryRequest(TKmainWindow, 2, 2); //printf("TkScriptpathShort : |%s|\n", TkScriptpathShort); if ( Tcl_EvalFile(getTclInterp(), TkScriptpathShort) == TCL_ERROR ) { releaseTclInterp(); Scierror(999, _("Tcl Error: Error during the Scilab/TK init process. Error while loading %s: %s\n"), TkScriptpathShort, Tcl_GetStringResult(getTclInterp())); } releaseTclInterp(); } if (SciPath) { FREE(SciPath); SciPath = NULL; } if (SciPathShort) { FREE(SciPathShort); SciPathShort = NULL; } if (TkScriptpathShort) { FREE(TkScriptpathShort); TkScriptpathShort = NULL; } // This start a periodic and endless call to "update" // TCL command. This causes any TCL application to start // and run as if it's in the main program thread. startTclLoop(); return(0); }
/*--------------------------------------------------------------------------*/ BOOL LoadLibrarypath(char *xmlfilename) { BOOL bOK = FALSE; if ( FileExist(xmlfilename) ) { char *encoding=GetXmlFileEncoding(xmlfilename); /* Don't care about line return / empty line */ xmlKeepBlanksDefault(0); /* check if the XML file has been encoded with utf8 (unicode) or not */ if ( stricmp("utf-8", encoding)==0 ) { xmlDocPtr doc = NULL; xmlXPathContextPtr xpathCtxt = NULL; xmlXPathObjectPtr xpathObj = NULL; char *libraryPath=NULL; { BOOL bConvert = FALSE; char *shortxmlfilename = getshortpathname(xmlfilename,&bConvert); if (shortxmlfilename) { doc = xmlParseFile (shortxmlfilename); FREE(shortxmlfilename); shortxmlfilename = NULL; } } if (doc == NULL) { fprintf(stderr,_("Error: could not parse file %s\n"), xmlfilename); if (encoding) {FREE(encoding);encoding=NULL;} return bOK; } xpathCtxt = xmlXPathNewContext(doc); xpathObj = xmlXPathEval((const xmlChar*)"//librarypaths/path", xpathCtxt); if(xpathObj && xpathObj->nodesetval->nodeMax) { /* the Xpath has been understood and there are node */ int i; for(i = 0; i < xpathObj->nodesetval->nodeNr; i++) { xmlAttrPtr attrib=xpathObj->nodesetval->nodeTab[i]->properties; /* Get the properties of <path> */ while (attrib != NULL) { /* loop until when have read all the attributes */ if (xmlStrEqual (attrib->name, (const xmlChar*) "value")) { /* we found the tag value */ libraryPath = (char*)attrib->children->content; } attrib = attrib->next; } if ( (libraryPath) && (strlen(libraryPath) > 0) ) { #define KEYWORDSCILAB "$SCILAB" char *FullLibrarypath = NULL; char *sciPath = getSCIpath(); if (strncmp(libraryPath,KEYWORDSCILAB, strlen(KEYWORDSCILAB))==0) { FullLibrarypath = (char*)MALLOC(sizeof(char)*(strlen(sciPath)+strlen(libraryPath)+1)); if (FullLibrarypath) { strcpy(FullLibrarypath,sciPath); strcat(FullLibrarypath,&libraryPath[strlen(KEYWORDSCILAB)]); } } else { FullLibrarypath = strdup(libraryPath); } if (FullLibrarypath) { addToLibrarypath(FullLibrarypath); FREE(FullLibrarypath); FullLibrarypath = NULL; } if (sciPath) {FREE(sciPath);sciPath=NULL;} libraryPath = NULL; } } bOK = TRUE; } else { fprintf(stderr,_("Wrong format for %s.\n"), xmlfilename); } if(xpathObj) xmlXPathFreeObject(xpathObj); if(xpathCtxt) xmlXPathFreeContext(xpathCtxt); xmlFreeDoc (doc); } else { fprintf(stderr,_("Error : Not a valid path file %s (encoding not 'utf-8') Encoding '%s' found\n"), xmlfilename, encoding); } if (encoding) {FREE(encoding);encoding=NULL;} } return bOK; }
/*--------------------------------------------------------------------------*/ int sci_dos(char *fname, void* pvApiCtx) { SciErr sciErr; int *piAddressVarOne = NULL; int iType1 = 0; wchar_t *pStVarOne = NULL; char **Output = NULL; int numberoflines = 0; BOOL ECHOMODE = FALSE; CheckRhs(1, 2); CheckLhs(1, 3); if (Rhs == 2) { int *piAddressVarTwo = NULL; int m2 = 0, n2 = 0; int iType2 = 0; char *pStVarTwo = NULL; int lenStVarTwo = 0; sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddressVarTwo); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2); return 0; } sciErr = getVarType(pvApiCtx, piAddressVarTwo, &iType2); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2); return 0; } if (iType2 != sci_strings ) { Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 2); return 0; } sciErr = getMatrixOfString(pvApiCtx, piAddressVarTwo, &m2, &n2, &lenStVarTwo, NULL); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2); return 0; } if ( (m2 != n2) && (n2 != 1) ) { Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), fname, 2); return 0; } pStVarTwo = (char*)MALLOC(sizeof(char) * (lenStVarTwo + 1)); if (pStVarTwo) { sciErr = getMatrixOfString(pvApiCtx, piAddressVarTwo, &m2, &n2, &lenStVarTwo, &pStVarTwo); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2); return 0; } if ( strcmp(pStVarTwo, "-echo") ) { FREE(pStVarTwo); pStVarTwo = NULL; Scierror(999, _("%s: Wrong value for input argument #%d: '%s' expected.\n"), fname, 2, "-echo"); return 0; } else { ECHOMODE = TRUE; } } else { Scierror(999, _("%s: No more memory.\n"), fname); return 0; } } sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType1); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } if (iType1 != sci_strings ) { Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 1); return 0; } if (isScalar(pvApiCtx, piAddressVarOne) == FALSE) { Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), fname, 1); return 0; } if (getAllocatedSingleWideString(pvApiCtx, piAddressVarOne, &pStVarOne)) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } double exitCode = 0.; BOOL DetachProcessOption = FALSE; BOOL *StatusExit = NULL; DetachProcessOption = DetectDetachProcessInCommandLine(pStVarOne); exitCode = (double)spawncommand(pStVarOne, DetachProcessOption); freeAllocatedSingleWideString(pStVarOne); StatusExit = (BOOL*)MALLOC(sizeof(BOOL)); if (DetachProcessOption) { if (strlen((const char *)(pipeSpawnErr.OutputBuffer))) { /* StdErr will be "Output" */ *StatusExit = FALSE; Output = CreateOuput(&pipeSpawnErr, DetachProcessOption); numberoflines = pipeSpawnErr.NumberOfLines; } else { /* StdOut will be "Output" */ *StatusExit = TRUE; Output = CreateOuput(&pipeSpawnOut, DetachProcessOption); numberoflines = pipeSpawnOut.NumberOfLines; } } else { char FileTMPDir[PATH_MAX + 16]; BOOL bConvert = FALSE; char *TMPDirLong = getTMPDIR(); char *TMPDirShort = getshortpathname(TMPDirLong, &bConvert); sprintf(FileTMPDir, "%s\\DOS.OK", TMPDirLong); FREE(TMPDirLong); TMPDirLong = NULL; FREE(TMPDirShort); TMPDirShort = NULL; if (FileExist(FileTMPDir)) { DeleteFile(FileTMPDir); /* StdOut will be "Output" */ *StatusExit = TRUE; Output = CreateOuput(&pipeSpawnOut, DetachProcessOption); numberoflines = pipeSpawnOut.NumberOfLines; } else { /* StdErr will be "Output" */ *StatusExit = FALSE; Output = CreateOuput(&pipeSpawnErr, DetachProcessOption); numberoflines = pipeSpawnErr.NumberOfLines; } } if (ECHOMODE) { PrintOuput(Output, numberoflines); } if (Lhs == 1) { int m_out = 1, n_out = 1; sciErr = createMatrixOfBoolean(pvApiCtx, Rhs + 1, m_out, n_out, StatusExit); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } LhsVar(1) = Rhs + 1; } else { int m_out2 = 1; int n_out2 = 1; if (Output && Output[0]) { int m_out1 = numberoflines; int n_out1 = 1; sciErr = createMatrixOfString(pvApiCtx, Rhs + 1, m_out1, n_out1, Output); } else { /* returns [] */ int m_out1 = 0; int n_out1 = 0; sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, m_out1, n_out1, NULL); } if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } LhsVar(1) = Rhs + 1; sciErr = createMatrixOfBoolean(pvApiCtx, Rhs + 2, m_out2, n_out2, StatusExit); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } LhsVar(2) = Rhs + 2; } if (Lhs > 2) { int m_out3 = 1, n_out3 = 1; sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 3, m_out3, n_out3, &exitCode); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } LhsVar(3) = Rhs + 3; } if (StatusExit) { FREE(StatusExit); StatusExit = NULL; } freeArrayOfString(Output, numberoflines); ClosePipeInfo(pipeSpawnOut); ClosePipeInfo(pipeSpawnErr); PutLhsVar(); return 0; }
/*--------------------------------------------------------------------------*/ BOOL getversionmodule(wchar_t* _pwstModule, int *sci_version_major, int *sci_version_minor, int *sci_version_maintenance, wchar_t* _pwstSciVersionString, int *sci_version_revision) { BOOL bOK = FALSE; if (with_module(_pwstModule)) { char* filename_VERSION_module = NULL; char* pstModule = wide_string_to_UTF8(_pwstModule); char* SciPath = NULL; int len = 0; SciPath = getSCI(); len = (int)strlen(FORMATVERSIONFILENAME) + (int)strlen(SciPath) + (int)strlen(pstModule) + 1; filename_VERSION_module = (char*)MALLOC(sizeof(char) * len); sprintf(filename_VERSION_module, FORMATVERSIONFILENAME, SciPath, pstModule); if (SciPath) { FREE(SciPath); SciPath = NULL; } if (FileExist(filename_VERSION_module)) { char *encoding = GetXmlFileEncoding(filename_VERSION_module); /* Don't care about line return / empty line */ xmlKeepBlanksDefault(0); /* check if the XML file has been encoded with utf8 (unicode) or not */ if ( stricmp("utf-8", encoding) == 0) { xmlDocPtr doc = NULL; xmlXPathContextPtr xpathCtxt = NULL; xmlXPathObjectPtr xpathObj = NULL; int version_major = 0; int version_minor = 0; int version_maintenance = 0; int version_revision = 0; wchar_t *pwstSciVersionString = 0; { BOOL bConvert = FALSE; char *shortfilename_VERSION_module = getshortpathname(filename_VERSION_module, &bConvert); if (shortfilename_VERSION_module) { doc = xmlParseFile (shortfilename_VERSION_module); FREE(shortfilename_VERSION_module); shortfilename_VERSION_module = NULL; } } if (doc == NULL) { fprintf(stderr, _("Error: Could not parse file %s\n"), filename_VERSION_module); return FALSE; } xpathCtxt = xmlXPathNewContext(doc); xpathObj = xmlXPathEval((const xmlChar*)"//MODULE_VERSION/VERSION", xpathCtxt); if (xpathObj && xpathObj->nodesetval->nodeMax) { xmlAttrPtr attrib = xpathObj->nodesetval->nodeTab[0]->properties; while (attrib != NULL) { if (xmlStrEqual (attrib->name, (const xmlChar*) "major")) { /* we found <major> */ const char *str = (const char*)attrib->children->content; version_major = atoi(str); } else if (xmlStrEqual (attrib->name, (const xmlChar*)"minor")) { /* we found <minor> */ const char *str = (const char*)attrib->children->content; version_minor = atoi(str); } else if (xmlStrEqual (attrib->name, (const xmlChar*)"maintenance")) { /* we found <maintenance> */ const char *str = (const char*)attrib->children->content; version_maintenance = atoi(str); } else if (xmlStrEqual (attrib->name, (const xmlChar*)"revision")) { /* we found <revision> */ const char *str = (const char*)attrib->children->content; version_revision = atoi(str); } else if (xmlStrEqual (attrib->name, (const xmlChar*)"string")) { /* we found <string> */ const char *str = (const char*)attrib->children->content; pwstSciVersionString = to_wide_string(str); } attrib = attrib->next; } *sci_version_major = version_major; *sci_version_minor = version_minor; *sci_version_maintenance = version_maintenance; *sci_version_revision = version_revision; wcscpy(_pwstSciVersionString, pwstSciVersionString); if (pwstSciVersionString) { FREE(pwstSciVersionString); pwstSciVersionString = NULL; } } else { fprintf(stderr, _("Error: Not a valid version file %s (should start with <MODULE_VERSION> and contain <VERSION major='' minor='' maintenance='' revision='' string=''>)\n"), filename_VERSION_module); return FALSE; } if (xpathObj) { xmlXPathFreeObject(xpathObj); } if (xpathCtxt) { xmlXPathFreeContext(xpathCtxt); } xmlFreeDoc (doc); } else { fprintf(stderr, _("Error: Not a valid version file %s (encoding not 'utf-8') Encoding '%s' found\n"), filename_VERSION_module, encoding); } if (encoding) { FREE(encoding); encoding = NULL; } bOK = TRUE; } else { // version.xml does not exist but module exists then we returns scilab version *sci_version_major = SCI_VERSION_MAJOR; *sci_version_minor = SCI_VERSION_MINOR; *sci_version_maintenance = SCI_VERSION_MAINTENANCE; *sci_version_revision = SCI_VERSION_TIMESTAMP; wcscpy(_pwstSciVersionString, L""); bOK = TRUE; } if (filename_VERSION_module) { FREE(filename_VERSION_module); filename_VERSION_module = NULL; } } return bOK; }