summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2005-08-25 11:57:52 +0000
committerSascha Hauer <s.hauer@pengutronix.de>2005-08-25 11:57:52 +0000
commit03fa195021ede1cdce8762753d9b62f2f41c1b18 (patch)
tree17ac5cbc25d65ab03e7f4421ef75ba5967c5e1bb
parent930bc0214403d2cfab693f31702211d5efaebb25 (diff)
downloadcanutils-03fa195021ede1cdce8762753d9b62f2f41c1b18.tar.gz
add long options and version information
git-svn-id: https://iocaste.extern.pengutronix.de/svn/canutils/trunks/canutils-1.0-trunk@34 5fd5a299-6ef2-0310-aa18-8b01d7c39d8c
-rw-r--r--candump.c38
1 files changed, 31 insertions, 7 deletions
diff --git a/candump.c b/candump.c
index 797746e..b8ceb8d 100644
--- a/candump.c
+++ b/candump.c
@@ -4,6 +4,7 @@
#include <string.h>
#include <signal.h>
#include <libgen.h>
+#include <getopt.h>
#include <sys/types.h>
#include <sys/socket.h>
@@ -12,18 +13,27 @@
#include <net/if.h>
#include <socket-can/can.h>
+#include <can_config.h>
extern int optind, opterr, optopt;
static int s = -1;
static int running = 1;
+enum
+{
+ VERSION_OPTION = CHAR_MAX + 1,
+};
+
void print_usage(char *prg)
{
- fprintf(stderr, "Usage: %s [can-interface] [Options]\n", prg);
- fprintf(stderr, "Options: -f <family> (default PF_CAN = %d)\n", PF_CAN);
- fprintf(stderr, " -t <type> (default SOCK_RAW = %d)\n", SOCK_RAW);
- fprintf(stderr, " -p <proto> (default CAN_PROTO_RAW = %d)\n", CAN_PROTO_RAW);
+ fprintf(stderr, "Usage: %s <can-interface> [Options]\n"
+ "Options:\n"
+ " -f, --family=FAMILY Protocol family (default PF_CAN = %d)\n"
+ " -t, --type=TYPE Socket type, see man 2 socket (default SOCK_RAW = %d)\n"
+ " -p, --protocol=PROTO CAN protocol (default CAN_PROTO_RAW = %d)\n"
+ " --version print version information and exit\n",
+ prg, PF_CAN, SOCK_RAW, CAN_PROTO_RAW);
}
void sigterm(int signo)
@@ -43,8 +53,21 @@ int main(int argc, char **argv)
signal(SIGTERM, sigterm);
signal(SIGHUP, sigterm);
- while ((opt = getopt(argc, argv, "f:t:p:m:v:")) != -1) {
+ struct option long_options[] = {
+ { "help", no_argument, 0, 'h' },
+ { "family", required_argument, 0, 'f' },
+ { "protocol", required_argument, 0, 'p' },
+ { "type", required_argument, 0, 't' },
+ { "version", no_argument, 0, VERSION_OPTION},
+ { 0, 0, 0, 0},
+ };
+
+ while ((opt = getopt_long(argc, argv, "f:t:p:m:v:", long_options, NULL)) != -1) {
switch (opt) {
+ case 'h':
+ print_usage(basename(argv[0]));
+ exit(0);
+
case 'f':
family = strtoul(optarg, NULL, 0);
break;
@@ -57,8 +80,9 @@ int main(int argc, char **argv)
proto = strtoul(optarg, NULL, 0);
break;
- case '?':
- break;
+ case VERSION_OPTION:
+ printf("canecho %s\n",VERSION);
+ exit(0);
default:
fprintf(stderr, "Unknown option %c\n", opt);