* regclass.c (fix_register): Fix typo.
[official-gcc.git] / libf2c / libI77 / backspace.c
blob848923912bf85fe2014c91f61b4e7d0f2129f42c
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;
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);
25 if(b->uend==1)
26 { b->uend=0;
27 return(0);
29 if(b->uwrt) {
30 t_runc(a);
31 if (f__nowreading(b))
32 err(a->aerr,errno,"backspace");
34 f = b->ufd; /* may have changed in t_runc() */
35 if(b->url>0)
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);
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);
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;
67 z = v;
69 err(a->aerr,(EOF),"backspace");
71 break2:
72 FSEEK(f, z, SEEK_SET);
73 return 0;