home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD2.bin
/
bbs
/
gnu
/
f2c-1993.04.28-src.lha
/
f2c-1993.04.28
/
src
/
io.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-04-28
|
29KB
|
1,421 lines
/****************************************************************
Copyright 1990, 1991, 1993 by AT&T Bell Laboratories and Bellcore.
Permission to use, copy, modify, and distribute this software
and its documentation for any purpose and without fee is hereby
granted, provided that the above copyright notice appear in all
copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the names of AT&T Bell Laboratories or
Bellcore or any of their entities not be used in advertising or
publicity pertaining to distribution of the software without
specific, written prior permission.
AT&T and Bellcore disclaim all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall AT&T or Bellcore be liable for
any special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
****************************************************************/
/* Routines to generate code for I/O statements.
Some corrections and improvements due to David Wasley, U. C. Berkeley
*/
/* TEMPORARY */
#define TYIOINT TYLONG
#define SZIOINT SZLONG
#include "defs.h"
#include "names.h"
#include "iob.h"
extern int inqmask;
LOCAL void dofclose(), dofinquire(), dofinquire(), dofmove(), dofopen(),
doiolist(), ioset(), ioseta(), iosetc(), iosetip(), iosetlc(),
putio(), putiocall();
iob_data *iob_list;
Addrp io_structs[9];
LOCAL char ioroutine[12];
LOCAL long ioendlab;
LOCAL long ioerrlab;
LOCAL int endbit;
LOCAL int errbit;
LOCAL long jumplab;
LOCAL long skiplab;
LOCAL int ioformatted;
LOCAL int statstruct = NO;
LOCAL struct Labelblock *skiplabel;
Addrp ioblkp;
#define UNFORMATTED 0
#define FORMATTED 1
#define LISTDIRECTED 2
#define NAMEDIRECTED 3
#define V(z) ioc[z].iocval
#define IOALL 07777
LOCAL struct Ioclist
{
char *iocname;
int iotype;
expptr iocval;
}
ioc[ ] =
{
{ "", 0 },
{ "unit", IOALL },
{ "fmt", M(IOREAD) | M(IOWRITE) },
{ "err", IOALL },
{ "end", M(IOREAD) },
{ "iostat", IOALL },
{ "rec", M(IOREAD) | M(IOWRITE) },
{ "recl", M(IOOPEN) | M(IOINQUIRE) },
{ "file", M(IOOPEN) | M(IOINQUIRE) },
{ "status", M(IOOPEN) | M(IOCLOSE) },
{ "access", M(IOOPEN) | M(IOINQUIRE) },
{ "form", M(IOOPEN) | M(IOINQUIRE) },
{ "blank", M(IOOPEN) | M(IOINQUIRE) },
{ "exist", M(IOINQUIRE) },
{ "opened", M(IOINQUIRE) },
{ "number", M(IOINQUIRE) },
{ "named", M(IOINQUIRE) },
{ "name", M(IOINQUIRE) },
{ "sequential", M(IOINQUIRE) },
{ "direct", M(IOINQUIRE) },
{ "formatted", M(IOINQUIRE) },
{ "unformatted", M(IOINQUIRE) },
{ "nextrec", M(IOINQUIRE) },
{ "nml", M(IOREAD) | M(IOWRITE) }
};
#define NIOS (sizeof(ioc)/sizeof(struct Ioclist) - 1)
/* #define IOSUNIT 1 */
/* #define IOSFMT 2 */
#define IOSERR 3
#define IOSEND 4
#define IOSIOSTAT 5
#define IOSREC 6
#define IOSRECL 7
#define IOSFILE 8
#define IOSSTATUS 9
#define IOSACCESS 10
#define IOSFORM 11
#define IOSBLANK 12
#define IOSEXISTS 13
#define IOSOPENED 14
#define IOSNUMBER 15
#define IOSNAMED 16
#define IOSNAME 17
#define IOSSEQUENTIAL 18
#define IOSDIRECT 19
#define IOSFORMATTED 20
#define IOSUNFORMATTED 21
#define IOSNEXTREC 22
#define IOSNML 23
#define IOSTP V(IOSIOSTAT)
/* offsets in generated structures */
#define SZFLAG SZIOINT
/* offsets for external READ and WRITE statements */
#define XERR 0
#define XUNIT SZFLAG
#define XEND SZFLAG + SZIOINT
#define XFMT 2*SZFLAG + SZIOINT
#define XREC 2*SZFLAG + SZIOINT + SZADDR
/* offsets for internal READ and WRITE statements */
#define XIUNIT SZFLAG
#define XIEND SZFLAG + SZADDR
#define XIFMT 2*SZFLAG + SZADDR
#define XIRLEN 2*SZFLAG + 2*SZADDR
#define XIRNUM 2*SZFLAG + 2*SZADDR + SZIOINT
#define XIREC 2*SZFLAG + 2*SZADDR + 2*SZIOINT
/* offsets for OPEN statements */
#define XFNAME SZFLAG + SZIOINT
#define XFNAMELEN SZFLAG + SZIOINT + SZADDR
#define XSTATUS SZFLAG + 2*SZIOINT + SZADDR
#define XACCESS SZFLAG + 2*SZIOINT + 2*SZADDR
#define XFORMATTED SZFLAG + 2*SZIOINT + 3*SZADDR
#define XRECLEN SZFLAG + 2*SZIOINT + 4*SZADDR
#define XBLANK SZFLAG + 3*SZIOINT + 4*SZADDR
/* offset for CLOSE statement */
#define XCLSTATUS SZFLAG + SZIOINT
/* offsets for INQUIRE statement */
#define XFILE SZFLAG + SZIOINT
#define XFILELEN SZFLAG + SZIOINT + SZADDR
#define XEXISTS SZFLAG + 2*SZIOINT + SZADDR
#define XOPEN SZFLAG + 2*SZIOINT + 2*SZADDR
#define XNUMBER SZFLAG + 2*SZIOINT + 3*SZADDR
#define XNAMED SZFLAG + 2*SZIOINT + 4*SZADDR
#define XNAME SZFLAG + 2*SZIOINT + 5*SZADDR
#define XNAMELEN SZFLAG + 2*SZIOINT + 6*SZADDR
#define XQACCESS SZFLAG + 3*SZIOINT + 6*SZADDR
#define XQACCLEN SZFLAG + 3*SZIOINT + 7*SZADDR
#define XSEQ SZFLAG + 4*SZIOINT + 7*SZADDR
#define XSEQLEN SZFLAG + 4*SZIOINT + 8*SZADDR
#define XDIRECT SZFLAG + 5*SZIOINT + 8*SZADDR
#define XDIRLEN SZFLAG + 5*SZIOINT + 9*SZADDR
#define XFORM SZFLAG + 6*SZIOINT + 9*SZADDR
#define XFORMLEN SZFLAG + 6*SZIOINT + 10*SZADDR
#define XFMTED SZFLAG + 7*SZIOINT + 10*SZADDR
#define XFMTEDLEN SZFLAG + 7*SZIOINT + 11*SZADDR
#define XUNFMT SZFLAG + 8*SZIOINT + 11*SZADDR
#define XUNFMTLEN SZFLAG + 8*SZIOINT + 12*SZADDR
#define XQRECL SZFLAG + 9*SZIOINT + 12*SZADDR
#define XNEXTREC SZFLAG + 9*SZIOINT + 13*SZADDR
#define XQBLANK SZFLAG + 9*SZIOINT + 14*SZADDR
#define XQBLANKLEN SZFLAG + 9*SZIOINT + 15*SZADDR
LOCAL char *cilist_names[] = {
"cilist",
"cierr",
"ciunit",
"ciend",
"cifmt",
"cirec"
};
LOCAL char *icilist_names[] = {
"icilist",
"icierr",
"iciunit",
"iciend",
"icifmt",
"icirlen",
"icirnum"
};
LOCAL char *olist_names[] = {
"olist",
"oerr",
"ounit",
"ofnm",
"ofnmlen",
"osta",
"oacc",
"ofm",
"orl",
"oblnk"
};
LOCAL char *cllist_names[] = {
"cllist",
"cerr",
"cunit",
"csta"
};
LOCAL char *alist_names[] = {
"alist",
"aerr",
"aunit"
};
LOCAL char *inlist_names[] = {
"inlist",
"inerr",
"inunit",
"infile",
"infilen",
"inex",
"inopen",
"innum",
"innamed",
"inname",
"innamlen",
"inacc",
"inacclen",
"inseq",
"inseqlen",
"indir",
"indirlen",
"infmt",
"infmtlen",
"inform",
"informlen",
"inunf",
"inunflen",
"inrecl",
"innrec",
"inblank",
"inblanklen"
};
LOCAL char **io_fields;
#define zork(n,t) n, sizeof(n)/sizeof(char *) - 1, t
LOCAL io_setup io_stuff[] = {
zork(cilist_names, TYCILIST), /* external read/write */
zork(inlist_names, TYINLIST), /* inquire */
zork(olist_names, TYOLIST), /* open */
zork(cllist_names, TYCLLIST), /* close */
zork(alist_names, TYALIST), /* rewind */
zork(alist_names, TYALIST), /* backspace */
zork(alist_names, TYALIST), /* endfile */
zork(icilist_names,TYICILIST), /* internal read */
zork(icilist_names,TYICILIST) /* internal write */
};
#undef zork
fmtstmt(lp)
register struct Labelblock *lp;
{
if(lp == NULL)
{
execerr("unlabeled format statement" , CNULL);
return(-1);
}
if(lp->labtype == LABUNKNOWN)
{
lp->labtype = LABFORMAT;
lp->labelno = newlabel();
}
else if(lp->labtype != LABFORMAT)
{
execerr("bad format number", CNULL);
return(-1);
}
return(lp->labelno);
}
setfmt(lp)
struct Labelblock *lp;
{
int n;
char *s0, *lexline();
register char *s, *se, *t;
register k;
s0 = s = lexline(&n);
se = t = s + n;
/* warn of trivial errors, e.g. " 11 CONTINUE" (one too few spaces) */
/* following FORMAT... */
if (n <= 0)
warn("No (...) after FORMAT");
else if (*s != '(')
warni("%c rather than ( after FORMAT", *s);
else if (se[-1] != ')') {
*se = 0;
while(--t > s && *t != ')') ;
if (t <= s)
warn("No ) at end of FORMAT statement");
else if (se - t > 30)
warn1("Extraneous text at end of FORMAT: ...%s", se-12);
else
warn1("Extraneous text at end of FORMAT: %s", t+1);
t = se;
}
/* fix MYQUOTES (\002's) and \\'s */
while(s < se)
switch(*s++) {
case 2:
t += 3; break;
case '"':
case '\\':
t++; break;
}
s = s0;
if (lp) {
lp->fmtstring = t = mem((int)(t - s + 1), 0);
while(s < se)
switch(k = *s++) {
case 2:
t[0] = '\\';
t[1] = '0';
t[2] = '0';
t[3] = '2';