diff --git a/n_atof.c b/n_atof.c index 2c88af03..b9979a3e 100644 --- a/n_atof.c +++ b/n_atof.c @@ -1,7 +1,7 @@ /* * atof.c -- * - * Derived from the "strtod" library procedure to be locale-independent + * Derived from the "strtod" library procedure to be locale-independent * * Copyright (c) 1988-1993 The Regents of the University of California. * Copyright (c) 1994 Sun Microsystems, Inc. @@ -42,14 +42,14 @@ extern int errno; #define NULL 0 #endif -static int maxExponent = 511; /* Largest possible base 10 exponent. Any - * exponent larger than this will already - * produce underflow or overflow, so there's - * no need to worry about additional digits. - */ -static double powersOf10[] = { /* Table giving binary powers of 10. Entry */ - 10., /* is 10^2^i. Used to convert decimal */ - 100., /* exponents into floating-point numbers. */ +static int maxExponent = 511; /* Largest possible base 10 exponent. Any + * exponent larger than this will already + * produce underflow or overflow, so there's + * no need to worry about additional digits. + */ +static double powersOf10[] = { /* Table giving binary powers of 10. Entry */ + 10., /* is 10^2^i. Used to convert decimal */ + 100., /* exponents into floating-point numbers. */ 1.0e4, 1.0e8, 1.0e16, @@ -64,58 +64,58 @@ static double powersOf10[] = { /* Table giving binary powers of 10. Entry */ * * atof -- a LOCALE-INDEPENDENT string to double * - * This procedure converts a floating-point number from an ASCII - * decimal representation to internal double-precision format. + * This procedure converts a floating-point number from an ASCII + * decimal representation to internal double-precision format. * * Results: - * The return value is the double-precision floating-point - * representation of the characters in string. If endPtr isn't - * NULL, then *endPtr is filled in with the address of the - * next character after the last one that was part of the - * floating-point number. + * The return value is the double-precision floating-point + * representation of the characters in string. If endPtr isn't + * NULL, then *endPtr is filled in with the address of the + * next character after the last one that was part of the + * floating-point number. * * Side effects: - * None. + * None. * *---------------------------------------------------------------------- */ double JAtoN(string, endPtr) - const char *string; /* A decimal ASCII floating-point number, - * optionally preceded by white space. - * Must have form "-I.FE-X", where I is the - * integer part of the mantissa, F is the - * fractional part of the mantissa, and X - * is the exponent. Either of the signs - * may be "+", "-", or omitted. Either I - * or F may be omitted, or both. The decimal - * point isn't necessary unless F is present. - * The "E" may actually be an "e". E and X - * may both be omitted (but not just one). - */ - char **endPtr; /* If non-NULL, store terminating character's - * address here. */ + const char *string; /* A decimal ASCII floating-point number, + * optionally preceded by white space. + * Must have form "-I.FE-X", where I is the + * integer part of the mantissa, F is the + * fractional part of the mantissa, and X + * is the exponent. Either of the signs + * may be "+", "-", or omitted. Either I + * or F may be omitted, or both. The decimal + * point isn't necessary unless F is present. + * The "E" may actually be an "e". E and X + * may both be omitted (but not just one). + */ + char **endPtr; /* If non-NULL, store terminating character's + * address here. */ { int sign, expSign = FALSE; double fraction, dblExp, *d; register const char *p; register int c; - int exp = 0; /* Exponent read from "EX" field. */ - int fracExp = 0; /* Exponent that derives from the fractional - * part. Under normal circumstatnces, it is - * the negative of the number of digits in F. - * However, if I is very long, the last digits - * of I get dropped (otherwise a long I with a - * large negative exponent could cause an - * unnecessary overflow on I alone). In this - * case, fracExp is incremented one for each - * dropped digit. */ - int mantSize; /* Number of digits in mantissa. */ - int decPt; /* Number of mantissa digits BEFORE decimal - * point. */ - const char *pExp; /* Temporarily holds location of exponent - * in string. */ + int exp = 0; /* Exponent read from "EX" field. */ + int fracExp = 0; /* Exponent that derives from the fractional + * part. Under normal circumstatnces, it is + * the negative of the number of digits in F. + * However, if I is very long, the last digits + * of I get dropped (otherwise a long I with a + * large negative exponent could cause an + * unnecessary overflow on I alone). In this + * case, fracExp is incremented one for each + * dropped digit. */ + int mantSize; /* Number of digits in mantissa. */ + int decPt; /* Number of mantissa digits BEFORE decimal + * point. */ + const char *pExp; /* Temporarily holds location of exponent + * in string. */ /* * Strip off leading blanks and check for a sign. @@ -123,16 +123,16 @@ JAtoN(string, endPtr) p = string; while (*p == ' ') { - p += 1; + p += 1; } if (*p == '-') { - sign = TRUE; - p += 1; + sign = TRUE; + p += 1; } else { - if (*p == '+') { - p += 1; - } - sign = FALSE; + if (*p == '+') { + p += 1; + } + sign = FALSE; } /* @@ -143,14 +143,14 @@ JAtoN(string, endPtr) decPt = -1; for (mantSize = 0; ; mantSize += 1) { - c = *p; - if (c < '0' || c > '9') { - if ((c != '.') || (decPt >= 0)) { - break; - } - decPt = mantSize; - } - p += 1; + c = *p; + if (c < '0' || c > '9') { + if ((c != '.') || (decPt >= 0)) { + break; + } + decPt = mantSize; + } + p += 1; } /* @@ -163,45 +163,45 @@ JAtoN(string, endPtr) pExp = p; p -= mantSize; if (decPt < 0) { - decPt = mantSize; + decPt = mantSize; } else { - mantSize -= 1; /* One of the digits was the point. */ + mantSize -= 1; /* One of the digits was the point. */ } if (mantSize > 18) { - fracExp = decPt - 18; - mantSize = 18; + fracExp = decPt - 18; + mantSize = 18; } else { - fracExp = decPt - mantSize; + fracExp = decPt - mantSize; } if (mantSize == 0) { - fraction = 0.0; - p = string; - goto done; + fraction = 0.0; + p = string; + goto done; } else { - int frac1, frac2; - frac1 = 0; - for ( ; mantSize > 9; mantSize -= 1) - { - c = *p; - p += 1; - if (c == '.') { - c = *p; - p += 1; - } - frac1 = 10*frac1 + (c - '0'); - } - frac2 = 0; - for (; mantSize > 0; mantSize -= 1) - { - c = *p; - p += 1; - if (c == '.') { - c = *p; - p += 1; - } - frac2 = 10*frac2 + (c - '0'); - } - fraction = (1.0e9 * frac1) + frac2; + int frac1, frac2; + frac1 = 0; + for ( ; mantSize > 9; mantSize -= 1) + { + c = *p; + p += 1; + if (c == '.') { + c = *p; + p += 1; + } + frac1 = 10*frac1 + (c - '0'); + } + frac2 = 0; + for (; mantSize > 0; mantSize -= 1) + { + c = *p; + p += 1; + if (c == '.') { + c = *p; + p += 1; + } + frac2 = 10*frac2 + (c - '0'); + } + fraction = (1.0e9 * frac1) + frac2; } /* @@ -210,25 +210,25 @@ JAtoN(string, endPtr) p = pExp; if ((*p == 'E') || (*p == 'e')) { - p += 1; - if (*p == '-') { - expSign = TRUE; - p += 1; - } else { - if (*p == '+') { - p += 1; - } - expSign = FALSE; - } - while (*p >= '0' && *p <= '9') { - exp = exp * 10 + (*p - '0'); - p += 1; - } + p += 1; + if (*p == '-') { + expSign = TRUE; + p += 1; + } else { + if (*p == '+') { + p += 1; + } + expSign = FALSE; + } + while (*p >= '0' && *p <= '9') { + exp = exp * 10 + (*p - '0'); + p += 1; + } } if (expSign) { - exp = fracExp - exp; + exp = fracExp - exp; } else { - exp = fracExp + exp; + exp = fracExp + exp; } /* @@ -239,34 +239,34 @@ JAtoN(string, endPtr) */ if (exp < 0) { - expSign = TRUE; - exp = -exp; + expSign = TRUE; + exp = -exp; } else { - expSign = FALSE; + expSign = FALSE; } if (exp > maxExponent) { - exp = maxExponent; - errno = ERANGE; + exp = maxExponent; + errno = ERANGE; } dblExp = 1.0; for (d = powersOf10; exp != 0; exp >>= 1, d += 1) { - if (exp & 01) { - dblExp *= *d; - } + if (exp & 01) { + dblExp *= *d; + } } if (expSign) { - fraction /= dblExp; + fraction /= dblExp; } else { - fraction *= dblExp; + fraction *= dblExp; } done: if (endPtr != NULL) { - *endPtr = (char *) p; + *endPtr = (char *) p; } if (sign) { - return -fraction; + return -fraction; } return fraction; } diff --git a/n_helpers.c b/n_helpers.c index 51e52940..1a63fb9a 100644 --- a/n_helpers.c +++ b/n_helpers.c @@ -733,55 +733,55 @@ bool NoteSendToRoute(const char *method, const char *routeAlias, char *notefile, // Get the voltage of the Notecard bool NoteGetVoltage(double *voltage) { - bool success = false; + bool success = false; *voltage = 0.0; J *rsp = NoteRequestResponse(NoteNewRequest("card.voltage")); - if (rsp != NULL) { + if (rsp != NULL) { if (!NoteResponseError(rsp)) *voltage = JGetNumber(rsp, "value"); NoteDeleteResponse(rsp); } - return success; + return success; } // Get the temperature of the Notecard bool NoteGetTemperature(double *temp) { - bool success = false; + bool success = false; *temp = 0.0; J *rsp = NoteRequestResponse(NoteNewRequest("card.temp")); - if (rsp != NULL) { + if (rsp != NULL) { if (!NoteResponseError(rsp)) *temp = JGetNumber(rsp, "value"); NoteDeleteResponse(rsp); } - return success; + return success; } // Get Contact Info bool NoteGetContact(char *nameBuf, int nameBufLen, char *orgBuf, int orgBufLen, char *roleBuf, int roleBufLen, char *emailBuf, int emailBufLen) { bool success = false; - if (nameBuf != NULL) - *nameBuf = '\0'; - if (orgBuf != NULL) - *orgBuf = '\0'; - if (roleBuf != NULL) - *roleBuf = '\0'; - if (emailBuf != NULL) - *emailBuf = '\0'; + if (nameBuf != NULL) + *nameBuf = '\0'; + if (orgBuf != NULL) + *orgBuf = '\0'; + if (roleBuf != NULL) + *roleBuf = '\0'; + if (emailBuf != NULL) + *emailBuf = '\0'; J *rsp = NoteRequestResponse(NoteNewRequest("card.contact")); if (rsp != NULL) { success = !NoteResponseError(rsp); if (success) { - if (nameBuf != NULL) - strlcpy(nameBuf, JGetString(rsp, "name"), nameBufLen); - if (orgBuf != NULL) - strlcpy(orgBuf, JGetString(rsp, "org"), orgBufLen); - if (roleBuf != NULL) - strlcpy(roleBuf, JGetString(rsp, "role"), roleBufLen); - if (emailBuf != NULL) - strlcpy(emailBuf, JGetString(rsp, "email"), emailBufLen); + if (nameBuf != NULL) + strlcpy(nameBuf, JGetString(rsp, "name"), nameBufLen); + if (orgBuf != NULL) + strlcpy(orgBuf, JGetString(rsp, "org"), orgBufLen); + if (roleBuf != NULL) + strlcpy(roleBuf, JGetString(rsp, "role"), roleBufLen); + if (emailBuf != NULL) + strlcpy(emailBuf, JGetString(rsp, "email"), emailBufLen); NoteDeleteResponse(rsp); } } @@ -791,16 +791,16 @@ bool NoteGetContact(char *nameBuf, int nameBufLen, char *orgBuf, int orgBufLen, // Set Contact Info bool NoteSetContact(char *nameBuf, char *orgBuf, char *roleBuf, char *emailBuf) { - J *req = NoteNewRequest("card.contact"); - if (req == NULL) - return false; - if (nameBuf != NULL) + J *req = NoteNewRequest("card.contact"); + if (req == NULL) + return false; + if (nameBuf != NULL) JAddStringToObject(req, "name", nameBuf); - if (orgBuf != NULL) + if (orgBuf != NULL) JAddStringToObject(req, "org", orgBuf); - if (roleBuf != NULL) + if (roleBuf != NULL) JAddStringToObject(req, "role", roleBuf); - if (emailBuf != NULL) + if (emailBuf != NULL) JAddStringToObject(req, "email", emailBuf); return NoteRequest(req); } diff --git a/n_hooks.c b/n_hooks.c index 6e9a1d33..20419a86 100644 --- a/n_hooks.c +++ b/n_hooks.c @@ -44,14 +44,14 @@ static nTransactionFn notecardTransaction = NULL; // Set the debug output hooks if they aren't already set void NoteSetFnDefault(mallocFn mallocfn, freeFn freefn, delayMsFn delayfn, getMsFn millisfn) { - if (hookMalloc == NULL) - hookMalloc = mallocfn; - if (hookFree == NULL) - hookFree = freefn; - if (hookDelayMs == NULL) - hookDelayMs = delayfn; - if (hookGetMs == NULL) - hookGetMs = millisfn; + if (hookMalloc == NULL) + hookMalloc = mallocfn; + if (hookFree == NULL) + hookFree = freefn; + if (hookDelayMs == NULL) + hookDelayMs = delayfn; + if (hookGetMs == NULL) + hookGetMs = millisfn; } // Set the debug output hook void NoteSetFn(mallocFn mallocfn, freeFn freefn, delayMsFn delayfn, getMsFn millisfn) { diff --git a/n_i2c.c b/n_i2c.c index ba6812d1..19abf031 100644 --- a/n_i2c.c +++ b/n_i2c.c @@ -87,9 +87,9 @@ const char *i2cNoteTransaction(char *json, char **jsonResponse) { // We've now received the chunk jsonbufLen += chunklen; - // If the last byte of the chunk is \n, chances are that we're done. However, just so - // that we pull everything pending from the module, we only exit when we've received - // a newline AND there's nothing left available from the module. + // If the last byte of the chunk is \n, chances are that we're done. However, just so + // that we pull everything pending from the module, we only exit when we've received + // a newline AND there's nothing left available from the module. if (jsonbufLen > 0 && jsonbuf[jsonbufLen-1] == '\n') receivedNewline = true; diff --git a/n_str.c b/n_str.c index 3779d466..4d77644e 100644 --- a/n_str.c +++ b/n_str.c @@ -1,5 +1,5 @@ -/* $OpenBSD: strlcpy.c,v 1.10 2005/08/08 08:05:37 espie Exp $ */ -/* $OpenBSD: strlcat.c,v 1.12 2005/03/30 20:13:52 otto Exp $ */ +/* $OpenBSD: strlcpy.c,v 1.10 2005/08/08 08:05:37 espie Exp $ */ +/* $OpenBSD: strlcat.c,v 1.12 2005/03/30 20:13:52 otto Exp $ */ /* * Copyright (c) 1998 Todd C. Miller @@ -27,27 +27,27 @@ */ __attribute__((weak)) size_t strlcpy(char *dst, const char *src, size_t siz) { - char *d = dst; - const char *s = src; - size_t n = siz; + char *d = dst; + const char *s = src; + size_t n = siz; - /* Copy as many bytes as will fit */ - if (n != 0) { - while (--n != 0) { - if ((*d++ = *s++) == '\0') - break; - } - } + /* Copy as many bytes as will fit */ + if (n != 0) { + while (--n != 0) { + if ((*d++ = *s++) == '\0') + break; + } + } - /* Not enough room in dst, add NUL and traverse rest of src */ - if (n == 0) { - if (siz != 0) - *d = '\0'; /* NUL-terminate dst */ - while (*s++) - ; - } + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) { + if (siz != 0) + *d = '\0'; /* NUL-terminate dst */ + while (*s++) + ; + } - return(s - src - 1); /* count does not include NUL */ + return(s - src - 1); /* count does not include NUL */ } /* @@ -59,27 +59,27 @@ __attribute__((weak)) size_t strlcpy(char *dst, const char *src, size_t siz) */ __attribute__((weak)) size_t strlcat(char *dst, const char *src, size_t siz) { - char *d = dst; - const char *s = src; - size_t n = siz; - size_t dlen; + char *d = dst; + const char *s = src; + size_t n = siz; + size_t dlen; - /* Find the end of dst and adjust bytes left but don't go past end */ - while (n-- != 0 && *d != '\0') - d++; - dlen = d - dst; - n = siz - dlen; + /* Find the end of dst and adjust bytes left but don't go past end */ + while (n-- != 0 && *d != '\0') + d++; + dlen = d - dst; + n = siz - dlen; - if (n == 0) - return(dlen + strlen(s)); - while (*s != '\0') { - if (n != 1) { - *d++ = *s; - n--; - } - s++; - } - *d = '\0'; + if (n == 0) + return(dlen + strlen(s)); + while (*s != '\0') { + if (n != 1) { + *d++ = *s; + n--; + } + s++; + } + *d = '\0'; - return(dlen + (s - src)); /* count does not include NUL */ + return(dlen + (s - src)); /* count does not include NUL */ } diff --git a/note.h b/note.h index d3607076..1ec3608a 100644 --- a/note.h +++ b/note.h @@ -86,7 +86,7 @@ bool JContainsString(J *rsp, const char *field, const char *substr); // Helper functions for apps that wish to limit their C library dependencies #define JNRound(x,NUMDIGITS) ((round((x) * 1E##NUMDIGITS)) / 1E##NUMDIGITS) -#define JNTOA_PRECISION (10) +#define JNTOA_PRECISION (10) #define JNTOA_MAX ((2*JNTOA_PRECISION)+1+1) char * JNtoA(double f, char * buf, int precision); double JAtoN(const char *string, char **endPtr);