|
|
1.1 root 1: /*
2: * file i/o error and initialization routines
3: */
4:
5: #include <sys/types.h>
6: #include <sys/stat.h>
7: #include <signal.h>
8: #include "fiodefs.h"
9:
10: /*
11: * global definitions
12: */
13:
14: char *tmplate = "tmp.FXXXXXX"; /* scratch file template */
15: char *fortfile = "fort.%D"; /* default file template */
16:
17: unit units[MXUNIT]; /*unit table*/
18: flag reading; /*1 if reading, 0 if writing*/
19: flag external; /*1 if external io, 0 if internal */
20: flag sequential; /*1 if sequential io, 0 if direct*/
21: flag formatted; /*1 if formatted io, 0 if unformatted, -1 if list*/
22: char *fmtbuf, *icptr, *icend, *fmtptr;
23: int (*doed)(),(*doned)();
24: int (*doend)(),(*donewrec)(),(*dorevert)(),(*dotab)();
25: int (*lioproc)();
26: int (*getn)(),(*putn)(),(*ungetn)(); /*for formatted io*/
27: icilist *svic; /* active internal io list */
28: FILE *cf; /*current file structure*/
29: unit *curunit; /*current unit structure*/
30: int lunit; /*current logical unit*/
31: char *lfname; /*current filename*/
32: int recpos; /*place in current record*/
33: ftnint recnum; /* current record number */
34: int reclen; /* current record length */
35: int cursor,scale;
36: int radix;
37: ioflag signit,tab,cplus,cblank,elist,errflag,endflag,lquit,l_first;
38: flag leof;
39: int lcount,line_len;
40:
41: /*error messages*/
42:
43: extern char *sys_errlist[];
44:
45: char *F_err[] =
46: {
47: /* 100 */ "error in format",
48: /* 101 */ "illegal unit number",
49: /* 102 */ "formatted io not allowed",
50: /* 103 */ "unformatted io not allowed",
51: /* 104 */ "direct io not allowed",
52: /* 105 */ "sequential io not allowed",
53: /* 106 */ "can't backspace file",
54: /* 107 */ "off beginning of record",
55: /* 108 */ "can't stat file",
56: /* 109 */ "no * after repeat count",
57: /* 110 */ "off end of record",
58: /* 111 */ "truncation failed",
59: /* 112 */ "incomprehensible list input",
60: /* 113 */ "out of free space",
61: /* 114 */ "unit not connected",
62: /* 115 */ "read unexpected character",
63: /* 116 */ "blank logical input field",
64: /* 117 */ "'new' file exists",
65: /* 118 */ "can't find 'old' file",
66: /* 119 */ "unknown system error",
67: /* 120 */ "requires seek ability",
68: /* 121 */ "illegal argument",
69: };
70:
71: #define MAXERR (sizeof(F_err)/sizeof(char *)+100)
72:
73:
74: fatal(n,s) char *s;
75: {
76: if(n<100 && n>=0)
77: fprintf(stderr,"%s: [%d] %s\n",s,n,sys_errlist[n]);
78: else if(n>=(int)MAXERR)
79: fprintf(stderr,"%s: [%d] illegal error number\n",s,n);
80: else if(n<0)
81: fprintf(stderr,"%s: [%d] end of file\n",s,n);
82: else
83: fprintf(stderr,"%s: [%d] %s\n",s,n,F_err[n-100]);
84: if(external)
85: {
86: if(!lfname) switch (lunit)
87: { case STDERR: lfname = "stderr";
88: break;
89: case STDIN: lfname = "stdin";
90: break;
91: case STDOUT: lfname = "stdout";
92: break;
93: default: lfname = "";
94: }
95: fprintf(stderr,"logical unit %d, named '%s'\n",lunit,lfname);
96: }
97: if (elist)
98: { fprintf(stderr,"lately: %s %s %s %s IO\n",
99: reading?"reading":"writing",
100: sequential?"sequential":"direct",
101: formatted>0?"formatted":(formatted<0?"list":"unformatted"),
102: external?"external":"internal");
103: if (formatted)
104: { if(fmtbuf) prnt_fmt(n);
105: if (external)
106: { if(reading && curunit->useek)
107: prnt_ext(); /* print external data */
108: }
109: else prnt_int(); /* print internal array */
110: }
111: }
112: _cleanup();
113: abort();
114: }
115:
116: prnt_ext()
117: { int ch;
118: int i=1;
119: long loc;
120: fprintf (stderr, "part of last data: ");
121: loc = ftell(curunit->ufd);
122: if(loc)
123: { if(loc==1L) rewind(curunit->ufd);
124: else for(;i<12 && last_char(curunit->ufd)!='\n';i++);
125: while(i--) fputc(fgetc(curunit->ufd),stderr);
126: }
127: fputc('|',stderr);
128: for(i=0;i<5 && (ch=fgetc(curunit->ufd)!=EOF);i++) fputc(ch,stderr);
129: fputc('\n',stderr);
130: }
131:
132: prnt_int()
133: { char *ep;
134: fprintf (stderr,"part of last string: ");
135: ep = icptr - (recpos<12?recpos:12);
136: while (ep<icptr) fputc(*ep++,stderr);
137: fputc('|',stderr);
138: while (ep<(icptr+5) && ep<icend) fputc(*ep++,stderr);
139: fputc('\n',stderr);
140: }
141:
142: prnt_fmt(n) int n;
143: { int i; char *ep;
144: fprintf(stderr, "part of last format: ");
145: if(n==100)
146: { i = fmtptr - fmtbuf;
147: ep = fmtptr - (i<20?i:20);
148: i = i + 5;
149: }
150: else
151: { ep = fmtbuf;
152: i = 25;
153: fmtptr = fmtbuf - 1;
154: }
155: while(i && *ep)
156: { fputc((*ep==GLITCH)?'"':*ep,stderr);
157: if(ep==fmtptr) fputc('|',stderr);
158: ep++; i--;
159: }
160: fputc('\n',stderr);
161: }
162:
163: /*initialization routine*/
164: f_init()
165: { ini_std(STDERR, stderr, WRITE);
166: ini_std(STDIN, stdin, READ);
167: ini_std(STDOUT, stdout, WRITE);
168: }
169:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.