Annotation of researchv9/jerq/sgs/strip/fcns.c, revision 1.1.1.1

1.1       root        1: /* UNIX HEADERS */
                      2: #include       <stdio.h>
                      3: #include       <signal.h>
                      4: 
                      5: /* COMMON SGS HEADERS */
                      6: #include       "filehdr.h"
                      7: #include       "ldfcn.h"
                      8: 
                      9: /* SGS SPECIFIC HEADER */
                     10: #include       "sgs.h"
                     11: 
                     12: /* STRIP HEADER */
                     13: #include       "defs.h"
                     14: 
                     15: 
                     16:     /*  error(file, message, level)
                     17:      *
                     18:      *  prints an error message
                     19:      *  and closes what ever files are open associated with the error level and
                     20:      *  the current state of the lister
                     21:      *
                     22:      *  simply returns
                     23:      */
                     24: 
                     25: 
                     26: error(file, message, level)
                     27: 
                     28: char   *file;
                     29: char   *message;
                     30: int    level;
                     31: 
                     32: {
                     33:        /* UNIX FUNCTIONS CALLED */
                     34:        extern          fprintf( ),
                     35:                        fclose( ),
                     36:                        unlink( );
                     37: 
                     38:        /* COMMON OBJECT FILE ACCESS ROUTINE CALLED */
                     39:        extern int      ldaclose( );
                     40: 
                     41:        /* EXTERNAL VARIABLES USED */
                     42:        extern LDFILE   *ldptr,
                     43:                        *fwdptr;
                     44:        extern FILE     *strp1,
                     45:                        *strp2,
                     46:                        *stripout;
                     47: #if AR16WR
                     48:        extern FILE     *tempfil,
                     49:                        *readtmp;
                     50: #endif
                     51:        extern char     tmpnam1[ ],
                     52:                        tmpnam2[ ];
                     53: 
                     54: 
                     55:        fprintf(stderr, "%sstrip:  %s:  %s\n", SGS, file, message);
                     56: 
                     57:        switch(level) {
                     58:            case 0:
                     59:                break;
                     60: 
                     61:            case 1:
                     62:                ldaclose(ldptr);
                     63:                break;
                     64: 
                     65:            case 2:
                     66:                ldaclose(ldptr);
                     67:                if (strp1 != NULL)
                     68:                        fclose(strp1);
                     69:                if (strp2 != NULL)
                     70:                        fclose(strp2);
                     71: #if AR16WR
                     72:                if (tempfil != NULL)
                     73:                        fclose(tempfil);
                     74:                if (readtmp != NULL)
                     75:                        fclose(readtmp);
                     76: #endif
                     77:                break;
                     78: 
                     79:            case 3:
                     80:                ldaclose(ldptr);
                     81:                ldaclose(fwdptr);
                     82:                if (strp1 != NULL)
                     83:                        fclose(strp1);
                     84:                if (strp2 != NULL)
                     85:                        fclose(strp2);
                     86: #if AR16WR
                     87:                if (tempfil != NULL)
                     88:                        fclose(tempfil);
                     89:                if (readtmp != NULL)
                     90:                        fclose(readtmp);
                     91: #endif
                     92:                break;
                     93: 
                     94:            case 4:
                     95:                if (stripout != NULL)
                     96:                        fclose(stripout);
                     97:                unlink(tmpnam1);
                     98:                break;
                     99: 
                    100:            case 5:
                    101:                if (strp1 != NULL)
                    102:                        fclose(strp1);
                    103:                if (strp2 != NULL)
                    104:                        fclose(strp2);
                    105: #if AR16WR
                    106:                if (tempfil != NULL)
                    107:                        fclose(tempfil);
                    108:                if (readtmp != NULL)
                    109:                        fclose(readtmp);
                    110: #endif
                    111:                if (stripout != NULL)
                    112:                        fclose(stripout);
                    113:                unlink(file);
                    114:                break;
                    115: 
                    116:            default:
                    117:                break;
                    118:        }
                    119:        return;
                    120: }
                    121: 
                    122: 
                    123: 
                    124: 
                    125:     /*  catchsig( )
                    126:      *
                    127:      *  prepares strip to field interrupts (via function onintr( ))
                    128:      *  so that if interrupted strip can remove the temporary files it has
                    129:      *  created
                    130:      *
                    131:      *  catchsig simply returns
                    132:      */
                    133: 
                    134: 
                    135: catchsig( )
                    136: 
                    137: {
                    138:        /* UNIX FUNCTION CALLED */
                    139:        extern int      (*signal( ))( );
                    140: 
                    141:        /* EXTERNAL VARIABLE USED */
                    142:        extern          onintr( );
                    143: 
                    144:        if ((signal(SIGINT, SIG_IGN)) == SIG_DFL)
                    145:                signal(SIGINT, onintr);
                    146: 
                    147:        if ((signal(SIGHUP, SIG_IGN)) == SIG_DFL)
                    148:                signal(SIGHUP, onintr);
                    149: 
                    150:        if ((signal(SIGQUIT, SIG_IGN)) == SIG_DFL)
                    151:                signal(SIGQUIT, onintr);
                    152: 
                    153:        if ((signal(SIGTERM, SIG_IGN)) == SIG_DFL)
                    154:                signal(SIGTERM, onintr);
                    155: 
                    156:        return;
                    157: 
                    158: }
                    159: 
                    160: 
                    161: 
                    162: 
                    163: /* STATIC VARIABLES USED */
                    164: static int     (*oldint)( );
                    165: static int     (*oldhup)( );
                    166: static int     (*oldquit)( );
                    167: static int     (*oldterm)( );
                    168: 
                    169: 
                    170:     /*  ignorsig( )
                    171:      *
                    172:      *  turns off interrupts but saves their former state in static variables
                    173:      *  so that previous state of interrupts can be restored later
                    174:      *
                    175:      *  ignorsig simply returns
                    176:      */
                    177: 
                    178: 
                    179: ignorsig( )
                    180: 
                    181: {
                    182:        /* UNIX FUNCTION CALLED */
                    183:        extern int      (*signal( ))( );
                    184: 
                    185:        oldint = signal(SIGINT, SIG_IGN);
                    186:        oldhup = signal(SIGHUP, SIG_IGN);
                    187:        oldquit = signal(SIGQUIT, SIG_IGN);
                    188:        oldterm = signal(SIGTERM, SIG_IGN);
                    189: 
                    190:        return;
                    191: }
                    192: 
                    193: 
                    194: 
                    195: 
                    196:     /*  resetsig( )
                    197:      *
                    198:      *  restores state of interrupts to what they were before ignorsig was
                    199:      *  called
                    200:      *  uses static variables old-whatever to do the restoration
                    201:      *
                    202:      *  simply returns
                    203:      */
                    204: 
                    205: 
                    206: resetsig( )
                    207: 
                    208: {
                    209:        /* UNIX FUNCTION CALLED */
                    210:        extern int      (*signal( ))( );
                    211: 
                    212:        signal(SIGINT, oldint);
                    213:        signal(SIGHUP, oldhup);
                    214:        signal(SIGQUIT, oldquit);
                    215:        signal(SIGTERM, oldterm);
                    216: 
                    217:        return;
                    218: }
                    219: 
                    220: 
                    221: 
                    222: 
                    223:     /*  onintr( )
                    224:      *
                    225:      *  is strip's interrupt handling routine
                    226:      *  onintr turns off interrupts while it closes all files that may be open
                    227:      *  and unlinks strip's temporary file
                    228:      *
                    229:      *  onintr always exits fatally
                    230:      */
                    231: 
                    232: 
                    233: onintr( )
                    234: 
                    235: {
                    236:        /* UNIX FUNCTIONS CALLED */
                    237:        extern int      (*signal( ))( );
                    238:        extern          fclose( ),
                    239:                        unlink( ),
                    240:                        exit( );
                    241: 
                    242:        /* COMMON OBJECT FILE ACCESS ROUTINE CALLED */
                    243:        extern int      ldaclose( );
                    244: 
                    245:        /* EXTERNAL VARIABLES USED */
                    246:        extern LDFILE   *ldptr,
                    247:                        *fwdptr;
                    248:        extern FILE     *strp1,
                    249:                        *strp2,
                    250:                        *stripout;
                    251: #if AR16WR
                    252:        extern FILE     *tempfil,
                    253:                        *readtmp;
                    254: #endif
                    255:        extern char     tmpnam1[ ],
                    256:                        tmpnam2[ ],
                    257:                        tmpnam3[ ];
                    258: 
                    259: 
                    260:        /* ignore signals */
                    261:        signal(SIGINT, SIG_IGN);
                    262:        signal(SIGHUP, SIG_IGN);
                    263:        signal(SIGQUIT, SIG_IGN);
                    264:        signal(SIGTERM, SIG_IGN);
                    265: 
                    266:        ldaclose(ldptr);
                    267:        ldaclose(fwdptr);
                    268:        if (strp1 != NULL)
                    269:                fclose(strp1);
                    270:        if (strp2 != NULL)
                    271:                fclose(strp2);
                    272: #if AR16WR
                    273:        if (tempfil != NULL)
                    274:                fclose(tempfil);
                    275:        if (readtmp != NULL)
                    276:                fclose(readtmp);
                    277: #endif
                    278:        unlink(tmpnam1);
                    279:        unlink(tmpnam2);
                    280:        unlink(tmpnam3);
                    281:        if (stripout != NULL)
                    282:                fclose(stripout);
                    283: 
                    284:        exit(FATAL);
                    285: 
                    286: }
                    287: 
                    288: /*
                    289:  *     static char ID[] = "@(#) fcns.c: 1.5 2/13/83";
                    290:  */

unix.superglobalmegacorp.com

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