|
|
1.1 ! root 1: # define BUF 256 ! 2: /* UNIX HEADER */ ! 3: #include <stdio.h> ! 4: #include <ar.h> ! 5: ! 6: /* COMMON SGS HEADERS */ ! 7: #include "filehdr.h" ! 8: #include "ldfcn.h" ! 9: ! 10: ! 11: ! 12: /* SGS SPECIFIC HEADERS */ ! 13: #include "paths.h" ! 14: #include "sgs.h" ! 15: ! 16: /* EXTERNAL VARIABLES DEFINED */ ! 17: LDFILE *ldptr; ! 18: ARCHDR arhead; ! 19: long xsize = 0; ! 20: int aflag; ! 21: long xmore; ! 22: int mag; ! 23: char tmpnam1[sizeof (TMPDIR) + 16], ! 24: tmpnam2[sizeof (TMPDIR) + 16], ! 25: tmpnam3[sizeof (TMPDIR) + 16], ! 26: tmpnam4[sizeof (TMPDIR) + 16]; ! 27: #if FLEXNAMES ! 28: char tmpnam5[sizeof (TMPDIR) + 16]; /* string table temp file */ ! 29: #endif ! 30: ! 31: /* The SGS/UNIX Strip Command operates on one or more object files ! 32: * ! 33: * main(argc, argv) ! 34: * ! 35: * parses the command line (setflags( )) ! 36: * prepares to field interrupt (catchsig( )) ! 37: * opens, processes and closes each command line object file argument ! 38: * cleans up after itself ! 39: * ! 40: * defines: ! 41: * - ldptr = ldopen(*argv, NULL) for each command line file argument ! 42: * - tmpnam1 = TMPDIR/SGSstrp1????? to be used for building the ! 43: * stripped file ! 44: * ! 45: * - tmpnam2 = TMPDIR/SGSstrp2????? to be used for building a ! 46: * temporary partially stripped symbol table ! 47: * calls: ! 48: * - setflags(--argc, ++argv) to set flags ! 49: * - catchsig( ) to set up interrupt handling ! 50: * - process(*argv) to direct the stripping of the object file *argv ! 51: * ! 52: * prints: ! 53: * - a usage message if there are no command line object file arguments ! 54: * - an error message if it can't open a file or if it isn't MAGIC ! 55: * ! 56: * exits successfully always ! 57: */ ! 58: ! 59: ! 60: main(argc, argv) ! 61: ! 62: int argc; ! 63: char **argv; ! 64: ! 65: { ! 66: /* UNIX FUNCTIONS CALLED */ ! 67: extern fprintf( ), ! 68: sprintf( ), ! 69: sputl( ), ! 70: unlink( ); ! 71: extern int getpid( ); ! 72: #ifdef PORT5AR ! 73: extern long time( ); ! 74: #endif ! 75: ! 76: /* OBJECT FILE ACCESS ROUTINES CALLED */ ! 77: extern LDFILE *ldopen( ); ! 78: extern int ldaclose( ); ! 79: ! 80: /* STRIP FUNCTIONS CALLED */ ! 81: extern int setflags( ), ! 82: process( ); ! 83: extern catchsig( ), ! 84: copyarh( ), ! 85: resetsig( ); ! 86: extern FILE *stripout; ! 87: FILE *tmp; ! 88: extern long xmore; ! 89: short buf[BUF]; ! 90: int nitems, ! 91: retval = 0; /* exit return value */ ! 92: #ifdef PORT5AR ! 93: struct ar_hdr arhbuf; ! 94: #endif ! 95: ! 96: ! 97: ! 98: if ((argc = setflags(--argc, ++argv)) == 0) { ! 99: #if UNIX ! 100: fprintf(stderr,"usage: %sstrip [-l] [-x] [-r] file ...\n", SGS); ! 101: #else ! 102: fprintf( stderr, "usage: %sstrip [-l] [-x] [-r] [-s] [-f] file ...\n", SGS); ! 103: #endif ! 104: exit(0); ! 105: } ! 106: ! 107: sprintf(tmpnam1, "%s/%sstrp1%d", TMPDIR, SGS, getpid( )); ! 108: sprintf(tmpnam2, "%s/%sstrp2%d", TMPDIR, SGS, getpid( )); ! 109: sprintf(tmpnam3, "%s/%sstrp3%d", TMPDIR, SGS, getpid( )); ! 110: sprintf(tmpnam4, "%s/%sstrp4%d", TMPDIR, SGS, getpid( )); ! 111: #if FLEXNAMES ! 112: sprintf( tmpnam5, "%s/%sstrp5%d", TMPDIR, SGS, getpid( )); ! 113: #endif ! 114: catchsig( ); ! 115: ! 116: for ( ; argc > 0; --argc, ++argv) { ! 117: if ((ldptr = ldopen(*argv, NULL)) == NULL) { ! 118: fprintf( stderr, "%sstrip: %s: cannot open\n", SGS, *argv ); ! 119: continue; ! 120: } ! 121: ! 122: mag = TYPE(ldptr); ! 123: if (!ISMAGIC (TYPE(ldptr)) && (TYPE(ldptr) != ARTYPE)) { ! 124: fprintf(stderr, "%sstrip: %s: bad magic\n", SGS, *argv); ! 125: ldaclose(ldptr); ! 126: ! 127: } else if (TYPE(ldptr) == ARTYPE) { ! 128: aflag = 1; ! 129: do { ! 130: if (ldahread(ldptr, &arhead) != SUCCESS) { ! 131: fprintf(stderr,"error in archive hdr read %s %s\n", *argv,arhead.ar_name); ! 132: ldaclose(ldptr); ! 133: exit(1); ! 134: } ! 135: ! 136: if (process(*argv) != SUCCESS) { ! 137: /* abandon processing archive, bail out */ ! 138: ldaclose(ldptr); ! 139: retval = 1; /* return an error code */ ! 140: goto getout; ! 141: } ! 142: } while (xmore != SUCCESS); ! 143: ! 144: if ((stripout = fopen(tmpnam4, "r")) == NULL) { ! 145: fprintf(stderr,"cannot open temporary file %s for reading \n", tmpnam4); ! 146: exit(1); ! 147: } ! 148: if ((tmp = fopen(*argv, "w")) == NULL) { ! 149: fprintf(stderr,"cannot open temporary file %s for writing\n", *argv); ! 150: exit(1); ! 151: } ! 152: ! 153: #if defined(PORTAR) || defined(PORT5AR) ! 154: /* rewrite the archive header without a symbol dir */ ! 155: fprintf(stderr,"%sstrip: Warning - symbol directory deleted from archive %s\n", ! 156: SGS, *argv); ! 157: fprintf(stderr," execute `ar ts %s` to restore symbol directory.\n", ! 158: *argv); ! 159: #endif ! 160: ! 161: #ifdef PORT5AR ! 162: strncpy(arhbuf.ar_magic,ARMAG,SARMAG); ! 163: strncpy(arhbuf.ar_name,*argv,sizeof(arhbuf.ar_name)); ! 164: sputl(time(NULL),arhbuf.ar_date); ! 165: sputl(0L,arhbuf.ar_syms); ! 166: if (fwrite(&arhbuf,sizeof(struct ar_hdr),1,tmp) != 1) { ! 167: #else ! 168: #ifdef PORTAR ! 169: if (fwrite( ARMAG, SARMAG, 1, tmp ) != 1) { ! 170: #else ! 171: if (fwrite( ARMAG, sizeof(ARMAG), 1, tmp ) != 1) { ! 172: #endif ! 173: #endif ! 174: error( *argv, "can't recreate file", 5 ); ! 175: resetsig( ); ! 176: exit(1); ! 177: } ! 178: while((nitems = fread(buf,sizeof(short), BUF, stripout)) != 0 ) { ! 179: if (fwrite(buf,sizeof(short), nitems,tmp) != nitems) { ! 180: error(*argv,"can't recreate file ",5); ! 181: resetsig( ); ! 182: exit(1); ! 183: } ! 184: } ! 185: ! 186: } else { /* not an archive */ ! 187: (void) process(*argv); ! 188: } ! 189: } /* for */ ! 190: ! 191: getout: ! 192: unlink(tmpnam1); ! 193: unlink(tmpnam2); ! 194: unlink(tmpnam3); ! 195: unlink(tmpnam4); ! 196: #if FLEXNAMES ! 197: unlink(tmpnam5); ! 198: #endif ! 199: exit(retval); ! 200: } ! 201: /* ! 202: * @(#) main.c: 1.5 11/17/83 ! 203: */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.