1: /*
   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.
   5:  *
   6:  *	@(#)err.c	5.2.1	1996/3/22
   7:  */
   8: 
   9: /*
  10:  * fatal(): i/o error routine
  11:  * flush_(): flush file buffer
  12:  */
  13: 
  14: #include <sys/types.h>
  15: #include <sys/stat.h>
  16: #include <signal.h>
  17: #include "fio.h"
  18: 
  19: /*
  20:  * global definitions
  21:  */
  22: 
  23: unit units[MXUNIT]; /*unit table*/
  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*/
  27: flag formatted;     /*1 if formatted io,	0 if unformatted,
  28: 				-1 if list directed, -2 if namelist */
  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*/
  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;
  46: struct ioiflg ioiflg_;  /* initialization flags */
  47: 
  48: /*error messages*/
  49: 
  50: extern char *f_errlist[];
  51: extern int f_nerr;
  52: 
  53: fatal(n,s) char *s;
  54: {
  55:     ftnint lu;
  56: 
  57:     for (lu=1; lu < MXUNIT; lu++)
  58:         flush_(&lu);
  59:     if(n<0)
  60:         fprintf(stderr,"%s: [%d] end of file\n",s,n);
  61:     else if(n>=F_ER && n<F_MAXERR)
  62:         fprintf(stderr,"%s: [%d] %s\n",s,n,f_errlist[n-F_ER]);
  63:     else
  64:         fprintf(stderr,"%s: [%d] %s\n",s,n,strerror(n));
  65:     if(external)
  66:     {
  67:         if(!lfname) switch (lunit)
  68:         {   case STDERR: lfname = "stderr";
  69:                     break;
  70:             case STDIN:  lfname = "stdin";
  71:                     break;
  72:             case STDOUT: lfname = "stdout";
  73:                     break;
  74:             default:     lfname = "";
  75:         }
  76:         fprintf(stderr,"logical unit %d, named '%s'\n",lunit,lfname);
  77:     }
  78:     if (elist)
  79:     {   fprintf(stderr,"lately: %s %s %s %s I/O\n",
  80:             reading?"reading":"writing",
  81:             sequential?"sequential":"direct",
  82:             formatted>0?"formatted":(formatted==0?"unformatted":
  83:                 (formatted==LISTDIRECTED?"list":"namelist")),
  84:             external?"external":"internal");
  85:         if (formatted)
  86:         {   if(fmtbuf) prnt_fmt(n);
  87:             if (external)
  88:             {   if(reading && curunit->useek)
  89:                     prnt_ext();  /* print external data */
  90:             }
  91:             else prnt_int();    /* print internal array */
  92:         }
  93:     }
  94:     f77_abort(1, n);
  95: }
  96: 
  97: LOCAL
  98: prnt_ext()
  99: {   int ch;
 100:     int i=1;
 101:     long loc;
 102:     fprintf (stderr, "part of last data: ");
 103:     loc = ftell(curunit->ufd);
 104:     if(loc)
 105:     {   if(loc==1L) rewind(curunit->ufd);
 106:         else for(;i<12 && last_char(curunit->ufd)!='\n';i++);
 107:         while(i--) ffputc(fgetc(curunit->ufd),stderr);
 108:     }
 109:     fputc('|',stderr);
 110:     for(i=0;i<5 && (ch=fgetc(curunit->ufd))!=EOF;i++) ffputc(ch,stderr);
 111:     fputc('\n',stderr);
 112: }
 113: 
 114: LOCAL
 115: prnt_int()
 116: {   char *ep;
 117:     fprintf (stderr,"part of last string: ");
 118:     ep = icptr - (recpos<12?recpos:12);
 119:     while (ep<icptr) ffputc(*ep++,stderr);
 120:     fputc('|',stderr);
 121:     while (ep<(icptr+5) && ep<icend) ffputc(*ep++,stderr);
 122:     fputc('\n',stderr);
 123: }
 124: 
 125: LOCAL
 126: prnt_fmt(n) int n;
 127: {   int i; char *ep;
 128:     fprintf(stderr, "format: ");
 129:     if(n==F_ERFMT)
 130:     {   i = fmtptr - fmtbuf;
 131:         ep = fmtptr - (i<25?i:25);
 132:         if(ep != fmtbuf) fprintf(stderr, "... ");
 133:         i = i + 5;
 134:     }
 135:     else
 136:     {   ep = fmtbuf;
 137:         i = 25;
 138:         fmtptr = fmtbuf - 1;
 139:     }
 140:     while(i && *ep)
 141:     {   ffputc((*ep==GLITCH)?'"':*ep,stderr);
 142:         if(ep==fmtptr) fputc('|',stderr);
 143:         ep++; i--;
 144:     }
 145:     if(*ep) fprintf(stderr, " ...");
 146:     fputc('\n',stderr);
 147: }
 148: 
 149: LOCAL
 150: ffputc(c, f)
 151: int c;
 152: FILE    *f;
 153: {
 154:     c &= 0177;
 155:     if (c < ' ' || c == 0177)
 156:     {
 157:         fputc('^', f);
 158:         c ^= 0100;
 159:     }
 160:     fputc(c, f);
 161: }
 162: 
 163: ftnint
 164: flush_(u) ftnint *u;
 165: {
 166:     FILE *F;
 167: 
 168:     if(not_legal(*u))
 169:         return(F_ERUNIT);
 170:     F = units[*u].ufd;
 171:     if(F)
 172:         return(fflush(F));
 173:     else
 174:         return(F_ERNOPEN);
 175: }

Defined functions

ffputc defined in line 149; used 5 times
flush_ defined in line 163; used 3 times
prnt_ext defined in line 97; used 1 times
  • in line 89
prnt_fmt defined in line 125; used 1 times
  • in line 86
prnt_int defined in line 114; used 1 times
  • in line 91

Defined variables

cblank defined in line 43; never used
cplus defined in line 43; never used
elist defined in line 43; used 1 times
  • in line 78
endflag defined in line 43; never used
errflag defined in line 43; never used
external defined in line 25; used 3 times
fmtptr defined in line 29; used 17 times
formatted defined in line 27; used 4 times
icend defined in line 29; used 1 times
icptr defined in line 29; used 3 times
ioiflg_ defined in line 46; never used
l_first defined in line 43; never used
lcount defined in line 45; used 22 times
leof defined in line 44; never used
lquit defined in line 43; never used
lunit defined in line 36; used 21 times
radix defined in line 42; used 7 times
reading defined in line 24; used 2 times
recnum defined in line 39; never used
scale defined in line 41; used 29 times
sequential defined in line 26; used 1 times
  • in line 81
signit defined in line 43; never used
tab defined in line 43; never used
Last modified: 1996-03-23
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1381
Valid CSS Valid XHTML 1.0 Strict