Skip to content

Commit b8cc6ee

Browse files
committed
parse_extension/parse_extension_c
1 parent 6c0594c commit b8cc6ee

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

ftype.c

+24-19
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,13 @@
33

44
#include <Types.h>
55

6-
int parse_extension(const char *cp, Word *ftype, LongWord *atype)
6+
// cp should be a filename w/ .ext
7+
int parse_extension(const char *cp, Word size, Word *ftype, LongWord *atype);
8+
int parse_extension_c(const char *cp, Word *ftype, LongWord *atype)
79
{
8-
Word size;
9-
Word *wp = (Word *)cp;
10-
Word h;
1110
int i;
1211
int pd;
1312

14-
*ftype = 0;
15-
*atype = 0;
16-
17-
1813
if (!cp || !*cp) return 0;
1914

2015
pd = -1;
@@ -34,23 +29,24 @@ int parse_extension(const char *cp, Word *ftype, LongWord *atype)
3429
if (pd + 1 >= i) return 0;
3530
pd++; // skip past it...
3631

37-
cp += pd;
38-
size = i - pd;
32+
return parse_extension(cp + pd, i - pd, ftype, atype);
33+
}
34+
35+
// cp is just the extension
36+
int parse_extension(const char *cp, Word size, Word *ftype, LongWord *atype)
37+
{
38+
Word *wp = (Word *)cp;
39+
Word h;
40+
41+
42+
if (!cp || !size) return 0;
43+
3944

4045
h = ((*cp | 0x20) ^ size) & 0x0f;
4146

4247
switch (h)
4348
{
4449
case 0x00:
45-
// text
46-
if (size == 4
47-
&& (wp[0] | 0x2020) == 0x6574 // 'te'
48-
&& (wp[1] | 0x2020) == 0x7478 // 'xt'
49-
) {
50-
*ftype = 0x04;
51-
*atype = 0x0000;
52-
return 1;
53-
}
5450
// shk
5551
if (size == 3
5652
&& (wp[0] | 0x2020) == 0x6873 // 'sh'
@@ -60,6 +56,15 @@ int parse_extension(const char *cp, Word *ftype, LongWord *atype)
6056
*atype = 0x8002;
6157
return 1;
6258
}
59+
// text
60+
if (size == 4
61+
&& (wp[0] | 0x2020) == 0x6574 // 'te'
62+
&& (wp[1] | 0x2020) == 0x7478 // 'xt'
63+
) {
64+
*ftype = 0x04;
65+
*atype = 0x0000;
66+
return 1;
67+
}
6368
break;
6469

6570
case 0x01:

ftype.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <Types.h>
66

77
// cp should be a filename w/ .ext
8+
int parse_extension(const char *cp, Word size, Word *ftype, LongWord *atype);
89
int parse_extension_c(const char *cp, Word *ftype, LongWord *atype)
910
{
1011
int i;
@@ -35,7 +36,6 @@ int parse_extension_c(const char *cp, Word *ftype, LongWord *atype)
3536
// cp is just the extension
3637
int parse_extension(const char *cp, Word size, Word *ftype, LongWord *atype)
3738
{
38-
Word size;
3939
Word *wp = (Word *)cp;
4040
Word h;
4141

0 commit comments

Comments
 (0)