1998-02-01 02:37:08 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include "f2c.h"
|
|
|
|
#include "fio.h"
|
|
|
|
#ifdef KR_headers
|
|
|
|
integer f_back(a) alist *a;
|
|
|
|
#else
|
|
|
|
integer f_back(alist *a)
|
|
|
|
#endif
|
|
|
|
{ unit *b;
|
1998-05-19 12:52:03 +02:00
|
|
|
long v, w, x, y, z;
|
1998-02-01 02:37:08 +01:00
|
|
|
uiolen n;
|
1998-05-19 12:52:03 +02:00
|
|
|
FILE *f;
|
|
|
|
|
1998-06-23 16:37:15 +02:00
|
|
|
f__curunit = b = &f__units[a->aunit]; /* curunit for error messages */
|
1998-02-01 02:37:08 +01:00
|
|
|
if (f__init & 2)
|
|
|
|
f__fatal (131, "I/O recursion");
|
|
|
|
if(a->aunit >= MXUNIT || a->aunit < 0)
|
|
|
|
err(a->aerr,101,"backspace");
|
|
|
|
if(b->useek==0) err(a->aerr,106,"backspace");
|
1998-05-19 12:52:03 +02:00
|
|
|
if((f = b->ufd) == NULL) {
|
1998-02-01 02:37:08 +01:00
|
|
|
fk_open(1, 1, a->aunit);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
if(b->uend==1)
|
|
|
|
{ b->uend=0;
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
if(b->uwrt) {
|
|
|
|
(void) t_runc(a);
|
|
|
|
if (f__nowreading(b))
|
|
|
|
err(a->aerr,errno,"backspace");
|
|
|
|
}
|
|
|
|
if(b->url>0)
|
|
|
|
{
|
1998-05-19 12:52:03 +02:00
|
|
|
x=ftell(f);
|
1998-02-01 02:37:08 +01:00
|
|
|
y = x % b->url;
|
|
|
|
if(y == 0) x--;
|
|
|
|
x /= b->url;
|
|
|
|
x *= b->url;
|
1998-05-19 12:52:03 +02:00
|
|
|
(void) fseek(f,x,SEEK_SET);
|
1998-02-01 02:37:08 +01:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(b->ufmt==0)
|
1998-05-19 12:52:03 +02:00
|
|
|
{ fseek(f,-(long)sizeof(uiolen),SEEK_CUR);
|
|
|
|
fread((char *)&n,sizeof(uiolen),1,f);
|
|
|
|
fseek(f,-(long)n-2*sizeof(uiolen),SEEK_CUR);
|
1998-02-01 02:37:08 +01:00
|
|
|
return(0);
|
|
|
|
}
|
1998-05-19 12:52:03 +02:00
|
|
|
w = x = ftell(f);
|
|
|
|
z = 0;
|
|
|
|
loop:
|
|
|
|
while(x) {
|
|
|
|
x -= x < 64 ? x : 64;
|
|
|
|
fseek(f,x,SEEK_SET);
|
|
|
|
for(y = x; y < w; y++) {
|
|
|
|
if (getc(f) != '\n')
|
|
|
|
continue;
|
|
|
|
v = ftell(f);
|
|
|
|
if (v == w) {
|
|
|
|
if (z)
|
|
|
|
goto break2;
|
|
|
|
goto loop;
|
|
|
|
}
|
|
|
|
z = v;
|
|
|
|
}
|
|
|
|
err(a->aerr,(EOF),"backspace");
|
1998-02-01 02:37:08 +01:00
|
|
|
}
|
|
|
|
break2:
|
1998-05-19 12:52:03 +02:00
|
|
|
fseek(f, z, SEEK_SET);
|
|
|
|
return 0;
|
1998-02-01 02:37:08 +01:00
|
|
|
}
|