[Git][NTPsec/ntpsec][master] ntpfrob: Add -h and -? options.

Gary E. Miller gitlab at mg.gitlab.com
Tue Nov 15 02:20:03 UTC 2016


Gary E. Miller pushed to branch master at NTPsec / ntpsec


Commits:
8a45f238 by Gary E. Miller at 2016-11-14T18:19:30-08:00
ntpfrob: Add -h and -? options.

- - - - -


2 changed files:

- docs/includes/ntpfrob-body.txt
- ntpfrob/main.c


Changes:

=====================================
docs/includes/ntpfrob-body.txt
=====================================
--- a/docs/includes/ntpfrob-body.txt
+++ b/docs/includes/ntpfrob-body.txt
@@ -5,7 +5,8 @@
 [[synop]]
 == Synopsis ==
 
-+ntpfrob+ [ +-A+] [+-b+ 'bump'] [ +-a+ 'tick' ] [ +-p+ 'ppsdev' ] [+-c+] [+-e+] [+-r+]
++ntpfrob+ [ +-A+] [+-b+ 'bump'] [ +-a+ 'tick' ] [ +-p+ 'ppsdev' ] [+-c+]
+[+-e+] [+-r+] [+-?+] [+-h+]
 
 [[descr]]
 == Description ==
@@ -36,6 +37,10 @@ utilities.
 +-r+::
   Raw mode.  Only applies to the jitter mode, and means the raw
   clock samples should be emitted to stdout for postanalysis.
++-?+::
+  Print sueage and exit.
++-h+::
+  Print sueage and exit.
 
 [[usage]]
 == Usage ==


=====================================
ntpfrob/main.c
=====================================
--- a/ntpfrob/main.c
+++ b/ntpfrob/main.c
@@ -10,12 +10,33 @@
 #include "config.h"
 #include "ntpfrob.h"
 
+void usage(void)
+{
+	fputs(
+"usage:\n"
+"ntpfrob [ -A] [-b bump] [ -a tick ] [ -p ppsdev ] [-c] [-e] [-r] {-h] [-?]\n"
+"        -a tick    Set kernel tick\n"
+"        -A         Display kernel tick\n"
+"        -b bump    Bump clock by specified microseconds.\n"
+"        -c         Compute and display clock jitter.\n"
+"        -e         Measure clock precision.\n"
+"        -j         Report in self-describing JSON.\n"
+"        -p ppsdev  Look for PPS pulses on a specified device\n"
+"        -r         Raw mode. Only applies to the jitter mode.\n"
+"        -?         Print usage\n"
+"        -h         Print usage\n"
+    , stderr);
+
+}
+
 int
 main(int argc, char **argv)
 {
 	int ch;
+        bool got_one = false;
 	iomode mode = plain_text;
-	while ((ch = getopt(argc, argv, "a:Ab:cejp:r")) != EOF) {
+	while ((ch = getopt(argc, argv, "a:Ab:cejp:rh?")) != EOF) {
+                got_one = true;
 		switch (ch) {
 		case 'A':
 		    tickadj(mode==json, 0);
@@ -50,10 +71,19 @@ main(int argc, char **argv)
 		    break;
 		default:
 		    fputs("ntpfrob: no mode option specified.\n", stderr);
+                    /* fall through */
+                case 'h':
+                case '?':
+                    usage();
 		    exit(1);
 		    break;
 		}
 	}
+        if ( !got_one ) {
+	    fputs("ntpfrob: no mode option specified.\n", stderr);
+	    usage();
+	    exit(1);
+        }
 
     exit(0);
 }



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/8a45f2385f2eb6b87213e8f94717e0d09593807b
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20161115/46d8bb5d/attachment.html>


More information about the vc mailing list