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