From 228e9c8a211e30f5af897b0d78c166a201600d40 Mon Sep 17 00:00:00 2001 From: Love Hornquist Astrand Date: Sun, 22 Nov 2009 07:14:32 -0800 Subject: [PATCH] add useage --- lib/ipc/tc.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/lib/ipc/tc.c b/lib/ipc/tc.c index d976e8fac..be686cdcb 100644 --- a/lib/ipc/tc.c +++ b/lib/ipc/tc.c @@ -34,11 +34,30 @@ */ #include +#include #include #include #include +#include #include +#include +static int help_flag; +static int version_flag; + +static struct getargs args[] = { + { "help", 'h', arg_flag, &help_flag }, + { "version", 'v', arg_flag, &version_flag } +}; + +static int num_args = sizeof(args) / sizeof(args[0]); + +static void +usage(int ret) +{ + arg_printusage (args, num_args, NULL, ""); + exit (ret); +} static void reply(void *ctx, int errorcode, heim_idata *reply, heim_icred cred) @@ -47,13 +66,27 @@ reply(void *ctx, int errorcode, heim_idata *reply, heim_icred cred) heim_ipc_semaphore_signal((heim_isemaphore)ctx); /* tell caller we are done */ } + int main(int argc, char **argv) { + int ret, optidx = 0; heim_isemaphore s; heim_idata req, rep; heim_ipc ipc; - int ret; + + setprogname(argv[0]); + + if (getarg(args, num_args, argc, argv, &optidx)) + usage(1); + + if (help_flag) + usage(0); + + if (version_flag) { + print_version(NULL); + exit(0); + } ret = heim_ipc_init_context("ANY:org.h5l.test-ipc", &ipc); if (ret)