From: Christos Zoulas Date: Fri, 4 Jun 2004 14:40:19 +0000 (+0000) Subject: make COMPILE_ONLY work again. X-Git-Tag: FILE5_05~864 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=16b588ebd883a3e9de98a30ab824125f6addea70;p=file make COMPILE_ONLY work again. --- diff --git a/src/apprentice.c b/src/apprentice.c index 5bcbf5cf..07c6c102 100644 --- a/src/apprentice.c +++ b/src/apprentice.c @@ -50,7 +50,7 @@ #endif #ifndef lint -FILE_RCSID("@(#)$Id: apprentice.c,v 1.76 2004/05/12 14:53:01 christos Exp $") +FILE_RCSID("@(#)$Id: apprentice.c,v 1.77 2004/06/04 14:40:19 christos Exp $") #endif /* lint */ #define EATAB {while (isascii((unsigned char) *l) && \ @@ -102,9 +102,6 @@ private size_t maxmagic = 0; private size_t magicsize = sizeof(struct magic); #ifdef COMPILE_ONLY -const char *magicfile; -char *progname; -int lineno; int main(int, char *[]); @@ -112,6 +109,8 @@ int main(int argc, char *argv[]) { int ret; + struct magic_set *ms; + char *progname; if ((progname = strrchr(argv[0], '/')) != NULL) progname++; @@ -119,12 +118,19 @@ main(int argc, char *argv[]) progname = argv[0]; if (argc != 2) { - (void)fprintf(stderr, "usage: %s file\n", progname); - exit(1); + (void)fprintf(stderr, "Usage: %s file\n", progname); + return 1; } - magicfile = argv[1]; - exit(file_apprentice(magicfile, COMPILE, MAGIC_CHECK) == -1 ? 1 : 0); + if ((ms = magic_open(MAGIC_CHECK)) == NULL) { + (void)fprintf(stderr, "%s: %s\n", progname, strerror(errno)); + return 1; + } + ret = magic_compile(ms, argv[1]) == -1 ? 1 : 0; + if (ret == 1) + (void)fprintf(stderr, "%s: %s\n", progname, magic_error(ms)); + magic_close(ms); + return ret; } #endif /* COMPILE_ONLY */ diff --git a/src/funcs.c b/src/funcs.c index f15616d6..44cbdf1a 100644 --- a/src/funcs.c +++ b/src/funcs.c @@ -34,7 +34,7 @@ #include #ifndef lint -FILE_RCSID("@(#)$Id: funcs.c,v 1.11 2003/11/11 20:01:46 christos Exp $") +FILE_RCSID("@(#)$Id: funcs.c,v 1.12 2004/06/04 14:40:20 christos Exp $") #endif /* lint */ /* * Like printf, only we print to a buffer and advance it. @@ -110,6 +110,7 @@ file_badread(struct magic_set *ms) file_error(ms, errno, "error reading"); } +#ifndef COMPILE_ONLY protected int file_buffer(struct magic_set *ms, const void *buf, size_t nb) { @@ -133,6 +134,7 @@ file_buffer(struct magic_set *ms, const void *buf, size_t nb) } return m; } +#endif protected int file_reset(struct magic_set *ms) diff --git a/src/magic.c b/src/magic.c index d6032969..2f57892c 100644 --- a/src/magic.c +++ b/src/magic.c @@ -65,7 +65,7 @@ #include "patchlevel.h" #ifndef lint -FILE_RCSID("@(#)$Id: magic.c,v 1.20 2004/03/23 15:33:43 christos Exp $") +FILE_RCSID("@(#)$Id: magic.c,v 1.21 2004/06/04 14:40:20 christos Exp $") #endif /* lint */ #ifdef __EMX__ @@ -204,6 +204,7 @@ close_and_restore(const struct magic_set *ms, const char *name, int fd, } } +#ifndef COMPILE_ONLY /* * find type of named file */ @@ -316,6 +317,7 @@ magic_buffer(struct magic_set *ms, const void *buf, size_t nb) } return file_getbuffer(ms); } +#endif public const char * magic_error(struct magic_set *ms)