1
#include "sysdep1.h" /* here to get stat64 on some badly designed Linux systems */
4
#define Const /*nothing*/
14
#include "fmt.h" /* for struct syl */
16
/* Compile this with -DNO_ISATTY if unistd.h does not exist or */
17
/* if it does not define int isatty(int). */
28
/*global definitions*/
29
unit f__units[MXUNIT]; /*unit table*/
30
flag f__init; /*0 on entry, 1 after initializations*/
31
cilist *f__elist; /*active external io list*/
32
icilist *f__svic; /*active internal io list*/
33
flag f__reading; /*1 if reading, 0 if writing*/
34
flag f__cplus,f__cblank;
35
Const char *f__fmtbuf;
36
flag f__external; /*1 if external io, 0 if internal */
38
int (*f__doed)(),(*f__doned)();
39
int (*f__doend)(),(*f__donewrec)(),(*f__dorevert)();
40
int (*f__getn)(); /* for formatted input */
41
void (*f__putn)(); /* for formatted output */
43
int (*f__getn)(void); /* for formatted input */
44
void (*f__putn)(int); /* for formatted output */
45
int (*f__doed)(struct syl*, char*, ftnlen),(*f__doned)(struct syl*);
46
int (*f__dorevert)(void),(*f__donewrec)(void),(*f__doend)(void);
48
flag f__sequential; /*1 if sequential io, 0 if direct*/
49
flag f__formatted; /*1 if formatted io, 0 if unformatted*/
50
FILE *f__cf; /*current file*/
51
unit *f__curunit; /*current unit*/
52
int f__recpos; /*place in current record*/
53
OFF_T f__cursor, f__hiwater;
60
"error in format", /* 100 */
61
"illegal unit number", /* 101 */
62
"formatted io not allowed", /* 102 */
63
"unformatted io not allowed", /* 103 */
64
"direct io not allowed", /* 104 */
65
"sequential io not allowed", /* 105 */
66
"can't backspace file", /* 106 */
67
"null file name", /* 107 */
68
"can't stat file", /* 108 */
69
"unit not connected", /* 109 */
70
"off end of record", /* 110 */
71
"truncation failed in endfile", /* 111 */
72
"incomprehensible list input", /* 112 */
73
"out of free space", /* 113 */
74
"unit not connected", /* 114 */
75
"read unexpected character", /* 115 */
76
"bad logical input field", /* 116 */
77
"bad variable type", /* 117 */
78
"bad namelist name", /* 118 */
79
"variable not in namelist", /* 119 */
80
"no end record", /* 120 */
81
"variable count incorrect", /* 121 */
82
"subscript for scalar variable", /* 122 */
83
"invalid array section", /* 123 */
84
"substring out of bounds", /* 124 */
85
"subscript out of bounds", /* 125 */
86
"can't read file", /* 126 */
87
"can't write file", /* 127 */
88
"'new' file exists", /* 128 */
89
"can't append to file", /* 129 */
90
"non-positive record number", /* 130 */
91
"nmLbuf overflow" /* 131 */
93
#define MAXERR (sizeof(F_err)/sizeof(char *)+100)
97
f__canseek(f) FILE *f; /*SYSDEP*/
99
f__canseek(FILE *f) /*SYSDEP*/
102
#ifdef NON_UNIX_STDIO
103
return !isatty(fileno(f));
107
if (FSTAT(fileno(f),&x) < 0)
110
switch(x.st_mode & S_IFMT) {
113
if(x.st_nlink > 0) /* !pipe */
118
if(isatty(fileno(f)))
129
if (S_ISREG(x.st_mode) || S_ISDIR(x.st_mode)) {
130
if(x.st_nlink > 0) /* !pipe */
135
if (S_ISCHR(x.st_mode)) {
136
if(isatty(fileno(f)))
140
if (S_ISBLK(x.st_mode))
143
Help! How does fstat work on this system?
146
return(0); /* who knows what it is? */
152
f__fatal(n,s) char *s;
154
f__fatal(int n, const char *s)
157
if(n<100 && n>=0) perror(s); /*SYSDEP*/
158
else if(n >= (int)MAXERR || n < -1)
159
{ fprintf(stderr,"%s: illegal error number %d\n",s,n);
161
else if(n == -1) fprintf(stderr,"%s: end of file\n",s);
163
fprintf(stderr,"%s: %s\n",s,F_err[n-100]);
165
fprintf(stderr,"apparent state: unit %d ",
166
(int)(f__curunit-f__units));
167
fprintf(stderr, f__curunit->ufnm ? "named %s\n" : "(unnamed)\n",
171
fprintf(stderr,"apparent state: internal I/O\n");
173
fprintf(stderr,"last format: %s\n",f__fmtbuf);
174
fprintf(stderr,"lately %s %s %s %s",f__reading?"reading":"writing",
175
f__sequential?"sequential":"direct",f__formatted?"formatted":"unformatted",
176
f__external?"external":"internal");
179
/*initialization routine*/
187
p->useek=f__canseek(stderr);
192
p->useek=f__canseek(stdin);
197
p->useek=f__canseek(stdout);
204
f__nowreading(x) unit *x;
206
f__nowreading(unit *x)
211
extern char *f__r_mode[], *f__w_mode[];
217
ufmt = x->url ? 0 : x->ufmt;
220
if (!FREOPEN(x->ufnm, f__w_mode[ufmt|2], x->ufd)) {
222
if(!FREOPEN(x->ufnm, f__r_mode[ufmt], x->ufd)) {
228
FSEEK(x->ufd,loc,SEEK_SET);
237
f__nowwriting(x) unit *x;
239
f__nowwriting(unit *x)
244
extern char *f__w_mode[];
248
FSEEK(x->ufd, (OFF_T)0, SEEK_CUR);
253
ufmt = x->url ? 0 : x->ufmt;
254
if (x->uwrt == 3) { /* just did write, rewind */
255
if (!(f__cf = x->ufd =
256
FREOPEN(x->ufnm,f__w_mode[ufmt],x->ufd)))
262
if (!(f__cf = x->ufd =
263
FREOPEN(x->ufnm, f__w_mode[ufmt | 2], x->ufd)))
271
FSEEK(x->ufd,loc,SEEK_SET);
280
err__fl(f, m, s) int f, m; char *s;
282
err__fl(int f, int m, const char *s)