diff options
author | ljo <ljo@FreeBSD.org> | 1994-10-26 18:15:35 +0000 |
---|---|---|
committer | ljo <ljo@FreeBSD.org> | 1994-10-26 18:15:35 +0000 |
commit | 80b2e1963004e4ae0173b4f9bc965518ba81d3b0 (patch) | |
tree | f59f79382fc6721a367c9c0ee1be96f075718569 /lib/libI77/backspace.c | |
download | FreeBSD-src-80b2e1963004e4ae0173b4f9bc965518ba81d3b0.zip FreeBSD-src-80b2e1963004e4ae0173b4f9bc965518ba81d3b0.tar.gz |
Library for f2c. (part 1 of 2)
Obtained from: netlib.att.com
Diffstat (limited to 'lib/libI77/backspace.c')
-rw-r--r-- | lib/libI77/backspace.c | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/lib/libI77/backspace.c b/lib/libI77/backspace.c new file mode 100644 index 0000000..4213424 --- /dev/null +++ b/lib/libI77/backspace.c @@ -0,0 +1,96 @@ +#include "f2c.h" +#include "fio.h" +#ifdef KR_headers +integer f_back(a) alist *a; +#else +integer f_back(alist *a) +#endif +{ unit *b; + int i, n, ndec; +#ifdef MSDOS + int j, k; + long w, z; +#endif + long x, y; + char buf[32]; + if(a->aunit >= MXUNIT || a->aunit < 0) + err(a->aerr,101,"backspace") + b= &f__units[a->aunit]; + if(b->useek==0) err(a->aerr,106,"backspace") + if(b->ufd==NULL) { + fk_open(1, 1, a->aunit); + return(0); + } + if(b->uend==1) + { b->uend=0; + return(0); + } + if(b->uwrt) { + (void) t_runc(a); + if (f__nowreading(b)) + err(a->aerr,errno,"backspace") + } + if(b->url>0) + { + x=ftell(b->ufd); + y = x % b->url; + if(y == 0) x--; + x /= b->url; + x *= b->url; + (void) fseek(b->ufd,x,SEEK_SET); + return(0); + } + + if(b->ufmt==0) + { (void) fseek(b->ufd,-(long)sizeof(int),SEEK_CUR); + (void) fread((char *)&n,sizeof(int),1,b->ufd); + (void) fseek(b->ufd,-(long)n-2*sizeof(int),SEEK_CUR); + return(0); + } +#ifdef MSDOS + w = -1; +#endif + for(ndec = 2;; ndec = 1) + { + y = x=ftell(b->ufd); + if(x<sizeof(buf)) x=0; + else x -= sizeof(buf); + (void) fseek(b->ufd,x,SEEK_SET); + n=fread(buf,1,(int)(y-x), b->ufd); + for(i=n-ndec;i>=0;i--) + { + if(buf[i]!='\n') continue; +#ifdef MSDOS + for(j = k = 0; j <= i; j++) + if (buf[j] == '\n') + k++; + fseek(b->ufd,x,SEEK_SET); + do { + if (getc(b->ufd) == '\n') { + --k; + if ((z = ftell(b->ufd)) >= y) { + if (w == -1) + goto break2; + break; + } + w = z; + } + } while(k > 0); + fseek(b->ufd, w, SEEK_SET); +#else + fseek(b->ufd,(long)(i+1-n),SEEK_CUR); +#endif + return(0); + } +#ifdef MSDOS + break2: +#endif + if(x==0) + { + (void) fseek(b->ufd, 0L, SEEK_SET); + return(0); + } + else if(n<=0) err(a->aerr,(EOF),"backspace") + (void) fseek(b->ufd, x, SEEK_SET); + } +} |