Only describe flags -L and -m in the usage if they are available.

That helps me get rid of some conditional compilation (INET6) in
ifconfig.

Let each protocol/feature-module print its own usage, so that the
ifconfig usage reflects the modules that are actually compiled-in.

Write usage information for carp(4) options.
This commit is contained in:
dyoung 2008-07-15 20:56:13 +00:00
parent 9b5b7fcda3
commit 3e89e7b09b
9 changed files with 154 additions and 45 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: af_inet6.c,v 1.22 2008/07/02 07:44:14 dyoung Exp $ */
/* $NetBSD: af_inet6.c,v 1.23 2008/07/15 20:56:13 dyoung Exp $ */
/*
* Copyright (c) 1983, 1993
@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: af_inet6.c,v 1.22 2008/07/02 07:44:14 dyoung Exp $");
__RCSID("$NetBSD: af_inet6.c,v 1.23 2008/07/15 20:56:13 dyoung Exp $");
#endif /* not lint */
#include <sys/param.h>
@ -73,6 +73,7 @@ static int setia6lifetime(prop_dictionary_t, int64_t, time_t *, uint32_t *);
static void in6_delscopeid(struct sockaddr_in6 *sin6);
static void in6_status(prop_dictionary_t, prop_dictionary_t, bool);
static struct usage_func usage;
static cmdloop_branch_t branch[2];
static const struct kwinst ia6flagskw[] = {
@ -479,12 +480,23 @@ in6_commit_address(prop_dictionary_t env, prop_dictionary_t oenv)
commit_address(env, oenv, &in6param);
}
static void
in6_usage(prop_dictionary_t env)
{
fprintf(stderr,
"\t[ anycast | -anycast ] [ deprecated | -deprecated ]\n"
"\t[ tentative | -tentative ] [ pltime n ] [ vltime n ] "
"[ eui64 ]\n");
}
static void
in6_constructor(void)
{
if (register_flag('L') != 0)
err(EXIT_FAILURE, __func__);
register_family(&in6af);
usage_func_init(&usage, in6_usage);
register_usage(&usage);
cmdloop_branch_init(&branch[0], &ia6flags.pk_parser);
cmdloop_branch_init(&branch[1], &inet6.pk_parser);
register_cmdloop_branch(&branch[0]);

View File

@ -1,4 +1,4 @@
/* $NetBSD: agr.c,v 1.13 2008/07/02 07:44:14 dyoung Exp $ */
/* $NetBSD: agr.c,v 1.14 2008/07/15 20:56:13 dyoung Exp $ */
/*-
* Copyright (c)2005 YAMAMOTO Takashi,
@ -28,7 +28,7 @@
#include <sys/cdefs.h>
#if !defined(lint)
__RCSID("$NetBSD: agr.c,v 1.13 2008/07/02 07:44:14 dyoung Exp $");
__RCSID("$NetBSD: agr.c,v 1.14 2008/07/15 20:56:13 dyoung Exp $");
#endif /* !defined(lint) */
#include <sys/param.h>
@ -174,13 +174,22 @@ again:
}
static status_func_t status;
static usage_func_t usage;
static cmdloop_branch_t branch;
static void
agr_usage(prop_dictionary_t env)
{
fprintf(stderr, "\t[ agrport i ] [ -agrport i ]\n");
}
static void
agr_constructor(void)
{
register_status(&status);
status_func_init(&status, agr_status);
usage_func_init(&usage, agr_usage);
register_status(&status);
register_usage(&usage);
cmdloop_branch_init(&branch, &agr.pk_parser);
register_cmdloop_branch(&branch);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: carp.c,v 1.10 2008/07/02 07:44:14 dyoung Exp $ */
/* $NetBSD: carp.c,v 1.11 2008/07/15 20:56:13 dyoung Exp $ */
/*
* Copyright (c) 2002 Michael Shalayeff. All rights reserved.
@ -28,7 +28,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: carp.c,v 1.10 2008/07/02 07:44:14 dyoung Exp $");
__RCSID("$NetBSD: carp.c,v 1.11 2008/07/15 20:56:13 dyoung Exp $");
#endif /* not lint */
#include <sys/param.h>
@ -53,6 +53,7 @@ __RCSID("$NetBSD: carp.c,v 1.10 2008/07/02 07:44:14 dyoung Exp $");
#include "extern.h"
static status_func_t status;
static usage_func_t usage;
static cmdloop_branch_t branch;
static void carp_constructor(void) __attribute__((constructor));
@ -273,11 +274,22 @@ setcarpdev(prop_dictionary_t env, prop_dictionary_t xenv)
return 0;
}
static void
carp_usage(prop_dictionary_t env)
{
fprintf(stderr,
"\t[ advbase n ] [ advskew n ] [ carpdev iface ] "
"[ pass passphrase ] [ state state ] [ vhid n ]\n");
}
static void
carp_constructor(void)
{
cmdloop_branch_init(&branch, &carp.pk_parser);
register_cmdloop_branch(&branch);
status_func_init(&status, carp_status);
usage_func_init(&usage, carp_usage);
register_status(&status);
register_usage(&usage);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: extern.h,v 1.12 2008/07/02 07:44:14 dyoung Exp $ */
/* $NetBSD: extern.h,v 1.13 2008/07/15 20:56:13 dyoung Exp $ */
/*
* Copyright (c) 1983, 1993
@ -39,14 +39,27 @@
#define MASK 2
#define DSTADDR 3
typedef void (*usage_cb_t)(prop_dictionary_t);
typedef void (*status_cb_t)(prop_dictionary_t, prop_dictionary_t);
typedef void (*statistics_cb_t)(prop_dictionary_t);
enum flag_type {
FLAG_T_MOD = 0
, FLAG_T_CMD = 1
};
typedef enum flag_type flag_type_t;
struct statistics_func {
SIMPLEQ_ENTRY(statistics_func) f_next;
statistics_cb_t f_func;
};
struct usage_func {
SIMPLEQ_ENTRY(usage_func) f_next;
usage_cb_t f_func;
};
struct status_func {
SIMPLEQ_ENTRY(status_func) f_next;
status_cb_t f_func;
@ -60,6 +73,7 @@ struct cmdloop_branch {
typedef struct statistics_func statistics_func_t;
typedef struct status_func status_func_t;
typedef struct usage_func usage_func_t;
typedef struct cmdloop_branch cmdloop_branch_t;
void cmdloop_branch_init(cmdloop_branch_t *, struct parser *);
@ -67,8 +81,10 @@ int register_family(struct afswtch *);
int register_cmdloop_branch(cmdloop_branch_t *);
void statistics_func_init(statistics_func_t *, statistics_cb_t);
void status_func_init(status_func_t *, status_cb_t);
void usage_func_init(usage_func_t *, usage_cb_t);
int register_statistics(statistics_func_t *);
int register_status(status_func_t *);
int register_usage(usage_func_t *);
int register_flag(int);
bool get_flag(int);

View File

@ -1,4 +1,4 @@
/* $NetBSD: ieee80211.c,v 1.20 2008/07/02 07:44:14 dyoung Exp $ */
/* $NetBSD: ieee80211.c,v 1.21 2008/07/15 20:56:13 dyoung Exp $ */
/*
* Copyright (c) 1983, 1993
@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: ieee80211.c,v 1.20 2008/07/02 07:44:14 dyoung Exp $");
__RCSID("$NetBSD: ieee80211.c,v 1.21 2008/07/15 20:56:13 dyoung Exp $");
#endif /* not lint */
#include <sys/param.h>
@ -1333,9 +1333,20 @@ mappsb(u_int isrfreq, u_int isrflags)
}
static status_func_t status;
static usage_func_t usage;
static statistics_func_t statistics;
static cmdloop_branch_t branch[2];
static void
ieee80211_usage(prop_dictionary_t env)
{
fprintf(stderr,
"\t[ nwid network_id ] [ nwkey network_key | -nwkey ]\n"
"\t[ list scan ]\n"
"\t[ powersave | -powersave ] [ powersavesleep duration ]\n"
"\t[ hidessid | -hidessid ] [ apbridge | -apbridge ]\n");
}
static void
ieee80211_constructor(void)
{
@ -1345,6 +1356,8 @@ ieee80211_constructor(void)
register_cmdloop_branch(&branch[1]);
status_func_init(&status, ieee80211_status);
statistics_func_init(&statistics, ieee80211_statistics);
usage_func_init(&usage, ieee80211_usage);
register_status(&status);
register_statistics(&statistics);
register_usage(&usage);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: ifconfig.c,v 1.208 2008/07/02 07:44:14 dyoung Exp $ */
/* $NetBSD: ifconfig.c,v 1.209 2008/07/15 20:56:13 dyoung Exp $ */
/*-
* Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
@ -63,7 +63,7 @@
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\
The Regents of the University of California. All rights reserved.\n");
__RCSID("$NetBSD: ifconfig.c,v 1.208 2008/07/02 07:44:14 dyoung Exp $");
__RCSID("$NetBSD: ifconfig.c,v 1.209 2008/07/15 20:56:13 dyoung Exp $");
#endif /* not lint */
#include <sys/param.h>
@ -239,6 +239,8 @@ struct paddr broadcast = PADDR_INITIALIZER(&broadcast,
static SIMPLEQ_HEAD(, afswtch) aflist = SIMPLEQ_HEAD_INITIALIZER(aflist);
static SIMPLEQ_HEAD(, usage_func) usage_funcs =
SIMPLEQ_HEAD_INITIALIZER(usage_funcs);
static SIMPLEQ_HEAD(, status_func) status_funcs =
SIMPLEQ_HEAD_INITIALIZER(status_funcs);
static SIMPLEQ_HEAD(, statistics_func) statistics_funcs =
@ -323,10 +325,16 @@ struct piface iface_start = PIFACE_INITIALIZER(&iface_start,
struct piface iface_only = PIFACE_INITIALIZER(&iface_only, "iface",
media_status_exec, "if", NULL);
static int
check_flag(char *flags, int flag)
static bool
flag_is_registered(const char *flags, int flag)
{
if (flags != NULL && strchr(flags, flag) != NULL) {
return flags != NULL && strchr(flags, flag) != NULL;
}
static int
check_flag(const char *flags, int flag)
{
if (flag_is_registered(flags, flag)) {
errno = EEXIST;
return -1;
}
@ -360,6 +368,12 @@ status_func_init(status_func_t *f, status_cb_t func)
f->f_func = func;
}
void
usage_func_init(usage_func_t *f, usage_cb_t func)
{
f->f_func = func;
}
int
register_cmdloop_branch(cmdloop_branch_t *b)
{
@ -381,6 +395,13 @@ register_status(status_func_t *f)
return 0;
}
int
register_usage(usage_func_t *f)
{
SIMPLEQ_INSERT_TAIL(&usage_funcs, f, f_next);
return 0;
}
int
register_family(struct afswtch *af)
{
@ -581,9 +602,7 @@ main(int argc, char **argv)
start = &opt_family_only.pb_parser;
break;
#ifdef INET6
case 'L':
#endif
case 'm':
case 'v':
case 'z':
@ -619,10 +638,8 @@ main(int argc, char **argv)
*/
if ((lflag || Cflag) && (aflag || get_flag('m') || vflag || zflag))
usage();
#ifdef INET6
if ((lflag || Cflag) && get_flag('L'))
usage();
#endif
if (lflag && Cflag)
usage();
@ -1269,35 +1286,34 @@ void
usage(void)
{
const char *progname = getprogname();
usage_func_t *usage_f;
prop_dictionary_t env;
fprintf(stderr,
"usage: %s [-h] [-m] [-v] [-z] "
#ifdef INET6
"[-L] "
#endif
"interface\n"
if ((env = prop_dictionary_create()) == NULL)
err(EXIT_FAILURE, "%s: prop_dictionary_create", __func__);
fprintf(stderr, "usage: %s [-h] %s[-v] [-z] %sinterface\n"
"\t[ af [ address [ dest_addr ] ] [ netmask mask ] [ prefixlen n ]\n"
"\t\t[ alias | -alias ] ]\n"
"\t[ up ] [ down ] [ metric n ] [ mtu n ]\n"
"\t[ nwid network_id ] [ nwkey network_key | -nwkey ]\n"
"\t[ list scan ]\n"
"\t[ powersave | -powersave ] [ powersavesleep duration ]\n"
"\t[ hidessid | -hidessid ] [ apbridge | -apbridge ]\n"
"\t[ [ af ] tunnel src_addr dest_addr ] [ deletetunnel ]\n"
"\t[ up ] [ down ] [ metric n ] [ mtu n ]\n", progname,
flag_is_registered(gflags, 'm') ? "[-m] " : "",
flag_is_registered(gflags, 'L') ? "[-L] " : "");
SIMPLEQ_FOREACH(usage_f, &usage_funcs, f_next)
(*usage_f->f_func)(env);
fprintf(stderr,
"\t[ arp | -arp ]\n"
"\t[ media type ] [ mediaopt opts ] [ -mediaopt opts ] "
"[ instance minst ]\n"
"\t[ preference n ]\n"
"\t[ vlan n vlanif i ]\n"
"\t[ agrport i ] [ -agrport i ]\n"
"\t[ anycast | -anycast ] [ deprecated | -deprecated ]\n"
"\t[ tentative | -tentative ] [ pltime n ] [ vltime n ] [ eui64 ]\n"
"\t[ link0 | -link0 ] [ link1 | -link1 ] [ link2 | -link2 ]\n"
" %s -a [-b] [-h] [-m] [-d] [-u] [-v] [-z] [ af ]\n"
" %s -l [-b] [-d] [-u] [-s]\n"
" %s -a [-b] [-d] [-h] %s[-u] [-v] [-z] [ af ]\n"
" %s -l [-b] [-d] [-s] [-u]\n"
" %s -C\n"
" %s interface create\n"
" %s interface destroy\n",
progname, progname, progname, progname, progname, progname);
progname, flag_is_registered(gflags, 'm') ? "[-m] " : "",
progname, progname, progname, progname);
prop_object_release((prop_object_t)env);
exit(EXIT_FAILURE);
}

View File

@ -1,6 +1,6 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: media.c,v 1.1 2008/07/02 07:44:15 dyoung Exp $");
__RCSID("$NetBSD: media.c,v 1.2 2008/07/15 20:56:13 dyoung Exp $");
#endif /* not lint */
#include <assert.h>
@ -44,6 +44,8 @@ static int media_current;
static int mediaopt_set;
static int mediaopt_clear;
static struct usage_func usage;
static const int ifm_status_valid_list[] = IFM_STATUS_VALID_LIST;
static const struct ifmedia_status_description ifm_status_descriptions[] =
@ -443,9 +445,19 @@ media_status(prop_dictionary_t env, prop_dictionary_t oenv)
free(media_list);
}
static void
media_usage(prop_dictionary_t env)
{
fprintf(stderr,
"\t[ media type ] [ mediaopt opts ] [ -mediaopt opts ] "
"[ instance minst ]\n");
}
static void
media_constructor(void)
{
if (register_flag('m') != 0)
err(EXIT_FAILURE, __func__);
usage_func_init(&usage, media_usage);
register_usage(&usage);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: tunnel.c,v 1.14 2008/07/02 07:44:15 dyoung Exp $ */
/* $NetBSD: tunnel.c,v 1.15 2008/07/15 20:56:13 dyoung Exp $ */
/*
* Copyright (c) 1983, 1993
@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: tunnel.c,v 1.14 2008/07/02 07:44:15 dyoung Exp $");
__RCSID("$NetBSD: tunnel.c,v 1.15 2008/07/15 20:56:13 dyoung Exp $");
#endif /* not lint */
#include <sys/param.h>
@ -59,6 +59,7 @@ __RCSID("$NetBSD: tunnel.c,v 1.14 2008/07/02 07:44:15 dyoung Exp $");
#include "util.h"
static status_func_t status;
static usage_func_t usage;
static cmdloop_branch_t branch;
static void tunnel_constructor(void) __attribute__((constructor));
@ -189,11 +190,20 @@ tunnel_status(prop_dictionary_t env, prop_dictionary_t oenv)
psrcaddr, srcserv, pdstaddr, dstserv);
}
static void
tunnel_usage(prop_dictionary_t env)
{
fprintf(stderr,
"\t[ [ af ] tunnel src_addr dest_addr ] [ deletetunnel ]\n");
}
static void
tunnel_constructor(void)
{
cmdloop_branch_init(&branch, &tunnel.pk_parser);
register_cmdloop_branch(&branch);
status_func_init(&status, tunnel_status);
usage_func_init(&usage, tunnel_usage);
register_status(&status);
register_usage(&usage);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: vlan.c,v 1.10 2008/07/02 07:44:15 dyoung Exp $ */
/* $NetBSD: vlan.c,v 1.11 2008/07/15 20:56:13 dyoung Exp $ */
/*
* Copyright (c) 1983, 1993
@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: vlan.c,v 1.10 2008/07/02 07:44:15 dyoung Exp $");
__RCSID("$NetBSD: vlan.c,v 1.11 2008/07/15 20:56:13 dyoung Exp $");
#endif /* not lint */
#include <sys/param.h>
@ -54,6 +54,7 @@ __RCSID("$NetBSD: vlan.c,v 1.10 2008/07/02 07:44:15 dyoung Exp $");
#include "util.h"
static status_func_t status;
static usage_func_t usage;
static cmdloop_branch_t branch;
static void vlan_constructor(void) __attribute__((constructor));
@ -171,11 +172,19 @@ vlan_status(prop_dictionary_t env, prop_dictionary_t oenv)
"<none>" : vlr.vlr_parent);
}
static void
vlan_usage(prop_dictionary_t env)
{
fprintf(stderr, "\t[ vlan n vlanif i ]\n");
}
static void
vlan_constructor(void)
{
cmdloop_branch_init(&branch, &vlan.pk_parser);
register_cmdloop_branch(&branch);
status_func_init(&status, vlan_status);
usage_func_init(&usage, vlan_usage);
register_status(&status);
register_usage(&usage);
}