Ejemplo n.º 1
0
/*--------------------------------------------------------------------------*/
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;
}
Ejemplo n.º 2
0
/*--------------------------------------------------------------------------*/
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;
}
Ejemplo n.º 3
0
/*--------------------------------------------------------------------------*/
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;
}
Ejemplo n.º 4
0
int parseLibFile(const std::wstring& _wstXML, MacroInfoList& info, std::wstring& libname)
{
    info.clear();

    char* pstFile = wide_string_to_UTF8(_wstXML.data());

    if (FileExist(pstFile) == FALSE)
    {
        FREE(pstFile);
        return 1;
    }
    std::string s(_wstXML.begin(),_wstXML.end());
    std::ifstream file(s);
    if (file)
    {
        const std::string XMLDecl("<?xml");
        std::string readXMLDecl;
        readXMLDecl.resize(XMLDecl.length(),' ');//reserve space
        file.read(&*readXMLDecl.begin(),XMLDecl.length());
        if (XMLDecl != readXMLDecl)
        {
          return 4;
        }
    }

    char *encoding = GetXmlFileEncoding(pstFile);

    /* 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))
    {
        FREE(pstFile);
        free(encoding);
        return 3;
    }

    xmlDocPtr doc;
    xmlXPathContextPtr xpathCtxt = NULL;
    xmlXPathObjectPtr xpathObj = NULL;
    wchar_t* pstName = NULL;
    wchar_t* pstLibName = NULL;
    wchar_t* pstFileName = NULL;
    wchar_t* pstMd5 = NULL;

    free(encoding);

    doc = xmlParseFile(pstFile);

    if (doc == NULL)
    {
        FREE(pstFile);
        return 3;
    }

    FREE(pstFile);

    xpathCtxt = xmlXPathNewContext(doc);
    xpathObj = xmlXPathEval((const xmlChar*)"//scilablib", xpathCtxt);
    if (xpathObj && xpathObj->nodesetval->nodeMax)
    {
        xmlAttrPtr attrib = xpathObj->nodesetval->nodeTab[0]->properties;
        if (xmlStrEqual(attrib->name, (const xmlChar*)"name"))
        {
            /* we found the tag name */
            const char *str = (const char*)attrib->children->content;
            pstLibName = to_wide_string(str);
            libname = pstLibName;
            FREE(pstLibName);
            xmlXPathFreeObject(xpathObj);
        }
        else
        {
            if (xpathCtxt)
            {
                xmlXPathFreeContext(xpathCtxt);
            }
            xmlXPathFreeObject(xpathObj);
            return 1;
        }
    }

    xpathObj = xmlXPathEval((const xmlChar*)"//scilablib/macro", xpathCtxt);
    if (xpathObj && xpathObj->nodesetval->nodeMax)
    {
        /* the Xpath has been understood and there are node */
        for (int i = 0; i < xpathObj->nodesetval->nodeNr; i++)
        {
            xmlAttrPtr attrib = xpathObj->nodesetval->nodeTab[i]->properties;
            /* Get the properties of <module>  */
            while (attrib != NULL)
            {
                /* loop until when have read all the attributes */
                if (xmlStrEqual(attrib->name, (const xmlChar*)"name"))
                {
                    /* we found the tag name */
                    const char *str = (const char*)attrib->children->content;
                    pstName = to_wide_string(str);
                }
                else if (xmlStrEqual(attrib->name, (const xmlChar*)"file"))
                {
                    /* we found the tag activate */
                    const char *str = (const char*)attrib->children->content;
                    pstFileName = to_wide_string(str);
                }
                else if (xmlStrEqual(attrib->name, (const xmlChar*)"md5"))
                {
                    /* we found the tag activate */
                    const char *str = (const char*)attrib->children->content;
                    pstMd5 = to_wide_string(str);
                }
                attrib = attrib->next;
            }

            if (pstName && pstFileName && pstMd5)
            {
                info[pstFileName] = MacroInfo(pstName, pstFileName, pstMd5);
            }

            if (pstName)
            {
                FREE(pstName);
                pstName = NULL;
            }

            if (pstFileName)
            {
                FREE(pstFileName);
                pstFileName = NULL;
            }

            if (pstMd5)
            {
                FREE(pstMd5);
                pstMd5 = NULL;
            }
        }
    }

    if (xpathObj)
    {
        xmlXPathFreeObject(xpathObj);
    }
    if (xpathCtxt)
    {
        xmlXPathFreeContext(xpathCtxt);
    }

    xmlFreeDoc(doc);
    return 0;
}
Ejemplo n.º 5
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;
}
Ejemplo n.º 6
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;
}