fb98811412f1a61efdc30b38091bf4708148a806Allan Foster/***********************************************************************
fb98811412f1a61efdc30b38091bf4708148a806Allan Foster* This software is part of the ast package *
fb98811412f1a61efdc30b38091bf4708148a806Allan Foster* Copyright (c) 1985-2011 AT&T Intellectual Property *
4c0f084e476c05989eb702c500a763ef09ba044ejeff.schenk* and is licensed under the *
fb98811412f1a61efdc30b38091bf4708148a806Allan Foster* Common Public License, Version 1.0 *
fb98811412f1a61efdc30b38091bf4708148a806Allan Foster* by AT&T Intellectual Property *
fb98811412f1a61efdc30b38091bf4708148a806Allan Foster* A copy of the License is available at *
fb98811412f1a61efdc30b38091bf4708148a806Allan Foster* http://www.opensource.org/licenses/cpl1.0.txt *
4c0f084e476c05989eb702c500a763ef09ba044ejeff.schenk* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
fb98811412f1a61efdc30b38091bf4708148a806Allan Foster* Information and Software Systems Research *
4c0f084e476c05989eb702c500a763ef09ba044ejeff.schenk* AT&T Research *
4c0f084e476c05989eb702c500a763ef09ba044ejeff.schenk* Florham Park NJ *
fb98811412f1a61efdc30b38091bf4708148a806Allan Foster* Glenn Fowler <gsf@research.att.com> *
fb98811412f1a61efdc30b38091bf4708148a806Allan Foster* David Korn <dgk@research.att.com> *
fb98811412f1a61efdc30b38091bf4708148a806Allan Foster* Phong Vo <kpv@research.att.com> *
fb98811412f1a61efdc30b38091bf4708148a806Allan Foster***********************************************************************/
fb98811412f1a61efdc30b38091bf4708148a806Allan Foster * Glenn Fowler
fb98811412f1a61efdc30b38091bf4708148a806Allan Foster * AT&T Research
fb98811412f1a61efdc30b38091bf4708148a806Allan Foster * library interface to file
4c0f084e476c05989eb702c500a763ef09ba044ejeff.schenk * the sum of the hacks {s5,v10,planix} is _____ than the parts
fb98811412f1a61efdc30b38091bf4708148a806Allan Fosterstatic const char id[] = "\n@(#)$Id: magic library (AT&T Research) 2011-01-28 $\0\n";
fb98811412f1a61efdc30b38091bf4708148a806Allan Foster#define T(m) (*m?ERROR_translate(NiL,NiL,lib,m):m)
fb98811412f1a61efdc30b38091bf4708148a806Allan Foster#define match(s,p) strgrpmatch(s,p,NiL,0,STR_LEFT|STR_RIGHT|STR_ICASE)
fb98811412f1a61efdc30b38091bf4708148a806Allan Fostertypedef struct /* identifier dictionary entry */
fb98811412f1a61efdc30b38091bf4708148a806Allan Fostertypedef struct /* loop info */
fb98811412f1a61efdc30b38091bf4708148a806Allan Foster#define CC_notext CC_text /* CC_text is flipped before checking */
fb98811412f1a61efdc30b38091bf4708148a806Allan Foster#define CC_MASK (CC_binary|CC_latin|CC_control|CC_text)
fb98811412f1a61efdc30b38091bf4708148a806Allan Foster#define CCTYPE(c) (((c)>0240)?CC_binary:((c)>=0200)?CC_latin:((c)<040&&(c)!=007&&(c)!=011&&(c)!=012&&(c)!=013&&(c)!=015)?CC_control:CC_text)
fb98811412f1a61efdc30b38091bf4708148a806Allan Foster Entry_t* magiclast; /* last entry in magic */ \
fb98811412f1a61efdc30b38091bf4708148a806Allan Foster unsigned char* x2n; /* CC_ALIEN=>CC_NATIVE */ \
fb98811412f1a61efdc30b38091bf4708148a806Allan Foster char xbuf[SF_BUFSIZE + 1]; /* indirect file data */ \
#include <magic.h>
if (off < 0)
register char* s = (char*)cs;
s = (char*)cs;
s = (char*)cs;
s = (char*)cs;
if (isalnum(*s))
s = (char*)cs;
if (map)
c = map[c];
ckmagic(register Magic_t* mp, const char* file, char* buf, char* end, struct stat* st, unsigned long off)
fun:
level = 0;
cur = b;
return buf;
goto fun;
goto fun;
goto checknest;
goto checknest;
num = 0;
case INFO_atime:
case INFO_blocks:
case INFO_ctime:
case INFO_fstype:
case INFO_gid:
case INFO_mode:
case INFO_mtime:
case INFO_name:
if (!base)
base++;
p = base;
case INFO_nlink:
case INFO_size:
case INFO_uid:
goto next;
num = *(unsigned char*)p;
goto next;
goto next;
goto next;
goto next;
goto next;
if ((c = regexec(ep->value.sub, p, elementsof(matches), matches, 0)) || (c = regsubexec(ep->value.sub, p, elementsof(matches), matches)))
if ((c = regexec(ep->value.sub, p, elementsof(matches), matches, 0)) || (c = regsubexec(ep->value.sub, p, elementsof(matches), matches)))
if (c != REG_NOMATCH)
goto next;
if (mp->keep[level]++ && b > cur && b < end && *(b - 1) != ' ' && *t && *t != ',' && *t != '.' && *t != '\b')
goto checknest;
goto next;
goto checkstr;
goto next;
if ((ep->type == 'm' || ep->type == 'M') ? strmatch(p, ep->value.str) : !memcmp(p, ep->value.str, ep->mask))
goto next;
if (mp->keep[level]++ && b > cur && b < end && *(b - 1) != ' ' && *q && *q != ',' && *q != '.' && *q != '\b')
goto checknest;
goto next;
if (!mask)
goto swapped;
goto swapped;
goto swapped;
goto next;
goto next;
goto next;
goto next;
goto next;
goto next;
goto fun;
goto next;
b += strlen(b);
goto next;
#if _UWIN
goto next;
goto next;
gp = 0;
if (gp)
if (!gp)
goto next;
while (isspace(*t))
e = "application/x-ms-";
goto next;
goto next;
goto next;
num++;
goto next;
goto checknest;
if (mp->keep[level]++ && b > cur && b < end && *(b - 1) != ' ' && *q && *q != ',' && *q != '.' && *q != '\b')
str = 0;
if (!str)
else if (level > 0)
if (--level < 0)
level = 0;
next:
goto checknest;
return buf;
flags = 0;
code = 0;
q = CC_ASCII;
n = CC_MASK;
for (c = 0; c < CC_MAPS; c++)
flags = n;
if (q != CC_NATIVE)
code = q;
for (s = (char*)b; b < e && isprint(*b); b++);
if (isspace(*t))
goto qualify;
badpun = 0;
pun = 0;
else if (!isdigit(c))
goto punctuation;
goto punctuation;
pun++;
badpun++;
if (!flags)
goto id_sh;
goto id_mk;
goto id_make;
goto id_mam;
goto id_c;
goto id_fortran;
goto id_html;
goto id_copybook;
goto id_cobol;
goto id_pl1;
goto id_tex;
goto id_asm;
goto qualify;
goto qualify;
goto qualify;
if (match(base, "*@(makefile|.mk)") || mp->multi['\t'] >= mp->count[':'] && (mp->multi['$'] > 0 || mp->multi[':'] > 0))
goto qualify;
goto qualify;
goto qualify;
if (c >= 2 && mp->identifier[ID_INCL2] >= c && mp->identifier[ID_INCL3] >= c && mp->count['.'] >= c ||
id_c:
switch (*suff)
goto qualify;
goto qualify;
goto qualify;
if (mp->identifier[ID_HTML] > 0 && mp->count['<'] >= 8 && (c = mp->count['<'] - mp->count['>']) >= -2 && c <= 2)
goto qualify;
if (mp->identifier[ID_COPYBOOK] > 0 && mp->identifier[ID_COBOL] == 0 && (c = mp->count['('] - mp->count[')']) >= -2 && c <= 2)
goto qualify;
if (mp->identifier[ID_COBOL] > 0 && mp->identifier[ID_COPYBOOK] > 0 && (c = mp->count['('] - mp->count[')']) >= -2 && c <= 2)
goto qualify;
goto qualify;
if (mp->count['{'] >= 6 && (c = mp->count['{'] - mp->count['}']) >= -2 && c <= 2 && mp->count['\\'] >= mp->count['{'])
goto qualify;
goto qualify;
goto qualify;
* compression/encryption via standard deviation
for (c = 0; c < UCHAR_MAX; c++)
if (!flags && mp->count['\n'] >= mp->count['\r'] && mp->count['\n'] <= (mp->count['\r'] + 1) && mp->count['\r'])
if (code)
s = buf;
s = buf;
s = buf;
return buf;
return buf;
return buf;
#ifdef S_ISSOCK
while (m < me && b < t)
ent = 0;
lev = 0;
old = 0;
ret = 0;
for (; isspace(*p); p++);
ent = 0;
ret = 0;
if (ret)
switch (old)
old = 0;
if (lev)
lev = 0;
if (last)
if (isdigit(*p))
if (!*p2)
*p2++ = 0;
if (isalpha(*p))
if (!*p2)
*p2++ = 0;
p = p2;
*p2++ = 0;
for (p2 = p;;)
switch (n = *p2++)
if (!qe)
qn++;
if (!qe)
qn++;
if (!qe)
qn++;
qn--;
if (!qe)
qe = n;
else if (qe == n)
qe = 0;
if (*p2)
p2++;
p2--;
lge = 0;
p = next;
stresc(p);
if (p2)
if (!*p3)
for (; isspace(*p); p++);
if (last)
if (lev < 0)
else if (lev > 0)
if (ret)
found = 0;
s = MAGIC_FILE;
if (!list)
if ((strneq(s, "~/", n = 2) || strneq(s, "$HOME/", n = 6) || strneq(s, "${HOME}/", n = 8)) && (t = getenv("HOME")))
goto nospace;
s = MAGIC_FILE;
if (list)
goto nospace;
goto next;
goto next;
if (n && !list)
next:
if (!found)
goto bad;
for (i = 0; i < CC_MAPS; i++)
for (n = 0; n <= UCHAR_MAX; n++)
i = CC_MAPS;
return mp;
bad:
if (!mp)
if (!st)
while (ep)
sfprintf(sp, "\t%s%c\t%c\t%lo\t", ep->swap == (char)~3 ? "L" : ep->swap == (char)~0 ? "B" : "", ep->type, ep->op, ep->mask);