#include <ctype.h>
#include <stdlib.h>
+#include <time.h>
#include <uniwidth.h>
#include "data/identifier.h"
void
fmt_settings_copy (struct fmt_settings *new, const struct fmt_settings *old)
{
+ new->epoch = old->epoch;
new->decimal = old->decimal;
for (int i = 0; i < FMT_N_CCS; i++)
new->ccs[i] = fmt_number_style_clone (old->ccs[i]);
}
}
+static int
+default_epoch (void)
+{
+ static int epoch = 0;
+ if (!epoch)
+ {
+ time_t t = time (0);
+ struct tm *tm = localtime (&t);
+ epoch = (tm != NULL ? tm->tm_year + 1900 : 2000) - 69;
+ }
+ return epoch;
+}
+
+int
+fmt_settings_get_epoch (const struct fmt_settings *settings)
+{
+ return !settings->epoch ? default_epoch () : settings->epoch;
+}
+
void
fmt_settings_set_cc (struct fmt_settings *settings, enum fmt_type type,
struct fmt_number_style *style)
struct fmt_settings
{
+ int epoch; /* 0 for default epoch. */
char decimal; /* '.' or ','. */
struct fmt_number_style *ccs[FMT_N_CCS]; /* CCA through CCE. */
};
const struct fmt_number_style *fmt_settings_get_style (
const struct fmt_settings *, enum fmt_type);
+int fmt_settings_get_epoch (const struct fmt_settings *);
void fmt_settings_set_cc (struct fmt_settings *, enum fmt_type,
struct fmt_number_style *);
#include <assert.h>
#include <stdlib.h>
-#include <time.h>
#include "data/case.h"
#include "data/format.h"
int viewwidth;
bool safer_mode;
bool include;
- int epoch;
bool route_errors_to_terminal;
bool route_errors_to_listing;
bool scompress;
79, /* viewwidth */
false, /* safer_mode */
true, /* include */
- -1, /* epoch */
true, /* route_errors_to_terminal */
true, /* route_errors_to_listing */
true, /* scompress */
void
settings_init (void)
{
- settings_set_epoch (-1);
settings_set_decimal_char (get_system_decimal ());
}
int
settings_get_epoch (void)
{
- assert (the_settings.epoch >= 0);
-
- return the_settings.epoch;
+ return fmt_settings_get_epoch (&the_settings.styles);
}
/* Sets the year that starts the epoch. */
void
settings_set_epoch (int epoch)
{
- if (epoch < 0)
- {
- time_t t = time (0);
- struct tm *tm = localtime (&t);
- epoch = (tm != NULL ? tm->tm_year + 1900 : 2000) - 69;
- }
-
- the_settings.epoch = epoch;
- assert (the_settings.epoch >= 0);
+ the_settings.styles.epoch = epoch;
}
/* Compress system files by default? */