updated mime functions (match prototypes)
This commit is contained in:
parent
b7e90885aa
commit
aa6bcc05d3
98
mime.c
98
mime.c
|
@ -1,19 +1,19 @@
|
||||||
#pragma optimize 79
|
#pragma optimize 79
|
||||||
#pragma noroot
|
#pragma noroot
|
||||||
|
#pragma debug 0x8000
|
||||||
|
|
||||||
#include <Types.h>
|
#include <Types.h>
|
||||||
|
#include "prototypes.h"
|
||||||
|
|
||||||
int parse_mime(const char *cp, Word *ftype, LongWord *atype)
|
|
||||||
|
int parse_mime_c(const char *cp, Word *ftype, LongWord *atype)
|
||||||
{
|
{
|
||||||
Word size;
|
|
||||||
Word *wp = (Word *)cp;
|
|
||||||
Word h;
|
|
||||||
int i;
|
int i;
|
||||||
int semi;
|
|
||||||
int slash;
|
int slash;
|
||||||
|
int semi;
|
||||||
|
|
||||||
*ftype = 0;
|
if (!cp || !*cp)
|
||||||
*atype = 0;
|
return 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* two pass
|
* two pass
|
||||||
|
@ -21,31 +21,43 @@ int parse_mime(const char *cp, Word *ftype, LongWord *atype)
|
||||||
* 2. type
|
* 2. type
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (!cp || !*cp) return 0;
|
|
||||||
|
|
||||||
// find any optional ';'
|
|
||||||
semi = slash = -1;
|
semi = slash = -1;
|
||||||
for (i = 0; ; ++i)
|
for (i = 0; ; ++i)
|
||||||
{
|
{
|
||||||
char c = cp[i];
|
char c = cp[i];
|
||||||
if (c == 0) break;
|
if (c == 0 || c == ';') break;
|
||||||
if (c == '/') slash = i;
|
|
||||||
if (c == ';')
|
if (c == '/')
|
||||||
{
|
{
|
||||||
semi = i;
|
slash = i;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
size = i;
|
|
||||||
|
|
||||||
for (i = 0; i < 2; ++i)
|
// try type/subtype
|
||||||
|
if (parse_mime(cp, i, ftype, atype));
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
|
||||||
|
// try type
|
||||||
|
if (slash != -1)
|
||||||
|
return parse_mime(cp, slash, ftype, atype);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int parse_mime(const char *cp, Word size, Word *ftype, LongWord *atype)
|
||||||
|
{
|
||||||
|
Word *wp = (Word *)cp;
|
||||||
|
Word h;
|
||||||
|
|
||||||
|
if (!cp || !size) return 0;
|
||||||
|
|
||||||
|
retry:
|
||||||
|
|
||||||
|
h = ((*cp | 0x20) ^ size) & 0x0f;
|
||||||
|
|
||||||
|
switch (h)
|
||||||
{
|
{
|
||||||
h = ((*cp | 0x20) ^ size) & 0x0f;
|
|
||||||
|
|
||||||
switch (h)
|
|
||||||
{
|
|
||||||
case 0x00:
|
case 0x00:
|
||||||
// text
|
// text
|
||||||
if (size == 4
|
if (size == 4
|
||||||
|
@ -59,6 +71,20 @@ int parse_mime(const char *cp, Word *ftype, LongWord *atype)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x09:
|
case 0x09:
|
||||||
|
// text/x-pascal
|
||||||
|
if (size == 13
|
||||||
|
&& (wp[0] | 0x2020) == 0x6574 // 'te'
|
||||||
|
&& (wp[1] | 0x2020) == 0x7478 // 'xt'
|
||||||
|
&& (wp[2] | 0x2020) == 0x782f // '/x'
|
||||||
|
&& (wp[3] | 0x2020) == 0x702d // '-p'
|
||||||
|
&& (wp[4] | 0x2020) == 0x7361 // 'as'
|
||||||
|
&& (wp[5] | 0x2020) == 0x6163 // 'ca'
|
||||||
|
&& (cp[12] | 0x20) == 0x6c // 'l'
|
||||||
|
) {
|
||||||
|
*ftype = 0xb0;
|
||||||
|
*atype = 0x0005;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
// application/octet-stream
|
// application/octet-stream
|
||||||
if (size == 24
|
if (size == 24
|
||||||
&& (wp[0] | 0x2020) == 0x7061 // 'ap'
|
&& (wp[0] | 0x2020) == 0x7061 // 'ap'
|
||||||
|
@ -78,20 +104,6 @@ int parse_mime(const char *cp, Word *ftype, LongWord *atype)
|
||||||
*atype = 0x0000;
|
*atype = 0x0000;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
// text/x-pascal
|
|
||||||
if (size == 13
|
|
||||||
&& (wp[0] | 0x2020) == 0x6574 // 'te'
|
|
||||||
&& (wp[1] | 0x2020) == 0x7478 // 'xt'
|
|
||||||
&& (wp[2] | 0x2020) == 0x782f // '/x'
|
|
||||||
&& (wp[3] | 0x2020) == 0x702d // '-p'
|
|
||||||
&& (wp[4] | 0x2020) == 0x7361 // 'as'
|
|
||||||
&& (wp[5] | 0x2020) == 0x6163 // 'ca'
|
|
||||||
&& (cp[12] | 0x20) == 0x6c // 'l'
|
|
||||||
) {
|
|
||||||
*ftype = 0xb0;
|
|
||||||
*atype = 0x0005;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x0c:
|
case 0x0c:
|
||||||
|
@ -108,11 +120,15 @@ int parse_mime(const char *cp, Word *ftype, LongWord *atype)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
size = slash;
|
|
||||||
if (size == -1) break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
// try again as type
|
||||||
|
while (--size)
|
||||||
|
{
|
||||||
|
if (cp[size] == '/') goto retry;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
9
mime.txt
9
mime.txt
|
@ -1,13 +1,17 @@
|
||||||
%%
|
%%
|
||||||
#pragma optimize 79
|
#pragma optimize 79
|
||||||
#pragma noroot
|
#pragma noroot
|
||||||
|
#pragma debug 0x8000
|
||||||
|
|
||||||
#include <Types.h>
|
#include <Types.h>
|
||||||
|
#include "prototypes.h"
|
||||||
|
|
||||||
|
|
||||||
int parse_mime_c(const char *cp, Word *ftype, LongWord *atype)
|
int parse_mime_c(const char *cp, Word *ftype, LongWord *atype)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int slash;
|
int slash;
|
||||||
|
int semi;
|
||||||
|
|
||||||
if (!cp || !*cp)
|
if (!cp || !*cp)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -31,20 +35,19 @@ int parse_mime_c(const char *cp, Word *ftype, LongWord *atype)
|
||||||
}
|
}
|
||||||
|
|
||||||
// try type/subtype
|
// try type/subtype
|
||||||
if (parse_mime(cp, i, ftype, atype))
|
if (parse_mime(cp, i, ftype, atype));
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
|
||||||
// try type
|
// try type
|
||||||
if (slash != -1)
|
if (slash != -1)
|
||||||
return parse_mime(cp, slash, ftype, atype));
|
return parse_mime(cp, slash, ftype, atype);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int parse_mime(const char *cp, Word size, Word *ftype, LongWord *atype)
|
int parse_mime(const char *cp, Word size, Word *ftype, LongWord *atype)
|
||||||
{
|
{
|
||||||
Word size;
|
|
||||||
Word *wp = (Word *)cp;
|
Word *wp = (Word *)cp;
|
||||||
Word h;
|
Word h;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue