2 * mstolfp - convert an ascii string in milliseconds to an l_fp number
9 #include "ntp_stdlib.h"
17 register const char *cp;
19 register const char *cpdec;
23 * We understand numbers of the form:
25 * [spaces][-][digits][.][digits][spaces|\n|\0]
27 * This is one enormous hack. Since I didn't feel like
28 * rewriting the decoding routine for milliseconds, what
29 * is essentially done here is to make a copy of the string
30 * with the decimal moved over three places so the seconds
31 * decoding routine can be used.
35 while (isspace((unsigned char)*cp))
43 if (*cp != '.' && !isdigit((unsigned char)*cp))
48 * Search forward for the decimal point or the end of the string.
51 while (isdigit((unsigned char)*cpdec))
55 * Found something. If we have more than three digits copy the
56 * excess over, else insert a leading 0.
58 if ((cpdec - cp) > 3) {
61 } while ((cpdec - cp) > 3);
67 * Stick the decimal in. If we've got less than three digits in
68 * front of the millisecond decimal we insert the appropriate number
72 if ((cpdec - cp) < 3) {
73 size_t i = 3 - (cpdec - cp);
80 * Copy the remainder up to the millisecond decimal. If cpdec
81 * is pointing at a decimal point, copy in the trailing number too.
88 while (isdigit((unsigned char)*cp))
94 * Check to make sure the string is properly terminated. If
95 * so, give the buffer to the decoding routine.
97 if (*cp != '\0' && !isspace((unsigned char)*cp))
99 return atolfp(buf, lfp);