version 1.25, 2008/11/18 09:17:31 |
version 1.36, 2017/06/12 06:22:50 |
|
|
* 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.24 2006/11/08 07:34:33 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/builtin/file.c,v 1.35 2017/06/10 05:32:24 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) |
#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> |
/* #define ECGEN_KEYNAME "SoftWare\\Fujitsu\\WinECgen\\1.00.000" */ |
/* #define ECGEN_KEYNAME "SoftWare\\Fujitsu\\WinECgen\\1.00.000" */ |
#define ECGEN_KEYNAME "SoftWare\\Fujitsu\\FSEcParamGen\\V1.0L10" |
#define ECGEN_KEYNAME "SoftWare\\Fujitsu\\FSEcParamGen\\V1.0L10" |
#define ASIR_KEYNAME "SoftWare\\Fujitsu\\Asir\\1999.03.31" |
#define ASIR_KEYNAME "SoftWare\\Fujitsu\\Asir\\1999.03.31" |
|
#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 80 void Pput_word(), Pget_word(); |
|
Line 83 void Pput_word(), Pget_word(); |
|
void Ppurge_stdin(); |
void Ppurge_stdin(); |
void Pfprintf(); |
void Pfprintf(); |
void Pimport(); |
void Pimport(); |
|
void Pgetpid(); |
|
|
extern int des_encryption; |
extern int des_encryption; |
extern char *asir_libdir; |
extern char *asir_libdir; |
Line 104 struct ftab file_tab[] = { |
|
Line 108 struct ftab file_tab[] = { |
|
{"bsave",Pbsave,2}, |
{"bsave",Pbsave,2}, |
{"bload",Pbload,1}, |
{"bload",Pbload,1}, |
{"get_rootdir",Pget_rootdir,0}, |
{"get_rootdir",Pget_rootdir,0}, |
#if defined(VISUAL) && defined(DES_ENC) |
#if defined(DES_ENC) |
{"bsave_enc",Pbsave_enc,2}, |
{"bsave_enc",Pbsave_enc,2}, |
{"bload_enc",Pbload_enc,1}, |
{"bload_enc",Pbload_enc,1}, |
#endif |
#endif |
Line 113 struct ftab file_tab[] = { |
|
Line 117 struct ftab file_tab[] = { |
|
{"bload_compat",Pbload_compat,1}, |
{"bload_compat",Pbload_compat,1}, |
{"bsave_cmo",Pbsave_cmo,2}, |
{"bsave_cmo",Pbsave_cmo,2}, |
{"bload_cmo",Pbload_cmo,1}, |
{"bload_cmo",Pbload_cmo,1}, |
|
{"getpid",Pgetpid,0}, |
{0,0,0}, |
{0,0,0}, |
}; |
}; |
|
|
Line 131 void Pfprintf(NODE arg,pointer *rp) |
|
Line 136 void Pfprintf(NODE arg,pointer *rp) |
|
if ( arg ) { |
if ( arg ) { |
Psprintf(arg,&s); |
Psprintf(arg,&s); |
fputs(BDY(s),fp); |
fputs(BDY(s),fp); |
fflush(fp); |
/* fflush(fp); */ |
} |
} |
*rp = 0; |
*rp = 0; |
return; |
return; |
Line 166 void Popen_file(NODE arg,Q *rp) |
|
Line 171 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 236 void Pget_line(NODE arg,STRING *rp) |
|
Line 241 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 503 void Pbload_cmo(NODE arg,Obj *rp) |
|
Line 514 void Pbload_cmo(NODE arg,Obj *rp) |
|
|
|
static struct oSTRING rootdir; |
static struct oSTRING rootdir; |
|
|
#if defined(VISUAL) |
#if defined(VISUAL) || defined(__MINGW32__) |
void get_rootdir(char *name,int len) |
void get_rootdir(char *name,int len) |
{ |
{ |
LONG ret; |
LONG ret; |
Line 515 void get_rootdir(char *name,int len) |
|
Line 526 void get_rootdir(char *name,int len) |
|
strcpy(name,rootdir.body); |
strcpy(name,rootdir.body); |
return; |
return; |
} |
} |
|
if ( GetModuleFileName(NULL,name,BUFSIZ) ) { |
if ( access("UseCurrentDir",0) >= 0 ) { |
|
GetCurrentDirectory(BUFSIZ,name); |
|
slash = strrchr(name,'\\'); |
slash = strrchr(name,'\\'); |
if ( slash ) |
*slash = 0; |
|
slash = strrchr(name,'\\'); |
|
if ( slash ) |
*slash = 0; |
*slash = 0; |
return; |
return; |
} |
} |
Line 582 void Pget_rootdir(STRING *rp) |
|
Line 593 void Pget_rootdir(STRING *rp) |
|
*rp = &rootdir; |
*rp = &rootdir; |
} |
} |
|
|
#if defined(VISUAL) && defined(DES_ENC) |
void Pgetpid(Q *rp) |
|
{ |
|
int id; |
|
|
|
#if defined(VISUAL) || defined(__MINGW32__) |
|
id = GetCurrentProcessId(); |
|
#else |
|
id = getpid(); |
|
#endif |
|
STOQ(id,*rp); |
|
} |
|
|
|
#if defined(DES_ENC) |
void Pbsave_enc(NODE arg,Obj *rp) |
void Pbsave_enc(NODE arg,Obj *rp) |
{ |
{ |
init_deskey(); |
init_deskey(); |
Line 678 void Premove_file(NODE arg,Q *rp) |
|
Line 701 void Premove_file(NODE arg,Q *rp) |
|
|
|
void Paccess(NODE arg,Q *rp) |
void Paccess(NODE arg,Q *rp) |
{ |
{ |
#if defined(VISUAL) |
|
if ( access(BDY((STRING)ARG0(arg)),04) >= 0 ) |
|
#else |
|
if ( access(BDY((STRING)ARG0(arg)),R_OK) >= 0 ) |
if ( access(BDY((STRING)ARG0(arg)),R_OK) >= 0 ) |
#endif |
|
*rp = ONE; |
*rp = ONE; |
else |
else |
*rp = 0; |
*rp = 0; |
} |
} |
|
|
#if defined(VISUAL) |
#if defined(VISUAL) || defined(__MINGW32__) |
int process_id() |
int process_id() |
{ |
{ |
return GetCurrentProcessId(); |
return GetCurrentProcessId(); |