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