mirror of
https://github.com/ksherlock/gopher.git
synced 2025-01-06 15:31:35 +00:00
parse_extension/parse_extension_c
This commit is contained in:
parent
6c0594c255
commit
b8cc6ee43a
43
ftype.c
43
ftype.c
@ -3,18 +3,13 @@
|
|||||||
|
|
||||||
#include <Types.h>
|
#include <Types.h>
|
||||||
|
|
||||||
int parse_extension(const char *cp, Word *ftype, LongWord *atype)
|
// cp should be a filename w/ .ext
|
||||||
|
int parse_extension(const char *cp, Word size, Word *ftype, LongWord *atype);
|
||||||
|
int parse_extension_c(const char *cp, Word *ftype, LongWord *atype)
|
||||||
{
|
{
|
||||||
Word size;
|
|
||||||
Word *wp = (Word *)cp;
|
|
||||||
Word h;
|
|
||||||
int i;
|
int i;
|
||||||
int pd;
|
int pd;
|
||||||
|
|
||||||
*ftype = 0;
|
|
||||||
*atype = 0;
|
|
||||||
|
|
||||||
|
|
||||||
if (!cp || !*cp) return 0;
|
if (!cp || !*cp) return 0;
|
||||||
|
|
||||||
pd = -1;
|
pd = -1;
|
||||||
@ -34,23 +29,24 @@ int parse_extension(const char *cp, Word *ftype, LongWord *atype)
|
|||||||
if (pd + 1 >= i) return 0;
|
if (pd + 1 >= i) return 0;
|
||||||
pd++; // skip past it...
|
pd++; // skip past it...
|
||||||
|
|
||||||
cp += pd;
|
return parse_extension(cp + pd, i - pd, ftype, atype);
|
||||||
size = i - pd;
|
}
|
||||||
|
|
||||||
|
// cp is just the extension
|
||||||
|
int parse_extension(const char *cp, Word size, Word *ftype, LongWord *atype)
|
||||||
|
{
|
||||||
|
Word *wp = (Word *)cp;
|
||||||
|
Word h;
|
||||||
|
|
||||||
|
|
||||||
|
if (!cp || !size) return 0;
|
||||||
|
|
||||||
|
|
||||||
h = ((*cp | 0x20) ^ size) & 0x0f;
|
h = ((*cp | 0x20) ^ size) & 0x0f;
|
||||||
|
|
||||||
switch (h)
|
switch (h)
|
||||||
{
|
{
|
||||||
case 0x00:
|
case 0x00:
|
||||||
// text
|
|
||||||
if (size == 4
|
|
||||||
&& (wp[0] | 0x2020) == 0x6574 // 'te'
|
|
||||||
&& (wp[1] | 0x2020) == 0x7478 // 'xt'
|
|
||||||
) {
|
|
||||||
*ftype = 0x04;
|
|
||||||
*atype = 0x0000;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
// shk
|
// shk
|
||||||
if (size == 3
|
if (size == 3
|
||||||
&& (wp[0] | 0x2020) == 0x6873 // 'sh'
|
&& (wp[0] | 0x2020) == 0x6873 // 'sh'
|
||||||
@ -60,6 +56,15 @@ int parse_extension(const char *cp, Word *ftype, LongWord *atype)
|
|||||||
*atype = 0x8002;
|
*atype = 0x8002;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
// text
|
||||||
|
if (size == 4
|
||||||
|
&& (wp[0] | 0x2020) == 0x6574 // 'te'
|
||||||
|
&& (wp[1] | 0x2020) == 0x7478 // 'xt'
|
||||||
|
) {
|
||||||
|
*ftype = 0x04;
|
||||||
|
*atype = 0x0000;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x01:
|
case 0x01:
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <Types.h>
|
#include <Types.h>
|
||||||
|
|
||||||
// cp should be a filename w/ .ext
|
// cp should be a filename w/ .ext
|
||||||
|
int parse_extension(const char *cp, Word size, Word *ftype, LongWord *atype);
|
||||||
int parse_extension_c(const char *cp, Word *ftype, LongWord *atype)
|
int parse_extension_c(const char *cp, Word *ftype, LongWord *atype)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@ -35,7 +36,6 @@ int parse_extension_c(const char *cp, Word *ftype, LongWord *atype)
|
|||||||
// cp is just the extension
|
// cp is just the extension
|
||||||
int parse_extension(const char *cp, Word size, Word *ftype, LongWord *atype)
|
int parse_extension(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
Block a user