Adding additional command line flags for help and version.
This commit is contained in:
parent
d1fca80734
commit
39b8fb640f
5 changed files with 54 additions and 9 deletions
8
Makefile
8
Makefile
|
|
@ -15,11 +15,11 @@ install : $(PROGRAMS)
|
|||
cp $^ $(HOME)/bin/
|
||||
|
||||
dlight : dlight.o buffer.o env.o http.o rss.o lockfile.o filter.o cconf.o \
|
||||
proc-cache.o dlhist.o hash.o xalloc.o error.o utils.o
|
||||
proc-cache.o dlhist.o hash.o xalloc.o error.o utils.o version.o
|
||||
dlight-compile : compile.o buffer.o env.o lockfile.o filter.o cconf.o \
|
||||
error.o
|
||||
dlight-read-config : read-config.o buffer.o env.o cconf.o error.o
|
||||
dlight-filter-check: filter-check.o filter.o error.o
|
||||
error.o version.o
|
||||
dlight-read-config : read-config.o buffer.o env.o cconf.o error.o version.o
|
||||
dlight-filter-check: filter-check.o filter.o error.o version.o
|
||||
|
||||
dlight-% : %.o
|
||||
$(CC) $(LDFLAGS) -o $@ $^
|
||||
|
|
|
|||
13
compile.c
13
compile.c
|
|
@ -31,6 +31,7 @@
|
|||
#include "cconf.h"
|
||||
#include "lockfile.h"
|
||||
#include "filter.h"
|
||||
#include "version.h"
|
||||
|
||||
#define isalias(x) (isalnum(x) || (x) == '-')
|
||||
|
||||
|
|
@ -303,6 +304,18 @@ int main(int argc, char **argv) {
|
|||
struct lockfile lock = LOCKFILE_INIT;
|
||||
char filename[4096];
|
||||
|
||||
if (argc > 1) {
|
||||
if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "-help")) {
|
||||
printf("dlight compiler\n");
|
||||
printf("%s [--help|-h|--version|-v]\n", argv[0]);
|
||||
} else if (!strcmp(argv[1], "-v")
|
||||
|| !strcmp(argv[1], "--version")) {
|
||||
printf("Version: %s\n",
|
||||
dlight_version_str);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
snprintf(filename, sizeof(filename), "%s/%s",
|
||||
env_get_dir(), "config");
|
||||
|
||||
|
|
|
|||
12
dlight.c
12
dlight.c
|
|
@ -14,6 +14,7 @@
|
|||
#include "filter.h"
|
||||
#include "http.h"
|
||||
#include "rss.h"
|
||||
#include "version.h"
|
||||
|
||||
#define PROC_CACHE_PURGE_INTERVAL (60*60*6) /* 6 hours (in seconds) */
|
||||
#define DLHIST_PURGE_INTERVAL (60*60*24) /* 1 day */
|
||||
|
|
@ -103,6 +104,17 @@ int main(int argc, char *argv[]) {
|
|||
struct cconf *config;
|
||||
char configfile[4096];
|
||||
|
||||
if (argc > 1) {
|
||||
if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "-help")) {
|
||||
printf("%s [--help|-h|--version|-v]\n", argv[0]);
|
||||
} else if (!strcmp(argv[1], "-v")
|
||||
|| !strcmp(argv[1], "--version")) {
|
||||
printf("dlight version %s\n",
|
||||
dlight_version_str);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
snprintf(configfile, sizeof(configfile), "%s/%s",
|
||||
env_get_dir(), "config");
|
||||
|
||||
|
|
|
|||
|
|
@ -20,13 +20,26 @@
|
|||
#include <stdio.h>
|
||||
#include "error.h"
|
||||
#include "filter.h"
|
||||
#include "version.h"
|
||||
|
||||
const char *usagestr = "dlight-filter-check <pattern> <subject>";
|
||||
const char *usagestr =
|
||||
"dlight-filter-check [ --help | -h | --version | -v ] "
|
||||
"| [ <pattern> <subject> ]";
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
if (argc < 3)
|
||||
if (argc > 1) {
|
||||
if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "-help")) {
|
||||
usage(usagestr);
|
||||
} else if (!strcmp(argv[1], "-v")
|
||||
|| !strcmp(argv[1], "--version")) {
|
||||
printf("Version: %s\n",
|
||||
dlight_version_str);
|
||||
return 0;
|
||||
}
|
||||
} else if (argc < 3) {
|
||||
usage(usagestr);
|
||||
}
|
||||
|
||||
if (!filter_check_syntax(argv[1]))
|
||||
return 0;
|
||||
|
|
@ -37,4 +50,4 @@ int main(int argc, char **argv) {
|
|||
puts("nomatch");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,8 +23,10 @@
|
|||
#include "cconf.h"
|
||||
#include "env.h"
|
||||
#include "error.h"
|
||||
#include "version.h"
|
||||
|
||||
static char *usagestr = "dlight-read-config [ <file> | -h ]";
|
||||
static char *usagestr =
|
||||
"dlight-read-config [ --help | -h | --version | -v ] [ <file> ]";
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
|
|
@ -33,8 +35,13 @@ int main(int argc, char **argv) {
|
|||
char file[4096];
|
||||
|
||||
if (argc > 1) {
|
||||
if (!strcmp(argv[1], "-h")) {
|
||||
if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "-help")) {
|
||||
usage(usagestr);
|
||||
} else if (!strcmp(argv[1], "-v")
|
||||
|| !strcmp(argv[1], "--version")) {
|
||||
printf("Version: %s\n",
|
||||
dlight_version_str);
|
||||
return 0;
|
||||
}
|
||||
strncpy(file, argv[1], sizeof(file));
|
||||
} else {
|
||||
|
|
|
|||
Reference in a new issue