Example #1
0
/*--------------------------------------------------------------------------*/
static char *GetSciPath(void)
/* force SciPath to Unix format for compatibility (Windows) */
{
    char *PathUnix = NULL;
    char *SciPathTmp = NULL;
    int i = 0;

    SciPathTmp = getSCIpath();

    if (SciPathTmp)
    {
        PathUnix = strdup(SciPathTmp);
        for (i = 0; i < (int)strlen(PathUnix); i++)
        {
            if (PathUnix[i] == '\\')
            {
                PathUnix[i] = '/';
            }
        }
    }
    if (SciPathTmp)
    {
        FREE(SciPathTmp);
        SciPathTmp = NULL;
    }
    return PathUnix;
}
Example #2
0
/*--------------------------------------------------------------------------*/
static char *getModuleXmlFilename(char *modulename)
{
	char *filename_module = NULL;
	
	if (modulename)
	{
		char *SciPath = NULL;
		SciPath = getSCIpath();
		if (SciPath)
		{
			int length_filename_module = 0;

			length_filename_module = (int)strlen(FORMATGATEWAYFILENAME) + 
			                   (int)strlen(SciPath)+((int)strlen(modulename)*2)+3;

			filename_module = (char*)MALLOC((length_filename_module+1)* 
							   sizeof(char));

			if (filename_module)
			{
				sprintf(filename_module,FORMATGATEWAYFILENAME,
					    SciPath,modulename,modulename);

				/* file doesn't exist */
				if ( !FileExist(filename_module) )
				{
					FREE(filename_module);
					filename_module = NULL;
				}
			}
			FREE(SciPath); SciPath = NULL;
		}
	}
	return filename_module;
}
Example #3
0
/*--------------------------------------------------------------------------*/
static char *getModuleXmlFilename(char *modulename)
{
    char *filename_module = NULL;

    if (modulename)
    {
        char *SciPath = NULL;
        SciPath = getSCIpath();
        if (SciPath)
        {
            size_t length_filename_module = 0UL;
            size_t length_filename_module_total;

            length_filename_module = (strlen(FORMATGATEWAYFILENAME)
                                      + strlen(SciPath)
                                      + (strlen(modulename) * 2UL)
                                      + 3UL);
            length_filename_module_total = ((length_filename_module + 1UL)
                                            * sizeof(char));

            filename_module = (char *)MALLOC(length_filename_module_total);

            if (filename_module)
            {
                snprintf(filename_module, length_filename_module_total,
                         FORMATGATEWAYFILENAME,
                         SciPath, modulename, modulename);

                /* file doesn't exist */
                if ( !FileExist(filename_module) )
                {
                    FREE(filename_module);
                    filename_module = NULL;
                }
            }
            FREE(SciPath);
            SciPath = NULL;
        }
    }
    return filename_module;
}
Example #4
0
/*--------------------------------------------------------------------------*/
dynamic_gateway_error_code callDynamicGateway(char *moduleName,
        char *dynLibName,
        char *gw_name,
        DynLibHandle *hlib,
        PROC_GATEWAY *ptrGateway)
{
    if (*hlib == NULL)
    {
#ifdef _MSC_VER
        wchar_t *wcdynLibName = to_wide_string(dynLibName);
        if (wcdynLibName)
        {
            *hlib = LoadDynLibraryW(wcdynLibName);
            FREE(wcdynLibName);
            wcdynLibName = NULL;
        }
        if (*hlib == NULL)
        {
            return DYN_GW_LOAD_LIBRARY_ERROR;
        }
#else

        /* First step, we are considering that we are in the source tree.
         * Therefor, the lib should be in modules/xxx/.libs/
         *
         * Otherwise, dlopen will search in various places (for example, the install specified
         * by --prefix).
         * This leads to serious and unexpected bugs like #8883
         * The original bug report for this issue was the bug #2875
         */
        char *SciPath = getSCIpath();
#define PATHTOMODULE "/modules/"
#ifndef LT_OBJDIR
#define LT_OBJDIR ".libs/"
#endif

        /* Build the full path to the library */
        char *pathToLib = (char*) MALLOC((strlen(SciPath) + strlen(PATHTOMODULE) + strlen(moduleName) + strlen("/") + strlen(LT_OBJDIR) + strlen(dynLibName) + 1) * sizeof(char));
        sprintf(pathToLib, "%s%s%s/%s%s", SciPath, PATHTOMODULE, moduleName, LT_OBJDIR, dynLibName);

        /* Load the library with the Scilab source-tree paths */
        *hlib = LoadDynLibrary(pathToLib);

        if (*hlib == NULL) /* Load of the hardcoded path to the lib failed */
        {

            if (FileExist(pathToLib))
            {
                /* It fails but the file exists */
                char *previousError = GetLastDynLibError();
                if (previousError != NULL)
                {
                    sciprint("A previous error has been detected while loading %s: %s\n", dynLibName, previousError);
                }
            }

            /* Under Linux/Unix, load thanks to dlopen on the system.
             * In the binary, the LD_LIBRARY_PATH is declared in the startup script (ie bin/scilab*)
             * Note that it is not possible to update the LD_LIBRARY_PATH at run time.
             */
            *hlib = LoadDynLibrary(dynLibName);
            if (*hlib == NULL)
            {
                char *previousError = GetLastDynLibError();
                if (previousError != NULL)
                {
                    sciprint("A previous error has been detected while loading %s: %s\n", dynLibName, previousError);
                }
                if (SciPath)
                {
                    FREE(SciPath);
                    SciPath = NULL;
                }
                if (pathToLib)
                {
                    FREE(pathToLib);
                    pathToLib = NULL;
                }
                return DYN_GW_LOAD_LIBRARY_ERROR;
            }
        }
        if (SciPath)
        {
            FREE(SciPath);
            SciPath = NULL;
        }
        if (pathToLib)
        {
            FREE(pathToLib);
            pathToLib = NULL;
        }
#endif
    }

    if (*ptrGateway == NULL)
    {
        *ptrGateway = (PROC_GATEWAY) GetDynLibFuncPtr(*hlib, gw_name);
        if (*ptrGateway == NULL)
        {
            return DYN_GW_PTR_FUNCTION_ERROR ;
        }
    }

    if ( (*hlib) && (*ptrGateway) )
    {
        (*ptrGateway)();
        return DYN_GW_NO_ERROR;
    }

    return DYN_GW_CALL_FUNCTION_ERROR;
}
BOOL InitializeLocalization(void)
{
#ifdef HAVE_LIBINTL_H

    char *SCIpath = getSCIpath();
    char *pathLocales = NULL, *previousPathLocales = NULL;
    char *ret = NULL;

    /* set directory containing message catalogs */
    pathLocales = (char *)MALLOC(sizeof(char) * (strlen(SCIpath) + strlen(PATHLOCALIZATIONFILE) + 1));

    strcpy(pathLocales, SCIpath);
    strcat(pathLocales, PATHLOCALIZATIONFILE);
    if (bindtextdomain(NAMELOCALIZATIONDOMAIN, pathLocales) == NULL || !isdir(pathLocales))
    {
        /* source tree and classic build */
        previousPathLocales = strdup(pathLocales);
        if (pathLocales)
        {
            FREE(pathLocales);
            pathLocales = NULL;
        }

        pathLocales = (char *)MALLOC(sizeof(char) * (strlen(SCIpath) + strlen("/..") + strlen(PATHLOCALIZATIONFILE) + 1));
        strcpy(pathLocales, SCIpath);
        strcat(pathLocales, "/..");
        strcat(pathLocales, PATHLOCALIZATIONFILE);
        if (bindtextdomain(NAMELOCALIZATIONDOMAIN, pathLocales) == NULL || !isdir(pathLocales))
        {
            /* when it is installed on the system for example /usr/share/locale/ */
            fprintf(stderr, "Warning: Localization issue: Error while binding the domain from %s or %s: Switch to the default language (English).\n", pathLocales, previousPathLocales);

            // Set default behaviour
            textdomain(NAMELOCALIZATIONDOMAIN);
            bind_textdomain_codeset (NAMELOCALIZATIONDOMAIN, "UTF-8");
#ifndef _MSC_VER
            setlanguage("");
#else
            /* We look if registry value LANGUAGE exists */
            /* If not exists the "" means that we will try to use the language of the system.*/
            {
                char *loadLanguage = getLanguagePreferences();
                setlanguage(loadLanguage);
                if (loadLanguage)
                {
                    FREE(loadLanguage);
                    loadLanguage = NULL;
                }
            }
#endif

            if (previousPathLocales)
            {
                FREE(previousPathLocales);
                previousPathLocales = NULL;
            }
            if (pathLocales)
            {
                FREE(pathLocales);
                pathLocales = NULL;
            }
            if (SCIpath)
            {
                FREE(SCIpath);
                SCIpath = NULL;
            }
            return FALSE;
        }
        if (previousPathLocales)
        {
            FREE(previousPathLocales);
            previousPathLocales = NULL;
        }
        if (pathLocales)
        {
            FREE(pathLocales);
            pathLocales = NULL;
        }
        if (SCIpath)
        {
            FREE(SCIpath);
            SCIpath = NULL;
        }

    }

    /* set domain for future gettext() calls */
    ret = textdomain(NAMELOCALIZATIONDOMAIN);
    if (ret == NULL)
    {
        fprintf(stderr, "Localization: Error while declaring the text domain %s\n", NAMELOCALIZATIONDOMAIN);
        FREE(pathLocales);
        return FALSE;
    }
    bind_textdomain_codeset (NAMELOCALIZATIONDOMAIN, "UTF-8"); /*such that gettext and dgettext return UTF8 string*/
#ifndef _MSC_VER
    /* Here, the "" means that we will try to use the language of the system
     * first. If it doesn't work, we switch back to default (English) */
    setlanguage("");
#else
    /* We look if registry value LANGUAGE exists */
    /* If not exists the "" means that we will try to use the language of the system.*/
    {
        char *loadLanguage = getLanguagePreferences();
        setlanguage(loadLanguage);
        if (loadLanguage)
        {
            FREE(loadLanguage);
            loadLanguage = NULL;
        }
    }
#endif

    if (previousPathLocales)
    {
        FREE(previousPathLocales);
    }
    if (pathLocales)
    {
        FREE(pathLocales);
    }
    if (SCIpath)
    {
        FREE(SCIpath);
    }

    return TRUE;
#else
    fprintf(stderr, "Localization: setlocale didn't exist on the computer used to compile Scilab ! This is abnormal ! No localization will be working for this distribution of Scilab.\n");
    return FALSE;
#endif
}
Example #6
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;
}