[Git][NTPsec/ntpsec][scanner] 2 commits: ntpd/refclock_trimble.c: Remove tabs, Single line /* comments to //

Hal Murray (@hal.murray) gitlab at mg.gitlab.com
Thu Aug 6 19:07:20 UTC 2026



Hal Murray pushed to branch scanner at NTPsec / ntpsec


Commits:
96d607cb by Gary E. Miller at 2026-08-06T11:58:16-07:00
ntpd/refclock_trimble.c: Remove tabs, Single line /* comments to //

- - - - -
d349d220 by Gary E. Miller at 2026-08-06T12:06:39-07:00
ntpd/ntp_scanner.c: Remove tabs, Single line /* comments to //

No functional changes.

- - - - -


2 changed files:

- ntpd/ntp_scanner.c
- ntpd/refclock_trimble.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_trimble.c
=====================================
@@ -41,34 +41,34 @@
 /*
  * GPS Definitions
  */
-#define	DESCRIPTION	"Trimble Palisade/Thunderbolt/Acutime/Resolution SMT/ACE/Copernicus GPSes" /* Long name */
-#define NAME		"TRIMBLE"	/* shortname */
-#define	PRECISION	(-20)		/* precision assumed (about 1 us) */
-#define	REFID		"GPS\0"		/* reference ID */
-#define TRMB_MINPOLL    4		/* 16 seconds */
-#define TRMB_MAXPOLL	5		/* 32 seconds */
-#define MIN_SAMPLES	7		/* minimum number of samples in the median filter to allow a poll */
+#define DESCRIPTION     "Trimble Palisade/Thunderbolt/Acutime/Resolution SMT/ACE/Copernicus GPSes"  // Long name
+#define NAME            "TRIMBLE"       // shortname
+#define PRECISION       (-20)           // precision assumed (about 1 us)
+#define REFID           "GPS\0"         // reference ID
+#define TRMB_MINPOLL    4               // 16 seconds
+#define TRMB_MAXPOLL    5               // 32 seconds
+#define MIN_SAMPLES     7               // minimum number of samples in the median filter to allow a poll
 
 /*
  * I/O Definitions
  */
 #ifndef ENABLE_CLASSIC_MODE
-#define	DEVICE		"/dev/trimble%d" 	/* device name and unit */
+#define DEVICE          "/dev/trimble%d"        // device name and unit
 #else
-#define	DEVICE		"/dev/palisade%d" 	/* device name and unit */
+#define DEVICE          "/dev/palisade%d"       // device name and unit
 #endif
-#define	SPEED232	B9600		  	/* uart speed (9600 baud) */
-#define	SPEED232COP	B38400		  	/* uart speed for Copernicus II (38400 baud) */
+#define SPEED232        B9600                   // uart speed (9600 baud)
+#define SPEED232COP     B38400                  // uart speed for Copernicus II (38400 baud)
 
-/* parse consts */
-#define RMAX 172 /* TSIP packet 0x58 can be 172 bytes */
+// parse consts
+#define RMAX 172  // TSIP packet 0x58 can be 172 bytes
 #define DLE 0x10
 #define ETX 0x03
 #define MSG_TSIP 0
 #define MSG_PRAECIS 1
-#define SPSTAT_LEN 34 /* length of reply from Praecis SPSTAT message */
+#define SPSTAT_LEN 34  // length of reply from Praecis SPSTAT message
 
-/* parse states */
+// parse states
 #define TSIP_PARSED_EMPTY       0
 #define TSIP_PARSED_FULL        1
 #define TSIP_PARSED_DLE_1       2
@@ -77,12 +77,12 @@
 #define TSIP_PARSED_ASCII       5
 #define TSIP_PARSED_PARITY      6
 
-#define mb(_X_) (up->rpt_buf[(_X_ + 1)]) /* shortcut for buffer access	*/
+#define mb(_X_) (up->rpt_buf[(_X_ + 1)])  // shortcut for buffer access
 
-/* Conversion Definitions */
+// Conversion Definitions
 #ifdef DEBUG
-# define GPS_PI 	(3.1415926535898)
-# define R2D		(180.0/GPS_PI)
+# define GPS_PI         (3.1415926535898)
+# define R2D            (180.0/GPS_PI)
 #endif
 
 /*
@@ -91,126 +91,126 @@
  */
 struct packettx
 {
-	short	size;
-	uint8_t *data;
+        short   size;
+        uint8_t *data;
 };
 
 /*
  * Trimble unit control structure.
  */
 struct trimble_unit {
-	short			unit;		/* NTP refclock unit number */
-	bool			got_pkt;	/* decoded a packet this poll */
-	bool			got_time;	/* got a time packet this poll */
-	int			samples;	/* samples in filter this poll */
-	unsigned char		UTC_flags;	/* UTC & leap second flag */
-	unsigned char		trk_status;	/* reported tracking status */
-	char			rpt_status;	/* TSIP Parser State */
-	size_t 			rpt_cnt;	/* TSIP packet length so far */
-	unsigned char 		rpt_buf[RMAX];	/* packet assembly buffer */
-	int			type;		/* Clock mode type */
-	bool			use_event;	/* receiver has event input */
-	bool			event_reply;	/* response to event input has been received */
-	int			MCR;		/* modem control register value at startup */
-	bool			parity_chk;	/* enable parity checking */
-	l_fp			p_recv_time;	/* timestamp of last received packet */
-	unsigned int		week;		/* GPS week number */
-	unsigned long int	TOW;		/* GPS time of week */
-	int			UTC_offset;	/* GPS-UTC offset */
-	struct  calendar	date;		/* calendar to avoid leap early announce */
-	unsigned int		build_week;	/* GPS week number of ntpd build date */
+        short                   unit;           // NTP refclock unit number
+        bool                    got_pkt;        // decoded a packet this poll
+        bool                    got_time;       // got a time packet this poll
+        int                     samples;        // samples in filter this poll
+        unsigned char           UTC_flags;      // UTC & leap second flag
+        unsigned char           trk_status;     // reported tracking status
+        char                    rpt_status;     // TSIP Parser State
+        size_t                  rpt_cnt;        // TSIP packet length so far
+        unsigned char           rpt_buf[RMAX];  // packet assembly buffer
+        int                     type;           // Clock mode type
+        bool                    use_event;      // receiver has event input
+        bool                    event_reply;    // response to event input has been received
+        int                     MCR;            // modem control register value at startup
+        bool                    parity_chk;     // enable parity checking
+        l_fp                    p_recv_time;    // timestamp of last received packet
+        unsigned int            week;           // GPS week number
+        unsigned long int       TOW;            // GPS time of week
+        int                     UTC_offset;     // GPS-UTC offset
+        struct  calendar        date;           // calendar to avoid leap early announce
+        unsigned int            build_week;     // GPS week number of ntpd build date
 };
 
 /*
  * Function prototypes
  */
-static	bool		trimble_start		(int, struct peer *);
-static	void		trimble_poll		(int, struct peer *);
-static	void		trimble_timer		(int, struct peer *);
-static	void 		trimble_io		(struct recvbuf *);
-static	void		trimble_receive		(struct peer *, int);
-static	bool		TSIP_decode		(struct peer *);
-static	void		HW_poll			(struct refclockproc *);
-static	float		getsgl			(uint8_t *);
-static	double		getdbl 			(uint8_t *);
-static	int16_t		gets16	 		(uint8_t *);
-static	uint16_t	getu16	 		(uint8_t *);
-static	uint32_t	getu32			(uint8_t *);
-static  void		sendcmd			(struct packettx *buffer, int c);
-static  void		sendsupercmd		(struct packettx *buffer, int c1, int c2);
-static  void		sendbyte		(struct packettx *buffer, int b);
-static  void		sendint			(struct packettx *buffer, int a);
-static  int		sendetx			(struct packettx *buffer, int fd);
-static  void		init_thunderbolt	(int fd);
-static  void		init_resolution_smt	(int fd);
+static  bool            trimble_start           (int, struct peer *);
+static  void            trimble_poll            (int, struct peer *);
+static  void            trimble_timer           (int, struct peer *);
+static  void            trimble_io              (struct recvbuf *);
+static  void            trimble_receive         (struct peer *, int);
+static  bool            TSIP_decode             (struct peer *);
+static  void            HW_poll                 (struct refclockproc *);
+static  float           getsgl                  (uint8_t *);
+static  double          getdbl                  (uint8_t *);
+static  int16_t         gets16                  (uint8_t *);
+static  uint16_t        getu16                  (uint8_t *);
+static  uint32_t        getu32                  (uint8_t *);
+static  void            sendcmd                 (struct packettx *buffer, int c);
+static  void            sendsupercmd            (struct packettx *buffer, int c1, int c2);
+static  void            sendbyte                (struct packettx *buffer, int b);
+static  void            sendint                 (struct packettx *buffer, int a);
+static  int             sendetx                 (struct packettx *buffer, int fd);
+static  void            init_thunderbolt        (int fd);
+static  void            init_resolution_smt     (int fd);
 
 #define PAL_TSTATS 14
 #ifdef DEBUG
 static const char tracking_status[PAL_TSTATS+1][16] = {
-	"Doing Fixes", "Good 1SV", "Approx. 1SV", "Need Time", "Need INIT",
-	"PDOP too High", "Bad 1SV", "0SV Usable", "1SV Usable", "2SV Usable",
-	"3SV Usable", "No Integrity", "Diff Corr", "Overdet Clock", "Invalid"};
+        "Doing Fixes", "Good 1SV", "Approx. 1SV", "Need Time", "Need INIT",
+        "PDOP too High", "Bad 1SV", "0SV Usable", "1SV Usable", "2SV Usable",
+        "3SV Usable", "No Integrity", "Diff Corr", "Overdet Clock", "Invalid"};
 #endif
 static const bool tracking_status_usable[PAL_TSTATS+1] = {
-	true, true, false, false, false,
-	false, false, false, false, false,
-	false, false, false, true, false};
+        true, true, false, false, false,
+        false, false, false, false, false,
+        false, false, false, true, false};
 
-#define TB_DECOD_STATS 16 /* convert TB decoding status to tracking_status */
+#define TB_DECOD_STATS 16  // convert TB decoding status to tracking_status
 static const unsigned int tb_decod_conv[TB_DECOD_STATS+1] = {
-	0, 3, 14, 5, 14, 14, 14, 14, 7, 8, 9, 10, 6, 14, 14, 14, 11};
+        0, 3, 14, 5, 14, 14, 14, 14, 7, 8, 9, 10, 6, 14, 14, 14, 11};
 
 #define TB_DISC_MODES 7
 #ifdef DEBUG
 static const char tb_disc_mode[TB_DISC_MODES+1][16] = {
-	"normal", "power-up", "auto holdover", "manual holdover",
-	"recovery", "unknown", "disabled", "invalid"};
+        "normal", "power-up", "auto holdover", "manual holdover",
+        "recovery", "unknown", "disabled", "invalid"};
 #endif
 static const bool tb_disc_in_holdover[TB_DISC_MODES+1] = {
-	false, false, true, true,
-	false, false, false, false};
+        false, false, true, true,
+        false, false, false, false};
 
 /*
  * Transfer vector
  */
 struct refclock refclock_trimble = {
-	NAME,			/* basename of driver */
-	trimble_start,		/* start up driver */
-	NULL,			/* shut down driver in the standard way */
-	trimble_poll,		/* transmit poll message */
-	NULL,			/* control - not used  */
-	NULL,			/* initialize driver (not used) */
-	trimble_timer		/* called at 1Hz by mainloop */
+        NAME,                   // basename of driver
+        trimble_start,          // start up driver
+        NULL,                   // shut down driver in the standard way
+        trimble_poll,           // transmit poll message
+        NULL,                   // control - not used
+        NULL,                   // initialize driver (not used)
+        trimble_timer           // called at 1Hz by mainloop
 };
 
-/* Extract the clock type from the mode setting */
+// Extract the clock type from the mode setting
 #define CLK_TYPE(x) ((int)(((x)->cfg.mode) & 0x7F))
 
-/* Supported clock types */
-#define CLK_PALISADE		0	/* Trimble Palisade */
-#define CLK_PRAECIS		1	/* Endrun Technologies Praecis */
-#define CLK_THUNDERBOLT		2	/* Trimble Thunderbolt GPS Receiver */
-#define CLK_ACUTIME   		3	/* Trimble Acutime Gold */
-#define CLK_RESOLUTIONSMT	5	/* Trimble Resolution SMT Receivers */
-#define CLK_ACE			6	/* Trimble ACE III */
-#define CLK_COPERNICUS		7	/* Trimble Copernicus II */
+// Supported clock types
+#define CLK_PALISADE            0       // Trimble Palisade
+#define CLK_PRAECIS             1       // Endrun Technologies Praecis
+#define CLK_THUNDERBOLT         2       // Trimble Thunderbolt GPS Receiver
+#define CLK_ACUTIME             3       // Trimble Acutime Gold
+#define CLK_RESOLUTIONSMT       5       // Trimble Resolution SMT Receivers
+#define CLK_ACE                 6       // Trimble ACE III
+#define CLK_COPERNICUS          7       // Trimble Copernicus II
 
-/* packet 8f-ad UTC flags */
-#define UTC_AVAILABLE	0x01
-#define LEAP_SCHEDULED	0x10
+// packet 8f-ad UTC flags
+#define UTC_AVAILABLE   0x01
+#define LEAP_SCHEDULED  0x10
 
 /*
  * sendcmd - Build data packet for sending
  */
 static void
 sendcmd (
-	struct packettx *buffer,
-	int c
-	)
+        struct packettx *buffer,
+        int c
+        )
 {
-	*buffer->data = DLE;
-	*(buffer->data + 1) = (unsigned char)c;
-	buffer->size = 2;
+        *buffer->data = DLE;
+        *(buffer->data + 1) = (unsigned char)c;
+        buffer->size = 2;
 }
 
 /*
@@ -218,15 +218,15 @@ sendcmd (
  */
 static void
 sendsupercmd (
-	struct packettx *buffer,
-	int c1,
-	int c2
-	)
+        struct packettx *buffer,
+        int c1,
+        int c2
+        )
 {
-	*buffer->data = DLE;
-	*(buffer->data + 1) = (unsigned char)c1;
-	*(buffer->data + 2) = (unsigned char)c2;
-	buffer->size = 3;
+        *buffer->data = DLE;
+        *(buffer->data + 1) = (unsigned char)c1;
+        *(buffer->data + 2) = (unsigned char)c2;
+        buffer->size = 3;
 }
 
 /*
@@ -234,14 +234,14 @@ sendsupercmd (
  */
 static void
 sendbyte (
-	struct packettx *buffer,
-	int b
-	)
+        struct packettx *buffer,
+        int b
+        )
 {
-	if (b == DLE) {
-		*(buffer->data+buffer->size++) = DLE;
-	}
-	*(buffer->data+buffer->size++) = (unsigned char)b;
+        if (b == DLE) {
+                *(buffer->data+buffer->size++) = DLE;
+        }
+        *(buffer->data+buffer->size++) = (unsigned char)b;
 }
 
 /*
@@ -249,12 +249,12 @@ sendbyte (
  */
 static void
 sendint (
-	struct packettx *buffer,
-	int a
-	)
+        struct packettx *buffer,
+        int a
+        )
 {
-	sendbyte(buffer, (unsigned char)((a>>8) & 0xff));
-	sendbyte(buffer, (unsigned char)(a & 0xff));
+        sendbyte(buffer, (unsigned char)((a>>8) & 0xff));
+        sendbyte(buffer, (unsigned char)(a & 0xff));
 }
 
 /*
@@ -262,77 +262,77 @@ sendint (
  */
 static int
 sendetx (
-	struct packettx *buffer,
-	int fd
-	)
+        struct packettx *buffer,
+        int fd
+        )
 {
-	ssize_t result;
+        ssize_t result;
 
-	*(buffer->data+buffer->size++) = DLE;
-	*(buffer->data+buffer->size++) = ETX;
-	result = write(fd, buffer->data, (size_t)buffer->size);
+        *(buffer->data+buffer->size++) = DLE;
+        *(buffer->data+buffer->size++) = ETX;
+        result = write(fd, buffer->data, (size_t)buffer->size);
 
-	if (result != -1)
-		return (result);
-	else
-		return (-1);
+        if (result != -1)
+                return (result);
+        else
+                return (-1);
 }
 
 /*
  * init_thunderbolt - Prepares Thunderbolt receiver to be used with
- *		      NTP (also taken from Markus Prosch).
+ *                    NTP (also taken from Markus Prosch).
  */
 static void
 init_thunderbolt (
-	int fd
-	)
+        int fd
+        )
 {
-	struct packettx tx;
-	uint8_t tx_data[10];
+        struct packettx tx;
+        uint8_t tx_data[10];
 
-	tx.size = 0;
-	tx.data = tx_data;
+        tx.size = 0;
+        tx.data = tx_data;
 
-	/* set UTC time */
-	sendsupercmd (&tx, 0x8E, 0xA2);
-	sendbyte     (&tx, 0x3);
-	sendetx      (&tx, fd);
+        // set UTC time
+        sendsupercmd (&tx, 0x8E, 0xA2);
+        sendbyte     (&tx, 0x3);
+        sendetx      (&tx, fd);
 
-	/* activate packets 0x8F-AB and 0x8F-AC */
-	sendsupercmd (&tx, 0x8E, 0xA5);
-	sendint      (&tx, 0x5);
-	sendetx      (&tx, fd);
+        // activate packets 0x8F-AB and 0x8F-AC
+        sendsupercmd (&tx, 0x8E, 0xA5);
+        sendint      (&tx, 0x5);
+        sendetx      (&tx, fd);
 }
 
 /*
  * init_resolution_smt - Prepares Resolution SMT receiver to be used with
- *		         NTP (also taken from Markus Prosch).
+ *                       NTP (also taken from Markus Prosch).
  */
 static void
 init_resolution_smt (
-	int fd
-	)
+        int fd
+        )
 {
-	struct packettx tx;
-	uint8_t tx_data[10];
-
-	tx.size = 0;
-	tx.data = tx_data;
-
-	/* set UTC time */
-	sendsupercmd (&tx, 0x8E, 0xA2);
-	sendbyte     (&tx, 0x3);
-	sendetx      (&tx, fd);
-
-	/* squelch PPS output unless locked to at least one satellite */
-	sendsupercmd (&tx, 0x8E, 0x4E);
-	sendbyte     (&tx, 0x3);
-	sendetx      (&tx, fd);
-
-	/* activate packets 0x8F-AB and 0x8F-AC */
-	sendsupercmd (&tx, 0x8E, 0xA5);
-	sendint      (&tx, 0x5);
-	sendetx      (&tx, fd);
+        struct packettx tx;
+        uint8_t tx_data[10];
+
+        tx.size = 0;
+        tx.data = tx_data;
+
+        // set UTC time
+        sendsupercmd (&tx, 0x8E, 0xA2);
+        sendbyte     (&tx, 0x3);
+        sendetx      (&tx, fd);
+
+        // squelch PPS output unless locked to at least one satellite
+        sendsupercmd (&tx, 0x8E, 0x4E);
+        sendbyte     (&tx, 0x3);
+        sendetx      (&tx, fd);
+
+        // activate packets 0x8F-AB and 0x8F-AC
+        sendsupercmd (&tx, 0x8E, 0xA5);
+        sendint      (&tx, 0x5);
+        sendetx      (&tx, fd);
 }
 
 /*
@@ -340,230 +340,230 @@ init_resolution_smt (
  */
 static bool
 trimble_start (
-	int unit,
-	struct peer *peer
-	)
+        int unit,
+        struct peer *peer
+        )
 {
-	struct trimble_unit *up;
-	struct refclockproc *pp;
-	int fd;
-	struct termios tio;
-	speed_t desired_speed;
-	struct calendar build_date;
-	unsigned int cflag, iflag;
-	char device[20], *path;
-
-	pp = peer->procptr;
-	pp->clockname = NAME;
-
-	/* Open serial port. */
-	if (peer->cfg.path)
-	    path = peer->cfg.path;
-	else
-	{
-	    int rcode;
-	    snprintf(device, sizeof(device), DEVICE, unit);
-
-	    /* build a path */
-	    rcode = snprintf(device, sizeof(device), DEVICE, unit);
-	    if ( 0 > rcode ) {
-	        /* failed, set to NUL */
-	        device[0] = '\0';
-	    }
-	    path = device;
+        struct trimble_unit *up;
+        struct refclockproc *pp;
+        int fd;
+        struct termios tio;
+        speed_t desired_speed;
+        struct calendar build_date;
+        unsigned int cflag, iflag;
+        char device[20], *path;
+
+        pp = peer->procptr;
+        pp->clockname = NAME;
+
+        // Open serial port.
+        if (peer->cfg.path)
+            path = peer->cfg.path;
+        else
+        {
+            int rcode;
+            snprintf(device, sizeof(device), DEVICE, unit);
+
+            // build a path
+            rcode = snprintf(device, sizeof(device), DEVICE, unit);
+            if ( 0 > rcode ) {
+                // failed, set to NUL
+                device[0] = '\0';
+            }
+            path = device;
+        }
+        fd = refclock_open(path,
+                                  peer->cfg.baud ? peer->cfg.baud :
+                                  (CLK_TYPE(peer) == CLK_COPERNICUS) ? SPEED232COP : SPEED232,
+                                  LDISC_RAW);
+        if (0 > fd) {
+                msyslog(LOG_ERR, "REFCLOCK: %s Trimble device open(%s) failed",
+                        refclock_name(peer), path);
+                // coverity[leaked_handle]
+                return false;
+        }
+
+        LOGIF(CLOCKINFO, (LOG_NOTICE, "%s open at %s",
+                          refclock_name(peer), path));
+
+        if (tcgetattr(fd, &tio) < 0) {
+                msyslog(LOG_ERR, "REFCLOCK: %s tcgetattr failed: %s",
+                        refclock_name(peer), strerror(errno));
+                close(fd);
+                return false;
+        }
+
+        // Allocate and initialize unit structure
+        up = emalloc_zero(sizeof(*up));
+
+        up->type = CLK_TYPE(peer);
+        up->parity_chk = true;
+        up->use_event = true;
+        pp->disp = 1000 * S_PER_NS;  // extra ~500ns for serial port delay
+
+        switch (up->type) {
+            case CLK_PALISADE:
+                msyslog(LOG_NOTICE, "REFCLOCK: %s Palisade mode enabled",
+                        refclock_name(peer));
+                break;
+            case CLK_PRAECIS:
+                msyslog(LOG_NOTICE, "REFCLOCK: %s Praecis mode enabled",
+                        refclock_name(peer));
+                // account for distance to tower
+                pp->disp = .00002;
+                break;
+            case CLK_THUNDERBOLT:
+                msyslog(LOG_NOTICE, "REFCLOCK: %s Thunderbolt mode enabled",
+                        refclock_name(peer));
+                up->parity_chk = false;
+                up->use_event = false;
+                /*
+                 * packet transmission delay varies from 9ms to 32ms depending
+                 * on the number of SVs the receiver is attempting to track
+                 */
+                pp->disp = .023;
+                break;
+            case CLK_ACUTIME:
+                msyslog(LOG_NOTICE, "REFCLOCK: %s Acutime Gold mode enabled",
+                        refclock_name(peer));
+                break;
+            case CLK_RESOLUTIONSMT:
+                msyslog(LOG_NOTICE, "REFCLOCK: %s Resolution SMT mode enabled",
+                        refclock_name(peer));
+                up->use_event = false;
+                break;
+            case CLK_ACE:
+                msyslog(LOG_NOTICE, "REFCLOCK: %s ACE III mode enabled",
+                        refclock_name(peer));
+                break;
+            case CLK_COPERNICUS:
+                msyslog(LOG_NOTICE, "REFCLOCK: %s Copernicus II mode enabled",
+                        refclock_name(peer));
+                up->use_event = false;
+                up->parity_chk = false;
+                break;
+            default:
+                msyslog(LOG_NOTICE, "REFCLOCK: %s mode unknown",
+                        refclock_name(peer));
+                close(fd);
+                free(up);
+                return false;
+        }
+        tio.c_cflag = (CS8|CLOCAL|CREAD);
+        tio.c_iflag &= (unsigned)~ICRNL;
+        if (up->parity_chk) {
+                tio.c_cflag |= (PARENB|PARODD);
+                tio.c_iflag &= (unsigned)~IGNPAR;
+                tio.c_iflag |= (INPCK|PARMRK);
+        }
+        cflag = tio.c_cflag;
+        iflag = tio.c_iflag;
+        if (tcsetattr(fd, TCSANOW, &tio) == -1 || tcgetattr(fd, &tio) == -1 ||
+            tio.c_cflag != cflag || tio.c_iflag != iflag) {
+                msyslog(LOG_ERR, "REFCLOCK: %s tcsetattr failed: wanted cflag 0x%x got 0x%x, wanted iflag 0x%x got 0x%x, return: %s",
+                        refclock_name(peer), cflag, (unsigned int)tio.c_cflag,
+                        iflag, (unsigned int)tio.c_iflag, strerror(errno));
+                close(fd);
+                free(up);
+                return false;
+        }
+        /*
+         * On some OS's, the calls to tcsetattr and tcgetattr above reset the baud
+         * rate to 0 as a side effect. Surprisingly, this doesn't appear to affect
+         * the operation of devices running at 9600 baud but it certainly does
+         * affect the 38400 baud Copernicus II.
+         * As a workaround, apply the baud rate once more here.
+         */
+        desired_speed = peer->cfg.baud ? peer->cfg.baud :
+                        (CLK_TYPE(peer) == CLK_COPERNICUS) ? SPEED232COP : SPEED232;
+        if (cfsetispeed(&tio, desired_speed) == -1 || cfsetospeed(&tio, desired_speed) == -1 ||
+            tcsetattr(fd, TCSANOW, &tio) == -1) {
+                msyslog(LOG_ERR, "REFCLOCK: %s: failed to set device baud rate",
+                        refclock_name(peer));
+                close(fd);
+                free(up);
+                return false;
+        }
+
+        if (up->use_event && (up->type != CLK_ACE)) {
+                /*
+                 * The width of the RTS pulse must be either less than 5us or
+                 * greater than 600ms or the Acutime 2000 may try to switch its
+                 * port A baud rate because of "Auto-DGPS". The Praecis will
+                 * produce unstable timestamps (-7us instead of +-40ns offsets)
+                 * when pulse width is more than a few us and less than 100us.
+                 * Palisade minimum puse width is specified as 1us. To satisfy
+                 * these constraints the RTS pin is idled with a positive
+                 * voltage and pulsed negative.
+                 */
+                if (ioctl(fd, TIOCMGET, &up->MCR) < 0) {
+                        msyslog(LOG_ERR, "REFCLOCK: %s TIOCMGET failed: %s",
+                                refclock_name(peer), strerror(errno));
+                        close(fd);
+                        free(up);
+                        return false;
+                }
+                up->MCR |= TIOCM_RTS;
+                if (ioctl(fd, TIOCMSET, &up->MCR) < 0 ||
+                    !(up->MCR & TIOCM_RTS)) {
+                        msyslog(LOG_ERR, "REFCLOCK: %s TIOCMSET failed: MCR=0x%x, return=%s",
+                                refclock_name(peer), (unsigned int)up->MCR, strerror(errno));
+                        close(fd);
+                        free(up);
+                        return false;
+                }
+        }
+        pp->io.clock_recv = trimble_io;
+        pp->io.srcclock = peer;
+        pp->io.datalen = 0;
+        pp->io.fd = fd;
+        if (!io_addclock(&pp->io)) {
+                msyslog(LOG_ERR, "%s io_addclock failed", refclock_name(peer));
+                close(fd);
+                pp->io.fd = -1;
+                free(up);
+                return false;
+        }
+
+        // Initialize miscellaneous variables
+        pp->unitptr = up;
+        pp->clockdesc = DESCRIPTION;
+
+        peer->precision = PRECISION;
+        peer->sstclktype = CTL_SST_TS_UHF;
+        peer->cfg.minpoll = TRMB_MINPOLL;
+        peer->cfg.maxpoll = TRMB_MAXPOLL;
+        memcpy((char *)&pp->refid, REFID, REFIDLEN);
+
+        up->unit = (short) unit;
+        up->rpt_status = TSIP_PARSED_EMPTY;
+        up->rpt_cnt = 0;
+
+        if (ntpcal_get_build_date(&build_date)) {
+                caltogps(&build_date, 0, &up->build_week, NULL);
+                up->build_week -= 2;  // timezone, UTC offset, build machine clock
+        } else {
+                up->build_week = 0;
+        }
+        if (up->build_week < MIN_BUILD_GPSWEEK || up->build_week > MAX_BUILD_GPSWEEK) {
+                msyslog(LOG_ERR,
+                        "REFCLOCK: %s ntpcal_get_build_date() failed: %u",
+                        refclock_name(peer), up->build_week);
+                close(fd);
+                pp->io.fd = -1;
+                free(up);
+                return false;
+        }
+
+        if (up->type == CLK_THUNDERBOLT) {
+                init_thunderbolt(fd);
         }
-	fd = refclock_open(path,
-				  peer->cfg.baud ? peer->cfg.baud :
-				  (CLK_TYPE(peer) == CLK_COPERNICUS) ? SPEED232COP : SPEED232,
-				  LDISC_RAW);
-	if (0 > fd) {
-	        msyslog(LOG_ERR, "REFCLOCK: %s Trimble device open(%s) failed",
-			refclock_name(peer), path);
-		/* coverity[leaked_handle] */
-		return false;
-	}
-
-	LOGIF(CLOCKINFO, (LOG_NOTICE, "%s open at %s",
-			  refclock_name(peer), path));
-
-	if (tcgetattr(fd, &tio) < 0) {
-		msyslog(LOG_ERR, "REFCLOCK: %s tcgetattr failed: %s",
-		        refclock_name(peer), strerror(errno));
-		close(fd);
-		return false;
-	}
-
-	/* Allocate and initialize unit structure */
-	up = emalloc_zero(sizeof(*up));
-
-	up->type = CLK_TYPE(peer);
-	up->parity_chk = true;
-	up->use_event = true;
-	pp->disp = 1000 * S_PER_NS; /* extra ~500ns for serial port delay */
-
-	switch (up->type) {
-	    case CLK_PALISADE:
-		msyslog(LOG_NOTICE, "REFCLOCK: %s Palisade mode enabled",
-		        refclock_name(peer));
-		break;
-	    case CLK_PRAECIS:
-		msyslog(LOG_NOTICE, "REFCLOCK: %s Praecis mode enabled",
-			refclock_name(peer));
-		/* account for distance to tower */
-		pp->disp = .00002;
-		break;
-	    case CLK_THUNDERBOLT:
-		msyslog(LOG_NOTICE, "REFCLOCK: %s Thunderbolt mode enabled",
-			refclock_name(peer));
-		up->parity_chk = false;
-		up->use_event = false;
-		/*
-		 * packet transmission delay varies from 9ms to 32ms depending
-		 * on the number of SVs the receiver is attempting to track
-		 */
-		pp->disp = .023;
-		break;
-	    case CLK_ACUTIME:
-		msyslog(LOG_NOTICE, "REFCLOCK: %s Acutime Gold mode enabled",
-			refclock_name(peer));
-		break;
-	    case CLK_RESOLUTIONSMT:
-		msyslog(LOG_NOTICE, "REFCLOCK: %s Resolution SMT mode enabled",
-			refclock_name(peer));
-		up->use_event = false;
-		break;
-	    case CLK_ACE:
-		msyslog(LOG_NOTICE, "REFCLOCK: %s ACE III mode enabled",
-			refclock_name(peer));
-		break;
-	    case CLK_COPERNICUS:
-		msyslog(LOG_NOTICE, "REFCLOCK: %s Copernicus II mode enabled",
-			refclock_name(peer));
-		up->use_event = false;
-		up->parity_chk = false;
-		break;
-	    default:
-	        msyslog(LOG_NOTICE, "REFCLOCK: %s mode unknown",
-			refclock_name(peer));
-		close(fd);
-		free(up);
-		return false;
-	}
-	tio.c_cflag = (CS8|CLOCAL|CREAD);
-	tio.c_iflag &= (unsigned)~ICRNL;
-	if (up->parity_chk) {
-		tio.c_cflag |= (PARENB|PARODD);
-		tio.c_iflag &= (unsigned)~IGNPAR;
-		tio.c_iflag |= (INPCK|PARMRK);
-	}
-	cflag = tio.c_cflag;
-	iflag = tio.c_iflag;
-	if (tcsetattr(fd, TCSANOW, &tio) == -1 || tcgetattr(fd, &tio) == -1 ||
-	    tio.c_cflag != cflag || tio.c_iflag != iflag) {
-		msyslog(LOG_ERR, "REFCLOCK: %s tcsetattr failed: wanted cflag 0x%x got 0x%x, wanted iflag 0x%x got 0x%x, return: %s",
-		        refclock_name(peer), cflag, (unsigned int)tio.c_cflag,
-		        iflag, (unsigned int)tio.c_iflag, strerror(errno));
-		close(fd);
-		free(up);
-		return false;
-	}
-	/*
-	 * On some OS's, the calls to tcsetattr and tcgetattr above reset the baud
-	 * rate to 0 as a side effect. Surprisingly, this doesn't appear to affect
-	 * the operation of devices running at 9600 baud but it certainly does
-	 * affect the 38400 baud Copernicus II.
-	 * As a workaround, apply the baud rate once more here.
-	 */
-	desired_speed = peer->cfg.baud ? peer->cfg.baud :
-	                (CLK_TYPE(peer) == CLK_COPERNICUS) ? SPEED232COP : SPEED232;
-	if (cfsetispeed(&tio, desired_speed) == -1 || cfsetospeed(&tio, desired_speed) == -1 ||
-	    tcsetattr(fd, TCSANOW, &tio) == -1) {
-		msyslog(LOG_ERR, "REFCLOCK: %s: failed to set device baud rate",
-		        refclock_name(peer));
-		close(fd);
-		free(up);
-		return false;
-	}
-
-	if (up->use_event && (up->type != CLK_ACE)) {
-		/*
-		 * The width of the RTS pulse must be either less than 5us or
-		 * greater than 600ms or the Acutime 2000 may try to switch its
-		 * port A baud rate because of "Auto-DGPS". The Praecis will
-		 * produce unstable timestamps (-7us instead of +-40ns offsets)
-		 * when pulse width is more than a few us and less than 100us.
-		 * Palisade minimum puse width is specified as 1us. To satisfy
-		 * these constraints the RTS pin is idled with a positive
-		 * voltage and pulsed negative.
-		 */
-		if (ioctl(fd, TIOCMGET, &up->MCR) < 0) {
-			msyslog(LOG_ERR, "REFCLOCK: %s TIOCMGET failed: %s",
-			        refclock_name(peer), strerror(errno));
-			close(fd);
-			free(up);
-			return false;
-		}
-		up->MCR |= TIOCM_RTS;
-		if (ioctl(fd, TIOCMSET, &up->MCR) < 0 ||
-		    !(up->MCR & TIOCM_RTS)) {
-			msyslog(LOG_ERR, "REFCLOCK: %s TIOCMSET failed: MCR=0x%x, return=%s",
-			        refclock_name(peer), (unsigned int)up->MCR, strerror(errno));
-			close(fd);
-			free(up);
-			return false;
-		}
-	}
-	pp->io.clock_recv = trimble_io;
-	pp->io.srcclock = peer;
-	pp->io.datalen = 0;
-	pp->io.fd = fd;
-	if (!io_addclock(&pp->io)) {
-		msyslog(LOG_ERR, "%s io_addclock failed", refclock_name(peer));
-		close(fd);
-		pp->io.fd = -1;
-		free(up);
-		return false;
-	}
-
-	/* Initialize miscellaneous variables */
-	pp->unitptr = up;
-	pp->clockdesc = DESCRIPTION;
-
-	peer->precision = PRECISION;
-	peer->sstclktype = CTL_SST_TS_UHF;
-	peer->cfg.minpoll = TRMB_MINPOLL;
-	peer->cfg.maxpoll = TRMB_MAXPOLL;
-	memcpy((char *)&pp->refid, REFID, REFIDLEN);
-
-	up->unit = (short) unit;
-	up->rpt_status = TSIP_PARSED_EMPTY;
-	up->rpt_cnt = 0;
-
-	if (ntpcal_get_build_date(&build_date)) {
-		caltogps(&build_date, 0, &up->build_week, NULL);
-		up->build_week -= 2; /* timezone, UTC offset, build machine clock */
-	} else {
-		up->build_week = 0;
-	}
-	if (up->build_week < MIN_BUILD_GPSWEEK || up->build_week > MAX_BUILD_GPSWEEK) {
-		msyslog(LOG_ERR,
-			"REFCLOCK: %s ntpcal_get_build_date() failed: %u",
-		        refclock_name(peer), up->build_week);
-		close(fd);
-		pp->io.fd = -1;
-		free(up);
-		return false;
-	}
-
-	if (up->type == CLK_THUNDERBOLT) {
-		init_thunderbolt(fd);
-	}
-
-	if (up->type == CLK_RESOLUTIONSMT) {
-		init_resolution_smt(fd);
-	}
-
-	return true;
+
+        if (up->type == CLK_RESOLUTIONSMT) {
+                init_resolution_smt(fd);
+        }
+
+        return true;
 }
 
 /*
@@ -571,400 +571,400 @@ trimble_start (
  */
 static bool
 TSIP_decode (
-	struct peer *peer
-	)
+        struct peer *peer
+        )
 {
-	unsigned char id, decod_stat, disc_mode, timing_flags;
-	long secint;
-	double secs, secfrac;
-	unsigned short event, m_alarms;
-	uint32_t holdover_t;
-	float TOWfloat;
-	uint32_t lastrec_frac;
-
-	struct trimble_unit *up;
-	struct refclockproc *pp;
-
-	pp = peer->procptr;
-	up = pp->unitptr;
-	id = (unsigned char)up->rpt_buf[0];
-
-	if (id == 0x8f) {
-		/* Superpackets */
-		event = getu16(&mb(1));
-		if ((up->type != CLK_THUNDERBOLT) && (up->type != CLK_RESOLUTIONSMT) && !event)
-			/* ignore auto-report */
-			return false;
-
-		switch (mb(0) & 0xff) {
-		    case 0x0B:
-			/*
-			 * comprehensive time packet: sent after 8f-ad from
-			 * Palisade and Acutime
-			 */
-			if (up->rpt_cnt != 74) {
-				DPRINT(1, ("TSIP_decode: unit %d: 8f-0b packet length is not 74 (%d)\n",
-				       up->unit, (int)up->rpt_cnt));
-				refclock_report(peer, CEVNT_BADREPLY);
-				return false;
-			}
-			up->got_time = true;
+        unsigned char id, decod_stat, disc_mode, timing_flags;
+        long secint;
+        double secs, secfrac;
+        unsigned short event, m_alarms;
+        uint32_t holdover_t;
+        float TOWfloat;
+        uint32_t lastrec_frac;
+
+        struct trimble_unit *up;
+        struct refclockproc *pp;
+
+        pp = peer->procptr;
+        up = pp->unitptr;
+        id = (unsigned char)up->rpt_buf[0];
+
+        if (id == 0x8f) {
+                // Superpackets
+                event = getu16(&mb(1));
+                if ((up->type != CLK_THUNDERBOLT) && (up->type != CLK_RESOLUTIONSMT) && !event)
+                        // ignore auto-report
+                        return false;
+
+                switch (mb(0) & 0xff) {
+                    case 0x0B:
+                        /*
+                         * comprehensive time packet: sent after 8f-ad from
+                         * Palisade and Acutime
+                         */
+                        if (up->rpt_cnt != 74) {
+                                DPRINT(1, ("TSIP_decode: unit %d: 8f-0b packet length is not 74 (%d)\n",
+                                       up->unit, (int)up->rpt_cnt));
+                                refclock_report(peer, CEVNT_BADREPLY);
+                                return false;
+                        }
+                        up->got_time = true;
 #ifdef DEBUG
-			if (debug > 1) { /* SPECIAL DEBUG */
-				int st, ts;
-				double lat, lon, alt;
-				lat = getdbl(&mb(42)) * R2D;
-				lon = getdbl(&mb(50)) * R2D;
-				alt = getdbl(&mb(58));
-
-				printf("TSIP_decode: unit %d: Latitude: %03.4f Longitude: %03.4f Alt: %05.2f m\n",
-				       up->unit, lat,lon,alt);
-				printf("TSIP_decode: unit %d: Sats:",
-				       up->unit);
-				for (st = 66, ts = 0; st <= 73; st++)
-					if (mb(st)) {
-						if (mb(st) > 0) ts++;
-						printf(" %02d", mb(st));
-					}
-				printf(" : Tracking %d\n", ts);
-			}
+                        if (debug > 1) {  // SPECIAL DEBUG
+                                int st, ts;
+                                double lat, lon, alt;
+                                lat = getdbl(&mb(42)) * R2D;
+                                lon = getdbl(&mb(50)) * R2D;
+                                alt = getdbl(&mb(58));
+
+                                printf("TSIP_decode: unit %d: Latitude: %03.4f Longitude: %03.4f Alt: %05.2f m\n",
+                                       up->unit, lat,lon,alt);
+                                printf("TSIP_decode: unit %d: Sats:",
+                                       up->unit);
+                                for (st = 66, ts = 0; st <= 73; st++)
+                                        if (mb(st)) {
+                                                if (mb(st) > 0) ts++;
+                                                printf(" %02d", mb(st));
+                                        }
+                                printf(" : Tracking %d\n", ts);
+                        }
 #endif
-			if (!tracking_status_usable[up->trk_status]) {
-				DPRINT(1, ("TSIP_decode: unit %d: unusable tracking status: %s\n",
-				       up->unit,
-				       tracking_status[up->trk_status]));
-				return false;
-			}
-			up->UTC_offset = gets16(&mb(16));
-			if (!(up->UTC_flags & UTC_AVAILABLE) ||
-			    (up->UTC_offset == 0)) {
-				pp->leap = LEAP_NOTINSYNC;
-				DPRINT(1, ("TSIP_decode: unit %d: UTC data not available\n",
-				       up->unit));
-				return false;
-			}
-
-			secs = getdbl(&mb(3));
-			secint = (long) secs;
-			secfrac = secs - secint; /* 0.0 <= secfrac < 1.0 */
-
-			pp->nsec = (long) (secfrac * NS_PER_S);
-
-			secint %= SECSPERDAY;    /* Only care about today */
-			up->date.hour = (int)(secint / SECSPERHR);
-			secint %= SECSPERHR;
-			up->date.minute = (int)(secint / 60);
-			secint %= 60;
-			up->date.second = secint % 60;
-			up->date.monthday = mb(11);
-			up->date.month = mb(12);
-			up->date.year = getu16(&mb(13));
-			up->date.yearday = 0;
-			caltogps(&up->date, up->UTC_offset, &up->week, &up->TOW);
-			gpsweekadj(&up->week, up->build_week);
-			gpstocal(up->week, up->TOW, up->UTC_offset, &up->date);
-
-			if ((up->UTC_flags & LEAP_SCHEDULED) &&
-			    /* Avoid early announce: https://bugs.ntp.org/2773 */
-			    (6 == up->date.month || 12 == up->date.month))
-				pp->leap = LEAP_ADDSECOND;
-			else
-				pp->leap = LEAP_NOWARNING;
-
-			DPRINT(2, ("TSIP_decode: unit %d: 8f-0b #%d %02d:%02d:%02d.%09ld %02d/%02d/%04d UTC %d\n    tracking status: %s\n",
-			       up->unit, event, up->date.hour, up->date.minute,
-			       up->date.second, pp->nsec, up->date.month,
-			       up->date.monthday, up->date.year,
-			       up->UTC_offset, tracking_status[up->trk_status]));
-
-			/* don't reuse UTC flags or tracking status */
-			up->UTC_flags = 0;
-			up->trk_status = PAL_TSTATS;
-			return true;
-			break;
-
-		    case 0xAD:
-			/*
-			 * primary UTC time packet: first packet sent after PPS
-			 * from Palisade, Acutime, and Praecis
-			 */
-			if (up->rpt_cnt != 22) {
-				DPRINT(1, ("TSIP_decode: unit %d: 8f-ad packet length is not 22 (%d)\n",
-				       up->unit, (int)up->rpt_cnt));
-				refclock_report(peer, CEVNT_BADREPLY);
-				return false;
-			}
-
-			/* flags checked in 8f-0b for Palisade and Acutime */
-			up->trk_status = mb(18);
-			if (up->trk_status > PAL_TSTATS) {
-				up->trk_status = PAL_TSTATS;
+                        if (!tracking_status_usable[up->trk_status]) {
+                                DPRINT(1, ("TSIP_decode: unit %d: unusable tracking status: %s\n",
+                                       up->unit,
+                                       tracking_status[up->trk_status]));
+                                return false;
+                        }
+                        up->UTC_offset = gets16(&mb(16));
+                        if (!(up->UTC_flags & UTC_AVAILABLE) ||
+                            (up->UTC_offset == 0)) {
+                                pp->leap = LEAP_NOTINSYNC;
+                                DPRINT(1, ("TSIP_decode: unit %d: UTC data not available\n",
+                                       up->unit));
+                                return false;
+                        }
+
+                        secs = getdbl(&mb(3));
+                        secint = (long) secs;
+                        secfrac = secs - secint;  // 0.0 <= secfrac < 1.0
+
+                        pp->nsec = (long) (secfrac * NS_PER_S);
+
+                        secint %= SECSPERDAY;    // Only care about today
+                        up->date.hour = (int)(secint / SECSPERHR);
+                        secint %= SECSPERHR;
+                        up->date.minute = (int)(secint / 60);
+                        secint %= 60;
+                        up->date.second = secint % 60;
+                        up->date.monthday = mb(11);
+                        up->date.month = mb(12);
+                        up->date.year = getu16(&mb(13));
+                        up->date.yearday = 0;
+                        caltogps(&up->date, up->UTC_offset, &up->week, &up->TOW);
+                        gpsweekadj(&up->week, up->build_week);
+                        gpstocal(up->week, up->TOW, up->UTC_offset, &up->date);
+
+                        if ((up->UTC_flags & LEAP_SCHEDULED) &&
+                            // Avoid early announce: https://bugs.ntp.org/2773
+                            (6 == up->date.month || 12 == up->date.month))
+                                pp->leap = LEAP_ADDSECOND;
+                        else
+                                pp->leap = LEAP_NOWARNING;
+
+                        DPRINT(2, ("TSIP_decode: unit %d: 8f-0b #%d %02d:%02d:%02d.%09ld %02d/%02d/%04d UTC %d\n    tracking status: %s\n",
+                               up->unit, event, up->date.hour, up->date.minute,
+                               up->date.second, pp->nsec, up->date.month,
+                               up->date.monthday, up->date.year,
+                               up->UTC_offset, tracking_status[up->trk_status]));
+
+                        // don't reuse UTC flags or tracking status
+                        up->UTC_flags = 0;
+                        up->trk_status = PAL_TSTATS;
+                        return true;
+                        break;
+
+                    case 0xAD:
+                        /*
+                         * primary UTC time packet: first packet sent after PPS
+                         * from Palisade, Acutime, and Praecis
+                         */
+                        if (up->rpt_cnt != 22) {
+                                DPRINT(1, ("TSIP_decode: unit %d: 8f-ad packet length is not 22 (%d)\n",
+                                       up->unit, (int)up->rpt_cnt));
+                                refclock_report(peer, CEVNT_BADREPLY);
+                                return false;
+                        }
+
+                        // flags checked in 8f-0b for Palisade and Acutime
+                        up->trk_status = mb(18);
+                        if (up->trk_status > PAL_TSTATS) {
+                                up->trk_status = PAL_TSTATS;
 }
-			up->UTC_flags = mb(19);
-
-			/* get timecode from 8f-0b except with Praecis */
-			if (up->type != CLK_PRAECIS)
-				return false;
-
-			if (!tracking_status_usable[up->trk_status]) {
-				DPRINT(1, ("TSIP_decode: unit %d: unusable tracking status: %s\n",
-				       up->unit,
-				       tracking_status[up->trk_status]));
-				return false;
-			}
-			if (!(up->UTC_flags & UTC_AVAILABLE)) {
-				pp->leap = LEAP_NOTINSYNC;
-				DPRINT(1, ("TSIP_decode: unit %d: UTC data not available\n",
-				       up->unit));
-				return false;
-			}
-
-			pp->nsec = (long) (getdbl(&mb(3)) * NS_PER_S);
-			up->date.year = getu16(&mb(16));
-			up->date.hour = mb(11);
-			up->date.minute = mb(12);
-			up->date.second = mb(13);
-			up->date.month = mb(15);
-			up->date.monthday = mb(14);
-			caltogps(&up->date, 0, &up->week, &up->TOW);
-			gpsweekadj(&up->week, up->build_week);
-			gpstocal(up->week, up->TOW, 0, &up->date);
-
-			if ((up->UTC_flags & LEAP_SCHEDULED) &&
-			    /* Avoid early announce: https://bugs.ntp.org/2773 */
-			    (6 == up->date.month || 12 == up->date.month))
-				pp->leap = LEAP_ADDSECOND;
-			else
-				pp->leap = LEAP_NOWARNING;
-
-			DPRINT(2, ("TSIP_decode: unit %d: 8f-ad #%d %02d:%02d:%02d.%09ld %02d/%02d/%04d UTC 0x%02x\n    tracking status: %s\n",
-			       up->unit, event, up->date.hour, up->date.minute,
-			       up->date.second, pp->nsec, up->date.month,
-			       up->date.monthday, up->date.year,
-			       up->UTC_flags, tracking_status[up->trk_status]));
-			return true;
-			break;
-
-		    case 0xAC:
-			/*
-			 * supplemental timing packet: sent after 8f-ab from
-			 * Thunderbolt and Resolution SMT
-			 */
-			if (up->rpt_cnt != 68) {
-				DPRINT(1, ("TSIP_decode: unit %d: 8f-ac packet length is not 68 (%d)\n",
-				       up->unit, (int)up->rpt_cnt));
-				refclock_report(peer, CEVNT_BADREPLY);
-				return false;
-			}
-			up->got_time = true;
+                        up->UTC_flags = mb(19);
+
+                        // get timecode from 8f-0b except with Praecis
+                        if (up->type != CLK_PRAECIS)
+                                return false;
+
+                        if (!tracking_status_usable[up->trk_status]) {
+                                DPRINT(1, ("TSIP_decode: unit %d: unusable tracking status: %s\n",
+                                       up->unit,
+                                       tracking_status[up->trk_status]));
+                                return false;
+                        }
+                        if (!(up->UTC_flags & UTC_AVAILABLE)) {
+                                pp->leap = LEAP_NOTINSYNC;
+                                DPRINT(1, ("TSIP_decode: unit %d: UTC data not available\n",
+                                       up->unit));
+                                return false;
+                        }
+
+                        pp->nsec = (long) (getdbl(&mb(3)) * NS_PER_S);
+                        up->date.year = getu16(&mb(16));
+                        up->date.hour = mb(11);
+                        up->date.minute = mb(12);
+                        up->date.second = mb(13);
+                        up->date.month = mb(15);
+                        up->date.monthday = mb(14);
+                        caltogps(&up->date, 0, &up->week, &up->TOW);
+                        gpsweekadj(&up->week, up->build_week);
+                        gpstocal(up->week, up->TOW, 0, &up->date);
+
+                        if ((up->UTC_flags & LEAP_SCHEDULED) &&
+                            // Avoid early announce: https://bugs.ntp.org/2773
+                            (6 == up->date.month || 12 == up->date.month))
+                                pp->leap = LEAP_ADDSECOND;
+                        else
+                                pp->leap = LEAP_NOWARNING;
+
+                        DPRINT(2, ("TSIP_decode: unit %d: 8f-ad #%d %02d:%02d:%02d.%09ld %02d/%02d/%04d UTC 0x%02x\n    tracking status: %s\n",
+                               up->unit, event, up->date.hour, up->date.minute,
+                               up->date.second, pp->nsec, up->date.month,
+                               up->date.monthday, up->date.year,
+                               up->UTC_flags, tracking_status[up->trk_status]));
+                        return true;
+                        break;
+
+                    case 0xAC:
+                        /*
+                         * supplemental timing packet: sent after 8f-ab from
+                         * Thunderbolt and Resolution SMT
+                         */
+                        if (up->rpt_cnt != 68) {
+                                DPRINT(1, ("TSIP_decode: unit %d: 8f-ac packet length is not 68 (%d)\n",
+                                       up->unit, (int)up->rpt_cnt));
+                                refclock_report(peer, CEVNT_BADREPLY);
+                                return false;
+                        }
+                        up->got_time = true;
 #ifdef DEBUG
-			if (debug > 1) { /* SPECIAL DEBUG */
-				double lat, lon, alt;
-				lat = getdbl(&mb(36)) * R2D;
-				lon = getdbl(&mb(44)) * R2D;
-				alt = getdbl(&mb(52));
-				printf("TSIP_decode: unit %d: Latitude: %03.4f Longitude: %03.4f Alt: %05.2f m\n",
-				       up->unit, lat,lon,alt);
-			}
+                        if (debug > 1) {  // SPECIAL DEBUG
+                                double lat, lon, alt;
+                                lat = getdbl(&mb(36)) * R2D;
+                                lon = getdbl(&mb(44)) * R2D;
+                                alt = getdbl(&mb(52));
+                                printf("TSIP_decode: unit %d: Latitude: %03.4f Longitude: %03.4f Alt: %05.2f m\n",
+                                       up->unit, lat,lon,alt);
+                        }
 #endif
-			decod_stat = mb(12);
-			if (decod_stat > TB_DECOD_STATS) {
-				decod_stat = TB_DECOD_STATS;
+                        decod_stat = mb(12);
+                        if (decod_stat > TB_DECOD_STATS) {
+                                decod_stat = TB_DECOD_STATS;
 }
-			disc_mode = mb(2);
-			if (disc_mode > TB_DISC_MODES) {
-				disc_mode = TB_DISC_MODES;
+                        disc_mode = mb(2);
+                        if (disc_mode > TB_DISC_MODES) {
+                                disc_mode = TB_DISC_MODES;
 }
-			DPRINT(2, ("TSIP_decode: unit %d: leap=%d  decod.stat=%s  disc.mode=%s\n",
-			       up->unit, pp->leap,
-			       tracking_status[tb_decod_conv[decod_stat]],
-			       tb_disc_mode[disc_mode]));
-
-			m_alarms = getu16(&mb(10));
-			if (m_alarms & 0x200) {
-				DPRINT(1, ("TSIP_decode: unit %d: 'position questionable' flag is set,\n    you must update the unit's stored position.\n",
-				       up->unit));
-				return false;
-			}
-
-			holdover_t = getu32(&mb(4));
-			if (!tracking_status_usable[tb_decod_conv[decod_stat]])	{
-				if (pp->fudgetime2 < 0.5) {
-					/* holdover not enabled */
-					DPRINT(1, ("TSIP_decode: unit %d: decod.stat of '%s' is unusable\n",
-					       up->unit,
-					       tracking_status[tb_decod_conv[decod_stat]]));
-					return false;
-				}else if (tb_disc_in_holdover[disc_mode] &&
-				          holdover_t > pp->fudgetime2) {
-					DPRINT(1, ("TSIP_decode: unit %d: unit in holdover (disc.mode=%s) with decod.stat of '%s' but holdover time of %us exceeds time2(%.fs)\n",
-					       up->unit,
-					       tb_disc_mode[disc_mode],
-					       tracking_status[tb_decod_conv[decod_stat]],
-					       holdover_t, pp->fudgetime2));
-					return false;
-				} else if (!tb_disc_in_holdover[disc_mode]) {
-					DPRINT(1, ("TSIP_decode: unit %d: not in holdover (disc.mode=%s) and decod.stat of '%s' is unusable\n",
-					       up->unit, tb_disc_mode[disc_mode],
-					       tracking_status[tb_decod_conv[decod_stat]]));
-					return false;
-				}
-			}
-
-			if (up->UTC_flags != UTC_AVAILABLE)
-				return false;
-
-			gpsweekadj(&up->week, up->build_week);
-			gpstocal(up->week, up->TOW, up->UTC_offset, &up->date);
-			if ((m_alarms & 0x80) &&
-			/* Avoid early announce: https://bugs.ntp.org/2773 */
-			    (6 == up->date.month || 12 == up->date.month) )
-				pp->leap = LEAP_ADDSECOND;  /* we ASSUME addsecond */
-			else
-				pp->leap = LEAP_NOWARNING;
-
-			DPRINT(2, ("TSIP_decode: unit %d: 8f-ac TOW: %lu week: %u adj.t: %02d:%02d:%02d.0 %02d/%02d/%04d\n",
-			       up->unit, up->TOW, up->week,
-			       up->date.hour, up->date.minute, up->date.second,
-			       up->date.month, up->date.monthday, up->date.year));
-			return true;
-			break;
-
-		    case 0xAB:
-			/*
-			 * primary timing packet: first packet sent after PPS
-			 * from Thunderbolt and Resolution SMT
-			 */
-			if (up->rpt_cnt != 17) {
-				DPRINT(1, ("TSIP_decode: unit %d: 8f-ab packet length is not 17 (%d)\n",
-				       up->unit, (int)up->rpt_cnt));
-				refclock_report(peer, CEVNT_BADREPLY);
-				return 0;
-			}
-			timing_flags = mb(9);
+                        DPRINT(2, ("TSIP_decode: unit %d: leap=%d  decod.stat=%s  disc.mode=%s\n",
+                               up->unit, pp->leap,
+                               tracking_status[tb_decod_conv[decod_stat]],
+                               tb_disc_mode[disc_mode]));
+
+                        m_alarms = getu16(&mb(10));
+                        if (m_alarms & 0x200) {
+                                DPRINT(1, ("TSIP_decode: unit %d: 'position questionable' flag is set,\n    you must update the unit's stored position.\n",
+                                       up->unit));
+                                return false;
+                        }
+
+                        holdover_t = getu32(&mb(4));
+                        if (!tracking_status_usable[tb_decod_conv[decod_stat]]) {
+                                if (pp->fudgetime2 < 0.5) {
+                                        // holdover not enabled
+                                        DPRINT(1, ("TSIP_decode: unit %d: decod.stat of '%s' is unusable\n",
+                                               up->unit,
+                                               tracking_status[tb_decod_conv[decod_stat]]));
+                                        return false;
+                                }else if (tb_disc_in_holdover[disc_mode] &&
+                                          holdover_t > pp->fudgetime2) {
+                                        DPRINT(1, ("TSIP_decode: unit %d: unit in holdover (disc.mode=%s) with decod.stat of '%s' but holdover time of %us exceeds time2(%.fs)\n",
+                                               up->unit,
+                                               tb_disc_mode[disc_mode],
+                                               tracking_status[tb_decod_conv[decod_stat]],
+                                               holdover_t, pp->fudgetime2));
+                                        return false;
+                                } else if (!tb_disc_in_holdover[disc_mode]) {
+                                        DPRINT(1, ("TSIP_decode: unit %d: not in holdover (disc.mode=%s) and decod.stat of '%s' is unusable\n",
+                                               up->unit, tb_disc_mode[disc_mode],
+                                               tracking_status[tb_decod_conv[decod_stat]]));
+                                        return false;
+                                }
+                        }
+
+                        if (up->UTC_flags != UTC_AVAILABLE)
+                                return false;
+
+                        gpsweekadj(&up->week, up->build_week);
+                        gpstocal(up->week, up->TOW, up->UTC_offset, &up->date);
+                        if ((m_alarms & 0x80) &&
+                        // Avoid early announce: https://bugs.ntp.org/2773
+                            (6 == up->date.month || 12 == up->date.month) )
+                                pp->leap = LEAP_ADDSECOND;  // we ASSUME addsecond
+                        else
+                                pp->leap = LEAP_NOWARNING;
+
+                        DPRINT(2, ("TSIP_decode: unit %d: 8f-ac TOW: %lu week: %u adj.t: %02d:%02d:%02d.0 %02d/%02d/%04d\n",
+                               up->unit, up->TOW, up->week,
+                               up->date.hour, up->date.minute, up->date.second,
+                               up->date.month, up->date.monthday, up->date.year));
+                        return true;
+                        break;
+
+                    case 0xAB:
+                        /*
+                         * primary timing packet: first packet sent after PPS
+                         * from Thunderbolt and Resolution SMT
+                         */
+                        if (up->rpt_cnt != 17) {
+                                DPRINT(1, ("TSIP_decode: unit %d: 8f-ab packet length is not 17 (%d)\n",
+                                       up->unit, (int)up->rpt_cnt));
+                                refclock_report(peer, CEVNT_BADREPLY);
+                                return 0;
+                        }
+                        timing_flags = mb(9);
 #ifdef DEBUG
-			if (debug > 1) { /* SPECIAL DEBUG */
-				printf("TSIP_decode: unit %d: timing flags:0x%02X=\n",
-				       up->unit, timing_flags);
-				if (timing_flags & 0x08) {
-					printf("    timecode aligned to GPS(UTC not avail.), PPS aligned to GPS(UTC not avail.)\n");
-				} else {
-					if (timing_flags & 0x01)
-						printf("    timecode aligned to UTC, ");
-					else
-						printf("    timecode aligned to GPS(misconfigured), ");
-					if (timing_flags & 0x02)
-						printf("PPS aligned to UTC\n");
-					else
-						printf("PPS aligned to GPS(misconfigured)\n");
-				}
-				if (timing_flags & 0x04)
-					printf("    time is NOT set, ");
-				else
-					printf("    time is set, ");
-				if (timing_flags & 0x08)
-					printf("UTC is NOT available, ");
-				else
-					printf("UTC is available, ");
-				if (timing_flags & 0x10)
-					printf("test-mode timesource(misconfigured)\n");
-				else
-					printf("satellite timesource\n");
-			}
+                        if (debug > 1) {  // SPECIAL DEBUG
+                                printf("TSIP_decode: unit %d: timing flags:0x%02X=\n",
+                                       up->unit, timing_flags);
+                                if (timing_flags & 0x08) {
+                                        printf("    timecode aligned to GPS(UTC not avail.), PPS aligned to GPS(UTC not avail.)\n");
+                                } else {
+                                        if (timing_flags & 0x01)
+                                                printf("    timecode aligned to UTC, ");
+                                        else
+                                                printf("    timecode aligned to GPS(misconfigured), ");
+                                        if (timing_flags & 0x02)
+                                                printf("PPS aligned to UTC\n");
+                                        else
+                                                printf("PPS aligned to GPS(misconfigured)\n");
+                                }
+                                if (timing_flags & 0x04)
+                                        printf("    time is NOT set, ");
+                                else
+                                        printf("    time is set, ");
+                                if (timing_flags & 0x08)
+                                        printf("UTC is NOT available, ");
+                                else
+                                        printf("UTC is available, ");
+                                if (timing_flags & 0x10)
+                                        printf("test-mode timesource(misconfigured)\n");
+                                else
+                                        printf("satellite timesource\n");
+                        }
 #endif
-			up->UTC_flags = 0;
-			up->UTC_offset = gets16(&mb(7));
-			if (timing_flags & 0x04 || timing_flags & 0x08 ||
-			    up->UTC_offset == 0) {
-				DPRINT(1, ("TSIP_decode: unit %d: time not set or UTC offset unavailable\n",
-					up->unit));
-				return false;
-			}
-			/*
-			 * configuration is sent only at ntpd startup. if unit
-			 * loses power it will revert to the factory default
-			 * time alignment (GPS)
-			 */
-			if (!(timing_flags & 0x01) || !(timing_flags & 0x02) ||
-			    (timing_flags & 0x10)) {
-				DPRINT(1, ("TSIP_decode: unit %d: 8f-ab flags: not UTC time: unit is misconfigured (0x%02X)\n",
-				       up->unit, timing_flags));
-				pp->leap = LEAP_NOTINSYNC;
-				refclock_report(peer, CEVNT_BADTIME);
-				return false;
-			}
-			up->TOW = getu32(&mb(1));
-			up->week = getu16(&mb(5));
-
-			pp->lastrec = up->p_recv_time;
-			pp->nsec = 0;
-			up->UTC_flags = UTC_AVAILABLE; /* flag for 8f-ac */
-			return false;
-			break;
-
-		    default:
-			break;
-		} /* switch */
-	}
-
-	else if (id == 0x41) {
-		/*
-		 * GPS time packet from ACE III or Copernicus II receiver.
-		 * The ACE III issues these in response to a HW poll.
-		 * The Copernicus II receiver issues these by default once a second.
-		 */
-		if ((up->type != CLK_ACE) && (up->type != CLK_COPERNICUS))
-			return false;
-
-		if (up->rpt_cnt != 10) {
-			DPRINT(1, ("TSIP_decode: unit %d: 41 packet length is not 10 (%d)\n",
-			       up->unit, (int)up->rpt_cnt));
-			refclock_report(peer, CEVNT_BADREPLY);
-			return false;
-		}
-
-		/*
+                        up->UTC_flags = 0;
+                        up->UTC_offset = gets16(&mb(7));
+                        if (timing_flags & 0x04 || timing_flags & 0x08 ||
+                            up->UTC_offset == 0) {
+                                DPRINT(1, ("TSIP_decode: unit %d: time not set or UTC offset unavailable\n",
+                                        up->unit));
+                                return false;
+                        }
+                        /*
+                         * configuration is sent only at ntpd startup. if unit
+                         * loses power it will revert to the factory default
+                         * time alignment (GPS)
+                         */
+                        if (!(timing_flags & 0x01) || !(timing_flags & 0x02) ||
+                            (timing_flags & 0x10)) {
+                                DPRINT(1, ("TSIP_decode: unit %d: 8f-ab flags: not UTC time: unit is misconfigured (0x%02X)\n",
+                                       up->unit, timing_flags));
+                                pp->leap = LEAP_NOTINSYNC;
+                                refclock_report(peer, CEVNT_BADTIME);
+                                return false;
+                        }
+                        up->TOW = getu32(&mb(1));
+                        up->week = getu16(&mb(5));
+
+                        pp->lastrec = up->p_recv_time;
+                        pp->nsec = 0;
+                        up->UTC_flags = UTC_AVAILABLE;  // flag for 8f-ac
+                        return false;
+                        break;
+
+                    default:
+                        break;
+                }  // switch
+        }
+
+        else if (id == 0x41) {
+                /*
+                 * GPS time packet from ACE III or Copernicus II receiver.
+                 * The ACE III issues these in response to a HW poll.
+                 * The Copernicus II receiver issues these by default once a second.
+                 */
+                if ((up->type != CLK_ACE) && (up->type != CLK_COPERNICUS))
+                        return false;
+
+                if (up->rpt_cnt != 10) {
+                        DPRINT(1, ("TSIP_decode: unit %d: 41 packet length is not 10 (%d)\n",
+                               up->unit, (int)up->rpt_cnt));
+                        refclock_report(peer, CEVNT_BADREPLY);
+                        return false;
+                }
+
+                /*
                  * A negative value of TOW indicates the receiver has not established the time.
-		 * This can occur even if UTC_offset is correct.
-		 */
-		TOWfloat = getsgl(&mb(0));
-		up->got_time = (TOWfloat >= 0);
-		if (!up->got_time)
-			return false;
-		up->TOW  = (unsigned long int)TOWfloat;
-		up->week = getu16(&mb(4));
-		up->UTC_offset = (int)getsgl(&mb(6));
-		if (up->UTC_offset == 0) {
-			DPRINT(1, ("TSIP_decode: unit %d: UTC data not available\n",
-			       up->unit));
-			return false;
-		}
-
-		gpsweekadj(&up->week, up->build_week);
-		gpstocal(up->week, up->TOW, up->UTC_offset, &up->date);
-
-		/*
+                 * This can occur even if UTC_offset is correct.
+                 */
+                TOWfloat = getsgl(&mb(0));
+                up->got_time = (TOWfloat >= 0);
+                if (!up->got_time)
+                        return false;
+                up->TOW  = (unsigned long int)TOWfloat;
+                up->week = getu16(&mb(4));
+                up->UTC_offset = (int)getsgl(&mb(6));
+                if (up->UTC_offset == 0) {
+                        DPRINT(1, ("TSIP_decode: unit %d: UTC data not available\n",
+                               up->unit));
+                        return false;
+                }
+
+                gpsweekadj(&up->week, up->build_week);
+                gpstocal(up->week, up->TOW, up->UTC_offset, &up->date);
+
+                /*
                  * The HW_poll occurs at 1Hz but with random phase w.r.t the system clock.
                  * If we are using polling, cancel out the random phase offset by setting
-		 * pp->nsec to the fractional part of lastrec.
-		 */
-		if (up->use_event) {
-			lastrec_frac = lfpfrac(pp->lastrec);
-			secfrac = (double)lastrec_frac / FRAC;
-			pp->nsec = (long) (secfrac * NS_PER_S);
-		} else {
-			pp->lastrec = up->p_recv_time;
-			pp->nsec = 0;
-		}
-
-		DPRINT(2, ("TSIP_decode: unit %d: 41 TOW: %lu week: %u UTC %d adj.t: %02d:%02d:%02d.0 %02d/%02d/%04d\n",
-		       up->unit, up->TOW, up->week, up->UTC_offset,
-		       up->date.hour, up->date.minute, up->date.second,
-		       up->date.month, up->date.monthday, up->date.year));
-		return true;
-	}
-
-	return false;
+                 * pp->nsec to the fractional part of lastrec.
+                 */
+                if (up->use_event) {
+                        lastrec_frac = lfpfrac(pp->lastrec);
+                        secfrac = (double)lastrec_frac / FRAC;
+                        pp->nsec = (long) (secfrac * NS_PER_S);
+                } else {
+                        pp->lastrec = up->p_recv_time;
+                        pp->nsec = 0;
+                }
+
+                DPRINT(2, ("TSIP_decode: unit %d: 41 TOW: %lu week: %u UTC %d adj.t: %02d:%02d:%02d.0 %02d/%02d/%04d\n",
+                       up->unit, up->TOW, up->week, up->UTC_offset,
+                       up->date.hour, up->date.minute, up->date.second,
+                       up->date.month, up->date.monthday, up->date.year));
+                return true;
+        }
+
+        return false;
 }
 
 /*
@@ -972,63 +972,63 @@ TSIP_decode (
  */
 static void
 trimble_receive (
-	struct peer * peer,
-	int type
-	)
+        struct peer * peer,
+        int type
+        )
 {
-	struct trimble_unit *up;
-	struct refclockproc *pp;
-
-	/* Initialize pointers and read the timecode and timestamp. */
-	pp = peer->procptr;
-	up = pp->unitptr;
-
-	/*
-	 * Wait for fudge flags to initialize. Also, startup may have caused
-	 * a spurious edge, so wait for first HW_poll()
-	 */
-	if (pp->polls < 1)
-		return;
-
-	up->got_pkt = true;
-	if (MSG_TSIP == type) {
-		if (!TSIP_decode(peer))
-			return;
-	} else {
-		if (SPSTAT_LEN == up->rpt_cnt &&
-		    up->rpt_buf[up->rpt_cnt - 1] == '\r') {
-			up->rpt_buf[up->rpt_cnt - 1] = '\0';
-			record_clock_stats(peer, (char *) up->rpt_buf);
-		}
-		return;
-	}
-
-	/* add sample to filter */
-	/*
+        struct trimble_unit *up;
+        struct refclockproc *pp;
+
+        // Initialize pointers and read the timecode and timestamp.
+        pp = peer->procptr;
+        up = pp->unitptr;
+
+        /*
+         * Wait for fudge flags to initialize. Also, startup may have caused
+         * a spurious edge, so wait for first HW_poll()
+         */
+        if (pp->polls < 1)
+                return;
+
+        up->got_pkt = true;
+        if (MSG_TSIP == type) {
+                if (!TSIP_decode(peer))
+                        return;
+        } else {
+                if (SPSTAT_LEN == up->rpt_cnt &&
+                    up->rpt_buf[up->rpt_cnt - 1] == '\r') {
+                        up->rpt_buf[up->rpt_cnt - 1] = '\0';
+                        record_clock_stats(peer, (char *) up->rpt_buf);
+                }
+                return;
+        }
+
+        // add sample to filter
+        /*
          * The ACE III receiver periodically outputs 0x41 packets by itself,
          * i.e. in addition to those output in response to a poll command.
-	 * When this happens, two 0x41 packets with the same contents will be
-	 * received back to back.  Only process the first of these.
-	 */
-	if (!((up->type == CLK_ACE) && up->event_reply)) {
-		pp->lastref = pp->lastrec;
-		pp->year = up->date.year;
-		pp->yday = up->date.yearday;
-		pp->hour = up->date.hour;
-		pp->minute = up->date.minute;
-		pp->second = up->date.second;
-		DPRINT(2, ("trimble_receive: unit %d: %4d %03d %02d:%02d:%02d.%09ld\n",
-			   up->unit, pp->year, pp->yday, pp->hour, pp->minute,
-			   pp->second, pp->nsec));
-		if (!refclock_process(pp)) {
-			refclock_report(peer, CEVNT_BADTIME);
-			DPRINT(1, ("trimble_receive: unit %d: refclock_process failed!\n",
-			       up->unit));
-			return;
-		}
-		up->samples++;
-		up->event_reply = true;
-	}
+         * When this happens, two 0x41 packets with the same contents will be
+         * received back to back.  Only process the first of these.
+         */
+        if (!((up->type == CLK_ACE) && up->event_reply)) {
+                pp->lastref = pp->lastrec;
+                pp->year = up->date.year;
+                pp->yday = up->date.yearday;
+                pp->hour = up->date.hour;
+                pp->minute = up->date.minute;
+                pp->second = up->date.second;
+                DPRINT(2, ("trimble_receive: unit %d: %4d %03d %02d:%02d:%02d.%09ld\n",
+                           up->unit, pp->year, pp->yday, pp->hour, pp->minute,
+                           pp->second, pp->nsec));
+                if (!refclock_process(pp)) {
+                        refclock_report(peer, CEVNT_BADTIME);
+                        DPRINT(1, ("trimble_receive: unit %d: refclock_process failed!\n",
+                               up->unit));
+                        return;
+                }
+                up->samples++;
+                up->event_reply = true;
+        }
 }
 
 /*
@@ -1036,69 +1036,69 @@ trimble_receive (
  */
 static void
 trimble_poll (
-	int unit,
-	struct peer *peer
-	)
+        int unit,
+        struct peer *peer
+        )
 {
-	struct trimble_unit *up;
-	struct refclockproc *pp;
-	int cl;
-	bool err;
-
-	UNUSED_ARG(unit);
-
-	pp = peer->procptr;
-	up = pp->unitptr;
-
-	/* samples are not taken until second poll */
-	if (++pp->polls < 2)
-		return;
-
-	/* check status for the previous poll interval */
-	err = (up->samples < MIN_SAMPLES);
-	if (err) {
-		refclock_report(peer, CEVNT_TIMEOUT);
-		if (!up->got_pkt) {
-			DPRINT(1, ("trimble_poll: unit %d: no packets found\n",
-			       up->unit));
-		} else if (!up->got_time) {
-			DPRINT(1, ("trimble_poll: unit %d: packet(s) found but none were usable.\nVerify unit isn't connected to Port B and flag3 is correct for Palisade/Acutime\n",
-			       up->unit));
-		} else {
-			DPRINT(1, ("trimble_poll: unit %d: not enough samples (%d, min %d), skipping poll\n",
-			       up->unit, up->samples, MIN_SAMPLES));
-			pp->codeproc = pp->coderecv; /* reset filter */
-		}
-	}
-	up->got_time = false;
-	up->got_pkt = false;
-	up->samples = 0;
-	if (err)
-		return;
-
-	/* ask Praecis for its signal status */
-	if(up->type == CLK_PRAECIS) {
-		if(write(peer->procptr->io.fd,"SPSTAT\r\n",8) < 0)
-			msyslog(LOG_ERR, "REFCLOCK: %s write: %s:",
-			        refclock_name(peer), strerror(errno));
-	}
-
-	/* record clockstats */
-	cl = snprintf(pp->a_lastcode, sizeof(pp->a_lastcode),
-		 "%4d %03d %02d:%02d:%02d.%09ld",
-		 pp->year, pp->yday, pp->hour,pp->minute, pp->second, pp->nsec);
-	pp->lencode = (cl < (int)sizeof(pp->a_lastcode)) ? cl : 0;
-	record_clock_stats(peer, pp->a_lastcode);
-
-	DPRINT(2, ("trimble_poll: unit %d: %s\n",
-	       up->unit, prettydate(pp->lastrec)));
-
-	if (pp->hour == 0 && up->week > up->build_week + 1000)
-		msyslog(LOG_WARNING, "REFCLOCK: %s current GPS week number (%u) is more than 1000 weeks past ntpd's build date (%u), please update",
-		        refclock_name(peer), up->week, up->build_week);
-
-	/* process samples in filter */
-	refclock_receive(peer);
+        struct trimble_unit *up;
+        struct refclockproc *pp;
+        int cl;
+        bool err;
+
+        UNUSED_ARG(unit);
+
+        pp = peer->procptr;
+        up = pp->unitptr;
+
+        // samples are not taken until second poll
+        if (++pp->polls < 2)
+                return;
+
+        // check status for the previous poll interval
+        err = (up->samples < MIN_SAMPLES);
+        if (err) {
+                refclock_report(peer, CEVNT_TIMEOUT);
+                if (!up->got_pkt) {
+                        DPRINT(1, ("trimble_poll: unit %d: no packets found\n",
+                               up->unit));
+                } else if (!up->got_time) {
+                        DPRINT(1, ("trimble_poll: unit %d: packet(s) found but none were usable.\nVerify unit isn't connected to Port B and flag3 is correct for Palisade/Acutime\n",
+                               up->unit));
+                } else {
+                        DPRINT(1, ("trimble_poll: unit %d: not enough samples (%d, min %d), skipping poll\n",
+                               up->unit, up->samples, MIN_SAMPLES));
+                        pp->codeproc = pp->coderecv;  // reset filter
+                }
+        }
+        up->got_time = false;
+        up->got_pkt = false;
+        up->samples = 0;
+        if (err)
+                return;
+
+        // ask Praecis for its signal status
+        if(up->type == CLK_PRAECIS) {
+                if(write(peer->procptr->io.fd,"SPSTAT\r\n",8) < 0)
+                        msyslog(LOG_ERR, "REFCLOCK: %s write: %s:",
+                                refclock_name(peer), strerror(errno));
+        }
+
+        // record clockstats
+        cl = snprintf(pp->a_lastcode, sizeof(pp->a_lastcode),
+                 "%4d %03d %02d:%02d:%02d.%09ld",
+                 pp->year, pp->yday, pp->hour,pp->minute, pp->second, pp->nsec);
+        pp->lencode = (cl < (int)sizeof(pp->a_lastcode)) ? cl : 0;
+        record_clock_stats(peer, pp->a_lastcode);
+
+        DPRINT(2, ("trimble_poll: unit %d: %s\n",
+               up->unit, prettydate(pp->lastrec)));
+
+        if (pp->hour == 0 && up->week > up->build_week + 1000)
+                msyslog(LOG_WARNING, "REFCLOCK: %s current GPS week number (%u) is more than 1000 weeks past ntpd's build date (%u), please update",
+                        refclock_name(peer), up->week, up->build_week);
+
+        // process samples in filter
+        refclock_receive(peer);
 }
 
 /*
@@ -1106,112 +1106,112 @@ trimble_poll (
  */
 static void
 trimble_io (
-	struct recvbuf *rbufp
-	)
+        struct recvbuf *rbufp
+        )
 {
-	struct trimble_unit *up;
-	struct refclockproc *pp;
-	struct peer *peer;
-
-	char * c, * d;
-
-	peer = rbufp->recv_peer;
-	pp = peer->procptr;
-	up = pp->unitptr;
-
-	c = (char *) &rbufp->recv_buffer;
-	d = c + rbufp->recv_length;
-
-	while (c != d) {
-		switch (up->rpt_status) {
-		    case TSIP_PARSED_DLE_1:
-			switch (*c)
-			{
-			    case 0:
-			    case DLE:
-			    case ETX:
-				up->rpt_status = TSIP_PARSED_EMPTY;
-				break;
-
-			    default:
-				up->rpt_status = TSIP_PARSED_DATA;
-				/* save packet ID */
-				up->rpt_buf[0] = *c;
-				/* save packet receive time */
-				up->p_recv_time = rbufp->recv_time;
-				break;
-			}
-			break;
-
-		    case TSIP_PARSED_DATA:
-			if (*c == DLE) {
-				up->rpt_status = TSIP_PARSED_DLE_2;
-			} else if (up->parity_chk && *c == '\377')
-				up->rpt_status = TSIP_PARSED_PARITY;
-			else
-				mb(up->rpt_cnt++) = *c;
-			break;
-
-		    case TSIP_PARSED_PARITY:
-			if (*c == '\377') {
-				up->rpt_status = TSIP_PARSED_DATA;
-				mb(up->rpt_cnt++) = *c;
-			} else {
-				msyslog(LOG_ERR, "REFCLOCK: %s: detected serial parity error or receive buffer overflow",
-					refclock_name(peer));
-				up->rpt_status = TSIP_PARSED_EMPTY;
-			}
-			break;
-
-		    case TSIP_PARSED_DLE_2:
-			if (*c == DLE) {
-				up->rpt_status = TSIP_PARSED_DATA;
-				mb(up->rpt_cnt++) = *c;
-			} else if (*c == ETX) {
-				up->rpt_status = TSIP_PARSED_FULL;
-				trimble_receive(peer, MSG_TSIP);
-			} else {
-				/* error: start new report packet */
-				up->rpt_status = TSIP_PARSED_DLE_1;
-				up->rpt_buf[0] = *c;
-			}
-			break;
-
-		    case TSIP_PARSED_ASCII:
-			if (*c == '\n') {
-				mb(up->rpt_cnt++) = *c;
-				up->rpt_status = TSIP_PARSED_FULL;
-				trimble_receive(peer, MSG_PRAECIS);
-			} else if (up->parity_chk && *c == '\377') {
-				up->rpt_status = TSIP_PARSED_PARITY;
-			} else {
-				mb(up->rpt_cnt++) = *c;
-			}
-			break;
-
-		    case TSIP_PARSED_FULL:
-		    case TSIP_PARSED_EMPTY:
-		    default:
-			up->rpt_cnt = 0;
-			if (*c == DLE) {
-				up->rpt_status = TSIP_PARSED_DLE_1;
-			} else if (up->type == CLK_PRAECIS && NULL != strchr("6L789ADTP", *c)) {
-				/* Praecis command reply */
-				up->rpt_buf[0] = *c;
-				up->rpt_status = TSIP_PARSED_ASCII;
-			} else {
- 				up->rpt_status = TSIP_PARSED_EMPTY;
-			}
-			break;
-		}
-		c++;
-		if (up->rpt_cnt > RMAX - 2) {/* additional byte for ID */
-			up->rpt_status = TSIP_PARSED_EMPTY;
-			DPRINT(1, ("trimble_io: unit %d: oversize serial message (%luB) 0x%02x discarded\n",
-			        up->unit, (unsigned long)up->rpt_cnt,
-				(uint8_t)up->rpt_buf[0]));
-		}
-	} /* while chars in buffer */
+        struct trimble_unit *up;
+        struct refclockproc *pp;
+        struct peer *peer;
+
+        char * c, * d;
+
+        peer = rbufp->recv_peer;
+        pp = peer->procptr;
+        up = pp->unitptr;
+
+        c = (char *) &rbufp->recv_buffer;
+        d = c + rbufp->recv_length;
+
+        while (c != d) {
+                switch (up->rpt_status) {
+                    case TSIP_PARSED_DLE_1:
+                        switch (*c)
+                        {
+                            case 0:
+                            case DLE:
+                            case ETX:
+                                up->rpt_status = TSIP_PARSED_EMPTY;
+                                break;
+
+                            default:
+                                up->rpt_status = TSIP_PARSED_DATA;
+                                // save packet ID
+                                up->rpt_buf[0] = *c;
+                                // save packet receive time
+                                up->p_recv_time = rbufp->recv_time;
+                                break;
+                        }
+                        break;
+
+                    case TSIP_PARSED_DATA:
+                        if (*c == DLE) {
+                                up->rpt_status = TSIP_PARSED_DLE_2;
+                        } else if (up->parity_chk && *c == '\377')
+                                up->rpt_status = TSIP_PARSED_PARITY;
+                        else
+                                mb(up->rpt_cnt++) = *c;
+                        break;
+
+                    case TSIP_PARSED_PARITY:
+                        if (*c == '\377') {
+                                up->rpt_status = TSIP_PARSED_DATA;
+                                mb(up->rpt_cnt++) = *c;
+                        } else {
+                                msyslog(LOG_ERR, "REFCLOCK: %s: detected serial parity error or receive buffer overflow",
+                                        refclock_name(peer));
+                                up->rpt_status = TSIP_PARSED_EMPTY;
+                        }
+                        break;
+
+                    case TSIP_PARSED_DLE_2:
+                        if (*c == DLE) {
+                                up->rpt_status = TSIP_PARSED_DATA;
+                                mb(up->rpt_cnt++) = *c;
+                        } else if (*c == ETX) {
+                                up->rpt_status = TSIP_PARSED_FULL;
+                                trimble_receive(peer, MSG_TSIP);
+                        } else {
+                                // error: start new report packet
+                                up->rpt_status = TSIP_PARSED_DLE_1;
+                                up->rpt_buf[0] = *c;
+                        }
+                        break;
+
+                    case TSIP_PARSED_ASCII:
+                        if (*c == '\n') {
+                                mb(up->rpt_cnt++) = *c;
+                                up->rpt_status = TSIP_PARSED_FULL;
+                                trimble_receive(peer, MSG_PRAECIS);
+                        } else if (up->parity_chk && *c == '\377') {
+                                up->rpt_status = TSIP_PARSED_PARITY;
+                        } else {
+                                mb(up->rpt_cnt++) = *c;
+                        }
+                        break;
+
+                    case TSIP_PARSED_FULL:
+                    case TSIP_PARSED_EMPTY:
+                    default:
+                        up->rpt_cnt = 0;
+                        if (*c == DLE) {
+                                up->rpt_status = TSIP_PARSED_DLE_1;
+                        } else if (up->type == CLK_PRAECIS && NULL != strchr("6L789ADTP", *c)) {
+                                // Praecis command reply
+                                up->rpt_buf[0] = *c;
+                                up->rpt_status = TSIP_PARSED_ASCII;
+                        } else {
+                                up->rpt_status = TSIP_PARSED_EMPTY;
+                        }
+                        break;
+                }
+                c++;
+                if (up->rpt_cnt > RMAX - 2) {  // additional byte for ID
+                        up->rpt_status = TSIP_PARSED_EMPTY;
+                        DPRINT(1, ("trimble_io: unit %d: oversize serial message (%luB) 0x%02x discarded\n",
+                                up->unit, (unsigned long)up->rpt_cnt,
+                                (uint8_t)up->rpt_buf[0]));
+                }
+        }  // while chars in buffer
 }
 
 /*
@@ -1219,20 +1219,20 @@ trimble_io (
  */
 static void
 trimble_timer(
-	int unit,
-	struct peer * peer
-	)
+        int unit,
+        struct peer * peer
+        )
 {
-	struct trimble_unit *up;
-	struct refclockproc *pp;
+        struct trimble_unit *up;
+        struct refclockproc *pp;
 
-	UNUSED_ARG(unit);
+        UNUSED_ARG(unit);
 
-	pp = peer->procptr;
-	up = pp->unitptr;
+        pp = peer->procptr;
+        up = pp->unitptr;
 
-	if (up->use_event)
-		HW_poll(pp);
+        if (up->use_event)
+                HW_poll(pp);
 }
 
 /*
@@ -1240,46 +1240,46 @@ trimble_timer(
  */
 static void
 HW_poll (
-	struct refclockproc * pp
-	)
+        struct refclockproc * pp
+        )
 {
-	struct trimble_unit *up;
-	static const struct timespec ts = {0, 13 * NS_PER_MS};
-
-	up = pp->unitptr;
-
-	struct packettx tx;
-	uint8_t tx_data[10];
-	if (up->type == CLK_ACE) {
-		/* Poll ACE III by sending a 0x21 command */
-		tx.size = 0;
-		tx.data = tx_data;
-		sendcmd (&tx, 0x21);
-		sendetx (&tx, pp->io.fd);
-	} else {
-		/* Edge trigger */
-		if (pp->sloppyclockflag & CLK_FLAG3) {
-			IGNORE(write (pp->io.fd, "", 1));
-		} else {
-			up->MCR &= ~TIOCM_RTS; /* set RTS low from high idle state */
-			IGNORE(ioctl(pp->io.fd, TIOCMSET, &up->MCR));
-
-			/*
-			 * The Acutime 2000 will occasionally transmit with parity
-			 * errors if the low state is held for less than 1ms, and the
-			 * Praecis will produce unstable timestamps if the low state is
-			 * held for less than 12ms.
-			 */
-			nanosleep(&ts, NULL);
-
-			up->MCR |= TIOCM_RTS;  /* make edge / restore idle */
-			IGNORE(ioctl(pp->io.fd, TIOCMSET, &up->MCR));
-		}
-	}
-	up->event_reply = 0;
-
-	/* get timestamp after triggering since RAND_bytes is slow */
-	get_systime(&pp->lastrec);
+        struct trimble_unit *up;
+        static const struct timespec ts = {0, 13 * NS_PER_MS};
+
+        up = pp->unitptr;
+
+        struct packettx tx;
+        uint8_t tx_data[10];
+        if (up->type == CLK_ACE) {
+                // Poll ACE III by sending a 0x21 command
+                tx.size = 0;
+                tx.data = tx_data;
+                sendcmd (&tx, 0x21);
+                sendetx (&tx, pp->io.fd);
+        } else {
+                // Edge trigger
+                if (pp->sloppyclockflag & CLK_FLAG3) {
+                        IGNORE(write (pp->io.fd, "", 1));
+                } else {
+                        up->MCR &= ~TIOCM_RTS;  // set RTS low from high idle state
+                        IGNORE(ioctl(pp->io.fd, TIOCMSET, &up->MCR));
+
+                        /*
+                         * The Acutime 2000 will occasionally transmit with parity
+                         * errors if the low state is held for less than 1ms, and the
+                         * Praecis will produce unstable timestamps if the low state is
+                         * held for less than 12ms.
+                         */
+                        nanosleep(&ts, NULL);
+
+                        up->MCR |= TIOCM_RTS;  // make edge / restore idle
+                        IGNORE(ioctl(pp->io.fd, TIOCMSET, &up->MCR));
+                }
+        }
+        up->event_reply = 0;
+
+        // get timestamp after triggering since RAND_bytes is slow
+        get_systime(&pp->lastrec);
 }
 
 /*
@@ -1287,29 +1287,29 @@ HW_poll (
  */
 static float
 getsgl (
-	uint8_t *bp
-	)
+        uint8_t *bp
+        )
 {
 #ifdef WORDS_BIGENDIAN
-	float out;
+        float out;
 
-	memcpy(&out, bp, sizeof(out));
-	return out;
+        memcpy(&out, bp, sizeof(out));
+        return out;
 #else
-	union {
-		uint8_t ch[4];
-		uint32_t u32;
-	} ui;
+        union {
+                uint8_t ch[4];
+                uint32_t u32;
+        } ui;
 
-	union {
-		float out;
-		uint32_t u32;
-	} uo;
+        union {
+                float out;
+                uint32_t u32;
+        } uo;
 
-	memcpy(ui.ch, bp, sizeof(ui.ch));
-	uo.u32 = ntohl(ui.u32);
+        memcpy(ui.ch, bp, sizeof(ui.ch));
+        uo.u32 = ntohl(ui.u32);
 
-	return uo.out;
+        return uo.out;
 #endif
 }
 
@@ -1318,32 +1318,32 @@ getsgl (
  */
 static double
 getdbl (
-	uint8_t *bp
-	)
+        uint8_t *bp
+        )
 {
 #ifdef WORDS_BIGENDIAN
-	double out;
+        double out;
 
-	memcpy(&out, bp, sizeof(out));
-	return out;
+        memcpy(&out, bp, sizeof(out));
+        return out;
 #else
-	union {
-		uint8_t ch[8];
-		uint32_t u32[2];
-	} ui;
-
-	union {
-		double out;
-		uint32_t u32[2];
-	} uo;
-
-	memcpy(ui.ch, bp, sizeof(ui.ch));
-	/* least-significant 32 bits of double from swapped bp[4] to bp[7] */
-	uo.u32[0] = ntohl(ui.u32[1]);
-	/* most-significant 32 bits from swapped bp[0] to bp[3] */
-	uo.u32[1] = ntohl(ui.u32[0]);
-
-	return uo.out;
+        union {
+                uint8_t ch[8];
+                uint32_t u32[2];
+        } ui;
+
+        union {
+                double out;
+                uint32_t u32[2];
+        } uo;
+
+        memcpy(ui.ch, bp, sizeof(ui.ch));
+        // least-significant 32 bits of double from swapped bp[4] to bp[7]
+        uo.u32[0] = ntohl(ui.u32[1]);
+        // most-significant 32 bits from swapped bp[0] to bp[3]
+        uo.u32[1] = ntohl(ui.u32[0]);
+
+        return uo.out;
 #endif
 }
 
@@ -1352,13 +1352,13 @@ getdbl (
  */
 static int16_t
 gets16 (
-	uint8_t *bp
-	)
+        uint8_t *bp
+        )
 {
-	int16_t us;
+        int16_t us;
 
-	memcpy(&us, bp, sizeof(us));
-	return ntohs(us);
+        memcpy(&us, bp, sizeof(us));
+        return ntohs(us);
 }
 
 /*
@@ -1366,13 +1366,13 @@ gets16 (
  */
 static uint16_t
 getu16 (
-	uint8_t *bp
-	)
+        uint8_t *bp
+        )
 {
-	uint16_t us;
+        uint16_t us;
 
-	memcpy(&us, bp, sizeof(us));
-	return ntohs(us);
+        memcpy(&us, bp, sizeof(us));
+        return ntohs(us);
 }
 
 /*
@@ -1380,11 +1380,11 @@ getu16 (
  */
 static uint32_t
 getu32(
-	uint8_t *bp
-	)
+        uint8_t *bp
+        )
 {
-	uint32_t u32;
+        uint32_t u32;
 
-	memcpy(&u32, bp, sizeof(u32));
-	return ntohl(u32);
+        memcpy(&u32, bp, sizeof(u32));
+        return ntohl(u32);
 }



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/compare/33df4dd37784d5dd8508e96d1d5ce20599bb3f83...d349d220f32be248273cced393f359b376913662

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/compare/33df4dd37784d5dd8508e96d1d5ce20599bb3f83...d349d220f32be248273cced393f359b376913662
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/dd5e4aeb/attachment-0001.htm>


More information about the vc mailing list