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 "url.h"
|
||||||
#include "connection.h"
|
#include "connection.h"
|
||||||
#include "readline2.h"
|
#include "readline2.h"
|
||||||
#include "prototypes.h"
|
#include "options.h"
|
||||||
#include "flags.h"
|
|
||||||
|
|
||||||
#include "s16debug.h"
|
#include "s16debug.h"
|
||||||
|
|
||||||
|
#include "prototypes.h"
|
||||||
|
|
||||||
static FileInfoRecGS FileInfo;
|
static FileInfoRecGS FileInfo;
|
||||||
static Word FileAttr;
|
static Word FileAttr;
|
||||||
|
|
||||||
|
|
5
http.c
5
http.c
|
@ -32,13 +32,14 @@
|
||||||
|
|
||||||
#include "url.h"
|
#include "url.h"
|
||||||
#include "connection.h"
|
#include "connection.h"
|
||||||
#include "prototypes.h"
|
|
||||||
#include "dictionary.h"
|
#include "dictionary.h"
|
||||||
#include "flags.h"
|
#include "options.h"
|
||||||
#include "readline2.h"
|
#include "readline2.h"
|
||||||
#include "http.utils.h"
|
#include "http.utils.h"
|
||||||
#include "s16debug.h"
|
#include "s16debug.h"
|
||||||
|
|
||||||
|
#include "prototypes.h"
|
||||||
|
|
||||||
|
|
||||||
static FileInfoRecGS FileInfo;
|
static FileInfoRecGS FileInfo;
|
||||||
static Word FileAttr;
|
static Word FileAttr;
|
||||||
|
|
40
main.c
40
main.c
|
@ -11,8 +11,9 @@
|
||||||
|
|
||||||
#include "url.h"
|
#include "url.h"
|
||||||
#include "connection.h"
|
#include "connection.h"
|
||||||
|
#include "options.h"
|
||||||
|
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
#include "flags.h"
|
|
||||||
|
|
||||||
// startup/shutdown flags.
|
// startup/shutdown flags.
|
||||||
enum {
|
enum {
|
||||||
|
@ -171,6 +172,30 @@ char *get_url_filename(const char *cp, URLComponents *components)
|
||||||
return out;
|
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)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
@ -180,14 +205,11 @@ int main(int argc, char **argv)
|
||||||
int x;
|
int x;
|
||||||
|
|
||||||
|
|
||||||
x = ParseFlags(argc, argv);
|
memset(&flags, 0, sizeof(flags));
|
||||||
if (x < 0) return 1;
|
argc = GetOptions(argc, argv, &flags);
|
||||||
|
|
||||||
argv += x;
|
|
||||||
argc -= x;
|
|
||||||
|
|
||||||
|
|
||||||
if (argc != 1)
|
if (argc != 2)
|
||||||
{
|
{
|
||||||
help();
|
help();
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -216,12 +238,12 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (argc == 1)
|
if (argc == 2)
|
||||||
{
|
{
|
||||||
const char *url;
|
const char *url;
|
||||||
URLComponents components;
|
URLComponents components;
|
||||||
|
|
||||||
url = *argv;
|
url = argv[1];
|
||||||
|
|
||||||
if (!ParseURL(url, strlen(url), &components))
|
if (!ParseURL(url, strlen(url), &components))
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
CFLAGS += $(DEFINES) -v -w
|
CFLAGS += $(DEFINES) -v -w
|
||||||
OBJS = main.o gopher.o url.o connection.o readline2.o scheme.o ftype.o \
|
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 \
|
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)
|
gopher: $(OBJS)
|
||||||
$(CC) $(LDFLAGS) $(OBJS) $(LDLIBS) -o $@
|
$(CC) $(LDFLAGS) $(OBJS) $(LDLIBS) -o $@
|
||||||
|
@ -22,10 +22,11 @@ connection.o: connection.c connection.h
|
||||||
readline2.o: readline2.c readline2.h
|
readline2.o: readline2.c readline2.h
|
||||||
common.o: common.c
|
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
|
http.utils.o: http.utils.c
|
||||||
|
|
||||||
data.o: data.c data.h
|
data.o: data.c data.h
|
||||||
|
|
14
options.c
14
options.c
|
@ -9,6 +9,9 @@
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
|
|
||||||
extern void help(void);
|
extern void help(void);
|
||||||
|
extern void version(void);
|
||||||
|
/* global */
|
||||||
|
struct Options flags;
|
||||||
|
|
||||||
int GetOptions(int argc, char **argv,
|
int GetOptions(int argc, char **argv,
|
||||||
struct Options *options)
|
struct Options *options)
|
||||||
|
@ -53,10 +56,17 @@ int GetOptions(int argc, char **argv,
|
||||||
case '0':
|
case '0':
|
||||||
options->_0 = 1;
|
options->_0 = 1;
|
||||||
options->_1 = 0;
|
options->_1 = 0;
|
||||||
|
options->_9 = 0;
|
||||||
break;
|
break;
|
||||||
case '1':
|
case '1':
|
||||||
options->_1 = 1;
|
options->_1 = 1;
|
||||||
options->_0 = 0;
|
options->_0 = 0;
|
||||||
|
options->_9 = 0;
|
||||||
|
break;
|
||||||
|
case '9':
|
||||||
|
options->_9 = 1;
|
||||||
|
options->_0 = 0;
|
||||||
|
options->_1 = 0;
|
||||||
break;
|
break;
|
||||||
case 'I':
|
case 'I':
|
||||||
options->_I = 1;
|
options->_I = 1;
|
||||||
|
@ -64,6 +74,10 @@ int GetOptions(int argc, char **argv,
|
||||||
case 'O':
|
case 'O':
|
||||||
options->_O = 1;
|
options->_O = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'V':
|
||||||
|
version();
|
||||||
|
exit(0);
|
||||||
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
help();
|
help();
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
|
@ -5,6 +5,7 @@ typedef struct Options
|
||||||
{
|
{
|
||||||
unsigned _0:1;
|
unsigned _0:1;
|
||||||
unsigned _1:1;
|
unsigned _1:1;
|
||||||
|
unsigned _9:1;
|
||||||
unsigned _I:1;
|
unsigned _I:1;
|
||||||
unsigned _O:1;
|
unsigned _O:1;
|
||||||
unsigned _i:1;
|
unsigned _i:1;
|
||||||
|
|
19
options.text
19
options.text
|
@ -4,15 +4,25 @@
|
||||||
|
|
||||||
%extra_includes ->
|
%extra_includes ->
|
||||||
extern void help(void);
|
extern void help(void);
|
||||||
|
extern void version(void);
|
||||||
|
/* global */
|
||||||
|
struct Options flags;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-h [virtual] ->
|
-h [virtual] ->
|
||||||
help();
|
help();
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
||||||
|
-V [virtual] ->
|
||||||
|
version();
|
||||||
|
exit(0);
|
||||||
|
|
||||||
# -o specifies the output name
|
# -o specifies the output name
|
||||||
# -O gets the name from the URL.
|
# -O gets the name from the URL.
|
||||||
-o: ->
|
-o: ->
|
||||||
options->_O = 0;
|
options->_O = 0;
|
||||||
|
|
||||||
-O
|
-O
|
||||||
|
|
||||||
-i
|
-i
|
||||||
|
@ -20,8 +30,15 @@
|
||||||
-v
|
-v
|
||||||
|
|
||||||
# -[0|1] -- set HTTP version.
|
# -[0|1] -- set HTTP version.
|
||||||
|
|
||||||
-0 ->
|
-0 ->
|
||||||
options->_1 = 0;
|
options->_1 = 0;
|
||||||
|
options->_9 = 0;
|
||||||
|
|
||||||
-1 ->
|
-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);
|
void tiTimeRec2GMTString(const TimeRecPtr t, char *str);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __Options__
|
||||||
|
extern struct Options flags;
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue