2 * mstolfp - convert an ascii string in milliseconds to an l_fp number
8 #include "ntp_stdlib.h"
16 register const char *cp;
18 register const char *cpdec;
22 * We understand numbers of the form:
24 * [spaces][-][digits][.][digits][spaces|\n|\0]
26 * This is one enormous hack. Since I didn't feel like
27 * rewriting the decoding routine for milliseconds, what
28 * is essentially done here is to make a copy of the string
29 * with the decimal moved over three places so the seconds
30 * decoding routine can be used.
34 while (isspace((int)*cp))
42 if (*cp != '.' && !isdigit((int)*cp))
47 * Search forward for the decimal point or the end of the string.
50 while (isdigit((int)*cpdec))
54 * Found something. If we have more than three digits copy the
55 * excess over, else insert a leading 0.
57 if ((cpdec - cp) > 3) {
60 } while ((cpdec - cp) > 3);
66 * Stick the decimal in. If we've got less than three digits in
67 * front of the millisecond decimal we insert the appropriate number
71 if ((cpdec - cp) < 3) {
72 register int 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((int)*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((int)*cp))
99 return atolfp(buf, lfp);