gcc/libf2c/libI77/backspace.c
Toon Moene f8d92613d0 configure.in: Check for fseeko, ftello.
2001-07-06  Toon Moene  <toon@moene.indiv.nluug.nl>
            Pedro Vazquez  <vazquez@penelope.iqm.unicamp.br>

	* configure.in: Check for fseeko, ftello.
	* configure: Rebuilt.
	* config.h.in: Rebuilt.
	* fio.h: Define FSEEK to be fseek or fseeko, depending
	on configure's findings.  Ditto for FTELL and ftell / ftello.
	* backspace.c (f_back): Use FSEEK for fseek, FTELL for ftell.
	* dfe.c (c_dfe): Ditto.
	* due.c (c_due, e_rdue): Ditto.
	* endfile.c (t_runc): Ditto.
	* err.c (f__nowreading, f__nowwriting): Ditto.
	* ftell_.c (G77_ftell_0, G77_fseek_0): Ditto.
	* inquire.c (f_inqu): Ditto.
	* open.c (f_open): Ditto.
	* rdfmt.c (rd_ed): Ditto.
	* sue.c (s_wsue, e_wsue, e_rsue): Ditto.

Co-Authored-By: Pedro Vazquez <vazquez@penelope.iqm.unicamp.br>

From-SVN: r43806
2001-07-06 12:09:39 +00:00

75 lines
1.3 KiB
C

#include "config.h"
#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;
off_t v, w, x, y, z;
uiolen n;
FILE *f;
f__curunit = b = &f__units[a->aunit]; /* curunit for error messages */
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");
if(b->ufd == NULL) {
fk_open(1, 1, a->aunit);
return(0);
}
if(b->uend==1)
{ b->uend=0;
return(0);
}
if(b->uwrt) {
t_runc(a);
if (f__nowreading(b))
err(a->aerr,errno,"backspace");
}
f = b->ufd; /* may have changed in t_runc() */
if(b->url>0)
{
x=FTELL(f);
y = x % b->url;
if(y == 0) x--;
x /= b->url;
x *= b->url;
FSEEK(f,x,SEEK_SET);
return(0);
}
if(b->ufmt==0)
{ FSEEK(f,-(off_t)sizeof(uiolen),SEEK_CUR);
fread((char *)&n,sizeof(uiolen),1,f);
FSEEK(f,-(off_t)n-2*sizeof(uiolen),SEEK_CUR);
return(0);
}
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");
}
break2:
FSEEK(f, z, SEEK_SET);
return 0;
}