diff --git a/gopher.c b/gopher.c index 36b2659..a89fbe6 100644 --- a/gopher.c +++ b/gopher.c @@ -17,11 +17,11 @@ #include "url.h" #include "connection.h" #include "readline2.h" -#include "prototypes.h" -#include "flags.h" - +#include "options.h" #include "s16debug.h" +#include "prototypes.h" + static FileInfoRecGS FileInfo; static Word FileAttr; diff --git a/http.c b/http.c index 2096743..4becaa7 100644 --- a/http.c +++ b/http.c @@ -32,13 +32,14 @@ #include "url.h" #include "connection.h" -#include "prototypes.h" #include "dictionary.h" -#include "flags.h" +#include "options.h" #include "readline2.h" #include "http.utils.h" #include "s16debug.h" +#include "prototypes.h" + static FileInfoRecGS FileInfo; static Word FileAttr; diff --git a/main.c b/main.c index c983e39..78f0816 100644 --- a/main.c +++ b/main.c @@ -11,8 +11,9 @@ #include "url.h" #include "connection.h" +#include "options.h" + #include "prototypes.h" -#include "flags.h" // startup/shutdown flags. enum { @@ -171,6 +172,30 @@ char *get_url_filename(const char *cp, URLComponents *components) return out; } +#define GOPHER_VERSION "0.3" +void version(void) +{ + puts("gopher version " GOPHER_VERSION); +} + +void help(void) +{ + puts("gopher version " GOPHER_VERSION); + puts("usage: gopher [options] url"); + puts(""); + puts("-h show help"); + puts("-V show version"); + puts("-o file write output to file"); + puts("-O write output to file based on URL"); + puts(""); + puts("HTTP options:"); + puts("-9 use HTTP version 0.9"); + puts("-0 use HTTP version 1.0"); + puts("-1 use HTTP version 1.1"); + puts("-i print headers"); + puts("-I print only headers (HEAD)"); +} + int main(int argc, char **argv) { @@ -180,14 +205,11 @@ int main(int argc, char **argv) int x; - x = ParseFlags(argc, argv); - if (x < 0) return 1; - - argv += x; - argc -= x; + memset(&flags, 0, sizeof(flags)); + argc = GetOptions(argc, argv, &flags); - if (argc != 1) + if (argc != 2) { help(); return 1; @@ -216,12 +238,12 @@ int main(int argc, char **argv) - if (argc == 1) + if (argc == 2) { const char *url; URLComponents components; - url = *argv; + url = argv[1]; if (!ParseURL(url, strlen(url), &components)) { diff --git a/makefile.mk b/makefile.mk index 428909a..03f1b90 100644 --- a/makefile.mk +++ b/makefile.mk @@ -1,7 +1,7 @@ CFLAGS += $(DEFINES) -v -w OBJS = main.o gopher.o url.o connection.o readline2.o scheme.o ftype.o \ mime.o setftype.o s16debug.o common.o http.o http.utils.o \ - dictionary.o flags.o time.o + dictionary.o options.o time.o gopher: $(OBJS) $(CC) $(LDFLAGS) $(OBJS) $(LDLIBS) -o $@ @@ -22,10 +22,11 @@ connection.o: connection.c connection.h readline2.o: readline2.c readline2.h common.o: common.c -flags.o: flags.c flags.h +options.o: options.c options.h -gopher.o: gopher.c url.h connection.h flags.h -http.o: http.c url.h connection.h flags.h + +gopher.o: gopher.c url.h connection.h options.h +http.o: http.c url.h connection.h options.h http.utils.o: http.utils.c data.o: data.c data.h diff --git a/options.c b/options.c index a202258..8440890 100644 --- a/options.c +++ b/options.c @@ -9,6 +9,9 @@ #include "options.h" extern void help(void); + extern void version(void); + /* global */ + struct Options flags; int GetOptions(int argc, char **argv, struct Options *options) @@ -53,10 +56,17 @@ int GetOptions(int argc, char **argv, case '0': options->_0 = 1; options->_1 = 0; + options->_9 = 0; break; case '1': options->_1 = 1; options->_0 = 0; + options->_9 = 0; + break; + case '9': + options->_9 = 1; + options->_0 = 0; + options->_1 = 0; break; case 'I': options->_I = 1; @@ -64,6 +74,10 @@ int GetOptions(int argc, char **argv, case 'O': options->_O = 1; break; + case 'V': + version(); + exit(0); + break; case 'h': help(); exit(0); diff --git a/options.h b/options.h index 18fd5c4..a103a9c 100644 --- a/options.h +++ b/options.h @@ -5,6 +5,7 @@ typedef struct Options { unsigned _0:1; unsigned _1:1; + unsigned _9:1; unsigned _I:1; unsigned _O:1; unsigned _i:1; diff --git a/options.text b/options.text index 8420541..b02c6d1 100644 --- a/options.text +++ b/options.text @@ -4,15 +4,25 @@ %extra_includes -> extern void help(void); + extern void version(void); + /* global */ + struct Options flags; + + -h [virtual] -> help(); exit(0); +-V [virtual] -> + version(); + exit(0); + # -o specifies the output name # -O gets the name from the URL. -o: -> options->_O = 0; + -O -i @@ -20,8 +30,15 @@ -v # -[0|1] -- set HTTP version. + -0 -> options->_1 = 0; + options->_9 = 0; -1 -> - options->_0 = 0; \ No newline at end of file + options->_0 = 0; + options->_9 = 0; + +-9 -> + options->_0 = 0; + options->_1 = 0; diff --git a/prototypes.h b/prototypes.h index 78eb3c2..1edc9af 100644 --- a/prototypes.h +++ b/prototypes.h @@ -59,5 +59,8 @@ void tiTimeRec2ISO8601(const TimeRecPtr t, char *str); void tiTimeRec2GMTString(const TimeRecPtr t, char *str); #endif +#ifdef __Options__ +extern struct Options flags; +#endif #endif