Annotation of cci/usr/src/usr.lib/libsI77/err.c, revision 1.1.1.1

1.1       root        1: /*
                      2: char id_err[] = "@(#)err.c     1.4";
                      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: 
                     43: /*error messages*/
                     44: 
                     45: extern char *sys_errlist[];
                     46: extern int sys_nerr;
                     47: 
                     48: extern char *f_errlist[];
                     49: extern int f_nerr;
                     50: 
                     51: 
                     52: fatal(n,s) char *s;
                     53: {
                     54:        ftnint lu;
                     55: 
                     56:        for (lu=1; lu < MXUNIT; lu++)
                     57:                flush_(&lu);
                     58:        if(n<0)
                     59:                fprintf(stderr,"%s: [%d] end of file\n",s,n);
                     60:        else if(n>=0 && n<sys_nerr)
                     61:                fprintf(stderr,"%s: [%d] %s\n",s,n,sys_errlist[n]);
                     62:        else if(n>=F_ER && n<F_MAXERR)
                     63:                fprintf(stderr,"%s: [%d] %s\n",s,n,f_errlist[n-F_ER]);
                     64:        else
                     65:                fprintf(stderr,"%s: [%d] unknown error number\n",s,n);
                     66:        if(external)
                     67:        {
                     68:                if(!lfname) switch (lunit)
                     69:                {       case STDERR: lfname = "stderr";
                     70:                                        break;
                     71:                        case STDIN:  lfname = "stdin";
                     72:                                        break;
                     73:                        case STDOUT: lfname = "stdout";
                     74:                                        break;
                     75:                        default:     lfname = "";
                     76:                }
                     77:                fprintf(stderr,"logical unit %d, named '%s'\n",lunit,lfname);
                     78:        }
                     79:        if (elist)
                     80:        {       fprintf(stderr,"lately: %s %s %s %s IO\n",
                     81:                        reading?"reading":"writing",
                     82:                        sequential?"sequential":"direct",
                     83:                        formatted>0?"formatted":(formatted<0?"list":"unformatted"),
                     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:        f_exit();
                     95:        _cleanup();
                     96:        abort();
                     97: }
                     98: 
                     99: prnt_ext()
                    100: {      int ch;
                    101:        int i=1;
                    102:        long loc;
                    103:        fprintf (stderr, "part of last data: ");
                    104:        loc = ftell(curunit->ufd);
                    105:        if(loc)
                    106:        {       if(loc==1L) rewind(curunit->ufd);
                    107:                else for(;i<12 && last_char(curunit->ufd)!='\n';i++);
                    108:                while(i--) ffputc(fgetc(curunit->ufd),stderr);
                    109:        }
                    110:        fputc('|',stderr);
                    111:        for(i=0;i<5 && (ch=fgetc(curunit->ufd)!=EOF);i++) ffputc(ch,stderr);
                    112:        fputc('\n',stderr);
                    113: }
                    114: 
                    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: prnt_fmt(n) int n;
                    126: {      int i; char *ep;
                    127:        fprintf(stderr, "part of last format: ");
                    128:        if(n==F_ERFMT)
                    129:        {       i = fmtptr - fmtbuf;
                    130:                ep = fmtptr - (i<20?i:20);
                    131:                i = i + 5;
                    132:        }
                    133:        else
                    134:        {       ep = fmtbuf;
                    135:                i = 25;
                    136:                fmtptr = fmtbuf - 1;
                    137:        }
                    138:        while(i && *ep)
                    139:        {       ffputc((*ep==GLITCH)?'"':*ep,stderr);
                    140:                if(ep==fmtptr) fputc('|',stderr);
                    141:                ep++; i--;
                    142:        }
                    143:        fputc('\n',stderr);
                    144: }
                    145: 
                    146: ffputc(c, f)
                    147: int    c;
                    148: FILE   *f;
                    149: {
                    150:        c &= 0177;
                    151:        if (c < ' ' || c == 0177)
                    152:        {
                    153:                fputc('^', f);
                    154:                c ^= 0100;
                    155:        }
                    156:        fputc(c, f);
                    157: }
                    158: 
                    159: /*initialization routine*/
                    160: f_init()
                    161: {
                    162:        extern short init66_;
                    163:        ini_std(STDERR, stderr, WRITE, 0);
                    164:        ini_std(STDIN, stdin, READ, 0);
                    165:        ini_std(STDOUT, stdout, WRITE, init66_);
                    166: }
                    167: 

unix.superglobalmegacorp.com

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