[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.1.1.1 and 1.33

version 1.1.1.1, 1999/12/03 07:39:12 version 1.33, 2018/03/29 01:32:54
Line 1 
Line 1 
 /* $OpenXM: OpenXM/src/asir99/parse/load.c,v 1.1.1.1 1999/11/10 08:12:34 noro Exp $ */  /*
    * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
    * All rights reserved.
    *
    * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited,
    * non-exclusive and royalty-free license to use, copy, modify and
    * redistribute, solely for non-commercial and non-profit purposes, the
    * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
    * conditions of this Agreement. For the avoidance of doubt, you acquire
    * only a limited right to use the SOFTWARE hereunder, and FLL or any
    * third party developer retains all rights, including but not limited to
    * copyrights, in and to the SOFTWARE.
    *
    * (1) FLL does not grant you a license in any way for commercial
    * purposes. You may use the SOFTWARE only for non-commercial and
    * non-profit purposes only, such as academic, research and internal
    * business use.
    * (2) The SOFTWARE is protected by the Copyright Law of Japan and
    * international copyright treaties. If you make copies of the SOFTWARE,
    * with or without modification, as permitted hereunder, you shall affix
    * to all such copies of the SOFTWARE the above copyright notice.
    * (3) An explicit reference to this SOFTWARE and its copyright owner
    * shall be made on your publication or presentation in any form of the
    * results obtained by use of the SOFTWARE.
    * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
    * 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
    * SOFTWARE.
    *
    * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
    * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
    * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
    * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
    * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
    * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
    * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
    * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
    * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
    * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
    * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
    * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
    * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
    * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
    * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
    * 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.32 2017/02/07 08:30:31 noro Exp $
   */
 #include "ca.h"  #include "ca.h"
 #include "parse.h"  #include "parse.h"
 #if defined(THINK_C)  
   #if defined(VISUAL) || defined(__MINGW32__)
 #include <string.h>  #include <string.h>
 #include        <StandardFile.h>  
 #include        <Windows.h>  
 #include        <OSUtils.h>  
 #include        <ToolUtils.h>  
 #else  
 #if defined(VISUAL)  
 #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 26 
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>
 #endif  #endif
   
 #if defined(VISUAL)  #if defined(VISUAL) || defined(__MINGW32__)
 #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
   
 #if defined(VISUAL)  char **ASIRLOADPATH;
   int ASIRLOADPATH_LEN;
   
   #if defined(VISUAL) || defined(__MINGW32__)
 #define ENVDELIM ';'  #define ENVDELIM ';'
 #define MORE "more < "  #define MORE "more < "
 #else  #else
Line 88  void resetDir() {
Line 91  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;
   
 void env_init() {  char *search_executable(char *name)
         char *e,*p,*q;  {
         int i,l;    char *c,*s,*ret;
         char *getenv();    int len,nlen;
         char *oxhome;    char dir[BUFSIZ],path[BUFSIZ];
         char rootname[BUFSIZ];    struct stat buf;
   
         if ( !(asir_libdir = getenv("ASIR_LIBDIR")) ) {    nlen = strlen(name);
                 if ( oxhome = getenv("OpenXM_HOME") ) {    for ( s = (char *)getenv("PATH"); s; ) {
                         asir_libdir = (char *)malloc(strlen(oxhome)+strlen("/lib/asir")+1);      c = (char *)index(s,':');
                         sprintf(asir_libdir,"%s/lib/asir",oxhome);      len = c ? c-s : strlen(s);
                 } else {      if ( len >= BUFSIZ ) continue;
 #if defined(VISUAL)      strncpy(dir,s,len); dir[len] = 0;
                         get_rootdir(rootname,sizeof(rootname));      if ( c ) s = c+1;
                         asir_libdir = (char *)malloc(strlen(rootname)+strlen("/lib")+1);      else s = 0;
                         sprintf(asir_libdir,"%s/lib",rootname);      if ( len+nlen+1 >= BUFSIZ ) continue;
 #else      sprintf(path,"%s/%s",dir,name);
                         asir_libdir = (char *)malloc(strlen(ASIR_LIBDIR)+1);      if ( !stat(path,&buf) && !(buf.st_mode & S_IFDIR)
                         strcpy(asir_libdir,ASIR_LIBDIR);  #if !defined(VISUAL) && !defined(__MINGW32__)
         && !access(path,X_OK)
 #endif  #endif
                 }                  ) {
         }        len = strlen(path)+1;
         if ( !(asir_pager = getenv("PAGER")) ) {        ret = (char *)MALLOC(len);
                 asir_pager = (char *)malloc(strlen(MORE)+1);        strcpy(ret,path);
                 strcpy(asir_pager,MORE);        return ret;
         }      }
         if ( e = getenv("ASIRLOADPATH" ) )    }
                 for ( i = 0; ; i++, e = p+1 ) {    return 0;
                         p = (char *)index(e,ENVDELIM);  
                         l = p ? p-e : strlen(e); q = (char *)MALLOC(l+1);  
                         if ( l ) {  
                                 strncpy(q,e,l); q[l] = 0; ASIRLOADPATH[i] = q;  
                         }  
                         if ( !p )  
                                 break;  
                 }  
         for ( i = 0; ASIRLOADPATH[i]; i++ );  
         ASIRLOADPATH[i] = asir_libdir;  
 }  }
   
 void searchasirpath(name,pathp)  void env_init() {
 char *name;    char *e,*p,*q;
 char **pathp;    int i,l,japanese;
 {    char *getenv();
         char **p;    char *oxhome;
         char *q;    char rootname[BUFSIZ];
         int l;      size_t len;
 #if !defined(THINK_C) && !defined(VISUAL)  
         struct stat sbuf;  
   
         if ( (name[0] == '/') || ( name[0] == '.') || strchr(name,':')  
                 || !ASIRLOADPATH[0] ) {  
                 if ( access(name,R_OK) >= 0 ) {  
                         stat(name,&sbuf);  
                         if ( (sbuf.st_mode & S_IFMT) != S_IFDIR )  
                                 *pathp = name;  
                         else  
                                 *pathp = 0;  
                 } else  
                         *pathp = 0;  
         } 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,R_OK) >= 0 ) {  
                                 stat(q,&sbuf);  
                                 if ( (sbuf.st_mode & S_IFMT) != S_IFDIR ) {  
                                         *pathp = (char *)MALLOC(l); strcpy(*pathp,q);  
                                         return;  
                                 }  
                         }  
                 }  
                 *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)    if ( oxhome = getenv("OpenXM_HOME") ) {
 #define DELIM ':'      len = strlen(oxhome);
 #elif defined(VISUAL)    }else {
 #define DELIM '/'  #if defined(VISUAL) || defined(__MINGW32__)
       get_rootdir(rootname,sizeof(rootname));
       len = strlen(rootname);
       oxhome = rootname;
 #endif  #endif
     }
   
 void Eungetc(int,FILE *);    if ( !(asir_libdir = getenv("ASIR_LIBDIR")) ) {
       if ( oxhome ) {
         asir_libdir = (char *)malloc(len+strlen("/lib/asir")+1);
         sprintf(asir_libdir,"%s/lib/asir",oxhome);
       } else {
         asir_libdir = (char *)malloc(strlen(ASIR_LIBDIR)+1);
         strcpy(asir_libdir,ASIR_LIBDIR);
       }
     }
   
 void loadasirfile(name0)    if ( !(asir_contrib_dir = getenv("ASIR_CONTRIB_DIR")) ) {
 char *name0;      if ( oxhome ) {
 {        asir_contrib_dir = (char *)malloc(len+strlen("/lib/asir-contrib")+1);
         FILE *in;        sprintf(asir_contrib_dir,"%s/lib/asir-contrib",oxhome);
         IN t;      } else {
         extern char cppname[];        asir_contrib_dir = (char *)malloc(strlen(ASIR_CONTRIB_DIR)+1);
 #if defined(THINK_C) || defined(VISUAL)        strcpy(asir_contrib_dir,ASIR_CONTRIB_DIR);
         char tname[BUFSIZ],dname[BUFSIZ],ibuf1[BUFSIZ],ibuf2[BUFSIZ];      }
         int ac;    }
 #if defined(__MWERKS__)  
         char *av[64];  
 #else  
         char *av[BUFSIZ];  
 #endif  
         char *p,*c;  
         FILE *fp;  
         char name[BUFSIZ],tname0[BUFSIZ];  
         int encoded;  
   
 #if defined(VISUAL)      asir_private_dir = NULL;
         fp = fopen(name0,"rb");  #if defined(VISUAL) || defined(__MINGW32__)
         if ( getc(fp) == 0xff ) {      if ( e = getenv("APPDATA") ) {
                 /* encoded file */          asir_private_dir = (char *)malloc(strlen(e)+strlen("/OpenXM/lib/asir-contrib")+1);
                 fclose(fp);          sprintf(asir_private_dir,"%s/OpenXM/lib/asir-contrib",e);
                 sprintf(name,"%s.$$$",name0);      }
                 decrypt_file(name0,name);  #endif
                 encoded = 1;  
         } else {  
                 fclose(fp);  
                 strcpy(name,name0);  
                 encoded = 0;  
         }  
 #else  
         strcpy(name,name0);  
 #endif  
   
         strcpy(dname,name);    if ( !(asir_pager = getenv("PAGER")) ) {
         p = strrchr(dname,DELIM);  #if 0
         av[0] = "cpp"; av[1] = name; av[2] = tname;      japanese = 0;
         sprintf(ibuf1,"-I%s",asir_libdir); av[3] = ibuf1; av[4] = "-DWINDOWS";      if ( (e = getenv("LANGUAGE")) &&
         if ( !p ) {        (!strncmp(e,"japan",5) || !strncmp(e,"ja_JP",5)) ) japanese = 1;
                 sprintf(tname,"%s.___",name); av[5] = 0; ac = 5;      else if ( (e = getenv("LC_ALL")) &&
         } else {        (!strncmp(e,"japan",5) || !strncmp(e,"ja_JP",5)) ) japanese = 1;
                 *p++ = 0;      else if ( (e = getenv("LC_CTYPE")) &&
 #if defined(VISUAL)        (!strncmp(e,"japan",5) || !strncmp(e,"ja_JP",5)) ) japanese = 1;
                 if ( c = strchr(dname,':') ) {      else if ( (e = getenv("LANG")) &&
                         *c = 0;        (!strncmp(e,"japan",5) || !strncmp(e,"ja_JP",5)) ) japanese = 1;
                         sprintf(tname,"%s:%s%c%s.___",dname,c+1,DELIM,p);      if ( japanese )
                         *c = ':';        asir_pager = search_executable("jless");
                 } else  
   
 #endif  #endif
                 sprintf(tname,"%s%c%s.___",dname,DELIM,p);      asir_pager = search_executable("less");
                 sprintf(ibuf2,"-I%s",dname); av[5] = ibuf2; av[6] = 0; ac = 6;      if ( !asir_pager ) {
         }        /* default: more */
         cpp_main(ac,av);        asir_pager = (char *)malloc(strlen(MORE)+1);
         if ( encoded ) {        strcpy(asir_pager,MORE);
                 unlink(name);      }
                 strcpy(tname0,tname);    }
                 sprintf(tname,"%s.###",tname0);    if ( e = getenv("ASIRLOADPATH" ) ) {
                 encrypt_file(tname0,tname);      for ( i = 0; ; i++, e = p+1 ) {
                 unlink(tname0);        p = (char *)index(e,ENVDELIM);
                 in = fopen(tname,"rb");        if ( !p )
         } else          break;
                 in = fopen(tname,"r");      }
         if ( !in ) {      i += 5;
                 perror("fopen");      ASIRLOADPATH_LEN=i;
                 error("load : failed");          ASIRLOADPATH=(char **)MALLOC(sizeof(char *)*i);
         }      for ( l = 0; l<i; l++) ASIRLOADPATH[l] = NULL;
         t = (IN)MALLOC(sizeof(struct oIN));      e = getenv("ASIRLOADPATH");
         t->name = (char *)MALLOC(strlen(name)+1); strcpy(t->name,name);      for ( i = 0; ; i++, e = p+1 ) {
         t->tname = (char *)MALLOC(strlen(tname)+1); strcpy(t->tname,tname);        p = (char *)index(e,ENVDELIM);
         t->encoded = encoded;        l = p ? p-e : strlen(e); q = (char *)MALLOC(l+1);
 #if defined(THINK_C)        if ( l ) {
         t->vol = getVol();          strncpy(q,e,l); q[l] = 0; ASIRLOADPATH[i] = q;
 #endif        }
 #else        if ( !p )
         char com[BUFSIZ];          break;
       }
       }else{
       ASIRLOADPATH=(char **)MALLOC(sizeof(char *)*3);
       ASIRLOADPATH[0] = NULL;
     }
   
         sprintf(com,"%s -I%s %s",cppname,asir_libdir,name0); in = popen(com,"r");    for ( i = 0; ASIRLOADPATH[i]; i++ );
         if ( !in ) {    if (asir_private_dir) ASIRLOADPATH[i++] = asir_private_dir;
                 perror("popen");    if (asir_contrib_dir) ASIRLOADPATH[i++] = asir_contrib_dir;
                 error("load : failed");    if (asir_libdir) ASIRLOADPATH[i++] = asir_libdir;
         }    ASIRLOADPATH[i++] = ".";
         t = (IN)MALLOC(sizeof(struct oIN));    ASIRLOADPATH[i] = NULL;
         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;  
         main_parser = 1; /* XXX */  
         Eungetc(afternl(),asir_infile->fp);  
         if ( !EPVS->va )  
                 reallocarray((char **)&EPVS->va,(int *)&EPVS->asize,(int *)&EPVS->n,(int)sizeof(struct oPV));  
 }  }
   
 void execasirfile(name)  #if defined(VISUAL) || defined(__MINGW32__)
 char *name;  #define R_OK 4
 {  #endif
         loadasirfile(name);  
         read_exec_file = 1;  
         read_eval_loop();  
         read_exec_file = 0;  
 }  
   
 static NODE objfile = 0;  void searchasirpath(char *name,char **pathp)
   
 #if defined(apollo) || defined(VISUAL) || defined(_PA_RISC1_1) || defined(__alpha) || defined(linux) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(SYSV) || defined(__SVR4)  
   
 int loadfile(s)  
 char *s;  
 {  {
         FILE *in;    char **p;
     char *q;
         if ( in = fopen(s,"r") ) {    size_t l;
                 fclose(in);    int ret;
                 loadasirfile(s);    struct stat sbuf;
                 return 1;  
         } else    if ( (name[0] == '/') || ( name[0] == '.') || strchr(name,':')
                 return 0;      || !ASIRLOADPATH[0] ) {
       if ( access(name,R_OK) >= 0 ) {
         ret = stat(name,&sbuf);
         if ( ret == 0 && (sbuf.st_mode & S_IFMT) != S_IFDIR )
           *pathp = name;
         else
           *pathp = 0;
       } else
         *pathp = 0;
     } 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,R_OK) >= 0 ) {
           ret = stat(q,&sbuf);
           if ( ret == 0 && (sbuf.st_mode & S_IFMT) != S_IFDIR ) {
             *pathp = (char *)MALLOC(l); strcpy(*pathp,q);
             return;
           }
         }
       }
       *pathp = 0;
     }
 }  }
   
 int loadfiles(node) NODE node; { return 0; }  #define DELIM '/'
   
 #else  void loadasirfile(char *name0)
 #if defined(THINK_C)  
   
 int loadfile(s)  
 char *s;  
 {  {
         FILE *in;    FILE *in;
     INFILE t;
         if ( in = fopen(s,"r") ) {    extern char cppname[];
                 loadasirfile(s); fclose(in);  #if defined(VISUAL) || defined(__MINGW32__)
                 return 1;    char ibuf1[BUFSIZ],ibuf2[BUFSIZ];
         } else    int ac;
                 return 0;    char *av[BUFSIZ];
 }    char *p;
     FILE *fp;
     char dname[BUFSIZ],tname0[BUFSIZ];
     char *name,*tname;
     int encoded;
     static char prefix[BUFSIZ];
     int process_id();
     char CppExe[BUFSIZ];
     char nbuf[BUFSIZ],tnbuf[BUFSIZ];
     STRING rootdir;
     void call_exe(char *,char **);
   
 int loadfiles(node) NODE node; { return 0; }    /* create the unique prefix */
     if ( !prefix[0] )
       sprintf(prefix,"asir%d",process_id());
   
 int finder_loadfile() {    fp = fopen(name0,"rb");
         Point p;    if ( getc(fp) == 0xff ) {
         SFTypeList t;      /* encoded file */
         SFReply r;      fclose(fp);
         int ret;      name = tempnam(NULL,prefix);
       decrypt_file(name0,name);
         p.h = p.v = 50; t[0] = 'TEXT';      /* the file 'name' created */
         SFGetFile(p,"\p",0,1,t,0,&r);      encoded = 1;
         if ( r.good ) {    } else {
                 setDir(r.vRefNum);      fclose(fp);
                 ret = loadfile(PtoCstr(r.fName));      name = name0;
                 resetDir();      encoded = 0;
                 return ret;    }
         } else  
                 return 0;  
 }  
   
 #else  
 #if defined(NeXT)  
 #include <rld.h>  
 #include <ldsyms.h>  
   
 void loadmachofile(char **);    strcpy(dname,name);
 void unloadmachofile(void);    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";
   
 int loadfile(s)    /* set the include directory */
 char *s;    p = strrchr(dname,DELIM);
 {    if ( !p ) {
         FILE *in;      av[5] = 0; ac = 5;
         unsigned magic;    } else {
         char **oname;      *p = 0;
       sprintf(ibuf2,"-I\"%s\"",dname);
       av[5] = ibuf2;
       av[6] = 0; ac = 6;
     }
   //  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 ) {
       unlink(name); free(name);
   
         if ( in = fopen(s,"r") ) {      strcpy(tname0,tname); free(tname);
                 fread(&magic,sizeof(unsigned),1,in); fclose(in);      tname = tempnam(NULL,prefix);
                 if (magic == MH_MAGIC) {  
                         oname = (char **)ALLOCA(BUFSIZ);  
                         oname[0] = s; oname[1] = "/usr/lib/libm.a",oname[2] = 0;  
                         loadmachofile(oname);  
                 } else  
                         loadasirfile(s);  
                 return 1;  
         } else  
                 return 0;  
 }  
   
 int loadfiles(node)      encrypt_file(tname0,tname);
 NODE node;      /* the file tname created */
 {      unlink(tname0);
         int i;  
         NODE n;  
         char *name;  
         char **oname;  
   
         for ( i = 0, n = node; n; i++, n = NEXT(n) );      in = fopen(tname,"rb");
                 if ( OID(BDY(n)) != O_STR )    } else
                         return 0;      in = fopen(tname,"r");
         oname = (char **)ALLOCA(i+1);    if ( !in ) {
         for ( i = 0, n = node; n; i++, n = NEXT(n) ) {      perror("fopen");
                 searchasirpath(BDY((STRING)BDY(node)),&name);      error("load : failed");
                 if ( !name )    }
                         return 0;    t = (INFILE)MALLOC(sizeof(struct oINFILE));
                 else    t->name = (char *)MALLOC(strlen(name0)+1); strcpy(t->name,name0);
                         oname[i] = name;    t->tname = (char *)MALLOC(strlen(tname)+1); strcpy(t->tname,tname); free(tname);
         }    t->encoded = encoded;
         oname[i] = 0;  #else
         loadmachofile(oname);    char com[BUFSIZ];
         return 1;  
 }  
   
 static NXStream *nxs = 0;    sprintf(com,"%s -I%s -D__FILE__=%s %s",cppname,asir_libdir,name0,name0); in = popen(com,"r");
     if ( !in ) {
 void loadmachofile(oname)      perror("popen");
 char **oname;      error("load : failed");
 {    }
         struct mach_header *h;    t = (INFILE)MALLOC(sizeof(struct oINFILE));
         unsigned int data_start,data_end;    t->name = (char *)MALLOC(strlen(name0)+1); strcpy(t->name,name0);
         struct section *tsec,*dsec,*bsec,*csec;  
         struct section *getsectbynamefromheader();  
   
         if ( !nxs )  
                 nxs = NXOpenFile(fileno(stderr),NX_WRITEONLY);  
         if ( rld_load(nxs,&h,oname,"/tmp/afo") ) {  
                 tsec = getsectbynamefromheader(h,"__TEXT","__text");  
                 dsec = getsectbynamefromheader(h,"__DATA","__data");  
                 bsec = getsectbynamefromheader(h,"__DATA","__bss");  
                 csec = getsectbynamefromheader(h,"__DATA","__common");  
                 data_start = dsec->addr; data_end = dsec->addr+dsec->size;  
                 if ( bsec->size ) {  
                         data_start = MIN(data_start,bsec->addr);  
                         data_end = MAX(data_end,(bsec->addr+bsec->size));  
                 }  
                 if ( csec->size ) {  
                         data_start = MIN(data_start,csec->addr);  
                         data_end = MAX(data_end,(csec->addr+csec->size));  
                 }  
 #if 0  
                 if ( data_start != data_end )  
                         add_data(data_start,data_end);  
 #endif  #endif
                 (*(int(*)())(tsec->addr))();    t->fp = in; t->ln = 1; t->next = asir_infile; asir_infile = t;
         } else if ( nxs )    main_parser = 1; /* XXX */
                 NXFlush(nxs);    Eungetc(afternl(),asir_infile->fp);
     if ( !EPVS->va )
       asir_reallocarray((char **)&EPVS->va,(int *)&EPVS->asize,(int *)&EPVS->n,(int)sizeof(struct oPV));
 }  }
   
 void unloadmachofile()  void execasirfile(char *name)
 {  {
         if ( !rld_unload(nxs) && nxs )    loadasirfile(name);
                 NXFlush(nxs);    if ( !SETJMP(asir_infile->jmpbuf) ) {
       asir_infile->ready_for_longjmp = 1;
       read_eval_loop();
     }
     closecurrentinput();
 }  }
   
 #else  static NODE objfile = 0;
 #ifdef mips  
 #include <sys/exec.h>  
 #else  
 #include <a.out.h>  
 #endif  
   
 void loadaoutfile(/* char ** */);  int loadfile(char *s)
   
 int loadfiles(node) NODE node; { return 0; }  
   
 int loadfile(s)  
 char *s;  
 {  {
         FILE *in;    FILE *in;
         struct exec h;  
         char **oname;  
   
         if ( in = fopen(s,"r") ) {    if ( in = fopen(s,"r") ) {
                 fread(&h,sizeof(h),1,in); fclose(in);      fclose(in);
 #if defined(__NetBSD__)      loadasirfile(s);
                 if ((N_GETMAGIC(h) == OMAGIC) || (N_GETMAGIC(h) == ZMAGIC)) {      return 1;
 #else    } else
                 if ((h.a_magic == OMAGIC) || (h.a_magic == ZMAGIC)) {      return 0;
 #endif  
                         oname = (char **)ALLOCA(BUFSIZ);  
                         oname[0] = s; oname[1] = 0;  
                         loadaoutfile(oname);  
                 } else  
                         loadasirfile(s);  
                 return 1;  
         } else  
                 return 0;  
 }  }
   
 #if 0  int loadfiles(NODE node) { return 0; }
 void loadaoutfile(name)  
 char **name;  
 {  
 #include <sys/wait.h>  
         FILE *in;  
         char *tmpf,*buf;  
         char **n;  
         NODE tn;  
         struct exec h;  
         char com[BUFSIZ];  
         char *ldargv[256];  
         char nbuf[BUFSIZ];  
         int i,w;  
         union wait status;  
         static char ldcom1[] = "ld -d -N -x -A %s -T %x ";  
         static char ldcom2[] = " -lm -lc -o ";  
         extern char asirname[];  
   
         tmpf = tempnam(0,"asir");  
         ldargv[0] = "ld"; ldargv[1] = "-d"; ldargv[2] = "-N";  
         ldargv[3] = "-x"; ldargv[4] = "-A"; ldargv[5] = asirname;  
         ldargv[6] = "-T"; ldargv[7] = "0";  
         for ( i = 8, n = name; *n; n++, i++ )  
                 ldargv[i] = *n;  
         ldargv[i++] = "-lm"; ldargv[i++] = "-lc"; ldargv[i++] = "-o";  
         ldargv[i++] = tmpf; ldargv[i] = 0;  
         if ( !vfork() ) {  
                 if ( execv("/bin/ld",ldargv) < 0 )  
                         _exit(0);  
         } else  
                 wait(&status);  
         if ( status.w_status ) {  
                 error("loadaoutfile : faild");  
         }  
         in = fopen(tmpf,"r"); fread(&h,sizeof(h),1,in);  
         fclose(in); unlink(tmpf);  
         buf = (char *)CALLOC(h.a_text+h.a_data+h.a_bss,1);  
         sprintf(nbuf,"%x",buf); ldargv[7] = nbuf;  
         if ( !vfork() ) {  
                 if ( execv("/bin/ld",ldargv) < 0 );  
                         _exit(0);  
         } else  
                 wait(&status);  
         in = fopen(tmpf,"r"); fread(&h,sizeof(h),1,in);  
 #ifdef mips  
         fseek(in,N_TXTOFF(h.ex_f,h.ex_o),0);  
 #endif  
         fread(buf,h.a_text+h.a_data,1,in);  
         MKNODE(tn,buf,objfile); objfile = tn;  
         (*(int(*)())buf)();  
         fclose(in); unlink(tmpf);  
 }  
 #endif  
   
 #if 1  
 void loadaoutfile(name)  
 char **name;  
 {  
         FILE *in;  
         char *tmpf,*buf,*p;  
         char **n;  
         NODE tn;  
         struct exec h;  
         char com[BUFSIZ];  
         int status,i,len;  
 #ifdef mips  
         static char ldcom1[] = "ld -G 0 -d -N -x -A %s -T %x ";  
         static char ldcom2[] = " -lm_G0 -lc -o ";  
 #else  
         static char ldcom1[] = "ld -d -N -x -A %s -T %x ";  
         static char ldcom2[] = " -lm -lc -o ";  
 #endif  
         extern char asirname[];  
   
         tmpf = tempnam(0,"asir");  
         sprintf(com,ldcom1,asirname,0);  
         for ( n = name; *n; n++ )  
                 strcat(com,*n);  
         strcat(com,ldcom2); strcat(com,tmpf);  
         status = system(com);  
         if ( status ) {  
                 fprintf(stderr,"system() : status = %d\n",status);  
                 error("loadaoutfile : could not exec system()");  
         }  
         in = fopen(tmpf,"r");  
         fread(&h,sizeof(h),1,in);  
         fclose(in); unlink(tmpf);  
         buf = (char *)CALLOC(h.a_text+h.a_data+h.a_bss,1);  
         sprintf(com,ldcom1,asirname,buf);  
         for ( n = name; *n; n++ )  
                 strcat(com,*n);  
         strcat(com,ldcom2); strcat(com,tmpf);  
         system(com);  
         in = fopen(tmpf,"r"); fread(&h,sizeof(h),1,in);  
 #ifdef mips  
         fseek(in,N_TXTOFF(h.ex_f,h.ex_o),0);  
 #endif  
         len = h.a_text+h.a_data; fread(buf,1,len,in);  
         /* to avoid a bug on RISC-NEWS */  
         fprintf(stderr,"text=%d data=%d bss=%d\n",h.a_text,h.a_data,h.a_bss);  
         MKNODE(tn,buf,objfile); objfile = tn;  
 /*      fprintf(stderr,"calling reg_sysf()...\n");  */  
         (*(int(*)())buf)();  
         fclose(in); unlink(tmpf);  
 }  
 #endif  
 #endif  
 #endif  
 #endif  
   
 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},
 {55,223},{75,65},{178,151},{85,222},{201,46},{51,243},{235,61},{106,113},  {55,223},{75,65},{178,151},{85,222},{201,46},{51,243},{235,61},{106,113},
Line 644  static unsigned char decrypt_tab[] = {
Line 450  static unsigned char decrypt_tab[] = {
   
 unsigned char encrypt_char(unsigned char c)  unsigned char encrypt_char(unsigned char c)
 {  {
         return encrypt_tab[c][mt_genrand()&1];    return encrypt_tab[c][mt_genrand()&1];
 }  }
   
 unsigned char decrypt_char(unsigned char c)  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;
   
         infp = fopen(in,"r");    infp = fopen(in,"r");
         outfp = fopen(out,"wb");    outfp = fopen(out,"wb");
         while ( 1 ) {    while ( 1 ) {
                 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;
   
         infp = fopen(in,"rb");    infp = fopen(in,"rb");
         outfp = fopen(out,"w");    outfp = fopen(out,"w");
         /* skip the magic number (=0xff) */    /* skip the magic number (=0xff) */
         getc(infp);    getc(infp);
         while ( 1 ) {    while ( 1 ) {
                 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.1.1.1  
changed lines
  Added in v.1.33

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