[Git][NTPsec/ntpsec][scanner] 2 commits: ntpd/refclock_truetime.c: Remove tabs, Single line /* comments to //
Hal Murray (@hal.murray)
gitlab at mg.gitlab.com
Thu Aug 6 18:50:06 UTC 2026
Hal Murray pushed to branch scanner at NTPsec / ntpsec
Commits:
38d2c1c8 by Gary E. Miller at 2026-08-06T11:45:19-07:00
ntpd/refclock_truetime.c: Remove tabs, Single line /* comments to //
- - - - -
33df4dd3 by Gary E. Miller at 2026-08-06T11:49:44-07:00
ntpd/ntp_scanner.c: Remove tabs, Single line /* comments to //
No functional changes.
- - - - -
2 changed files:
- ntpd/ntp_scanner.c
- ntpd/refclock_truetime.c
Changes:
=====================================
ntpd/ntp_scanner.c
=====================================
@@ -3,9 +3,9 @@
*
* The source code for a simple lexical analyzer.
*
- * Written By: Sachin Kamboj
- * University of Delaware
- * Newark, DE 19711
+ * Written By: Sachin Kamboj
+ * University of Delaware
+ * Newark, DE 19711
* Copyright Sachin Kamboj
* Copyright the NTPsec project contributors
* SPDX-License-Identifier: BSD-2-Clause
@@ -29,24 +29,24 @@
#include "ntp_scanner.h"
#include "ntp_debug.h"
#include "ntp_parser.tab.h"
-#include "timespecops.h" /* for D_ISZERO_NS() */
+#include "timespecops.h" // for D_ISZERO_NS()
-/* ntp_keyword.h declares finite state machine and token text */
+// ntp_keyword.h declares finite state machine and token text
#include "ntp_keyword.h"
-/* used to implement g and G suffixes for numeric literals in fudge offset declarations */
-#define SECONDS_IN_WEEK (unsigned long long)(7 * 24 * 60 * 60) /* 32bit systems*/
-#define GPS_ERA_10BIT (1024L * SECONDS_IN_WEEK)
-#define GPS_ERA_13BIT (8192L * SECONDS_IN_WEEK)
-#define ERA_SUFFIX(c) ((c) == 'g' || (c) == 'G')
+// used to implement g and G suffixes for numeric literals in fudge offset declarations
+#define SECONDS_IN_WEEK (unsigned long long)(7 * 24 * 60 * 60) // 32bit systems
+#define GPS_ERA_10BIT (1024L * SECONDS_IN_WEEK)
+#define GPS_ERA_13BIT (8192L * SECONDS_IN_WEEK)
+#define ERA_SUFFIX(c) ((c) == 'g' || (c) == 'G')
/* SCANNER GLOBAL VARIABLES
* ------------------------
*/
-#define MAX_LEXEME (1024 + 1) /* The maximum size of a lexeme */
-static char yytext[MAX_LEXEME]; /* Buffer for storing the input text/lexeme */
-static uint32_t conf_file_sum; /* Simple sum of characters read */
+#define MAX_LEXEME (1024 + 1) // The maximum size of a lexeme
+static char yytext[MAX_LEXEME]; // Buffer for storing the input text/lexeme
+static uint32_t conf_file_sum; // Simple sum of characters read
static struct FILE_INFO * lex_stack = NULL;
@@ -54,7 +54,7 @@ static struct FILE_INFO * lex_stack = NULL;
* --------------------
*/
#define ENDSWITH(str, suff) (strcmp(str + strlen(str) - strlen(suff), suff)==0)
-#define CONF_ENABLE(s) ENDSWITH(s, ".conf")
+#define CONF_ENABLE(s) ENDSWITH(s, ".conf")
/* SCANNER GLOBAL VARIABLES
@@ -72,29 +72,29 @@ static int is_keyword(char *lexeme, follby *pfollowedby);
/*
* keyword() - Return the keyword associated with token T_ identifier.
- * See also token_name() for the string-ized T_ identifier.
- * Example: keyword(T_Server) returns "server"
- * token_name(T_Server) returns "T_Server"
+ * See also token_name() for the string-ized T_ identifier.
+ * Example: keyword(T_Server) returns "server"
+ * token_name(T_Server) returns "T_Server"
*/
const char *
keyword(
- int token
- )
+ int token
+ )
{
- size_t i;
- const char *text;
+ size_t i;
+ const char *text;
- i = (size_t)(token - LOWEST_KEYWORD_ID);
+ i = (size_t)(token - LOWEST_KEYWORD_ID);
- if (i < COUNTOF(keyword_text)) {
- text = keyword_text[i];
- } else {
- text = NULL;
- }
+ if (i < COUNTOF(keyword_text)) {
+ text = keyword_text[i];
+ } else {
+ text = NULL;
+ }
- return (text != NULL)
- ? text
- : "(keyword not found)";
+ return (text != NULL)
+ ? text
+ : "(keyword not found)";
}
@@ -135,30 +135,30 @@ keyword(
*/
static struct FILE_INFO *
lex_open(
- const char *path,
- const char *mode
- )
+ const char *path,
+ const char *mode
+ )
{
- struct FILE_INFO *stream;
- size_t nnambuf;
-
- nnambuf = strlen(path);
- stream = emalloc_zero(sizeof(*stream) + nnambuf);
- stream->curpos.nline = 1;
- stream->backch = EOF;
- /* copy name with memcpy -- trailing NUL already there! */
- memcpy(stream->fname, path, nnambuf);
-
- if (NULL != mode) {
- stream->fpi = fopen(path, mode);
- if (NULL == stream->fpi) {
- free(stream);
- msyslog(LOG_ERR, "CONFIG: failed to open \'%s\': %s",
- path, strerror(errno));
- stream = NULL;
- }
- }
- return stream;
+ struct FILE_INFO *stream;
+ size_t nnambuf;
+
+ nnambuf = strlen(path);
+ stream = emalloc_zero(sizeof(*stream) + nnambuf);
+ stream->curpos.nline = 1;
+ stream->backch = EOF;
+ // copy name with memcpy -- trailing NUL already there!
+ memcpy(stream->fname, path, nnambuf);
+
+ if (NULL != mode) {
+ stream->fpi = fopen(path, mode);
+ if (NULL == stream->fpi) {
+ free(stream);
+ msyslog(LOG_ERR, "CONFIG: failed to open \'%s\': %s",
+ path, strerror(errno));
+ stream = NULL;
+ }
+ }
+ return stream;
}
/* get next character from buffer or file. This will return any putback
@@ -167,62 +167,62 @@ lex_open(
*/
static int
lex_getch(
- struct FILE_INFO *stream
- )
+ struct FILE_INFO *stream
+ )
{
- int ch;
-
- if (NULL == stream || stream->force_eof)
- return EOF;
-
- if (EOF != stream->backch) {
- ch = stream->backch;
- stream->backch = EOF;
- if (stream->fpi)
- conf_file_sum += (unsigned int)ch;
- } else if (stream->fpi) {
- /* fetch next 7-bit ASCII char (or EOF) from file */
- /* coverity[tainted_scalar] */
- while ((ch = fgetc(stream->fpi)) != EOF && ch > SCHAR_MAX) {
- stream->curpos.ncol++;
- }
- if (EOF != ch) {
- conf_file_sum += (unsigned int)ch;
- stream->curpos.ncol++;
- }
- } else {
- /* fetch next 7-bit ASCII char from buffer */
- const char * scan;
- scan = &remote_config.buffer[remote_config.pos];
- while ((ch = (uint8_t)*scan) > SCHAR_MAX) {
- scan++;
- stream->curpos.ncol++;
- }
- if ('\0' != ch) {
- scan++;
- stream->curpos.ncol++;
- } else {
- ch = EOF;
- }
- remote_config.pos = (int)(scan - remote_config.buffer);
- }
-
- /* If the last line ends without '\n', generate one. This
- * happens most likely on Windows, where editors often have a
- * sloppy concept of a line.
- */
- if (EOF == ch && stream->curpos.ncol != 0) {
- ch = '\n';
- }
-
- /* update scan position tallies */
- if (ch == '\n') {
- stream->bakpos = stream->curpos;
- stream->curpos.nline++;
- stream->curpos.ncol = 0;
- }
-
- return ch;
+ int ch;
+
+ if (NULL == stream || stream->force_eof)
+ return EOF;
+
+ if (EOF != stream->backch) {
+ ch = stream->backch;
+ stream->backch = EOF;
+ if (stream->fpi)
+ conf_file_sum += (unsigned int)ch;
+ } else if (stream->fpi) {
+ // fetch next 7-bit ASCII char (or EOF) from file
+ // coverity[tainted_scalar]
+ while ((ch = fgetc(stream->fpi)) != EOF && ch > SCHAR_MAX) {
+ stream->curpos.ncol++;
+ }
+ if (EOF != ch) {
+ conf_file_sum += (unsigned int)ch;
+ stream->curpos.ncol++;
+ }
+ } else {
+ // fetch next 7-bit ASCII char from buffer
+ const char * scan;
+ scan = &remote_config.buffer[remote_config.pos];
+ while ((ch = (uint8_t)*scan) > SCHAR_MAX) {
+ scan++;
+ stream->curpos.ncol++;
+ }
+ if ('\0' != ch) {
+ scan++;
+ stream->curpos.ncol++;
+ } else {
+ ch = EOF;
+ }
+ remote_config.pos = (int)(scan - remote_config.buffer);
+ }
+
+ /* If the last line ends without '\n', generate one. This
+ * happens most likely on Windows, where editors often have a
+ * sloppy concept of a line.
+ */
+ if (EOF == ch && stream->curpos.ncol != 0) {
+ ch = '\n';
+ }
+
+ // update scan position tallies
+ if (ch == '\n') {
+ stream->bakpos = stream->curpos;
+ stream->curpos.nline++;
+ stream->curpos.ncol = 0;
+ }
+
+ return ch;
}
/* Note: lex_ungetch will fail to track more than one line of push
@@ -231,29 +231,29 @@ lex_getch(
*/
static int
lex_ungetch(
- int ch,
- struct FILE_INFO *stream
- )
+ int ch,
+ struct FILE_INFO *stream
+ )
{
- /* check preconditions */
- if (NULL == stream || stream->force_eof)
- return EOF;
- if (EOF != stream->backch || EOF == ch) {
- return EOF;
- }
-
- /* keep for later reference and update checksum */
- stream->backch = (uint8_t)ch;
- if (stream->fpi)
- conf_file_sum -= (unsigned int)stream->backch;
-
- /* update position */
- if (stream->backch == '\n') {
- stream->curpos = stream->bakpos;
- stream->bakpos.ncol = -1;
- }
- stream->curpos.ncol--;
- return stream->backch;
+ // check preconditions
+ if (NULL == stream || stream->force_eof)
+ return EOF;
+ if (EOF != stream->backch || EOF == ch) {
+ return EOF;
+ }
+
+ // keep for later reference and update checksum
+ stream->backch = (uint8_t)ch;
+ if (stream->fpi)
+ conf_file_sum -= (unsigned int)stream->backch;
+
+ // update position
+ if (stream->backch == '\n') {
+ stream->curpos = stream->bakpos;
+ stream->bakpos.ncol = -1;
+ }
+ stream->curpos.ncol--;
+ return stream->backch;
}
/* dispose of an input structure. If the file pointer is not NULL, close
@@ -261,15 +261,15 @@ lex_ungetch(
*/
static void
lex_close(
- struct FILE_INFO *stream
- )
+ struct FILE_INFO *stream
+ )
{
- if (NULL != stream) {
- if (NULL != stream->fpi) {
- fclose(stream->fpi);
- }
- free(stream);
- }
+ if (NULL != stream) {
+ if (NULL != stream->fpi) {
+ fclose(stream->fpi);
+ }
+ free(stream);
+ }
}
/* INPUT STACK
@@ -287,16 +287,16 @@ lex_close(
static struct FILE_INFO *
_drop_stack_do(
- struct FILE_INFO * head
- )
+ struct FILE_INFO * head
+ )
{
- struct FILE_INFO * tail;
- while (NULL != head) {
- tail = head->st_next;
- lex_close(head);
- head = tail;
- }
- return head;
+ struct FILE_INFO * tail;
+ while (NULL != head) {
+ tail = head->st_next;
+ lex_close(head);
+ head = tail;
+ }
+ return head;
}
@@ -309,16 +309,16 @@ _drop_stack_do(
*/
bool
lex_init_stack(
- const char * path,
- const char * mode
- )
+ const char * path,
+ const char * mode
+ )
{
- if (NULL != lex_stack || NULL == path)
- return false;
+ if (NULL != lex_stack || NULL == path)
+ return false;
- //fprintf(stderr, "lex_init_stack(%s)\n", path);
- lex_stack = lex_open(path, mode);
- return (NULL != lex_stack);
+ //fprintf(stderr, "lex_init_stack(%s)\n", path);
+ lex_stack = lex_open(path, mode);
+ return (NULL != lex_stack);
}
/* This removes *all* input sources from the stack, leaving the head
@@ -331,7 +331,7 @@ lex_init_stack(
void
lex_drop_stack(void)
{
- lex_stack = _drop_stack_do(lex_stack);
+ lex_stack = _drop_stack_do(lex_stack);
}
/* Flush the lexer input stack: This will nip all input objects on the
@@ -344,43 +344,43 @@ lex_drop_stack(void)
*/
bool
lex_flush_stack(void) {
- bool retv = false;
-
- if (NULL != lex_stack) {
- retv = !lex_stack->force_eof;
- lex_stack->force_eof = true;
- lex_stack->st_next = _drop_stack_do(
- lex_stack->st_next);
- }
- return retv;
+ bool retv = false;
+
+ if (NULL != lex_stack) {
+ retv = !lex_stack->force_eof;
+ lex_stack->force_eof = true;
+ lex_stack->st_next = _drop_stack_do(
+ lex_stack->st_next);
+ }
+ return retv;
}
/* Reversed string comparison - we want to LIFO directory subfiles so they
* actually get evaluated in sort order.
*/
static int rcmpstring(const void *p1, const void *p2) {
- return strcmp(*(const char * const *)p1, *(const char * const *)p2);
+ return strcmp(*(const char * const *)p1, *(const char * const *)p2);
}
bool is_directory(const char *path) {
- struct stat sb;
- return stat(path, &sb) == 0 && S_ISDIR(sb.st_mode);
+ struct stat sb;
+ return stat(path, &sb) == 0 && S_ISDIR(sb.st_mode);
}
void reparent(char *fullpath, size_t fullpathsize,
- const char *dir, const char *base)
+ const char *dir, const char *base)
{
- fullpath[0] = '\0';
- if (base[0] != DIR_SEP) {
- char *dirpart = strdup(dir);
- char *end;
- strlcpy(fullpath, dirname(dirpart), fullpathsize-2);
- end = fullpath + strlen(fullpath);
- *end++ = DIR_SEP;
- *end++ = '\0';
- free(dirpart);
- }
- strlcat(fullpath, base, fullpathsize);
+ fullpath[0] = '\0';
+ if (base[0] != DIR_SEP) {
+ char *dirpart = strdup(dir);
+ char *end;
+ strlcpy(fullpath, dirname(dirpart), fullpathsize-2);
+ end = fullpath + strlen(fullpath);
+ *end++ = DIR_SEP;
+ *end++ = '\0';
+ free(dirpart);
+ }
+ strlcat(fullpath, base, fullpathsize);
}
/* Push another file on the parsing stack. If the mode is NULL, create a
@@ -400,40 +400,40 @@ void reparent(char *fullpath, size_t fullpathsize,
* Returns true if a new info record was pushed onto the stack.
*/
bool lex_push_file(
- const char * path
- )
+ const char * path
+ )
{
- struct FILE_INFO * next = NULL;
-
- if (NULL != path) {
- char fullpath[PATH_MAX];
- if (lex_stack != NULL) {
- reparent(fullpath, sizeof(fullpath), lex_stack->fname, path);
- } else {
- strlcpy(fullpath, path, sizeof(fullpath));
- }
- //fprintf(stderr, "lex_push_file(%s)\n", fullpath);
- if (is_directory(fullpath)) {
- /* directory scanning */
- DIR *dfd;
- struct dirent *dp;
- char **baselist;
- int basecount = 0;
- if ((dfd = opendir(fullpath)) == NULL)
- return false;
- baselist = (char **)malloc(sizeof(char *));
- if (NULL == baselist) {
- msyslog(LOG_ERR,
+ struct FILE_INFO * next = NULL;
+
+ if (NULL != path) {
+ char fullpath[PATH_MAX];
+ if (lex_stack != NULL) {
+ reparent(fullpath, sizeof(fullpath), lex_stack->fname, path);
+ } else {
+ strlcpy(fullpath, path, sizeof(fullpath));
+ }
+ //fprintf(stderr, "lex_push_file(%s)\n", fullpath);
+ if (is_directory(fullpath)) {
+ // directory scanning
+ DIR *dfd;
+ struct dirent *dp;
+ char **baselist;
+ int basecount = 0;
+ if ((dfd = opendir(fullpath)) == NULL)
+ return false;
+ baselist = (char **)malloc(sizeof(char *));
+ if (NULL == baselist) {
+ msyslog(LOG_ERR,
"CONFIG: lex_push_file: NULL from malloc");
- exit(3);
- }
- while ((dp = readdir(dfd)) != NULL)
- {
- if (!CONF_ENABLE(dp->d_name)) {
- continue;
- }
- baselist[basecount++] = strdup(dp->d_name);
- baselist = realloc(baselist,
+ exit(3);
+ }
+ while ((dp = readdir(dfd)) != NULL)
+ {
+ if (!CONF_ENABLE(dp->d_name)) {
+ continue;
+ }
+ baselist[basecount++] = strdup(dp->d_name);
+ baselist = realloc(baselist,
(size_t)(basecount+1) * sizeof(char *));
if (NULL == baselist) {
msyslog(LOG_ERR,
@@ -441,43 +441,43 @@ bool lex_push_file(
"NULL from realloc");
exit(3);
}
- }
- closedir(dfd);
- qsort(baselist, (size_t)basecount, sizeof(char *),
+ }
+ closedir(dfd);
+ qsort(baselist, (size_t)basecount, sizeof(char *),
rcmpstring);
- for (int i = 0; i < basecount; i++) {
- char subpath[PATH_MAX];
- size_t pathlen = strlcpy(subpath, fullpath, PATH_MAX);
- if ((pathlen < PATH_MAX - 1) &&
- (subpath[pathlen -1] != DIR_SEP)
- ) {
- char *ep = subpath + strlen(subpath);
- *ep++ = DIR_SEP;
- *ep = '\0';
- }
- strlcat(subpath, baselist[i], PATH_MAX);
- /* This should barf safely if the complete
- * filename was too long to fit in the buffer.
- */
- msyslog(LOG_NOTICE,
- "CONFIG: opening <%s> from dir <%s>",
- subpath, fullpath);
- lex_push_file(subpath);
- }
- for (int i = 0; i < basecount; i++) {
- free(baselist[i]);
- }
- free(baselist);
- return basecount > 0;
- } else {
- next = lex_open(fullpath, "r");
- if (NULL != next) {
- next->st_next = lex_stack;
- lex_stack = next;
- }
- }
- }
- return (NULL != next);
+ for (int i = 0; i < basecount; i++) {
+ char subpath[PATH_MAX];
+ size_t pathlen = strlcpy(subpath, fullpath, PATH_MAX);
+ if ((pathlen < PATH_MAX - 1) &&
+ (subpath[pathlen -1] != DIR_SEP)
+ ) {
+ char *ep = subpath + strlen(subpath);
+ *ep++ = DIR_SEP;
+ *ep = '\0';
+ }
+ strlcat(subpath, baselist[i], PATH_MAX);
+ /* This should barf safely if the complete
+ * filename was too long to fit in the buffer.
+ */
+ msyslog(LOG_NOTICE,
+ "CONFIG: opening <%s> from dir <%s>",
+ subpath, fullpath);
+ lex_push_file(subpath);
+ }
+ for (int i = 0; i < basecount; i++) {
+ free(baselist[i]);
+ }
+ free(baselist);
+ return basecount > 0;
+ } else {
+ next = lex_open(fullpath, "r");
+ if (NULL != next) {
+ next->st_next = lex_stack;
+ lex_stack = next;
+ }
+ }
+ }
+ return (NULL != next);
}
/* Pop, close & free the top of the include stack, unless the stack
@@ -490,17 +490,17 @@ bool lex_push_file(
bool
lex_pop_file(void)
{
- struct FILE_INFO * head = lex_stack;
- struct FILE_INFO * tail = NULL;
-
- if (NULL != head) {
- tail = head->st_next;
- if (NULL != tail) {
- lex_stack = tail;
- lex_close(head);
- }
- }
- return (NULL != tail);
+ struct FILE_INFO * head = lex_stack;
+ struct FILE_INFO * tail = NULL;
+
+ if (NULL != head) {
+ tail = head->st_next;
+ if (NULL != tail) {
+ lex_stack = tail;
+ lex_close(head);
+ }
+ }
+ return (NULL != tail);
}
/* Get include nesting level. This currently loops over the stack and
@@ -516,30 +516,30 @@ lex_pop_file(void)
size_t
lex_level(void)
{
- size_t cnt = 0;
- struct FILE_INFO *ipf = lex_stack;
-
- while (NULL != ipf) {
- cnt++;
- ipf = ipf->st_next;
- }
- return cnt;
+ size_t cnt = 0;
+ struct FILE_INFO *ipf = lex_stack;
+
+ while (NULL != ipf) {
+ cnt++;
+ ipf = ipf->st_next;
+ }
+ return cnt;
}
-/* check if the current input is from a file */
+// check if the current input is from a file
bool
lex_from_file(void)
{
- return (NULL != lex_stack) && (NULL != lex_stack->fpi);
+ return (NULL != lex_stack) && (NULL != lex_stack->fpi);
}
struct FILE_INFO *
lex_current(void)
{
- /* this became so simple, it could be a macro. But then,
- * lex_stack needed to be global...
- */
- return lex_stack;
+ /* this became so simple, it could be a macro. But then,
+ * lex_stack needed to be global...
+ */
+ return lex_stack;
}
@@ -547,239 +547,239 @@ lex_current(void)
* --------------
*/
-/* Keywords */
+// Keywords
static int
is_keyword(
- char *lexeme,
- follby *pfollowedby
- )
+ char *lexeme,
+ follby *pfollowedby
+ )
{
- follby fb;
- int curr_s; /* current state index */
- int token;
-
- curr_s = SCANNER_INIT_S;
- token = 0;
-
- for (int i = 0; lexeme[i]; i++) {
- while (curr_s && (lexeme[i] != SS_CH(sst[curr_s])))
- curr_s = (int)SS_OTHER_N(sst[curr_s]);
-
- if (curr_s && (lexeme[i] == SS_CH(sst[curr_s]))) {
- if ('\0' == lexeme[i + 1]
- && FOLLBY_NON_ACCEPTING
- != SS_FB(sst[curr_s])) {
- fb = SS_FB(sst[curr_s]);
- *pfollowedby = fb;
- token = curr_s;
- break;
- }
- curr_s = SS_MATCH_N(sst[curr_s]);
- } else
- break;
- }
-
- return token;
+ follby fb;
+ int curr_s; // current state index
+ int token;
+
+ curr_s = SCANNER_INIT_S;
+ token = 0;
+
+ for (int i = 0; lexeme[i]; i++) {
+ while (curr_s && (lexeme[i] != SS_CH(sst[curr_s])))
+ curr_s = (int)SS_OTHER_N(sst[curr_s]);
+
+ if (curr_s && (lexeme[i] == SS_CH(sst[curr_s]))) {
+ if ('\0' == lexeme[i + 1]
+ && FOLLBY_NON_ACCEPTING
+ != SS_FB(sst[curr_s])) {
+ fb = SS_FB(sst[curr_s]);
+ *pfollowedby = fb;
+ token = curr_s;
+ break;
+ }
+ curr_s = SS_MATCH_N(sst[curr_s]);
+ } else
+ break;
+ }
+
+ return token;
}
-/* Integer */
+// Integer
static int
is_integer(
- char *lexeme
- )
+ char *lexeme
+ )
{
- int i;
- int is_neg;
- unsigned int u_val;
-
- i = 0;
-
- /* Allow a leading minus sign */
- if (lexeme[i] == '-') {
- i++;
- is_neg = true;
- } else {
- is_neg = false;
- }
-
- /* Check that all the remaining characters are digits */
- for (; lexeme[i] != '\0'; i++) {
- if (!isdigit((uint8_t)lexeme[i]))
- return false;
- }
-
- if (is_neg)
- return true;
-
- /* Reject numbers that fit in unsigned but not in signed int */
- if (1 == sscanf(lexeme, "%u", &u_val)) {
- return (u_val <= INT_MAX);
- } else {
- return false;
- }
+ int i;
+ int is_neg;
+ unsigned int u_val;
+
+ i = 0;
+
+ // Allow a leading minus sign
+ if (lexeme[i] == '-') {
+ i++;
+ is_neg = true;
+ } else {
+ is_neg = false;
+ }
+
+ // Check that all the remaining characters are digits
+ for (; lexeme[i] != '\0'; i++) {
+ if (!isdigit((uint8_t)lexeme[i]))
+ return false;
+ }
+
+ if (is_neg)
+ return true;
+
+ // Reject numbers that fit in unsigned but not in signed int
+ if (1 == sscanf(lexeme, "%u", &u_val)) {
+ return (u_val <= INT_MAX);
+ } else {
+ return false;
+ }
}
-/* unsigned int -- assumes is_integer() has returned false */
+// unsigned int -- assumes is_integer() has returned false
static int
is_u_int(
- char *lexeme
- )
+ char *lexeme
+ )
{
- int i;
- int is_hex;
-
- i = 0;
- if ('0' == lexeme[i] && 'x' == tolower((uint8_t)lexeme[i + 1])) {
- i += 2;
- is_hex = true;
- } else {
- is_hex = false;
- }
-
- /* Check that all the remaining characters are digits */
- for (; lexeme[i] != '\0'; i++) {
- if (is_hex && !isxdigit((uint8_t)lexeme[i]))
- return false;
- if (!is_hex && !isdigit((uint8_t)lexeme[i]))
- return false;
- }
-
- return true;
+ int i;
+ int is_hex;
+
+ i = 0;
+ if ('0' == lexeme[i] && 'x' == tolower((uint8_t)lexeme[i + 1])) {
+ i += 2;
+ is_hex = true;
+ } else {
+ is_hex = false;
+ }
+
+ // Check that all the remaining characters are digits
+ for (; lexeme[i] != '\0'; i++) {
+ if (is_hex && !isxdigit((uint8_t)lexeme[i]))
+ return false;
+ if (!is_hex && !isdigit((uint8_t)lexeme[i]))
+ return false;
+ }
+
+ return true;
}
-/* Double */
+// Double
static bool
is_double(
- char *lexeme
- )
+ char *lexeme
+ )
{
- unsigned int num_digits = 0; /* Number of digits read */
- unsigned int i;
-
- i = 0;
-
- /* Check for an optional '+' or '-' */
- if ('+' == lexeme[i] || '-' == lexeme[i]) {
- i++;
- }
-
- /* Read the integer part */
- for (; lexeme[i] && isdigit((uint8_t)lexeme[i]); i++)
- num_digits++;
-
- /* Check for the optional decimal point */
- if ('.' == lexeme[i]) {
- i++;
- /* Check for any digits after the decimal point */
- for (; lexeme[i] && isdigit((uint8_t)lexeme[i]); i++)
- num_digits++;
- }
-
- /*
- * The number of digits in both the decimal part and the
- * fraction part must not be zero at this point
- */
- if (!num_digits)
- return false;
-
- /* Check if we are done */
- if (!lexeme[i])
- return true;
-
- /* There is still more input, read the exponent */
- if ('e' == tolower((uint8_t)lexeme[i])) {
- i++;
-
- /* Read an optional Sign */
- if ('+' == lexeme[i] || '-' == lexeme[i]) {
- i++;
- }
-
- /* Now read the exponent part */
- while (lexeme[i] && isdigit((uint8_t)lexeme[i]))
- i++;
-
- }
-
- /* Allow trailing multipliers */
- while (lexeme[i] && ERA_SUFFIX(lexeme[i])) {
- i++;
- }
-
- /* Check if we are done */
- if (!lexeme[i])
- return true;
- else
- return false;
+ unsigned int num_digits = 0; // Number of digits read
+ unsigned int i;
+
+ i = 0;
+
+ // Check for an optional '+' or '-'
+ if ('+' == lexeme[i] || '-' == lexeme[i]) {
+ i++;
+ }
+
+ // Read the integer part
+ for (; lexeme[i] && isdigit((uint8_t)lexeme[i]); i++)
+ num_digits++;
+
+ // Check for the optional decimal point
+ if ('.' == lexeme[i]) {
+ i++;
+ // Check for any digits after the decimal point
+ for (; lexeme[i] && isdigit((uint8_t)lexeme[i]); i++)
+ num_digits++;
+ }
+
+ /*
+ * The number of digits in both the decimal part and the
+ * fraction part must not be zero at this point
+ */
+ if (!num_digits)
+ return false;
+
+ // Check if we are done
+ if (!lexeme[i])
+ return true;
+
+ // There is still more input, read the exponent
+ if ('e' == tolower((uint8_t)lexeme[i])) {
+ i++;
+
+ // Read an optional Sign
+ if ('+' == lexeme[i] || '-' == lexeme[i]) {
+ i++;
+ }
+
+ // Now read the exponent part
+ while (lexeme[i] && isdigit((uint8_t)lexeme[i]))
+ i++;
+
+ }
+
+ // Allow trailing multipliers
+ while (lexeme[i] && ERA_SUFFIX(lexeme[i])) {
+ i++;
+ }
+
+ // Check if we are done
+ if (!lexeme[i])
+ return true;
+ else
+ return false;
}
-/* is_special() - Test whether a character is a token */
+// is_special() - Test whether a character is a token
static inline bool
is_special(
- int ch
- )
+ int ch
+ )
{
- return strchr(special_chars, ch) != NULL;
+ return strchr(special_chars, ch) != NULL;
}
static bool
is_EOC(
- int ch
- )
+ int ch
+ )
{
- if ( ch == '\n')
- return true;
- return false;
+ if ( ch == '\n')
+ return true;
+ return false;
}
char *
quote_if_needed(char *str) {
- char *ret;
- size_t len;
- size_t octets;
-
- len = strlen(str);
- octets = len + 2 + 1;
- ret = emalloc(octets);
- if ('"' != str[0]
- && (strcspn(str, special_chars) < len
- || strchr(str, ' ') != NULL)) {
- snprintf(ret, octets, "\"%s\"", str);
- } else {
- strlcpy(ret, str, octets);
- }
-
- return ret;
+ char *ret;
+ size_t len;
+ size_t octets;
+
+ len = strlen(str);
+ octets = len + 2 + 1;
+ ret = emalloc(octets);
+ if ('"' != str[0]
+ && (strcspn(str, special_chars) < len
+ || strchr(str, ' ') != NULL)) {
+ snprintf(ret, octets, "\"%s\"", str);
+ } else {
+ strlcpy(ret, str, octets);
+ }
+
+ return ret;
}
static int
create_string_token(
- char *lexeme
- )
+ char *lexeme
+ )
{
- char *pch;
-
- /*
- * ignore end of line whitespace
- */
- pch = lexeme;
- while (*pch && isspace((uint8_t)*pch))
- pch++;
-
- if (!*pch) {
- yylval.Integer = T_EOC;
- return yylval.Integer;
- }
-
- yylval.String = estrdup(lexeme);
- return T_String;
+ char *pch;
+
+ /*
+ * ignore end of line whitespace
+ */
+ pch = lexeme;
+ while (*pch && isspace((uint8_t)*pch))
+ pch++;
+
+ if (!*pch) {
+ yylval.Integer = T_EOC;
+ return yylval.Integer;
+ }
+
+ yylval.String = estrdup(lexeme);
+ return T_String;
}
@@ -793,277 +793,277 @@ create_string_token(
int
yylex(void)
{
- static follby followedby = FOLLBY_TOKEN;
- int i;
- bool instring;
- bool yylval_was_set;
- int converted;
- int token; /* The return value */
- int ch;
-
- instring = false;
- yylval_was_set = false;
-
- do {
- /* Ignore whitespace at the beginning */
- while (EOF != (ch = lex_getch(lex_stack)) &&
- isspace(ch) &&
- !is_EOC(ch))
-
- ; /* Null Statement */
-
- if (EOF == ch) {
-
- if ( ! lex_pop_file())
- return 0;
- token = T_EOC;
- goto normal_return;
-
- } else if (is_EOC(ch)) {
-
- /* end FOLLBY_STRINGS_TO_EOC effect */
- followedby = FOLLBY_TOKEN;
- token = T_EOC;
- goto normal_return;
-
- } else if (is_special(ch) && FOLLBY_TOKEN == followedby) {
- /* special chars are their own token values */
- token = ch;
- /*
- * '=' outside simulator configuration implies
- * a single string following as in:
- * setvar Owner = "The Boss" default
- */
- if ('=' == ch ) {
- followedby = FOLLBY_STRING;
- }
- yytext[0] = (char)ch;
- yytext[1] = '\0';
- goto normal_return;
- } else
- lex_ungetch(ch, lex_stack);
-
- /* save the position of start of the token */
- lex_stack->tokpos = lex_stack->curpos;
-
- /* Read in the lexeme */
- i = 0;
- while (EOF != (ch = lex_getch(lex_stack))) {
-
- yytext[i] = (char)ch;
-
- /* Break on whitespace or a special character */
- if (isspace(ch) || is_EOC(ch)
- || '"' == ch
- || (FOLLBY_TOKEN == followedby
- && is_special(ch)))
- break;
-
- /* Read the rest of the line on reading a start
- of comment character */
- if ('#' == ch) {
- while (EOF != (ch = lex_getch(lex_stack))
- && '\n' != ch) {
- ; /* Null Statement */
- }
- break;
- }
-
- i++;
- if (i >= (int)COUNTOF(yytext)) {
- goto lex_too_long;
- }
- }
- /* Pick up all of the string inside between " marks, to
- * end of line. If we make it to EOL without a
- * terminating " assume it for them.
- *
- * XXX - HMS: I'm not sure we want to assume the closing "
- */
- if ('"' == ch) {
- instring = true;
- while (EOF != (ch = lex_getch(lex_stack)) &&
- ch != '"' && ch != '\n') {
- yytext[i++] = (char)ch;
- if (i >= (int)COUNTOF(yytext)) {
- goto lex_too_long;
- }
- }
- /*
- * yytext[i] will be pushed back as not part of
- * this lexeme, but any closing quote should
- * not be pushed back, so we read another char.
- */
- if ('"' == ch) {
- ch = lex_getch(lex_stack);
- }
- }
- /* Pushback the last character read that is not a part
- * of this lexeme. This fails silently if ch is EOF,
- * but then the EOF condition persists and is handled on
- * the next turn by the include stack mechanism.
- */
- lex_ungetch(ch, lex_stack);
-
- yytext[i] = '\0';
- } while (i == 0);
-
- /* Now return the desired token */
-
- /* First make sure that the parser is *not* expecting a string
- * as the next token (based on the previous token that was
- * returned) and that we haven't read a string.
- */
-
- if (followedby == FOLLBY_TOKEN && !instring) {
- token = is_keyword(yytext, &followedby);
- if (token) {
- goto normal_return;
- } else if (is_integer(yytext)) {
- yylval_was_set = true;
- errno = 0;
- yylval.Integer = (int)strtol(yytext, NULL, 10);
- if (yylval.Integer == 0
- && ((errno == EINVAL) || (errno == ERANGE))) {
- msyslog(LOG_ERR,
- "CONFIG: Integer cannot be represented: %s",
- yytext);
- if (lex_from_file()) {
- exit(1);
- } else {
- /* force end of parsing */
- yylval.Integer = 0;
- return 0;
- }
- }
- token = T_Integer;
- goto normal_return;
- } else if (is_u_int(yytext)) {
- yylval_was_set = true;
- if ('0' == yytext[0] &&
- 'x' == tolower((int)yytext[1]))
- converted = sscanf(&yytext[2], "%x",
- &yylval.U_int);
- else
- converted = sscanf(yytext, "%u",
- &yylval.U_int);
- if (1 != converted) {
- msyslog(LOG_ERR,
- "CONFIG: U_int cannot be represented: %s",
- yytext);
- if (lex_from_file()) {
- exit(1);
- } else {
- /* force end of parsing */
- yylval.Integer = 0;
- return 0;
- }
- }
- token = T_U_int;
- goto normal_return;
- } else if (is_double(yytext)) {
- double era_offset = 0;
- yylval_was_set = true;
- errno = 0;
- while (ERA_SUFFIX(yytext[strlen(yytext)-1])) {
- if (yytext[strlen(yytext)-1] == 'g') {
- era_offset += GPS_ERA_10BIT;
- }
- if (yytext[strlen(yytext)-1] == 'G') {
- era_offset += GPS_ERA_13BIT;
- }
- yytext[strlen(yytext)-1] = '\0';
- }
- yylval.Double = era_offset + atof(yytext);
- if ( D_ISZERO_NS(yylval.Double) && errno == ERANGE) {
- /* FIXME, POSIX says atof() never returns errors */
- msyslog(LOG_ERR,
- "CONFIG: Double too large to represent: %s",
- yytext);
- exit(1);
- } else {
- token = T_Double;
- goto normal_return;
- }
- } else {
- /* Default: Everything is a string */
- yylval_was_set = true;
- token = create_string_token(yytext);
- goto normal_return;
- }
- }
-
- /*
- * Either followedby is not FOLLBY_TOKEN or this lexeme is part
- * of a string. Hence, we need to return T_String.
- *
- * _Except_ we might have a -4 or -6 flag on a an association
- * configuration line (server, peer, pool, etc.).
- *
- * This is a terrible hack, but the grammar is ambiguous so we
- * don't have a choice. [SK]
- *
- * The ambiguity is in the keyword scanner, not ntp_parser.y.
- * We do not require server addresses be quoted in ntp.conf,
- * complicating the scanner's job. To avoid trying (and
- * failing) to match an IP address or DNS name to a keyword,
- * the association keywords use FOLLBY_STRING in the keyword
- * table, which tells the scanner to force the next token to be
- * a T_String, so it does not try to match a keyword but rather
- * expects a string when -4/-6 modifiers to server, peer, etc.
- * are encountered.
- * restrict -4 and restrict -6 parsing works correctly without
- * this hack, as restrict uses FOLLBY_TOKEN. [DH]
- */
- if ('-' == yytext[0]) {
- if ('4' == yytext[1]) {
- token = T_Ipv4_flag;
- goto normal_return;
- } else if ('6' == yytext[1]) {
- token = T_Ipv6_flag;
- goto normal_return;
- }
- }
-
- instring = false;
- if (FOLLBY_STRING == followedby) {
- followedby = FOLLBY_TOKEN;
- }
-
- yylval_was_set = true;
- token = create_string_token(yytext);
+ static follby followedby = FOLLBY_TOKEN;
+ int i;
+ bool instring;
+ bool yylval_was_set;
+ int converted;
+ int token; // The return value
+ int ch;
+
+ instring = false;
+ yylval_was_set = false;
+
+ do {
+ // Ignore whitespace at the beginning
+ while (EOF != (ch = lex_getch(lex_stack)) &&
+ isspace(ch) &&
+ !is_EOC(ch))
+
+ ; // Null Statement
+
+ if (EOF == ch) {
+
+ if ( ! lex_pop_file())
+ return 0;
+ token = T_EOC;
+ goto normal_return;
+
+ } else if (is_EOC(ch)) {
+
+ // end FOLLBY_STRINGS_TO_EOC effect
+ followedby = FOLLBY_TOKEN;
+ token = T_EOC;
+ goto normal_return;
+
+ } else if (is_special(ch) && FOLLBY_TOKEN == followedby) {
+ // special chars are their own token values
+ token = ch;
+ /*
+ * '=' outside simulator configuration implies
+ * a single string following as in:
+ * setvar Owner = "The Boss" default
+ */
+ if ('=' == ch ) {
+ followedby = FOLLBY_STRING;
+ }
+ yytext[0] = (char)ch;
+ yytext[1] = '\0';
+ goto normal_return;
+ } else
+ lex_ungetch(ch, lex_stack);
+
+ // save the position of start of the token
+ lex_stack->tokpos = lex_stack->curpos;
+
+ // Read in the lexeme
+ i = 0;
+ while (EOF != (ch = lex_getch(lex_stack))) {
+
+ yytext[i] = (char)ch;
+
+ // Break on whitespace or a special character
+ if (isspace(ch) || is_EOC(ch)
+ || '"' == ch
+ || (FOLLBY_TOKEN == followedby
+ && is_special(ch)))
+ break;
+
+ /* Read the rest of the line on reading a start
+ of comment character */
+ if ('#' == ch) {
+ while (EOF != (ch = lex_getch(lex_stack))
+ && '\n' != ch) {
+ ; // Null Statement
+ }
+ break;
+ }
+
+ i++;
+ if (i >= (int)COUNTOF(yytext)) {
+ goto lex_too_long;
+ }
+ }
+ /* Pick up all of the string inside between " marks, to
+ * end of line. If we make it to EOL without a
+ * terminating " assume it for them.
+ *
+ * XXX - HMS: I'm not sure we want to assume the closing "
+ */
+ if ('"' == ch) {
+ instring = true;
+ while (EOF != (ch = lex_getch(lex_stack)) &&
+ ch != '"' && ch != '\n') {
+ yytext[i++] = (char)ch;
+ if (i >= (int)COUNTOF(yytext)) {
+ goto lex_too_long;
+ }
+ }
+ /*
+ * yytext[i] will be pushed back as not part of
+ * this lexeme, but any closing quote should
+ * not be pushed back, so we read another char.
+ */
+ if ('"' == ch) {
+ ch = lex_getch(lex_stack);
+ }
+ }
+ /* Pushback the last character read that is not a part
+ * of this lexeme. This fails silently if ch is EOF,
+ * but then the EOF condition persists and is handled on
+ * the next turn by the include stack mechanism.
+ */
+ lex_ungetch(ch, lex_stack);
+
+ yytext[i] = '\0';
+ } while (i == 0);
+
+ // Now return the desired token
+
+ /* First make sure that the parser is *not* expecting a string
+ * as the next token (based on the previous token that was
+ * returned) and that we haven't read a string.
+ */
+
+ if (followedby == FOLLBY_TOKEN && !instring) {
+ token = is_keyword(yytext, &followedby);
+ if (token) {
+ goto normal_return;
+ } else if (is_integer(yytext)) {
+ yylval_was_set = true;
+ errno = 0;
+ yylval.Integer = (int)strtol(yytext, NULL, 10);
+ if (yylval.Integer == 0
+ && ((errno == EINVAL) || (errno == ERANGE))) {
+ msyslog(LOG_ERR,
+ "CONFIG: Integer cannot be represented: %s",
+ yytext);
+ if (lex_from_file()) {
+ exit(1);
+ } else {
+ // force end of parsing
+ yylval.Integer = 0;
+ return 0;
+ }
+ }
+ token = T_Integer;
+ goto normal_return;
+ } else if (is_u_int(yytext)) {
+ yylval_was_set = true;
+ if ('0' == yytext[0] &&
+ 'x' == tolower((int)yytext[1]))
+ converted = sscanf(&yytext[2], "%x",
+ &yylval.U_int);
+ else
+ converted = sscanf(yytext, "%u",
+ &yylval.U_int);
+ if (1 != converted) {
+ msyslog(LOG_ERR,
+ "CONFIG: U_int cannot be represented: %s",
+ yytext);
+ if (lex_from_file()) {
+ exit(1);
+ } else {
+ // force end of parsing
+ yylval.Integer = 0;
+ return 0;
+ }
+ }
+ token = T_U_int;
+ goto normal_return;
+ } else if (is_double(yytext)) {
+ double era_offset = 0;
+ yylval_was_set = true;
+ errno = 0;
+ while (ERA_SUFFIX(yytext[strlen(yytext)-1])) {
+ if (yytext[strlen(yytext)-1] == 'g') {
+ era_offset += GPS_ERA_10BIT;
+ }
+ if (yytext[strlen(yytext)-1] == 'G') {
+ era_offset += GPS_ERA_13BIT;
+ }
+ yytext[strlen(yytext)-1] = '\0';
+ }
+ yylval.Double = era_offset + atof(yytext);
+ if ( D_ISZERO_NS(yylval.Double) && errno == ERANGE) {
+ // FIXME, POSIX says atof() never returns errors
+ msyslog(LOG_ERR,
+ "CONFIG: Double too large to represent: %s",
+ yytext);
+ exit(1);
+ } else {
+ token = T_Double;
+ goto normal_return;
+ }
+ } else {
+ // Default: Everything is a string
+ yylval_was_set = true;
+ token = create_string_token(yytext);
+ goto normal_return;
+ }
+ }
+
+ /*
+ * Either followedby is not FOLLBY_TOKEN or this lexeme is part
+ * of a string. Hence, we need to return T_String.
+ *
+ * _Except_ we might have a -4 or -6 flag on a an association
+ * configuration line (server, peer, pool, etc.).
+ *
+ * This is a terrible hack, but the grammar is ambiguous so we
+ * don't have a choice. [SK]
+ *
+ * The ambiguity is in the keyword scanner, not ntp_parser.y.
+ * We do not require server addresses be quoted in ntp.conf,
+ * complicating the scanner's job. To avoid trying (and
+ * failing) to match an IP address or DNS name to a keyword,
+ * the association keywords use FOLLBY_STRING in the keyword
+ * table, which tells the scanner to force the next token to be
+ * a T_String, so it does not try to match a keyword but rather
+ * expects a string when -4/-6 modifiers to server, peer, etc.
+ * are encountered.
+ * restrict -4 and restrict -6 parsing works correctly without
+ * this hack, as restrict uses FOLLBY_TOKEN. [DH]
+ */
+ if ('-' == yytext[0]) {
+ if ('4' == yytext[1]) {
+ token = T_Ipv4_flag;
+ goto normal_return;
+ } else if ('6' == yytext[1]) {
+ token = T_Ipv6_flag;
+ goto normal_return;
+ }
+ }
+
+ instring = false;
+ if (FOLLBY_STRING == followedby) {
+ followedby = FOLLBY_TOKEN;
+ }
+
+ yylval_was_set = true;
+ token = create_string_token(yytext);
normal_return:
- if (T_EOC == token)
- DPRINT(4,("\t<end of command>\n"));
- else
- DPRINT(4, ("yylex: lexeme '%s' -> %s\n", yytext,
- token_name(token)));
+ if (T_EOC == token)
+ DPRINT(4,("\t<end of command>\n"));
+ else
+ DPRINT(4, ("yylex: lexeme '%s' -> %s\n", yytext,
+ token_name(token)));
- if (!yylval_was_set)
- yylval.Integer = token;
+ if (!yylval_was_set)
+ yylval.Integer = token;
- return token;
+ return token;
lex_too_long:
- yytext[min(sizeof(yytext) - 1, 50)] = 0;
- msyslog(LOG_ERR,
- "CONFIG: configuration item on line %d longer than limit of %lu, began with '%s'",
- lex_stack->curpos.nline, (unsigned long)min(sizeof(yytext) - 1, 50),
- yytext);
-
- /*
- * If we hit the length limit reading the startup configuration
- * file, abort.
- */
- if (lex_from_file())
- exit(sizeof(yytext) - 1);
-
- /*
- * If it's runtime configuration via ntpq :config treat it as
- * if the configuration text ended before the too-long lexeme,
- * hostname, or string.
- */
- yylval.Integer = 0;
- return 0;
+ yytext[min(sizeof(yytext) - 1, 50)] = 0;
+ msyslog(LOG_ERR,
+ "CONFIG: configuration item on line %d longer than limit of %lu, began with '%s'",
+ lex_stack->curpos.nline, (unsigned long)min(sizeof(yytext) - 1, 50),
+ yytext);
+
+ /*
+ * If we hit the length limit reading the startup configuration
+ * file, abort.
+ */
+ if (lex_from_file())
+ exit(sizeof(yytext) - 1);
+
+ /*
+ * If it's runtime configuration via ntpq :config treat it as
+ * if the configuration text ended before the too-long lexeme,
+ * hostname, or string.
+ */
+ yylval.Integer = 0;
+ return 0;
}
=====================================
ntpd/refclock_truetime.c
=====================================
@@ -1,6 +1,6 @@
/*
* refclock_true - clock driver for the Kinemetrics/TrueTime receivers
- * Receiver Version 3.0C - tested plain, with CLKLDISC
+ * Receiver Version 3.0C - tested plain, with CLKLDISC
*/
#include "config.h"
@@ -26,20 +26,20 @@
* the PPS event and our being called.)
*/
#ifdef ENABLE_PPS720
-# undef min /* XXX */
-# undef max /* XXX */
+# undef min // XXX
+# undef max // XXX
# include <machine/inline.h>
# include <sys/pcl720.h>
# include <sys/i8253.h>
-# define PCL720_IOB 0x2a0 /* XXX */
-# define PCL720_CTR 0 /* XXX */
+# define PCL720_IOB 0x2a0 // XXX
+# define PCL720_CTR 0 // XXX
#endif
/*
* Support for Kinemetrics Truetime Receivers
- * GPS/TM-TMD:
- * XL-DC: (a 151-602-210, reported by the driver as a GPS/TM-TMD)
- * GPS-800 TCU: (an 805-957 with the RS232 Talker/Listener module)
+ * GPS/TM-TMD:
+ * XL-DC: (a 151-602-210, reported by the driver as a GPS/TM-TMD)
+ * GPS-800 TCU: (an 805-957 with the RS232 Talker/Listener module)
*
* WARNING: This driver depends on the system clock for year disambiguation.
* It will thus not be usable for recovery if the system clock is trashed.
@@ -49,15 +49,15 @@
* It has been so mangled that wwvb is not a recognizable ancestor.
*
* Timcode format: ADDD:HH:MM:SSQCL
- * A - control A (this is stripped before we see it)
- * Q - Quality indication (see below)
- * C - Carriage return
- * L - Line feed
+ * A - control A (this is stripped before we see it)
+ * Q - Quality indication (see below)
+ * C - Carriage return
+ * L - Line feed
*
* Quality codes indicate possible error of
* GPS-TM/TMD Receiver: (default quality codes for XL-DC)
- * ? +/- 1 milliseconds # +/- 100 microseconds
- * * +/- 10 microseconds . +/- 1 microsecond
+ * ? +/- 1 milliseconds # +/- 100 microseconds
+ * * +/- 10 microseconds . +/- 1 microsecond
* space less than 1 microsecond
* TL-3 Receiver: (default quality codes for TL-3)
* ? unknown quality (receiver is unlocked)
@@ -74,33 +74,33 @@
/*
* Definitions
*/
-#define DEVICE "/dev/true%d"
-#define SPEED232 B9600 /* 9600 baud */
+#define DEVICE "/dev/true%d"
+#define SPEED232 B9600 // 9600 baud
/*
* Radio interface parameters
*/
-#define PRECISION (-10) /* precision assumed (about 1 ms) */
-#define REFID "TRUE" /* reference id */
-#define NAME "TRUETIME" /* shortname */
-#define DESCRIPTION "Kinemetrics/TrueTime Receiver"
+#define PRECISION (-10) // precision assumed (about 1 ms)
+#define REFID "TRUE" // reference id
+#define NAME "TRUETIME" // shortname
+#define DESCRIPTION "Kinemetrics/TrueTime Receiver"
/*
* used by the state machine
*/
-enum true_event {e_Init, e_Huh, e_F18, e_F50, e_F51,
- e_Location, e_TS, e_Max};
+enum true_event {e_Init, e_Huh, e_F18, e_F50, e_F51,
+ e_Location, e_TS, e_Max};
static const char *events[] = {"Init", "Huh", "F18", "F50", "F51",
- "Location", "TS"};
+ "Location", "TS"};
#define eventStr(x) (((int)x<(int)e_Max) ? events[(int)x] : "?")
-enum true_state {s_Base, s_InqTM, s_InqTCU, s_InqGOES,
- s_Init, s_F18, s_F50, s_Start, s_Auto, s_Max};
+enum true_state {s_Base, s_InqTM, s_InqTCU, s_InqGOES,
+ s_Init, s_F18, s_F50, s_Start, s_Auto, s_Max};
static const char *states[] = {"Base", "InqTM", "InqTCU", "InqGOES",
- "Init", "F18", "F50", "Start", "Auto"};
+ "Init", "F18", "F50", "Start", "Auto"};
#define stateStr(x) (((int)x<(int)s_Max) ? states[(int)x] : "?")
-enum true_type {t_unknown, t_tm, t_tcu, t_tl3, t_Max};
+enum true_type {t_unknown, t_tm, t_tcu, t_tl3, t_Max};
static const char *types[] = {"unknown", "tm", "tcu", "tl3"};
#define typeStr(x) (((int)x<(int)t_Max) ? types[(int)x] : "?")
@@ -108,42 +108,42 @@ static const char *types[] = {"unknown", "tm", "tcu", "tl3"};
* unit control structure
*/
struct true_unit {
- unsigned int pollcnt; /* poll message counter */
- unsigned int station; /* which station we are on */
- bool polled; /* Hand in a time sample? */
- enum true_state state; /* state machine */
- enum true_type type; /* what kind of clock is it? */
- int unit; /* save an extra copy of this */
- FILE *debug; /* debug logging file */
+ unsigned int pollcnt; // poll message counter
+ unsigned int station; // which station we are on
+ bool polled; // Hand in a time sample?
+ enum true_state state; // state machine
+ enum true_type type; // what kind of clock is it?
+ int unit; // save an extra copy of this
+ FILE *debug; // debug logging file
#ifdef ENABLE_PPS720
- int pcl720init; /* init flag for PCL 720 */
+ int pcl720init; // init flag for PCL 720
#endif
};
/*
* Function prototypes
*/
-static bool true_start (int, struct peer *);
-static void true_receive (struct recvbuf *);
-static void true_poll (int, struct peer *);
-static void true_send (struct peer *, const char *);
-static void true_doevent (struct peer *, enum true_event);
+static bool true_start (int, struct peer *);
+static void true_receive (struct recvbuf *);
+static void true_poll (int, struct peer *);
+static void true_send (struct peer *, const char *);
+static void true_doevent (struct peer *, enum true_event);
#ifdef ENABLE_PPS720
-static unsigned long true_sample720 (void);
+static unsigned long true_sample720 (void);
#endif
/*
* Transfer vector
*/
-struct refclock refclock_true = {
- NAME, /* basename of driver */
- true_start, /* start up driver */
- NULL, /* shut down driver in the stabdard way */
- true_poll, /* transmit poll message */
- NULL, /* not used (old true_control) */
- NULL, /* initialize driver (not used) */
- NULL /* timer - not used */
+struct refclock refclock_true = {
+ NAME, // basename of driver
+ true_start, // start up driver
+ NULL, // shut down driver in the stabdard way
+ true_poll, // transmit poll message
+ NULL, // not used (old true_control)
+ NULL, // initialize driver (not used)
+ NULL // timer - not used
};
@@ -151,43 +151,43 @@ NTP_PRINTF(2, 3)
static void
true_debug(struct peer *peer, const char *fmt, ...)
{
- va_list ap;
- int want_debugging, now_debugging;
- struct refclockproc *pp;
- struct true_unit *up;
-
- va_start(ap, fmt);
- pp = peer->procptr;
- up = pp->unitptr;
-
- want_debugging = (pp->sloppyclockflag & CLK_FLAG2) != 0;
- now_debugging = (up->debug != NULL);
- if (want_debugging != now_debugging)
- {
- if (want_debugging) {
- char filename[40];
- int fd;
-
- snprintf(filename, sizeof(filename),
- "/tmp/true%d.debug", up->unit);
- fd = open(filename, O_CREAT | O_WRONLY | O_EXCL,
- 0600);
- if (fd >= 0 && (up->debug = fdopen(fd, "w"))) {
- static char buf[BUFSIZ];
-
- setvbuf(up->debug, buf, _IOLBF, BUFSIZ);
- }
- } else {
- fclose(up->debug);
- up->debug = NULL;
- }
- }
-
- if (up->debug) {
- fprintf(up->debug, "true%d: ", up->unit);
- vfprintf(up->debug, fmt, ap);
- }
- va_end(ap);
+ va_list ap;
+ int want_debugging, now_debugging;
+ struct refclockproc *pp;
+ struct true_unit *up;
+
+ va_start(ap, fmt);
+ pp = peer->procptr;
+ up = pp->unitptr;
+
+ want_debugging = (pp->sloppyclockflag & CLK_FLAG2) != 0;
+ now_debugging = (up->debug != NULL);
+ if (want_debugging != now_debugging)
+ {
+ if (want_debugging) {
+ char filename[40];
+ int fd;
+
+ snprintf(filename, sizeof(filename),
+ "/tmp/true%d.debug", up->unit);
+ fd = open(filename, O_CREAT | O_WRONLY | O_EXCL,
+ 0600);
+ if (fd >= 0 && (up->debug = fdopen(fd, "w"))) {
+ static char buf[BUFSIZ];
+
+ setvbuf(up->debug, buf, _IOLBF, BUFSIZ);
+ }
+ } else {
+ fclose(up->debug);
+ up->debug = NULL;
+ }
+ }
+
+ if (up->debug) {
+ fprintf(up->debug, "true%d: ", up->unit);
+ vfprintf(up->debug, fmt, ap);
+ }
+ va_end(ap);
}
/*
@@ -195,64 +195,64 @@ true_debug(struct peer *peer, const char *fmt, ...)
*/
static bool
true_start(
- int unit,
- struct peer *peer
- )
+ int unit,
+ struct peer *peer
+ )
{
- struct true_unit *up;
- struct refclockproc *pp;
- char device[40];
- int fd;
-
- /*
- * Open serial port
- */
- snprintf(device, sizeof(device), DEVICE, unit);
- fd = refclock_open(peer->cfg.path ? peer->cfg.path : device,
- peer->cfg.baud ? peer->cfg.baud : SPEED232, LDISC_STD);
- if (fd <= 0)
- /* coverity[leaked_handle] */
- return false;
-
- /*
- * Allocate and initialize unit structure
- */
- up = emalloc_zero(sizeof(*up));
- pp = peer->procptr;
- pp->io.clock_recv = true_receive;
- pp->io.srcclock = peer;
- pp->io.datalen = 0;
- pp->io.fd = fd;
- if (!io_addclock(&pp->io)) {
- close(fd);
- pp->io.fd = -1;
- free(up);
- return false;
- }
- pp->unitptr = up;
-
- /*
- * Initialize miscellaneous variables
- */
- peer->precision = PRECISION;
- pp->clockname = NAME;
- pp->clockdesc = DESCRIPTION;
- memcpy(&pp->refid, REFID, REFIDLEN);
- peer->sstclktype = CTL_SST_TS_UHF;
- up->pollcnt = 2;
- up->type = t_unknown;
- up->state = s_Base;
-
- /*
- * Send a CTRL-C character at the start,
- * just in case the clock is already
- * sending timecodes
- */
- true_send(peer, "\03\r");
-
- true_doevent(peer, e_Init);
-
- return true;
+ struct true_unit *up;
+ struct refclockproc *pp;
+ char device[40];
+ int fd;
+
+ /*
+ * Open serial port
+ */
+ snprintf(device, sizeof(device), DEVICE, unit);
+ fd = refclock_open(peer->cfg.path ? peer->cfg.path : device,
+ peer->cfg.baud ? peer->cfg.baud : SPEED232, LDISC_STD);
+ if (fd <= 0)
+ // coverity[leaked_handle]
+ return false;
+
+ /*
+ * Allocate and initialize unit structure
+ */
+ up = emalloc_zero(sizeof(*up));
+ pp = peer->procptr;
+ pp->io.clock_recv = true_receive;
+ pp->io.srcclock = peer;
+ pp->io.datalen = 0;
+ pp->io.fd = fd;
+ if (!io_addclock(&pp->io)) {
+ close(fd);
+ pp->io.fd = -1;
+ free(up);
+ return false;
+ }
+ pp->unitptr = up;
+
+ /*
+ * Initialize miscellaneous variables
+ */
+ peer->precision = PRECISION;
+ pp->clockname = NAME;
+ pp->clockdesc = DESCRIPTION;
+ memcpy(&pp->refid, REFID, REFIDLEN);
+ peer->sstclktype = CTL_SST_TS_UHF;
+ up->pollcnt = 2;
+ up->type = t_unknown;
+ up->state = s_Base;
+
+ /*
+ * Send a CTRL-C character at the start,
+ * just in case the clock is already
+ * sending timecodes
+ */
+ true_send(peer, "\03\r");
+
+ true_doevent(peer, e_Init);
+
+ return true;
}
@@ -261,213 +261,213 @@ true_start(
*/
static void
true_receive(
- struct recvbuf *rbufp
- )
+ struct recvbuf *rbufp
+ )
{
- struct true_unit *up;
- struct refclockproc *pp;
- struct peer *peer;
- char synced;
- int i;
- /* These variables hold data until we decide to keep it */
- char rd_lastcode[BMAX];
- l_fp rd_tmp;
- unsigned short rd_lencode;
-
- /*
- * Get the clock this applies to and pointers to the data.
- */
- peer = rbufp->recv_peer;
- pp = peer->procptr;
- up = pp->unitptr;
-
- /*
- * Read clock output. Automatically handles CLKLDISC.
- */
- rd_lencode = (unsigned short)refclock_gtlin(rbufp, rd_lastcode, BMAX, &rd_tmp);
- rd_lastcode[rd_lencode] = '\0';
-
- /*
- * There is a case where <cr><lf> generates 2 timestamps.
- */
- if (rd_lencode == 0) {
- return;
+ struct true_unit *up;
+ struct refclockproc *pp;
+ struct peer *peer;
+ char synced;
+ int i;
+ // These variables hold data until we decide to keep it
+ char rd_lastcode[BMAX];
+ l_fp rd_tmp;
+ unsigned short rd_lencode;
+
+ /*
+ * Get the clock this applies to and pointers to the data.
+ */
+ peer = rbufp->recv_peer;
+ pp = peer->procptr;
+ up = pp->unitptr;
+
+ /*
+ * Read clock output. Automatically handles CLKLDISC.
+ */
+ rd_lencode = (unsigned short)refclock_gtlin(rbufp, rd_lastcode, BMAX, &rd_tmp);
+ rd_lastcode[rd_lencode] = '\0';
+
+ /*
+ * There is a case where <cr><lf> generates 2 timestamps.
+ */
+ if (rd_lencode == 0) {
+ return;
}
- pp->lencode = rd_lencode;
- strlcpy(pp->a_lastcode, rd_lastcode, sizeof(pp->a_lastcode));
- pp->lastrec = rd_tmp;
- true_debug(peer, "receive(%s) [%d]\n", pp->a_lastcode,
- pp->lencode);
-
- up->pollcnt = 2;
- record_clock_stats(peer, pp->a_lastcode);
-
- /*
- * We get down to business, check the timecode format and decode
- * its contents. This code decodes a multitude of different
- * clock messages. Timecodes are processed if needed. All replies
- * will be run through the state machine to tweak driver options
- * and program the clock.
- */
-
- /*
- * Clock misunderstood our last command?
- */
- if (pp->a_lastcode[0] == '?' ||
- strcmp(pp->a_lastcode, "ERROR 05 NO SUCH FUNCTION") == 0) {
- true_doevent(peer, e_Huh);
- return;
- }
-
- /*
- * Timecode: "Fnn"
- * (from TM/TMD clock when it wants to tell us what it's up to.)
- */
- if (sscanf(pp->a_lastcode, "F%2d", &i) == 1 && i > 0 && i < 80) {
- switch (i) {
- case 50:
- true_doevent(peer, e_F50);
- break;
- case 51:
- true_doevent(peer, e_F51);
- break;
- default:
- true_debug(peer, "got F%02d - ignoring\n", i);
- break;
- }
- return;
- }
-
- /*
- * Timecode: " TRUETIME Mk III" or " TRUETIME XL"
- * (from a TM/TMD/XL clock during initialization.)
- */
- if (strncmp(pp->a_lastcode, " TRUETIME Mk III ", 17) == 0 ||
- strncmp(pp->a_lastcode, " TRUETIME XL", 12) == 0) {
- true_doevent(peer, e_F18);
- NLOG(NLOG_CLOCKSTATUS) {
- msyslog(LOG_INFO, "REFCLOCK: TM/TMD/XL: %s", pp->a_lastcode);
- }
- return;
- }
-
- /*
- * Timecode: "N03726428W12209421+000033"
- * 1 2
- * index 0123456789012345678901234
- * (from a TCU during initialization)
- */
- if ((pp->a_lastcode[0] == 'N' || pp->a_lastcode[0] == 'S') &&
- (pp->a_lastcode[9] == 'W' || pp->a_lastcode[9] == 'E') &&
- pp->a_lastcode[18] == '+') {
- true_doevent(peer, e_Location);
- NLOG(NLOG_CLOCKSTATUS) {
- msyslog(LOG_INFO, "REFCLOCK: TCU-800: %s", pp->a_lastcode);
- }
- return;
- }
- /*
- * Timecode: "ddd:hh:mm:ssQ"
- * 1 2
- * index 0123456789012345678901234
- * (from all clocks supported by this driver.)
- */
- if (pp->a_lastcode[3] == ':' &&
- pp->a_lastcode[6] == ':' &&
- pp->a_lastcode[9] == ':' &&
- sscanf(pp->a_lastcode, "%3d:%2d:%2d:%2d%c",
- &pp->yday, &pp->hour, &pp->minute,
- &pp->second, &synced) == 5) {
-
- /*
- * Adjust the synchronize indicator according to timecode
- * say were OK, and then say not if we really are not OK
- */
- if (synced == '>' || synced == '#' || synced == '?'
- || synced == 'X')
- pp->leap = LEAP_NOTINSYNC;
- else
- pp->leap = LEAP_NOWARNING;
-
- true_doevent(peer, e_TS);
+ pp->lencode = rd_lencode;
+ strlcpy(pp->a_lastcode, rd_lastcode, sizeof(pp->a_lastcode));
+ pp->lastrec = rd_tmp;
+ true_debug(peer, "receive(%s) [%d]\n", pp->a_lastcode,
+ pp->lencode);
+
+ up->pollcnt = 2;
+ record_clock_stats(peer, pp->a_lastcode);
+
+ /*
+ * We get down to business, check the timecode format and decode
+ * its contents. This code decodes a multitude of different
+ * clock messages. Timecodes are processed if needed. All replies
+ * will be run through the state machine to tweak driver options
+ * and program the clock.
+ */
+
+ /*
+ * Clock misunderstood our last command?
+ */
+ if (pp->a_lastcode[0] == '?' ||
+ strcmp(pp->a_lastcode, "ERROR 05 NO SUCH FUNCTION") == 0) {
+ true_doevent(peer, e_Huh);
+ return;
+ }
+
+ /*
+ * Timecode: "Fnn"
+ * (from TM/TMD clock when it wants to tell us what it's up to.)
+ */
+ if (sscanf(pp->a_lastcode, "F%2d", &i) == 1 && i > 0 && i < 80) {
+ switch (i) {
+ case 50:
+ true_doevent(peer, e_F50);
+ break;
+ case 51:
+ true_doevent(peer, e_F51);
+ break;
+ default:
+ true_debug(peer, "got F%02d - ignoring\n", i);
+ break;
+ }
+ return;
+ }
+
+ /*
+ * Timecode: " TRUETIME Mk III" or " TRUETIME XL"
+ * (from a TM/TMD/XL clock during initialization.)
+ */
+ if (strncmp(pp->a_lastcode, " TRUETIME Mk III ", 17) == 0 ||
+ strncmp(pp->a_lastcode, " TRUETIME XL", 12) == 0) {
+ true_doevent(peer, e_F18);
+ NLOG(NLOG_CLOCKSTATUS) {
+ msyslog(LOG_INFO, "REFCLOCK: TM/TMD/XL: %s", pp->a_lastcode);
+ }
+ return;
+ }
+
+ /*
+ * Timecode: "N03726428W12209421+000033"
+ * 1 2
+ * index 0123456789012345678901234
+ * (from a TCU during initialization)
+ */
+ if ((pp->a_lastcode[0] == 'N' || pp->a_lastcode[0] == 'S') &&
+ (pp->a_lastcode[9] == 'W' || pp->a_lastcode[9] == 'E') &&
+ pp->a_lastcode[18] == '+') {
+ true_doevent(peer, e_Location);
+ NLOG(NLOG_CLOCKSTATUS) {
+ msyslog(LOG_INFO, "REFCLOCK: TCU-800: %s", pp->a_lastcode);
+ }
+ return;
+ }
+ /*
+ * Timecode: "ddd:hh:mm:ssQ"
+ * 1 2
+ * index 0123456789012345678901234
+ * (from all clocks supported by this driver.)
+ */
+ if (pp->a_lastcode[3] == ':' &&
+ pp->a_lastcode[6] == ':' &&
+ pp->a_lastcode[9] == ':' &&
+ sscanf(pp->a_lastcode, "%3d:%2d:%2d:%2d%c",
+ &pp->yday, &pp->hour, &pp->minute,
+ &pp->second, &synced) == 5) {
+
+ /*
+ * Adjust the synchronize indicator according to timecode
+ * say were OK, and then say not if we really are not OK
+ */
+ if (synced == '>' || synced == '#' || synced == '?'
+ || synced == 'X')
+ pp->leap = LEAP_NOTINSYNC;
+ else
+ pp->leap = LEAP_NOWARNING;
+
+ true_doevent(peer, e_TS);
#ifdef ENABLE_PPS720
- /* If it's taken more than 65ms to get here, we'll lose. */
- if ((pp->sloppyclockflag & CLK_FLAG4) && up->pcl720init) {
- l_fp off;
+ // If it's taken more than 65ms to get here, we'll lose.
+ if ((pp->sloppyclockflag & CLK_FLAG4) && up->pcl720init) {
+ l_fp off;
#ifdef CLOCK_PPS
- uint32_t sec;
- /*
- * find out what time it really is. Include
- * the count from the PCL720
- */
- if (!clocktime(pp->year, pp->yday, pp->hour, pp->minute,
- pp->second, lfpuint(pp->lastrec),
- &pp->yearstart, &sec)) {
- refclock_report(peer, CEVNT_BADTIME);
- return;
- }
- off = lfpinut(sec, 0);
+ uint32_t sec;
+ /*
+ * find out what time it really is. Include
+ * the count from the PCL720
+ */
+ if (!clocktime(pp->year, pp->yday, pp->hour, pp->minute,
+ pp->second, lfpuint(pp->lastrec),
+ &pp->yearstart, &sec)) {
+ refclock_report(peer, CEVNT_BADTIME);
+ return;
+ }
+ off = lfpinut(sec, 0);
#endif
- pp->usec = true_sample720();
+ pp->usec = true_sample720();
#ifdef CLOCK_PPS
- TVUTOTSF(pp->usec, lfpfrac(off));
+ TVUTOTSF(pp->usec, lfpfrac(off));
#endif
- /*
- * Stomp all over the timestamp that was pulled out
- * of the input stream. It's irrelevant since we've
- * adjusted the input time to reflect now (via pp->usec)
- * rather than when the data was collected.
- */
- get_systime(&pp->lastrec);
+ /*
+ * Stomp all over the timestamp that was pulled out
+ * of the input stream. It's irrelevant since we've
+ * adjusted the input time to reflect now (via pp->usec)
+ * rather than when the data was collected.
+ */
+ get_systime(&pp->lastrec);
#ifdef CLOCK_PPS
- /*
- * Create a true offset for feeding to pps_sample()
- */
- off -= pp->lastrec;
+ /*
+ * Create a true offset for feeding to pps_sample()
+ */
+ off -= pp->lastrec;
- pps_sample(peer, &off);
+ pps_sample(peer, &off);
#endif
- true_debug(peer, "true_sample720: %luus\n", pp->usec);
- }
+ true_debug(peer, "true_sample720: %luus\n", pp->usec);
+ }
#endif
- /*
- * The clock will blurt a timecode every second but we only
- * want one when polled. If we haven't been polled, bail out.
- */
- if (!up->polled)
- return;
-
- if (!refclock_process(pp)) {
- refclock_report(peer, CEVNT_BADTIME);
- return;
- }
- /*
- * If clock is good we send a NOMINAL message so that
- * any previous BAD messages are nullified
- */
- pp->lastref = pp->lastrec;
- refclock_receive(peer);
- refclock_report(peer, CEVNT_NOMINAL);
-
- /*
- * We have succeeded in answering the poll.
- * Turn off the flag and return
- */
- up->polled = false;
-
- return;
- }
-
- /*
- * No match to known timecodes, report failure and return
- */
- refclock_report(peer, CEVNT_BADREPLY);
- return;
+ /*
+ * The clock will blurt a timecode every second but we only
+ * want one when polled. If we haven't been polled, bail out.
+ */
+ if (!up->polled)
+ return;
+
+ if (!refclock_process(pp)) {
+ refclock_report(peer, CEVNT_BADTIME);
+ return;
+ }
+ /*
+ * If clock is good we send a NOMINAL message so that
+ * any previous BAD messages are nullified
+ */
+ pp->lastref = pp->lastrec;
+ refclock_receive(peer);
+ refclock_report(peer, CEVNT_NOMINAL);
+
+ /*
+ * We have succeeded in answering the poll.
+ * Turn off the flag and return
+ */
+ up->polled = false;
+
+ return;
+ }
+
+ /*
+ * No match to known timecodes, report failure and return
+ */
+ refclock_report(peer, CEVNT_BADREPLY);
+ return;
}
@@ -476,24 +476,24 @@ true_receive(
*/
static void
true_send(
- struct peer *peer,
- const char *cmd
- )
+ struct peer *peer,
+ const char *cmd
+ )
{
- struct refclockproc *pp;
+ struct refclockproc *pp;
- pp = peer->procptr;
- if (!(pp->sloppyclockflag & CLK_FLAG1)) {
+ pp = peer->procptr;
+ if (!(pp->sloppyclockflag & CLK_FLAG1)) {
ssize_t ret;
- size_t len = strlen(cmd);
-
- true_debug(peer, "Send '%s'\n", cmd);
- ret = write(pp->io.fd, cmd, len);
- if (ret < 0 || (size_t)ret != len)
- refclock_report(peer, CEVNT_FAULT);
- else
- pp->polls++;
- }
+ size_t len = strlen(cmd);
+
+ true_debug(peer, "Send '%s'\n", cmd);
+ ret = write(pp->io.fd, cmd, len);
+ if (ret < 0 || (size_t)ret != len)
+ refclock_report(peer, CEVNT_FAULT);
+ else
+ pp->polls++;
+ }
}
@@ -502,34 +502,34 @@ true_send(
*/
static void
true_doevent(
- struct peer *peer,
- enum true_event event
- )
+ struct peer *peer,
+ enum true_event event
+ )
{
- struct true_unit *up;
- struct refclockproc *pp;
-
- pp = peer->procptr;
- up = pp->unitptr;
- if (event != e_TS) {
- NLOG(NLOG_CLOCKSTATUS) {
- msyslog(LOG_INFO, "REFCLOCK: TRUETIME: clock %s, state %s, event %s",
- typeStr(up->type),
- stateStr(up->state),
- eventStr(event));
- }
- }
- true_debug(peer, "clock %s, state %s, event %s\n",
- typeStr(up->type), stateStr(up->state), eventStr(event));
- switch (up->type) {
- case t_tm:
- switch (event) {
- case e_Init:
- true_send(peer, "F18\r");
- up->state = s_Init;
- break;
- case e_F18:
- true_send(peer, "F50\r");
+ struct true_unit *up;
+ struct refclockproc *pp;
+
+ pp = peer->procptr;
+ up = pp->unitptr;
+ if (event != e_TS) {
+ NLOG(NLOG_CLOCKSTATUS) {
+ msyslog(LOG_INFO, "REFCLOCK: TRUETIME: clock %s, state %s, event %s",
+ typeStr(up->type),
+ stateStr(up->state),
+ eventStr(event));
+ }
+ }
+ true_debug(peer, "clock %s, state %s, event %s\n",
+ typeStr(up->type), stateStr(up->state), eventStr(event));
+ switch (up->type) {
+ case t_tm:
+ switch (event) {
+ case e_Init:
+ true_send(peer, "F18\r");
+ up->state = s_Init;
+ break;
+ case e_F18:
+ true_send(peer, "F50\r");
/*
* Timecode: " TRUETIME Mk III" or " TRUETIME XL"
* (from a TM/TMD/XL clock during initialization.)
@@ -543,59 +543,59 @@ true_doevent(
}
return;
}
- up->state = s_F18;
- break;
- case e_F50:
- true_send(peer, "F51\r");
- up->state = s_F50;
- break;
- case e_F51:
- true_send(peer, "F08\r");
- up->state = s_Start;
- break;
- case e_TS:
- if (up->state != s_Start && up->state != s_Auto) {
- true_send(peer, "\03\r");
- break;
- }
- up->state = s_Auto;
- break;
- case e_Huh:
- case e_Location:
- case e_Max:
- default:
- break;
- }
- break;
- case t_tcu:
- switch (event) {
- case e_Init:
- true_send(peer, "MD3\r"); /* GPS Synch'd Gen. */
- true_send(peer, "TSU\r"); /* UTC, not GPS. */
- true_send(peer, "AU\r"); /* Auto Timestamps. */
- up->state = s_Start;
- break;
- case e_TS:
- if (up->state != s_Start && up->state != s_Auto) {
- true_send(peer, "\03\r");
- break;
- }
- up->state = s_Auto;
- break;
- case e_Huh:
- case e_F18:
- case e_F50:
- case e_F51:
- case e_Location:
- case e_Max:
- default:
- break;
- }
- break;
- case t_tl3:
+ up->state = s_F18;
+ break;
+ case e_F50:
+ true_send(peer, "F51\r");
+ up->state = s_F50;
+ break;
+ case e_F51:
+ true_send(peer, "F08\r");
+ up->state = s_Start;
+ break;
+ case e_TS:
+ if (up->state != s_Start && up->state != s_Auto) {
+ true_send(peer, "\03\r");
+ break;
+ }
+ up->state = s_Auto;
+ break;
+ case e_Huh:
+ case e_Location:
+ case e_Max:
+ default:
+ break;
+ }
+ break;
+ case t_tcu:
+ switch (event) {
+ case e_Init:
+ true_send(peer, "MD3\r"); // GPS Synch'd Gen.
+ true_send(peer, "TSU\r"); // UTC, not GPS.
+ true_send(peer, "AU\r"); // Auto Timestamps.
+ up->state = s_Start;
+ break;
+ case e_TS:
+ if (up->state != s_Start && up->state != s_Auto) {
+ true_send(peer, "\03\r");
+ break;
+ }
+ up->state = s_Auto;
+ break;
+ case e_Huh:
+ case e_F18:
+ case e_F50:
+ case e_F51:
+ case e_Location:
+ case e_Max:
+ default:
+ break;
+ }
+ break;
+ case t_tl3:
switch (event) {
case e_Init:
- true_send(peer, "ST1"); /* Turn on continuous stream */
+ true_send(peer, "ST1"); // Turn on continuous stream
break;
case e_TS:
up->state = s_Auto;
@@ -610,112 +610,112 @@ true_doevent(
break;
}
break;
- case t_unknown:
- switch (up->state) {
- case s_Base:
- if (event != e_Init) {
- abort();
- }
- true_send(peer, "P\r");
- up->state = s_InqGOES;
- break;
- case s_InqGOES:
- switch (event) {
- case e_Init: /*FALLTHROUGH*/
- case e_Huh:
- sleep(1); /* wait for it */
+ case t_unknown:
+ switch (up->state) {
+ case s_Base:
+ if (event != e_Init) {
+ abort();
+ }
+ true_send(peer, "P\r");
+ up->state = s_InqGOES;
+ break;
+ case s_InqGOES:
+ switch (event) {
+ case e_Init: // FALLTHROUGH
+ case e_Huh:
+ sleep(1); // wait for it
break;
- case e_F18:
- case e_F50:
- case e_F51:
- case e_TS:
- case e_Location:
- case e_Max:
+ case e_F18:
+ case e_F50:
+ case e_F51:
+ case e_TS:
+ case e_Location:
+ case e_Max:
default:
abort();
}
break;
- case s_InqTM:
- switch (event) {
- case e_F18:
- up->type = t_tm;
- true_doevent(peer, e_Init);
- break;
- case e_Init: /*FALLTHROUGH*/
- case e_Huh:
- true_send(peer, "PO\r");
- up->state = s_InqTCU;
- break;
- case e_F50:
- case e_F51:
- case e_Location:
- case e_TS:
- case e_Max:
- default:
+ case s_InqTM:
+ switch (event) {
+ case e_F18:
+ up->type = t_tm;
+ true_doevent(peer, e_Init);
+ break;
+ case e_Init: // FALLTHROUGH
+ case e_Huh:
+ true_send(peer, "PO\r");
+ up->state = s_InqTCU;
+ break;
+ case e_F50:
+ case e_F51:
+ case e_Location:
+ case e_TS:
+ case e_Max:
+ default:
msyslog(LOG_INFO,
"REFCLOCK: TRUETIME: TM/TMD init fellthrough!");
- break;
- }
- break;
- case s_InqTCU:
- switch (event) {
- case e_Location:
- up->type = t_tcu;
- true_doevent(peer, e_Init);
- break;
- case e_Init: /*FALLTHROUGH*/
- case e_Huh:
- up->state = s_Base;
- sleep(1); /* XXX */
- break;
- case e_F18:
- case e_F50:
- case e_F51:
- case e_TS:
- case e_Max:
- default:
+ break;
+ }
+ break;
+ case s_InqTCU:
+ switch (event) {
+ case e_Location:
+ up->type = t_tcu;
+ true_doevent(peer, e_Init);
+ break;
+ case e_Init: // FALLTHROUGH
+ case e_Huh:
+ up->state = s_Base;
+ sleep(1); // XXX
+ break;
+ case e_F18:
+ case e_F50:
+ case e_F51:
+ case e_TS:
+ case e_Max:
+ default:
msyslog(LOG_INFO,
"REFCLOCK: TRUETIME: TCU init fellthrough!");
break;
- }
- break;
- /*
- * An expedient hack to prevent lint complaints,
- * these don't actually need to be used here...
- */
- case s_Init:
- case s_F18:
- case s_F50:
- case s_Start:
- case s_Auto:
- case s_Max:
- msyslog(LOG_INFO, "REFCLOCK: TRUETIME: state %s is unexpected!",
- stateStr(up->state));
- default:
- /* huh? */
- break;
- }
- break;
- case t_Max:
- default:
+ }
+ break;
+ /*
+ * An expedient hack to prevent lint complaints,
+ * these don't actually need to be used here...
+ */
+ case s_Init:
+ case s_F18:
+ case s_F50:
+ case s_Start:
+ case s_Auto:
+ case s_Max:
+ msyslog(LOG_INFO, "REFCLOCK: TRUETIME: state %s is unexpected!",
+ stateStr(up->state));
+ default:
+ // huh?
+ break;
+ }
+ break;
+ case t_Max:
+ default:
msyslog(LOG_INFO, "REFCLOCK: TRUETIME: cannot identify refclock!");
- abort();
- /* NOTREACHED */
- }
+ abort();
+ // NOTREACHED
+ }
#ifdef ENABLE_PPS720
- if ((pp->sloppyclockflag & CLK_FLAG4) && !up->pcl720init) {
- /* Make counter trigger on gate0, count down from 65535. */
- pcl720_load(PCL720_IOB, PCL720_CTR, i8253_oneshot, 65535);
- /*
- * (These constants are OK since
- * they represent hardware maximums.)
- */
- NLOG(NLOG_CLOCKINFO) {
- msyslog(LOG_NOTICE, "REFCLOCK: PCL-720 initialized");
- }
- up->pcl720init++;
- }
+ if ((pp->sloppyclockflag & CLK_FLAG4) && !up->pcl720init) {
+ // Make counter trigger on gate0, count down from 65535.
+ pcl720_load(PCL720_IOB, PCL720_CTR, i8253_oneshot, 65535);
+ /*
+ * (These constants are OK since
+ * they represent hardware maximums.)
+ */
+ NLOG(NLOG_CLOCKINFO) {
+ msyslog(LOG_NOTICE, "REFCLOCK: PCL-720 initialized");
+ }
+ up->pcl720init++;
+ }
#endif
@@ -726,35 +726,35 @@ true_doevent(
*/
static void
true_poll(
- int unit,
- struct peer *peer
- )
+ int unit,
+ struct peer *peer
+ )
{
- struct true_unit *up;
- struct refclockproc *pp;
-
- UNUSED_ARG(unit);
-
- /*
- * You don't need to poll this clock. It puts out timecodes
- * once per second. If asked for a timestamp, take note.
- * The next time a timecode comes in, it will be fed back.
- */
- pp = peer->procptr;
- up = pp->unitptr;
- if (up->pollcnt > 0) {
- up->pollcnt--;
- } else {
- true_doevent(peer, e_Init);
- refclock_report(peer, CEVNT_TIMEOUT);
- }
-
- /*
- * polled every 64 seconds. Ask true_receive to hand in a
- * timestamp.
- */
- up->polled = true;
- pp->polls++;
+ struct true_unit *up;
+ struct refclockproc *pp;
+
+ UNUSED_ARG(unit);
+
+ /*
+ * You don't need to poll this clock. It puts out timecodes
+ * once per second. If asked for a timestamp, take note.
+ * The next time a timecode comes in, it will be fed back.
+ */
+ pp = peer->procptr;
+ up = pp->unitptr;
+ if (up->pollcnt > 0) {
+ up->pollcnt--;
+ } else {
+ true_doevent(peer, e_Init);
+ refclock_report(peer, CEVNT_TIMEOUT);
+ }
+
+ /*
+ * polled every 64 seconds. Ask true_receive to hand in a
+ * timestamp.
+ */
+ up->polled = true;
+ pp->polls++;
}
#ifdef ENABLE_PPS720
@@ -764,23 +764,23 @@ true_poll(
static unsigned long
true_sample720(void)
{
- unsigned long f;
-
- /* We wire the PCL-720's 8253.OUT0 to bit 0 of connector 3.
- * If it is not being held low now, we did not get called
- * within 65535us.
- */
- if (inb(pcl720_data_16_23(PCL720_IOB)) & 0x01) {
- NLOG(NLOG_CLOCKINFO) {
- msyslog(LOG_NOTICE, "REFCLOCK: PCL-720 out of synch");
- }
- return (0);
- }
- f = (65536 - pcl720_read(PCL720_IOB, PCL720_CTR));
+ unsigned long f;
+
+ /* We wire the PCL-720's 8253.OUT0 to bit 0 of connector 3.
+ * If it is not being held low now, we did not get called
+ * within 65535us.
+ */
+ if (inb(pcl720_data_16_23(PCL720_IOB)) & 0x01) {
+ NLOG(NLOG_CLOCKINFO) {
+ msyslog(LOG_NOTICE, "REFCLOCK: PCL-720 out of synch");
+ }
+ return (0);
+ }
+ f = (65536 - pcl720_read(PCL720_IOB, PCL720_CTR));
#ifdef DEBUG_PPS720
- msyslog(LOG_DEBUG, "REFCLOCK: PCL-720: %luus", f);
+ msyslog(LOG_DEBUG, "REFCLOCK: PCL-720: %luus", f);
#endif
- return (f);
+ return (f);
}
#endif
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/compare/c281f95cd3834786abeca138940d0af2d7ccc3fb...33df4dd37784d5dd8508e96d1d5ce20599bb3f83
--
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/compare/c281f95cd3834786abeca138940d0af2d7ccc3fb...33df4dd37784d5dd8508e96d1d5ce20599bb3f83
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20260806/ef7f268f/attachment-0001.htm>
More information about the vc
mailing list