00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #pragma ident "@(#) libf/fio/fcontext.c 92.1 06/18/99 16:08:47"
00039
00040 #include <ctype.h>
00041 #include <errno.h>
00042 #include <stdio.h>
00043 #include <stdlib.h>
00044 #include <string.h>
00045 #include "fio.h"
00046
00047 #define MAX_ENT_LEN 32
00048
00049 extern int _who_called_me();
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 void
00067 _fcontext(FIOSPTR css)
00068 {
00069 register short is_int;
00070 register int utindex;
00071 char *file, *fstruct, *idir, *oprn, *sepr;
00072 register unum_t unum;
00073 long stmt;
00074 unit *cup;
00075
00076
00077
00078 if (css == NULL)
00079 return;
00080
00081
00082
00083 cup = css->f_cu;
00084 unum = css->f_curun;
00085 stmt = css->f_iostmt;
00086 is_int = css->f_intflg;
00087
00088 file = (!OPEN_UPTR(cup) || cup->alfnm == NULL) ? NULL : cup->alfnm;
00089
00090 if (stmt & TF_READ)
00091 idir = " READ from";
00092 else
00093 if (stmt & TF_WRITE)
00094 idir = " WRITE to";
00095 else
00096 idir = "";
00097
00098
00099
00100 switch (stmt) {
00101
00102 case T_RSF:
00103 case T_WSF:
00104 oprn = " sequential formatted";
00105 break;
00106
00107 case T_RSU:
00108 case T_WSU:
00109 oprn = " sequential unformatted";
00110 break;
00111
00112 case T_RDF:
00113 case T_WDF:
00114 oprn = " direct access formatted";
00115 break;
00116
00117 case T_RDU:
00118 case T_WDU:
00119 oprn = " direct access unformatted";
00120 break;
00121
00122 case T_RLIST:
00123 case T_WLIST:
00124 oprn = " list-directed";
00125 break;
00126
00127 case T_RNL:
00128 case T_WNL:
00129 oprn = " namelist";
00130 break;
00131
00132 case T_BUFOUT:
00133 oprn = " BUFFER OUT on";
00134 idir = "";
00135 break;
00136
00137 case T_BUFIN:
00138 oprn = " BUFFER IN from";
00139 idir = "";
00140 break;
00141
00142 case T_OPEN:
00143 oprn = "n OPEN of";
00144 idir = "";
00145 break;
00146
00147 case T_REWIND:
00148 oprn = " REWIND on";
00149 idir = "";
00150 break;
00151
00152 case T_BACKSPACE:
00153 oprn = " BACKSPACE on";
00154 idir = "";
00155 break;
00156
00157 case T_ENDFILE:
00158 oprn = "n ENDFILE on";
00159 idir = "";
00160 break;
00161
00162 case T_CLOSE:
00163 oprn = " CLOSE of";
00164 idir = "";
00165 break;
00166
00167 case T_INQF:
00168 oprn = "n INQUIRE by file on";
00169 unum = -1;
00170 idir = "";
00171 break;
00172
00173 case T_INQU:
00174 oprn = "n INQUIRE by unit on";
00175 idir = "";
00176 break;
00177
00178 case T_GETPOS:
00179 oprn = " GETPOS on";
00180 idir = "";
00181 break;
00182
00183 case T_SETPOS:
00184 oprn = " SETPOS on";
00185 idir = "";
00186 break;
00187
00188 case T_LENGTH:
00189 oprn = " LENGTH function on";
00190 idir = "";
00191 break;
00192
00193 case T_UNIT:
00194 oprn = " UNIT function on";
00195 idir = "";
00196 break;
00197
00198 case T_TAPE:
00199 oprn = " tape operation on";
00200 idir = "";
00201 break;
00202
00203 default:
00204 oprn = "n I/O operation on";
00205 break;
00206
00207 }
00208
00209 (void) fprintf(errfile, "\nEncountered during a%s%s", oprn, idir);
00210
00211 if (is_int)
00212 (void) fprintf(errfile,
00213 " an internal file (character variable)\n");
00214 else {
00215 if (unum != -1) {
00216 (void) fprintf(errfile, " unit %lld\n", unum);
00217
00218 (void) fprintf(errfile, "Fortran unit %lld is ",
00219 unum);
00220
00221 if (!OPEN_UPTR(cup)) {
00222 if (GOOD_UNUM(unum))
00223 (void) fprintf(errfile,
00224 "not connected\n");
00225 else
00226 (void) fprintf(errfile,
00227 "not a valid unit number\n");
00228 }
00229 else {
00230 (void) fprintf(errfile, "connected to ");
00231
00232 utindex = IO_TYPE(cup);
00233 fstruct = FIO_STRUCT(_deduce_fstruct(
00234 cup->ufs,
00235 (struct fdinfo*)cup->ufp.fdc,
00236 cup->ufmt));
00237
00238 if (fstruct == NULL)
00239 fstruct = "";
00240
00241 (void) fprintf(errfile, "a %s %s file",
00242 FIO_METHOD(utindex), fstruct);
00243
00244 if (file == NULL && cup->ufs != FS_FDC) {
00245 if (cup->ufp.std == stdin)
00246 file = "standard input";
00247 else if (cup->ufp.std == stdout)
00248 file = "standard output";
00249 else if (cup->ufp.std == stderr)
00250 file = "standard error";
00251 else
00252 file = "unnamed";
00253
00254 (void) fprintf(errfile,
00255 "\n (%s).\n", file);
00256 }
00257 else {
00258 if ((int)strlen(file) > 8)
00259 sepr = ":\n ";
00260 else
00261 sepr = ": ";
00262
00263 (void) fprintf(errfile, "%s\"%s\"\n",
00264 sepr, file);
00265 }
00266
00267
00268
00269
00270
00271
00272
00273 if ((stmt & TF_FMT) &&
00274 css->u.fmt.u.fe.fmtbuf != NULL) {
00275
00276 int i, offset;
00277
00278 offset = css->u.fmt.u.fe.fmtcol - 2 +
00279 fprintf(errfile,
00280 " Current format: ");
00281
00282 if (css->u.fmt.u.fe.fmtnum > 0)
00283
00284 offset = offset +
00285 fprintf(errfile,
00286 "%5d FORMAT",
00287 css->u.fmt.u.fe.fmtnum);
00288
00289 (void) fprintf(errfile, "%.*s\n",
00290 css->u.fmt.u.fe.fmtlen,
00291 css->u.fmt.u.fe.fmtbuf);
00292
00293 for (i = 0; i <= offset; i++)
00294 (void) fprintf(errfile, " ");
00295
00296 (void) fprintf(errfile, "^\n");
00297 }
00298 }
00299 }
00300 else
00301 if (file == NULL)
00302 (void) fprintf(errfile,
00303 " an indeterminate file\n");
00304 else
00305 (void) fprintf(errfile, " file \"%s\"\n", file);
00306 }
00307
00308
00309
00310
00311
00312 #ifdef _UNICOS
00313 {
00314 int len, lineno;
00315 char name[MAX_ENT_LEN];
00316
00317 len = _who_called_me(&lineno, name, MAX_ENT_LEN, 2);
00318
00319 if (len > 0) {
00320
00321 name[len] = '\0';
00322
00323 (void) fprintf(errfile,
00324 "Error initiated at line %d in routine '%s'.\n",
00325 lineno, name);
00326 }
00327 }
00328 #endif
00329
00330 #ifdef _CRAY2
00331
00332
00333
00334
00335
00336
00337 (void) _tracebk(25, errfile);
00338 #endif
00339
00340 return;
00341 }