1*2484Sdlw /*
2*2484Sdlw char id_backspace[] = "@(#)backspace.c	1.1";
3*2484Sdlw  *
4*2484Sdlw  * Backspace records
5*2484Sdlw  */
6*2484Sdlw 
7*2484Sdlw #include "fio.h"
8*2484Sdlw 
9*2484Sdlw char *bksp = "backspace";
10*2484Sdlw char last_char();
11*2484Sdlw 
12*2484Sdlw f_back(a) alist *a;
13*2484Sdlw {	unit *b;
14*2484Sdlw 	int n,i;
15*2484Sdlw 	long x,y;
16*2484Sdlw 	lfname = NULL;
17*2484Sdlw 	elist = NO;
18*2484Sdlw 	external = YES;
19*2484Sdlw 	errflag = a->aerr;
20*2484Sdlw 	lunit = a->aunit;
21*2484Sdlw 	if (not_legal(lunit)) err(errflag,101,bksp)
22*2484Sdlw 	b= &units[lunit];
23*2484Sdlw 	if(!b->ufd && (n=fk_open(READ,SEQ,FMT,(ftnint)lunit)) )
24*2484Sdlw 		err(errflag,n,bksp)
25*2484Sdlw 	lfname = b->ufnm;
26*2484Sdlw 	if(b->uend)
27*2484Sdlw 	{	b->uend = NO;
28*2484Sdlw 		return(OK);
29*2484Sdlw 	}
30*2484Sdlw 	if((x=ftell(b->ufd))==0) return(OK);
31*2484Sdlw 	if(!b->useek) err(errflag,106,bksp)
32*2484Sdlw 	if(b->uwrt) t_runc(b,errflag);
33*2484Sdlw 	if(b->url)		/* direct access, purely academic */
34*2484Sdlw 	{	y = x%(long)b->url;
35*2484Sdlw 		x -= y?y:b->url;
36*2484Sdlw 		fseek(b->ufd,x,0);
37*2484Sdlw 		return(OK);
38*2484Sdlw 	}
39*2484Sdlw 	if(!b->ufmt)		/* unformatted sequential */
40*2484Sdlw 	{	fseek(b->ufd,-(long)sizeof(int),1);
41*2484Sdlw 		fread((char *)&n,sizeof(int),1,b->ufd);
42*2484Sdlw 		fseek(b->ufd,-(long)n-2*sizeof(int),1);
43*2484Sdlw 		return(OK);
44*2484Sdlw 	}
45*2484Sdlw 	if(x==1)			/* formatted sequential */
46*2484Sdlw 	{	rewind(b->ufd);
47*2484Sdlw 		return(OK);
48*2484Sdlw 	}
49*2484Sdlw 	while(last_char(b->ufd)!='\n');	/* slow but simple */
50*2484Sdlw 	return(OK);
51*2484Sdlw }
52