Annotation of cci/usr/src/usr.lib/libI77/err.c, revision 1.1

1.1     ! root        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.1     6/7/85
        !             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, -1 if list*/
        !            28: char *fmtbuf, *icptr, *icend, *fmtptr;
        !            29: int (*doed)(),(*doned)();
        !            30: int (*doend)(),(*donewrec)(),(*dorevert)(),(*dotab)();
        !            31: int (*lioproc)();
        !            32: int (*getn)(),(*putn)(),(*ungetn)();   /*for formatted io*/
        !            33: FILE *cf;              /*current file structure*/
        !            34: unit *curunit;         /*current unit structure*/
        !            35: int lunit;             /*current logical unit*/
        !            36: char *lfname;          /*current filename*/
        !            37: int recpos;            /*place in current record*/
        !            38: ftnint recnum;         /* current record number */
        !            39: int reclen;            /* current record length */
        !            40: int cursor,scale;
        !            41: int radix;
        !            42: ioflag signit,tab,cplus,cblank,elist,errflag,endflag,lquit,l_first;
        !            43: flag leof;
        !            44: int lcount,line_len;
        !            45: struct ioiflg ioiflg_; /* initialization flags */
        !            46: 
        !            47: /*error messages*/
        !            48: 
        !            49: extern char *sys_errlist[];
        !            50: extern int sys_nerr;
        !            51: 
        !            52: extern char *f_errlist[];
        !            53: extern int f_nerr;
        !            54: 
        !            55: 
        !            56: fatal(n,s) char *s;
        !            57: {
        !            58:        ftnint lu;
        !            59: 
        !            60:        for (lu=1; lu < MXUNIT; lu++)
        !            61:                flush_(&lu);
        !            62:        if(n<0)
        !            63:                fprintf(stderr,"%s: [%d] end of file\n",s,n);
        !            64:        else if(n>=0 && n<sys_nerr)
        !            65:                fprintf(stderr,"%s: [%d] %s\n",s,n,sys_errlist[n]);
        !            66:        else if(n>=F_ER && n<F_MAXERR)
        !            67:                fprintf(stderr,"%s: [%d] %s\n",s,n,f_errlist[n-F_ER]);
        !            68:        else
        !            69:                fprintf(stderr,"%s: [%d] unknown error number\n",s,n);
        !            70:        if(external)
        !            71:        {
        !            72:                if(!lfname) switch (lunit)
        !            73:                {       case STDERR: lfname = "stderr";
        !            74:                                        break;
        !            75:                        case STDIN:  lfname = "stdin";
        !            76:                                        break;
        !            77:                        case STDOUT: lfname = "stdout";
        !            78:                                        break;
        !            79:                        default:     lfname = "";
        !            80:                }
        !            81:                fprintf(stderr,"logical unit %d, named '%s'\n",lunit,lfname);
        !            82:        }
        !            83:        if (elist)
        !            84:        {       fprintf(stderr,"lately: %s %s %s %s I/O\n",
        !            85:                        reading?"reading":"writing",
        !            86:                        sequential?"sequential":"direct",
        !            87:                        formatted>0?"formatted":(formatted<0?"list":"unformatted"),
        !            88:                        external?"external":"internal");
        !            89:                if (formatted)
        !            90:                {       if(fmtbuf) prnt_fmt(n);
        !            91:                        if (external)
        !            92:                        {       if(reading && curunit->useek)
        !            93:                                        prnt_ext();  /* print external data */
        !            94:                        }
        !            95:                        else prnt_int();        /* print internal array */
        !            96:                }
        !            97:        }
        !            98:        f77_abort(n);
        !            99: }
        !           100: 
        !           101: LOCAL
        !           102: prnt_ext()
        !           103: {      int ch;
        !           104:        int i=1;
        !           105:        long loc;
        !           106:        fprintf (stderr, "part of last data: ");
        !           107:        loc = ftell(curunit->ufd);
        !           108:        if(loc)
        !           109:        {       if(loc==1L) rewind(curunit->ufd);
        !           110:                else for(;i<12 && last_char(curunit->ufd)!='\n';i++);
        !           111:                while(i--) ffputc(fgetc(curunit->ufd),stderr);
        !           112:        }
        !           113:        fputc('|',stderr);
        !           114:        for(i=0;i<5 && (ch=fgetc(curunit->ufd))!=EOF;i++) ffputc(ch,stderr);
        !           115:        fputc('\n',stderr);
        !           116: }
        !           117: 
        !           118: LOCAL
        !           119: prnt_int()
        !           120: {      char *ep;
        !           121:        fprintf (stderr,"part of last string: ");
        !           122:        ep = icptr - (recpos<12?recpos:12);
        !           123:        while (ep<icptr) ffputc(*ep++,stderr);
        !           124:        fputc('|',stderr);
        !           125:        while (ep<(icptr+5) && ep<icend) ffputc(*ep++,stderr);
        !           126:        fputc('\n',stderr);
        !           127: }
        !           128: 
        !           129: LOCAL
        !           130: prnt_fmt(n) int n;
        !           131: {      int i; char *ep;
        !           132:        fprintf(stderr, "format: ");
        !           133:        if(n==F_ERFMT)
        !           134:        {       i = fmtptr - fmtbuf;
        !           135:                ep = fmtptr - (i<25?i:25);
        !           136:                if(ep != fmtbuf) fprintf(stderr, "... ");
        !           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:        if(*ep) fprintf(stderr, " ...");
        !           150:        fputc('\n',stderr);
        !           151: }
        !           152: 
        !           153: LOCAL
        !           154: ffputc(c, f)
        !           155: int    c;
        !           156: FILE   *f;
        !           157: {
        !           158:        c &= 0177;
        !           159:        if (c < ' ' || c == 0177)
        !           160:        {
        !           161:                fputc('^', f);
        !           162:                c ^= 0100;
        !           163:        }
        !           164:        fputc(c, f);
        !           165: }
        !           166: 
        !           167: ftnint
        !           168: flush_(u) ftnint *u;
        !           169: {
        !           170:        FILE *F;
        !           171: 
        !           172:        if(not_legal(*u))
        !           173:                return(F_ERUNIT);
        !           174:        F = units[*u].ufd;
        !           175:        if(F)
        !           176:                return(fflush(F));
        !           177:        else
        !           178:                return(F_ERNOPEN);
        !           179: }

unix.superglobalmegacorp.com

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