Move copyright, version and config file stuff into a common file.
bk: 443c523cCitlkE1q1NBD-TtUc8cZnQ
--- /dev/null
+/* -*- Mode: Text -*- */
+
+autogen definitions options;
+
+/*
+ * $Id: opts.def,v 3.34 2004/10/15 01:48:34 bkorb Exp $
+ *
+ * NTP copyright 1970-2004 Someone
+ *
+ * NTP is free software.
+ * You may redistribute it and/or modify it under the terms of the
+ * GNU General Public License, as published by the Free Software
+ * Foundation; either version 2, or (at your option) any later version.
+ *
+ * AutoGen is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with AutoGen. See the file "COPYING". If not,
+ * write to: The Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+prog-name = "clktest";
+prog-title = "test the clock line discipline";
+argument = '<tty_device>';
+
+#include copyright.def
+
+detail = <<- _EODetail_
+ Clktest can be used to test the clock line discipline (CLKLDISC,
+ it must be available), and to take a look at radio clocks attached
+ to a serial port.
+ _EODetail_;
+
+test-main;
+
+export = <<- _EOExport_
+ #include <stdio.h>
+ #include <ctype.h>
+ #include <sys/types.h>
+ #include <sys/socket.h>
+ #include <signal.h>
+ #include <netinet/in.h>
+ #include <sys/ioctl.h>
+ #include <sys/time.h>
+ #include <sys/file.h>
+ #include <sgtty.h>
+
+ #include "../include/ntp_fp.h"
+ #include "../include/ntp.h"
+ #include "../include/ntp_unixtime.h"
+
+ #ifdef CLKLDISC
+ # define DEFMAGIC '\r'
+ #endif
+
+ #ifdef CLKLDISC
+ # ifdef STREAM
+ # include <stropts.h>
+ # ifdef HAVE_SYS_CLKDEFS_H
+ # include <sys/clkdefs.h>
+ # endif
+ # undef DEFMAGIC
+ # define DEFMAGIC "\r"
+ # endif
+ #endif
+ _EOExport_;
+
+flag = {
+ name = magic2;
+ value = a;
+ arg-type = number;
+ arg-name = kill-code;
+ arg-range = '0->255';
+ descrip = "The 'kill' character (default: '\\r')";
+ ifdef = CLKLDISC;
+ doc = <<- _EndOfDoc_
+ "CLKLDISC" is actually never defined, or you will have compile issues.
+ _EndOfDoc_;
+};
+
+flag = {
+ name = magic1;
+ value = c;
+ arg-type = number;
+ arg-name = erase-code;
+ arg-range = '0->255';
+ descrip = "The 'erase' character (default: '\\r')";
+ ifdef = CLKLDISC;
+ doc = <<- _EndOfDoc_
+ Or maybe the kill or maybe something else.
+ _EndOfDoc_;
+};
+
+extern = <<- _EOExtern_
+ #ifdef STREAM
+ extern char magic[32];
+ #endif
+ _EOExtern_;
+
+include = <<- _EOInclude_
+ #ifdef STREAM
+ char magic[32] = "";
+ #endif
+ _EOInclude_;
+
+flag = {
+ name = magic1;
+ value = c;
+ arg-type = string;
+ arg-name = erase-code;
+ descrip = "Magic characters for streams";
+ ifdef = STREAM;
+ doc = <<- _EndOfDoc_
+ Or maybe the kill or maybe something else.
+ _EndOfDoc_;
+
+ flag-code = <<- _EOCode_
+ unsigned long tmp;
+
+ if (!atouint(pOptDesc->pzLastArg, &tmp)) {
+ fprintf(stderr, "%s error: not a number: ``%s''\n",
+ pOptions->pzProgName, pOptDesc->pzLastArg );
+ USAGE( EXIT_FAILURE );
+ }
+ _EOCode_;
+};
+
+include = 'extern int speed;';
+flag = {
+ name = speed;
+ value = b;
+ arg-type = string;
+ arg-name = bps;
+ descrip = "Set the rate according to the speed";
+ doc = <<- _EndOfDoc_
+ Be careful with this option. It will cause an infinite loop, unless
+ all speeds are unsupported.
+ _EndOfDoc_;
+
+ flag-code = <<- _EOCode_
+ /*
+ * speed table
+ */
+ static struct speeds {
+ const unsigned int bps;
+ const unsigned int rate;
+ } *spd, speedtab[] = {
+ { 300, B300 },
+ { 1200, B1200 },
+ { 2400, B2400 },
+ { 4800, B4800 },
+ { 9600, B9600 },
+ { 19200, EXTA },
+ { 38400, EXTB },
+ { 0, 0 }
+ };
+ unsigned long tmp;
+
+ if (!atouint(pOptDesc->pzLastArg, &tmp)) {
+ fprintf(stderr, "%s error: not a number: ``%s''\n",
+ pOptions->pzProgName, pOptDesc->pzLastArg );
+ USAGE( EXIT_FAILURE );
+ }
+
+ for (spd = speedtab;;) {
+ if (tmp == spd->bps)
+ break;
+ spd++;
+ if (spd->bps == 0) {
+ fprintf(stderr, "%s: speed %lu is unsupported\n",
+ pOptions->pzProgName, tmp);
+ USAGE( EXIT_FAILURE );
+ }
+ }
+
+ speed = spd->rate;
+ _EOCode_;
+};
+
+
+flag = {
+ name = debug;
+ value = d;
+ descrip = "Turn on debugging output";
+ doc = <<- _EndOfDoc_
+ This option is not really used.
+ _EndOfDoc_;
+};
+
+include = 'extern int ttflags;';
+flag = {
+ name = crmod;
+ value = f;
+ descrip = "Turn on CRMOD flag";
+ flag-code = ' ttflags |= CRMOD;';
+ doc = <<- _EndOfDoc_
+
+ _EndOfDoc_;
+};
+
+flag = {
+ name = command;
+ value = s;
+ arg-type = string;
+ arg-name = cmd-name;
+ descrip = "";
+ flags-must= timeout;
+ doc = <<- _EndOfDoc_
+
+ _EndOfDoc_;
+};
+
+flag = {
+ name = timeout;
+ value = t;
+ arg-type = number;
+ arg-name = seconds;
+ arg-range = '1->600'; /* one second to ten minutes */
+ descrip = "Limit wait for command completion";
+ doc = <<- _EndOfDoc_
+
+ _EndOfDoc_;
+};
* usage: clktest -b bps -f -t timeo -s cmd -c char1 -a char2 /dev/whatever
*/
-#include <stdio.h>
-#include <ctype.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <signal.h>
-#include <netinet/in.h>
-#include <sys/ioctl.h>
-#include <sys/time.h>
-#include <sys/file.h>
-#include <sgtty.h>
-
-#include "../include/ntp_fp.h"
-#include "../include/ntp.h"
-#include "../include/ntp_unixtime.h"
+#include "clktest-opts.h"
#define STREQ(a, b) (*(a) == *(b) && strcmp((a), (b)) == 0)
#endif
#ifndef STREAM
-#ifndef CLKLDISC
-CLOCK_LINE_DISCIPLINE_NEEDED_BY_THIS_PROGRAM;
-#endif
+# ifndef CLKLDISC
+ CLOCK_LINE_DISCIPLINE_NEEDED_BY_THIS_PROGRAM;
+# endif
+#else
+# ifdef CLKLDISC
+ ONLY_ONE_CLOCK_LINE_DISCIPLINE_FOR_THIS_PROGRAM;
+# endif
#endif
/*
*/
#define BLOCKSIGMASK (sigmask(SIGIO)|sigmask(SIGALRM))
-/*
- * speed table
- */
-struct speeds {
- int bps;
- int rate;
-} speedtab[] = {
- { 300, B300 },
- { 1200, B1200 },
- { 2400, B2400 },
- { 4800, B4800 },
- { 9600, B9600 },
- { 19200, EXTA },
- { 38400, EXTB },
- { 0, 0 }
-};
-
-char *progname;
-int debug;
-
-#ifdef CLKLDISC
-#define DEFMAGIC '\r'
-#endif
+#define progname clktestOptions.pzProgName
-#ifdef CLKLDISC
-# ifdef STREAM
-# include <stropts.h>
-# ifdef HAVE_SYS_CLKDEFS_H
-# include <sys/clkdefs.h>
-# endif
-# define DEFMAGIC "\r"
-# endif
-#endif
-
struct timeval timeout = { 0 };
char *cmd = NULL;
int cmdlen;
-int docmd = 0;
+
#ifdef CLKLDISC
u_long magic1 = DEFMAGIC;
u_long magic2 = DEFMAGIC;
#endif
-#ifdef STREAM
-char magic[32];
-#endif
+
int speed = B9600;
int ttflags = RAW|EVENP|ODDP;
extern u_long ustotsmid[];
extern u_long ustotshi[];
+int alarming();
+int ioready();
+
/*
* main - parse arguments and handle options
*/
char *argv[]
)
{
- int c;
- int errflg = 0;
- struct speeds *spd;
- u_long tmp;
int fd;
struct sgttyb ttyb;
struct itimerval itimer;
- extern int ntp_optind;
- extern char *ntp_optarg;
- int alarming();
- int ioready();
- progname = argv[0];
#ifdef STREAM
magic[0] = 0;
#endif
- while ((c = ntp_getopt(argc, argv, "a:b:c:dfs:t:")) != EOF)
- switch (c) {
-#ifdef CLKLDISC
- case 'a':
-#endif
- case 'c':
- if (!atouint(ntp_optarg, &tmp)) {
- (void) fprintf(stderr,
- "%s: argument for -%c must be integer\n",
- progname, c);
- errflg++;
- break;
- }
-#ifdef CLKLDISC
- if (c == 'c')
- magic1 = tmp;
- else
- magic2 = tmp;
-#endif
-#ifdef STREAM
- magic[strlen(magic)+1] = '\0';
- magic[strlen(magic)] = tmp;
-#endif
- break;
- case 'b':
- if (!atouint(ntp_optarg, &tmp)) {
- errflg++;
- break;
- }
- spd = speedtab;
- while (spd->bps != 0)
- if ((int)tmp == spd->bps)
- break;
- if (spd->bps == 0) {
- (void) fprintf(stderr,
- "%s: speed %lu is unsupported\n",
- progname, tmp);
- errflg++;
- } else {
- speed = spd->rate;
- }
- break;
- case 'd':
- ++debug;
- break;
- case 'f':
- ttflags |= CRMOD;
- break;
- case 's':
- cmdlen = strlen(ntp_optarg);
- if (cmdlen == 0)
- errflg++;
- else
- cmd = ntp_optarg;
- break;
- case 't':
- if (!atouint(ntp_optarg, &tmp))
- errflg++;
- else {
- timeout.tv_sec = (long)tmp;
- docmd = 1;
- }
- break;
- default:
- errflg++;
- break;
+
+ {
+ int ct = optionProcess( &clktestOptions, argc, argv );
+ if (HAVE_OPT(COMMAND) && (strlen(OPT_ARG(COMMAND)) == 0)) {
+ fputs( "The command option string must not be empty\n", stderr );
+ USAGE( EXIT_FAILURE );
}
- if (errflg || ntp_optind+1 != argc) {
- (void) fprintf(stderr,
-#ifdef CLKLDISC
- "usage: %s [-b bps] [-c magic1] [-a magic2] [-f] [-s cmd] [-t timeo] tty_device\n",
-#endif
-#ifdef STREAM
- "usage: %s [-b bps] [-c magic1] [-c magic2]... [-f] [-s cmd] [-t timeo] tty_device\n",
-#endif
- progname);
- exit(2);
- }
+ if ((argc -= ct) != 1) {
+ fputs( "Missing tty device name\n", stderr );
+ USAGE( EXIT_FAILURE );
+ }
+ argv += ct;
+ }
#ifdef STREAM
if (!strlen(magic))
strcpy(magic,DEFMAGIC);
#endif
- if (docmd)
- fd = open(argv[ntp_optind], O_RDWR, 0777);
- else
- fd = open(argv[ntp_optind], O_RDONLY, 0777);
+ fd = open(*argv, HAVE_OPT(TIMEOUT) ? O_RDWR : O_RDONLY, 0777);
if (fd == -1) {
- (void) fprintf(stderr, "%s: open(%s): ", progname,
- argv[ntp_optind]);
+ fprintf(stderr, "%s: open(%s): ", progname, *argv);
perror("");
exit(1);
}
(void) gettimeofday(&lasttv, (struct timezone *)0);
- if (docmd) {
+ if (HAVE_OPT(TIMEOUT)) {
/*
* set non-blocking, async I/O on the descriptor
*/
*/
wasalarmed = 0;
(void) signal(SIGALRM, alarming);
+ timeout.tv_sec = OPT_VALUE_TIMEOUT;
itimer.it_interval = itimer.it_value = timeout;
setitimer(ITIMER_REAL, &itimer, (struct itimerval *)0);
doboth(fd);
{
int n;
- if (cmd == NULL || cmdlen <= 0)
+ if (! HAVE_OPT(COMMAND))
return;
n = write(fd, cmd, cmdlen);
--- /dev/null
+/* -*- Mode: Text -*- */
+
+copyright = {
+ date = "1970-2004";
+ owner = "ntp.org";
+ eaddr = "http://bugs.ntp.isc.org, bugs@ntp.org";
+ type = bsd;
+};
+
+#ifndef __windows__
+rcfile = ".ntprc";
+#else
+rcfile = "ntp.ini";
+#endif
+
+homerc = $HOME, ".";
+long-opts;
+config-header = config.h;
+environrc;
+
+version = `
+eval VERSION=\`sed -e 's/.*,\\[//' -e 's/\\].*//' < ../version.m4\`
+[ -z "${VERSION}" ] && echo "Cannot determine VERSION" && kill -TERM $AG_pid
+echo $VERSION`;
* Boston, MA 02111-1307, USA.
*/
-copyright = {
- date = "1970-2004";
- owner = "ntp.org";
- eaddr = "http://bugs.ntp.isc.org, bugs@ntp.org";
- type = bsd;
-};
-
-
prog-name = "ntpdc";
prog-title = "vendor-specific NTP query program";
-homerc = $HOME, ".";
-long-opts;
-config-header = config.h;
-argument = '[ host ...]';
-
-#ifndef __windows__
-rcfile = ".ntprc";
-#else
-rcfile = "ntp.ini";
-#endif
-
-environrc;
-
-version = `
-eval VERSION=\`sed -e 's/.*,\\[//' -e 's/\\].*//' < ../version.m4\`
-[ -z "${VERSION}" ] && echo "Cannot determine VERSION" && kill -TERM $AG_pid
-echo $VERSION`;
+
+#include copyright.def
test-main;