version 1.1, 2018/09/19 05:45:05 |
version 1.2, 2018/09/28 08:20:27 |
|
|
* 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: OpenXM_contrib2/asir2018/builtin/file.c,v 1.1 2018/09/19 05:45:05 noro Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
#include "parse.h" |
#include "parse.h" |
Line 125 void Pfprintf(NODE arg,pointer *rp) |
|
Line 125 void Pfprintf(NODE arg,pointer *rp) |
|
FILE *fp; |
FILE *fp; |
STRING s; |
STRING s; |
asir_assert(ARG0(arg),O_N,"fprintf"); |
asir_assert(ARG0(arg),O_N,"fprintf"); |
fp = file_ptrs[QTOS((Q)ARG0(arg))]; |
fp = file_ptrs[ZTOS((Q)ARG0(arg))]; |
if ( !fp ) { |
if ( !fp ) { |
error("fprintf : invalid argument"); |
error("fprintf : invalid argument"); |
} |
} |
Line 175 void Popen_file(NODE arg,Z *rp) |
|
Line 175 void Popen_file(NODE arg,Z *rp) |
|
error(errbuf); |
error(errbuf); |
} |
} |
file_ptrs[i] = fp; |
file_ptrs[i] = fp; |
STOQ(i,*rp); |
STOZ(i,*rp); |
} |
} |
|
|
void Pclose_file(NODE arg,Z *rp) |
void Pclose_file(NODE arg,Z *rp) |
Line 183 void Pclose_file(NODE arg,Z *rp) |
|
Line 183 void Pclose_file(NODE arg,Z *rp) |
|
int i; |
int i; |
|
|
asir_assert(ARG0(arg),O_N,"close_file"); |
asir_assert(ARG0(arg),O_N,"close_file"); |
i = QTOS((Q)ARG0(arg)); |
i = ZTOS((Q)ARG0(arg)); |
if ( file_ptrs[i] ) { |
if ( file_ptrs[i] ) { |
fclose(file_ptrs[i]); |
fclose(file_ptrs[i]); |
file_ptrs[i] = 0; |
file_ptrs[i] = 0; |
Line 214 void Pget_line(NODE arg,STRING *rp) |
|
Line 214 void Pget_line(NODE arg,STRING *rp) |
|
} |
} |
|
|
asir_assert(ARG0(arg),O_N,"get_line"); |
asir_assert(ARG0(arg),O_N,"get_line"); |
i = QTOS((Q)ARG0(arg)); |
i = ZTOS((Q)ARG0(arg)); |
if ( fp = file_ptrs[i] ) { |
if ( fp = file_ptrs[i] ) { |
if ( feof(fp) ) { |
if ( feof(fp) ) { |
*rp = 0; |
*rp = 0; |
Line 255 void Pget_byte(NODE arg,Z *rp) |
|
Line 255 void Pget_byte(NODE arg,Z *rp) |
|
FILE *fp; |
FILE *fp; |
|
|
asir_assert(ARG0(arg),O_N,"get_byte"); |
asir_assert(ARG0(arg),O_N,"get_byte"); |
i = QTOS((Q)ARG0(arg)); |
i = ZTOS((Q)ARG0(arg)); |
if ( fp = file_ptrs[i] ) { |
if ( fp = file_ptrs[i] ) { |
if ( feof(fp) ) { |
if ( feof(fp) ) { |
STOQ(-1,*rp); |
STOZ(-1,*rp); |
return; |
return; |
} |
} |
c = getc(fp); |
c = getc(fp); |
STOQ(c,*rp); |
STOZ(c,*rp); |
} else |
} else |
error("get_byte : invalid argument"); |
error("get_byte : invalid argument"); |
} |
} |
Line 273 void Pget_word(NODE arg,Z *rp) |
|
Line 273 void Pget_word(NODE arg,Z *rp) |
|
FILE *fp; |
FILE *fp; |
|
|
asir_assert(ARG0(arg),O_N,"get_word"); |
asir_assert(ARG0(arg),O_N,"get_word"); |
i = QTOS((Q)ARG0(arg)); |
i = ZTOS((Q)ARG0(arg)); |
if ( fp = file_ptrs[i] ) { |
if ( fp = file_ptrs[i] ) { |
if ( feof(fp) ) { |
if ( feof(fp) ) { |
error("get_word : end of file"); |
error("get_word : end of file"); |
return; |
return; |
} |
} |
read_int(fp,&c); |
read_int(fp,&c); |
STOQ(c,*rp); |
STOZ(c,*rp); |
} else |
} else |
error("get_word : invalid argument"); |
error("get_word : invalid argument"); |
} |
} |
Line 293 void Pput_byte(NODE arg,Obj *rp) |
|
Line 293 void Pput_byte(NODE arg,Obj *rp) |
|
TB tb; |
TB tb; |
|
|
asir_assert(ARG0(arg),O_N,"put_byte"); |
asir_assert(ARG0(arg),O_N,"put_byte"); |
i = QTOS((Q)ARG0(arg)); |
i = ZTOS((Q)ARG0(arg)); |
if ( !(fp = file_ptrs[i]) ) |
if ( !(fp = file_ptrs[i]) ) |
error("put_byte : invalid argument"); |
error("put_byte : invalid argument"); |
|
|
obj = (Obj)ARG1(arg); |
obj = (Obj)ARG1(arg); |
if ( !obj || OID(obj) == O_N ) { |
if ( !obj || OID(obj) == O_N ) { |
c = QTOS((Q)obj); |
c = ZTOS((Q)obj); |
putc(c,fp); |
putc(c,fp); |
} else if ( OID(obj) == O_STR ) |
} else if ( OID(obj) == O_STR ) |
fputs(BDY((STRING)obj),fp); |
fputs(BDY((STRING)obj),fp); |
Line 319 void Pput_word(NODE arg,Obj *rp) |
|
Line 319 void Pput_word(NODE arg,Obj *rp) |
|
|
|
asir_assert(ARG0(arg),O_N,"put_word"); |
asir_assert(ARG0(arg),O_N,"put_word"); |
asir_assert(ARG1(arg),O_N,"put_word"); |
asir_assert(ARG1(arg),O_N,"put_word"); |
i = QTOS((Q)ARG0(arg)); |
i = ZTOS((Q)ARG0(arg)); |
if ( !(fp = file_ptrs[i]) ) |
if ( !(fp = file_ptrs[i]) ) |
error("put_word : invalid argument"); |
error("put_word : invalid argument"); |
|
|
obj = (Obj)ARG1(arg); |
obj = (Obj)ARG1(arg); |
c = QTOS((Q)obj); |
c = ZTOS((Q)obj); |
write_int(fp,&c); |
write_int(fp,&c); |
*rp = obj; |
*rp = obj; |
} |
} |
Line 352 void Pload(NODE arg,Z *rp) |
|
Line 352 void Pload(NODE arg,Z *rp) |
|
break; |
break; |
} |
} |
} |
} |
STOQ(ret,*rp); |
STOZ(ret,*rp); |
} |
} |
|
|
NODE imported_files; |
NODE imported_files; |
Line 412 void Ploadfiles(NODE arg,Z *rp) |
|
Line 412 void Ploadfiles(NODE arg,Z *rp) |
|
ret = loadfiles(BDY((LIST)ARG0(arg))); |
ret = loadfiles(BDY((LIST)ARG0(arg))); |
else |
else |
ret = 0; |
ret = 0; |
STOQ(ret,*rp); |
STOZ(ret,*rp); |
} |
} |
|
|
void Poutput(NODE arg,Z *rp) |
void Poutput(NODE arg,Z *rp) |
Line 610 void Pgetpid(Z *rp) |
|
Line 610 void Pgetpid(Z *rp) |
|
#else |
#else |
id = getpid(); |
id = getpid(); |
#endif |
#endif |
STOQ(id,*rp); |
STOZ(id,*rp); |
} |
} |
|
|
#if defined(DES_ENC) |
#if defined(DES_ENC) |