/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1985-2010 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
* *
* 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
*
*/
#include "mimelib.h"
typedef struct Att_s
{
char* name;
char* value;
} Att_t;
typedef struct Cap_s
{
unsigned long flags;
char* test;
} Cap_t;
typedef struct
{
} Ent_t;
typedef struct
{
char* data;
int size;
} String_t;
typedef struct
{
char* next;
} Parse_t;
typedef struct
{
const char* pattern;
int prefix;
int hit;
} Walk_t;
/*
* convert c to lower case
*/
static int
lower(register int c)
{
}
/*
* Ent_t case insensitive comparf
*/
static int
{
return strcasecmp(a, b);
}
/*
* Cap_t free
*/
static void
{
{
}
}
/*
* Ent_t freef
*/
static void
{
{
}
}
/*
* add mime type entry in s to mp
*/
int
{
register char* t;
register char* v;
register char* k;
char* x;
int q;
for (; isspace(*s); s++);
if (*s && *s != '#')
{
cap = 0;
for (v = s; *v && *v != ';'; v++)
*v = 0;
if (*v)
{
*v++ = 0;
do
{
for (; isspace(*v); v++);
if (cap)
{
for (t = v; *t && !isspace(*t) && *t != '='; t++);
for (k = t; isspace(*t); t++);
if (!*t || *t == '=' || *t == ';')
{
if (*t)
while (isspace(*++t));
*k = 0;
k = v;
v = t;
}
else
k = 0;
}
if (*v == '"')
q = *v++;
else
q = 0;
for (t = v; *t; t++)
if (*t == '\\')
{
switch (*(t + 1))
{
case 0:
case '\\':
case '%':
*t = *(t + 1);
break;
default:
*t = ' ';
break;
}
if (!*++t)
break;
}
else if (*t == q)
{
*t = ' ';
q = 0;
}
else if (*t == ';' && !q)
{
*t = ' ';
break;
}
for (; t > v && isspace(*(t - 1)); t--);
if (t <= v && (!cap || !k))
break;
if (!cap)
{
return -1;
if (*t)
*t++ = 0;
}
else if (k)
{
if (*t)
*t++ = 0;
return -1;
if (!strcasecmp(k, "test"))
}
} while (*(v = t));
}
if (cap)
{
if (ent)
{
{
if (flags & MIME_REPLACE)
{
if (pud)
else
}
return 0;
}
}
return -1;
else
{
}
}
}
return 0;
}
/*
* load mime type files into mp
*/
int
{
register char* s;
register char* t;
register char* e;
register int n;
if (!(s = (char*)file))
{
if (!(s = getenv(MIME_FILES_ENV)))
s = MIME_FILES;
}
for (;;)
{
e = 0;
else if (e = strchr(s, ':'))
{
/*
* ok, so ~ won't work for the last list element
* we do it for MIME_FILES_ENV anyway
*/
if ((strneq(s, "~/", n = 2) || strneq(s, "$HOME/", n = 6) || strneq(s, "${HOME}/", n = 8)) && (t = getenv("HOME")))
{
s += n - 1;
}
return -1;
}
{
break;
}
return -1;
if (!e)
break;
s = e + 1;
}
return 0;
}
/*
* mimelist walker
*/
static int
{
if (!wp->pattern || !strncasecmp(ent->name, wp->pattern, wp->prefix) && (!ent->name[wp->prefix] || ent->name[wp->prefix] == '/'))
{
{
{
{
}
}
}
}
return 0;
}
/*
* find entry matching type
* if exact match fails then left and right x- and right version number
* permutations are attempted
*/
static Ent_t*
{
register char* lp;
register char* rp;
register char* rb;
register char* rv;
register int rc;
register int i;
char* s;
return ent;
*rp++ = 0;
rp += 2;
lp += 2;
do
{
do
{
{
return 0;
return ent;
if (rc)
{
*rv = 0;
return 0;
return ent;
}
}
} while (*rp);
} while (*lp);
}
/*
* list mime <type,data> for pat on fp
*/
int
{
{
{
}
}
}
/*
* get next arg in pp
* 0 returned if no more args
*/
static int
{
register char* s;
register int c;
register int q;
int x;
if (!*s || *s == '\n')
{
return 0;
}
q = 0;
x = 0;
while ((c = *s++) && c != ';' && c != '\n')
{
if (c == '"')
{
q = 1;
{
if (x)
x = -1;
else
x = 1;
}
{
x = 1;
}
do
{
if (!(c = *s++) || c == '\n')
{
s--;
break;
}
} while (c != '"');
if (first < 0 || x > 0)
{
c = ';';
break;
}
}
else if (c == '=' && !first)
{
first = 1;
}
break;
}
if (first >= 0 || !q)
else
{
}
return 0;
}
/*
* low level for mimeview()
*/
static char*
{
register char* t;
register int c;
for (;;)
{
switch (c = *s++)
{
case 0:
case '\n':
break;
case '%':
switch (c = *s++)
{
case 's':
continue;
case 't':
continue;
case '{':
for (t = s; *s && *s != '}'; s++);
{
break;
}
continue;
}
/*FALLTHROUGH*/
default:
continue;
}
break;
}
}
/*
* return value valid until next mime*() call
*/
char*
{
register char* s;
int c;
{
{
{
/*
* try to do a few common cases here
* mailcap consistency is a winning
* strategy
*/
{
goto lose;
if (a1.name.size == 6 && strneq(a1.name.data, "strcmp", 6) || a1.name.size == 10 && strneq(a1.name.data, "strcasecmp", 10))
{
goto lose;
goto lose;
c ^= 0;
else c ^= (a1.name.size == 6 ? strncmp : strncasecmp)(a2.name.data, a3.name.data, a2.name.size) == 0;
if (c)
break;
goto skip;
}
{
goto lose;
if (!arg(&a2, -1) || a2.name.size > 2 || a2.name.size == 1 && *a2.name.data != '=' || a2.name.size == 2 && (!strneq(a1.name.data, "!=", 2) || !strneq(a2.name.data, "==", 2)))
goto lose;
goto lose;
{
}
{
goto lose;
goto lose;
}
else
c ^= 0;
if (c)
break;
goto skip;
}
}
lose:
if (!system(s))
break;
}
skip:
return 0;
}
return 0;
}
return 0;
}
/*
* lower case identifier prefix strcmp
* if e!=0 then it will point to the next char after the match
*/
int
mimecmp(register const char* s, register const char* v, char** e)
{
register int n;
return n;
{
if (e)
*e = (char*)s;
return 0;
}
}
/*
* parse mime headers in strsearch(tab,num,siz) from s
* return >0 if mime header consumed
*/
int
{
register void* p;
char* e;
s += 9;
{
s += 8;
{
{
return 0;
return 0;
return 1;
}
}
else if (strchr(s, ':'))
return 1;
}
}
/*
* open a mime library handle
*/
{
return 0;
{
return 0;
}
return mp;
}
/*
* close a mimeopen() handle
*/
int
{
if (mp)
{
}
return 0;
}