version 1.11, 2004/03/02 08:28:49 |
version 1.29, 2015/08/14 13:51:56 |
|
|
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* |
* |
* $OpenXM: OpenXM_contrib2/asir2000/parse/load.c,v 1.10 2004/03/02 07:44:02 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/parse/load.c,v 1.28 2015/08/06 10:01:53 fujimoto Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
#include "parse.h" |
#include "parse.h" |
|
|
#if defined(VISUAL) |
#if defined(VISUAL) || defined(__MINGW32__) |
#include <string.h> |
#include <string.h> |
#include <fcntl.h> |
#include <fcntl.h> |
#include <sys/stat.h> |
#include <sys/stat.h> |
|
|
#include <unistd.h> |
#include <unistd.h> |
#endif |
#endif |
|
|
#if defined(VISUAL) |
#if defined(VISUAL) || defined(__MINGW32__) |
#include <io.h> |
#include <io.h> |
#endif |
#endif |
|
|
#ifdef MALLOC |
#ifdef MALLOC |
#undef MALLOC |
#undef MALLOC |
#define MALLOC(x) GC_malloc((x)+4) |
#define MALLOC(x) Risa_GC_malloc((x)+4) |
#endif |
#endif |
|
|
char *ASIRLOADPATH[32]; |
char **ASIRLOADPATH; |
|
int ASIRLOADPATH_LEN; |
|
|
#if defined(VISUAL) |
#if defined(VISUAL) || defined(__MINGW32__) |
#define ENVDELIM ';' |
#define ENVDELIM ';' |
#define MORE "more < " |
#define MORE "more < " |
#else |
#else |
Line 90 char *ASIRLOADPATH[32]; |
|
Line 91 char *ASIRLOADPATH[32]; |
|
#endif |
#endif |
|
|
#ifndef ASIR_LIBDIR |
#ifndef ASIR_LIBDIR |
#define ASIR_LIBDIR "." |
#define ASIR_LIBDIR "/usr/local/lib/asir" |
#endif |
#endif |
|
#ifndef ASIR_CONTRIB_DIR |
|
#define ASIR_CONTRIB_DIR "/usr/local/lib/asir-contrib" |
|
#endif |
|
|
char *getenv(); |
char *getenv(); |
void Pget_rootdir(); |
void Pget_rootdir(); |
char *search_executable(char *name); |
char *search_executable(char *name); |
|
|
extern char *asir_libdir; |
extern char *asir_libdir; |
|
extern char *asir_contrib_dir; |
|
extern char *asir_private_dir; |
extern char *asir_pager; |
extern char *asir_pager; |
extern int read_exec_file; |
|
extern int main_parser; |
extern int main_parser; |
extern JMP_BUF exec_env; |
extern JMP_BUF exec_env; |
|
|
Line 111 char *search_executable(char *name) |
|
Line 116 char *search_executable(char *name) |
|
struct stat buf; |
struct stat buf; |
|
|
nlen = strlen(name); |
nlen = strlen(name); |
for ( s = (char *)getenv("PATH"); *s; ) { |
for ( s = (char *)getenv("PATH"); s; ) { |
c = (char *)index(s,':'); |
c = (char *)index(s,':'); |
len = c ? c-s : strlen(dir); |
len = c ? c-s : strlen(s); |
if ( len >= BUFSIZ ) continue; |
if ( len >= BUFSIZ ) continue; |
strncpy(dir,s,len); s = c+1; dir[len] = 0; |
strncpy(dir,s,len); dir[len] = 0; |
|
if ( c ) s = c+1; |
|
else s = 0; |
if ( len+nlen+1 >= BUFSIZ ) continue; |
if ( len+nlen+1 >= BUFSIZ ) continue; |
sprintf(path,"%s/%s",dir,name); |
sprintf(path,"%s/%s",dir,name); |
if ( !stat(path,&buf) && !(buf.st_mode & S_IFDIR) |
if ( !stat(path,&buf) && !(buf.st_mode & S_IFDIR) |
&& !access(path,X_OK) ) { |
#if !defined(VISUAL) && !defined(__MINGW32__) |
|
&& !access(path,X_OK) |
|
#endif |
|
) { |
len = strlen(path)+1; |
len = strlen(path)+1; |
ret = (char *)MALLOC(len); |
ret = (char *)MALLOC(len); |
strcpy(ret,path); |
strcpy(ret,path); |
Line 135 void env_init() { |
|
Line 145 void env_init() { |
|
char *getenv(); |
char *getenv(); |
char *oxhome; |
char *oxhome; |
char rootname[BUFSIZ]; |
char rootname[BUFSIZ]; |
|
size_t len; |
|
|
|
if ( oxhome = getenv("OpenXM_HOME") ) { |
|
len = strlen(oxhome); |
|
}else { |
|
#if defined(VISUAL) || defined(__MINGW32__) |
|
get_rootdir(rootname,sizeof(rootname)); |
|
len = strlen(rootname); |
|
oxhome = rootname; |
|
#endif |
|
} |
|
|
if ( !(asir_libdir = getenv("ASIR_LIBDIR")) ) { |
if ( !(asir_libdir = getenv("ASIR_LIBDIR")) ) { |
if ( oxhome = getenv("OpenXM_HOME") ) { |
if ( oxhome ) { |
asir_libdir = (char *)malloc(strlen(oxhome)+strlen("/lib/asir")+1); |
asir_libdir = (char *)malloc(len+strlen("/lib/asir")+1); |
sprintf(asir_libdir,"%s/lib/asir",oxhome); |
sprintf(asir_libdir,"%s/lib/asir",oxhome); |
} else { |
} 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); |
asir_libdir = (char *)malloc(strlen(ASIR_LIBDIR)+1); |
strcpy(asir_libdir,ASIR_LIBDIR); |
strcpy(asir_libdir,ASIR_LIBDIR); |
#endif |
|
} |
} |
} |
} |
|
|
|
if ( !(asir_contrib_dir = getenv("ASIR_CONTRIB_DIR")) ) { |
|
if ( oxhome ) { |
|
asir_contrib_dir = (char *)malloc(len+strlen("/lib/asir-contrib")+1); |
|
sprintf(asir_contrib_dir,"%s/lib/asir-contrib",oxhome); |
|
} else { |
|
asir_contrib_dir = (char *)malloc(strlen(ASIR_CONTRIB_DIR)+1); |
|
strcpy(asir_contrib_dir,ASIR_CONTRIB_DIR); |
|
} |
|
} |
|
|
|
asir_private_dir = NULL; |
|
#if defined(VISUAL) || defined(__MINGW32__) |
|
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")) ) { |
if ( !(asir_pager = getenv("PAGER")) ) { |
japanese = 0; |
japanese = 0; |
if ( (e = getenv("LANGUAGE")) && |
if ( (e = getenv("LANGUAGE")) && |
Line 169 void env_init() { |
|
Line 203 void env_init() { |
|
strcpy(asir_pager,MORE); |
strcpy(asir_pager,MORE); |
} |
} |
} |
} |
if ( e = getenv("ASIRLOADPATH" ) ) |
if ( e = getenv("ASIRLOADPATH" ) ) { |
for ( i = 0; ; i++, e = p+1 ) { |
for ( i = 0; ; i++, e = p+1 ) { |
p = (char *)index(e,ENVDELIM); |
p = (char *)index(e,ENVDELIM); |
|
if ( !p ) |
|
break; |
|
} |
|
i += 5; |
|
ASIRLOADPATH_LEN=i; |
|
ASIRLOADPATH=(char **)MALLOC(sizeof(char *)*i); |
|
for ( l = 0; l<i; l++) ASIRLOADPATH[l] = NULL; |
|
e = getenv("ASIRLOADPATH"); |
|
for ( i = 0; ; i++, e = p+1 ) { |
|
p = (char *)index(e,ENVDELIM); |
l = p ? p-e : strlen(e); q = (char *)MALLOC(l+1); |
l = p ? p-e : strlen(e); q = (char *)MALLOC(l+1); |
if ( l ) { |
if ( l ) { |
strncpy(q,e,l); q[l] = 0; ASIRLOADPATH[i] = q; |
strncpy(q,e,l); q[l] = 0; ASIRLOADPATH[i] = q; |
Line 179 void env_init() { |
|
Line 223 void env_init() { |
|
if ( !p ) |
if ( !p ) |
break; |
break; |
} |
} |
|
}else{ |
|
ASIRLOADPATH=(char **)MALLOC(sizeof(char *)*3); |
|
ASIRLOADPATH[0] = NULL; |
|
} |
|
|
for ( i = 0; ASIRLOADPATH[i]; i++ ); |
for ( i = 0; ASIRLOADPATH[i]; i++ ); |
ASIRLOADPATH[i] = asir_libdir; |
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++] = "."; |
|
ASIRLOADPATH[i] = NULL; |
} |
} |
|
|
|
#if defined(VISUAL) || defined(__MINGW32__) |
|
#define R_OK 4 |
|
#endif |
|
|
void searchasirpath(char *name,char **pathp) |
void searchasirpath(char *name,char **pathp) |
{ |
{ |
char **p; |
char **p; |
char *q; |
char *q; |
int l; |
size_t l; |
#if !defined(VISUAL) |
int ret; |
struct stat sbuf; |
struct stat sbuf; |
|
|
if ( (name[0] == '/') || ( name[0] == '.') || strchr(name,':') |
if ( (name[0] == '/') || ( name[0] == '.') || strchr(name,':') |
|| !ASIRLOADPATH[0] ) { |
|| !ASIRLOADPATH[0] ) { |
if ( access(name,R_OK) >= 0 ) { |
if ( access(name,R_OK) >= 0 ) { |
stat(name,&sbuf); |
ret = stat(name,&sbuf); |
if ( (sbuf.st_mode & S_IFMT) != S_IFDIR ) |
if ( ret == 0 && (sbuf.st_mode & S_IFMT) != S_IFDIR ) |
*pathp = name; |
*pathp = name; |
else |
else |
*pathp = 0; |
*pathp = 0; |
Line 206 void searchasirpath(char *name,char **pathp) |
|
Line 263 void searchasirpath(char *name,char **pathp) |
|
l = strlen(*p)+strlen(name)+2; |
l = strlen(*p)+strlen(name)+2; |
q = (char *)ALLOCA(l); sprintf(q,"%s/%s",*p,name); |
q = (char *)ALLOCA(l); sprintf(q,"%s/%s",*p,name); |
if ( access(q,R_OK) >= 0 ) { |
if ( access(q,R_OK) >= 0 ) { |
stat(q,&sbuf); |
ret = stat(q,&sbuf); |
if ( (sbuf.st_mode & S_IFMT) != S_IFDIR ) { |
if ( ret == 0 && (sbuf.st_mode & S_IFMT) != S_IFDIR ) { |
*pathp = (char *)MALLOC(l); strcpy(*pathp,q); |
*pathp = (char *)MALLOC(l); strcpy(*pathp,q); |
return; |
return; |
} |
} |
Line 215 void searchasirpath(char *name,char **pathp) |
|
Line 272 void searchasirpath(char *name,char **pathp) |
|
} |
} |
*pathp = 0; |
*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 '/' |
#define DELIM '/' |
Line 240 void loadasirfile(char *name0) |
|
Line 281 void loadasirfile(char *name0) |
|
FILE *in; |
FILE *in; |
INFILE t; |
INFILE t; |
extern char cppname[]; |
extern char cppname[]; |
#if defined(VISUAL) |
#if defined(VISUAL) || defined(__MINGW32__) |
char ibuf1[BUFSIZ],ibuf2[BUFSIZ]; |
char ibuf1[BUFSIZ],ibuf2[BUFSIZ]; |
int ac; |
int ac; |
char *av[BUFSIZ]; |
char *av[BUFSIZ]; |
Line 343 void loadasirfile(char *name0) |
|
Line 384 void loadasirfile(char *name0) |
|
void execasirfile(char *name) |
void execasirfile(char *name) |
{ |
{ |
loadasirfile(name); |
loadasirfile(name); |
read_exec_file = 1; |
if ( !SETJMP(asir_infile->jmpbuf) ) { |
read_eval_loop(); |
asir_infile->ready_for_longjmp = 1; |
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; |
|
read_eval_loop(); |
read_eval_loop(); |
read_exec_file = 0; |
|
} |
} |
fclose(fp); |
closecurrentinput(); |
restorepvs(); |
|
asir_infile = save_asir_infile; |
|
prresult = save_prresult; |
|
} |
} |
|
|
static NODE objfile = 0; |
static NODE objfile = 0; |