[BACK]Return to load.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / parse

Diff for /OpenXM_contrib2/asir2000/parse/load.c between version 1.6 and 1.17

version 1.6, 2001/08/20 09:03:27 version 1.17, 2005/03/24 23:40:50
Line 45 
Line 45 
  * 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.5 2000/11/10 08:28:53 noro Exp $   * $OpenXM: OpenXM_contrib2/asir2000/parse/load.c,v 1.16 2005/03/24 22:54:22 takayama Exp $
 */  */
 #include "ca.h"  #include "ca.h"
 #include "parse.h"  #include "parse.h"
Line 74 
Line 74 
 #include <io.h>  #include <io.h>
 #endif  #endif
   
   #ifdef MALLOC
 #undef MALLOC  #undef MALLOC
 #define MALLOC(x) GC_malloc((x)+4)  #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)  #if defined(VISUAL)
 #define ENVDELIM ';'  #define ENVDELIM ';'
 #define MORE "more < "  #define MORE "more < "
Line 91  void decrypt_file(char *,char *);
Line 90  void decrypt_file(char *,char *);
 #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();
   char *search_executable(char *name);
   
 extern char *asir_libdir;  extern char *asir_libdir;
   extern char *asir_contrib_dir;
 extern char *asir_pager;  extern char *asir_pager;
 extern int read_exec_file;  extern int read_exec_file;
 extern int main_parser;  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() {  void env_init() {
         char *e,*p,*q;          char *e,*p,*q;
         int i,l;          int i,l,japanese;
         char *getenv();          char *getenv();
         char *oxhome;          char *oxhome;
         char rootname[BUFSIZ];          char rootname[BUFSIZ];
Line 116  void env_init() {
Line 153  void env_init() {
 #if defined(VISUAL)  #if defined(VISUAL)
                         get_rootdir(rootname,sizeof(rootname));                          get_rootdir(rootname,sizeof(rootname));
                         asir_libdir = (char *)malloc(strlen(rootname)+strlen("/lib")+1);                          asir_libdir = (char *)malloc(strlen(rootname)+strlen("/lib")+1);
                         sprintf(asir_libdir,"%s/lib",rootname);  
 #else  #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  #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")) ) {          if ( !(asir_pager = getenv("PAGER")) ) {
                 asir_pager = (char *)malloc(strlen(MORE)+1);                  japanese = 0;
                 strcpy(asir_pager,MORE);                  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 ) {                  for ( i = 0; ; i++, e = p+1 ) {
                         p = (char *)index(e,ENVDELIM);                          p = (char *)index(e,ENVDELIM);
                           if ( !p )
                                   break;
                   }
                   i += 4;
           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 137  void env_init() {
Line 213  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_contrib_dir) ASIRLOADPATH[i++] = asir_contrib_dir;
           if (asir_libdir) ASIRLOADPATH[i++] = asir_libdir;
           ASIRLOADPATH[i] = NULL;
 }  }
   
 void searchasirpath(name,pathp)  void searchasirpath(char *name,char **pathp)
 char *name;  
 char **pathp;  
 {  {
         char **p;          char **p;
         char *q;          char *q;
Line 195  char **pathp;
Line 276  char **pathp;
   
 #define DELIM '/'  #define DELIM '/'
   
 void Eungetc(int,FILE *);  void loadasirfile(char *name0)
   
 void loadasirfile(name0)  
 char *name0;  
 {  {
         FILE *in;          FILE *in;
         IN t;          INFILE t;
         extern char cppname[];          extern char cppname[];
 #if defined(VISUAL)  #if defined(VISUAL)
         char ibuf1[BUFSIZ],ibuf2[BUFSIZ];          char ibuf1[BUFSIZ],ibuf2[BUFSIZ];
         int ac;          int ac;
         char *av[BUFSIZ];          char *av[BUFSIZ];
         char *p,*c;          char *p;
         FILE *fp;          FILE *fp;
         char dname[BUFSIZ],tname0[BUFSIZ];          char dname[BUFSIZ],tname0[BUFSIZ];
         char *name,*tname;          char *name,*tname;
Line 217  char *name0;
Line 295  char *name0;
         char CppExe[BUFSIZ];          char CppExe[BUFSIZ];
         char nbuf[BUFSIZ],tnbuf[BUFSIZ];          char nbuf[BUFSIZ],tnbuf[BUFSIZ];
         STRING rootdir;          STRING rootdir;
           void call_exe(char *,char **);
   
         /* create the unique prefix */          /* create the unique prefix */
         if ( !prefix[0] )          if ( !prefix[0] )
Line 280  char *name0;
Line 359  char *name0;
                 perror("fopen");                  perror("fopen");
                 error("load : failed");                  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);          t->name = (char *)MALLOC(strlen(name0)+1); strcpy(t->name,name0);
         t->tname = (char *)MALLOC(strlen(tname)+1); strcpy(t->tname,tname); free(tname);          t->tname = (char *)MALLOC(strlen(tname)+1); strcpy(t->tname,tname); free(tname);
         t->encoded = encoded;          t->encoded = encoded;
Line 292  char *name0;
Line 371  char *name0;
                 perror("popen");                  perror("popen");
                 error("load : failed");                  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);          t->name = (char *)MALLOC(strlen(name0)+1); strcpy(t->name,name0);
 #endif  #endif
         t->fp = in; t->ln = 1; t->next = asir_infile; asir_infile = t;          t->fp = in; t->ln = 1; t->next = asir_infile; asir_infile = t;
Line 302  char *name0;
Line 381  char *name0;
                 reallocarray((char **)&EPVS->va,(int *)&EPVS->asize,(int *)&EPVS->n,(int)sizeof(struct oPV));                  reallocarray((char **)&EPVS->va,(int *)&EPVS->asize,(int *)&EPVS->n,(int)sizeof(struct oPV));
 }  }
   
 void execasirfile(name)  void execasirfile(char *name)
 char *name;  
 {  {
         loadasirfile(name);          loadasirfile(name);
         read_exec_file = 1;          read_exec_file = 1;
Line 311  char *name;
Line 389  char *name;
         read_exec_file = 0;          read_exec_file = 0;
 }  }
   
 void load_and_execfile(name)  void load_and_execfile(char *name)
 char *name;  
 {  {
         FILE *fp;          FILE *fp;
         IN save_asir_infile;          INFILE save_asir_infile;
           int save_prresult;
           extern prresult;
   
         savepvs();          savepvs();
         save_asir_infile = asir_infile;          save_asir_infile = asir_infile;
           save_prresult = prresult;
         fp = fopen(name,"rb");          fp = fopen(name,"rb");
         input_init(fp,name);          input_init(fp,name);
         if ( !setjmp(exec_env) ) {          if ( !SETJMP(exec_env) ) {
                 /* XXX : information for asir_teriminate() */                  /* XXX : information for asir_teriminate() */
                 read_exec_file = 2;                  read_exec_file = 2;
                 read_eval_loop();                  read_eval_loop();
Line 330  char *name;
Line 410  char *name;
         fclose(fp);          fclose(fp);
         restorepvs();          restorepvs();
         asir_infile = save_asir_infile;          asir_infile = save_asir_infile;
           prresult = save_prresult;
 }  }
   
 static NODE objfile = 0;  static NODE objfile = 0;
   
 int loadfile(s)  int loadfile(char *s)
 char *s;  
 {  {
         FILE *in;          FILE *in;
   
Line 347  char *s;
Line 427  char *s;
                 return 0;                  return 0;
 }  }
   
 int loadfiles(node) NODE node; { return 0; }  int loadfiles(NODE node) { return 0; }
   
 static unsigned char encrypt_tab[128][2] = {  static unsigned char encrypt_tab[128][2] = {
 {137,40},{1,194},{133,79},{48,20},{254,76},{98,17},{110,233},{19,231},  {137,40},{1,194},{133,79},{48,20},{254,76},{98,17},{110,233},{19,231},
Line 397  unsigned char decrypt_char(unsigned char c)
Line 477  unsigned char decrypt_char(unsigned char c)
         return decrypt_tab[c];          return decrypt_tab[c];
 }  }
   
 void encrypt_file(in,out)  void encrypt_file(char *in,char *out)
 char *in,*out;  
 {  {
         FILE *infp,*outfp;          FILE *infp,*outfp;
         int c;          int c;
Line 409  char *in,*out;
Line 488  char *in,*out;
                 c = getc(infp);                  c = getc(infp);
                 if ( c == EOF )                  if ( c == EOF )
                         break;                          break;
                 putc(encrypt_char(c),outfp);                  putc(encrypt_char((unsigned char)c),outfp);
         }          }
         fclose(infp); fclose(outfp);          fclose(infp); fclose(outfp);
 }  }
   
 void decrypt_file(in,out)  void decrypt_file(char *in,char *out)
 char *in,*out;  
 {  {
         FILE *infp,*outfp;          FILE *infp,*outfp;
         int c;          int c;
Line 428  char *in,*out;
Line 506  char *in,*out;
                 c = getc(infp);                  c = getc(infp);
                 if ( c == EOF )                  if ( c == EOF )
                         break;                          break;
                 putc(decrypt_char(c),outfp);                  putc(decrypt_char((unsigned char)c),outfp);
         }          }
         fclose(infp); fclose(outfp);          fclose(infp); fclose(outfp);
 }  }

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.17

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>