"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "lib/formatter.c" between
udunits-2.2.26.tar.gz and udunits-2.2.28.tar.gz

About: UDUNITS supports units of physical quantities. Its C library provides for arithmetic manipulation of units and for conversion of numeric values between compatible units.

formatter.c  (udunits-2.2.26):formatter.c  (udunits-2.2.28)
/* /*
* Copyright 2013 University Corporation for Atmospheric Research * Copyright 2020 University Corporation for Atmospheric Research
* *
* This file is part of the UDUNITS-2 package. See the file COPYRIGHT * This file is part of the UDUNITS-2 package. See the file COPYRIGHT
* in the top-level source-directory of the package for copying and * in the top-level source-directory of the package for copying and
* redistribution conditions. * redistribution conditions.
*/ */
/* /*
* This module is thread-compatible but not thread-safe. * This module is thread-compatible but not thread-safe.
*/ */
/*LINTLIBRARY*/ /*LINTLIBRARY*/
#ifndef _XOPEN_SOURCE #include "config.h"
# define _XOPEN_SOURCE 500
#endif #include "udunits2.h"
#include "unitToIdMap.h"
#ifdef _MSC_VER #ifdef _MSC_VER
#define _USE_MATH_DEFINES #define _USE_MATH_DEFINES
#endif #endif
#include <ctype.h> #include <ctype.h>
#include <float.h> #include <float.h>
#include <limits.h> #include <limits.h>
#include <math.h> #include <math.h>
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include "udunits2.h"
#include "unitToIdMap.h"
typedef const char* (*IdGetter)(const ut_unit*, ut_encoding); typedef const char* (*IdGetter)(const ut_unit*, ut_encoding);
typedef int (*ProductPrinter)(const ut_unit* const*, const in t*, typedef int (*ProductPrinter)(const ut_unit* const*, const in t*,
int, char*, size_t, IdGetter); int, char*, size_t, IdGetter);
/* /*
* Formatting parameters: * Formatting parameters:
*/ */
typedef struct { typedef struct {
IdGetter getId; IdGetter getId;
ProductPrinter printProduct; ProductPrinter printProduct;
skipping to change at line 63 skipping to change at line 61
#define ABS(x) ((x) < 0 ? -(x) : (x)) #define ABS(x) ((x) < 0 ? -(x) : (x))
#define RETURNS_NAME(getId) ((getId) == getName) #define RETURNS_NAME(getId) ((getId) == getName)
#define SUBTRACT_SIZET(a, b) ((a) > (b) ? (a) - (b) : 0) #define SUBTRACT_SIZET(a, b) ((a) > (b) ? (a) - (b) : 0)
static int static int
asciiPrintProduct( asciiPrintProduct(
const ut_unit* const* const basicUnits, const ut_unit* const* const basicUnits,
const int* const powers, const int* const powers,
const int count, const int count,
char* const buf, char* const buf,
const size_t max, size_t max,
IdGetter getId); IdGetter getId);
static int static int
latin1PrintProduct( latin1PrintProduct(
const ut_unit* const* const basicUnits, const ut_unit* const* const basicUnits,
const int* const powers, const int* const powers,
const int count, const int count,
char* const buf, char* const buf,
const size_t max, size_t max,
IdGetter getId); IdGetter getId);
static int static int
utf8PrintProduct( utf8PrintProduct(
const ut_unit* const* const basicUnits, const ut_unit* const* const basicUnits,
const int* const powers, const int* const powers,
const int count, const int count,
char* const buf, char* const buf,
const size_t max, size_t max,
IdGetter getId); IdGetter getId);
static ut_visitor formatter; static ut_visitor formatter;
/* /*
* Returns a name for a unit. * Returns a name for a unit.
* *
* Arguments: * Arguments:
* unit Pointer to the unit to have it's name returned. * unit Pointer to the unit to have it's name returned.
* encoding The encoding of the name to be returned. * encoding The encoding of the name to be returned.
skipping to change at line 753 skipping to change at line 751
nchar += n; nchar += n;
size = SUBTRACT_SIZET(size, n); size = SUBTRACT_SIZET(size, n);
if (negativeCount > 1) { if (negativeCount > 1) {
n = snprintf(buf+nchar, size, "%s", ")"); n = snprintf(buf+nchar, size, "%s", ")");
if (0 > n) { if (0 > n) {
nchar = n; nchar = n;
} }
else { else {
nchar += n; nchar += n;
size = SUBTRACT_SIZET(size, n); // size = SUBTRACT_SIZET(size, n); // not us ed
} }
} }
} }
} /* solidus appended */ } /* solidus appended */
} /* positive exponents printed */ } /* positive exponents printed */
} /* "buf" initialized */ } /* "buf" initialized */
(void)free(order); (void)free(order);
} /* "order" allocated */ } /* "order" allocated */
} /* using Latin-1 encoding */ } /* using Latin-1 encoding */
skipping to change at line 914 skipping to change at line 912
} /* non-zero offset */ } /* non-zero offset */
if (nchar >= 0) { if (nchar >= 0) {
if (needParens) { if (needParens) {
n = snprintf(buf+nchar, size, "%s", ")"); n = snprintf(buf+nchar, size, "%s", ")");
if (0 > n) { if (0 > n) {
nchar = n; nchar = n;
} }
else { else {
nchar += n; nchar += n;
size = SUBTRACT_SIZET(size, n); // size = SUBTRACT_SIZET(size, n); // Not used
} }
} }
} /* printed offset if appropriate */ } /* printed offset if appropriate */
} /* underlying unit printed */ } /* underlying unit printed */
} /* scale printed if appropriate */ } /* scale printed if appropriate */
return nchar; return nchar;
} }
/* /*
skipping to change at line 1041 skipping to change at line 1039
} }
if (nchar >= 0) { if (nchar >= 0) {
int useNames = RETURNS_NAME(getId); int useNames = RETURNS_NAME(getId);
n = format(underlyingUnit, buf+nchar, size, useNames, getDefinition, n = format(underlyingUnit, buf+nchar, size, useNames, getDefinition,
encoding, 1); encoding, 1);
nchar = n < 0 ? n : nchar + n; nchar = n < 0 ? n : nchar + n;
if (nchar >= 0) { if (nchar >= 0) {
int useSeparators = useNames || year < 1000 || year > 9999; size = SUBTRACT_SIZET(size, n);
int useSeparators = useNames || year < 1000 || year > 9999;
n = snprintf(buf+nchar, size, n = snprintf(buf+nchar, size,
useSeparators useSeparators
? " %s %d-%02d-%02d %02d:%02d" ? " %s %d-%02d-%02d %02d:%02d"
: " %s %d%02d%02dT%02d%02d", : " %s %d%02d%02dT%02d%02d",
useNames ? "since" : "@", useNames ? "since" : "@",
year, month, day, hour, minute); year, month, day, hour, minute);
if (0 > n) { if (0 > n) {
nchar = -1; nchar = -1;
} }
else { else {
nchar += n; nchar += n;
size = SUBTRACT_SIZET(size, n); size = SUBTRACT_SIZET(size, n);
} }
if (nchar >= 0) { if (nchar >= 0) {
int decimalCount = -(int)floor(log10(resolution)); int decimalCount = resolution <= 0.0
? 9 // Nanosecond resolution
: -(int)floor(log10(resolution));
if (decimalCount > -2) { if (decimalCount > -2) {
n = snprintf(buf+nchar, size, n = snprintf(buf+nchar, size,
useSeparators ? ":%0*.*f" : "%0*.*f", useSeparators ? ":%0*.*f" : "%0*.*f",
decimalCount+3, decimalCount, second); decimalCount+3, decimalCount, second);
if (0 > n) { if (0 > n) {
nchar = -1; nchar = -1;
} }
else { else {
nchar += n; nchar += n;
skipping to change at line 1081 skipping to change at line 1083
} /* sufficient precision for seconds */ } /* sufficient precision for seconds */
if (nchar >= 0) { if (nchar >= 0) {
n = snprintf(buf+nchar, size, "%s", n = snprintf(buf+nchar, size, "%s",
addParens ? " UTC)" : " UTC"); addParens ? " UTC)" : " UTC");
if (0 > n) { if (0 > n) {
nchar = -1; nchar = -1;
} }
else { else {
nchar += n; nchar += n;
size = SUBTRACT_SIZET(size, n); // size = SUBTRACT_SIZET(size, n); // Not used
} }
} /* printed seconds if appropriate */ } /* printed seconds if appropriate */
} /* printed year through minute */ } /* printed year through minute */
} /* underlying unit printed */ } /* underlying unit printed */
} /* leading "(" printed if appropriate */ } /* leading "(" printed if appropriate */
return nchar; return nchar;
} }
/* /*
 End of changes. 11 change blocks. 
15 lines changed or deleted 17 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)