source: branches/libc-0.6/src/gcc/libf2c/libI77/backspace.c

Last change on this file was 1392, checked in by bird, 21 years ago

This commit was generated by cvs2svn to compensate for changes in r1391,
which included commits to RCS files with non-trunk default branches.

  • Property cvs2svn:cvs-rev set to 1.1.1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 1.5 KB
Line 
1#include "config.h"
2#include <sys/types.h>
3#include "f2c.h"
4#include "fio.h"
5integer
6f_back (alist * a)
7{
8 unit *b;
9 off_t v, w, x, y, z;
10 uiolen n;
11 FILE *f;
12
13 f__curunit = b = &f__units[a->aunit]; /* curunit for error messages */
14 if (f__init & 2)
15 f__fatal (131, "I/O recursion");
16 if (a->aunit >= MXUNIT || a->aunit < 0)
17 err (a->aerr, 101, "backspace");
18 if (b->useek == 0)
19 err (a->aerr, 106, "backspace");
20 if (b->ufd == NULL)
21 {
22 fk_open (1, 1, a->aunit);
23 return (0);
24 }
25 if (b->uend == 1)
26 {
27 b->uend = 0;
28 return (0);
29 }
30 if (b->uwrt)
31 {
32 t_runc (a);
33 if (f__nowreading (b))
34 err (a->aerr, errno, "backspace");
35 }
36 f = b->ufd; /* may have changed in t_runc() */
37 if (b->url > 0)
38 {
39 x = FTELL (f);
40 y = x % b->url;
41 if (y == 0)
42 x--;
43 x /= b->url;
44 x *= b->url;
45 FSEEK (f, x, SEEK_SET);
46 return (0);
47 }
48
49 if (b->ufmt == 0)
50 {
51 FSEEK (f, -(off_t) sizeof (uiolen), SEEK_CUR);
52 fread ((char *) &n, sizeof (uiolen), 1, f);
53 FSEEK (f, -(off_t) n - 2 * sizeof (uiolen), SEEK_CUR);
54 return (0);
55 }
56 w = x = FTELL (f);
57 z = 0;
58loop:
59 while (x)
60 {
61 x -= x < 64 ? x : 64;
62 FSEEK (f, x, SEEK_SET);
63 for (y = x; y < w; y++)
64 {
65 if (getc (f) != '\n')
66 continue;
67 v = FTELL (f);
68 if (v == w)
69 {
70 if (z)
71 goto break2;
72 goto loop;
73 }
74 z = v;
75 }
76 err (a->aerr, (EOF), "backspace");
77 }
78break2:
79 FSEEK (f, z, SEEK_SET);
80 return 0;
81}
Note: See TracBrowser for help on using the repository browser.