Annotation of OpenXM_contrib2/asir2000/builtin/file.c, Revision 1.25
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.25 ! ohara 48: * $OpenXM: OpenXM_contrib2/asir2000/builtin/file.c,v 1.24 2006/11/08 07:34:33 noro 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"
68: #endif
69:
70: void Pget_rootdir();
71: void Paccess(),Premove_file();
72: void Pbsave_enc(), Pbload_enc();
73:
74: void Pload(), Pwhich(), Ploadfiles(), Poutput();
75: void Pbsave(), Pbload(), Pbload27();
76: void Pbsave_compat(), Pbload_compat();
77: void Pbsave_cmo(), Pbload_cmo();
1.13 noro 78: void Popen_file(), Pclose_file(), Pget_line(), Pget_byte(), Pput_byte();
1.24 noro 79: void Pput_word(), Pget_word();
1.10 noro 80: void Ppurge_stdin();
1.25 ! ohara 81: void Pfprintf();
1.22 noro 82: void Pimport();
1.1 noro 83:
84: extern int des_encryption;
85: extern char *asir_libdir;
86:
87: struct ftab file_tab[] = {
1.25 ! ohara 88: {"fprintf",Pfprintf,-99999999},
1.10 noro 89: {"purge_stdin",Ppurge_stdin,0},
1.13 noro 90: {"open_file",Popen_file,-2},
1.3 noro 91: {"close_file",Pclose_file,1},
1.8 noro 92: {"get_byte",Pget_byte,1},
1.13 noro 93: {"put_byte",Pput_byte,2},
1.24 noro 94: {"get_word",Pget_word,1},
95: {"put_word",Pput_word,2},
1.10 noro 96: {"get_line",Pget_line,-1},
1.1 noro 97: {"remove_file",Premove_file,1},
98: {"access",Paccess,1},
99: {"load",Pload,-1},
1.22 noro 100: {"import",Pimport,-1},
1.1 noro 101: {"which",Pwhich,1},
102: {"loadfiles",Ploadfiles,1},
103: {"output",Poutput,-1},
104: {"bsave",Pbsave,2},
105: {"bload",Pbload,1},
106: {"get_rootdir",Pget_rootdir,0},
1.6 noro 107: #if defined(VISUAL) && defined(DES_ENC)
1.1 noro 108: {"bsave_enc",Pbsave_enc,2},
109: {"bload_enc",Pbload_enc,1},
1.6 noro 110: #endif
1.1 noro 111: {"bload27",Pbload27,1},
112: {"bsave_compat",Pbsave_compat,2},
113: {"bload_compat",Pbload_compat,1},
114: {"bsave_cmo",Pbsave_cmo,2},
115: {"bload_cmo",Pbload_cmo,1},
116: {0,0,0},
117: };
1.3 noro 118:
119: static FILE *file_ptrs[BUFSIZ];
120:
1.25 ! ohara 121: void Pfprintf(NODE arg,pointer *rp)
! 122: {
! 123: FILE *fp;
! 124: STRING s;
! 125: asir_assert(ARG0(arg),O_N,"fprintf");
! 126: fp = file_ptrs[QTOS((Q)ARG0(arg))];
! 127: if ( !fp ) {
! 128: error("fprintf : invalid argument");
! 129: }
! 130: arg = NEXT(arg);
! 131: if ( arg ) {
! 132: Psprintf(arg,&s);
! 133: fputs(BDY(s),fp);
! 134: fflush(fp);
! 135: }
! 136: *rp = 0;
! 137: return;
! 138: }
! 139:
1.15 noro 140: void Ppurge_stdin(Q *rp)
1.10 noro 141: {
142: purge_stdin(stdin);
143: *rp = 0;
144: }
145:
1.15 noro 146: void Popen_file(NODE arg,Q *rp)
1.3 noro 147: {
148: char *name;
149: FILE *fp;
150: char errbuf[BUFSIZ];
151: int i;
152:
153: asir_assert(ARG0(arg),O_STR,"open_file");
154: for ( i = 0; i < BUFSIZ && file_ptrs[i]; i++ );
155: if ( i == BUFSIZ )
156: error("open_file : too many open files");
157: name = BDY((STRING)ARG0(arg));
1.18 takayama 158: if (strcmp(name,"unix://stdin") == 0) {
159: fp = stdin;
160: }else if (strcmp(name,"unix://stdout") == 0) {
161: fp = stdout;
162: }else if (strcmp(name,"unix://stderr") == 0) {
163: fp = stderr;
164: }else{
165: if ( argc(arg) == 2 ) {
1.13 noro 166: asir_assert(ARG1(arg),O_STR,"open_file");
167: fp = fopen(name,BDY((STRING)ARG1(arg)));
1.18 takayama 168: } else
1.13 noro 169: fp = fopen(name,"r");
1.18 takayama 170: }
1.3 noro 171: if ( !fp ) {
1.13 noro 172: sprintf(errbuf,"open_file : cannot open \"%s\"",name);
1.3 noro 173: error(errbuf);
174: }
175: file_ptrs[i] = fp;
176: STOQ(i,*rp);
177: }
178:
1.15 noro 179: void Pclose_file(NODE arg,Q *rp)
1.3 noro 180: {
181: int i;
182:
1.8 noro 183: asir_assert(ARG0(arg),O_N,"close_file");
1.3 noro 184: i = QTOS((Q)ARG0(arg));
185: if ( file_ptrs[i] ) {
186: fclose(file_ptrs[i]);
187: file_ptrs[i] = 0;
188: } else
189: error("close_file : invalid argument");
190: *rp = ONE;
191: }
192:
1.15 noro 193: void Pget_line(NODE arg,STRING *rp)
1.3 noro 194: {
195: int i,j,c;
196: FILE *fp;
197: fpos_t head;
198: char *str;
1.10 noro 199: char buf[BUFSIZ];
200:
201: if ( !arg ) {
202: #if defined(VISUAL_LIB)
203: get_string(buf,sizeof(buf));
204: #else
205: fgets(buf,sizeof(buf),stdin);
206: #endif
207: i = strlen(buf);
208: str = (char *)MALLOC_ATOMIC(i+1);
209: strcpy(str,buf);
210: MKSTR(*rp,str);
211: return;
212: }
1.3 noro 213:
1.8 noro 214: asir_assert(ARG0(arg),O_N,"get_line");
1.3 noro 215: i = QTOS((Q)ARG0(arg));
216: if ( fp = file_ptrs[i] ) {
217: if ( feof(fp) ) {
218: *rp = 0;
219: return;
220: }
221: fgetpos(fp,&head);
222: j = 0;
223: while ( 1 ) {
224: c = getc(fp);
225: if ( c == EOF ) {
226: if ( !j ) {
227: *rp = 0;
228: return;
229: } else
230: break;
231: }
232: j++;
233: if ( c == '\n' )
234: break;
235: }
236: fsetpos(fp,&head);
237: str = (char *)MALLOC_ATOMIC(j+1);
238: fgets(str,j+1,fp);
239: MKSTR(*rp,str);
240: } else
241: error("get_line : invalid argument");
1.8 noro 242: }
243:
1.15 noro 244: void Pget_byte(NODE arg,Q *rp)
1.8 noro 245: {
246: int i,c;
247: FILE *fp;
248:
249: asir_assert(ARG0(arg),O_N,"get_byte");
250: i = QTOS((Q)ARG0(arg));
251: if ( fp = file_ptrs[i] ) {
252: if ( feof(fp) ) {
253: STOQ(-1,*rp);
254: return;
255: }
256: c = getc(fp);
257: STOQ(c,*rp);
258: } else
259: error("get_byte : invalid argument");
1.13 noro 260: }
261:
1.24 noro 262: void Pget_word(NODE arg,Q *rp)
263: {
264: int i,c;
265: FILE *fp;
266:
267: asir_assert(ARG0(arg),O_N,"get_word");
268: i = QTOS((Q)ARG0(arg));
269: if ( fp = file_ptrs[i] ) {
270: if ( feof(fp) ) {
271: error("get_word : end of file");
272: return;
273: }
274: read_int(fp,&c);
275: STOQ(c,*rp);
276: } else
277: error("get_word : invalid argument");
278: }
279:
1.20 noro 280: void Pput_byte(NODE arg,Obj *rp)
1.13 noro 281: {
1.20 noro 282: int i,j,c;
1.13 noro 283: FILE *fp;
1.20 noro 284: Obj obj;
285: TB tb;
1.13 noro 286:
287: asir_assert(ARG0(arg),O_N,"put_byte");
288: i = QTOS((Q)ARG0(arg));
1.20 noro 289: if ( !(fp = file_ptrs[i]) )
290: error("put_byte : invalid argument");
291:
292: obj = (Obj)ARG1(arg);
293: if ( !obj || OID(obj) == O_N ) {
294: c = QTOS((Q)obj);
1.13 noro 295: putc(c,fp);
1.20 noro 296: } else if ( OID(obj) == O_STR )
297: fputs(BDY((STRING)obj),fp);
298: else if ( OID(obj) == O_TB ) {
299: tb = (TB)obj;
300: for ( j = 0; j < tb->next; j++ )
301: fputs(tb->body[j],fp);
302: }
303: *rp = obj;
1.3 noro 304: }
1.1 noro 305:
1.24 noro 306: void Pput_word(NODE arg,Obj *rp)
307: {
308: int i,c;
309: FILE *fp;
310: Obj obj;
311:
312: asir_assert(ARG0(arg),O_N,"put_word");
313: asir_assert(ARG1(arg),O_N,"put_word");
314: i = QTOS((Q)ARG0(arg));
315: if ( !(fp = file_ptrs[i]) )
316: error("put_word : invalid argument");
317:
318: obj = (Q)ARG1(arg);
319: c = QTOS((Q)obj);
320: write_int(fp,&c);
321: *rp = obj;
322: }
323:
1.15 noro 324: void Pload(NODE arg,Q *rp)
1.1 noro 325: {
326: int ret = 0;
327: char *name,*name0;
328: char errbuf[BUFSIZ];
329:
1.23 noro 330: if ( !arg ) error("load : invalid argument");
1.1 noro 331: if ( ARG0(arg) ) {
332: switch (OID(ARG0(arg))) {
333: case O_STR:
334: name0 = BDY((STRING)ARG0(arg));
335: searchasirpath(name0,&name);
336: if ( !name ) {
337: sprintf(errbuf,"load : \"%s\" not found in the search path",name0);
338: error(errbuf);
339: }
1.22 noro 340: execasirfile(name);
1.1 noro 341: break;
342: default:
343: error("load : invalid argument");
344: break;
345: }
346: }
1.14 noro 347: STOQ(ret,*rp);
348: }
349:
1.21 noro 350: NODE imported_files;
351:
352: void Pimport(NODE arg,Q *rp)
353: {
1.22 noro 354: char *name;
355: NODE t,p,opt;
356:
357: name = BDY((STRING)ARG0(arg));
358: for ( t = imported_files; t; t = NEXT(t) )
359: if ( !strcmp((char *)BDY(t),name) ) break;
360: if ( !t ) {
361: Pload(arg,rp);
362: MKNODE(t,name,imported_files);
363: imported_files = t;
364: return;
365: } else if ( current_option ) {
366: for ( opt = current_option; opt; opt = NEXT(opt) ) {
367: p = BDY((LIST)BDY(opt));
368: if ( !strcmp(BDY((STRING)BDY(p)),"reimport") && BDY(NEXT(p)) ) {
369: Pload(arg,rp);
370: return;
1.21 noro 371: }
372: }
1.15 noro 373: }
1.22 noro 374: *rp = 0;
1.1 noro 375: }
376:
1.15 noro 377: void Pwhich(NODE arg,STRING *rp)
1.1 noro 378: {
379: char *name;
380: STRING str;
381:
382: switch (OID(ARG0(arg))) {
383: case O_STR:
384: searchasirpath(BDY((STRING)ARG0(arg)),&name);
385: break;
386: default:
387: name = 0;
388: break;
389: }
390: if ( name ) {
391: MKSTR(str,name); *rp = str;
392: } else
393: *rp = 0;
394: }
395:
1.15 noro 396: void Ploadfiles(NODE arg,Q *rp)
1.1 noro 397: {
398: int ret;
399:
400: if ( ARG0(arg) )
401: if ( OID(ARG0(arg)) != O_LIST )
402: ret = 0;
403: else
404: ret = loadfiles(BDY((LIST)ARG0(arg)));
405: else
406: ret = 0;
407: STOQ(ret,*rp);
408: }
409:
1.15 noro 410: void Poutput(NODE arg,Q *rp)
1.1 noro 411: {
1.17 ohara 412: #if defined(PARI)
1.1 noro 413: extern FILE *outfile;
414: #endif
415: FILE *fp;
416:
417: fflush(asir_out);
418: if ( asir_out != stdout )
419: fclose(asir_out);
420: switch ( argc(arg) ) {
421: case 0:
422: fp = stdout; break;
423: case 1:
424: asir_assert(ARG0(arg),O_STR,"output");
425: fp = fopen(((STRING)ARG0(arg))->body,"a+");
426: if ( !fp )
427: error("output : invalid filename");
428: break;
429: }
1.17 ohara 430: #if defined(PARI)
1.1 noro 431: pari_outfile =
432: #endif
433: asir_out = fp;
434: *rp = ONE;
435: }
436:
437: extern int ox_file_io;
438:
1.15 noro 439: void Pbsave(NODE arg,Q *rp)
1.1 noro 440: {
441: FILE *fp;
442: VL vl,t;
443:
444: asir_assert(ARG1(arg),O_STR,"bsave");
445: get_vars_recursive(ARG0(arg),&vl);
446: for ( t = vl; t; t = NEXT(t) )
447: if ( t->v->attr == (pointer)V_UC )
448: error("bsave : not implemented");
449: fp = fopen(BDY((STRING)ARG1(arg)),"wb");
450: if ( !fp )
451: error("bsave : invalid filename");
452: ox_file_io = 1; /* network byte order is used */
453: savevl(fp,vl);
454: saveobj(fp,ARG0(arg));
455: fclose(fp);
456: ox_file_io = 0;
457: *rp = ONE;
458: }
459:
1.15 noro 460: void Pbload(NODE arg,Obj *rp)
1.1 noro 461: {
462: FILE *fp;
463:
464: asir_assert(ARG0(arg),O_STR,"bload");
465: fp = fopen(BDY((STRING)ARG0(arg)),"rb");
466: if ( !fp )
467: error("bload : invalid filename");
468: ox_file_io = 1; /* network byte order is used */
469: loadvl(fp);
470: loadobj(fp,rp);
471: fclose(fp);
472: ox_file_io = 0;
473: }
474:
1.15 noro 475: void Pbsave_cmo(NODE arg,Q *rp)
1.1 noro 476: {
477: FILE *fp;
478:
479: asir_assert(ARG1(arg),O_STR,"bsave_cmo");
480: fp = fopen(BDY((STRING)ARG1(arg)),"wb");
481: if ( !fp )
482: error("bsave_cmo : invalid filename");
483: ox_file_io = 1; /* network byte order is used */
484: write_cmo(fp,ARG0(arg));
485: fclose(fp);
486: ox_file_io = 0;
487: *rp = ONE;
488: }
489:
1.15 noro 490: void Pbload_cmo(NODE arg,Obj *rp)
1.1 noro 491: {
492: FILE *fp;
493:
494: asir_assert(ARG0(arg),O_STR,"bload_cmo");
495: fp = fopen(BDY((STRING)ARG0(arg)),"rb");
496: if ( !fp )
497: error("bload_cmo : invalid filename");
498: ox_file_io = 1; /* network byte order is used */
499: read_cmo(fp,rp);
500: fclose(fp);
501: ox_file_io = 0;
502: }
503:
1.7 noro 504: static struct oSTRING rootdir;
505:
1.1 noro 506: #if defined(VISUAL)
1.15 noro 507: void get_rootdir(char *name,int len)
1.1 noro 508: {
509: LONG ret;
510: HKEY hOpenKey;
511: DWORD Type;
1.7 noro 512: char *slash;
1.12 noro 513:
1.7 noro 514: if ( rootdir.body ) {
515: strcpy(name,rootdir.body);
1.12 noro 516: return;
517: }
518:
519: if ( access("UseCurrentDir",0) >= 0 ) {
520: GetCurrentDirectory(BUFSIZ,name);
521: slash = strrchr(name,'\\');
522: if ( slash )
523: *slash = 0;
1.7 noro 524: return;
525: }
1.1 noro 526: name[0] = 0;
527: ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, ECGEN_KEYNAME, 0,
528: KEY_QUERY_VALUE, &hOpenKey);
529: if ( ret != ERROR_SUCCESS )
530: ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, ASIR_KEYNAME, 0,
531: KEY_QUERY_VALUE, &hOpenKey);
532: if( ret == ERROR_SUCCESS ) {
533: RegQueryValueEx(hOpenKey, "Directory", NULL, &Type, name, &len);
534: RegCloseKey(hOpenKey);
1.7 noro 535: } else {
536: GetCurrentDirectory(len,name);
537: slash = strrchr(name,'\\');
538: if ( slash )
539: *slash = 0;
1.1 noro 540: }
541: }
1.7 noro 542:
1.15 noro 543: void set_rootdir(char *name)
1.7 noro 544: {
545: static char DirName[BUFSIZ];
546:
547: strcpy(DirName,name);
548: rootdir.id = O_STR;
549: rootdir.body = DirName;
550: asir_libdir = DirName;
551: /* XXX */
552: env_init();
553: }
554:
1.1 noro 555: #else
1.15 noro 556: void get_rootdir(char *name,int len)
1.1 noro 557: {
558: strcpy(name,asir_libdir);
559: }
1.7 noro 560:
1.15 noro 561: void set_rootdir(char *name)
1.7 noro 562: {
563: static char DirName[BUFSIZ];
564:
565: strcpy(DirName,name);
566: asir_libdir = DirName;
567: /* XXX */
568: env_init();
569: }
570:
1.1 noro 571: #endif
572:
1.15 noro 573: void Pget_rootdir(STRING *rp)
1.1 noro 574: {
575: static char DirName[BUFSIZ];
576:
577: if ( !rootdir.body ) {
578: get_rootdir(DirName,sizeof(DirName));
579: rootdir.id = O_STR;
580: rootdir.body = DirName;
581: }
582: *rp = &rootdir;
583: }
584:
1.6 noro 585: #if defined(VISUAL) && defined(DES_ENC)
1.15 noro 586: void Pbsave_enc(NODE arg,Obj *rp)
1.1 noro 587: {
588: init_deskey();
589: des_encryption = 1;
590: Pbsave(arg,rp);
591: des_encryption = 0;
592: }
593:
1.15 noro 594: void Pbload_enc(NODE arg,Obj *rp)
1.1 noro 595: {
596: init_deskey();
597: des_encryption = 1;
598: Pbload(arg,rp);
599: des_encryption = 0;
600: }
1.6 noro 601: #endif
1.1 noro 602:
1.15 noro 603: void Pbload27(NODE arg,Obj *rp)
1.1 noro 604: {
605: FILE *fp;
606: Obj r;
607:
608: asir_assert(ARG0(arg),O_STR,"bload27");
609: fp = fopen(BDY((STRING)ARG0(arg)),"rb");
610: if ( !fp )
611: error("bload : invalid filename");
612: loadvl(fp);
613: loadobj(fp,&r);
614: fclose(fp);
615: bobjtoobj(BASE27,r,rp);
616: }
617:
1.15 noro 618: void Pbsave_compat(NODE arg,Q *rp)
1.1 noro 619: {
620: FILE *fp;
621: VL vl,t;
622:
623: asir_assert(ARG1(arg),O_STR,"bsave_compat");
624: get_vars_recursive(ARG0(arg),&vl);
625: for ( t = vl; t; t = NEXT(t) )
626: if ( t->v->attr == (pointer)V_UC )
627: error("bsave : not implemented");
628: fp = fopen(BDY((STRING)ARG1(arg)),"wb");
629: if ( !fp )
630: error("bsave : invalid filename");
631: /* indicator of an asir32 file */
632: putw(0,fp); putw(0,fp);
633: savevl(fp,vl);
634: saveobj(fp,ARG0(arg));
635: fclose(fp);
636: *rp = ONE;
637: }
638:
1.15 noro 639: void Pbload_compat(NODE arg,Obj *rp)
1.1 noro 640: {
641: FILE *fp;
642: unsigned int hdr[2];
643: Obj r;
644: int c;
645:
646: asir_assert(ARG0(arg),O_STR,"bload_compat");
647: fp = fopen(BDY((STRING)ARG0(arg)),"rb");
648: if ( !fp )
649: error("bload : invalid filename");
650: fread(hdr,sizeof(unsigned int),2,fp);
651: if ( !hdr[0] && !hdr[1] ) {
652: /* asir32 file or asir27 0 */
653: c = fgetc(fp);
654: if ( c == EOF ) {
655: /* asir27 0 */
656: *rp = 0;
657: } else {
658: /* asir32 file */
659: ungetc(c,fp);
660: loadvl(fp);
661: loadobj(fp,rp);
662: }
663: } else {
664: /* asir27 file */
665: rewind(fp);
666: loadvl(fp);
667: loadobj(fp,&r);
668: bobjtoobj(BASE27,r,rp);
669: }
670: fclose(fp);
671: }
672:
1.15 noro 673: void Premove_file(NODE arg,Q *rp)
1.1 noro 674: {
675: unlink((char *)BDY((STRING)ARG0(arg)));
676: *rp = ONE;
677: }
678:
1.15 noro 679: void Paccess(NODE arg,Q *rp)
1.1 noro 680: {
681: #if defined(VISUAL)
682: if ( access(BDY((STRING)ARG0(arg)),04) >= 0 )
683: #else
684: if ( access(BDY((STRING)ARG0(arg)),R_OK) >= 0 )
685: #endif
686: *rp = ONE;
687: else
688: *rp = 0;
689: }
1.9 noro 690:
691: #if defined(VISUAL)
692: int process_id()
693: {
694: return GetCurrentProcessId();
695: }
696:
1.15 noro 697: void call_exe(char *name,char **av)
1.9 noro 698: {
699: _spawnv(_P_WAIT,name,av);
700: }
701: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>