|
|
1.1 root 1: #include "f2c.h"
2: #include "fio.h"
3: #ifdef KR_headers
4: integer f_back(a) alist *a;
5: #else
6: integer f_back(alist *a)
7: #endif
8: { unit *b;
9: int i, n, ndec;
10: long x;
11: char buf[32];
12: if(a->aunit >= MXUNIT || a->aunit < 0)
13: err(a->aerr,101,"backspace")
14: b= &f__units[a->aunit];
15: if(b->useek==0) err(a->aerr,106,"backspace")
16: if(b->ufd==NULL) {
17: fk_open(1, 1, a->aunit);
18: return(0);
19: }
20: if(b->uend==1)
21: { b->uend=0;
22: return(0);
23: }
24: if(b->uwrt) {
25: (void) t_runc(a);
26: if (f__nowreading(b))
27: err(a->aerr,errno,"backspace")
28: }
29: if(b->url>0)
30: { long y;
31: x=ftell(b->ufd);
32: y = x % b->url;
33: if(y == 0) x--;
34: x /= b->url;
35: x *= b->url;
36: (void) fseek(b->ufd,x,SEEK_SET);
37: return(0);
38: }
39:
40: if(b->ufmt==0)
41: { (void) fseek(b->ufd,-(long)sizeof(int),SEEK_CUR);
42: (void) fread((char *)&n,sizeof(int),1,b->ufd);
43: (void) fseek(b->ufd,-(long)n-2*sizeof(int),SEEK_CUR);
44: return(0);
45: }
46: for(ndec = 2;; ndec = 1)
47: { long y;
48: y = x=ftell(b->ufd);
49: if(x<sizeof(buf)) x=0;
50: else x -= sizeof(buf);
51: (void) fseek(b->ufd,x,SEEK_SET);
52: n=fread(buf,1,(int)(y-x), b->ufd);
53: for(i=n-ndec;i>=0;i--)
54: {
55: if(buf[i]!='\n') continue;
56: (void) fseek(b->ufd,(long)(i+1-n),SEEK_CUR);
57: return(0);
58: }
59: if(x==0)
60: {
61: (void) fseek(b->ufd, 0L, SEEK_SET);
62: return(0);
63: }
64: else if(n<=0) err(a->aerr,(EOF),"backspace")
65: (void) fseek(b->ufd, x, SEEK_SET);
66: }
67: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.