=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2000/parse/load.c,v retrieving revision 1.8 retrieving revision 1.17 diff -u -p -r1.8 -r1.17 --- OpenXM_contrib2/asir2000/parse/load.c 2001/10/09 01:36:24 1.8 +++ OpenXM_contrib2/asir2000/parse/load.c 2005/03/24 23:40:50 1.17 @@ -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.7 2001/08/20 09:14:14 noro Exp $ + * $OpenXM: OpenXM_contrib2/asir2000/parse/load.c,v 1.16 2005/03/24 22:54:22 takayama Exp $ */ #include "ca.h" #include "parse.h" @@ -79,7 +79,7 @@ #define MALLOC(x) GC_malloc((x)+4) #endif -char *ASIRLOADPATH[32]; +char **ASIRLOADPATH; #if defined(VISUAL) #define ENVDELIM ';' @@ -90,21 +90,57 @@ char *ASIRLOADPATH[32]; #endif #ifndef ASIR_LIBDIR -#define ASIR_LIBDIR "." +#define ASIR_LIBDIR "/usr/local/lib/asir" #endif +#ifndef ASIR_CONTRIB_DIR +#define ASIR_CONTRIB_DIR "/usr/local/lib/asir-contrib" +#endif char *getenv(); void Pget_rootdir(); +char *search_executable(char *name); extern char *asir_libdir; +extern char *asir_contrib_dir; extern char *asir_pager; extern int read_exec_file; extern int main_parser; -extern jmp_buf exec_env; +extern JMP_BUF exec_env; +char *search_executable(char *name) +{ + char *c,*s,*ret; + int len,nlen; + char dir[BUFSIZ],path[BUFSIZ]; + struct stat buf; + + nlen = strlen(name); + for ( s = (char *)getenv("PATH"); s; ) { + c = (char *)index(s,':'); + len = c ? c-s : strlen(s); + if ( len >= BUFSIZ ) continue; + strncpy(dir,s,len); dir[len] = 0; + if ( c ) s = c+1; + else s = 0; + if ( len+nlen+1 >= BUFSIZ ) continue; + sprintf(path,"%s/%s",dir,name); + if ( !stat(path,&buf) && !(buf.st_mode & S_IFDIR) +#if !defined(VISUAL) + && !access(path,X_OK) +#endif + ) { + len = strlen(path)+1; + ret = (char *)MALLOC(len); + strcpy(ret,path); + return ret; + } + } + return 0; +} + void env_init() { char *e,*p,*q; - int i,l; + int i,l,japanese; char *getenv(); char *oxhome; char rootname[BUFSIZ]; @@ -117,20 +153,59 @@ void env_init() { #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); + 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 + } + } + if ( !(asir_pager = getenv("PAGER")) ) { - asir_pager = (char *)malloc(strlen(MORE)+1); - strcpy(asir_pager,MORE); + japanese = 0; + if ( (e = getenv("LANGUAGE")) && + (!strncmp(e,"japan",5) || !strncmp(e,"ja_JP",5)) ) japanese = 1; + else if ( (e = getenv("LC_ALL")) && + (!strncmp(e,"japan",5) || !strncmp(e,"ja_JP",5)) ) japanese = 1; + else if ( (e = getenv("LC_CTYPE")) && + (!strncmp(e,"japan",5) || !strncmp(e,"ja_JP",5)) ) japanese = 1; + else if ( (e = getenv("LANG")) && + (!strncmp(e,"japan",5) || !strncmp(e,"ja_JP",5)) ) japanese = 1; + if ( japanese ) + asir_pager = search_executable("jless"); + if ( !asir_pager ) { + /* default: more */ + asir_pager = (char *)malloc(strlen(MORE)+1); + strcpy(asir_pager,MORE); + } } - if ( e = getenv("ASIRLOADPATH" ) ) + if ( e = getenv("ASIRLOADPATH" ) ) { for ( i = 0; ; i++, e = p+1 ) { p = (char *)index(e,ENVDELIM); + if ( !p ) + break; + } + i += 4; + ASIRLOADPATH=(char **)MALLOC(sizeof(char *)*i); + for ( l = 0; l