From b4242ec2712e6b5caccdf52b6cf87f4b4611f9dc Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Mon, 16 Apr 2012 18:38:25 -0400 Subject: [PATCH] set the filetype based on the extension. --- ftype.c | 9 ++++++++- ftype.txt | 9 +++++++-- gopher.c | 5 +++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/ftype.c b/ftype.c index b09e80c..4ef6af4 100644 --- a/ftype.c +++ b/ftype.c @@ -1,13 +1,20 @@ +#pragma optimize 79 + #include int parse_ftype(const char *cp, Word size, Word *ftype, Word *atype) { Word *wp = (Word *)cp; + Word h; *ftype = 0; *atype = 0; - switch ((*cp | 0x20) ^ size) + if (!cp || !size) return 0; + + h = ((*cp | 0x20) ^ size) & 0x0f; + + switch (h) { case 0x00: // shk diff --git a/ftype.txt b/ftype.txt index edf4153..270857d 100644 --- a/ftype.txt +++ b/ftype.txt @@ -6,11 +6,16 @@ int parse_ftype(const char *cp, Word size, Word *ftype, Word *atype) { Word *wp = (Word *)cp; - + Word h; + *ftype = 0; *atype = 0; - switch ((*cp | 0x20) ^ size) + if (!cp || !size) return 0; + + h = ((*cp | 0x20) ^ size) & 0x0f; + + switch (h) { %% } diff --git a/gopher.c b/gopher.c index 574f7c3..0751dac 100644 --- a/gopher.c +++ b/gopher.c @@ -16,6 +16,8 @@ #include +extern int setfiletype(const char *filename); + /* * connect gopher.floodgap.com:70 * send path @@ -566,6 +568,7 @@ int main(int argc, char **argv) filename, strerror(errno)); exit(1); } + setfiletype(filename); } else if (flagO) { @@ -586,6 +589,8 @@ int main(int argc, char **argv) exit(1); } + setfiletype(filename); + free(filename); filename = NULL; }