=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2000/parse/load.c,v retrieving revision 1.17 retrieving revision 1.28 diff -u -p -r1.17 -r1.28 --- OpenXM_contrib2/asir2000/parse/load.c 2005/03/24 23:40:50 1.17 +++ OpenXM_contrib2/asir2000/parse/load.c 2015/08/06 10:01:53 1.28 @@ -45,12 +45,12 @@ * 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.16 2005/03/24 22:54:22 takayama Exp $ + * $OpenXM: OpenXM_contrib2/asir2000/parse/load.c,v 1.27 2014/05/12 02:35:36 ohara Exp $ */ #include "ca.h" #include "parse.h" -#if defined(VISUAL) +#if defined(VISUAL) || defined(__MINGW32__) || defined(__MINGW64__) #include #include #include @@ -70,18 +70,19 @@ #include #endif -#if defined(VISUAL) +#if defined(VISUAL) || defined(__MINGW32__) || defined(__MINGW64__) #include #endif #ifdef MALLOC #undef MALLOC -#define MALLOC(x) GC_malloc((x)+4) +#define MALLOC(x) Risa_GC_malloc((x)+4) #endif char **ASIRLOADPATH; +int ASIRLOADPATH_LEN; -#if defined(VISUAL) +#if defined(VISUAL) || defined(__MINGW32__) || defined(__MINGW64__) #define ENVDELIM ';' #define MORE "more < " #else @@ -102,8 +103,8 @@ 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 read_exec_file; extern int main_parser; extern JMP_BUF exec_env; @@ -125,7 +126,7 @@ char *search_executable(char *name) if ( len+nlen+1 >= BUFSIZ ) continue; sprintf(path,"%s/%s",dir,name); if ( !stat(path,&buf) && !(buf.st_mode & S_IFDIR) -#if !defined(VISUAL) +#if !defined(VISUAL) && !defined(__MINGW32__) && !defined(__MINGW64__) && !access(path,X_OK) #endif ) { @@ -144,38 +145,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) || defined(__MINGW32__) || defined(__MINGW64__) + 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); -#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) || defined(__MINGW32__) || defined(__MINGW64__) + if ( e = getenv("APPDATA") ) { + asir_private_dir = (char *)malloc(strlen(e)+strlen("/OpenXM/lib/asir-contrib")+1); + sprintf(asir_private_dir,"%s/OpenXM/lib/asir-contrib",e); + } +#endif + if ( !(asir_pager = getenv("PAGER")) ) { japanese = 0; if ( (e = getenv("LANGUAGE")) && @@ -200,7 +209,8 @@ void env_init() { if ( !p ) break; } - i += 4; + i += 5; + ASIRLOADPATH_LEN=i; ASIRLOADPATH=(char **)MALLOC(sizeof(char *)*i); for ( l = 0; l= 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 +263,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 +272,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 '/' @@ -281,7 +281,7 @@ void loadasirfile(char *name0) FILE *in; INFILE t; extern char cppname[]; -#if defined(VISUAL) +#if defined(VISUAL) || defined(__MINGW32__) || defined(__MINGW64__) char ibuf1[BUFSIZ],ibuf2[BUFSIZ]; int ac; char *av[BUFSIZ]; @@ -384,33 +384,11 @@ void loadasirfile(char *name0) void execasirfile(char *name) { loadasirfile(name); - read_exec_file = 1; - read_eval_loop(); - read_exec_file = 0; -} - -void load_and_execfile(char *name) -{ - FILE *fp; - INFILE save_asir_infile; - int save_prresult; - extern prresult; - - savepvs(); - save_asir_infile = asir_infile; - save_prresult = prresult; - fp = fopen(name,"rb"); - input_init(fp,name); - if ( !SETJMP(exec_env) ) { - /* XXX : information for asir_teriminate() */ - read_exec_file = 2; + if ( !SETJMP(asir_infile->jmpbuf) ) { + asir_infile->ready_for_longjmp = 1; read_eval_loop(); - read_exec_file = 0; } - fclose(fp); - restorepvs(); - asir_infile = save_asir_infile; - prresult = save_prresult; + closecurrentinput(); } static NODE objfile = 0;