Annotation of 42BSD/usr.lib/libI77/err.c, revision 1.1.1.1

1.1       root        1: /*
                      2: char id_err[] = "@(#)err.c     1.11";
                      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:        sigsetmask(0);
                    100: #else  pdp11
                    101:        signal(SIGIOT, SIG_DFL);
                    102: #endif
                    103:        abort();
                    104: }
                    105: 
                    106: prnt_ext()
                    107: {      int ch;
                    108:        int i=1;
                    109:        long loc;
                    110:        fprintf (stderr, "part of last data: ");
                    111:        loc = ftell(curunit->ufd);
                    112:        if(loc)
                    113:        {       if(loc==1L) rewind(curunit->ufd);
                    114:                else for(;i<12 && last_char(curunit->ufd)!='\n';i++);
                    115:                while(i--) ffputc(fgetc(curunit->ufd),stderr);
                    116:        }
                    117:        fputc('|',stderr);
                    118:        for(i=0;i<5 && (ch=fgetc(curunit->ufd))!=EOF;i++) ffputc(ch,stderr);
                    119:        fputc('\n',stderr);
                    120: }
                    121: 
                    122: prnt_int()
                    123: {      char *ep;
                    124:        fprintf (stderr,"part of last string: ");
                    125:        ep = icptr - (recpos<12?recpos:12);
                    126:        while (ep<icptr) ffputc(*ep++,stderr);
                    127:        fputc('|',stderr);
                    128:        while (ep<(icptr+5) && ep<icend) ffputc(*ep++,stderr);
                    129:        fputc('\n',stderr);
                    130: }
                    131: 
                    132: prnt_fmt(n) int n;
                    133: {      int i; char *ep;
                    134:        fprintf(stderr, "part of last format: ");
                    135:        if(n==F_ERFMT)
                    136:        {       i = fmtptr - fmtbuf;
                    137:                ep = fmtptr - (i<20?i:20);
                    138:                i = i + 5;
                    139:        }
                    140:        else
                    141:        {       ep = fmtbuf;
                    142:                i = 25;
                    143:                fmtptr = fmtbuf - 1;
                    144:        }
                    145:        while(i && *ep)
                    146:        {       ffputc((*ep==GLITCH)?'"':*ep,stderr);
                    147:                if(ep==fmtptr) fputc('|',stderr);
                    148:                ep++; i--;
                    149:        }
                    150:        fputc('\n',stderr);
                    151: }
                    152: 
                    153: ffputc(c, f)
                    154: int    c;
                    155: FILE   *f;
                    156: {
                    157:        c &= 0177;
                    158:        if (c < ' ' || c == 0177)
                    159:        {
                    160:                fputc('^', f);
                    161:                c ^= 0100;
                    162:        }
                    163:        fputc(c, f);
                    164: }
                    165: 
                    166: /*initialization routine*/
                    167: f_init()
                    168: {
                    169:        ini_std(STDERR, stderr, WRITE);
                    170:        ini_std(STDIN, stdin, READ);
                    171:        ini_std(STDOUT, stdout, WRITE);
                    172: }
                    173: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.