123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- diff -bBur file-3.20.1/apprentice.c zzz-file/apprentice.c
- --- file-3.20.1/apprentice.c Wed Jun 18 23:58:04 1997
- +++ zzz-file/apprentice.c Wed Mar 12 17:07:11 1997
- @@ -45,7 +45,7 @@
-
- static int getvalue __P((struct magic *, char **));
- static int hextoint __P((int));
- -static char *getstr __P((char *, char *, int, int *));
- +static char *getstr __P((char *, char *, int, int *, char));
- static int parse __P((char *, int *, int));
- static void eatsize __P((char **));
-
- @@ -162,6 +162,7 @@
- v = (long) v;
- break;
- case STRING:
- + case REGEX:
- break;
- default:
- magwarn("can't happen: m->type=%d\n",
- @@ -276,6 +277,7 @@
- #define NLESHORT 7
- #define NLELONG 6
- #define NLEDATE 6
- +#define NREGEX 5
-
- if (*l == 'u') {
- ++l;
- @@ -316,6 +318,10 @@
- } else if (strncmp(l, "ledate", NLEDATE)==0) {
- m->type = LEDATE;
- l += NLEDATE;
- + } else if (strncmp(l, "regex", NREGEX)==0) {
- + m->type = REGEX;
- + m->reln = '=';
- + l += NREGEX;
- } else {
- magwarn("type %s invalid", l);
- return -1;
- @@ -329,7 +335,7 @@
- m->mask = ~0L;
- EATAB;
-
- - switch (*l) {
- + if (m->type!=REGEX) switch (*l) { // regex ignores reln
- case '>':
- case '<':
- /* Old-style anding: "0 byte &0x80 dynamically linked" */
- @@ -402,8 +408,8 @@
- {
- int slen;
-
- - if (m->type == STRING) {
- - *p = getstr(*p, m->value.s, sizeof(m->value.s), &slen);
- + if (m->type == STRING || m->type == REGEX) {
- + *p = getstr(*p, m->value.s, sizeof(m->value.s), &slen, m->type==REGEX);
- m->vallen = slen;
- } else
- if (m->reln != 'x') {
- @@ -420,18 +426,25 @@
- * Return updated scan pointer as function result.
- */
- static char *
- -getstr(s, p, plen, slen)
- +getstr(s, p, plen, slen, regex)
- register char *s;
- register char *p;
- int plen, *slen;
- +char regex;
- {
- char *origs = s, *origp = p;
- char *pmax = p + plen - 1;
- register int c;
- register int val;
-
- + if (regex)
- + {
- + regex = *s++;
- + if (regex==0) goto out;
- + }
- +
- while ((c = *s++) != '\0') {
- - if (isspace((unsigned char) c))
- + if ((regex && (c==regex)) || (!regex && isspace((unsigned char) c)))
- break;
- if (p >= pmax) {
- fprintf(stderr, "String too long: %s\n", origs);
- @@ -519,6 +532,7 @@
- } else
- *p++ = (char)c;
- }
- + if (regex) s++;
- out:
- *p = '\0';
- *slen = p - origp;
- diff -bBur file-3.20.1/print.c zzz-file/print.c
- --- file-3.20.1/print.c Wed Jun 18 23:58:19 1997
- +++ zzz-file/print.c Wed Mar 12 17:09:30 1997
- @@ -52,7 +52,7 @@
- static char *typ[] = { "invalid", "byte", "short", "invalid",
- "long", "string", "date", "beshort",
- "belong", "bedate", "leshort", "lelong",
- - "ledate" };
- + "ledate","regex" };
- (void) fputc('[', stderr);
- (void) fprintf(stderr, ">>>>>>>> %d" + 8 - (m->cont_level & 7),
- m->offset);
- @@ -84,6 +84,7 @@
- case BELONG:
- (void) fprintf(stderr, "%ld", m->value.l);
- break;
- + case REGEX:
- case STRING:
- showstr(stderr, m->value.s, -1);
- break;
- diff -bBur file-3.20.1/softmagic.c zzz-file/softmagic.c
- --- file-3.20.1/softmagic.c Thu Jun 19 00:36:54 1997
- +++ zzz-file/softmagic.c Wed Mar 12 18:45:11 1997
- @@ -30,10 +30,11 @@
- #include <string.h>
- #include <time.h>
- #include <sys/types.h>
- +#include <regex.h>
-
- #include "file.h"
-
- -#if 0
- +#ifndef lint
- static char *moduleid =
- "@(#)$Id: softmagic.c,v 1.31 1996/06/22 22:04:22 christos Exp $";
- #endif /* lint */
- @@ -233,12 +234,17 @@
- else {
- /* nick@feedback.com.ar Only print things before first newline */
- char *qqq;
- - if ((qqq=strchr(p->s,'\n'))) *qqq='\0';
- + if (qqq=strchr(p->s,'\n')) *qqq='\0';
- (void) printf(m->desc, p->s);
- t = m->offset + strlen(p->s);
- }
- break;
-
- + case REGEX:
- + (void) fputs(m->desc,stdout);
- + t = m->offset + 32; /* FIXME! */
- + break;
- +
- case DATE:
- case BEDATE:
- case LEDATE:
- @@ -247,7 +253,7 @@
- *rt = '\0';
- (void) printf(m->desc, pp);
- t = m->offset + sizeof(time_t);
- - break;
- + return;
- default:
- error("invalid m->type (%d) in mprint().\n", m->type);
- /*NOTREACHED*/
- @@ -268,6 +274,7 @@
- case SHORT:
- case LONG:
- case DATE:
- + case REGEX:
- return 1;
- case STRING:
- {
- @@ -376,6 +383,24 @@
- return 1;
- }
-
- +static int regex_match(const char *s, const char *pat)
- +{
- + regex_t reg;
- + regmatch_t *rm;
- + int err;
- +
- + err=regcomp(®,pat,REG_NEWLINE);
- + if (err)
- + {
- + error("Bad regex pattern: %s\n",pat);
- + }
- + rm=(regmatch_t*) malloc( sizeof(regmatch_t) * (reg.re_nsub+1) );
- + err=regexec(®,s,reg.re_nsub+1,rm,0);
- + regfree(®);
- + free(rm);
- + return err;
- +}
- +
- static int
- mcheck(p, m)
- union VALUETYPE* p;
- @@ -428,6 +453,10 @@
- if ((v = *b++ - *a++) != 0)
- break;
- }
- + break;
- + case REGEX:
- + l = 0;
- + v = regex_match(p->s, m->value.s);
- break;
- default:
- error("invalid type %d in mcheck().\n", m->type);
|