1: /*
   2: char id_err[] = "@(#)err.c	1.10";
   3:  *
   4:  * file i/o error and initialization routines
   5:  */
   6: 
   7: #include <sys/types.h>
   8: #include <sys/stat.h>
   9: #include <signal.h>
  10: #include "fiodefs.h"
  11: 
  12: /*
  13:  * global definitions
  14:  */
  15: 
  16: char *tmplate = "tmp.FXXXXXX";  /* scratch file template */
  17: char *fortfile = "fort.%d"; /* default file template */
  18: 
  19: unit units[MXUNIT] = 0; /*unit table*/
  20: flag reading;       /*1 if reading,		0 if writing*/
  21: flag external;      /*1 if external io,	0 if internal */
  22: flag sequential;    /*1 if sequential io,	0 if direct*/
  23: flag formatted;     /*1 if formatted io,	0 if unformatted, -1 if list*/
  24: char *fmtbuf, *icptr, *icend, *fmtptr;
  25: int (*doed)(),(*doned)();
  26: int (*doend)(),(*donewrec)(),(*dorevert)(),(*dotab)();
  27: int (*lioproc)();
  28: int (*getn)(),(*putn)(),(*ungetn)();    /*for formatted io*/
  29: icilist *svic;      /* active internal io list */
  30: FILE *cf;       /*current file structure*/
  31: unit *curunit;      /*current unit structure*/
  32: int lunit;      /*current logical unit*/
  33: char *lfname;       /*current filename*/
  34: int recpos;     /*place in current record*/
  35: ftnint recnum;      /* current record number */
  36: int reclen;     /* current record length */
  37: int cursor,scale;
  38: int radix;
  39: ioflag signit,tab,cplus,cblank,elist,errflag,endflag,lquit,l_first;
  40: flag leof;
  41: int lcount,line_len;
  42: struct ioiflg ioiflg_;  /* initialization flags */
  43: 
  44: /*error messages*/
  45: 
  46: extern char *sys_errlist[];
  47: extern int sys_nerr;
  48: 
  49: extern char *f_errlist[];
  50: extern int f_nerr;
  51: 
  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>=0 && n<sys_nerr)
  62:         fprintf(stderr,"%s: [%d] %s\n",s,n,sys_errlist[n]);
  63:     else if(n>=F_ER && n<F_MAXERR)
  64:         fprintf(stderr,"%s: [%d] %s\n",s,n,f_errlist[n-F_ER]);
  65:     else
  66:         fprintf(stderr,"%s: [%d] unknown error number\n",s,n);
  67:     if(external)
  68:     {
  69:         if(!lfname) switch (lunit)
  70:         {   case STDERR: lfname = "stderr";
  71:                     break;
  72:             case STDIN:  lfname = "stdin";
  73:                     break;
  74:             case STDOUT: lfname = "stdout";
  75:                     break;
  76:             default:     lfname = "";
  77:         }
  78:         fprintf(stderr,"logical unit %d, named '%s'\n",lunit,lfname);
  79:     }
  80:     if (elist)
  81:     {   fprintf(stderr,"lately: %s %s %s %s IO\n",
  82:             reading?"reading":"writing",
  83:             sequential?"sequential":"direct",
  84:             formatted>0?"formatted":(formatted<0?"list":"unformatted"),
  85:             external?"external":"internal");
  86:         if (formatted)
  87:         {   if(fmtbuf) prnt_fmt(n);
  88:             if (external)
  89:             {   if(reading && curunit->useek)
  90:                     prnt_ext();  /* print external data */
  91:             }
  92:             else prnt_int();    /* print internal array */
  93:         }
  94:     }
  95:     f_exit();
  96:     _cleanup();
  97: #if vax
  98:     signal(SIGILL, SIG_DFL);
  99: #else   pdp11
 100:     signal(SIGIOT, SIG_DFL);
 101: #endif
 102:     abort();
 103: }
 104: 
 105: prnt_ext()
 106: {   int ch;
 107:     int i=1;
 108:     long loc;
 109:     fprintf (stderr, "part of last data: ");
 110:     loc = ftell(curunit->ufd);
 111:     if(loc)
 112:     {   if(loc==1L) rewind(curunit->ufd);
 113:         else for(;i<12 && last_char(curunit->ufd)!='\n';i++);
 114:         while(i--) ffputc(fgetc(curunit->ufd),stderr);
 115:     }
 116:     fputc('|',stderr);
 117:     for(i=0;i<5 && (ch=fgetc(curunit->ufd))!=EOF;i++) ffputc(ch,stderr);
 118:     fputc('\n',stderr);
 119: }
 120: 
 121: prnt_int()
 122: {   char *ep;
 123:     fprintf (stderr,"part of last string: ");
 124:     ep = icptr - (recpos<12?recpos:12);
 125:     while (ep<icptr) ffputc(*ep++,stderr);
 126:     fputc('|',stderr);
 127:     while (ep<(icptr+5) && ep<icend) ffputc(*ep++,stderr);
 128:     fputc('\n',stderr);
 129: }
 130: 
 131: prnt_fmt(n) int n;
 132: {   int i; char *ep;
 133:     fprintf(stderr, "part of last format: ");
 134:     if(n==F_ERFMT)
 135:     {   i = fmtptr - fmtbuf;
 136:         ep = fmtptr - (i<20?i:20);
 137:         i = i + 5;
 138:     }
 139:     else
 140:     {   ep = fmtbuf;
 141:         i = 25;
 142:         fmtptr = fmtbuf - 1;
 143:     }
 144:     while(i && *ep)
 145:     {   ffputc((*ep==GLITCH)?'"':*ep,stderr);
 146:         if(ep==fmtptr) fputc('|',stderr);
 147:         ep++; i--;
 148:     }
 149:     fputc('\n',stderr);
 150: }
 151: 
 152: ffputc(c, f)
 153: int c;
 154: FILE    *f;
 155: {
 156:     c &= 0177;
 157:     if (c < ' ' || c == 0177)
 158:     {
 159:         fputc('^', f);
 160:         c ^= 0100;
 161:     }
 162:     fputc(c, f);
 163: }
 164: 
 165: /*initialization routine*/
 166: f_init()
 167: {
 168:     ini_std(STDERR, stderr, WRITE);
 169:     ini_std(STDIN, stdin, READ);
 170:     ini_std(STDOUT, stdout, WRITE);
 171: }

Defined functions

f_init defined in line 166; used 1 times
ffputc defined in line 152; used 5 times
prnt_ext defined in line 105; used 1 times
  • in line 90
prnt_fmt defined in line 131; used 1 times
  • in line 87
prnt_int defined in line 121; used 1 times
  • in line 92

Defined variables

cblank defined in line 39; never used
cplus defined in line 39; never used
elist defined in line 39; used 1 times
  • in line 80
endflag defined in line 39; never used
errflag defined in line 39; never used
external defined in line 21; used 3 times
fmtptr defined in line 24; used 13 times
formatted defined in line 23; used 3 times
fortfile defined in line 17; used 2 times
icend defined in line 24; used 5 times
icptr defined in line 24; used 17 times
ioiflg_ defined in line 42; never used
l_first defined in line 39; never used
lcount defined in line 41; used 13 times
leof defined in line 40; never used
line_len defined in line 41; used 3 times
lquit defined in line 39; never used
lunit defined in line 32; used 25 times
reading defined in line 20; used 2 times
recnum defined in line 35; never used
sequential defined in line 22; used 1 times
  • in line 83
signit defined in line 39; never used
tab defined in line 39; never used
tmplate defined in line 16; used 2 times
Last modified: 1983-09-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1077
Valid CSS Valid XHTML 1.0 Strict