Commit | Line | Data |
---|---|---|
bd899150 | 1 | /* |
161423a6 RE |
2 | * Copyright (c) 1980 Regents of the University of California. |
3 | * All rights reserved. The Berkeley software License Agreement | |
4 | * specifies the terms and conditions for redistribution. | |
bd899150 | 5 | * |
60fce068 | 6 | * @(#)err.c 5.2 %G% |
161423a6 RE |
7 | */ |
8 | ||
9 | /* | |
5e52dbf7 DL |
10 | * fatal(): i/o error routine |
11 | * flush_(): flush file buffer | |
bd899150 DW |
12 | */ |
13 | ||
14 | #include <sys/types.h> | |
15 | #include <sys/stat.h> | |
16 | #include <signal.h> | |
5e52dbf7 | 17 | #include "fio.h" |
bd899150 DW |
18 | |
19 | /* | |
20 | * global definitions | |
21 | */ | |
22 | ||
bd60b332 | 23 | unit units[MXUNIT]; /*unit table*/ |
bd899150 DW |
24 | flag reading; /*1 if reading, 0 if writing*/ |
25 | flag external; /*1 if external io, 0 if internal */ | |
26 | flag sequential; /*1 if sequential io, 0 if direct*/ | |
60fce068 JB |
27 | flag formatted; /*1 if formatted io, 0 if unformatted, |
28 | -1 if list directed, -2 if namelist */ | |
bd899150 DW |
29 | char *fmtbuf, *icptr, *icend, *fmtptr; |
30 | int (*doed)(),(*doned)(); | |
31 | int (*doend)(),(*donewrec)(),(*dorevert)(),(*dotab)(); | |
32 | int (*lioproc)(); | |
33 | int (*getn)(),(*putn)(),(*ungetn)(); /*for formatted io*/ | |
bd899150 DW |
34 | FILE *cf; /*current file structure*/ |
35 | unit *curunit; /*current unit structure*/ | |
36 | int lunit; /*current logical unit*/ | |
37 | char *lfname; /*current filename*/ | |
38 | int recpos; /*place in current record*/ | |
39 | ftnint recnum; /* current record number */ | |
40 | int reclen; /* current record length */ | |
41 | int cursor,scale; | |
42 | int radix; | |
43 | ioflag signit,tab,cplus,cblank,elist,errflag,endflag,lquit,l_first; | |
44 | flag leof; | |
45 | int lcount,line_len; | |
70d375c4 | 46 | struct ioiflg ioiflg_; /* initialization flags */ |
bd899150 DW |
47 | |
48 | /*error messages*/ | |
49 | ||
50 | extern char *sys_errlist[]; | |
51 | extern int sys_nerr; | |
52 | ||
278ccb77 DW |
53 | extern char *f_errlist[]; |
54 | extern int f_nerr; | |
bd899150 DW |
55 | |
56 | ||
57 | fatal(n,s) char *s; | |
58 | { | |
59 | ftnint lu; | |
60 | ||
61 | for (lu=1; lu < MXUNIT; lu++) | |
62 | flush_(&lu); | |
63 | if(n<0) | |
64 | fprintf(stderr,"%s: [%d] end of file\n",s,n); | |
65 | else if(n>=0 && n<sys_nerr) | |
66 | fprintf(stderr,"%s: [%d] %s\n",s,n,sys_errlist[n]); | |
278ccb77 | 67 | else if(n>=F_ER && n<F_MAXERR) |
bd899150 DW |
68 | fprintf(stderr,"%s: [%d] %s\n",s,n,f_errlist[n-F_ER]); |
69 | else | |
70 | fprintf(stderr,"%s: [%d] unknown error number\n",s,n); | |
71 | if(external) | |
72 | { | |
73 | if(!lfname) switch (lunit) | |
74 | { case STDERR: lfname = "stderr"; | |
75 | break; | |
76 | case STDIN: lfname = "stdin"; | |
77 | break; | |
78 | case STDOUT: lfname = "stdout"; | |
79 | break; | |
80 | default: lfname = ""; | |
81 | } | |
82 | fprintf(stderr,"logical unit %d, named '%s'\n",lunit,lfname); | |
83 | } | |
84 | if (elist) | |
8fbd82cd | 85 | { fprintf(stderr,"lately: %s %s %s %s I/O\n", |
bd899150 DW |
86 | reading?"reading":"writing", |
87 | sequential?"sequential":"direct", | |
60fce068 JB |
88 | formatted>0?"formatted":(formatted==0?"unformatted": |
89 | (formatted==LISTDIRECTED?"list":"namelist")), | |
bd899150 DW |
90 | external?"external":"internal"); |
91 | if (formatted) | |
92 | { if(fmtbuf) prnt_fmt(n); | |
93 | if (external) | |
94 | { if(reading && curunit->useek) | |
95 | prnt_ext(); /* print external data */ | |
96 | } | |
97 | else prnt_int(); /* print internal array */ | |
98 | } | |
99 | } | |
8fbd82cd | 100 | f77_abort(n); |
bd899150 DW |
101 | } |
102 | ||
5e52dbf7 | 103 | LOCAL |
bd899150 DW |
104 | prnt_ext() |
105 | { int ch; | |
106 | int i=1; | |
107 | long loc; | |
108 | fprintf (stderr, "part of last data: "); | |
109 | loc = ftell(curunit->ufd); | |
110 | if(loc) | |
111 | { if(loc==1L) rewind(curunit->ufd); | |
112 | else for(;i<12 && last_char(curunit->ufd)!='\n';i++); | |
e2841838 | 113 | while(i--) ffputc(fgetc(curunit->ufd),stderr); |
bd899150 DW |
114 | } |
115 | fputc('|',stderr); | |
e2841838 | 116 | for(i=0;i<5 && (ch=fgetc(curunit->ufd))!=EOF;i++) ffputc(ch,stderr); |
bd899150 DW |
117 | fputc('\n',stderr); |
118 | } | |
119 | ||
5e52dbf7 | 120 | LOCAL |
bd899150 DW |
121 | prnt_int() |
122 | { char *ep; | |
123 | fprintf (stderr,"part of last string: "); | |
124 | ep = icptr - (recpos<12?recpos:12); | |
e2841838 | 125 | while (ep<icptr) ffputc(*ep++,stderr); |
bd899150 | 126 | fputc('|',stderr); |
e2841838 | 127 | while (ep<(icptr+5) && ep<icend) ffputc(*ep++,stderr); |
bd899150 DW |
128 | fputc('\n',stderr); |
129 | } | |
130 | ||
5e52dbf7 | 131 | LOCAL |
bd899150 DW |
132 | prnt_fmt(n) int n; |
133 | { int i; char *ep; | |
a4042d05 | 134 | fprintf(stderr, "format: "); |
43666f58 | 135 | if(n==F_ERFMT) |
bd899150 | 136 | { i = fmtptr - fmtbuf; |
a4042d05 DL |
137 | ep = fmtptr - (i<25?i:25); |
138 | if(ep != fmtbuf) fprintf(stderr, "... "); | |
bd899150 DW |
139 | i = i + 5; |
140 | } | |
141 | else | |
142 | { ep = fmtbuf; | |
143 | i = 25; | |
144 | fmtptr = fmtbuf - 1; | |
145 | } | |
146 | while(i && *ep) | |
e2841838 | 147 | { ffputc((*ep==GLITCH)?'"':*ep,stderr); |
bd899150 DW |
148 | if(ep==fmtptr) fputc('|',stderr); |
149 | ep++; i--; | |
150 | } | |
a4042d05 | 151 | if(*ep) fprintf(stderr, " ..."); |
bd899150 DW |
152 | fputc('\n',stderr); |
153 | } | |
154 | ||
5e52dbf7 | 155 | LOCAL |
e2841838 DW |
156 | ffputc(c, f) |
157 | int c; | |
158 | FILE *f; | |
159 | { | |
160 | c &= 0177; | |
161 | if (c < ' ' || c == 0177) | |
162 | { | |
163 | fputc('^', f); | |
164 | c ^= 0100; | |
165 | } | |
166 | fputc(c, f); | |
167 | } | |
168 | ||
5e52dbf7 DL |
169 | ftnint |
170 | flush_(u) ftnint *u; | |
d8e31067 | 171 | { |
5e52dbf7 | 172 | FILE *F; |
bd899150 | 173 | |
5e52dbf7 DL |
174 | if(not_legal(*u)) |
175 | return(F_ERUNIT); | |
176 | F = units[*u].ufd; | |
177 | if(F) | |
178 | return(fflush(F)); | |
179 | else | |
180 | return(F_ERNOPEN); | |
181 | } |