Revision 14548,
1.3 KB
checked in by ghudson, 24 years ago
(diff) |
This commit was generated by cvs2svn to compensate for changes in r14547,
which included commits to RCS files with non-trunk default branches.
|
Line | |
---|
1 | #include <sys/types.h> |
---|
2 | #include "f2c.h" |
---|
3 | #include "fio.h" |
---|
4 | #ifdef KR_headers |
---|
5 | integer f_back(a) alist *a; |
---|
6 | #else |
---|
7 | integer f_back(alist *a) |
---|
8 | #endif |
---|
9 | { unit *b; |
---|
10 | long v, w, x, y, z; |
---|
11 | uiolen n; |
---|
12 | FILE *f; |
---|
13 | |
---|
14 | f__curunit = b = &f__units[a->aunit]; /* curunit for error messages */ |
---|
15 | if (f__init & 2) |
---|
16 | f__fatal (131, "I/O recursion"); |
---|
17 | if(a->aunit >= MXUNIT || a->aunit < 0) |
---|
18 | err(a->aerr,101,"backspace"); |
---|
19 | if(b->useek==0) err(a->aerr,106,"backspace"); |
---|
20 | if((f = b->ufd) == NULL) { |
---|
21 | fk_open(1, 1, a->aunit); |
---|
22 | return(0); |
---|
23 | } |
---|
24 | if(b->uend==1) |
---|
25 | { b->uend=0; |
---|
26 | return(0); |
---|
27 | } |
---|
28 | if(b->uwrt) { |
---|
29 | (void) t_runc(a); |
---|
30 | f = b->ufd; /* t_runc might change b->ufd */ |
---|
31 | if (f__nowreading(b)) |
---|
32 | err(a->aerr,errno,"backspace"); |
---|
33 | } |
---|
34 | if(b->url>0) |
---|
35 | { |
---|
36 | x=ftell(f); |
---|
37 | y = x % b->url; |
---|
38 | if(y == 0) x--; |
---|
39 | x /= b->url; |
---|
40 | x *= b->url; |
---|
41 | (void) fseek(f,x,SEEK_SET); |
---|
42 | return(0); |
---|
43 | } |
---|
44 | |
---|
45 | if(b->ufmt==0) |
---|
46 | { fseek(f,-(long)sizeof(uiolen),SEEK_CUR); |
---|
47 | fread((char *)&n,sizeof(uiolen),1,f); |
---|
48 | fseek(f,-(long)n-2*sizeof(uiolen),SEEK_CUR); |
---|
49 | return(0); |
---|
50 | } |
---|
51 | w = x = ftell(f); |
---|
52 | z = 0; |
---|
53 | loop: |
---|
54 | while(x) { |
---|
55 | x -= x < 64 ? x : 64; |
---|
56 | fseek(f,x,SEEK_SET); |
---|
57 | for(y = x; y < w; y++) { |
---|
58 | if (getc(f) != '\n') |
---|
59 | continue; |
---|
60 | v = ftell(f); |
---|
61 | if (v == w) { |
---|
62 | if (z) |
---|
63 | goto break2; |
---|
64 | goto loop; |
---|
65 | } |
---|
66 | z = v; |
---|
67 | } |
---|
68 | err(a->aerr,(EOF),"backspace"); |
---|
69 | } |
---|
70 | break2: |
---|
71 | fseek(f, z, SEEK_SET); |
---|
72 | return 0; |
---|
73 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.