|
Last change
on this file since 603 was 2, checked in by bird, 23 years ago |
|
Initial revision
|
-
Property cvs2svn:cvs-rev
set to
1.1
-
Property svn:eol-style
set to
native
-
Property svn:executable
set to
*
|
|
File size:
1.3 KB
|
| Rev | Line | |
|---|
| [2] | 1 | #include "config.h"
|
|---|
| 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;
|
|---|
| 11 | off_t v, w, x, y, z;
|
|---|
| 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");
|
|---|
| 21 | if(b->ufd == NULL) {
|
|---|
| 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) {
|
|---|
| 30 | t_runc(a);
|
|---|
| 31 | if (f__nowreading(b))
|
|---|
| 32 | err(a->aerr,errno,"backspace");
|
|---|
| 33 | }
|
|---|
| 34 | f = b->ufd; /* may have changed in t_runc() */
|
|---|
| 35 | if(b->url>0)
|
|---|
| 36 | {
|
|---|
| 37 | x=FTELL(f);
|
|---|
| 38 | y = x % b->url;
|
|---|
| 39 | if(y == 0) x--;
|
|---|
| 40 | x /= b->url;
|
|---|
| 41 | x *= b->url;
|
|---|
| 42 | FSEEK(f,x,SEEK_SET);
|
|---|
| 43 | return(0);
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | if(b->ufmt==0)
|
|---|
| 47 | { FSEEK(f,-(off_t)sizeof(uiolen),SEEK_CUR);
|
|---|
| 48 | fread((char *)&n,sizeof(uiolen),1,f);
|
|---|
| 49 | FSEEK(f,-(off_t)n-2*sizeof(uiolen),SEEK_CUR);
|
|---|
| 50 | return(0);
|
|---|
| 51 | }
|
|---|
| 52 | w = x = FTELL(f);
|
|---|
| 53 | z = 0;
|
|---|
| 54 | loop:
|
|---|
| 55 | while(x) {
|
|---|
| 56 | x -= x < 64 ? x : 64;
|
|---|
| 57 | FSEEK(f,x,SEEK_SET);
|
|---|
| 58 | for(y = x; y < w; y++) {
|
|---|
| 59 | if (getc(f) != '\n')
|
|---|
| 60 | continue;
|
|---|
| 61 | v = FTELL(f);
|
|---|
| 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:
|
|---|
| 72 | FSEEK(f, z, SEEK_SET);
|
|---|
| 73 | return 0;
|
|---|
| 74 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.