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

Diff for /OpenXM_contrib2/asir2000/builtin/file.c between version 1.28 and 1.37

version 1.28, 2013/02/15 07:05:49 version 1.37, 2017/09/02 04:04:41
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/builtin/file.c,v 1.27 2009/03/13 04:45:15 ohara Exp $   * $OpenXM: OpenXM_contrib2/asir2000/builtin/file.c,v 1.36 2017/06/12 06:22:50 noro Exp $
 */  */
 #include "ca.h"  #include "ca.h"
 #include "parse.h"  #include "parse.h"
 #include "ox.h"  #include "ox.h"
 #include "base.h"  #include "base.h"
 #if !defined(VISUAL)  #include <stdlib.h>
   #if !defined(VISUAL) && !defined(__MINGW32__)
 #include "unistd.h"  #include "unistd.h"
 #endif  #endif
 #if defined(PARI)  #if defined(PARI)
 #include "genpari.h"  #include "genpari.h"
 #endif  #endif
   
 #if defined(VISUAL)  #if defined(VISUAL) || defined(__MINGW32__)
 #include <windows.h>  #include <windows.h>
 #include <process.h>  #include <process.h>
 #include <io.h>  #include <io.h>
Line 68 
Line 69 
 #define R_OK 0x04  #define R_OK 0x04
 #endif  #endif
   
   void Psprintf(NODE,STRING *);
   
 void Pget_rootdir();  void Pget_rootdir();
 void Paccess(),Premove_file();  void Paccess(),Premove_file();
 void Pbsave_enc(), Pbload_enc();  void Pbsave_enc(), Pbload_enc();
Line 169  void Popen_file(NODE arg,Q *rp)
Line 172  void Popen_file(NODE arg,Q *rp)
                 asir_assert(ARG1(arg),O_STR,"open_file");                  asir_assert(ARG1(arg),O_STR,"open_file");
                 fp = fopen(name,BDY((STRING)ARG1(arg)));                  fp = fopen(name,BDY((STRING)ARG1(arg)));
           } else            } else
                 fp = fopen(name,"r");                  fp = fopen(name,"rb");
     }      }
         if ( !fp ) {          if ( !fp ) {
                 sprintf(errbuf,"open_file : cannot open \"%s\"",name);                  sprintf(errbuf,"open_file : cannot open \"%s\"",name);
Line 239  void Pget_line(NODE arg,STRING *rp)
Line 242  void Pget_line(NODE arg,STRING *rp)
                 fsetpos(fp,&head);                  fsetpos(fp,&head);
                 str = (char *)MALLOC_ATOMIC(j+1);                  str = (char *)MALLOC_ATOMIC(j+1);
                 fgets(str,j+1,fp);                  fgets(str,j+1,fp);
                   for ( i = 0; i < j; i++ )
                     if ( str[i] == '\r' ) {
                        str[i] = '\n';
                        str[i+1] = 0;
                        break;
                     }
                 MKSTR(*rp,str);                  MKSTR(*rp,str);
         } else          } else
                 error("get_line : invalid argument");                  error("get_line : invalid argument");
Line 506  void Pbload_cmo(NODE arg,Obj *rp)
Line 515  void Pbload_cmo(NODE arg,Obj *rp)
   
 static struct oSTRING rootdir;  static struct oSTRING rootdir;
   
 #if defined(VISUAL)  #if defined(VISUAL) || defined(__MINGW32__)
   static void chop_delim(char *s)
   {
       int n=strlen(s);
       if(n>1 && s[n-1]=='\\') {
           s[n-1]=0;
       }
   }
   
 void get_rootdir(char *name,int len)  void get_rootdir(char *name,int len)
 {  {
         LONG    ret;          LONG    ret;
         HKEY    hOpenKey;          HKEY    hOpenKey;
         DWORD   Type;          DWORD   Type;
         char    *slash;          char    drive[_MAX_DRIVE], dir0[_MAX_DIR], dir[_MAX_DIR];
           char    fullname[_MAX_PATH];
   
         if ( rootdir.body ) {          if ( rootdir.body ) {
                 strcpy(name,rootdir.body);                  strcpy_s(name,len,rootdir.body);
                 return;                  return;
         }          }
           if ( GetModuleFileName(NULL,fullname,_MAX_PATH) ) {
         if ( access("UseCurrentDir",0) >= 0 ) {          _splitpath(fullname,drive,dir0,NULL,NULL);
                 GetCurrentDirectory(BUFSIZ,name);          chop_delim(dir0);
                 slash = strrchr(name,'\\');          _splitpath(dir0,NULL,dir,NULL,NULL);
                 if ( slash )          chop_delim(dir);
                         *slash = 0;          strcpy_s(name,len,drive);
           strcat_s(name,len,dir);
                 return;                  return;
         }          }
         name[0] = 0;          name[0] = 0;
Line 536  void get_rootdir(char *name,int len)
Line 555  void get_rootdir(char *name,int len)
                 RegQueryValueEx(hOpenKey, "Directory", NULL, &Type, name, &len);                  RegQueryValueEx(hOpenKey, "Directory", NULL, &Type, name, &len);
                 RegCloseKey(hOpenKey);                  RegCloseKey(hOpenKey);
         } else {          } else {
                 GetCurrentDirectory(len,name);          GetCurrentDirectory(_MAX_PATH,fullname);
                 slash = strrchr(name,'\\');          _splitpath(fullname,drive,dir,NULL,NULL);
                 if ( slash )          chop_delim(dir);
                         *slash = 0;          strcpy_s(name,len,drive);
           strcat_s(name,len,dir);
         }          }
 }  }
   
Line 589  void Pgetpid(Q *rp)
Line 609  void Pgetpid(Q *rp)
 {  {
         int id;          int id;
   
 #if defined(VISUAL)  #if defined(VISUAL) || defined(__MINGW32__)
         id = GetCurrentProcessId();          id = GetCurrentProcessId();
 #else  #else
         id = getpid();          id = getpid();
Line 699  void Paccess(NODE arg,Q *rp)
Line 719  void Paccess(NODE arg,Q *rp)
                 *rp = 0;                  *rp = 0;
 }  }
   
 #if defined(VISUAL)  #if defined(VISUAL) || defined(__MINGW32__)
 int process_id()  int process_id()
 {  {
         return GetCurrentProcessId();          return GetCurrentProcessId();

Legend:
Removed from v.1.28  
changed lines
  Added in v.1.37

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