[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.3 and 1.26

version 1.3, 2000/08/21 08:31:47 version 1.26, 2014/05/09 18:32:13
Line 23 
Line 23 
  * shall be made on your publication or presentation in any form of the   * shall be made on your publication or presentation in any form of the
  * results obtained by use of the SOFTWARE.   * results obtained by use of the SOFTWARE.
  * (4) In the event that you modify the SOFTWARE, you shall notify FLL by   * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
  * e-mail at risa-admin@flab.fujitsu.co.jp of the detailed specification   * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
  * for such modification or the source code of the modified part of the   * for such modification or the source code of the modified part of the
  * SOFTWARE.   * SOFTWARE.
  *   *
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.2 2000/01/19 05:05:04 noro Exp $   * $OpenXM: OpenXM_contrib2/asir2000/parse/load.c,v 1.25 2014/04/02 22:08:29 ohara Exp $
 */  */
 #include "ca.h"  #include "ca.h"
 #include "parse.h"  #include "parse.h"
 #if defined(THINK_C)  
 #include <string.h>  
 #include        <StandardFile.h>  
 #include        <Windows.h>  
 #include        <OSUtils.h>  
 #include        <ToolUtils.h>  
 #else  
 #if defined(VISUAL)  #if defined(VISUAL)
 #include <string.h>  #include <string.h>
 #include <fcntl.h>  #include <fcntl.h>
 #if defined(GO32)  
 #include <unistd.h>  
 #endif  
 #include <sys/stat.h>  #include <sys/stat.h>
 #else  #else /* VISUAL */
 #if defined(_PA_RISC1_1) || defined(SYSV) || defined(__SVR4)  #if defined(_PA_RISC1_1) || defined(SYSV) || defined(__SVR4)
 #include <unistd.h>  #include <unistd.h>
 #include <string.h>  #include <string.h>
Line 74 
Line 65 
 #include <sys/file.h>  #include <sys/file.h>
 #include <sys/stat.h>  #include <sys/stat.h>
 #endif  #endif
 #endif  
   
 #if defined(linux)  #if defined(linux)
 #include <unistd.h>  #include <unistd.h>
Line 84 
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) Risa_GC_malloc((x)+4)
   
 char *ASIRLOADPATH[32];  
   
 void encrypt_file(char *,char *);  
 void decrypt_file(char *,char *);  
   
 #if defined(THINK_C)  
 void searchasirpath(char *,char **);  
 void loadasirfile(char *);  
   
 short initvol;  
   
 void initVol();  
 short getVol();  
 void setDir(short);  
 void resetDir();  
   
 void initVol() {  
         char buf[BUFSIZ];  
   
         GetVol((StringPtr)buf,&initvol);  
 }  
   
 short getVol() {  
         short vol;  
         char buf[BUFSIZ];  
   
         GetVol((StringPtr)buf,&vol);  
         return vol;  
 }  
   
 void setDir(short vol)  
 {  
         SetVol(0,vol);  
 }  
   
 void resetDir() {  
         SetVol(0,initvol);  
 }  
 #endif  #endif
   
   char **ASIRLOADPATH;
   
 #if defined(VISUAL)  #if defined(VISUAL)
 #define ENVDELIM ';'  #define ENVDELIM ';'
 #define MORE "more < "  #define MORE "more < "
Line 136  void resetDir() {
Line 90  void resetDir() {
 #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_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;
   
   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];
       size_t len;
   
           if ( oxhome = getenv("OpenXM_HOME") ) {
                   len = strlen(oxhome);
           }else {
   #if defined(VISUAL)
                   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)
       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")) ) {
                 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 181  void env_init() {
Line 221  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;
 }  }
   
 void searchasirpath(name,pathp)  #if defined(VISUAL)
 char *name;  #define R_OK 4
 char **pathp;  #endif
   
   void searchasirpath(char *name,char **pathp)
 {  {
         char **p;          char **p;
         char *q;          char *q;
         int l;          size_t l;
 #if !defined(THINK_C) && !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 210  char **pathp;
Line 261  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 219  char **pathp;
Line 270  char **pathp;
                 }                  }
                 *pathp = 0;                  *pathp = 0;
         }          }
 #elif defined(VISUAL)  
         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;  
         }  
 #else  
         if ( (name[0] == '/') || ( name[0] == '.') || !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);  
                         *pathp = (char *)MALLOC(l); strcpy(*pathp,q);  
                         return;  
                 }  
                 *pathp = 0;  
         }  
 #endif  
 }  }
   
 #if defined(THINK_C)  
 #define DELIM ':'  
 #elif defined(VISUAL)  
 #define DELIM '/'  #define DELIM '/'
 #endif  
   
 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(THINK_C) || defined(VISUAL)  #if defined(VISUAL)
         char tname[BUFSIZ],dname[BUFSIZ],ibuf1[BUFSIZ],ibuf2[BUFSIZ];          char ibuf1[BUFSIZ],ibuf2[BUFSIZ];
         int ac;          int ac;
 #if defined(__MWERKS__)  
         char *av[64];  
 #else  
         char *av[BUFSIZ];          char *av[BUFSIZ];
 #endif          char *p;
         char *p,*c;  
         FILE *fp;          FILE *fp;
         char name[BUFSIZ],tname0[BUFSIZ];          char dname[BUFSIZ],tname0[BUFSIZ];
           char *name,*tname;
         int encoded;          int encoded;
           static char prefix[BUFSIZ];
           int process_id();
           char CppExe[BUFSIZ];
           char nbuf[BUFSIZ],tnbuf[BUFSIZ];
           STRING rootdir;
           void call_exe(char *,char **);
   
 #if defined(VISUAL)          /* create the unique prefix */
           if ( !prefix[0] )
                   sprintf(prefix,"asir%d",process_id());
   
         fp = fopen(name0,"rb");          fp = fopen(name0,"rb");
         if ( getc(fp) == 0xff ) {          if ( getc(fp) == 0xff ) {
                 /* encoded file */                  /* encoded file */
                 fclose(fp);                  fclose(fp);
                 sprintf(name,"%s.$$$",name0);                  name = tempnam(NULL,prefix);
                 decrypt_file(name0,name);                  decrypt_file(name0,name);
                   /* the file 'name' created */
                 encoded = 1;                  encoded = 1;
         } else {          } else {
                 fclose(fp);                  fclose(fp);
                 strcpy(name,name0);                  name = name0;
                 encoded = 0;                  encoded = 0;
         }          }
 #else  
         strcpy(name,name0);  
 #endif  
   
         strcpy(dname,name);          strcpy(dname,name);
           av[0] = "cpp";
           sprintf(nbuf,"\"%s\"",name);
           av[1] = nbuf;
           tname = tempnam(NULL,prefix);
           sprintf(tnbuf,"\"%s\"",tname);
           av[2] = tnbuf;
           sprintf(ibuf1,"-I\"%s\"",asir_libdir);
           av[3] = ibuf1;
           av[4] = "-DWINDOWS";
   
           /* set the include directory */
         p = strrchr(dname,DELIM);          p = strrchr(dname,DELIM);
         av[0] = "cpp"; av[1] = name; av[2] = tname;  
         sprintf(ibuf1,"-I%s",asir_libdir); av[3] = ibuf1; av[4] = "-DWINDOWS";  
         if ( !p ) {          if ( !p ) {
                 sprintf(tname,"%s.___",name); av[5] = 0; ac = 5;                  av[5] = 0; ac = 5;
         } else {          } else {
                 *p++ = 0;                  *p = 0;
 #if defined(VISUAL)                  sprintf(ibuf2,"-I\"%s\"",dname);
                 if ( c = strchr(dname,':') ) {                  av[5] = ibuf2;
                         *c = 0;                  av[6] = 0; ac = 6;
                         sprintf(tname,"%s:%s%c%s.___",dname,c+1,DELIM,p);  
                         *c = ':';  
                 } else  
   
 #endif  
                 sprintf(tname,"%s%c%s.___",dname,DELIM,p);  
                 sprintf(ibuf2,"-I%s",dname); av[5] = ibuf2; av[6] = 0; ac = 6;  
         }          }
         cpp_main(ac,av);  //      cpp_main(ac,av);
           Pget_rootdir(&rootdir);
           sprintf(CppExe,"%s\\bin\\cpp.exe",BDY(rootdir));
           call_exe(CppExe,av);
   
           /* the file tname created */
         if ( encoded ) {          if ( encoded ) {
                 unlink(name);                  unlink(name); free(name);
                 strcpy(tname0,tname);  
                 sprintf(tname,"%s.###",tname0);                  strcpy(tname0,tname); free(tname);
                   tname = tempnam(NULL,prefix);
   
                 encrypt_file(tname0,tname);                  encrypt_file(tname0,tname);
                   /* the file tname created */
                 unlink(tname0);                  unlink(tname0);
   
                 in = fopen(tname,"rb");                  in = fopen(tname,"rb");
         } else          } else
                 in = fopen(tname,"r");                  in = fopen(tname,"r");
Line 326  char *name0;
Line 357  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(name)+1); strcpy(t->name,name);          t->name = (char *)MALLOC(strlen(name0)+1); strcpy(t->name,name0);
         t->tname = (char *)MALLOC(strlen(tname)+1); strcpy(t->tname,tname);          t->tname = (char *)MALLOC(strlen(tname)+1); strcpy(t->tname,tname); free(tname);
         t->encoded = encoded;          t->encoded = encoded;
 #if defined(THINK_C)  
         t->vol = getVol();  
 #endif  
 #else  #else
         char com[BUFSIZ];          char com[BUFSIZ];
   
Line 341  char *name0;
Line 369  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 351  char *name0;
Line 379  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;          if ( !SETJMP(asir_infile->jmpbuf) ) {
         read_eval_loop();                  asir_infile->ready_for_longjmp = 1;
         read_exec_file = 0;                  read_eval_loop();
           }
           closecurrentinput();
 }  }
   
 static NODE objfile = 0;  static NODE objfile = 0;
   
 int loadfile(s)  int loadfile(char *s)
 char *s;  
 {  {
         FILE *in;          FILE *in;
   
Line 375  char *s;
Line 403  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 425  unsigned char decrypt_char(unsigned char c)
Line 453  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 437  char *in,*out;
Line 464  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 456  char *in,*out;
Line 482  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.3  
changed lines
  Added in v.1.26

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