From 297216e5d05cae232b40e9ad32545321dc62abeb Mon Sep 17 00:00:00 2001 From: Allan Cornet Date: Thu, 5 Jun 2008 08:30:22 +0000 Subject: [PATCH] update for [a,b] = getversion() modelicac is searched in PATH environment variable --- scilab/modules/core/src/c/inisci-c.c | 25 ++--- scilab/modules/io/includes/getenvc.h | 10 ++ scilab/modules/io/src/c/Scilab_Windows_Import.def | 10 ++ scilab/modules/io/src/c/getenvc.c | 102 ++++++++++++++++++++- scilab/modules/io/src/c/io.vcproj | 30 +++--- 5 files changed, 142 insertions(+), 35 deletions(-) create mode 100644 scilab/modules/io/src/c/Scilab_Windows_Import.def diff --git a/scilab/modules/core/src/c/inisci-c.c b/scilab/modules/core/src/c/inisci-c.c index bb96644..a3986b3 100644 --- a/scilab/modules/core/src/c/inisci-c.c +++ b/scilab/modules/core/src/c/inisci-c.c @@ -175,23 +175,14 @@ int C2F(gettmpdir)(char *buf,int *nbuf,long int lbuf) /*--------------------------------------------------------------------------*/ BOOL ExistModelicac(void) { - // @ TO DO remove this - // used in getversion (compatibility) - #define FORMAT_SCIBIN_PATH "%s/bin/%s" - BOOL bOK=FALSE; - char *SCIPATH = (char*)getSCIpath(); - char *fullpathModelicac=NULL; - int length_path = strlen(SCIPATH) + - strlen(ModelicacName) + - strlen(FORMAT_SCIBIN_PATH) + 1 ; - - fullpathModelicac=(char*)MALLOC((length_path)*sizeof(char)); - sprintf(fullpathModelicac,FORMAT_SCIBIN_PATH,SCIPATH,ModelicacName); - - bOK = FileExist(fullpathModelicac); - if (fullpathModelicac) FREE(fullpathModelicac); - if (SCIPATH) FREE(SCIPATH); - return bOK; + char *fullpathModelicac = searchEnv( ModelicacName,"PATH"); + if (fullpathModelicac) + { + FREE(fullpathModelicac); + fullpathModelicac = NULL; + return TRUE; + } + return FALSE; } /*--------------------------------------------------------------------------*/ int C2F(withgui)(int *rep) diff --git a/scilab/modules/io/includes/getenvc.h b/scilab/modules/io/includes/getenvc.h index 21abc4b..96809e2 100644 --- a/scilab/modules/io/includes/getenvc.h +++ b/scilab/modules/io/includes/getenvc.h @@ -1,6 +1,7 @@ /* * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab * Copyright (C) 2007 - INRIA - Sylvestre LEDRU + * 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 @@ -24,4 +25,13 @@ */ void C2F(getenvc)(int *ierr,char *var,char *buf,int *buflen,int *iflag); +/** +* Searches for a file using environment paths +* @param[in] filename +* @param[in] environment variable where we search +* @return path found +*/ +char *searchEnv(const char *name,const char *env_var); + + #endif /* __GETENVC_H__ */ diff --git a/scilab/modules/io/src/c/Scilab_Windows_Import.def b/scilab/modules/io/src/c/Scilab_Windows_Import.def new file mode 100644 index 0000000..3a3e9b3 --- /dev/null +++ b/scilab/modules/io/src/c/Scilab_Windows_Import.def @@ -0,0 +1,10 @@ + LIBRARY scilab_windows.dll + + +EXPORTS +; +; scilab_windows +; + strdup_windows +; + diff --git a/scilab/modules/io/src/c/getenvc.c b/scilab/modules/io/src/c/getenvc.c index a3eb031..e1151d0 100644 --- a/scilab/modules/io/src/c/getenvc.c +++ b/scilab/modules/io/src/c/getenvc.c @@ -1,6 +1,7 @@ /* * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab * Copyright (C) 2006 - INRIA + * 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 @@ -10,15 +11,22 @@ * */ +#include +#include /* strlen */ #ifdef _MSC_VER #include /* GetEnvironmentVariable */ -#else - #include /* getenv */ + #include "strdup_windows.h" #endif -#include /* strlen */ +#include "MALLOC.h" #include "getenvc.h" #include "localization.h" #include "sciprint.h" +#include "FileExist.h" +/*--------------------------------------------------------------------------*/ +#ifndef _MSC_VER +static void searchenv_others(const char *filename, const char *varname, + char *pathname); +#endif /*--------------------------------------------------------------------------*/ void C2F(getenvc)(int *ierr,char *var,char *buf,int *buflen,int *iflag) { @@ -49,4 +57,92 @@ void C2F(getenvc)(int *ierr,char *var,char *buf,int *buflen,int *iflag) #endif } /*--------------------------------------------------------------------------*/ +#ifndef _MSC_VER +static void searchenv_others(const char *filename, + const char *varname, + char *pathname) +{ + char *cp = NULL; + + *pathname = '\0'; + + if( filename[0] == DIR_SEPARATOR[0]) + { + strcpy(pathname, filename); + return; + } + + cp = getenv(varname); + if(cp == NULL) + { + /* environment Variable not defined. */ + return; + } + + while(*cp) + { + char *concat = NULL; + *pathname = '\0'; + concat = pathname; + /* skip PATH_SEPARATOR[0] and empty entries */ + while( (*cp) && (*cp == PATH_SEPARATOR[0]) ) + { + cp++; + } + + /* copy path */ + while( (*cp) && (*cp != PATH_SEPARATOR[0]) ) + { + *concat = *cp; + cp++; + concat++; + } + + if ( concat == pathname ) + { + /* filename not found */ + *pathname = '\0'; + return; + } + + if( *(concat-1) != DIR_SEPARATOR[0] ) + { + /* add directory separator */ + *concat = DIR_SEPARATOR[0]; + concat++; + } + + /* concatate path & filename */ + strcpy(concat, filename); + + /* file exists ? */ + if(FileExist(pathname)) + { + // file found + return; + } + } + + /* file not found */ + *pathname = '\0'; +} +#endif +/*--------------------------------------------------------------------------*/ +char *searchEnv(const char *name,const char *env_var) +{ + char *buffer = NULL; + char fullpath[PATH_MAX]; + + strcpy(fullpath,""); + + #if _MSC_VER + _searchenv(name,env_var,fullpath); + #else + searchenv_others(name,env_var,fullpath); + #endif + + if (strlen(fullpath) > 0) buffer = strdup(fullpath); + return buffer; +} +/*--------------------------------------------------------------------------*/ diff --git a/scilab/modules/io/src/c/io.vcproj b/scilab/modules/io/src/c/io.vcproj index 7a00fdd..bee9a18 100644 --- a/scilab/modules/io/src/c/io.vcproj +++ b/scilab/modules/io/src/c/io.vcproj @@ -6,7 +6,7 @@ ProjectGUID="{80C0F142-184B-4E08-A8EE-5E71437CF904}" RootNamespace="io" Keyword="Win32Proj" - + TargetFrameworkVersion="0" >