From: Christos Zoulas Date: Tue, 23 Oct 2007 21:26:55 +0000 (+0000) Subject: add -b and -bb option... I need to re-think this because it breaks compatibility X-Git-Tag: FILE4_22~22 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=25f2e980610c11d35211aa22cdab19b24b86d51c;p=file add -b and -bb option... I need to re-think this because it breaks compatibility --- diff --git a/.cvsignore b/.cvsignore index d8992189..948f00a9 100644 --- a/.cvsignore +++ b/.cvsignore @@ -1 +1,7 @@ autom4te.cache +Makefile +config.h +config.log +config.status +libtool +stamp-h1 diff --git a/ChangeLog b/ChangeLog index 223ef468..ced051b9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2007-10-23 5:25 Christos Zoulas + + * Add --with-filename, and --no-filename (Reuben Thomas) + 2007-10-23 3:59 Christos Zoulas * Rest of the mime split (Reuben Thomas) diff --git a/doc/.cvsignore b/doc/.cvsignore new file mode 100644 index 00000000..afdbc3e1 --- /dev/null +++ b/doc/.cvsignore @@ -0,0 +1,4 @@ +Makefile +*.1 +*.3 +*.4 diff --git a/magic/.cvsignore b/magic/.cvsignore new file mode 100644 index 00000000..7ad882c6 --- /dev/null +++ b/magic/.cvsignore @@ -0,0 +1,3 @@ +Makefile +magic +*.mgc diff --git a/python/.cvsignore b/python/.cvsignore new file mode 100644 index 00000000..a8f619d8 --- /dev/null +++ b/python/.cvsignore @@ -0,0 +1 @@ +Makefile diff --git a/src/.cvsignore b/src/.cvsignore new file mode 100644 index 00000000..ab6fbe74 --- /dev/null +++ b/src/.cvsignore @@ -0,0 +1,12 @@ +.deps +Makefile +config.h +config.log +config.status +libtool +stamp-h1 +.libs +*.lo +*.la +Makefile +file diff --git a/src/file.c b/src/file.c index 557adb16..39c1ec48 100644 --- a/src/file.c +++ b/src/file.c @@ -206,19 +206,26 @@ main(int argc, char *argv[]) case 0: help(); break; - case 10: + case 5: + bflag++; + break; + case 6: + bflag = 0; + break; + case 12: flags |= MAGIC_MIME_TYPE; break; - case 11: + case 13: flags |= MAGIC_MIME_ENCODING; break; } + break; #endif case '0': nulsep = 1; break; case 'b': - ++bflag; + bflag++; break; case 'c': action = FILE_CHECK; @@ -277,9 +284,9 @@ main(int argc, char *argv[]) flags |= MAGIC_DEVICES; break; case 'v': - (void)fprintf(stdout, "%s-%d.%.2d\n", progname, + (void)fprintf(stderr, "%s-%d.%.2d\n", progname, FILE_VERSION_MAJOR, patchlevel); - (void)fprintf(stdout, "magic file from %s\n", + (void)fprintf(stderr, "magic file from %s\n", magicfile); return 1; case 'z': @@ -337,6 +344,13 @@ main(int argc, char *argv[]) if (nw > wid) wid = nw; } + /* + * If bflag is only set once, set it depending on + * number of files + */ + if (bflag == 1) { + bflag = optind >= argc - 1; + } for (; optind < argc; optind++) process(argv[optind], wid); } @@ -541,13 +555,14 @@ usage(void) private void help(void) { - (void)puts( + (void)fputs( "Usage: file [OPTION...] [FILE...]\n" -"Determine file type of FILEs.\n"); +"Determine type of FILEs.\n" +"\n", stderr); #define OPT(shortname, longname, opt, doc) \ - printf(" -%c, --" longname doc, shortname); + fprintf(stderr, " -%c, --" longname doc, shortname); #define OPT_LONGONLY(longname, opt, doc) \ - printf(" --" longname doc); + fprintf(stderr, " --" longname doc); #include "file_opts.h" #undef OPT #undef OPT_LONGONLY diff --git a/src/file_opts.h b/src/file_opts.h index f46cf99b..7f377a41 100644 --- a/src/file_opts.h +++ b/src/file_opts.h @@ -1,5 +1,3 @@ -/* $File$ */ - /* * Table of command-line options * @@ -10,6 +8,8 @@ * * N.B. The long options' order must correspond to the code in file.c, * and OPTSTRING must be kept up-to-date with the short options. + * Pay particular attention to the numbers of long-only options in the + * switch statement! */ OPT_LONGONLY("help", 0, " display this help and exit\n") @@ -17,7 +17,14 @@ OPT('v', "version", 0, " output version information and exit\n") OPT('m', "magic-file", 1, " LIST use LIST as a colon-separated list of magic\n" " number files\n") OPT('z', "uncompress", 0, " try to look inside compressed files\n") -OPT('b', "brief", 0, " do not prepend filenames to output lines\n") +OPT('b', "brief", 0, " do not prepend filenames to output lines\n" + " If this flag is specified once, then\n" + " the filename is printed if more than one\n" + " files are tested. If this flag is specified\n" + " more than once, then filenames are never printed\n") +OPT_LONGONLY("no-filename", 0, " synonym for --brief\n") +OPT_LONGONLY("with-filename", 0, " print the file name for each match. This is\n" + " the default.\n") OPT('c', "checking-printout", 0, " print the parsed form of the magic file, use in\n" " conjunction with -m to debug a new magic file\n" " before installing it\n")