diff options
author | delphij <delphij@FreeBSD.org> | 2015-07-15 19:21:26 +0000 |
---|---|---|
committer | delphij <delphij@FreeBSD.org> | 2015-07-15 19:21:26 +0000 |
commit | 2a25cee78ab1d37e7d2bc40ae675646974d99f56 (patch) | |
tree | b0302ac4be59e104f4e1e54014561a1389397192 /contrib/ntp/libparse/parse.c | |
parent | a0741a75537b2e0514472ac3b28afc55a7846c30 (diff) | |
download | FreeBSD-src-2a25cee78ab1d37e7d2bc40ae675646974d99f56.zip FreeBSD-src-2a25cee78ab1d37e7d2bc40ae675646974d99f56.tar.gz |
MFC r280849,280915-280916,281015-281016,282097,282408,282415,283542,
284864,285169-285170,285435:
ntp 4.2.8p3.
Relnotes: yes
Approved by: re (?)
Diffstat (limited to 'contrib/ntp/libparse/parse.c')
-rw-r--r-- | contrib/ntp/libparse/parse.c | 136 |
1 files changed, 66 insertions, 70 deletions
diff --git a/contrib/ntp/libparse/parse.c b/contrib/ntp/libparse/parse.c index dfbbaa6..64167f1 100644 --- a/contrib/ntp/libparse/parse.c +++ b/contrib/ntp/libparse/parse.c @@ -1,6 +1,6 @@ /* * /src/NTP/ntp4-dev/libparse/parse.c,v 4.20 2005/08/06 17:39:40 kardel RELEASE_20050806_A - * + * * parse.c,v 4.20 2005/08/06 17:39:40 kardel RELEASE_20050806_A * * Parser module for reference clock @@ -12,7 +12,7 @@ * when PARSEKERNEL is not defined NTP time stamps will be used. * * Copyright (c) 1995-2005 by Frank Kardel <kardel <AT> ntp.org> - * Copyright (c) 1989-1994 by Frank Kardel, Friedrich-Alexander Universität Erlangen-Nürnberg, Germany + * Copyright (c) 1989-1994 by Frank Kardel, Friedrich-Alexander Universitaet Erlangen-Nuernberg, Germany * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -51,7 +51,7 @@ static char rcsid[] = "parse.c,v 4.20 2005/08/06 17:39:40 kardel RELEASE_2005080 #endif #include "ntp_fp.h" -#include "ntp_unixtime.h" +#include "timevalops.h" #include "ntp_calendar.h" #include "ntp_stdlib.h" #include "ntp_machine.h" @@ -68,7 +68,7 @@ static char rcsid[] = "parse.c,v 4.20 2005/08/06 17:39:40 kardel RELEASE_2005080 extern clockformat_t *clockformats[]; extern unsigned short nformats; -static u_long timepacket P((parse_t *)); +static u_long timepacket (parse_t *); /* * strings support usually not in kernel - duplicated, but what the heck @@ -106,7 +106,7 @@ Strcmp( while (!(c = *s++ - *t++) && *s && *t) /* empty loop */; - + return c; } @@ -128,10 +128,6 @@ parse_timedout( delta.tv_usec += 1000000; } #else - extern long tstouslo[]; - extern long tstousmid[]; - extern long tstoushi[]; - l_fp delt; delt = tstamp->fp; @@ -158,10 +154,10 @@ parse_ioinit( ) { parseprintf(DD_PARSE, ("parse_iostart\n")); - + parseio->parse_plen = 0; parseio->parse_pdata = (void *)0; - + parseio->parse_data = 0; parseio->parse_ldata = 0; parseio->parse_dsize = 0; @@ -170,7 +166,7 @@ parse_ioinit( parseio->parse_ioflags = PARSE_IO_CS7; /* usual unix default */ parseio->parse_index = 0; parseio->parse_ldsize = 0; - + return 1; } @@ -192,15 +188,15 @@ parse_ioend( unsigned int parse_restart( parse_t *parseio, - unsigned int ch + char ch ) { unsigned int updated = PARSE_INP_SKIP; - + /* * re-start packet - timeout - overflow - start symbol */ - + if (parseio->parse_index) { /* @@ -212,17 +208,17 @@ parse_restart( parseio->parse_ldsize = parseio->parse_index; updated = PARSE_INP_TIME; } - + parseio->parse_index = 1; parseio->parse_data[0] = ch; parseprintf(DD_PARSE, ("parse: parse_restart: buffer start (updated = %x)\n", updated)); return updated; } - + unsigned int parse_addchar( parse_t *parseio, - unsigned int ch + char ch ) { /* @@ -234,7 +230,7 @@ parse_addchar( * collect into buffer */ parseprintf(DD_PARSE, ("parse: parse_addchar: buffer[%d] = 0x%x\n", parseio->parse_index, ch)); - parseio->parse_data[parseio->parse_index++] = ch; + parseio->parse_data[parseio->parse_index++] = (char)ch; return PARSE_INP_SKIP; } else @@ -243,7 +239,7 @@ parse_addchar( */ return parse_restart(parseio, ch); } - + unsigned int parse_end( parse_t *parseio @@ -264,11 +260,11 @@ parse_end( int parse_ioread( register parse_t *parseio, - register unsigned int ch, + register char ch, register timestamp_t *tstamp ) { - register unsigned updated = CVT_NONE; + register u_int updated = CVT_NONE; /* * within STREAMS CSx (x < 8) chars still have the upper bits set * so we normalize the characters by masking unecessary bits off. @@ -286,9 +282,9 @@ parse_ioread( case PARSE_IO_CS7: ch &= 0x7F; break; - + case PARSE_IO_CS8: - ch &= 0xFF; + ch &= (char) 0xFFU; break; } @@ -310,18 +306,18 @@ parse_ioread( { updated = CVT_OK; } - + if (input_status & PARSE_INP_TIME) /* time sample is available */ { - updated = timepacket(parseio); + updated = (u_int) timepacket(parseio); } - + if (input_status & PARSE_INP_DATA) /* got additional data */ { updated |= CVT_ADDITIONAL; } } - + /* * remember last character time @@ -357,7 +353,7 @@ parse_iopps( register timestamp_t *ptime ) { - register unsigned updated = CVT_NONE; + register u_int updated = CVT_NONE; /* * PPS pulse information will only be delivered to ONE clock format @@ -368,7 +364,7 @@ parse_iopps( if (clockformats[parseio->parse_lformat]->syncpps) { - updated = clockformats[parseio->parse_lformat]->syncpps(parseio, status == SYNC_ONE, ptime); + updated = (u_int) clockformats[parseio->parse_lformat]->syncpps(parseio, status == SYNC_ONE, ptime); parseprintf(DD_PARSE, ("parse_iopps: updated = 0x%x\n", updated)); } @@ -407,13 +403,13 @@ parse_to_unixtime( ) { #define SETRTC(_X_) { if (cvtrtc) *cvtrtc = (_X_); } - static int days_of_month[] = + static int days_of_month[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; register int i; time_t t; - + if (clock_time->utctime) return clock_time->utctime; /* if the conversion routine gets it right away - why not */ @@ -427,12 +423,12 @@ parse_to_unixtime( SETRTC(CVT_FAIL|CVT_BADDATE); return -1; } - + /* * sorry, slow section here - but it's not time critical anyway */ t = julian0(clock_time->year) - julian0(1970); /* Y2kFixes */ - /* month */ + /* month */ if (clock_time->month <= 0 || clock_time->month > 12) { SETRTC(CVT_FAIL|CVT_BADDATE); @@ -470,7 +466,7 @@ parse_to_unixtime( t = TIMES24(t) + clock_time->hour; - /* min */ + /* min */ if (clock_time->minute < 0 || clock_time->minute > 59) { SETRTC(CVT_FAIL|CVT_BADTIME); @@ -479,7 +475,7 @@ parse_to_unixtime( t = TIMES60(t) + clock_time->minute; /* sec */ - + if (clock_time->second < 0 || clock_time->second > 60) /* allow for LEAPs */ { SETRTC(CVT_FAIL|CVT_BADTIME); @@ -514,7 +510,7 @@ Stoi( while(*s == ' ') s++; - + if (*s == '-') { s++; @@ -523,7 +519,7 @@ Stoi( else if (*s == '+') s++; - + for(;;) { c = *s++; @@ -577,16 +573,16 @@ updatetimeinfo( { int s = splhigh(); #endif - + parseio->parse_lstate = parseio->parse_dtime.parse_state | flags | PARSEB_TIMECODE; - + parseio->parse_dtime.parse_state = parseio->parse_lstate; #ifdef PARSEKERNEL (void)splx((unsigned int)s); } #endif - + #ifdef PARSEKERNEL parseprintf(DD_PARSE, ("updatetimeinfo status=0x%x, time=%x\n", parseio->parse_dtime.parse_state, @@ -595,7 +591,7 @@ updatetimeinfo( parseprintf(DD_PARSE, ("updatetimeinfo status=0x%lx, time=%x\n", (long)parseio->parse_dtime.parse_state, parseio->parse_dtime.parse_time.fp.l_ui)); #endif - + return CVT_OK; /* everything fine and dandy... */ } @@ -618,7 +614,7 @@ syn_simple( } /* - * pps_simple + * parse_pps_fnc_t pps_simple * * handle a pps time stamp */ @@ -632,12 +628,12 @@ pps_simple( { parseio->parse_dtime.parse_ptime = *ptime; parseio->parse_dtime.parse_state |= PARSEB_PPS|PARSEB_S_PPS; - + return CVT_NONE; } /* - * pps_one + * parse_pps_fnc_t pps_one * * handle a pps time stamp in ONE edge */ @@ -651,12 +647,12 @@ pps_one( { if (status) return pps_simple(parseio, status, ptime); - + return CVT_NONE; } /* - * pps_zero + * parse_pps_fnc_t pps_zero * * handle a pps time stamp in ZERO edge */ @@ -670,7 +666,7 @@ pps_zero( { if (!status) return pps_simple(parseio, status, ptime); - + return CVT_NONE; } @@ -688,39 +684,39 @@ timepacket( register time_t t; u_long cvtrtc; /* current conversion result */ clocktime_t clock_time; - + memset((char *)&clock_time, 0, sizeof clock_time); format = parseio->parse_lformat; if (format == (unsigned short)~0) return CVT_NONE; - + switch ((cvtrtc = clockformats[format]->convert ? clockformats[format]->convert((unsigned char *)parseio->parse_ldata, parseio->parse_ldsize, (struct format *)(clockformats[format]->data), &clock_time, parseio->parse_pdata) : CVT_NONE) & CVT_MASK) { case CVT_FAIL: parseio->parse_badformat++; - break; - + return cvtrtc; + case CVT_NONE: /* * too bad - pretend bad format */ parseio->parse_badformat++; - break; - + return CVT_NONE; + case CVT_OK: break; - + case CVT_SKIP: return CVT_NONE; default: /* shouldn't happen */ #ifndef PARSEKERNEL - msyslog(LOG_WARNING, "parse: INTERNAL error: bad return code of convert routine \"%s\"\n", clockformats[format]->name); -#endif + msyslog(LOG_WARNING, "parse: INTERNAL error: bad return code of convert routine \"%s\"", clockformats[format]->name); +#endif return CVT_FAIL|cvtrtc; } @@ -728,7 +724,7 @@ timepacket( { return CVT_FAIL|cvtrtc; } - + /* * time stamp */ @@ -736,7 +732,7 @@ timepacket( parseio->parse_dtime.parse_time.tv.tv_sec = t; parseio->parse_dtime.parse_time.tv.tv_usec = clock_time.usecond; #else - parseio->parse_dtime.parse_time.fp.l_ui = t + JAN_1970; + parseio->parse_dtime.parse_time.fp.l_ui = (uint32_t) (t + JAN_1970); TVUTOTSF(clock_time.usecond, parseio->parse_dtime.parse_time.fp.l_uf); #endif @@ -762,7 +758,7 @@ parse_timecode( */ dct->parsegettc.parse_badformat = parse->parse_badformat; parse->parse_badformat = 0; - + if (parse->parse_ldsize <= PARSE_TCMAX) { dct->parsegettc.parse_count = parse->parse_ldsize; @@ -775,7 +771,7 @@ parse_timecode( } } - + /*ARGSUSED*/ int parse_setfmt( @@ -796,7 +792,7 @@ parse_setfmt( if (parse->parse_pdata) FREE(parse->parse_pdata, parse->parse_plen); parse->parse_pdata = 0; - + parse->parse_plen = clockformats[i]->plen; if (parse->parse_plen) @@ -813,9 +809,9 @@ parse_setfmt( if (parse->parse_data) FREE(parse->parse_data, (unsigned)(parse->parse_dsize * 2 + 2)); parse->parse_ldata = parse->parse_data = 0; - + parse->parse_dsize = clockformats[i]->length; - + if (parse->parse_dsize) { parse->parse_data = (char*)MALLOC((unsigned)(parse->parse_dsize * 2 + 2)); @@ -824,20 +820,20 @@ parse_setfmt( if (parse->parse_pdata) FREE(parse->parse_pdata, parse->parse_plen); parse->parse_pdata = 0; - + parseprintf(DD_PARSE, ("init failed: malloc for data area failed\n")); return 0; } } - + /* * leave room for '\0' */ parse->parse_ldata = parse->parse_data + parse->parse_dsize + 1; - + parse->parse_lformat = i; - + return 1; } } @@ -856,7 +852,7 @@ parse_getfmt( if (dct->parseformat.parse_format < nformats && Strlen(clockformats[dct->parseformat.parse_format]->name) <= PARSE_TCMAX) { - dct->parseformat.parse_count = Strlen(clockformats[dct->parseformat.parse_format]->name)+1; + dct->parseformat.parse_count = (unsigned short) (Strlen(clockformats[dct->parseformat.parse_format]->name) + 1); memcpy(dct->parseformat.parse_buffer, clockformats[dct->parseformat.parse_format]->name, dct->parseformat.parse_count); return 1; } @@ -874,7 +870,7 @@ parse_setcs( ) { parse->parse_ioflags &= ~PARSE_IO_CSIZE; - parse->parse_ioflags |= dct->parsesetcs.parse_cs & PARSE_IO_CSIZE; + parse->parse_ioflags |= (int) (dct->parsesetcs.parse_cs & PARSE_IO_CSIZE); return 1; } |