=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2000/parse/load.c,v retrieving revision 1.7 retrieving revision 1.20 diff -u -p -r1.7 -r1.20 --- OpenXM_contrib2/asir2000/parse/load.c 2001/08/20 09:14:14 1.7 +++ OpenXM_contrib2/asir2000/parse/load.c 2006/02/08 02:11:19 1.20 @@ -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.6 2001/08/20 09:03:27 noro Exp $ + * $OpenXM: OpenXM_contrib2/asir2000/parse/load.c,v 1.19 2006/02/05 08:28:04 noro Exp $ */ #include "ca.h" #include "parse.h" @@ -74,14 +74,13 @@ #include #endif +#ifdef MALLOC #undef MALLOC #define MALLOC(x) GC_malloc((x)+4) +#endif -char *ASIRLOADPATH[32]; +char **ASIRLOADPATH; -void encrypt_file(char *,char *); -void decrypt_file(char *,char *); - #if defined(VISUAL) #define ENVDELIM ';' #define MORE "more < " @@ -91,19 +90,56 @@ void decrypt_file(char *,char *); #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]; @@ -123,13 +159,53 @@ void env_init() { #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; lname = (char *)MALLOC(strlen(name0)+1); strcpy(t->name,name0); t->tname = (char *)MALLOC(strlen(tname)+1); strcpy(t->tname,tname); free(tname); t->encoded = encoded; @@ -292,7 +371,7 @@ char *name0; perror("popen"); error("load : failed"); } - t = (IN)MALLOC(sizeof(struct oIN)); + t = (INFILE)MALLOC(sizeof(struct oINFILE)); t->name = (char *)MALLOC(strlen(name0)+1); strcpy(t->name,name0); #endif t->fp = in; t->ln = 1; t->next = asir_infile; asir_infile = t; @@ -302,44 +381,19 @@ char *name0; reallocarray((char **)&EPVS->va,(int *)&EPVS->asize,(int *)&EPVS->n,(int)sizeof(struct oPV)); } -void execasirfile(name) -char *name; +void execasirfile(char *name) { loadasirfile(name); - read_exec_file = 1; - read_eval_loop(); - read_exec_file = 0; -} - -void load_and_execfile(name) -char *name; -{ - FILE *fp; - IN 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; -int loadfile(s) -char *s; +int loadfile(char *s) { FILE *in; @@ -351,7 +405,7 @@ char *s; return 0; } -int loadfiles(node) NODE node; { return 0; } +int loadfiles(NODE node) { return 0; } static unsigned char encrypt_tab[128][2] = { {137,40},{1,194},{133,79},{48,20},{254,76},{98,17},{110,233},{19,231}, @@ -401,8 +455,7 @@ unsigned char decrypt_char(unsigned char c) return decrypt_tab[c]; } -void encrypt_file(in,out) -char *in,*out; +void encrypt_file(char *in,char *out) { FILE *infp,*outfp; int c; @@ -413,13 +466,12 @@ char *in,*out; c = getc(infp); if ( c == EOF ) break; - putc(encrypt_char(c),outfp); + putc(encrypt_char((unsigned char)c),outfp); } fclose(infp); fclose(outfp); } -void decrypt_file(in,out) -char *in,*out; +void decrypt_file(char *in,char *out) { FILE *infp,*outfp; int c; @@ -432,7 +484,7 @@ char *in,*out; c = getc(infp); if ( c == EOF ) break; - putc(decrypt_char(c),outfp); + putc(decrypt_char((unsigned char)c),outfp); } fclose(infp); fclose(outfp); }