/*--------------------------------------------------------------------------*/ 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; }
/*--------------------------------------------------------------------------*/ int sci_javaclasspath(char *fname, unsigned long fname_len) { int *piAddressVarOne = NULL; int iType = 0; SciErr sciErr; Rhs = Max(Rhs, 0); CheckRhs(0, 1); CheckLhs(0, 1); if (Rhs == 0) { int nbRow = 0; int nbCol = 1; char **Strings = NULL; Strings = getClasspath(&nbRow); createMatrixOfString(pvApiCtx, Rhs + 1, nbRow, nbCol, Strings); LhsVar(1) = Rhs + 1; PutLhsVar(); freeArrayOfString(Strings, nbRow * nbCol); } else { 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, &iType); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } if ( iType == sci_strings ) { char **pStVarOne = NULL; int *lenStVarOne = NULL; static int n1 = 0, m1 = 0; int i = 0; /* get dimensions */ sciErr = getMatrixOfString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, pStVarOne); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } lenStVarOne = (int*)MALLOC(sizeof(int) * (m1 * n1)); if (lenStVarOne == NULL) { Scierror(999, _("%s: No more memory.\n"), fname); return 0; } /* get lengths */ sciErr = getMatrixOfString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, pStVarOne); if (sciErr.iErr) { if (lenStVarOne) { FREE(lenStVarOne); lenStVarOne = NULL; } printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } pStVarOne = (char **)MALLOC(sizeof(char*) * (m1 * n1)); if (pStVarOne == NULL) { if (lenStVarOne) { FREE(lenStVarOne); lenStVarOne = NULL; } Scierror(999, _("%s: No more memory.\n"), fname); return 0; } for (i = 0; i < m1 * n1; i++) { pStVarOne[i] = (char*)MALLOC(sizeof(char*) * (lenStVarOne[i] + 1)); } /* get strings */ sciErr = getMatrixOfString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, pStVarOne); if (sciErr.iErr) { freeArrayOfString(pStVarOne, m1 * n1); if (lenStVarOne) { FREE(lenStVarOne); lenStVarOne = NULL; } printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } for (i = 0; i < m1 * n1 ; i++) { if (!addToClasspath(pStVarOne[i], STARTUP)) { Scierror(999, _("%s: Could not add URL to system classloader : %s.\n"), fname, pStVarOne[i]); freeArrayOfString(pStVarOne, m1 * n1); return 0; } } LhsVar(1) = 0; PutLhsVar(); freeArrayOfString(pStVarOne, m1 * n1); } else { Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, 1); } } return 0; }