]> granicus.if.org Git - file/commitdiff
make COMPILE_ONLY work again.
authorChristos Zoulas <christos@zoulas.com>
Fri, 4 Jun 2004 14:40:19 +0000 (14:40 +0000)
committerChristos Zoulas <christos@zoulas.com>
Fri, 4 Jun 2004 14:40:19 +0000 (14:40 +0000)
src/apprentice.c
src/funcs.c
src/magic.c

index 5bcbf5cfcb808e47ae6908b4412f5138936828d4..07c6c1026b42c5458d9f26182c3a081ecc8ed7c4 100644 (file)
@@ -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 */
 
index f15616d61d5d3b1397b98157536e6128bfbaecda..44cbdf1af35435487150a1cd4ba0dbe61955d152 100644 (file)
@@ -34,7 +34,7 @@
 #include <ctype.h>
 
 #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)
index d603296904fc2cf9c82d68ee2b68a85c9b537b5f..2f57892cf795a7cb2be338eaad78fd836539d131 100644 (file)
@@ -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)