2001-05-16 20:59:29 +02:00
|
|
|
#include "config.h"
|
1998-02-01 02:37:08 +01:00
|
|
|
#ifndef NON_UNIX_STDIO
|
1998-05-19 12:52:03 +02:00
|
|
|
#define _INCLUDE_POSIX_SOURCE /* for HP-UX */
|
|
|
|
#define _INCLUDE_XOPEN_SOURCE /* for HP-UX */
|
1998-02-01 02:37:08 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#endif
|
|
|
|
#include "f2c.h"
|
|
|
|
#undef abs
|
|
|
|
#undef min
|
|
|
|
#undef max
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "fio.h"
|
2002-06-01 14:38:32 +02:00
|
|
|
#include "fmt.h" /* for struct syl */
|
1998-02-01 02:37:08 +01:00
|
|
|
|
|
|
|
/*global definitions*/
|
2002-06-01 14:38:32 +02:00
|
|
|
unit f__units[MXUNIT]; /*unit table */
|
|
|
|
int f__init; /*bit 0: set after initializations;
|
|
|
|
bit 1: set during I/O involving returns to
|
|
|
|
caller of library (or calls to user code) */
|
|
|
|
cilist *f__elist; /*active external io list */
|
|
|
|
icilist *f__svic; /*active internal io list */
|
|
|
|
flag f__reading; /*1 if reading, 0 if writing */
|
|
|
|
flag f__cplus, f__cblank;
|
1998-02-01 02:37:08 +01:00
|
|
|
char *f__fmtbuf;
|
|
|
|
int f__fmtlen;
|
2002-06-01 14:38:32 +02:00
|
|
|
flag f__external; /*1 if external io, 0 if internal */
|
|
|
|
int (*f__getn) (void); /* for formatted input */
|
|
|
|
void (*f__putn) (int); /* for formatted output */
|
|
|
|
int (*f__doed) (struct syl *, char *, ftnlen), (*f__doned) (struct syl *);
|
|
|
|
int (*f__dorevert) (void), (*f__donewrec) (void), (*f__doend) (void);
|
|
|
|
flag f__sequential; /*1 if sequential io, 0 if direct */
|
|
|
|
flag f__formatted; /*1 if formatted io, 0 if unformatted */
|
|
|
|
FILE *f__cf; /*current file */
|
|
|
|
unit *f__curunit; /*current unit */
|
|
|
|
int f__recpos; /*place in current record */
|
1998-02-01 02:37:08 +01:00
|
|
|
int f__cursor, f__hiwater, f__scale;
|
|
|
|
char *f__icptr;
|
|
|
|
|
|
|
|
/*error messages*/
|
2002-06-01 14:38:32 +02:00
|
|
|
char *F_err[] = {
|
|
|
|
"error in format", /* 100 */
|
|
|
|
"illegal unit number", /* 101 */
|
|
|
|
"formatted io not allowed", /* 102 */
|
|
|
|
"unformatted io not allowed", /* 103 */
|
|
|
|
"direct io not allowed", /* 104 */
|
|
|
|
"sequential io not allowed", /* 105 */
|
|
|
|
"can't backspace file", /* 106 */
|
|
|
|
"null file name", /* 107 */
|
|
|
|
"can't stat file", /* 108 */
|
|
|
|
"unit not connected", /* 109 */
|
|
|
|
"off end of record", /* 110 */
|
|
|
|
"truncation failed in endfile", /* 111 */
|
|
|
|
"incomprehensible list input", /* 112 */
|
|
|
|
"out of free space", /* 113 */
|
|
|
|
"unit not connected", /* 114 */
|
|
|
|
"read unexpected character", /* 115 */
|
|
|
|
"bad logical input field", /* 116 */
|
|
|
|
"bad variable type", /* 117 */
|
|
|
|
"bad namelist name", /* 118 */
|
|
|
|
"variable not in namelist", /* 119 */
|
|
|
|
"no end record", /* 120 */
|
|
|
|
"variable count incorrect", /* 121 */
|
|
|
|
"subscript for scalar variable", /* 122 */
|
|
|
|
"invalid array section", /* 123 */
|
|
|
|
"substring out of bounds", /* 124 */
|
|
|
|
"subscript out of bounds", /* 125 */
|
|
|
|
"can't read file", /* 126 */
|
|
|
|
"can't write file", /* 127 */
|
|
|
|
"'new' file exists", /* 128 */
|
|
|
|
"can't append to file", /* 129 */
|
|
|
|
"non-positive record number", /* 130 */
|
|
|
|
"I/O started while already doing I/O", /* 131 */
|
|
|
|
"Temporary file name (TMPDIR?) too long" /* 132 */
|
1998-02-01 02:37:08 +01:00
|
|
|
};
|
|
|
|
#define MAXERR (sizeof(F_err)/sizeof(char *)+100)
|
|
|
|
|
main.c (main): Avoid implicit int.
* libF77/main.c (main): Avoid implicit int.
* libI77/dfe.c (y_rsk, y_getc, c_dfe): Likewise.
* libI77/due.c (c_due): Likewise.
* libI77/err.c (f__canseek, f__nowreading, f__nowwriting):
Likewise.
* libI77/fmt.c (op_gen, ne_d, e_d, pars_f, type_f, en_fio):
Likewise.
* libI77/iio.c (z_getc, z_rnew, c_si, z_wnew): Likewise.
* libI77/lread.c (t_getc, c_le, l_read): Likewise.
* libI77/lwrite.c (l_write): Likewise.
* libI77/open.c (fk_open): Likewise.
* libI77/rdfmt.c (rd_ed, rd_ned): Likewise.
* libI77/rsfe.c (xrd_SL, x_getc, x_endp, x_rev): Likewise.
* libI77/rsne.c (t_getc, x_rsne): Likewise.
* libI77/sfe.c (c_sfe): Likewise.
* libI77/sue.c (c_sue): Likewise.
* libI77/uio.c (do_us): Likewise.
* libI77/wref.c (wrt_E, wrt_F): Likewise.
* libI77/wrtfmt.c (wrt_L, w_ed, w_ned): Likewise.
From-SVN: r54169
2002-06-02 15:01:12 +02:00
|
|
|
int
|
2002-06-01 14:38:32 +02:00
|
|
|
f__canseek (FILE * f) /*SYSDEP*/
|
1998-02-01 02:37:08 +01:00
|
|
|
{
|
|
|
|
#ifdef NON_UNIX_STDIO
|
2002-06-01 14:38:32 +02:00
|
|
|
return !isatty (fileno (f));
|
1998-02-01 02:37:08 +01:00
|
|
|
#else
|
2002-06-01 14:38:32 +02:00
|
|
|
struct stat x;
|
1998-02-01 02:37:08 +01:00
|
|
|
|
2002-06-01 14:38:32 +02:00
|
|
|
if (fstat (fileno (f), &x) < 0)
|
|
|
|
return (0);
|
1998-02-01 02:37:08 +01:00
|
|
|
#ifdef S_IFMT
|
2002-06-01 14:38:32 +02:00
|
|
|
switch (x.st_mode & S_IFMT)
|
|
|
|
{
|
|
|
|
case S_IFDIR:
|
|
|
|
case S_IFREG:
|
|
|
|
if (x.st_nlink > 0) /* !pipe */
|
|
|
|
return (1);
|
|
|
|
else
|
|
|
|
return (0);
|
|
|
|
case S_IFCHR:
|
|
|
|
if (isatty (fileno (f)))
|
|
|
|
return (0);
|
|
|
|
return (1);
|
1998-02-01 02:37:08 +01:00
|
|
|
#ifdef S_IFBLK
|
2002-06-01 14:38:32 +02:00
|
|
|
case S_IFBLK:
|
|
|
|
return (1);
|
1998-02-01 02:37:08 +01:00
|
|
|
#endif
|
2002-06-01 14:38:32 +02:00
|
|
|
}
|
1998-02-01 02:37:08 +01:00
|
|
|
#else
|
|
|
|
#ifdef S_ISDIR
|
2002-06-01 14:38:32 +02:00
|
|
|
/* POSIX version */
|
|
|
|
if (S_ISREG (x.st_mode) || S_ISDIR (x.st_mode))
|
|
|
|
{
|
|
|
|
if (x.st_nlink > 0) /* !pipe */
|
|
|
|
return (1);
|
|
|
|
else
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
if (S_ISCHR (x.st_mode))
|
|
|
|
{
|
|
|
|
if (isatty (fileno (f)))
|
|
|
|
return (0);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
if (S_ISBLK (x.st_mode))
|
|
|
|
return (1);
|
1998-02-01 02:37:08 +01:00
|
|
|
#else
|
2002-06-01 14:38:32 +02:00
|
|
|
Help ! How does fstat work on this system ?
|
1998-02-01 02:37:08 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
2002-06-01 14:38:32 +02:00
|
|
|
return (0); /* who knows what it is? */
|
1998-02-01 02:37:08 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2002-06-01 14:38:32 +02:00
|
|
|
void
|
|
|
|
f__fatal (int n, char *s)
|
1998-02-01 02:37:08 +01:00
|
|
|
{
|
2002-06-01 14:38:32 +02:00
|
|
|
static int dead = 0;
|
1998-02-01 02:37:08 +01:00
|
|
|
|
2002-06-01 14:38:32 +02:00
|
|
|
if (n < 100 && n >= 0)
|
|
|
|
perror (s);
|
|
|
|
/*SYSDEP*/
|
|
|
|
else if (n >= (int) MAXERR || n < -1)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "%s: illegal error number %d\n", s, n);
|
|
|
|
}
|
|
|
|
else if (n == -1)
|
|
|
|
fprintf (stderr, "%s: end of file\n", s);
|
|
|
|
else
|
|
|
|
fprintf (stderr, "%s: %s\n", s, F_err[n - 100]);
|
|
|
|
if (dead)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "(libf2c f__fatal already called, aborting.)");
|
|
|
|
abort ();
|
|
|
|
}
|
|
|
|
dead = 1;
|
|
|
|
if (f__init & 1)
|
|
|
|
{
|
|
|
|
if (f__curunit)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "apparent state: unit %d ",
|
|
|
|
(int) (f__curunit - f__units));
|
|
|
|
fprintf (stderr, f__curunit->ufnm ? "named %s\n" : "(unnamed)\n",
|
|
|
|
f__curunit->ufnm);
|
1998-02-01 02:37:08 +01:00
|
|
|
}
|
2002-06-01 14:38:32 +02:00
|
|
|
else
|
|
|
|
fprintf (stderr, "apparent state: internal I/O\n");
|
|
|
|
if (f__fmtbuf)
|
|
|
|
fprintf (stderr, "last format: %.*s\n", f__fmtlen, f__fmtbuf);
|
|
|
|
fprintf (stderr, "lately %s %s %s %s",
|
|
|
|
f__reading ? "reading" : "writing",
|
|
|
|
f__sequential ? "sequential" : "direct",
|
|
|
|
f__formatted ? "formatted" : "unformatted",
|
|
|
|
f__external ? "external" : "internal");
|
|
|
|
}
|
|
|
|
f__init &= ~2; /* No longer doing I/O (no more user code to be called). */
|
|
|
|
sig_die (" IO", 1);
|
1998-02-01 02:37:08 +01:00
|
|
|
}
|
2002-06-01 14:38:32 +02:00
|
|
|
|
1998-02-01 02:37:08 +01:00
|
|
|
/*initialization routine*/
|
g2c.hin, [...]: Kill VOID, Void and Int.
* g2c.hin, libF77/d_cnjg.c, libF77/main.c, libF77/r_cnjg.c,
libF77/s_cat.c, libF77/s_paus.c, libF77/s_rnge.c, libF77/setarg.c,
libF77/setsig.c, libF77/signal1.h0, libI77/dfe.c, libI77/due.c,
libI77/err.c, libI77/fio.h, libI77/fmt.c, libI77/iio.c,
libI77/ilnw.c, libI77/lread.c, libI77/lwrite.c, libI77/rsfe.c,
libI77/rsli.c, libI77/rsne.c, libI77/sfe.c, libI77/sue.c,
libI77/util.c, libI77/wrtfmt.c, libI77/wsfe.c, libI77/wsle.c,
libI77/xwsne.c, libU77/date_.c: Kill VOID, Void and Int.
From-SVN: r54134
2002-06-01 03:58:10 +02:00
|
|
|
void
|
2002-06-01 14:38:32 +02:00
|
|
|
f_init (void)
|
|
|
|
{
|
|
|
|
unit *p;
|
1998-02-01 02:37:08 +01:00
|
|
|
|
2002-06-01 14:38:32 +02:00
|
|
|
if (f__init & 2)
|
|
|
|
f__fatal (131, "I/O recursion");
|
|
|
|
f__init = 1;
|
|
|
|
p = &f__units[0];
|
|
|
|
p->ufd = stderr;
|
|
|
|
p->useek = f__canseek (stderr);
|
|
|
|
p->ufmt = 1;
|
|
|
|
p->uwrt = 1;
|
|
|
|
p = &f__units[5];
|
|
|
|
p->ufd = stdin;
|
|
|
|
p->useek = f__canseek (stdin);
|
|
|
|
p->ufmt = 1;
|
|
|
|
p->uwrt = 0;
|
|
|
|
p = &f__units[6];
|
|
|
|
p->ufd = stdout;
|
|
|
|
p->useek = f__canseek (stdout);
|
|
|
|
p->ufmt = 1;
|
|
|
|
p->uwrt = 1;
|
1998-02-01 02:37:08 +01:00
|
|
|
}
|
2002-06-01 14:38:32 +02:00
|
|
|
|
main.c (main): Avoid implicit int.
* libF77/main.c (main): Avoid implicit int.
* libI77/dfe.c (y_rsk, y_getc, c_dfe): Likewise.
* libI77/due.c (c_due): Likewise.
* libI77/err.c (f__canseek, f__nowreading, f__nowwriting):
Likewise.
* libI77/fmt.c (op_gen, ne_d, e_d, pars_f, type_f, en_fio):
Likewise.
* libI77/iio.c (z_getc, z_rnew, c_si, z_wnew): Likewise.
* libI77/lread.c (t_getc, c_le, l_read): Likewise.
* libI77/lwrite.c (l_write): Likewise.
* libI77/open.c (fk_open): Likewise.
* libI77/rdfmt.c (rd_ed, rd_ned): Likewise.
* libI77/rsfe.c (xrd_SL, x_getc, x_endp, x_rev): Likewise.
* libI77/rsne.c (t_getc, x_rsne): Likewise.
* libI77/sfe.c (c_sfe): Likewise.
* libI77/sue.c (c_sue): Likewise.
* libI77/uio.c (do_us): Likewise.
* libI77/wref.c (wrt_E, wrt_F): Likewise.
* libI77/wrtfmt.c (wrt_L, w_ed, w_ned): Likewise.
From-SVN: r54169
2002-06-02 15:01:12 +02:00
|
|
|
int
|
2002-06-01 14:38:32 +02:00
|
|
|
f__nowreading (unit * x)
|
1998-02-01 02:37:08 +01:00
|
|
|
{
|
2002-06-01 14:38:32 +02:00
|
|
|
off_t loc;
|
|
|
|
int ufmt, urw;
|
|
|
|
extern char *f__r_mode[], *f__w_mode[];
|
1998-02-01 02:37:08 +01:00
|
|
|
|
2002-06-01 14:38:32 +02:00
|
|
|
if (x->urw & 1)
|
|
|
|
goto done;
|
|
|
|
if (!x->ufnm)
|
|
|
|
goto cantread;
|
|
|
|
ufmt = x->url ? 0 : x->ufmt;
|
|
|
|
loc = FTELL (x->ufd);
|
|
|
|
urw = 3;
|
|
|
|
if (!freopen (x->ufnm, f__w_mode[ufmt | 2], x->ufd))
|
|
|
|
{
|
|
|
|
urw = 1;
|
|
|
|
if (!freopen (x->ufnm, f__r_mode[ufmt], x->ufd))
|
|
|
|
{
|
|
|
|
cantread:
|
|
|
|
errno = 126;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FSEEK (x->ufd, loc, SEEK_SET);
|
|
|
|
x->urw = urw;
|
|
|
|
done:
|
|
|
|
x->uwrt = 0;
|
|
|
|
return 0;
|
1998-02-01 02:37:08 +01:00
|
|
|
}
|
2002-06-01 14:38:32 +02:00
|
|
|
|
main.c (main): Avoid implicit int.
* libF77/main.c (main): Avoid implicit int.
* libI77/dfe.c (y_rsk, y_getc, c_dfe): Likewise.
* libI77/due.c (c_due): Likewise.
* libI77/err.c (f__canseek, f__nowreading, f__nowwriting):
Likewise.
* libI77/fmt.c (op_gen, ne_d, e_d, pars_f, type_f, en_fio):
Likewise.
* libI77/iio.c (z_getc, z_rnew, c_si, z_wnew): Likewise.
* libI77/lread.c (t_getc, c_le, l_read): Likewise.
* libI77/lwrite.c (l_write): Likewise.
* libI77/open.c (fk_open): Likewise.
* libI77/rdfmt.c (rd_ed, rd_ned): Likewise.
* libI77/rsfe.c (xrd_SL, x_getc, x_endp, x_rev): Likewise.
* libI77/rsne.c (t_getc, x_rsne): Likewise.
* libI77/sfe.c (c_sfe): Likewise.
* libI77/sue.c (c_sue): Likewise.
* libI77/uio.c (do_us): Likewise.
* libI77/wref.c (wrt_E, wrt_F): Likewise.
* libI77/wrtfmt.c (wrt_L, w_ed, w_ned): Likewise.
From-SVN: r54169
2002-06-02 15:01:12 +02:00
|
|
|
int
|
2002-06-01 14:38:32 +02:00
|
|
|
f__nowwriting (unit * x)
|
1998-02-01 02:37:08 +01:00
|
|
|
{
|
2002-06-01 14:38:32 +02:00
|
|
|
off_t loc;
|
|
|
|
int ufmt;
|
|
|
|
extern char *f__w_mode[];
|
1998-02-01 02:37:08 +01:00
|
|
|
|
2002-06-01 14:38:32 +02:00
|
|
|
if (x->urw & 2)
|
|
|
|
goto done;
|
|
|
|
if (!x->ufnm)
|
|
|
|
goto cantwrite;
|
|
|
|
ufmt = x->url ? 0 : x->ufmt;
|
|
|
|
if (x->uwrt == 3)
|
|
|
|
{ /* just did write, rewind */
|
|
|
|
if (!(f__cf = x->ufd = freopen (x->ufnm, f__w_mode[ufmt], x->ufd)))
|
|
|
|
goto cantwrite;
|
|
|
|
x->urw = 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
loc = FTELL (x->ufd);
|
|
|
|
if (!(f__cf = x->ufd = freopen (x->ufnm, f__w_mode[ufmt |= 2], x->ufd)))
|
|
|
|
{
|
|
|
|
x->ufd = NULL;
|
|
|
|
cantwrite:
|
|
|
|
errno = 127;
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
x->urw = 3;
|
|
|
|
FSEEK (x->ufd, loc, SEEK_SET);
|
|
|
|
}
|
|
|
|
done:
|
|
|
|
x->uwrt = 1;
|
|
|
|
return 0;
|
1998-02-01 02:37:08 +01:00
|
|
|
}
|
|
|
|
|
2002-06-01 14:38:32 +02:00
|
|
|
int
|
|
|
|
err__fl (int f, int m, char *s)
|
1998-02-01 02:37:08 +01:00
|
|
|
{
|
2002-06-01 14:38:32 +02:00
|
|
|
if (!f)
|
|
|
|
f__fatal (m, s);
|
|
|
|
if (f__doend)
|
|
|
|
(*f__doend) ();
|
|
|
|
f__init &= ~2;
|
|
|
|
return errno = m;
|
|
|
|
}
|