version 1.21, 2006/02/03 03:55:18 |
version 1.32, 2015/03/15 19:31:30 |
|
|
* 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.20 2004/04/26 05:28:40 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/builtin/file.c,v 1.31 2014/05/12 02:27:49 ohara Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
#include "parse.h" |
#include "parse.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 76 void Pbsave(), Pbload(), Pbload27(); |
|
Line 79 void Pbsave(), Pbload(), Pbload27(); |
|
void Pbsave_compat(), Pbload_compat(); |
void Pbsave_compat(), Pbload_compat(); |
void Pbsave_cmo(), Pbload_cmo(); |
void Pbsave_cmo(), Pbload_cmo(); |
void Popen_file(), Pclose_file(), Pget_line(), Pget_byte(), Pput_byte(); |
void Popen_file(), Pclose_file(), Pget_line(), Pget_byte(), Pput_byte(); |
|
void Pput_word(), Pget_word(); |
void Ppurge_stdin(); |
void Ppurge_stdin(); |
void Pexec(),Pimport(); |
void Pfprintf(); |
|
void Pimport(); |
|
void Pgetpid(); |
|
|
extern int des_encryption; |
extern int des_encryption; |
extern char *asir_libdir; |
extern char *asir_libdir; |
|
|
struct ftab file_tab[] = { |
struct ftab file_tab[] = { |
|
{"fprintf",Pfprintf,-99999999}, |
{"purge_stdin",Ppurge_stdin,0}, |
{"purge_stdin",Ppurge_stdin,0}, |
{"open_file",Popen_file,-2}, |
{"open_file",Popen_file,-2}, |
{"close_file",Pclose_file,1}, |
{"close_file",Pclose_file,1}, |
{"get_byte",Pget_byte,1}, |
{"get_byte",Pget_byte,1}, |
{"put_byte",Pput_byte,2}, |
{"put_byte",Pput_byte,2}, |
|
{"get_word",Pget_word,1}, |
|
{"put_word",Pput_word,2}, |
{"get_line",Pget_line,-1}, |
{"get_line",Pget_line,-1}, |
{"remove_file",Premove_file,1}, |
{"remove_file",Premove_file,1}, |
{"access",Paccess,1}, |
{"access",Paccess,1}, |
{"load",Pload,-1}, |
{"load",Pload,-1}, |
{"exec",Pexec,1}, |
{"import",Pimport,-1}, |
{"import",Pimport,1}, |
|
{"which",Pwhich,1}, |
{"which",Pwhich,1}, |
{"loadfiles",Ploadfiles,1}, |
{"loadfiles",Ploadfiles,1}, |
{"output",Poutput,-1}, |
{"output",Poutput,-1}, |
{"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 109 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}, |
}; |
}; |
|
|
static FILE *file_ptrs[BUFSIZ]; |
static FILE *file_ptrs[BUFSIZ]; |
|
|
|
void Pfprintf(NODE arg,pointer *rp) |
|
{ |
|
FILE *fp; |
|
STRING s; |
|
asir_assert(ARG0(arg),O_N,"fprintf"); |
|
fp = file_ptrs[QTOS((Q)ARG0(arg))]; |
|
if ( !fp ) { |
|
error("fprintf : invalid argument"); |
|
} |
|
arg = NEXT(arg); |
|
if ( arg ) { |
|
Psprintf(arg,&s); |
|
fputs(BDY(s),fp); |
|
/* fflush(fp); */ |
|
} |
|
*rp = 0; |
|
return; |
|
} |
|
|
void Ppurge_stdin(Q *rp) |
void Ppurge_stdin(Q *rp) |
{ |
{ |
purge_stdin(stdin); |
purge_stdin(stdin); |
Line 236 void Pget_byte(NODE arg,Q *rp) |
|
Line 264 void Pget_byte(NODE arg,Q *rp) |
|
error("get_byte : invalid argument"); |
error("get_byte : invalid argument"); |
} |
} |
|
|
|
void Pget_word(NODE arg,Q *rp) |
|
{ |
|
int i,c; |
|
FILE *fp; |
|
|
|
asir_assert(ARG0(arg),O_N,"get_word"); |
|
i = QTOS((Q)ARG0(arg)); |
|
if ( fp = file_ptrs[i] ) { |
|
if ( feof(fp) ) { |
|
error("get_word : end of file"); |
|
return; |
|
} |
|
read_int(fp,&c); |
|
STOQ(c,*rp); |
|
} else |
|
error("get_word : invalid argument"); |
|
} |
|
|
void Pput_byte(NODE arg,Obj *rp) |
void Pput_byte(NODE arg,Obj *rp) |
{ |
{ |
int i,j,c; |
int i,j,c; |
Line 262 void Pput_byte(NODE arg,Obj *rp) |
|
Line 308 void Pput_byte(NODE arg,Obj *rp) |
|
*rp = obj; |
*rp = obj; |
} |
} |
|
|
|
void Pput_word(NODE arg,Obj *rp) |
|
{ |
|
int i,c; |
|
FILE *fp; |
|
Obj obj; |
|
|
|
asir_assert(ARG0(arg),O_N,"put_word"); |
|
asir_assert(ARG1(arg),O_N,"put_word"); |
|
i = QTOS((Q)ARG0(arg)); |
|
if ( !(fp = file_ptrs[i]) ) |
|
error("put_word : invalid argument"); |
|
|
|
obj = (Q)ARG1(arg); |
|
c = QTOS((Q)obj); |
|
write_int(fp,&c); |
|
*rp = obj; |
|
} |
|
|
void Pload(NODE arg,Q *rp) |
void Pload(NODE arg,Q *rp) |
{ |
{ |
int ret = 0; |
int ret = 0; |
char *name,*name0; |
char *name,*name0; |
char errbuf[BUFSIZ]; |
char errbuf[BUFSIZ]; |
|
|
|
if ( !arg ) error("load : invalid argument"); |
if ( ARG0(arg) ) { |
if ( ARG0(arg) ) { |
switch (OID(ARG0(arg))) { |
switch (OID(ARG0(arg))) { |
case O_STR: |
case O_STR: |
Line 277 void Pload(NODE arg,Q *rp) |
|
Line 342 void Pload(NODE arg,Q *rp) |
|
sprintf(errbuf,"load : \"%s\" not found in the search path",name0); |
sprintf(errbuf,"load : \"%s\" not found in the search path",name0); |
error(errbuf); |
error(errbuf); |
} |
} |
ret = loadfile(name); |
execasirfile(name); |
if ( !ret ) { |
|
sprintf(errbuf,"load : \"%s\" could not be loaded",name); |
|
error(errbuf); |
|
} |
|
break; |
break; |
default: |
default: |
error("load : invalid argument"); |
error("load : invalid argument"); |
Line 291 void Pload(NODE arg,Q *rp) |
|
Line 352 void Pload(NODE arg,Q *rp) |
|
STOQ(ret,*rp); |
STOQ(ret,*rp); |
} |
} |
|
|
void Pexec(NODE arg,Q *rp) |
|
{ |
|
int ret; |
|
char *name0,*name; |
|
|
|
name0 = BDY((STRING)ARG0(arg)); |
|
searchasirpath(name0,&name); |
|
if ( !name ) |
|
ret = -1; |
|
else { |
|
load_and_execfile(name); |
|
ret = 0; |
|
} |
|
STOQ(ret,*rp); |
|
} |
|
|
|
NODE imported_files; |
NODE imported_files; |
|
|
void Pimport(NODE arg,Q *rp) |
void Pimport(NODE arg,Q *rp) |
{ |
{ |
int ret; |
char *name; |
char *name0,*name; |
NODE t,p,opt; |
NODE t,opt,p; |
|
|
|
name0 = BDY((STRING)ARG0(arg)); |
name = BDY((STRING)ARG0(arg)); |
searchasirpath(name0,&name); |
for ( t = imported_files; t; t = NEXT(t) ) |
if ( !name ) |
if ( !strcmp((char *)BDY(t),name) ) break; |
ret = -1; |
if ( !t ) { |
else { |
Pload(arg,rp); |
for ( t = imported_files; t; t = NEXT(t) ) |
MKNODE(t,name,imported_files); |
if ( !strcmp((char *)BDY(t),name) ) break; |
imported_files = t; |
if ( !t ) { |
return; |
load_and_execfile(name); |
} else if ( current_option ) { |
MKNODE(t,name,imported_files); |
for ( opt = current_option; opt; opt = NEXT(opt) ) { |
imported_files = t; |
p = BDY((LIST)BDY(opt)); |
} else if ( current_option ) { |
if ( !strcmp(BDY((STRING)BDY(p)),"reimport") && BDY(NEXT(p)) ) { |
for ( opt = current_option; opt; opt = NEXT(opt) ) { |
Pload(arg,rp); |
p = BDY((LIST)BDY(opt)); |
return; |
if ( !strcmp(BDY((STRING)BDY(p)),"reimport") && BDY(NEXT(p)) ) |
|
load_and_execfile(name); |
|
} |
} |
} |
} |
ret = 0; |
|
} |
} |
STOQ(ret,*rp); |
*rp = 0; |
} |
} |
|
|
void Pwhich(NODE arg,STRING *rp) |
void Pwhich(NODE arg,STRING *rp) |
Line 479 void get_rootdir(char *name,int len) |
|
Line 520 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 546 void Pget_rootdir(STRING *rp) |
|
Line 587 void Pget_rootdir(STRING *rp) |
|
*rp = &rootdir; |
*rp = &rootdir; |
} |
} |
|
|
#if defined(VISUAL) && defined(DES_ENC) |
void Pgetpid(Q *rp) |
|
{ |
|
int id; |
|
|
|
#if defined(VISUAL) |
|
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 642 void Premove_file(NODE arg,Q *rp) |
|
Line 695 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; |