Annotation of 40BSD/cmd/lisp/fpipe.c, revision 1.1

1.1     ! root        1: static char *sccsid = "@(#)fpipe.c     34.2 10/18/80";
        !             2: 
        !             3: #include "global.h"
        !             4: #include <signal.h>
        !             5: FILE *_dofpip(iodes)
        !             6: int iodes;
        !             7: {
        !             8:        register FILE *p;
        !             9: 
        !            10:        for(p=_iob; (p->_flag&(_IOWRT|_IOREAD))!=0; p++)
        !            11:                if (p >= _iob+_NFILE)
        !            12:                        return(NULL);
        !            13:        p->_file = iodes;
        !            14:        p->_cnt = 0;
        !            15:        p->_base = p->_ptr = NULL;
        !            16:        return(p);
        !            17: }
        !            18: 
        !            19: FILE * fpipe(info)
        !            20: FILE *info[2];
        !            21: {
        !            22:        register FILE *p;
        !            23:        int descrips[2];
        !            24: 
        !            25:        if(0 > pipe(descrips)) return( (FILE *) -1);
        !            26: 
        !            27:        if(NULL==(p = _dofpip(descrips[0]))) return( (FILE *) -1);
        !            28:        p->_flag = (_IONBF|_IOREAD);
        !            29:        info[0] = p;
        !            30: 
        !            31:        if(NULL==(p = _dofpip(descrips[1]))) return( (FILE *) -1);
        !            32:        p->_flag = _IOWRT;
        !            33:        info[1] = p;
        !            34:        return((FILE *) 2); /*indicate sucess*/
        !            35: }
        !            36: #ifndef VMS
        !            37: /*C library -- write
        !            38:   nwritten = write(file, buffer, count);
        !            39:   nwritten == -1 means error
        !            40: */
        !            41: write(file, buffer, count)
        !            42: char *buffer;
        !            43: {
        !            44:        register lispval handy;
        !            45:        int retval;
        !            46:        if((file != 1) || (Vcntlw->a.clb == nil)) goto top;
        !            47:        /* since ^w is non nil, we do not want to print to the terminal,
        !            48:           but we must be sure to return a correct value from the write
        !            49:           in case there is no write to ptport
        !            50:        */
        !            51:        asm(" movl 12(ap),-4(fp) ") /* retval = count  */
        !            52:        goto skipit;
        !            53: 
        !            54: top:
        !            55: 
        !            56: asm("  .set    write,4 ");
        !            57: asm("  chmk    $write  ");
        !            58: asm("  bcc     noerror ");
        !            59: asm("  jmp     cerror  ");
        !            60: asm("noerror:          ");
        !            61: asm("  movl    r0,-4(fp)");
        !            62: 
        !            63: skipit:
        !            64:     if(file==1) {
        !            65:        handy = Vptport->a.clb;
        !            66:        if(handy!=nil && TYPE(handy)==PORT && handy->p->_file!=1) {
        !            67:                fflush(handy->p);
        !            68:                file = handy->p->_file;
        !            69:                goto top;
        !            70:        }
        !            71:     }
        !            72:     return(retval);
        !            73: }
        !            74: 
        !            75: /*
        !            76: # C library -- read
        !            77: 
        !            78: # nread = read(file, buffer, count);
        !            79: #
        !            80: # nread ==0 means eof; nread == -1 means error
        !            81: */
        !            82: read(file,buffer,count)
        !            83: {
        !            84: asm("  .set    read,3 ");
        !            85: asm("  .set    eintr,4  ");  /* from /usr/include/errno.h */
        !            86: again:
        !            87: asm("  chmk    $read ");
        !            88: asm("  bcs     error ");
        !            89: asm("  ret ");
        !            90: asm("error: ");
        !            91: asm("  cmpl    r0,$eintr ");
        !            92: asm("  jeql    intseen ");
        !            93: asm("  jmp     cerror ");
        !            94: asm(" intseen: ");
        !            95:        if(sigintcnt > 0) sigcall(SIGINT);
        !            96:        goto again;
        !            97: }
        !            98: #endif

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.