02111-1307, USA. */
#include <config.h>
-#include <assert.h>
+#include "error.h"
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <stdlib.h>
#include <time.h>
-#include "approx.h"
+#include "calendar.h"
#include "error.h"
#include "format.h"
-#include "julcal/julcal.h"
#include "magic.h"
#include "misc.h"
#include "misc.h"
case FMT_A:
assert (0);
+ abort ();
case FMT_AHEX:
assert (0);
+ abort ();
case FMT_IB:
ok = convert_IB (s, fp, number);
default:
assert (0);
+ abort ();
}
}
else
default:
assert (0);
+ abort ();
}
}
/* The C locale always uses a period `.' as a decimal point.
Translate to comma if necessary. */
- if ((set_decimal == ',' && fp->type != FMT_DOT)
- || (set_decimal == '.' && fp->type == FMT_DOT))
+ if ((get_decimal() == ',' && fp->type != FMT_DOT)
+ || (get_decimal() == '.' && fp->type == FMT_DOT))
{
char *cp = strchr (buf, '.');
if (cp)
};
char buf[64] = {0};
+ int ofs = number / 86400.;
int month, day, year;
- julian_to_calendar (number / 86400., &year, &month, &day);
+ if (ofs < 1)
+ return 0;
+
+ calendar_offset_to_gregorian (ofs, &year, &month, &day);
switch (fp->type)
{
case FMT_DATE:
break;
case FMT_JDATE:
{
- int yday = (number / 86400.) - calendar_to_julian (year, 1, 1) + 1;
+ int yday = calendar_offset_to_yday (ofs);
- if (fp->w >= 7)
- {
- if (year4 (year))
- sprintf (buf, "%04d%03d", year, yday);
- }
- else
- sprintf (buf, "%02d%03d", year % 100, yday);
+ if (fp->w < 7)
+ sprintf (buf, "%02d%03d", year % 100, yday);
+ else if (year4 (year))
+ sprintf (buf, "%04d%03d", year, yday);
+ else
break;
}
case FMT_QYR:
break;
case FMT_WKYR:
{
- int yday = (number / 86400.) - calendar_to_julian (year, 1, 1) + 1;
+ int yday = calendar_offset_to_yday (ofs);
if (fp->w >= 10)
sprintf (buf, "%02d WK% 04d", (yday - 1) / 7 + 1, year);
if (i % 3 == 0 && n_digits > i && n_items > n_reserved)
{
n_items--;
- *dst++ = fp->type == FMT_COMMA ? set_grouping : set_decimal;
+ *dst++ = fp->type == FMT_COMMA ? get_grouping() : get_decimal();
}
*dst++ = *sp++;
}
static int
try_CCx (char *dst, const struct fmt_spec *fp, double number)
{
- struct set_cust_currency *cc = &set_cc[fp->type - FMT_CCA];
+ const struct set_cust_currency *cc = get_cc(fp->type - FMT_CCA);
struct fmt_spec f;
/* Determine length available, decimal character for number
proper. */
- f.type = cc->decimal == set_decimal ? FMT_COMMA : FMT_DOT;
+ f.type = cc->decimal == get_decimal() ? FMT_COMMA : FMT_DOT;
f.w = fp->w - strlen (cc->prefix) - strlen (cc->suffix);
if (number < 0)
f.w -= strlen (cc->neg_prefix) + strlen (cc->neg_suffix) - 1;
n_int = 0;
/* Avoid printing `-.000'. 7/6/96. */
- if (approx_eq (number, 0.0))
+ if (mag < EPSILON)
number = 0.0;
}
else
digits in floor(number), including any sign. */
for (;;)
{
- if (mag >= power10[n_int]) /* Should this be approx_ge()? */
+ if (mag >= power10[n_int])
{
assert (delta[j]);
n_int += delta[j++];
if (n == n_int + n_dec)
{
/* Convert periods `.' to commas `,' for our foreign friends. */
- if ((set_decimal == ',' && fp->type != FMT_DOT)
- || (set_decimal == '.' && fp->type == FMT_DOT))
+ if ((get_decimal() == ',' && fp->type != FMT_DOT)
+ || (get_decimal() == '.' && fp->type == FMT_DOT))
{
cp = strchr (cp, '.');
if (cp)