thad@cup.portal.com (Thad P Floryan) (12/30/90)
---- Cut Here and feed the following to sh ---- #!/bin/sh # This is a shell archive (produced by shar 3.49) # To extract the files from this archive, save it to a file, remove # everything above the "!/bin/sh" line above, and type "sh file_name". # # made 12/30/1990 13:59 UTC by thad@thadlabs # Source directory /usr/local/src/coffdate # # existing files will NOT be overwritten unless -c is specified # # This shar contains: # length mode name # ------ ---------- ------------------------------------------ # 962 -rw-r--r-- README # 388 -rw-r--r-- Makefile # 1131 -rw-r--r-- coffdate.1L # 5258 -rw-r--r-- coffdate.c # if touch 2>&1 | fgrep 'amc' > /dev/null then TOUCH=touch else TOUCH=true fi # ============= README ============== if test -f 'README' -a X"$1" != X"-c"; then echo 'x - skipping README (File already exists)' else echo 'x - extracting README (Text)' sed 's/^X//' << 'SHAR_EOF' > 'README' && Xcoffdate is something I whipped up quickly to solve several problems: X X 1) dates on executable files being altered by "install" scripts X 2) verifying which of several *.o files was, in fact, most recent X XFrom the program's docs: X Xdisplays the date embedded in COFF files and optionally alters the Xfiles' access and modify dates to be that of their COFF f_timdat. X Xusage: coffdate [ -a ] [ -m ] [ - { c | s } ] filelist X Xwhere: -a resets file's access date&time to the COFF f_timdat X -m resets file's modify date&time to the COFF f_timdat X -c list only COFF files (i.e. suppress "not a COFF file") X -s silent operation X Xoptions may be combined noting that -c and -s are mutually exclusive. X XThis version is for mc68k COFF files; to function with other systems' XCOFF files the equates in chkCOFF() need to be changed to reflect those Xin /usr/include/sgs.h or /usr/include/filehdr.h on those other systems. X XV1.0 30-Dec-1990, Thad Floryan (thad@cup.portal.com) SHAR_EOF $TOUCH -am 1230050590 'README' && chmod 0644 README || echo 'restore of README failed' Wc_c="`wc -c < 'README'`" test 962 -eq "$Wc_c" || echo 'README: original size 962, current size' "$Wc_c" fi # ============= Makefile ============== if test -f 'Makefile' -a X"$1" != X"-c"; then echo 'x - skipping Makefile (File already exists)' else echo 'x - extracting Makefile (Text)' sed 's/^X//' << 'SHAR_EOF' > 'Makefile' && X# makefile for coffdate X# XCC = gcc XCFLAGS = -O XLDFLAGS = -s XLIBS = /lib/crt0s.o /lib/shlib.ifile # 3b1/UNIXPC/PC7300 X#LIBS = -lc_s # SVR3.* XNAME = coffdate XOBJS = coffdate.o XDEST = /usr/local/bin XFMODE = 555 X X$(NAME) : $(OBJS) X $(LD) $(LDFLAGS) -o $(NAME) $(OBJS) $(LIBS) X Xinstall : $(NAME) X mv $(NAME) $(DEST)/. X chmod $(FMODE) $(DEST)/$(NAME) X Xclean : X rm -f $(OBJS) core *~ SHAR_EOF $TOUCH -am 1230045090 'Makefile' && chmod 0644 Makefile || echo 'restore of Makefile failed' Wc_c="`wc -c < 'Makefile'`" test 388 -eq "$Wc_c" || echo 'Makefile: original size 388, current size' "$Wc_c" fi # ============= coffdate.1L ============== if test -f 'coffdate.1L' -a X"$1" != X"-c"; then echo 'x - skipping coffdate.1L (File already exists)' else echo 'x - extracting coffdate.1L (Text)' sed 's/^X//' << 'SHAR_EOF' > 'coffdate.1L' && X.TH COFFDATE 1L "Local Utilities" X.UC 4 X.SH NAME Xcoffdate \- reports COFF dates and times of specified files X.SH SYNOPSIS X.I coffdate X[ X.I \-a X] [ X.I \-m X] [ \- { X.I c X| X.I s X} ] files ... X.SH DESCRIPTION X.PP X.I coffdate Xdisplays the date and time embedded in COFF files and optionally alters the Xfiles' access and modify dates to be that of their COFF f_timdat. X.TP 6 X.I \-a Xresets file's access date&time to the COFF f_timdat X.TP 6 X.I \-m Xresets file's modify date&time to the COFF f_timdat X.TP 6 X.I \-c Xlist only COFF files (i.e. suppress "not a COFF file") X.TP 6 X.I \-s Xsilent operation X.PP Xoptions may be combined noting that X.I \-c Xand X.I \-s Xare mutually exclusive. X.SH AUTHOR XThad Floryan X.RS 0 XUUCP email address: thad@cup.portal.com (OR) ..!sun!portal!cup.portal.com!thad X.RE X.SH VERSION XThe present version of X.I coffdate Xis 1.0, dated 30-Dec-1990. X.SH CAVEATS X.PP XThis version is for mc68k COFF files; to function with other systems' XCOFF files the equates in chkCOFF() need to be changed to reflect those Xin /usr/include/sgs.h or /usr/include/filehdr.h on those other systems. X.SH BUGS X.PP XNone known. :-) SHAR_EOF $TOUCH -am 1230055490 'coffdate.1L' && chmod 0644 coffdate.1L || echo 'restore of coffdate.1L failed' Wc_c="`wc -c < 'coffdate.1L'`" test 1131 -eq "$Wc_c" || echo 'coffdate.1L: original size 1131, current size' "$Wc_c" fi # ============= coffdate.c ============== if test -f 'coffdate.c' -a X"$1" != X"-c"; then echo 'x - skipping coffdate.c (File already exists)' else echo 'x - extracting coffdate.c (Text)' sed 's/^X//' << 'SHAR_EOF' > 'coffdate.c' && X/* coffdate X * X * displays the date embedded in COFF files and optionally alters the X * files' access and modify dates to be that of their COFF f_timdat. X * X * usage: coffdate [ -a ] [ -m ] [ - { c | s } ] filelist X * X * where: -a resets file's access date&time to the COFF f_timdat X * -m resets file's modify date&time to the COFF f_timdat X * -c list only COFF files (i.e. suppress "not a COFF file") X * -s silent operation X * X * options may be combined noting that -c and -s are mutually exclusive. X * X * This version is for mc68k COFF files; to function with other systems' X * COFF files the equates in chkCOFF() need to be changed to reflect those X * in /usr/include/sgs.h or /usr/include/filehdr.h on those other systems. X * X * V1.0 30-Dec-1990, Thad Floryan (thad@cup.portal.com) X */ X X#include <fcntl.h> /* for low-level I/O definitions */ X#include <filehdr.h> /* for COFF header first part */ X#include <sgs.h> /* for COFF magic */ X#include <stdio.h> /* for standard I/O defs, BUFSIZ, etc. */ X#include <time.h> /* for ctime(3C) definitions */ X#include <sys/stat.h> X#include <sys/types.h> X Xstruct utimbuf { /* structure for utime(2); not in any *.h file */ X time_t actime; /* access time */ X time_t modtime;/* modify time */ X}; X X#define CROFFSET 24 /* offset of '\n' in ctime(3C) string */ X#define CTIMELEN 26 /* length of ctime(3C) string */ X Xstatic char *version = "@(#) coffdate V1.0, Thad Floryan, 30-Dec-1990"; X Xstatic char *usage_text[] = { X "usage: coffdate [ -a ] [ -m ] [ - { c | s } ] filelist\n", X "where: -a resets file's access date&time to the COFF f_timdat", X " -m resets file's modify date&time to the COFF f_timdat", X " -c list only COFF files (i.e. suppress \"not a COFF file\")", X " -s silent operation", X 0 X}; X Xstatic int OPTaccess = 0; /* option switch for access dates */ Xstatic int OPTmodify = 0; /* option switch for modify dates */ Xstatic int OPTcoff = 0; /* option switch for COFF-only */ Xstatic int OPTsilent = 0; /* option switch for silent operation */ X Xmain( argc, argv ) X int argc; X char *argv[]; X{ X extern char *malloc(); X extern int close(), free(), getopt(), open(), read(), stat(), utime(); X X extern int optind; X X long chkCOFF(); X void dpyCOFF(), usage(); X X long COFFdate; /* -1 if not COFF, else COFF's f_timdat */ X void *bufptr; /* file data input buffer */ X char errstr[80]; /* holds expanded error string */ X int fd; /* file descriptor */ X int ndx; /* general loop index and subscript */ X int numread; /* number of bytes read from file */ X int optchr; /* option char from getopt(3C) */ X struct stat statbuf; /* buffer for stat(2) results */ X struct utimbuf ambuf; /* buffer for utime(2) input */ X X X while ( ( optchr = getopt( argc, argv, "amcs?hH" ) ) != EOF ) X { X switch (optchr) X { X case 'a': ++OPTaccess; X break; X case 'm': ++OPTmodify; X break; X case 'c': if ( OPTsilent ) X usage(); X else X ++OPTcoff; X break; X case 's': if ( OPTcoff ) X usage(); X else X ++OPTsilent; X break; X case '?': X case 'h': X case 'H': X default: usage(); X } X } X X if ( optind == argc ) X { X usage(); /* does exit(1) and never returns */ X } X X bufptr = malloc( BUFSIZ ); X X for ( ndx = optind; ndx < argc; ndx++ ) X { X if ( ( fd = open( argv[ndx], O_RDONLY, 0 ) ) < 0 ) X { X sprintf( errstr, "?%s: cannot open %s", argv[0], argv[ndx] ); X perror( errstr ); X } X else X { X COFFdate = -1L; X X if ( (numread = read( fd, bufptr, BUFSIZ ) ) < 0 ) X { X sprintf( errstr, "?%s: error reading %s", X argv[0], argv[ndx] ); X perror( errstr ); X } X else X { X COFFdate = chkCOFF( bufptr, numread ); X dpyCOFF( COFFdate, argv[ndx] ); X } X close( fd ); X X if ( COFFdate >= 0 && ( OPTaccess || OPTmodify ) ) X { X if ( stat ( argv[ndx], &statbuf ) < 0 ) X { X sprintf( errstr,"?%s: stat() failure on %s", X argv[0], argv[ndx] ); X perror( errstr ); X } X else X { X ambuf.actime = (OPTaccess) ? (time_t) COFFdate : X statbuf.st_atime; X ambuf.modtime = (OPTmodify) ? (time_t) COFFdate : X statbuf.st_mtime; X if ( utime( argv[ndx], &ambuf ) < 0 ) X { X sprintf( errstr,"?%s: utime() failure for %s", X argv[0], argv[ndx] ); X perror( errstr ); X } X } X } X } X } X free( bufptr ); X} X Xlong chkCOFF( bufptr, bufsize ) X FILHDR *bufptr; X int bufsize; X{ X int magic; X X if ( bufsize > FILHSZ ) X { X magic = bufptr->f_magic; X X if (magic == AOUT1MAGIC || X magic == AOUT2MAGIC || X magic == AOUT3MAGIC || X magic == MC68KWRMAGIC || X magic == MC68KROMAGIC || X magic == MC68KPGMAGIC ) X { X return bufptr->f_timdat; X } X else X { X return -1L; X } X } X else X { X return -1L; X } X} X Xvoid dpyCOFF( ldate, filename ) X long ldate; X char *filename; X{ X char timebuf[CTIMELEN]; X X if ( OPTsilent ) return; X X if ( ldate >= 0L ) X { X strcpy( timebuf, ctime( &ldate ) ); X timebuf[CROFFSET] = '\0'; X fprintf( stdout, "%s %s\n", timebuf, filename ); X } X else if ( OPTcoff == 0 ) X { X fprintf( stdout, "not a COFF file %s\n", filename ); X } X} X Xvoid usage() X{ X int ndx = 0; X X while ( usage_text[ndx] != 0 ) X { X fprintf( stderr, "%s\n", usage_text[ndx++] ); X } X fprintf( stderr, "%s\n", version ); X exit( 1 ); X} SHAR_EOF $TOUCH -am 1230045590 'coffdate.c' && chmod 0644 coffdate.c || echo 'restore of coffdate.c failed' Wc_c="`wc -c < 'coffdate.c'`" test 5258 -eq "$Wc_c" || echo 'coffdate.c: original size 5258, current size' "$Wc_c" fi exit 0