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

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

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