string.h is ANSI C include file
[unix-history] / usr / src / usr.bin / f77 / libI77 / backspace.c
CommitLineData
7bd0b8c0 1/*
161423a6
RE
2 * Copyright (c) 1980 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
7bd0b8c0 5 *
afe045b5 6 * @(#)backspace.c 5.2 %G%
161423a6
RE
7 */
8
9/*
7bd0b8c0
DW
10 * Backspace records
11 */
12
13#include "fio.h"
14
fdfc35cb
DW
15static char bksp[] = "backspace";
16char last_char();
7bd0b8c0 17
fdfc35cb
DW
18f_back(a)
19alist *a;
7bd0b8c0
DW
20{ unit *b;
21 int n,i;
22 long x,y;
2621bc46 23
7bd0b8c0
DW
24 lfname = NULL;
25 elist = NO;
26 external = YES;
27 errflag = a->aerr;
28 lunit = a->aunit;
fdfc35cb
DW
29 if (not_legal(lunit))
30 err(errflag, F_ERUNIT, bksp)
7bd0b8c0 31 b= &units[lunit];
afe045b5 32 if(!b->ufd) return(OK);
7bd0b8c0
DW
33 lfname = b->ufnm;
34 if(b->uend)
35 { b->uend = NO;
1604dff5 36 clearerr(b->ufd);
7bd0b8c0
DW
37 return(OK);
38 }
fdfc35cb
DW
39 if((x = ftell(b->ufd)) == 0)
40 return(OK);
41 if(!b->useek)
42 err(errflag, F_ERNOBKSP, bksp)
331ef099 43 if(b->uwrt && (n = t_runc(b, errflag, bksp))) /* sets 'reading' */
fdfc35cb 44 return(n);
7bd0b8c0
DW
45 if(b->url) /* direct access, purely academic */
46 { y = x%(long)b->url;
47 x -= y?y:b->url;
48 fseek(b->ufd,x,0);
49 return(OK);
50 }
51 if(!b->ufmt) /* unformatted sequential */
52 { fseek(b->ufd,-(long)sizeof(int),1);
53 fread((char *)&n,sizeof(int),1,b->ufd);
54 fseek(b->ufd,-(long)n-2*sizeof(int),1);
55 return(OK);
56 }
fdfc35cb 57 if(x == 1) /* formatted sequential */
7bd0b8c0
DW
58 { rewind(b->ufd);
59 return(OK);
60 }
fdfc35cb
DW
61 while (last_char(b->ufd) != '\n') /* slow but simple */
62 ;
7bd0b8c0
DW
63 return(OK);
64}