4 * mstolfp - convert an ascii string in milliseconds to an l_fp number
10 #include "ntp_stdlib.h"
18 register const char *cp
;
20 register const char *cpdec
;
24 * We understand numbers of the form:
26 * [spaces][-][digits][.][digits][spaces|\n|\0]
28 * This is one enormous hack. Since I didn't feel like
29 * rewriting the decoding routine for milliseconds, what
30 * is essentially done here is to make a copy of the string
31 * with the decimal moved over three places so the seconds
32 * decoding routine can be used.
36 while (isspace((int)*cp
))
44 if (*cp
!= '.' && !isdigit((int)*cp
))
49 * Search forward for the decimal point or the end of the string.
52 while (isdigit((int)*cpdec
))
56 * Found something. If we have more than three digits copy the
57 * excess over, else insert a leading 0.
59 if ((cpdec
- cp
) > 3) {
62 } while ((cpdec
- cp
) > 3);
68 * Stick the decimal in. If we've got less than three digits in
69 * front of the millisecond decimal we insert the appropriate number
73 if ((cpdec
- cp
) < 3) {
74 register int i
= 3 - (cpdec
- cp
);
82 * Copy the remainder up to the millisecond decimal. If cpdec
83 * is pointing at a decimal point, copy in the trailing number too.
90 while (isdigit((int)*cp
))
96 * Check to make sure the string is properly terminated. If
97 * so, give the buffer to the decoding routine.
99 if (*cp
!= '\0' && !isspace((int)*cp
))
101 return atolfp(buf
, lfp
);