Deleted Added
full compact
15,19d14
< * 3. All advertising materials mentioning features or use of this software
< * must display the following acknowledgement:
< * This product includes software developed by Ian F. Darwin and others.
< * 4. The name of the author may not be used to endorse or promote products
< * derived from this software without specific prior written permission.
53c48
< FILE_RCSID("@(#)$Id: apprentice.c,v 1.78 2004/07/24 20:38:56 christos Exp $")
---
> FILE_RCSID("@(#)$Id: apprentice.c,v 1.82 2004/11/24 18:56:04 christos Exp $")
81a77,79
> #define IS_STRING(t) ((t) == FILE_STRING || (t) == FILE_PSTRING || \
> (t) == FILE_BESTRING16 || (t) == FILE_LESTRING16)
>
94c92
< private char *mkdbname(const char *, char *, size_t);
---
> private char *mkdbname(const char *, char *, size_t, int);
99c97
< private int check_format(struct magic *);
---
> private int check_format(struct magic_set *, struct magic *);
169c167
< file_magwarn("using regular magic file `%s'", fn);
---
> file_magwarn(ms, "using regular magic file `%s'", fn);
300d297
< int lineno;
303c300
< f = fopen(fn, "r");
---
> f = fopen(ms->file = fn, "r");
324c321,322
< for (lineno = 1; fgets(line, BUFSIZ, f) != NULL; lineno++) {
---
> for (ms->line = 1; fgets(line, BUFSIZ, f) != NULL; ms->line++) {
> size_t len;
327c325,326
< if (strlen(line) <= (unsigned)1) /* null line, garbage, etc */
---
> len = strlen(line);
> if (len < 2) /* null line, garbage, etc */
329c328
< line[strlen(line)-1] = '\0'; /* delete newline */
---
> line[len - 1] = '\0'; /* delete newline */
376a376,377
> case FILE_BESTRING16:
> case FILE_LESTRING16:
382c383
< file_magwarn("cannot happen: m->type=%d\n",
---
> file_magwarn(ms, "cannot happen: m->type=%d\n",
438c439
< file_magwarn("offset %s invalid", l);
---
> file_magwarn(ms, "offset `%s' invalid", l);
472,473c473,474
< file_magwarn(
< "indirect offset type %c invalid",
---
> file_magwarn(ms,
> "indirect offset type `%c' invalid",
523c524,525
< file_magwarn("missing ')' in indirect offset");
---
> file_magwarn(ms,
> "missing ')' in indirect offset");
547a550,551
> #define NBESTRING16 10
> #define NLESTRING16 10
605c609,615
< l += sizeof("regex");
---
> l += NREGEX;
> } else if (strncmp(l, "bestring16", NBESTRING16)==0) {
> m->type = FILE_BESTRING16;
> l += NBESTRING16;
> } else if (strncmp(l, "lestring16", NLESTRING16)==0) {
> m->type = FILE_LESTRING16;
> l += NLESTRING16;
608c618
< file_magwarn("type %s invalid", l);
---
> file_magwarn(ms, "type `%s' invalid", l);
614c624
< if (FILE_STRING != m->type && FILE_PSTRING != m->type)
---
> if (!IS_STRING(m->type))
620,621c630
< if (op != FILE_OPDIVIDE ||
< (FILE_STRING != m->type && FILE_PSTRING != m->type)) {
---
> if (op != FILE_OPDIVIDE || !IS_STRING(m->type)) {
643,644c652,653
< file_magwarn(
< "string extension %c invalid",
---
> file_magwarn(ms,
> "string extension `%c' invalid",
672c681
< if (m->type != FILE_STRING && m->type != FILE_PSTRING) {
---
> if (!IS_STRING(m->type)) {
716c725
< if (!check_format(m))
---
> if (!check_format(ms, m))
733c742
< check_format(struct magic *m)
---
> check_format(struct magic_set *ms, struct magic *m)
747c756
< file_magwarn("Internal error inconsistency between m->type"
---
> file_magwarn(ms, "Internal error inconsistency between m->type"
752,753c761,762
< file_magwarn("No format string for `%s' with description `%s'",
< m->desc, names[m->type]);
---
> file_magwarn(ms, "No format string for `%s' with description "
> "`%s'", m->desc, names[m->type]);
766c775
< file_magwarn("Invalid format `%s' for type `%s'",
---
> file_magwarn(ms, "Invalid format `%s' for type `%s'",
771c780
< file_magwarn("Printf format `%c' is not valid for type `%s'"
---
> file_magwarn(ms, "Printf format `%c' is not valid for type `%s'"
789a799,800
> case FILE_BESTRING16:
> case FILE_LESTRING16:
796c807
< file_magwarn("cannot get string from `%s'",
---
> file_magwarn(ms, "cannot get string from `%s'",
1028c1039
< char *dbname = mkdbname(fn, buf, sizeof(buf));
---
> char *dbname = mkdbname(fn, buf, sizeof(buf), 0);
1119c1130
< char *dbname = mkdbname(fn, buf, sizeof(buf));
---
> char *dbname = mkdbname(fn, buf, sizeof(buf), 1);
1155c1166
< mkdbname(const char *fn, char *buf, size_t bufsiz)
---
> mkdbname(const char *fn, char *buf, size_t bufsiz, int strip)
1157,1161c1168,1173
< #ifdef notdef
< const char *p;
< if ((p = strrchr(fn, '/')) != NULL)
< fn = ++p;
< #endif
---
> if (strip) {
> const char *p;
> if ((p = strrchr(fn, '/')) != NULL)
> fn = ++p;
> }
>
1216c1228
< if (m->type != FILE_STRING)
---
> if (IS_STRING(m->type))