You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by pq...@apache.org on 2009/02/15 10:06:31 UTC
svn commit: r744637 - /labs/orthrus/trunk/src/ui/ortcalc/ortcalc.c
Author: pquerna
Date: Sun Feb 15 09:06:31 2009
New Revision: 744637
URL: http://svn.apache.org/viewvc?rev=744637&view=rev
Log:
Add basic argv parsing.
Modified:
labs/orthrus/trunk/src/ui/ortcalc/ortcalc.c
Modified: labs/orthrus/trunk/src/ui/ortcalc/ortcalc.c
URL: http://svn.apache.org/viewvc/labs/orthrus/trunk/src/ui/ortcalc/ortcalc.c?rev=744637&r1=744636&r2=744637&view=diff
==============================================================================
--- labs/orthrus/trunk/src/ui/ortcalc/ortcalc.c (original)
+++ labs/orthrus/trunk/src/ui/ortcalc/ortcalc.c Sun Feb 15 09:06:31 2009
@@ -15,9 +15,12 @@
*/
#include "orthrus.h"
+#include "orthrus_version.h"
+
#include "apr_file_io.h"
#include "apr_lib.h"
#include "apr_strings.h"
+#include "apr_getopt.h"
#if APR_HAVE_STDLIB_H
#include <stdlib.h> /* for atexit() */
@@ -63,7 +66,10 @@
{
apr_file_printf(oc->errfile,
"%s -- Program to calculate OTP responses" NL
- "Usage: %s [-V] [challenge]"
+ "Usage: %s [-Vh] [sequence] [seed]"
+ ""NL
+ " -V Print version information and exit." NL
+ " -h Print help text and exit." NL
""NL,
oc->shortname,
oc->shortname);
@@ -71,6 +77,10 @@
int main(int argc, const char * const argv[])
{
+ int optoff = 0;
+ apr_getopt_t *opt;
+ const char *optarg;
+ char ch;
orthrus_response_t *reply;
ortcalc_t oc;
apr_status_t rv = APR_SUCCESS;
@@ -111,13 +121,45 @@
return 1;
}
- /* TODO: Parse Argv in more detail */
- if (argc != 3) {
+ rv = apr_getopt_init(&opt, oc.pool, argc, argv);
+
+ if (rv != APR_SUCCESS) {
+ apr_file_printf(oc.errfile, "apr_getopt_init failed."NL );
+ return 1;
+ }
+
+ if (argc <= 1) {
+ usage(&oc);
+ return 1;
+ }
+
+ opt->interleave = 1;
+
+ while ((rv = apr_getopt(opt, "Vvh", &ch, &optarg)) == APR_SUCCESS) {
+ switch (ch) {
+ case 'V':
+ apr_file_printf(oc.outfile, "%s %s" NL, oc.shortname, ORTHRUS_VERSION_STRING);
+ return 0;
+ case 'h':
+ usage(&oc);
+ return 0;
+ }
+ }
+
+ if (rv != APR_EOF) {
+ apr_file_printf(oc.errfile, "Error: Parsing Arguments Failed" NL NL);
+ usage(&oc);
+ return 1;
+ }
+
+ if (argc - opt->ind != 2) {
+ apr_file_printf(oc.errfile, "Error: Expected sequence and seed, but none found" NL NL);
usage(&oc);
return 1;
}
- oc.num = apr_atoi64(argv[1]);
- oc.seed = apr_pstrdup(oc.pool, argv[2]);
+
+ oc.num = apr_atoi64(opt->argv[opt->ind]);
+ oc.seed = apr_pstrdup(oc.pool, opt->argv[opt->ind+1]);
err = acquire_password(&oc);
if (err) {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org