Annotation of OpenXM_contrib2/asir2000/builtin/file.c, Revision 1.30
1.4 noro 1: /*
2: * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
3: * All rights reserved.
4: *
5: * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited,
6: * non-exclusive and royalty-free license to use, copy, modify and
7: * redistribute, solely for non-commercial and non-profit purposes, the
8: * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
9: * conditions of this Agreement. For the avoidance of doubt, you acquire
10: * only a limited right to use the SOFTWARE hereunder, and FLL or any
11: * third party developer retains all rights, including but not limited to
12: * copyrights, in and to the SOFTWARE.
13: *
14: * (1) FLL does not grant you a license in any way for commercial
15: * purposes. You may use the SOFTWARE only for non-commercial and
16: * non-profit purposes only, such as academic, research and internal
17: * business use.
18: * (2) The SOFTWARE is protected by the Copyright Law of Japan and
19: * international copyright treaties. If you make copies of the SOFTWARE,
20: * with or without modification, as permitted hereunder, you shall affix
21: * to all such copies of the SOFTWARE the above copyright notice.
22: * (3) An explicit reference to this SOFTWARE and its copyright owner
23: * shall be made on your publication or presentation in any form of the
24: * results obtained by use of the SOFTWARE.
25: * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
1.5 noro 26: * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.4 noro 27: * for such modification or the source code of the modified part of the
28: * SOFTWARE.
29: *
30: * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
31: * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
32: * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
33: * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
34: * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
35: * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
36: * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
37: * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
38: * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
39: * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
40: * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
41: * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
42: * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
43: * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
44: * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
45: * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
46: * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
47: *
1.30 ! ohara 48: * $OpenXM: OpenXM_contrib2/asir2000/builtin/file.c,v 1.29 2013/08/20 14:22:33 ohara Exp $
1.4 noro 49: */
1.1 noro 50: #include "ca.h"
51: #include "parse.h"
1.15 noro 52: #include "ox.h"
1.1 noro 53: #include "base.h"
1.16 noro 54: #if !defined(VISUAL)
1.2 noro 55: #include "unistd.h"
1.16 noro 56: #endif
1.17 ohara 57: #if defined(PARI)
1.1 noro 58: #include "genpari.h"
1.2 noro 59: #endif
1.1 noro 60:
61: #if defined(VISUAL)
62: #include <windows.h>
1.9 noro 63: #include <process.h>
1.15 noro 64: #include <io.h>
1.1 noro 65: /* #define ECGEN_KEYNAME "SoftWare\\Fujitsu\\WinECgen\\1.00.000" */
66: #define ECGEN_KEYNAME "SoftWare\\Fujitsu\\FSEcParamGen\\V1.0L10"
67: #define ASIR_KEYNAME "SoftWare\\Fujitsu\\Asir\\1999.03.31"
1.27 ohara 68: #define R_OK 0x04
1.1 noro 69: #endif
70:
71: void Pget_rootdir();
1.30 ! ohara 72: void Pget_asirloadpath();
1.1 noro 73: void Paccess(),Premove_file();
74: void Pbsave_enc(), Pbload_enc();
75:
76: void Pload(), Pwhich(), Ploadfiles(), Poutput();
77: void Pbsave(), Pbload(), Pbload27();
78: void Pbsave_compat(), Pbload_compat();
79: void Pbsave_cmo(), Pbload_cmo();
1.13 noro 80: void Popen_file(), Pclose_file(), Pget_line(), Pget_byte(), Pput_byte();
1.24 noro 81: void Pput_word(), Pget_word();
1.10 noro 82: void Ppurge_stdin();
1.25 ohara 83: void Pfprintf();
1.22 noro 84: void Pimport();
1.28 noro 85: void Pgetpid();
1.1 noro 86:
87: extern int des_encryption;
88: extern char *asir_libdir;
1.30 ! ohara 89: extern char **ASIRLOADPATH;
1.1 noro 90:
91: struct ftab file_tab[] = {
1.25 ohara 92: {"fprintf",Pfprintf,-99999999},
1.10 noro 93: {"purge_stdin",Ppurge_stdin,0},
1.13 noro 94: {"open_file",Popen_file,-2},
1.3 noro 95: {"close_file",Pclose_file,1},
1.8 noro 96: {"get_byte",Pget_byte,1},
1.13 noro 97: {"put_byte",Pput_byte,2},
1.24 noro 98: {"get_word",Pget_word,1},
99: {"put_word",Pput_word,2},
1.10 noro 100: {"get_line",Pget_line,-1},
1.1 noro 101: {"remove_file",Premove_file,1},
102: {"access",Paccess,1},
103: {"load",Pload,-1},
1.22 noro 104: {"import",Pimport,-1},
1.1 noro 105: {"which",Pwhich,1},
106: {"loadfiles",Ploadfiles,1},
107: {"output",Poutput,-1},
108: {"bsave",Pbsave,2},
109: {"bload",Pbload,1},
110: {"get_rootdir",Pget_rootdir,0},
1.30 ! ohara 111: {"get_asirloadpath",Pget_asirloadpath,0},
1.27 ohara 112: #if defined(DES_ENC)
1.1 noro 113: {"bsave_enc",Pbsave_enc,2},
114: {"bload_enc",Pbload_enc,1},
1.6 noro 115: #endif
1.1 noro 116: {"bload27",Pbload27,1},
117: {"bsave_compat",Pbsave_compat,2},
118: {"bload_compat",Pbload_compat,1},
119: {"bsave_cmo",Pbsave_cmo,2},
120: {"bload_cmo",Pbload_cmo,1},
1.28 noro 121: {"getpid",Pgetpid,0},
1.1 noro 122: {0,0,0},
123: };
1.3 noro 124:
125: static FILE *file_ptrs[BUFSIZ];
126:
1.25 ohara 127: void Pfprintf(NODE arg,pointer *rp)
128: {
129: FILE *fp;
130: STRING s;
131: asir_assert(ARG0(arg),O_N,"fprintf");
132: fp = file_ptrs[QTOS((Q)ARG0(arg))];
133: if ( !fp ) {
134: error("fprintf : invalid argument");
135: }
136: arg = NEXT(arg);
137: if ( arg ) {
138: Psprintf(arg,&s);
139: fputs(BDY(s),fp);
1.26 ohara 140: /* fflush(fp); */
1.25 ohara 141: }
142: *rp = 0;
143: return;
144: }
145:
1.15 noro 146: void Ppurge_stdin(Q *rp)
1.10 noro 147: {
148: purge_stdin(stdin);
149: *rp = 0;
150: }
151:
1.15 noro 152: void Popen_file(NODE arg,Q *rp)
1.3 noro 153: {
154: char *name;
155: FILE *fp;
156: char errbuf[BUFSIZ];
157: int i;
158:
159: asir_assert(ARG0(arg),O_STR,"open_file");
160: for ( i = 0; i < BUFSIZ && file_ptrs[i]; i++ );
161: if ( i == BUFSIZ )
162: error("open_file : too many open files");
163: name = BDY((STRING)ARG0(arg));
1.18 takayama 164: if (strcmp(name,"unix://stdin") == 0) {
165: fp = stdin;
166: }else if (strcmp(name,"unix://stdout") == 0) {
167: fp = stdout;
168: }else if (strcmp(name,"unix://stderr") == 0) {
169: fp = stderr;
170: }else{
171: if ( argc(arg) == 2 ) {
1.13 noro 172: asir_assert(ARG1(arg),O_STR,"open_file");
173: fp = fopen(name,BDY((STRING)ARG1(arg)));
1.18 takayama 174: } else
1.13 noro 175: fp = fopen(name,"r");
1.18 takayama 176: }
1.3 noro 177: if ( !fp ) {
1.13 noro 178: sprintf(errbuf,"open_file : cannot open \"%s\"",name);
1.3 noro 179: error(errbuf);
180: }
181: file_ptrs[i] = fp;
182: STOQ(i,*rp);
183: }
184:
1.15 noro 185: void Pclose_file(NODE arg,Q *rp)
1.3 noro 186: {
187: int i;
188:
1.8 noro 189: asir_assert(ARG0(arg),O_N,"close_file");
1.3 noro 190: i = QTOS((Q)ARG0(arg));
191: if ( file_ptrs[i] ) {
192: fclose(file_ptrs[i]);
193: file_ptrs[i] = 0;
194: } else
195: error("close_file : invalid argument");
196: *rp = ONE;
197: }
198:
1.15 noro 199: void Pget_line(NODE arg,STRING *rp)
1.3 noro 200: {
201: int i,j,c;
202: FILE *fp;
203: fpos_t head;
204: char *str;
1.10 noro 205: char buf[BUFSIZ];
206:
207: if ( !arg ) {
208: #if defined(VISUAL_LIB)
209: get_string(buf,sizeof(buf));
210: #else
211: fgets(buf,sizeof(buf),stdin);
212: #endif
213: i = strlen(buf);
214: str = (char *)MALLOC_ATOMIC(i+1);
215: strcpy(str,buf);
216: MKSTR(*rp,str);
217: return;
218: }
1.3 noro 219:
1.8 noro 220: asir_assert(ARG0(arg),O_N,"get_line");
1.3 noro 221: i = QTOS((Q)ARG0(arg));
222: if ( fp = file_ptrs[i] ) {
223: if ( feof(fp) ) {
224: *rp = 0;
225: return;
226: }
227: fgetpos(fp,&head);
228: j = 0;
229: while ( 1 ) {
230: c = getc(fp);
231: if ( c == EOF ) {
232: if ( !j ) {
233: *rp = 0;
234: return;
235: } else
236: break;
237: }
238: j++;
239: if ( c == '\n' )
240: break;
241: }
242: fsetpos(fp,&head);
243: str = (char *)MALLOC_ATOMIC(j+1);
244: fgets(str,j+1,fp);
245: MKSTR(*rp,str);
246: } else
247: error("get_line : invalid argument");
1.8 noro 248: }
249:
1.15 noro 250: void Pget_byte(NODE arg,Q *rp)
1.8 noro 251: {
252: int i,c;
253: FILE *fp;
254:
255: asir_assert(ARG0(arg),O_N,"get_byte");
256: i = QTOS((Q)ARG0(arg));
257: if ( fp = file_ptrs[i] ) {
258: if ( feof(fp) ) {
259: STOQ(-1,*rp);
260: return;
261: }
262: c = getc(fp);
263: STOQ(c,*rp);
264: } else
265: error("get_byte : invalid argument");
1.13 noro 266: }
267:
1.24 noro 268: void Pget_word(NODE arg,Q *rp)
269: {
270: int i,c;
271: FILE *fp;
272:
273: asir_assert(ARG0(arg),O_N,"get_word");
274: i = QTOS((Q)ARG0(arg));
275: if ( fp = file_ptrs[i] ) {
276: if ( feof(fp) ) {
277: error("get_word : end of file");
278: return;
279: }
280: read_int(fp,&c);
281: STOQ(c,*rp);
282: } else
283: error("get_word : invalid argument");
284: }
285:
1.20 noro 286: void Pput_byte(NODE arg,Obj *rp)
1.13 noro 287: {
1.20 noro 288: int i,j,c;
1.13 noro 289: FILE *fp;
1.20 noro 290: Obj obj;
291: TB tb;
1.13 noro 292:
293: asir_assert(ARG0(arg),O_N,"put_byte");
294: i = QTOS((Q)ARG0(arg));
1.20 noro 295: if ( !(fp = file_ptrs[i]) )
296: error("put_byte : invalid argument");
297:
298: obj = (Obj)ARG1(arg);
299: if ( !obj || OID(obj) == O_N ) {
300: c = QTOS((Q)obj);
1.13 noro 301: putc(c,fp);
1.20 noro 302: } else if ( OID(obj) == O_STR )
303: fputs(BDY((STRING)obj),fp);
304: else if ( OID(obj) == O_TB ) {
305: tb = (TB)obj;
306: for ( j = 0; j < tb->next; j++ )
307: fputs(tb->body[j],fp);
308: }
309: *rp = obj;
1.3 noro 310: }
1.1 noro 311:
1.24 noro 312: void Pput_word(NODE arg,Obj *rp)
313: {
314: int i,c;
315: FILE *fp;
316: Obj obj;
317:
318: asir_assert(ARG0(arg),O_N,"put_word");
319: asir_assert(ARG1(arg),O_N,"put_word");
320: i = QTOS((Q)ARG0(arg));
321: if ( !(fp = file_ptrs[i]) )
322: error("put_word : invalid argument");
323:
324: obj = (Q)ARG1(arg);
325: c = QTOS((Q)obj);
326: write_int(fp,&c);
327: *rp = obj;
328: }
329:
1.15 noro 330: void Pload(NODE arg,Q *rp)
1.1 noro 331: {
332: int ret = 0;
333: char *name,*name0;
334: char errbuf[BUFSIZ];
335:
1.23 noro 336: if ( !arg ) error("load : invalid argument");
1.1 noro 337: if ( ARG0(arg) ) {
338: switch (OID(ARG0(arg))) {
339: case O_STR:
340: name0 = BDY((STRING)ARG0(arg));
341: searchasirpath(name0,&name);
342: if ( !name ) {
343: sprintf(errbuf,"load : \"%s\" not found in the search path",name0);
344: error(errbuf);
345: }
1.22 noro 346: execasirfile(name);
1.1 noro 347: break;
348: default:
349: error("load : invalid argument");
350: break;
351: }
352: }
1.14 noro 353: STOQ(ret,*rp);
354: }
355:
1.21 noro 356: NODE imported_files;
357:
358: void Pimport(NODE arg,Q *rp)
359: {
1.22 noro 360: char *name;
361: NODE t,p,opt;
362:
363: name = BDY((STRING)ARG0(arg));
364: for ( t = imported_files; t; t = NEXT(t) )
365: if ( !strcmp((char *)BDY(t),name) ) break;
366: if ( !t ) {
367: Pload(arg,rp);
368: MKNODE(t,name,imported_files);
369: imported_files = t;
370: return;
371: } else if ( current_option ) {
372: for ( opt = current_option; opt; opt = NEXT(opt) ) {
373: p = BDY((LIST)BDY(opt));
374: if ( !strcmp(BDY((STRING)BDY(p)),"reimport") && BDY(NEXT(p)) ) {
375: Pload(arg,rp);
376: return;
1.21 noro 377: }
378: }
1.15 noro 379: }
1.22 noro 380: *rp = 0;
1.1 noro 381: }
382:
1.15 noro 383: void Pwhich(NODE arg,STRING *rp)
1.1 noro 384: {
385: char *name;
386: STRING str;
387:
388: switch (OID(ARG0(arg))) {
389: case O_STR:
390: searchasirpath(BDY((STRING)ARG0(arg)),&name);
391: break;
392: default:
393: name = 0;
394: break;
395: }
396: if ( name ) {
397: MKSTR(str,name); *rp = str;
398: } else
399: *rp = 0;
400: }
401:
1.15 noro 402: void Ploadfiles(NODE arg,Q *rp)
1.1 noro 403: {
404: int ret;
405:
406: if ( ARG0(arg) )
407: if ( OID(ARG0(arg)) != O_LIST )
408: ret = 0;
409: else
410: ret = loadfiles(BDY((LIST)ARG0(arg)));
411: else
412: ret = 0;
413: STOQ(ret,*rp);
414: }
415:
1.15 noro 416: void Poutput(NODE arg,Q *rp)
1.1 noro 417: {
1.17 ohara 418: #if defined(PARI)
1.1 noro 419: extern FILE *outfile;
420: #endif
421: FILE *fp;
422:
423: fflush(asir_out);
424: if ( asir_out != stdout )
425: fclose(asir_out);
426: switch ( argc(arg) ) {
427: case 0:
428: fp = stdout; break;
429: case 1:
430: asir_assert(ARG0(arg),O_STR,"output");
431: fp = fopen(((STRING)ARG0(arg))->body,"a+");
432: if ( !fp )
433: error("output : invalid filename");
434: break;
435: }
1.17 ohara 436: #if defined(PARI)
1.1 noro 437: pari_outfile =
438: #endif
439: asir_out = fp;
440: *rp = ONE;
441: }
442:
443: extern int ox_file_io;
444:
1.15 noro 445: void Pbsave(NODE arg,Q *rp)
1.1 noro 446: {
447: FILE *fp;
448: VL vl,t;
449:
450: asir_assert(ARG1(arg),O_STR,"bsave");
451: get_vars_recursive(ARG0(arg),&vl);
452: for ( t = vl; t; t = NEXT(t) )
453: if ( t->v->attr == (pointer)V_UC )
454: error("bsave : not implemented");
455: fp = fopen(BDY((STRING)ARG1(arg)),"wb");
456: if ( !fp )
457: error("bsave : invalid filename");
458: ox_file_io = 1; /* network byte order is used */
459: savevl(fp,vl);
460: saveobj(fp,ARG0(arg));
461: fclose(fp);
462: ox_file_io = 0;
463: *rp = ONE;
464: }
465:
1.15 noro 466: void Pbload(NODE arg,Obj *rp)
1.1 noro 467: {
468: FILE *fp;
469:
470: asir_assert(ARG0(arg),O_STR,"bload");
471: fp = fopen(BDY((STRING)ARG0(arg)),"rb");
472: if ( !fp )
473: error("bload : invalid filename");
474: ox_file_io = 1; /* network byte order is used */
475: loadvl(fp);
476: loadobj(fp,rp);
477: fclose(fp);
478: ox_file_io = 0;
479: }
480:
1.15 noro 481: void Pbsave_cmo(NODE arg,Q *rp)
1.1 noro 482: {
483: FILE *fp;
484:
485: asir_assert(ARG1(arg),O_STR,"bsave_cmo");
486: fp = fopen(BDY((STRING)ARG1(arg)),"wb");
487: if ( !fp )
488: error("bsave_cmo : invalid filename");
489: ox_file_io = 1; /* network byte order is used */
490: write_cmo(fp,ARG0(arg));
491: fclose(fp);
492: ox_file_io = 0;
493: *rp = ONE;
494: }
495:
1.15 noro 496: void Pbload_cmo(NODE arg,Obj *rp)
1.1 noro 497: {
498: FILE *fp;
499:
500: asir_assert(ARG0(arg),O_STR,"bload_cmo");
501: fp = fopen(BDY((STRING)ARG0(arg)),"rb");
502: if ( !fp )
503: error("bload_cmo : invalid filename");
504: ox_file_io = 1; /* network byte order is used */
505: read_cmo(fp,rp);
506: fclose(fp);
507: ox_file_io = 0;
508: }
509:
1.7 noro 510: static struct oSTRING rootdir;
511:
1.1 noro 512: #if defined(VISUAL)
1.15 noro 513: void get_rootdir(char *name,int len)
1.1 noro 514: {
515: LONG ret;
516: HKEY hOpenKey;
517: DWORD Type;
1.7 noro 518: char *slash;
1.12 noro 519:
1.7 noro 520: if ( rootdir.body ) {
521: strcpy(name,rootdir.body);
1.12 noro 522: return;
523: }
1.29 ohara 524: if ( GetModuleFileName(NULL,name,BUFSIZ) ) {
525: slash = strrchr(name,'\\');
526: *slash = 0;
1.12 noro 527: slash = strrchr(name,'\\');
1.29 ohara 528: if ( slash )
1.12 noro 529: *slash = 0;
1.7 noro 530: return;
531: }
1.1 noro 532: name[0] = 0;
533: ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, ECGEN_KEYNAME, 0,
534: KEY_QUERY_VALUE, &hOpenKey);
535: if ( ret != ERROR_SUCCESS )
536: ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, ASIR_KEYNAME, 0,
537: KEY_QUERY_VALUE, &hOpenKey);
538: if( ret == ERROR_SUCCESS ) {
539: RegQueryValueEx(hOpenKey, "Directory", NULL, &Type, name, &len);
540: RegCloseKey(hOpenKey);
1.7 noro 541: } else {
542: GetCurrentDirectory(len,name);
543: slash = strrchr(name,'\\');
544: if ( slash )
545: *slash = 0;
1.1 noro 546: }
547: }
1.7 noro 548:
1.15 noro 549: void set_rootdir(char *name)
1.7 noro 550: {
551: static char DirName[BUFSIZ];
552:
553: strcpy(DirName,name);
554: rootdir.id = O_STR;
555: rootdir.body = DirName;
556: asir_libdir = DirName;
557: /* XXX */
558: env_init();
559: }
560:
1.1 noro 561: #else
1.15 noro 562: void get_rootdir(char *name,int len)
1.1 noro 563: {
564: strcpy(name,asir_libdir);
565: }
1.7 noro 566:
1.15 noro 567: void set_rootdir(char *name)
1.7 noro 568: {
569: static char DirName[BUFSIZ];
570:
571: strcpy(DirName,name);
572: asir_libdir = DirName;
573: /* XXX */
574: env_init();
575: }
576:
1.1 noro 577: #endif
578:
1.15 noro 579: void Pget_rootdir(STRING *rp)
1.1 noro 580: {
581: static char DirName[BUFSIZ];
582:
583: if ( !rootdir.body ) {
584: get_rootdir(DirName,sizeof(DirName));
585: rootdir.id = O_STR;
586: rootdir.body = DirName;
587: }
588: *rp = &rootdir;
589: }
590:
1.30 ! ohara 591: void Pget_asirloadpath(LIST *rp)
! 592: {
! 593: STRING s;
! 594: int i;
! 595: NODE t,prev;
! 596: if( ASIRLOADPATH[0] == NULL ) {
! 597: *rp = NULL;
! 598: return;
! 599: }
! 600: for(i=0; ASIRLOADPATH[i]; i++) {
! 601: }
! 602: for(t=0,i--; i>=0; i--) {
! 603: prev=t;
! 604: MKSTR(s,ASIRLOADPATH[i]);
! 605: MKNODE(t,s,prev);
! 606: }
! 607: MKLIST(*rp,t);
! 608: }
! 609:
1.28 noro 610: void Pgetpid(Q *rp)
611: {
612: int id;
613:
614: #if defined(VISUAL)
615: id = GetCurrentProcessId();
616: #else
617: id = getpid();
618: #endif
619: STOQ(id,*rp);
620: }
621:
1.27 ohara 622: #if defined(DES_ENC)
1.15 noro 623: void Pbsave_enc(NODE arg,Obj *rp)
1.1 noro 624: {
625: init_deskey();
626: des_encryption = 1;
627: Pbsave(arg,rp);
628: des_encryption = 0;
629: }
630:
1.15 noro 631: void Pbload_enc(NODE arg,Obj *rp)
1.1 noro 632: {
633: init_deskey();
634: des_encryption = 1;
635: Pbload(arg,rp);
636: des_encryption = 0;
637: }
1.6 noro 638: #endif
1.1 noro 639:
1.15 noro 640: void Pbload27(NODE arg,Obj *rp)
1.1 noro 641: {
642: FILE *fp;
643: Obj r;
644:
645: asir_assert(ARG0(arg),O_STR,"bload27");
646: fp = fopen(BDY((STRING)ARG0(arg)),"rb");
647: if ( !fp )
648: error("bload : invalid filename");
649: loadvl(fp);
650: loadobj(fp,&r);
651: fclose(fp);
652: bobjtoobj(BASE27,r,rp);
653: }
654:
1.15 noro 655: void Pbsave_compat(NODE arg,Q *rp)
1.1 noro 656: {
657: FILE *fp;
658: VL vl,t;
659:
660: asir_assert(ARG1(arg),O_STR,"bsave_compat");
661: get_vars_recursive(ARG0(arg),&vl);
662: for ( t = vl; t; t = NEXT(t) )
663: if ( t->v->attr == (pointer)V_UC )
664: error("bsave : not implemented");
665: fp = fopen(BDY((STRING)ARG1(arg)),"wb");
666: if ( !fp )
667: error("bsave : invalid filename");
668: /* indicator of an asir32 file */
669: putw(0,fp); putw(0,fp);
670: savevl(fp,vl);
671: saveobj(fp,ARG0(arg));
672: fclose(fp);
673: *rp = ONE;
674: }
675:
1.15 noro 676: void Pbload_compat(NODE arg,Obj *rp)
1.1 noro 677: {
678: FILE *fp;
679: unsigned int hdr[2];
680: Obj r;
681: int c;
682:
683: asir_assert(ARG0(arg),O_STR,"bload_compat");
684: fp = fopen(BDY((STRING)ARG0(arg)),"rb");
685: if ( !fp )
686: error("bload : invalid filename");
687: fread(hdr,sizeof(unsigned int),2,fp);
688: if ( !hdr[0] && !hdr[1] ) {
689: /* asir32 file or asir27 0 */
690: c = fgetc(fp);
691: if ( c == EOF ) {
692: /* asir27 0 */
693: *rp = 0;
694: } else {
695: /* asir32 file */
696: ungetc(c,fp);
697: loadvl(fp);
698: loadobj(fp,rp);
699: }
700: } else {
701: /* asir27 file */
702: rewind(fp);
703: loadvl(fp);
704: loadobj(fp,&r);
705: bobjtoobj(BASE27,r,rp);
706: }
707: fclose(fp);
708: }
709:
1.15 noro 710: void Premove_file(NODE arg,Q *rp)
1.1 noro 711: {
712: unlink((char *)BDY((STRING)ARG0(arg)));
713: *rp = ONE;
714: }
715:
1.15 noro 716: void Paccess(NODE arg,Q *rp)
1.1 noro 717: {
718: if ( access(BDY((STRING)ARG0(arg)),R_OK) >= 0 )
719: *rp = ONE;
720: else
721: *rp = 0;
722: }
1.9 noro 723:
724: #if defined(VISUAL)
725: int process_id()
726: {
727: return GetCurrentProcessId();
728: }
729:
1.15 noro 730: void call_exe(char *name,char **av)
1.9 noro 731: {
732: _spawnv(_P_WAIT,name,av);
733: }
734: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>