Annotation of 40BSD/lib/libI77uc/err.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * file i/o error and initialization routines
                      3:  */
                      4: 
                      5: #include <sys/types.h>
                      6: #include <sys/stat.h>
                      7: #include <signal.h>
                      8: #include "fiodefs.h"
                      9: 
                     10: /*
                     11:  * global definitions
                     12:  */
                     13: 
                     14: char *tmplate = "tmp.FXXXXXX"; /* scratch file template */
                     15: char *fortfile = "fort.%d";    /* default file template */
                     16: 
                     17: unit units[MXUNIT] = 0;        /*unit table*/
                     18: flag reading;          /*1 if reading,         0 if writing*/
                     19: flag external;         /*1 if external io,     0 if internal */
                     20: flag sequential;       /*1 if sequential io,   0 if direct*/
                     21: flag formatted;                /*1 if formatted io,    0 if unformatted, -1 if list*/
                     22: char *fmtbuf, *icptr, *icend, *fmtptr;
                     23: int (*doed)(),(*doned)();
                     24: int (*doend)(),(*donewrec)(),(*dorevert)(),(*dotab)();
                     25: int (*lioproc)();
                     26: int (*getn)(),(*putn)(),(*ungetn)();   /*for formatted io*/
                     27: icilist *svic;         /* active internal io list */
                     28: FILE *cf;              /*current file structure*/
                     29: unit *curunit;         /*current unit structure*/
                     30: int lunit;             /*current logical unit*/
                     31: char *lfname;          /*current filename*/
                     32: int recpos;            /*place in current record*/
                     33: ftnint recnum;         /* current record number */
                     34: int reclen;            /* current record length */
                     35: int cursor,scale;
                     36: int radix;
                     37: ioflag signit,tab,cplus,cblank,elist,errflag,endflag,lquit,l_first;
                     38: flag leof;
                     39: int lcount,line_len;
                     40: 
                     41: /*error messages*/
                     42: 
                     43: extern char *sys_errlist[];
                     44: 
                     45: char *F_err[] =
                     46: {
                     47: /* 100 */      "error in format",
                     48: /* 101 */      "illegal unit number",
                     49: /* 102 */      "formatted io not allowed",
                     50: /* 103 */      "unformatted io not allowed",
                     51: /* 104 */      "direct io not allowed",
                     52: /* 105 */      "sequential io not allowed",
                     53: /* 106 */      "can't backspace file",
                     54: /* 107 */      "off beginning of record",
                     55: /* 108 */      "can't stat file",
                     56: /* 109 */      "no * after repeat count",
                     57: /* 110 */      "off end of record",
                     58: /* 111 */      "truncation failed",
                     59: /* 112 */      "incomprehensible list input",
                     60: /* 113 */      "out of free space",
                     61: /* 114 */      "unit not connected",
                     62: /* 115 */      "read unexpected character",
                     63: /* 116 */      "blank logical input field",
                     64: /* 117 */      "'new' file exists",
                     65: /* 118 */      "can't find 'old' file",
                     66: /* 119 */      "unknown system error",
                     67: /* 120 */      "requires seek ability",
                     68: /* 121 */      "illegal argument",
                     69: /* 122 */      "negative repeat count",
                     70: };
                     71: 
                     72: #define MAXERR (sizeof(F_err)/sizeof(char *)+100)
                     73: 
                     74: 
                     75: fatal(n,s) char *s;
                     76: {
                     77:        ftnint lu;
                     78: 
                     79:        for (lu=1; lu < MXUNIT; lu++)
                     80:                flush_(&lu);
                     81:        if(n<100 && n>=0)
                     82:                fprintf(stderr,"%s: [%d] %s\n",s,n,sys_errlist[n]);
                     83:        else if(n>=(int)MAXERR)
                     84:                fprintf(stderr,"%s: [%d] illegal error number\n",s,n);
                     85:        else if(n<0)
                     86:                fprintf(stderr,"%s: [%d] end of file\n",s,n);
                     87:        else
                     88:                fprintf(stderr,"%s: [%d] %s\n",s,n,F_err[n-100]);
                     89:        if(external)
                     90:        {
                     91:                if(!lfname) switch (lunit)
                     92:                {       case STDERR: lfname = "stderr";
                     93:                                        break;
                     94:                        case STDIN:  lfname = "stdin";
                     95:                                        break;
                     96:                        case STDOUT: lfname = "stdout";
                     97:                                        break;
                     98:                        default:     lfname = "";
                     99:                }
                    100:                fprintf(stderr,"logical unit %d, named '%s'\n",lunit,lfname);
                    101:        }
                    102:        if (elist)
                    103:        {       fprintf(stderr,"lately: %s %s %s %s IO\n",
                    104:                        reading?"reading":"writing",
                    105:                        sequential?"sequential":"direct",
                    106:                        formatted>0?"formatted":(formatted<0?"list":"unformatted"),
                    107:                        external?"external":"internal");
                    108:                if (formatted)
                    109:                {       if(fmtbuf) prnt_fmt(n);
                    110:                        if (external)
                    111:                        {       if(reading && curunit->useek)
                    112:                                        prnt_ext();  /* print external data */
                    113:                        }
                    114:                        else prnt_int();        /* print internal array */
                    115:                }
                    116:        }
                    117:        f_exit();
                    118:        _cleanup();
                    119:        abort();
                    120: }
                    121: 
                    122: prnt_ext()
                    123: {      int ch;
                    124:        int i=1;
                    125:        long loc;
                    126:        fprintf (stderr, "part of last data: ");
                    127:        loc = ftell(curunit->ufd);
                    128:        if(loc)
                    129:        {       if(loc==1L) rewind(curunit->ufd);
                    130:                else for(;i<12 && last_char(curunit->ufd)!='\n';i++);
                    131:                while(i--) fputc(fgetc(curunit->ufd),stderr);
                    132:        }
                    133:        fputc('|',stderr);
                    134:        for(i=0;i<5 && (ch=fgetc(curunit->ufd)!=EOF);i++) fputc(ch,stderr);
                    135:        fputc('\n',stderr);
                    136: }
                    137: 
                    138: prnt_int()
                    139: {      char *ep;
                    140:        fprintf (stderr,"part of last string: ");
                    141:        ep = icptr - (recpos<12?recpos:12);
                    142:        while (ep<icptr) fputc(*ep++,stderr);
                    143:        fputc('|',stderr);
                    144:        while (ep<(icptr+5) && ep<icend) fputc(*ep++,stderr);
                    145:        fputc('\n',stderr);
                    146: }
                    147: 
                    148: prnt_fmt(n) int n;
                    149: {      int i; char *ep;
                    150:        fprintf(stderr, "part of last format: ");
                    151:        if(n==100)
                    152:        {       i = fmtptr - fmtbuf;
                    153:                ep = fmtptr - (i<20?i:20);
                    154:                i = i + 5;
                    155:        }
                    156:        else
                    157:        {       ep = fmtbuf;
                    158:                i = 25;
                    159:                fmtptr = fmtbuf - 1;
                    160:        }
                    161:        while(i && *ep)
                    162:        {       fputc((*ep==GLITCH)?'"':*ep,stderr);
                    163:                if(ep==fmtptr) fputc('|',stderr);
                    164:                ep++; i--;
                    165:        }
                    166:        fputc('\n',stderr);
                    167: }
                    168: 
                    169: /*initialization routine*/
                    170: f_init()
                    171: {      ini_std(STDERR, stderr, WRITE);
                    172:        ini_std(STDIN, stdin, READ);
                    173:        ini_std(STDOUT, stdout, WRITE);
                    174: }
                    175: 

unix.superglobalmegacorp.com

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