/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1985-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* library interface to file
*
* the sum of the hacks {s5,v10,planix} is _____ than the parts
*/
#include <ast.h>
#include <ctype.h>
#include <ccode.h>
#include <dt.h>
#include <modex.h>
#include <error.h>
#include <regex.h>
#include <swap.h>
typedef struct /* identifier dictionary entry */
{
} Info_t;
{
} Edit_t;
struct Entry;
typedef struct /* loop info */
{
} Loop_t;
{
union
{
unsigned long num;
char* str;
} Entry_t;
typedef unsigned short Cctype_t;
#else
typedef unsigned long Cctype_t;
#endif
#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)
#define ID_NONE 0
#define _MAGIC_PRIVATE_ \
char* mime; /* MIME type */ \
unsigned char* x2n; /* CC_ALIEN=>CC_NATIVE */ \
int fbsz; /* fbuf size */ \
int fbmx; /* fbuf max size */ \
int xbsz; /* xbuf size */ \
int swap; /* swap() operation */ \
unsigned long flags; /* disc+open flags */ \
long xoff; /* xbuf offset */ \
#include <magic.h>
{
{ "COMMON", ID_FORTRAN },
{ "COMPUTE", ID_COBOL },
{ "COMP", ID_COPYBOOK },
{ "COMPUTATIONAL",ID_COPYBOOK },
{ "DCL", ID_PL1 },
{ "DEFINED", ID_PL1 },
{ "DIMENSION", ID_FORTRAN },
{ "DIVISION", ID_COBOL },
{ "FILLER", ID_COPYBOOK },
{ "FIXED", ID_PL1 },
{ "FUNCTION", ID_FORTRAN },
{ "HTML", ID_HTML },
{ "INTEGER", ID_FORTRAN },
{ "MAIN", ID_PL1 },
{ "OPTIONS", ID_PL1 },
{ "PERFORM", ID_COBOL },
{ "PIC", ID_COPYBOOK },
{ "REAL", ID_FORTRAN },
{ "REDEFINES", ID_COPYBOOK },
{ "S9", ID_COPYBOOK },
{ "SECTION", ID_COBOL },
{ "SELECT", ID_COBOL },
{ "SUBROUTINE", ID_FORTRAN },
{ "TEXT", ID_ASM },
{ "VALUE", ID_COPYBOOK },
{ "attr", ID_MAM3 },
{ "binary", ID_YACC },
{ "block", ID_FORTRAN },
{ "bss", ID_ASM },
{ "byte", ID_ASM },
{ "char", ID_C },
{ "class", ID_CPLUSPLUS },
{ "clr", ID_NOTEXT },
{ "comm", ID_ASM },
{ "common", ID_FORTRAN },
{ "data", ID_ASM },
{ "dimension", ID_FORTRAN },
{ "done", ID_MAM2 },
{ "double", ID_C },
{ "even", ID_ASM },
{ "exec", ID_MAM3 },
{ "extern", ID_C },
{ "float", ID_C },
{ "function", ID_FORTRAN },
{ "globl", ID_ASM },
{ "h", ID_INCL3 },
{ "html", ID_HTML },
{ "include", ID_INCL1 },
{ "int", ID_C },
{ "integer", ID_FORTRAN },
{ "jmp", ID_NOTEXT },
{ "left", ID_YACC },
{ "libc", ID_INCL2 },
{ "long", ID_C },
{ "make", ID_MAM1 },
{ "mov", ID_NOTEXT },
{ "private", ID_CPLUSPLUS },
{ "public", ID_CPLUSPLUS },
{ "real", ID_FORTRAN },
{ "register", ID_C },
{ "right", ID_YACC },
{ "sfio", ID_INCL2 },
{ "static", ID_C },
{ "stdio", ID_INCL2 },
{ "struct", ID_C },
{ "subroutine", ID_FORTRAN },
{ "sys", ID_NOTEXT },
{ "term", ID_YACC },
{ "text", ID_ASM },
{ "tst", ID_NOTEXT },
{ "type", ID_YACC },
{ "typedef", ID_C },
{ "u", ID_INCL2 },
{ "union", ID_YACC },
{ "void", ID_C },
};
{
{ "atime", INFO_atime },
{ "blocks", INFO_blocks },
{ "ctime", INFO_ctime },
{ "fstype", INFO_fstype },
{ "gid", INFO_gid },
{ "mode", INFO_mode },
{ "mtime", INFO_mtime },
{ "name", INFO_name },
{ "nlink", INFO_nlink },
{ "size", INFO_size },
{ "uid", INFO_uid },
};
/*
* return pointer to data at offset off and size siz
*/
static char*
{
register long n;
if (off < 0)
return 0;
{
return 0;
return 0;
{
return 0;
}
return 0;
}
}
/*
* @... evaluator for strexpr()
*/
static long
{
register char* s = (char*)cs;
register long n = 0;
register char* p;
if (s)
{
if (*s == '@')
{
switch (*(s = *e))
{
case 'b':
case 'B':
s++;
n = *(unsigned char*)p;
else
s = (char*)cs;
break;
case 'h':
case 'H':
s++;
else
s = (char*)cs;
break;
case 'q':
case 'Q':
s++;
else
s = (char*)cs;
break;
default:
if (isalnum(*s))
s++;
else
s = (char*)cs;
break;
}
}
*e = s;
}
return n;
}
/*
* emit regex error message
*/
static void
{
{
}
}
/*
* decompose vcodex(3) method composition
*/
static char*
vcdecomp(char* b, char* e, unsigned char* m, unsigned char* x)
{
unsigned char* map;
const char* o;
int c;
int n;
int i;
int a;
a = 0;
i = 1;
for (;;)
{
if (i)
i = 0;
else
*b++ = '^';
if (m < (x - 1) && !*(m + 1))
{
/*
* obsolete indices
*/
if (!a)
{
a = 1;
o = "old, ";
while (b < e && (c = *o++))
*b++ = c;
}
switch (*m)
{
case 0: o = "delta"; break;
case 1: o = "huffman"; break;
case 2: o = "huffgroup"; break;
case 3: o = "arith"; break;
case 4: o = "bwt"; break;
case 5: o = "rle"; break;
case 6: o = "mtf"; break;
case 7: o = "transpose"; break;
case 8: o = "table"; break;
case 9: o = "huffpart"; break;
case 50: o = "map"; break;
case 100: o = "recfm"; break;
case 101: o = "ss7"; break;
default: o = "UNKNOWN"; break;
}
m += 2;
while (b < e && (c = *o++))
*b++ = c;
}
else
while (b < e && m < x && (c = *m++))
{
if (map)
c = map[c];
*b++ = c;
}
if (b >= e)
break;
n = 0;
while (m < x)
{
n = (n<<7) | (*m & 0x7f);
if (!(*m++ & 0x80))
break;
}
if (n >= (x - m))
break;
m += n;
}
return b;
}
/*
* check for magic table match in buf
*/
static char*
ckmagic(register Magic_t* mp, const char* file, char* buf, char* end, struct stat* st, unsigned long off)
{
register char* p;
register char* b;
register int level = 0;
int all = 0;
int c;
int str;
char* q;
char* t;
char* cur;
char* base = 0;
unsigned long num;
unsigned long mask;
{
fun:
{
{
call = -1;
level = 0;
continue;
}
}
{
case '#':
{
{
all = 1;
*b++ = '\n';
cur = b;
continue;
}
*b = 0;
return buf;
}
continue;
break;
case '$':
{
goto fun;
}
continue;
case ':':
goto fun;
continue;
case '|':
goto checknest;
/*FALLTHROUGH*/
default:
{
goto checknest;
}
break;
}
p = "";
num = 0;
else
{
case 0:
break;
case INFO_atime:
break;
case INFO_blocks:
break;
case INFO_ctime:
break;
case INFO_fstype:
break;
case INFO_gid:
{
}
else
{
}
break;
case INFO_mode:
{
}
else
{
}
break;
case INFO_mtime:
break;
case INFO_name:
if (!base)
{
base++;
else
}
p = base;
break;
case INFO_nlink:
break;
case INFO_size:
break;
case INFO_uid:
{
}
else
{
}
break;
}
{
case 'b':
goto next;
num = *(unsigned char*)p;
break;
case 'h':
goto next;
break;
case 'd':
case 'l':
case 'v':
goto next;
break;
case 'q':
goto next;
break;
case 'e':
goto next;
/*FALLTHROUGH*/
case 'E':
goto next;
if ((c = regexec(ep->value.sub, p, elementsof(matches), matches, 0)) || (c = regsubexec(ep->value.sub, p, elementsof(matches), matches)))
{
p[c] = 0;
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;
}
}
t = *q ? q : p;
if (mp->keep[level]++ && b > cur && b < end && *(b - 1) != ' ' && *t && *t != ',' && *t != '.' && *t != '\b')
*b++ = ' ';
goto checknest;
case 's':
goto next;
goto checkstr;
case 'm':
goto next;
/*FALLTHROUGH*/
case 'M':
case 'S':
for (;;)
{
break;
if ((ep->type == 'm' || ep->type == 'M') ? strmatch(p, ep->value.str) : !memcmp(p, ep->value.str, ep->mask))
break;
goto next;
}
if (mp->keep[level]++ && b > cur && b < end && *(b - 1) != ' ' && *q && *q != ',' && *q != '.' && *q != '\b')
*b++ = ' ';
*t = 0;
*t = c;
goto checknest;
}
{
case '=':
case '@':
break;
goto next;
if (!mask)
{
{
goto swapped;
}
}
{
for (c = 1; c < 4; c++)
{
goto swapped;
}
}
{
for (c = 1; c < 8; c++)
goto swapped;
}
goto next;
case '!':
break;
goto next;
case '^':
break;
goto next;
case '>':
break;
goto next;
case '<':
break;
goto next;
case 'l':
{
{
}
{
goto next;
}
else
goto fun;
}
goto next;
case 'm':
if (t)
{
*b = ' ';
b += strlen(b);
}
goto next;
break;
case 'r':
#if _UWIN
{
char* e;
goto next;
goto next;
gp = 0;
{
{
if (gp)
break;
}
else
{
{
break;
}
}
}
if (!gp)
goto next;
{
t += 9;
while (isspace(*t))
t++;
e = "application/x-ms-";
while ((c = *t++) && c != '.' && c != ' ')
*e = 0;
}
if (*t && !streq(t, "\"\""))
{
break;
}
goto next;
if (!t)
if (*t == '.')
*t = ' ';
break;
}
#else
goto next;
#endif
case 'v':
goto next;
c = 0;
do
{
num++;
c = (c<<7) | (*p & 0x7f);
} while (*p++ & 0x80);
goto next;
{
*b++ = ',';
*b++ = ' ';
}
goto checknest;
}
if (mp->keep[level]++ && b > cur && b < end && *(b - 1) != ' ' && *q && *q != ',' && *q != '.' && *q != '\b')
*b++ = ' ';
if (*q == '\b')
q++;
str = 0;
for (t = q; *t; t++)
if (*t == '%' && (c = *(t + 1)))
{
if (c == '%')
t++;
else
while (c && c != '%')
{
if (c == 's')
{
str = 1;
break;
}
else if (c == 'c' || c == 'd' || c == 'i' || c == 'u' || c == 'x' || c == 'X')
goto format;
t++;
c = *(t + 1);
}
}
if (!str)
else
{
{
}
else if (level > 0)
if (--level < 0)
{
level = 0;
}
}
continue;
next:
goto checknest;
}
{
*b = 0;
return buf;
}
return 0;
}
/*
* check english language stats
*/
static int
{
register char* s;
register int vowl = 0;
register int freq = 0;
register int rare = 0;
return 0;
return 0;
return 0;
for (s = "aeiou"; *s; s++)
for (s = "etaion"; *s; s++)
for (s = "vjkqxz"; *s; s++)
}
/*
* check programming language stats
*/
static char*
{
register int c;
register unsigned char* b;
register unsigned char* e;
register int q;
register char* s;
char* t;
char* base;
char* suff;
char* t1;
char* t2;
char* t3;
int n;
int badpun;
int code;
int pun;
/*
* check character coding
*/
flags = 0;
while (b < e)
code = 0;
q = CC_ASCII;
n = CC_MASK;
for (c = 0; c < CC_MAPS; c++)
{
{
q = c;
}
}
flags = n;
{
if (q != CC_NATIVE)
{
code = q;
}
if (b[0] == '#' && b[1] == '!')
{
for (b += 2; b < e && isspace(*b); b++);
for (s = (char*)b; b < e && isprint(*b); b++);
c = *b;
*b = 0;
{
if (t = strrchr(s, '/'))
s = t + 1;
for (t = s; *t; t++)
if (isspace(*t))
{
*t = 0;
break;
}
if (match(s, "*sh"))
{
t1 = T("command");
if (streq(s, "sh"))
*s = 0;
else
{
*b++ = ' ';
*b = 0;
}
}
else
{
t1 = T("interpreter");
*b++ = ' ';
*b = 0;
}
goto qualify;
}
*b = c;
}
badpun = 0;
pun = 0;
q = 0;
s = 0;
t = 0;
while (b < e)
{
c = *b++;
if (c == q && (q != '*' || *b == '/' && b++))
{
q = 0;
}
else if (c == '\\')
{
s = 0;
b++;
}
else if (!q)
{
if (isalpha(c) || c == '_')
{
if (!s)
s = (char*)b - 1;
}
else if (!isdigit(c))
{
if (s)
{
switch (*(s - 1))
{
case ':':
if (*b == ':')
break;
case '.':
break;
case '\n':
case '\\':
if (*b == '{')
t = (char*)b + 1;
break;
case '{':
if (s == t && *b == '}')
break;
}
{
for (q = 0; q < elementsof(dict); q++)
q = 0;
}
{
*(b - 1) = 0;
*(b - 1) = c;
}
s = 0;
}
switch (c)
{
case '\t':
break;
case '"':
case '\'':
q = c;
break;
case '/':
if (*b == '*')
q = *b++;
else if (*b == '/')
q = '\n';
break;
case '$':
if (*b == '(' && *(b + 1) != ' ')
break;
case '{':
case '}':
case '[':
case ']':
case '(':
break;
case ')':
goto punctuation;
case ':':
goto punctuation;
case '.':
case ',':
case '%':
case ';':
case '?':
pun++;
if (*b != ' ' && *b != '\n')
badpun++;
break;
}
}
}
}
}
else
while (b < e)
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;
{
s = T("command script");
goto qualify;
}
{
s = T("mail message");
goto qualify;
}
{
s = "mkfile";
goto qualify;
}
if (match(base, "*@(makefile|.mk)") || mp->multi['\t'] >= mp->count[':'] && (mp->multi['$'] > 0 || mp->multi[':'] > 0))
{
s = "makefile";
goto qualify;
}
{
s = T("nroff input");
goto qualify;
}
{
s = T("TeX input");
goto qualify;
}
{
if (c >= 2 && mp->identifier[ID_INCL2] >= c && mp->identifier[ID_INCL3] >= c && mp->count['.'] >= c ||
{
id_c:
t1 = "";
t2 = "c ";
t3 = T("program");
switch (*suff)
{
case 'c':
case 'C':
break;
case 'l':
case 'L':
t1 = "lex ";
break;
default:
t3 = T("header");
{
break;
}
/*FALLTHROUGH*/
case 'y':
case 'Y':
t1 = "yacc ";
break;
}
{
t2 = "c++ ";
}
goto qualify;
}
}
{
s = T("mam program");
goto qualify;
}
{
s = T("fortran program");
goto qualify;
}
if (mp->identifier[ID_HTML] > 0 && mp->count['<'] >= 8 && (c = mp->count['<'] - mp->count['>']) >= -2 && c <= 2)
{
s = T("html input");
goto qualify;
}
if (mp->identifier[ID_COPYBOOK] > 0 && mp->identifier[ID_COBOL] == 0 && (c = mp->count['('] - mp->count[')']) >= -2 && c <= 2)
{
s = T("cobol copybook");
goto qualify;
}
if (mp->identifier[ID_COBOL] > 0 && mp->identifier[ID_COPYBOOK] > 0 && (c = mp->count['('] - mp->count[')']) >= -2 && c <= 2)
{
s = T("cobol program");
goto qualify;
}
{
s = T("pl1 program");
goto qualify;
}
if (mp->count['{'] >= 6 && (c = mp->count['{'] - mp->count['}']) >= -2 && c <= 2 && mp->count['\\'] >= mp->count['{'])
{
s = T("TeX input");
goto qualify;
}
{
s = T("as program");
goto qualify;
}
{
s = T("english text");
goto qualify;
}
}
{
return T("core dump");
}
{
n = 0;
for (;;)
{
c = *b++;
q = 0;
while (c & 0x80)
{
c <<= 1;
q++;
}
switch (q)
{
case 4:
if (b < e && (*b++ & 0xc0) != 0x80)
break;
case 3:
if (b < e && (*b++ & 0xc0) != 0x80)
break;
case 2:
if (b < e && (*b++ & 0xc0) != 0x80)
break;
n = 1;
case 0:
if (b >= e)
{
if (n)
{
}
break;
}
continue;
}
break;
}
}
{
unsigned long d = 0;
{
/*
* compression/encryption via standard deviation
*/
for (c = 0; c < UCHAR_MAX; c++)
{
}
}
if (d <= 0)
s = T("binary");
else if (d < 4)
s = T("encrypted");
else if (d < 16)
s = T("packed");
else if (d < 64)
s = T("compressed");
else if (d < 256)
s = T("delta");
else
s = T("data");
return s;
}
else
if (!flags && mp->count['\n'] >= mp->count['\r'] && mp->count['\n'] <= (mp->count['\r'] + 1) && mp->count['\r'])
{
t = "dos ";
}
else
t = "";
if (code)
{
else
{
}
s = buf;
}
else if (*t)
{
s = buf;
}
return s;
}
/*
* return the basic magic string for file,st in buf,size
*/
static char*
{
register char* s;
register char* t;
{
{
return T("directory");
}
{
s = buf;
return T("cannot read symbolic link text");
return buf;
}
{
return buf;
}
{
return buf;
}
{
return "fifo";
}
#ifdef S_ISSOCK
{
return "socket";
}
#endif
}
s = T("empty");
s = T("cannot read");
else
{
s = T("empty");
else
{
}
}
{
register char* b;
register char* be;
register char* m;
register char* me;
while (m < me && b < t)
*m++ = *b++;
b = t = s;
for (;;)
{
{
break;
}
break;
b = t;
t = be + 1;
}
if ((*m++ = *b++) == ' ')
*(m - 1) = '-';
*m = 0;
}
return s;
}
/*
* low level for magicload()
*/
static int
{
register char* p;
register char* p2;
char* p3;
char* next;
int n;
int lge;
int lev;
int ent;
int old;
int cont;
cont = '$';
ent = 0;
lev = 0;
old = 0;
ret = 0;
error_info.line = 0;
{
error_info.line++;
for (; isspace(*p); p++);
/*
* nesting
*/
switch (*p)
{
case 0:
case '#':
cont = '#';
continue;
case '{':
continue;
case '}':
{
}
{
ent = 0;
ret = 0;
}
else
continue;
default:
if (*(p + 1) == '{' || *(p + 1) == '(' && *p != '+' && *p != '>' && *p != '&' && *p != '|')
{
n = *p++;
if (n >= 'a' && n <= 'z')
n -= 'a';
else
{
n = 0;
}
if (*p == '{')
{
}
else
{
}
if (ret)
continue;
}
break;
}
/*
* continuation
*/
cont = '$';
switch (*p)
{
case '>':
old = 1;
if (*(p + 1) == *p)
{
/*
* old style nesting push
*/
p++;
old = 2;
{
lev = 1;
}
}
/*FALLTHROUGH*/
case '+':
case '&':
case '|':
break;
default:
/*FALLTHROUGH*/
case '*':
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
break;
}
switch (old)
{
case 1:
old = 0;
if (lev)
{
/*
* old style nesting pop
*/
lev = 0;
if (last)
}
break;
case 2:
old = 1;
break;
}
if (isdigit(*p))
{
/*
* absolute offset
*/
}
else
{
if (!*p2)
{
continue;
}
/*
* offset expression
*/
*p2++ = 0;
if (isalpha(*p))
{
/*
* convert old style indirection to @
*/
for (;;)
{
switch (*p++)
{
case 0:
case '@':
case '(':
break;
case ')':
break;
default:
continue;
}
break;
}
if (*--p == ')')
{
*p = 0;
}
}
}
if (!*p2)
{
continue;
}
*p2++ = 0;
/*
* type
*/
if ((*p == 'b' || *p == 'l') && *(p + 1) == 'e')
{
p += 2;
}
if (*p == 's')
{
if (*(p + 1) == 'h')
else
}
else if (*p == 'a')
else
if (p = strchr(p, '&'))
{
/*
* old style mask
*/
}
*--p2 = '=';
/*
* comparison operation
*/
p = p2;
*p2++ = 0;
else
{
int qe = 0;
int qn = 0;
/*
* assume balanced {}[]()\\""'' field
*/
for (p2 = p;;)
{
switch (n = *p2++)
{
case 0:
break;
case '{':
if (!qe)
qe = '}';
if (qe == '}')
qn++;
continue;
case '(':
if (!qe)
qe = ')';
if (qe == ')')
qn++;
continue;
case '[':
if (!qe)
qe = ']';
if (qe == ']')
qn++;
continue;
case '}':
case ')':
case ']':
qn--;
continue;
case '"':
case '\'':
if (!qe)
qe = n;
else if (qe == n)
qe = 0;
continue;
case '\\':
if (*p2)
p2++;
continue;
default:
break;
continue;
}
if (n)
*(p2 - 1) = 0;
else
p2--;
break;
}
}
lge = 0;
else
{
if (*p == '&')
{
p = next;
}
switch (*p)
{
case '=':
case '>':
case '<':
case '*':
if (*p == '=')
{
p++;
{
case '>':
lge = -1;
break;
case '<':
lge = 1;
break;
}
}
break;
case '!':
case '@':
if (*p == '=')
p++;
break;
case 'x':
p++;
break;
default:
break;
}
}
{
{
{
{
}
if (n)
{
}
}
}
{
}
{
}
else if (*p == '\'')
{
stresc(p);
}
else if (strmatch(p, "+([a-z])\\(*\\)"))
{
char* t;
t = p;
while (*p && *p++ != '(');
{
case 'l':
n = *p++;
if (n < 'a' || n > 'z')
{
}
else if (!fun[n -= 'a'])
{
}
else
{
while (*p && *p++ != ',');
while (*t && *t++ != ',');
}
break;
case 'm':
case 'r':
break;
case 'v':
break;
default:
break;
}
}
else
{
}
}
/*
* file description
*/
if (p2)
{
{
/*
* check for message catalog index
*/
*p++ = 0;
{
if (*p3++ == ':')
{
if (!*p3)
{
*p++ = 0;
}
}
}
}
if (p)
{
for (; isspace(*p); p++);
if (*p)
}
}
else
/*
* get next entry
*/
}
if (last)
{
else
}
{
if (lev < 0)
else if (lev > 0)
if (ret)
}
error_info.file = 0;
error_info.line = 0;
return 0;
}
/*
* load a magic file into mp
*/
int
{
register char* s;
register char* e;
register char* t;
int n;
int found;
int list;
found = 0;
{
if (!(s = getenv(MAGIC_FILE_ENV)) || !*s)
s = MAGIC_FILE;
}
for (;;)
{
if (!list)
e = 0;
else if (e = strchr(s, ':'))
{
/*
* ok, so ~ won't work for the last list element
* we do it for MAGIC_FILES_ENV anyway
*/
if ((strneq(s, "~/", n = 2) || strneq(s, "$HOME/", n = 6) || strneq(s, "${HOME}/", n = 8)) && (t = getenv("HOME")))
{
s += n - 1;
}
goto nospace;
}
if (!*s || streq(s, "-"))
s = MAGIC_FILE;
{
if (list)
{
{
goto nospace;
goto next;
}
goto next;
}
else
{
return -1;
}
}
found = 1;
if (n && !list)
return -1;
next:
if (!e)
break;
s = e + 1;
}
if (!found)
{
{
}
return -1;
}
return 0;
return -1;
}
/*
* open a magic session
*/
{
register int i;
register int n;
register int f;
register int c;
return 0;
{
return 0;
}
goto bad;
for (n = 0; n < elementsof(info); n++)
for (i = 0; i < CC_MAPS; i++)
for (n = 0; n <= UCHAR_MAX; n++)
{
f = 0;
i = CC_MAPS;
while (--i >= 0)
{
}
}
return mp;
bad:
magicclose(mp);
return 0;
}
/*
* close a magicopen() session
*/
int
{
if (!mp)
return -1;
return 0;
}
/*
* return the magic string for file with optional stat info st
*/
char*
{
char* s;
if (!st)
s = T("cannot stat");
else
{
{
s = T("out of space");
}
}
if (!s)
s = T("error");
return s;
}
/*
* list the magic table in mp on sp
*/
int
{
while (ep)
{
else
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);
{
case 'm':
case 's':
break;
case 'V':
{
case 'l':
sfprintf(sp, "loop(%d,%d,%d,%d)", ep->value.loop->start, ep->value.loop->size, ep->value.loop->count, ep->value.loop->offset);
break;
case 'v':
break;
default:
break;
}
break;
default:
break;
}
{
}
else
{
{
}
}
}
return 0;
}