|
|
1.1 root 1: /*
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.
5: *
6: * @(#)backspace.c 5.1 6/7/85
7: */
8:
9: /*
10: * Backspace records
11: */
12:
13: #include "fio.h"
14:
15: static char bksp[] = "backspace";
16: char last_char();
17:
18: f_back(a)
19: alist *a;
20: { unit *b;
21: int n,i;
22: long x,y;
23:
24: lfname = NULL;
25: elist = NO;
26: external = YES;
27: errflag = a->aerr;
28: lunit = a->aunit;
29: if (not_legal(lunit))
30: err(errflag, F_ERUNIT, bksp)
31: b= &units[lunit];
32: if(!b->ufd && (n = fk_open(READ, SEQ, FMT, (ftnint)lunit)) )
33: err(errflag, n, bksp)
34: lfname = b->ufnm;
35: if(b->uend)
36: { b->uend = NO;
37: clearerr(b->ufd);
38: return(OK);
39: }
40: if((x = ftell(b->ufd)) == 0)
41: return(OK);
42: if(!b->useek)
43: err(errflag, F_ERNOBKSP, bksp)
44: if(b->uwrt && (n = t_runc(b, errflag, bksp))) /* sets 'reading' */
45: return(n);
46: if(b->url) /* direct access, purely academic */
47: { y = x%(long)b->url;
48: x -= y?y:b->url;
49: fseek(b->ufd,x,0);
50: return(OK);
51: }
52: if(!b->ufmt) /* unformatted sequential */
53: { fseek(b->ufd,-(long)sizeof(int),1);
54: fread((char *)&n,sizeof(int),1,b->ufd);
55: fseek(b->ufd,-(long)n-2*sizeof(int),1);
56: return(OK);
57: }
58: if(x == 1) /* formatted sequential */
59: { rewind(b->ufd);
60: return(OK);
61: }
62: while (last_char(b->ufd) != '\n') /* slow but simple */
63: ;
64: return(OK);
65: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.