From b1e44b1eeba366ed30295e71563fcbfec44e236f Mon Sep 17 00:00:00 2001 From: Christos Zoulas Date: Sat, 21 Jan 1995 21:03:35 +0000 Subject: [PATCH] Added CSECTION for the file man page Added version flag -v Fixed bug with -f input flag (from iorio@violet.berkeley.edu) Lots of magic fixes and reorganization... --- doc/file.man | 52 ++++++++++++++++++++---------------------------- doc/magic.man | 22 ++++++++++---------- src/Makefile | 10 ++++++---- src/file.c | 35 ++++++++++++++++++++++++-------- src/fsmagic.c | 4 +++- src/patchlevel.h | 12 ++++++++--- 6 files changed, 78 insertions(+), 57 deletions(-) diff --git a/doc/file.man b/doc/file.man index c10b221c..51aa6435 100644 --- a/doc/file.man +++ b/doc/file.man @@ -1,18 +1,12 @@ -.TH FILE 1 "Copyright but distributable" -.\# $Id: file.man,v 1.23 1993/09/24 18:50:48 christos Exp $ +.TH FILE __CSECTION__ "Copyright but distributable" +.\" $Id: file.man,v 1.24 1995/01/21 21:03:35 christos Exp $ .SH NAME -.I file +file \- determine file type .SH SYNOPSIS .B file [ -.B \-c -] -[ -.B \-z -] -[ -.B \-L +.B \-vczL ] [ .B \-f @@ -101,44 +95,42 @@ The language test routines also test for some miscellany .I tar archives) and determine whether an unknown file should be labelled as `ascii text' or `data'. -.PP -Use -.B \-m -.I file -to specify an alternate file of magic numbers. -.PP -The +.SH OPTIONS +.TP 8 +.B \-v +Print the version of the program and exit. +.TP 8 +.B \-m file +Specify an alternate file of magic numbers. +.TP 8 .B \-z -tries to look inside compressed files. -.PP -The +Try to look inside compressed files. +.TP 8 .B \-c -option causes a checking printout of the parsed form of the magic file. +Cause a checking printout of the parsed form of the magic file. This is usually used in conjunction with .B \-m to debug a new magic file before installing it. -.PP -The -.B \-f -.I namefile -option specifies that the names of the files to be examined -are to be read (one per line) from +.TP 8 +.B \-f namefile +Read the names of the files to be examined from .I namefile +(one per line) before the argument list. Either .I namefile or at least one filename argument must be present; to test the standard input, use ``-'' as a filename argument. -.PP -The +.TP 8 .B \-L option causes symlinks to be followed, as the like-named option in .IR ls (1). +(on systems that support symbolic links). .SH FILES .I __MAGIC__ \- default list of magic numbers .SH SEE ALSO -.IR magic (__SECTION__) +.IR magic (__FSECTION__) \- description of magic file format. .br .IR Strings (1), " od" (1) diff --git a/doc/magic.man b/doc/magic.man index 7c2788e9..2ae8e699 100644 --- a/doc/magic.man +++ b/doc/magic.man @@ -1,10 +1,10 @@ -.TH MAGIC __SECTION__ "Public Domain" +.TH MAGIC __FSECTION__ "Public Domain" .\" install as magic.4 on USG, magic.5 on V7 or Berkeley systems. .SH NAME magic \- file command's magic number file .SH DESCRIPTION The -.IR file (1) +.IR file (__CSECTION__) command identifies the type of a file using, among other tests, a test for whether the file begins with a certain @@ -79,10 +79,13 @@ value, .BR & , to specify that the value from the file must have set all of the bits that are set in the specified value, -or .BR ^ , to specify that the value from the file must have clear any of the bits -that are set in the specified value. +that are set in the specified value, or +.BR x , +to specify that any value will match. If the character is omitted, +it is assumed to be +.BR = . .IP Numeric values are specified in C form; e.g. .B 13 @@ -91,9 +94,6 @@ is decimal, is octal, and .B 0x13 is hexadecimal. -to specify that any value will match. If the character -is omitted, it is assumed to be -.BR = . .IP For string values, the byte string from the file must match the specified byte string. @@ -143,7 +143,7 @@ If the first character following the last is a .B ( then the string after the parenthesis is interpreted as an indirect offset. -That means that the number after the parenthesis is used as a offset in +That means that the number after the parenthesis is used as an offset in the file. The value at that offset is read, and is used again as an offset in the file. Indirect offsets are of the form: .BI (( x [.[bsl]][+-][ y ]). @@ -168,7 +168,7 @@ The formats .IR bedate , and .I ledate -are system-dependant; perhaps they should be specified as a number +are system-dependent; perhaps they should be specified as a number of bytes (2B, 4B, etc), since the files being recognized typically come from a system on which the lengths are invariant. @@ -176,7 +176,7 @@ a system on which the lengths are invariant. There is (currently) no support for specified-endian data to be used in indirect offsets. .SH SEE ALSO -.IR file (1) +.IR file (__CSECTION__) \- the command that reads this file. .\" .\" From: guy@sun.uucp (Guy Harris) @@ -191,4 +191,4 @@ indirect offsets. .\" the changes I posted to the S5R2 version. .\" .\" Modified for Ian Darwin's version of the file command. -.\" @(#)$Id: magic.man,v 1.11 1994/05/03 17:58:23 christos Exp $ +.\" @(#)$Id: magic.man,v 1.12 1995/01/21 21:03:35 christos Exp $ diff --git a/src/Makefile b/src/Makefile index d59f490f..ffaad646 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,6 +1,6 @@ # Makefile for file(1) cmd. # Copyright (c) Ian F. Darwin 86/09/01 - see LEGAL.NOTICE. -# @(#)$Id: Makefile,v 1.43 1994/05/03 17:57:59 christos Exp $ +# @(#)$Id: Makefile,v 1.44 1995/01/21 21:03:35 christos Exp $ # # This software is not subject to any license of the American Telephone # and Telegraph Company or of the Regents of the University of California. @@ -91,7 +91,7 @@ try: all $(OFILE) what ./file >lastnocore file: $(OBJS) - $(CC) $(CFLAGS) $(OBJS) -o $@ + $(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) -o $@ lint: $(SRCS) lint -ha $(DEFS) $(SRCS) | tee $@ magic: Magdir @@ -119,12 +119,14 @@ clobber: magic.${MANFEXT} : Makefile magic.man @rm -f $@ - sed -e s@__SECTION__@${MANFEXT}@g \ + sed -e s@__CSECTION__@${MANCEXT}@g \ + -e s@__FSECTION__@${MANFEXT}@g \ -e s@__MAGIC__@${MAGIC}@g magic.man > $@ file.${MANCEXT} : Makefile file.man @rm -f $@ - sed -e s@__SECTION__@${MANCEXT}@g \ + sed -e s@__CSECTION__@${MANCEXT}@g \ + -e s@__FSECTION__@${MANFEXT}@g \ -e s@__MAGIC__@${MAGIC}@g file.man > $@ send: dist diff --git a/src/file.c b/src/file.c index a8acdd43..4fafe9a6 100644 --- a/src/file.c +++ b/src/file.c @@ -26,7 +26,7 @@ */ #ifndef lint static char *moduleid = - "@(#)$Id: file.c,v 1.29 1993/10/27 20:59:05 christos Exp $"; + "@(#)$Id: file.c,v 1.30 1995/01/21 21:03:35 christos Exp $"; #endif /* lint */ #include @@ -36,15 +36,20 @@ static char *moduleid = #include /* for MAXPATHLEN */ #include #include /* for open() */ +#if (__COHERENT__ >= 0x420) +#include +#else #include +#endif #include /* for read() */ +#include "patchlevel.h" #include "file.h" #ifdef S_IFLNK -# define USAGE "Usage: %s [-czL] [-f namefile] [-m magicfile] file...\n" +# define USAGE "Usage: %s [-vczL] [-f namefile] [-m magicfile] file...\n" #else -# define USAGE "Usage: %s [-cz] [-f namefile] [-m magicfile] file...\n" +# define USAGE "Usage: %s [-vcz] [-f namefile] [-m magicfile] file...\n" #endif #ifndef MAGIC @@ -78,15 +83,19 @@ int argc; char *argv[]; { int c; - int check = 0, didsomefiles = 0, errflg = 0, ret = 0; + int check = 0, didsomefiles = 0, errflg = 0, ret = 0, app = 0; if ((progname = strrchr(argv[0], '/')) != NULL) progname++; else progname = argv[0]; - while ((c = getopt(argc, argv, "cdf:Lm:z")) != EOF) + while ((c = getopt(argc, argv, "vcdf:Lm:z")) != EOF) switch (c) { + case 'v': + (void) fprintf(stdout, "%s-%d.%d\n", progname, + FILE_VERSION_MAJOR, patchlevel); + return 1; case 'c': ++check; break; @@ -94,6 +103,12 @@ char *argv[]; ++debug; break; case 'f': + if (!app) { + ret = apprentice(magicfile, check); + if (check) + exit(ret); + app = 1; + } unwrap(optarg); ++didsomefiles; break; @@ -113,14 +128,18 @@ char *argv[]; errflg++; break; } + if (errflg) { (void) fprintf(stderr, USAGE, progname); exit(2); } - ret = apprentice(magicfile, check); - if (check) - exit(ret); + if (!app) { + ret = apprentice(magicfile, check); + if (check) + exit(ret); + app = 1; + } if (optind == argc) { if (!didsomefiles) { diff --git a/src/fsmagic.c b/src/fsmagic.c index 684e118d..5e00c4f1 100644 --- a/src/fsmagic.c +++ b/src/fsmagic.c @@ -46,7 +46,7 @@ #ifndef lint static char *moduleid = - "@(#)$Id: fsmagic.c,v 1.22 1993/02/19 12:09:04 ian Exp $"; + "@(#)$Id: fsmagic.c,v 1.23 1995/01/21 21:03:35 christos Exp $"; #endif /* lint */ int @@ -151,9 +151,11 @@ struct stat *sb; return 1; #endif #ifdef S_IFSOCK +#ifndef __COHERENT__ case S_IFSOCK: ckfputs("socket", stdout); return 1; +#endif #endif case S_IFREG: break; diff --git a/src/patchlevel.h b/src/patchlevel.h index 490a7d53..444bbb25 100644 --- a/src/patchlevel.h +++ b/src/patchlevel.h @@ -1,12 +1,18 @@ #define FILE_VERSION_MAJOR 3 -#define patchlevel 14 +#define patchlevel 15 /* * Patchlevel file for Ian Darwin's MAGIC command. - * $Id: patchlevel.h,v 1.14 1994/05/03 17:58:23 christos Exp $ + * $Id: patchlevel.h,v 1.15 1995/01/21 21:03:35 christos Exp $ * * $Log: patchlevel.h,v $ - * Revision 1.14 1994/05/03 17:58:23 christos + * Revision 1.15 1995/01/21 21:03:35 christos + * Added CSECTION for the file man page + * Added version flag -v + * Fixed bug with -f input flag (from iorio@violet.berkeley.edu) + * Lots of magic fixes and reorganization... + * + * Revision 1.14 1994/05/03 17:58:23 christos * changes from mycroft@gnu.ai.mit.edu (Charles Hannum) for unsigned * * Revision 1.13 1994/01/21 01:27:01 christos -- 2.40.0