mirror of
https://github.com/ksherlock/gopher.git
synced 2025-04-29 04:37:42 +00:00
replace flags with options
This commit is contained in:
parent
58df66cc71
commit
cd55a2de3b
6
gopher.c
6
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;
|
||||
|
||||
|
5
http.c
5
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;
|
||||
|
40
main.c
40
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))
|
||||
{
|
||||
|
@ -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
|
||||
|
14
options.c
14
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);
|
||||
|
@ -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;
|
||||
|
19
options.text
19
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;
|
||||
options->_0 = 0;
|
||||
options->_9 = 0;
|
||||
|
||||
-9 ->
|
||||
options->_0 = 0;
|
||||
options->_1 = 0;
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user