Annotation of 41BSD/lib/libI77/backspace.c, revision 1.1.1.1

1.1       root        1: #include "fio.h"
                      2: f_back(a) alist *a;
                      3: {      unit *b;
                      4:        int n,i;
                      5:        long x;
                      6:        char buf[32];
                      7:        if(a->aunit >= MXUNIT || a->aunit < 0)
                      8:                err(a->aerr,101,"backspace")
                      9:        b= &units[a->aunit];
                     10:        if(b->useek==0) err(a->aerr,106,"backspace")
                     11:        if(b->ufd==NULL) err(a->aerr,114,"backspace")
                     12:        if(b->uend==1)
                     13:        {       b->uend=0;
                     14:                return(0);
                     15:        }
                     16:        if(b->uwrt)
                     17:        {       (void) t_runc(b);
                     18:                (void) nowreading(b);
                     19:        }
                     20:        if(b->url>0)
                     21:        {       long y;
                     22:                x=ftell(b->ufd);
                     23:                y = x % b->url;
                     24:                if(y == 0) x--;
                     25:                x /= b->url;
                     26:                x *= b->url;
                     27:                (void) fseek(b->ufd,x,0);
                     28:                return(0);
                     29:        }
                     30:        if(b->ufmt==0)
                     31:        {       (void) fseek(b->ufd,-(long)sizeof(int),1);
                     32:                (void) fread((char *)&n,sizeof(int),1,b->ufd);
                     33:                (void) fseek(b->ufd,-(long)n-2*sizeof(int),1);
                     34:                return(0);
                     35:        }
                     36:        for(;;)
                     37:        {       long y;
                     38:                y = x=ftell(b->ufd);
                     39:                if(x<sizeof(buf)) x=0;
                     40:                else x -= sizeof(buf);
                     41:                (void) fseek(b->ufd,x,0);
                     42:                n=fread(buf,1,(int)(y-x), b->ufd);
                     43:                for(i=n-2;i>=0;i--)
                     44:                {
                     45:                        if(buf[i]!='\n') continue;
                     46:                        (void) fseek(b->ufd,(long)(i+1-n),1);
                     47:                        return(0);
                     48:                }
                     49:                if(x==0) return(0);
                     50:                else if(n<=0) err(a->aerr,(EOF),"backspace")
                     51:                (void) fseek(b->ufd, x, 0);
                     52:        }
                     53: }

unix.superglobalmegacorp.com

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