[BACK]Return to file.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / builtin

Annotation of OpenXM_contrib2/asir2000/builtin/file.c, Revision 1.23

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>