=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2000/parse/load.c,v retrieving revision 1.20 retrieving revision 1.25 diff -u -p -r1.20 -r1.25 --- OpenXM_contrib2/asir2000/parse/load.c 2006/02/08 02:11:19 1.20 +++ OpenXM_contrib2/asir2000/parse/load.c 2014/04/02 22:08:29 1.25 @@ -45,7 +45,7 @@ * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. * - * $OpenXM: OpenXM_contrib2/asir2000/parse/load.c,v 1.19 2006/02/05 08:28:04 noro Exp $ + * $OpenXM: OpenXM_contrib2/asir2000/parse/load.c,v 1.24 2014/03/30 10:48:16 ohara Exp $ */ #include "ca.h" #include "parse.h" @@ -76,7 +76,7 @@ #ifdef MALLOC #undef MALLOC -#define MALLOC(x) GC_malloc((x)+4) +#define MALLOC(x) Risa_GC_malloc((x)+4) #endif char **ASIRLOADPATH; @@ -102,6 +102,7 @@ char *search_executable(char *name); extern char *asir_libdir; extern char *asir_contrib_dir; +extern char *asir_private_dir; extern char *asir_pager; extern int main_parser; extern JMP_BUF exec_env; @@ -143,39 +144,46 @@ void env_init() { char *getenv(); char *oxhome; char rootname[BUFSIZ]; + size_t len; + if ( oxhome = getenv("OpenXM_HOME") ) { + len = strlen(oxhome); + }else { +#if defined(VISUAL) + get_rootdir(rootname,sizeof(rootname)); + len = strlen(rootname); + oxhome = rootname; +#endif + } + if ( !(asir_libdir = getenv("ASIR_LIBDIR")) ) { - if ( oxhome = getenv("OpenXM_HOME") ) { - asir_libdir = (char *)malloc(strlen(oxhome)+strlen("/lib/asir")+1); + if ( oxhome ) { + asir_libdir = (char *)malloc(len+strlen("/lib/asir")+1); sprintf(asir_libdir,"%s/lib/asir",oxhome); } else { -#if defined(VISUAL) - get_rootdir(rootname,sizeof(rootname)); - asir_libdir = (char *)malloc(strlen(rootname)+strlen("/lib")+1); - sprintf(asir_libdir,"%s/lib",rootname); -#else asir_libdir = (char *)malloc(strlen(ASIR_LIBDIR)+1); strcpy(asir_libdir,ASIR_LIBDIR); -#endif } } if ( !(asir_contrib_dir = getenv("ASIR_CONTRIB_DIR")) ) { - if ( oxhome = getenv("OpenXM_HOME") ) { - asir_contrib_dir = (char *)malloc(strlen(oxhome)+strlen("/lib/asir-contrib")+1); + if ( oxhome ) { + asir_contrib_dir = (char *)malloc(len+strlen("/lib/asir-contrib")+1); sprintf(asir_contrib_dir,"%s/lib/asir-contrib",oxhome); } else { -#if defined(VISUAL) - get_rootdir(rootname,sizeof(rootname)); - asir_contrib_dir = (char *)malloc(strlen(rootname)+strlen("/lib-asir-contrib")+1); - sprintf(asir_contrib_dir,"%s/lib-asir-contrib",rootname); -#else asir_contrib_dir = (char *)malloc(strlen(ASIR_CONTRIB_DIR)+1); strcpy(asir_contrib_dir,ASIR_CONTRIB_DIR); -#endif } } + asir_private_dir = NULL; +#if defined(VISUAL) + if ( e = getenv("APPDATA") ) { + asir_private_dir = (char *)malloc(strlen(e)+strlen("/asir/lib/asir-contrib")+1); + sprintf(asir_private_dir,"%s/asir/lib/asir-contrib",e); + } +#endif + if ( !(asir_pager = getenv("PAGER")) ) { japanese = 0; if ( (e = getenv("LANGUAGE")) && @@ -219,24 +227,29 @@ void env_init() { } for ( i = 0; ASIRLOADPATH[i]; i++ ); + if (asir_private_dir) ASIRLOADPATH[i++] = asir_private_dir; if (asir_contrib_dir) ASIRLOADPATH[i++] = asir_contrib_dir; if (asir_libdir) ASIRLOADPATH[i++] = asir_libdir; ASIRLOADPATH[i] = NULL; } +#if defined(VISUAL) +#define R_OK 4 +#endif + void searchasirpath(char *name,char **pathp) { char **p; char *q; - int l; -#if !defined(VISUAL) + size_t l; + int ret; struct stat sbuf; if ( (name[0] == '/') || ( name[0] == '.') || strchr(name,':') || !ASIRLOADPATH[0] ) { if ( access(name,R_OK) >= 0 ) { - stat(name,&sbuf); - if ( (sbuf.st_mode & S_IFMT) != S_IFDIR ) + ret = stat(name,&sbuf); + if ( ret == 0 && (sbuf.st_mode & S_IFMT) != S_IFDIR ) *pathp = name; else *pathp = 0; @@ -247,8 +260,8 @@ void searchasirpath(char *name,char **pathp) l = strlen(*p)+strlen(name)+2; q = (char *)ALLOCA(l); sprintf(q,"%s/%s",*p,name); if ( access(q,R_OK) >= 0 ) { - stat(q,&sbuf); - if ( (sbuf.st_mode & S_IFMT) != S_IFDIR ) { + ret = stat(q,&sbuf); + if ( ret == 0 && (sbuf.st_mode & S_IFMT) != S_IFDIR ) { *pathp = (char *)MALLOC(l); strcpy(*pathp,q); return; } @@ -256,22 +269,6 @@ void searchasirpath(char *name,char **pathp) } *pathp = 0; } -#else - if ( (name[0] == '/') || ( name[0] == '.') || strchr(name,':') - || !ASIRLOADPATH[0] ) - *pathp = name; - else { - for ( p = ASIRLOADPATH; *p; p++ ) { - l = strlen(*p)+strlen(name)+2; - q = (char *)ALLOCA(l); sprintf(q,"%s/%s",*p,name); - if ( access(q,04) >= 0 ) { - *pathp = (char *)MALLOC(l); strcpy(*pathp,q); - return; - } - } - *pathp = 0; - } -#endif } #define DELIM '/'