Commit 2e2a2e81 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Cleanup around arg processing. Need to think a bit more about

usage strings, before I continue.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4953 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent ffc2d2fc
......@@ -244,7 +244,7 @@ main(int argc, char * const *argv)
if (n_arg != NULL) {
vsd = VSM_New();
assert(VSL_Log_Arg(vsd, 'n', n_arg));
assert(VSL_Arg(vsd, 'n', n_arg));
if (!VSM_Open(vsd, 1)) {
if (T_arg == NULL) {
p = VSM_Find_Chunk(vsd, "Arg", "-T", "", NULL);
......
......@@ -324,7 +324,7 @@ main(int argc, char **argv)
vd = VSM_New();
VSL_Setup(vd);
while ((o = getopt(argc, argv, VSL_LOG_ARGS "Vw:")) != -1) {
while ((o = getopt(argc, argv, VSL_ARGS "Vw:")) != -1) {
switch (o) {
case 'V':
varnish_version("varnishhist");
......@@ -333,7 +333,7 @@ main(int argc, char **argv)
delay = atoi(optarg);
break;
default:
if (VSL_Log_Arg(vd, o, optarg) > 0)
if (VSL_Arg(vd, o, optarg) > 0)
break;
usage();
}
......
......@@ -320,18 +320,18 @@ main(int argc, char * const *argv)
vd = VSM_New();
VSL_Setup(vd);
while ((c = getopt(argc, argv, VSL_LOG_ARGS "aDoP:uVw:")) != -1) {
while ((c = getopt(argc, argv, VSL_ARGS "aDoP:uVw:")) != -1) {
switch (c) {
case 'a':
a_flag = 1;
break;
case 'b':
b_flag = 1;
AN(VSL_Log_Arg(vd, c, optarg));
AN(VSL_Arg(vd, c, optarg));
break;
case 'c':
c_flag = 1;
AN(VSL_Log_Arg(vd, c, optarg));
AN(VSL_Arg(vd, c, optarg));
break;
case 'D':
D_flag = 1;
......@@ -352,7 +352,7 @@ main(int argc, char * const *argv)
w_arg = optarg;
break;
default:
if (VSL_Log_Arg(vd, c, optarg) > 0)
if (VSL_Arg(vd, c, optarg) > 0)
break;
usage();
}
......
......@@ -530,7 +530,7 @@ main(int argc, char *argv[])
vd = VSM_New();
VSL_Setup(vd);
while ((c = getopt(argc, argv, VSL_LOG_ARGS "aDP:Vw:f")) != -1) {
while ((c = getopt(argc, argv, VSL_ARGS "aDP:Vw:f")) != -1) {
switch (c) {
case 'a':
a_flag = 1;
......@@ -558,13 +558,13 @@ main(int argc, char *argv[])
/* XXX: Silently ignored: it's required anyway */
break;
default:
if (VSL_Log_Arg(vd, c, optarg) > 0)
if (VSL_Arg(vd, c, optarg) > 0)
break;
usage();
}
}
VSL_Log_Arg(vd, 'c', optarg);
VSL_Arg(vd, 'c', optarg);
if (VSL_Open(vd, 1))
exit(1);
......
......@@ -724,7 +724,7 @@ main(int argc, char *argv[])
VSL_Setup(vd);
debug = 0;
VSL_Log_Arg(vd, 'c', NULL);
VSL_Arg(vd, 'c', NULL);
while ((c = getopt(argc, argv, "a:Dr:n:")) != -1) {
switch (c) {
case 'a':
......@@ -734,7 +734,7 @@ main(int argc, char *argv[])
++debug;
break;
default:
if (VSL_Log_Arg(vd, c, optarg) > 0)
if (VSL_Arg(vd, c, optarg) > 0)
break;
usage();
}
......
......@@ -325,7 +325,7 @@ main(int argc, char **argv)
vd = VSM_New();
VSL_Setup(vd);
while ((o = getopt(argc, argv, VSL_LOG_ARGS "Vw:")) != -1) {
while ((o = getopt(argc, argv, VSL_ARGS "Vw:")) != -1) {
switch (o) {
case 'V':
varnish_version("varnishsizes");
......@@ -334,7 +334,7 @@ main(int argc, char **argv)
delay = atoi(optarg);
break;
default:
if (VSL_Log_Arg(vd, o, optarg) > 0)
if (VSL_Arg(vd, o, optarg) > 0)
break;
usage();
}
......
......@@ -169,7 +169,9 @@ usage(void)
{
#define FMT " %-28s # %s\n"
fprintf(stderr, "usage: varnishstat "
"[-1lV] [-f field_list] [-n varnish_name] [-w delay]\n");
"[-1lV] [-f field_list] "
VSC_n_USAGE " "
"[-w delay]\n");
fprintf(stderr, FMT, "-1", "Print the statistics once and exit");
fprintf(stderr, FMT, "-f field_list",
"Comma separated list of fields to display. ");
......@@ -199,7 +201,7 @@ main(int argc, char * const *argv)
vd = VSM_New();
VSC_Setup(vd);
while ((c = getopt(argc, argv, VSL_STAT_ARGS "1f:lVw:x")) != -1) {
while ((c = getopt(argc, argv, VSC_ARGS "1f:lVw:x")) != -1) {
switch (c) {
case '1':
once = 1;
......
......@@ -361,7 +361,7 @@ varnish_launch(struct varnish *v)
vtc_log(v->vl, 0, "CLI auth command failed: %u %s", u, r);
free(r);
(void)VSL_Log_Arg(v->vd, 'n', v->workdir);
(void)VSL_Arg(v->vd, 'n', v->workdir);
AZ(VSC_Open(v->vd, 1));
}
......
......@@ -310,10 +310,10 @@ main(int argc, char **argv)
vd = VSM_New();
VSL_Setup(vd);
while ((o = getopt(argc, argv, VSL_LOG_ARGS "1fV")) != -1) {
while ((o = getopt(argc, argv, VSL_ARGS "1fV")) != -1) {
switch (o) {
case '1':
AN(VSL_Log_Arg(vd, 'd', NULL));
AN(VSL_Arg(vd, 'd', NULL));
once = 1;
break;
case 'f':
......@@ -323,7 +323,7 @@ main(int argc, char **argv)
varnish_version("varnishtop");
exit(0);
default:
if (VSL_Log_Arg(vd, o, optarg) > 0)
if (VSL_Arg(vd, o, optarg) > 0)
break;
usage();
}
......
......@@ -66,6 +66,8 @@ void VSM_Diag(struct VSM_data *vd, vsm_diag_f *func, void *priv);
* If func is NULL, diagnostics are disabled.
*/
#define VSM_n_USAGE "[-n varnish_name]"
int VSM_n_Arg(struct VSM_data *vd, const char *n_arg);
/*
* Configure which varnishd instance to access.
......@@ -148,6 +150,10 @@ void VSC_Setup(struct VSM_data *vd);
* Setup vd for use with VSC functions.
*/
#define VSC_ARGS "L:n:"
#define VSC_n_USAGE VSM_n_USAGE
#define VSC_USAGE VSC_N_USAGE
int VSC_Arg(struct VSM_data *vd, int arg, const char *opt);
/*
* Handle standard stat-presenter arguments
......@@ -204,22 +210,48 @@ int VSL_Open(struct VSM_data *vd, int diag);
* != 0 on failure
*/
#define VSL_ARGS "bCcdI:i:k:L:n:r:s:X:x:"
#define VSL_b_USAGE "[-b]"
#define VSL_c_USAGE "[-c]"
#define VSL_C_USAGE "[-C]"
#define VSL_d_USAGE "[-d]"
#define VSL_i_USAGE "[-i tag]"
#define VSL_I_USAGE "[-I regexp]"
#define VSL_k_USAGE "[-k keep]"
#define VSL_n_USAGE VSM_n_USAGE
#define VSL_r_USAGE "[-r file]"
#define VSL_s_USAGE "[-s skip]"
#define VSL_x_USAGE "[-x tag]"
#define VSL_X_USAGE "[-X regexp]"
#define VSL_USAGE "[-bCcd] " \
VSL_i_USAGE " " \
VSL_I_USAGE " " \
VSL_k_USAGE " " \
VSL_n_USAGE " " \
VSL_r_USAGE " " \
VSL_s_USAGE " " \
VSL_X_USAGE " " \
VSL_x_USAGE
int VSL_Arg(struct VSM_data *vd, int arg, const char *opt);
/*
* Handle standard log-presenter arguments
* Return:
* -1 error
* 0 not handled
* 1 Handled.
*/
typedef int vsl_handler(void *priv, enum vsl_tag tag, unsigned fd,
unsigned len, unsigned spec, const char *ptr);
#define VSL_S_CLIENT (1 << 0)
#define VSL_S_BACKEND (1 << 1)
#define VSL_LOG_ARGS "bCcdI:i:k:L:n:r:s:X:x:"
#define VSL_STAT_ARGS "L:n:"
#define VSL_USAGE "[-bCcd] [-i tag] [-I regexp] [-k keep]" \
" [-r file] [-s skip] [-X regexp] [-x tag]"
vsl_handler VSL_H_Print;
struct VSM_data;
void VSL_Select(const struct VSM_data *vd, unsigned tag);
void VSL_NonBlocking(const struct VSM_data *vd, int nb);
int VSL_Dispatch(const struct VSM_data *vd, vsl_handler *func, void *priv);
int VSL_NextLog(const struct VSM_data *lh, uint32_t **pp);
int VSL_Log_Arg(struct VSM_data *vd, int arg, const char *opt);
extern const char *VSL_tags[256];
......
......@@ -192,7 +192,7 @@ vsl_k_arg(const struct VSM_data *vd, const char *opt)
/*--------------------------------------------------------------------*/
int
VSL_Log_Arg(struct VSM_data *vd, int arg, const char *opt)
VSL_Arg(struct VSM_data *vd, int arg, const char *opt)
{
CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment