* ggc-page.c (alloc_page): If HAVE_MMAP_ANYWHERE and we're
[official-gcc.git] / libf2c / libI77 / backspace.c
blob1968801aab75160fdb5e35d3318b664522ff3c5e
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;
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(b->ufd == NULL) {
21 fk_open(1, 1, a->aunit);
22 return(0);
24 if(b->uend==1)
25 { b->uend=0;
26 return(0);
28 if(b->uwrt) {
29 t_runc(a);
30 if (f__nowreading(b))
31 err(a->aerr,errno,"backspace");
33 f = b->ufd; /* may have changed in t_runc() */
34 if(b->url>0)
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);
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);
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;
66 z = v;
68 err(a->aerr,(EOF),"backspace");
70 break2:
71 fseek(f, z, SEEK_SET);
72 return 0;