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
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 #include <cmplrs/fio.h>
00054 #include <mutex.h>
00055 #include <sys/types.h>
00056 #include <sys/stat.h>
00057 #include <errno.h>
00058 #include <stdio.h>
00059 #include <stdlib.h>
00060 #include <mutex.h>
00061 #include <unistd.h>
00062
00063 #include "err.h"
00064 #include "fmt.h"
00065 #include "iomode.h"
00066 #include "util.h"
00067 #include "cmplrs/f_errno.h"
00068 #include "idxio.h"
00069
00070 unit * Internal_File;
00071 int fmt_check = 0;
00072
00073 #define STR(x) (x==NULL?"":x)
00074
00075 #define SHUTUP_G0 = 0
00076
00077 #include "vmsflags.h"
00078
00079
00080 static char *f77F_err[] =
00081 {
00082 "error in format",
00083 "out of space for unit table",
00084 "formatted io not allowed",
00085 "unformatted io not allowed",
00086 "direct io not allowed",
00087 "sequential io not allowed",
00088 "can't backspace file",
00089 "null file name",
00090 "can't stat file",
00091 "file already connected",
00092 "off end of record",
00093 "truncation failed in endfile",
00094 "incomprehensible list input",
00095 "out of free space",
00096 "unit not connected",
00097 "read unexpected character",
00098 "blank logical input field",
00099 "bad variable type",
00100 "bad namelist name",
00101 "variable not in namelist",
00102 "no end record",
00103 "namelist subscript out of range",
00104 "negative repeat count",
00105 "illegal operation for unit",
00106 "off beginning of record",
00107 "no * after repeat count",
00108 "'new' file exists",
00109 "can't find 'old' file",
00110 "unknown system error",
00111 "requires seek ability",
00112 "illegal argument",
00113 "duplicate key value on write",
00114 "indexed file not open",
00115 "bad isam argument",
00116 "bad key description",
00117 "too many open indexed files",
00118 "corrupted isam file",
00119 "isam file not opened for exclusive access",
00120 "record locked",
00121 "key already exists",
00122 "cannot delete primary key",
00123 "beginning or end of file reached",
00124 "cannot find requested record",
00125 "current record not defined",
00126 "isam file is exclusively locked",
00127 "filename too long",
00128 "cannot create lock file",
00129 "record too long",
00130 "key structure does not match file structure",
00131 "direct access on an indexed file not allowed",
00132 "keyed access on a sequential file not allowed",
00133 "keyed access on a relative file not allowed",
00134 "append access on an indexed file not allowed",
00135 "must specify record length",
00136 "key field value type does not match key type",
00137 "character key field value length too long",
00138 "fixed record on sequential file not allowed",
00139 "variable records allowed only on unformatted sequential file",
00140 "stream records allowed only on formatted sequential file",
00141 "maximum number of records in direct access file exceeded",
00142 "attempt to write to a readonly file",
00143 "must specify key descriptions",
00144 "carriage control not allowed for unformatted units",
00145 "indexed files only",
00146 "cannot use on indexed file",
00147 "cannot use on indexed or append file",
00148 "error on closing file",
00149 "invalid code in format specification",
00150 "invalid record number in direct access file",
00151 "cannot have endfile record on non-sequential file",
00152
00153 "cannot position within current file",
00154 "cannot have sequential records on direct access file",
00155 "cannot find namelist in input file ",
00156 "cannot read from stdout",
00157 "cannot write to stdin",
00158 "stat call failed in f77inode",
00159 #ifdef I90
00160 "illegal value for specifier",
00161 "end-of-record condition occurs with PAD=NO",
00162 "EOR= specifier requires ADVANCE=NO",
00163 "SIZE= specifier requires ADVANCE=NO",
00164 "attempt to read from a writeonly file",
00165 "direct unformatted io not allowed",
00166 "cannot open a directory",
00167 "subscript out of bounds",
00168 "function not declared as varargs",
00169 "internal error",
00170 "illegal input value" ,
00171 "position specifier is allowed only for sequential files",
00172 "position specifier has an illegal value",
00173 "Memory exhausted",
00174 "already ALLOCATED (see F90 6.3.1.1)",
00175 "not currently ALLOCATED (see F90 6.3.3.1)",
00176 "not currently ASSOCIATED (see F90 6.3.3.2)",
00177 "not created by ALLOCATE (see F90 6.3.3.2)",
00178 "cannot be DEALLOCATEd via a pointer (see F90 6.3.3.2)"
00179 "cannot keep a file opened as a scratch file"
00180
00181 #else
00182 "",
00183 "",
00184 "",
00185 "",
00186 "",
00187 "direct unformatted io not allowed",
00188 "cannot open a directory",
00189 "subscript out of bounds",
00190 "function not declared as varargs",
00191 "internal error"
00192 ,"illegal input value",
00193 "",
00194 "",
00195 "Memory exhausted",
00196 "",
00197 "",
00198 "",
00199 "",
00200 "",
00201 "cannot keep a file opened as a scratch file",
00202 "edit descriptor conflicts with the I/O item data type"
00203 #endif
00204 };
00205
00206 #define MAXERR (sizeof(f77F_err)/sizeof(char *)+F_ER)
00207
00208 static int f77f_nerr = MAXERR + 1;
00209 extern void _cleanup(void);
00210
00211
00212 void
00213 f77fatal (unit *ftnunit, int n, char *s)
00214 {
00215 char *acc;
00216 char *dumpflag;
00217 int coredump = 0;
00218
00219 if (n < 100 && n >= 0) {
00220 perror (s);
00221 } else if (n >= (int) MAXERR) {
00222 fprintf (stderr, "%s: illegal error number %d\n", s, n);
00223 } else if (n < 0) {
00224 fprintf (stderr, "%s: end of file %d\n", s, n);
00225 } else {
00226 fprintf (stderr, "%s: %s\n", s, f77F_err[n - 100]);
00227 }
00228
00229 if (ftnunit) {
00230 switch (ftnunit->uacc) {
00231 case SEQUENTIAL:
00232 case APPEND:
00233 acc = "sequential";
00234 break;
00235 case DIRECT:
00236 acc = "direct";
00237 break;
00238 case KEYED:
00239 acc = "indexed";
00240 default:
00241 acc = "(null)";
00242 }
00243 fprintf (stderr, "apparent state: unit %d named %s\n",
00244 ftnunit->luno, STR (ftnunit->ufnm));
00245 if (ftnunit->ufmt)
00246 fprintf (stderr, "last format: %s\n", STR (ftnunit->f77fmtbuf));
00247 fprintf (stderr, "Unit %d is a %s %s %s file\n", ftnunit->luno,
00248 acc, ftnunit->ufmt ? "formatted" : "unformatted",
00249 !ftnunit->f77errlist.iciunit ? "external" : "internal");
00250 }
00251 iscleanup();
00252
00253
00254
00255 if (dumpflag = getenv ("f77_dump_flag")) {
00256 coredump = up_low (*dumpflag) == 'y' ? 1 : 0;
00257 }
00258 if (coredump) {
00259 _cleanup ();
00260 abort ();
00261 } else {
00262 _cleanup ();
00263 fprintf (stderr, "*** Execution Terminated (%d) ***\n", n);
00264 exit (n);
00265 }
00266
00267 }
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282 void
00283 f_init (void)
00284 {
00285 unit *p;
00286 static unsigned long init_flag = 0;
00287 static pid_t f_init_pid = 0;
00288 char *num, *v;
00289
00290 if (test_and_set( &init_flag, 1L ) != 0) {
00291
00292 if (getpid() == f_init_pid) return;
00293
00294
00295 while (f77init == 0) {
00296 sginap(0);
00297 }
00298 return;
00299 }
00300 f_init_pid = getpid();
00301
00302 if ((num = getenv ("FORTRAN_OPENED_UNITS")) != NULL)
00303 mxunit = atol(num) + 4;
00304
00305 else
00306 mxunit = INIT_MXUNIT;
00307
00308 f77units =
00309 (unit *) calloc (mxunit, sizeof (unit));
00310
00311
00312
00313 p = map_luno (0);
00314 p->ufd = stderr;
00315 p->luno = 0;
00316 p->uconn = 1;
00317 p->useek = f77canseek (stderr);
00318 p->uistty = isatty (fileno(stderr));
00319 p->ufmt = 1;
00320 p->ucc = CC_LIST;
00321 p->uwrt = WR_READY;
00322 p->ualias = p;
00323
00324
00325
00326 p = map_luno (5);
00327 p->ufd = stdin;
00328 p->luno = 5;
00329 p->uconn = 1;
00330 p->useek = f77canseek (stdin);
00331 p->uistty = isatty (fileno(stdin));
00332 p->ufmt = 1;
00333 p->ucc = CC_NONE;
00334 p->uwrt = 0;
00335
00336
00337
00338 p = p->ualias = map_luno (6);
00339 p->ufd = stdout;
00340 p->luno = 6;
00341 p->uconn = 1;
00342 p->useek = f77canseek (stdout);
00343 p->uistty = isatty (fileno(stdout));
00344 p->ufmt = 1;
00345 p->ucc = (char) (f77vms_flag_[VMS_CC] ? CC_FORTRAN : CC_LIST);
00346 p->ucchar = '\0';
00347 p->uwrt = WR_READY;
00348
00349
00350 p = map_luno(-1);
00351 Internal_File = p;
00352 p->uconn = 1;
00353 p->ufmt = 1;
00354 p->uwrt = WR_READY;
00355
00356 if ((v = getenv ("FMT_CHECK")) != NULL) {
00357 if (*v == 'Y' || *v == 'y') {
00358 fmt_check = 1;
00359 }
00360 }
00361
00362
00363
00364 f77init = 1;
00365
00366
00367
00368
00369
00370
00371
00372
00373 }
00374
00375
00376 int
00377 f77canseek (FILE *f)
00378 {
00379 struct stat x;
00380
00381 (void) fstat (fileno (f), &x);
00382 if (x.st_nlink > 0 && !isatty (fileno (f))) {
00383 return (1);
00384 }
00385 return (0);
00386 }
00387
00388 #if 0
00389
00390 void
00391 s_abort (int errnum)
00392 {
00393 char *dumpflag;
00394 int coredump = 0;
00395
00396 if (dumpflag = getenv ("f77_dump_flag")) {
00397 coredump = up_low (*dumpflag) == 'y' ? 1 : 0;
00398 }
00399 if (coredump) {
00400 _cleanup ();
00401 abort ();
00402 } else {
00403 _cleanup ();
00404 fprintf (stderr, "*** Execution Terminated (%d) ***\n", errnum);
00405 exit (errnum);
00406 }
00407 }
00408 #endif
00409
00410 void
00411 perror_ (char *s, int len)
00412 {
00413 unit *lu;
00414 char buf[40];
00415 char *mesg = s + len;
00416
00417 while (len > 0 && *--mesg == ' ')
00418 len--;
00419 if (errno >= 0 && errno < sys_nerr)
00420 mesg = sys_errlist[errno];
00421 else if (errno >= F_ER && errno <= f77f_nerr)
00422 mesg = f77F_err[errno - F_ER];
00423 else {
00424 sprintf (buf, "%d: unknown error number", errno);
00425 mesg = buf;
00426 }
00427 lu = (unit *) map_luno (0);
00428 while (len-- > 0)
00429 putc (*s++, lu->ufd);
00430 fprintf (lu->ufd, ": %s\n", mesg);
00431 }
00432
00433
00434
00435 void
00436 gerror_ (char *s, int len)
00437 {
00438 char *mesg;
00439
00440 if (errno >= F_ER && errno < f77f_nerr)
00441 mesg = f77F_err[errno - F_ER];
00442 else if (errno >= 0 && errno < sys_nerr)
00443 mesg = sys_errlist[errno];
00444 else
00445 mesg = "unknown error number";
00446 b_char (mesg, s, len);
00447 }
00448
00449
00450 void
00451 strerror_ (int *errno, char *s, int len)
00452 {
00453 char *mesg;
00454
00455 if (*errno >= F_ER && *errno < f77f_nerr)
00456 mesg = f77F_err[*errno - F_ER];
00457 else if (*errno >= 0 && *errno < sys_nerr)
00458 mesg = sys_errlist[*errno];
00459 else
00460 mesg = "unknown error number";
00461 b_char (mesg, s, len);
00462 }