[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.22

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.22    ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/builtin/file.c,v 1.21 2006/02/03 03:55:18 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:
                    270:        if ( ARG0(arg) ) {
                    271:                switch (OID(ARG0(arg))) {
                    272:                        case O_STR:
                    273:                                name0 = BDY((STRING)ARG0(arg));
                    274:                                searchasirpath(name0,&name);
                    275:                                if ( !name ) {
                    276:                                        sprintf(errbuf,"load : \"%s\" not found in the search path",name0);
                    277:                                        error(errbuf);
                    278:                                }
1.22    ! noro      279:                                execasirfile(name);
1.1       noro      280:                                break;
                    281:                        default:
                    282:                                error("load : invalid argument");
                    283:                                break;
                    284:                }
                    285:        }
1.14      noro      286:        STOQ(ret,*rp);
                    287: }
                    288:
1.21      noro      289: NODE imported_files;
                    290:
                    291: void Pimport(NODE arg,Q *rp)
                    292: {
1.22    ! noro      293:        char *name;
        !           294:        NODE t,p,opt;
        !           295:
        !           296:        name = BDY((STRING)ARG0(arg));
        !           297:        for ( t = imported_files; t; t = NEXT(t) )
        !           298:                if ( !strcmp((char *)BDY(t),name) ) break;
        !           299:        if ( !t ) {
        !           300:                Pload(arg,rp);
        !           301:                MKNODE(t,name,imported_files);
        !           302:                imported_files = t;
        !           303:                return;
        !           304:        } else if ( current_option ) {
        !           305:                for ( opt = current_option; opt; opt = NEXT(opt) ) {
        !           306:                        p = BDY((LIST)BDY(opt));
        !           307:                        if ( !strcmp(BDY((STRING)BDY(p)),"reimport") && BDY(NEXT(p)) ) {
        !           308:                                Pload(arg,rp);
        !           309:                                return;
1.21      noro      310:                        }
                    311:                }
1.15      noro      312:        }
1.22    ! noro      313:        *rp = 0;
1.1       noro      314: }
                    315:
1.15      noro      316: void Pwhich(NODE arg,STRING *rp)
1.1       noro      317: {
                    318:        char *name;
                    319:        STRING str;
                    320:
                    321:        switch (OID(ARG0(arg))) {
                    322:                case O_STR:
                    323:                        searchasirpath(BDY((STRING)ARG0(arg)),&name);
                    324:                        break;
                    325:                default:
                    326:                        name = 0;
                    327:                        break;
                    328:        }
                    329:        if ( name ) {
                    330:                MKSTR(str,name); *rp = str;
                    331:        } else
                    332:                *rp = 0;
                    333: }
                    334:
1.15      noro      335: void Ploadfiles(NODE arg,Q *rp)
1.1       noro      336: {
                    337:        int ret;
                    338:
                    339:        if ( ARG0(arg) )
                    340:                if ( OID(ARG0(arg)) != O_LIST )
                    341:                        ret = 0;
                    342:                else
                    343:                        ret = loadfiles(BDY((LIST)ARG0(arg)));
                    344:        else
                    345:                ret = 0;
                    346:        STOQ(ret,*rp);
                    347: }
                    348:
1.15      noro      349: void Poutput(NODE arg,Q *rp)
1.1       noro      350: {
1.17      ohara     351: #if defined(PARI)
1.1       noro      352:        extern FILE *outfile;
                    353: #endif
                    354:        FILE *fp;
                    355:
                    356:        fflush(asir_out);
                    357:        if ( asir_out != stdout )
                    358:                fclose(asir_out);
                    359:        switch ( argc(arg) ) {
                    360:                case 0:
                    361:                        fp = stdout; break;
                    362:                case 1:
                    363:                        asir_assert(ARG0(arg),O_STR,"output");
                    364:                        fp = fopen(((STRING)ARG0(arg))->body,"a+");
                    365:                        if ( !fp )
                    366:                                error("output : invalid filename");
                    367:                        break;
                    368:        }
1.17      ohara     369: #if defined(PARI)
1.1       noro      370:        pari_outfile =
                    371: #endif
                    372:        asir_out = fp;
                    373:        *rp = ONE;
                    374: }
                    375:
                    376: extern int ox_file_io;
                    377:
1.15      noro      378: void Pbsave(NODE arg,Q *rp)
1.1       noro      379: {
                    380:        FILE *fp;
                    381:        VL vl,t;
                    382:
                    383:        asir_assert(ARG1(arg),O_STR,"bsave");
                    384:        get_vars_recursive(ARG0(arg),&vl);
                    385:        for ( t = vl; t; t = NEXT(t) )
                    386:                if ( t->v->attr == (pointer)V_UC )
                    387:                        error("bsave : not implemented");
                    388:        fp = fopen(BDY((STRING)ARG1(arg)),"wb");
                    389:        if ( !fp )
                    390:                error("bsave : invalid filename");
                    391:        ox_file_io = 1; /* network byte order is used */
                    392:        savevl(fp,vl);
                    393:        saveobj(fp,ARG0(arg));
                    394:        fclose(fp);
                    395:        ox_file_io = 0;
                    396:        *rp = ONE;
                    397: }
                    398:
1.15      noro      399: void Pbload(NODE arg,Obj *rp)
1.1       noro      400: {
                    401:        FILE *fp;
                    402:
                    403:        asir_assert(ARG0(arg),O_STR,"bload");
                    404:        fp = fopen(BDY((STRING)ARG0(arg)),"rb");
                    405:        if ( !fp )
                    406:                error("bload : invalid filename");
                    407:        ox_file_io = 1; /* network byte order is used */
                    408:        loadvl(fp);
                    409:        loadobj(fp,rp);
                    410:        fclose(fp);
                    411:        ox_file_io = 0;
                    412: }
                    413:
1.15      noro      414: void Pbsave_cmo(NODE arg,Q *rp)
1.1       noro      415: {
                    416:        FILE *fp;
                    417:
                    418:        asir_assert(ARG1(arg),O_STR,"bsave_cmo");
                    419:        fp = fopen(BDY((STRING)ARG1(arg)),"wb");
                    420:        if ( !fp )
                    421:                error("bsave_cmo : invalid filename");
                    422:        ox_file_io = 1; /* network byte order is used */
                    423:        write_cmo(fp,ARG0(arg));
                    424:        fclose(fp);
                    425:        ox_file_io = 0;
                    426:        *rp = ONE;
                    427: }
                    428:
1.15      noro      429: void Pbload_cmo(NODE arg,Obj *rp)
1.1       noro      430: {
                    431:        FILE *fp;
                    432:
                    433:        asir_assert(ARG0(arg),O_STR,"bload_cmo");
                    434:        fp = fopen(BDY((STRING)ARG0(arg)),"rb");
                    435:        if ( !fp )
                    436:                error("bload_cmo : invalid filename");
                    437:        ox_file_io = 1; /* network byte order is used */
                    438:        read_cmo(fp,rp);
                    439:        fclose(fp);
                    440:        ox_file_io = 0;
                    441: }
                    442:
1.7       noro      443: static struct oSTRING rootdir;
                    444:
1.1       noro      445: #if defined(VISUAL)
1.15      noro      446: void get_rootdir(char *name,int len)
1.1       noro      447: {
                    448:        LONG    ret;
                    449:        HKEY    hOpenKey;
                    450:        DWORD   Type;
1.7       noro      451:        char    *slash;
1.12      noro      452:
1.7       noro      453:        if ( rootdir.body ) {
                    454:                strcpy(name,rootdir.body);
1.12      noro      455:                return;
                    456:        }
                    457:
                    458:        if ( access("UseCurrentDir",0) >= 0 ) {
                    459:                GetCurrentDirectory(BUFSIZ,name);
                    460:                slash = strrchr(name,'\\');
                    461:                if ( slash )
                    462:                        *slash = 0;
1.7       noro      463:                return;
                    464:        }
1.1       noro      465:        name[0] = 0;
                    466:        ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, ECGEN_KEYNAME, 0,
                    467:                KEY_QUERY_VALUE, &hOpenKey);
                    468:        if ( ret != ERROR_SUCCESS )
                    469:                ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, ASIR_KEYNAME, 0,
                    470:                        KEY_QUERY_VALUE, &hOpenKey);
                    471:        if( ret == ERROR_SUCCESS ) {
                    472:                RegQueryValueEx(hOpenKey, "Directory", NULL, &Type, name, &len);
                    473:                RegCloseKey(hOpenKey);
1.7       noro      474:        } else {
                    475:                GetCurrentDirectory(len,name);
                    476:                slash = strrchr(name,'\\');
                    477:                if ( slash )
                    478:                        *slash = 0;
1.1       noro      479:        }
                    480: }
1.7       noro      481:
1.15      noro      482: void set_rootdir(char *name)
1.7       noro      483: {
                    484:        static char DirName[BUFSIZ];
                    485:
                    486:        strcpy(DirName,name);
                    487:        rootdir.id = O_STR;
                    488:        rootdir.body = DirName;
                    489:        asir_libdir = DirName;
                    490:        /* XXX */
                    491:        env_init();
                    492: }
                    493:
1.1       noro      494: #else
1.15      noro      495: void get_rootdir(char *name,int len)
1.1       noro      496: {
                    497:        strcpy(name,asir_libdir);
                    498: }
1.7       noro      499:
1.15      noro      500: void set_rootdir(char *name)
1.7       noro      501: {
                    502:        static char DirName[BUFSIZ];
                    503:
                    504:        strcpy(DirName,name);
                    505:        asir_libdir = DirName;
                    506:        /* XXX */
                    507:        env_init();
                    508: }
                    509:
1.1       noro      510: #endif
                    511:
1.15      noro      512: void Pget_rootdir(STRING *rp)
1.1       noro      513: {
                    514:        static char DirName[BUFSIZ];
                    515:
                    516:        if ( !rootdir.body ) {
                    517:                get_rootdir(DirName,sizeof(DirName));
                    518:                rootdir.id = O_STR;
                    519:                rootdir.body = DirName;
                    520:        }
                    521:        *rp = &rootdir;
                    522: }
                    523:
1.6       noro      524: #if defined(VISUAL) && defined(DES_ENC)
1.15      noro      525: void Pbsave_enc(NODE arg,Obj *rp)
1.1       noro      526: {
                    527:        init_deskey();
                    528:        des_encryption = 1;
                    529:        Pbsave(arg,rp);
                    530:        des_encryption = 0;
                    531: }
                    532:
1.15      noro      533: void Pbload_enc(NODE arg,Obj *rp)
1.1       noro      534: {
                    535:        init_deskey();
                    536:        des_encryption = 1;
                    537:        Pbload(arg,rp);
                    538:        des_encryption = 0;
                    539: }
1.6       noro      540: #endif
1.1       noro      541:
1.15      noro      542: void Pbload27(NODE arg,Obj *rp)
1.1       noro      543: {
                    544:        FILE *fp;
                    545:        Obj r;
                    546:
                    547:        asir_assert(ARG0(arg),O_STR,"bload27");
                    548:        fp = fopen(BDY((STRING)ARG0(arg)),"rb");
                    549:        if ( !fp )
                    550:                error("bload : invalid filename");
                    551:        loadvl(fp);
                    552:        loadobj(fp,&r);
                    553:        fclose(fp);
                    554:        bobjtoobj(BASE27,r,rp);
                    555: }
                    556:
1.15      noro      557: void Pbsave_compat(NODE arg,Q *rp)
1.1       noro      558: {
                    559:        FILE *fp;
                    560:        VL vl,t;
                    561:
                    562:        asir_assert(ARG1(arg),O_STR,"bsave_compat");
                    563:        get_vars_recursive(ARG0(arg),&vl);
                    564:        for ( t = vl; t; t = NEXT(t) )
                    565:                if ( t->v->attr == (pointer)V_UC )
                    566:                        error("bsave : not implemented");
                    567:        fp = fopen(BDY((STRING)ARG1(arg)),"wb");
                    568:        if ( !fp )
                    569:                error("bsave : invalid filename");
                    570:        /* indicator of an asir32 file */
                    571:        putw(0,fp); putw(0,fp);
                    572:        savevl(fp,vl);
                    573:        saveobj(fp,ARG0(arg));
                    574:        fclose(fp);
                    575:        *rp = ONE;
                    576: }
                    577:
1.15      noro      578: void Pbload_compat(NODE arg,Obj *rp)
1.1       noro      579: {
                    580:        FILE *fp;
                    581:        unsigned int hdr[2];
                    582:        Obj r;
                    583:        int c;
                    584:
                    585:        asir_assert(ARG0(arg),O_STR,"bload_compat");
                    586:        fp = fopen(BDY((STRING)ARG0(arg)),"rb");
                    587:        if ( !fp )
                    588:                error("bload : invalid filename");
                    589:        fread(hdr,sizeof(unsigned int),2,fp);
                    590:        if ( !hdr[0] && !hdr[1] ) {
                    591:                /* asir32 file or asir27 0 */
                    592:                c = fgetc(fp);
                    593:                if ( c == EOF ) {
                    594:                        /* asir27 0 */
                    595:                        *rp = 0;
                    596:                } else {
                    597:                        /* asir32 file */
                    598:                        ungetc(c,fp);
                    599:                        loadvl(fp);
                    600:                        loadobj(fp,rp);
                    601:                }
                    602:        } else {
                    603:                /* asir27 file */
                    604:                rewind(fp);
                    605:                loadvl(fp);
                    606:                loadobj(fp,&r);
                    607:                bobjtoobj(BASE27,r,rp);
                    608:        }
                    609:        fclose(fp);
                    610: }
                    611:
1.15      noro      612: void Premove_file(NODE arg,Q *rp)
1.1       noro      613: {
                    614:        unlink((char *)BDY((STRING)ARG0(arg)));
                    615:        *rp = ONE;
                    616: }
                    617:
1.15      noro      618: void Paccess(NODE arg,Q *rp)
1.1       noro      619: {
                    620: #if defined(VISUAL)
                    621:        if ( access(BDY((STRING)ARG0(arg)),04) >= 0 )
                    622: #else
                    623:        if ( access(BDY((STRING)ARG0(arg)),R_OK) >= 0 )
                    624: #endif
                    625:                *rp = ONE;
                    626:        else
                    627:                *rp = 0;
                    628: }
1.9       noro      629:
                    630: #if defined(VISUAL)
                    631: int process_id()
                    632: {
                    633:        return GetCurrentProcessId();
                    634: }
                    635:
1.15      noro      636: void call_exe(char *name,char **av)
1.9       noro      637: {
                    638:        _spawnv(_P_WAIT,name,av);
                    639: }
                    640: #endif

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