/* * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab * Copyright (C) 2008 - INRIA - Allan CORNET * * This file must be used under the terms of the CeCILL. * This source file is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt * */ /*--------------------------------------------------------------------------*/ #include #include #include #include "getJvmOptions.h" #include "GetXmlFileEncoding.h" #include "MALLOC.h" #include "localization.h" #include "machine.h" #include "stricmp.h" #include "FileExist.h" #ifdef _MSC_VER #include "strdup_windows.h" #endif #include "strsubst.h" #include "getos.h" #include "getshortpathname.h" #include "BOOL.h" #include "getScilabPreference.h" static char * getJavaHeapSize(void); /*--------------------------------------------------------------------------*/ 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); if (encoding) { 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 heapSizeUsed = 0; char *heapSize = getJavaHeapSize(); for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) { xmlAttrPtr attrib = xpathObj->nodesetval->nodeTab[i]->properties; /* Get the properties of