1 #include "v3p_f2c.h"
2 #include "fio.h"
3 #ifdef __cplusplus
4 extern "C" {
5 #endif
6 #ifdef KR_headers
f_back(a)7 integer f_back(a) alist *a;
8 #else
9 integer f_back(alist *a)
10 #endif
11 { unit *b;
12 OFF_T v, w, x, y, z;
13 uiolen n;
14 FILE *f;
15
16 f__curunit = b = &f__units[a->aunit]; /* curunit for error messages */
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(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 t_runc(a);
30 if (f__nowreading(b))
31 err(a->aerr,errno,"backspace")
32 }
33 f = b->ufd; /* may have changed in t_runc() */
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,-(OFF_T)sizeof(uiolen),SEEK_CUR);
47 fread((char *)&n,sizeof(uiolen),1,f);
48 FSEEK(f,-(OFF_T)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 }
74 #ifdef __cplusplus
75 }
76 #endif
77