From b8cc6ee43a706c7aa6444fe56b62c71baf474840 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Sun, 11 Aug 2013 00:42:42 -0400 Subject: [PATCH] parse_extension/parse_extension_c --- ftype.c | 43 ++++++++++++++++++++++++------------------- ftype.txt | 2 +- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/ftype.c b/ftype.c index 3ee336f..1527ff9 100644 --- a/ftype.c +++ b/ftype.c @@ -3,18 +3,13 @@ #include -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 pd; - *ftype = 0; - *atype = 0; - - if (!cp || !*cp) return 0; pd = -1; @@ -34,23 +29,24 @@ int parse_extension(const char *cp, Word *ftype, LongWord *atype) if (pd + 1 >= i) return 0; pd++; // skip past it... - cp += pd; - size = i - pd; + return parse_extension(cp + pd, i - pd, ftype, atype); +} + +// 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; switch (h) { case 0x00: - // text - if (size == 4 - && (wp[0] | 0x2020) == 0x6574 // 'te' - && (wp[1] | 0x2020) == 0x7478 // 'xt' - ) { - *ftype = 0x04; - *atype = 0x0000; - return 1; - } // shk if (size == 3 && (wp[0] | 0x2020) == 0x6873 // 'sh' @@ -60,6 +56,15 @@ int parse_extension(const char *cp, Word *ftype, LongWord *atype) *atype = 0x8002; return 1; } + // text + if (size == 4 + && (wp[0] | 0x2020) == 0x6574 // 'te' + && (wp[1] | 0x2020) == 0x7478 // 'xt' + ) { + *ftype = 0x04; + *atype = 0x0000; + return 1; + } break; case 0x01: diff --git a/ftype.txt b/ftype.txt index 3dfc276..87bfd26 100644 --- a/ftype.txt +++ b/ftype.txt @@ -5,6 +5,7 @@ #include // 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 i; @@ -35,7 +36,6 @@ int parse_extension_c(const char *cp, Word *ftype, LongWord *atype) // cp is just the extension int parse_extension(const char *cp, Word size, Word *ftype, LongWord *atype) { - Word size; Word *wp = (Word *)cp; Word h;