From: Dave Hart Date: Sat, 4 Dec 2010 07:42:26 +0000 (+0000) Subject: centralize TTY header goop in ntp_tty.h. X-Git-Tag: NTP_4_2_7P89~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e15b2bd19726b8b334773c6f8984691256c106f8;p=thirdparty%2Fntp.git centralize TTY header goop in ntp_tty.h. move clockstuff utils closer to building cleanly. bk: 4cf9f0e2FtwusOQa4TZq-SuxRRWJdA --- diff --git a/clockstuff/Makefile.am b/clockstuff/Makefile.am index 9bf6fd8ad..6b244beb7 100644 --- a/clockstuff/Makefile.am +++ b/clockstuff/Makefile.am @@ -2,9 +2,9 @@ AUTOMAKE_OPTIONS = noinst_PROGRAMS = @PROPDELAY@ @CHUTEST@ @CLKTEST@ EXTRA_PROGRAMS = propdelay chutest clktest -BUILT_SOURCES = clktest-opts.c clktest-opts.h +BUILT_SOURCES = $(srcdir)/clktest-opts.c $(srcdir)/clktest-opts.h -clktest_SOURCES = clktest.c clktest-opts.c clktest-opts.h +clktest_SOURCES = clktest.c clktest-opts.c INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/lib/isc/include INCLUDES += -I$(top_srcdir)/lib/isc/nothreads/include diff --git a/clockstuff/clktest-opts.def b/clockstuff/clktest-opts.def index 2960f0f18..68dc47ff0 100644 --- a/clockstuff/clktest-opts.def +++ b/clockstuff/clktest-opts.def @@ -18,38 +18,6 @@ detail = <<- _EODetail_ test-main; -export = <<- _EOExport_ - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - - #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 - # ifdef HAVE_SYS_CLKDEFS_H - # include - # endif - # undef DEFMAGIC - # define DEFMAGIC "\r" - # endif - #endif - _EOExport_; - #ifdef CLKLDISC flag = { name = magic2; diff --git a/clockstuff/clktest.c b/clockstuff/clktest.c index a97884fb2..5bd6ae0d9 100644 --- a/clockstuff/clktest.c +++ b/clockstuff/clktest.c @@ -7,6 +7,40 @@ #ifdef HAVE_CONFIG_H # include #endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef HAVE_SGTTY_H +#include +#endif +#ifdef HAVE_UNISTD_H +# include +#endif + +#ifdef CLKLDISC +# define DEFMAGIC '\r' +#endif + +#ifdef CLKLDISC +# ifdef STREAM +# include +# ifdef HAVE_SYS_CLKDEFS_H +# include +# endif +# undef DEFMAGIC +# define DEFMAGIC "\r" +# endif +#endif + +#include "ntp_fp.h" +#include "ntp.h" +#include "ntp_unixtime.h" #include "clktest-opts.h" #define STREQ(a, b) (*(a) == *(b) && strcmp((a), (b)) == 0) diff --git a/include/ntp_machine.h b/include/ntp_machine.h index ad4b5860b..1346b09f5 100644 --- a/include/ntp_machine.h +++ b/include/ntp_machine.h @@ -329,44 +329,9 @@ extern char *strdup(const char *); #include "ERROR: You must define one of the HAVE_xx_NICE defines!" #endif -/* - * use only one tty model - no use in initialising - * a tty in three ways - * HAVE_TERMIOS is preferred over HAVE_SYSV_TTYS over HAVE_BSD_TTYS - */ - -#ifdef HAVE_TERMIOS_H -# define HAVE_TERMIOS -#else -# ifdef HAVE_TERMIO_H -# define HAVE_SYSV_TTYS -# else -# ifdef HAVE_SGTTY_H -# define HAVE_BSD_TTYS -# endif -# endif -#endif - -#ifdef HAVE_TERMIOS -# undef HAVE_BSD_TTYS -# undef HAVE_SYSV_TTYS -#endif - #ifndef HAVE_TIMEGM extern time_t timegm (struct tm *); #endif -#ifdef HAVE_SYSV_TTYS -# undef HAVE_BSD_TTYS -#endif - -#if !defined(SYS_WINNT) && !defined(VMS) && !defined(SYS_VXWORKS) -# if !defined(HAVE_SYSV_TTYS) \ - && !defined(HAVE_BSD_TTYS) \ - && !defined(HAVE_TERMIOS) -#include "ERROR: no tty type defined!" -# endif -#endif /* !SYS_WINNT && !VMS && !SYS_VXWORKS*/ - #endif /* NTP_MACHINE_H */ diff --git a/include/ntp_refclock.h b/include/ntp_refclock.h index e6bc11fec..ec1756ff0 100644 --- a/include/ntp_refclock.h +++ b/include/ntp_refclock.h @@ -5,44 +5,14 @@ #ifndef NTP_REFCLOCK_H #define NTP_REFCLOCK_H -#include "ntp_types.h" - -#if defined(HAVE_BSD_TTYS) -#include -#endif /* HAVE_BSD_TTYS */ - -#if defined(HAVE_SYSV_TTYS) -#include -#endif /* HAVE_SYSV_TTYS */ - -#if defined(HAVE_TERMIOS) -# ifdef TERMIOS_NEEDS__SVID3 -# define _SVID3 -# endif -# include -# ifdef TERMIOS_NEEDS__SVID3 -# undef _SVID3 -# endif -#endif - #if defined(HAVE_SYS_MODEM_H) #include #endif -#if 0 /* If you need that, include ntp_io.h instead */ -#if defined(STREAM) -#include -#if defined(CLK) /* This is never defined, except perhaps by a system header file */ -#include -#endif /* CLK */ -#endif /* STREAM */ -#endif - +#include "ntp_types.h" +#include "ntp_tty.h" #include "recvbuff.h" -#if !defined(SYSV_TTYS) && !defined(STREAM) & !defined(BSD_TTYS) -#define BSD_TTYS -#endif /* SYSV_TTYS STREAM BSD_TTYS */ #define SAMPLE(x) pp->coderecv = (pp->coderecv + 1) % MAXSTAGE; \ pp->filter[pp->coderecv] = (x); \ diff --git a/include/ntp_tty.h b/include/ntp_tty.h index 983311923..828006389 100644 --- a/include/ntp_tty.h +++ b/include/ntp_tty.h @@ -1,10 +1,31 @@ /* * ntp_tty.h - header file for serial lines handling */ - #ifndef NTP_TTY_H #define NTP_TTY_H +/* + * use only one tty model - no use in initialising + * a tty in three ways + * HAVE_TERMIOS is preferred over HAVE_SYSV_TTYS over HAVE_BSD_TTYS + */ + +#if defined(HAVE_TERMIOS_H) || defined(HAVE_SYS_TERMIOS_H) +# define HAVE_TERMIOS +#elif defined(HAVE_TERMIO_H) +# define HAVE_SYSV_TTYS +#elif defined(HAVE_SGTTY_H) +# define HAVE_BSD_TTYS +#endif + +#if !defined(VMS) && !defined(SYS_VXWORKS) +# if !defined(HAVE_SYSV_TTYS) \ + && !defined(HAVE_BSD_TTYS) \ + && !defined(HAVE_TERMIOS) +#include "ERROR: no tty type defined!" +# endif +#endif /* !VMS && !SYS_VXWORKS*/ + #if defined(HAVE_BSD_TTYS) #include #define TTY struct sgttyb @@ -34,22 +55,47 @@ #endif /* HAVE_SYSV_TTYS */ #if defined(HAVE_TERMIOS) -# ifdef TERMIOS_NEEDS__SVID3 -# define _SVID3 -# endif -# include -# ifdef TERMIOS_NEEDS__SVID3 -# undef _SVID3 +# if defined(HAVE_TERMIOS_H) +# ifdef TERMIOS_NEEDS__SVID3 +# define _SVID3 +# endif +# include +# ifdef TERMIOS_NEEDS__SVID3 +# undef _SVID3 +# endif +# elif defined(HAVE_SYS_TERMIOS_H) +# include # endif -#define TTY struct termios +# define TTY struct termios #endif #if defined(HAVE_SYS_MODEM_H) #include #endif -#if !defined(SYSV_TTYS) && !defined(STREAM) & !defined(BSD_TTYS) -#define BSD_TTYS -#endif /* SYSV_TTYS STREAM BSD_TTYS */ +/* + * Line discipline flags. These require line discipline or streams + * modules to be installed/loaded in the kernel. If specified, but not + * installed, the code runs as if unspecified. + */ +#define LDISC_STD 0x00 /* standard */ +#define LDISC_CLK 0x01 /* tty_clk \n intercept */ +#define LDISC_CLKPPS 0x02 /* tty_clk \377 intercept */ +#define LDISC_ACTS 0x04 /* tty_clk #* intercept */ +#define LDISC_CHU 0x08 /* depredated */ +#define LDISC_PPS 0x10 /* ppsclock, ppsapi */ +#define LDISC_RAW 0x20 /* raw binary */ +#define LDISC_ECHO 0x40 /* enable echo */ +#define LDISC_REMOTE 0x80 /* remote mode */ +#define LDISC_7O1 0x100 /* 7-bit, odd parity for Z3801A */ + +/* function prototypes for ntp_tty.c */ +#if !defined(SYS_VXWORKS) && !defined(SYS_WINNT) +# if defined(HAVE_TERMIOS) || defined(HAVE_SYSV_TTYS) || \ + defined(HAVE_BSD_TTYS) +extern int ntp_tty_setup(int, u_int, u_int); +extern int ntp_tty_ioctl(int, u_int); +# endif +#endif #endif /* NTP_TTY_H */ diff --git a/libntp/icom.c b/libntp/icom.c index f45a591fe..881ca6707 100644 --- a/libntp/icom.c +++ b/libntp/icom.c @@ -87,10 +87,10 @@ doublefreq( /* returns void */ ) { int i; - char s1[11]; + char s1[16]; char *y; - sprintf(s1, " %10.0f", freq); + snprintf(s1, sizeof(s1), " %10.0f", freq); y = s1 + 10; i = 0; while (*y != ' ') { @@ -98,13 +98,13 @@ doublefreq( /* returns void */ x[i] = x[i] | ((*y-- & 0x0f) << 4); i++; } - for (; i < len; i++) + for ( ; i < len; i++) x[i] = 0; x[i] = FI; } /* - * icom_open() - open and initialize serial interface + * icom_init() - open and initialize serial interface * * This routine opens the serial interface for raw transmission; that * is, character-at-a-time, no stripping, checking or monkeying with the diff --git a/ntpd/refclock_datum.c b/ntpd/refclock_datum.c index 743bfb0c1..68804bf69 100644 --- a/ntpd/refclock_datum.c +++ b/ntpd/refclock_datum.c @@ -19,6 +19,7 @@ #include "ntpd.h" #include "ntp_io.h" +#include "ntp_tty.h" #include "ntp_refclock.h" #include "ntp_unixtime.h" #include "ntp_stdlib.h" @@ -26,17 +27,6 @@ #include #include -#if defined(HAVE_BSD_TTYS) -#include -#endif /* HAVE_BSD_TTYS */ - -#if defined(HAVE_SYSV_TTYS) -#include -#endif /* HAVE_SYSV_TTYS */ - -#if defined(HAVE_TERMIOS) -#include -#endif #if defined(STREAM) #include #if defined(WWVBCLK)