From 9cb66f740b56b3743dc0e582558b3861b24617a1 Mon Sep 17 00:00:00 2001 From: "Andrew Poelstra (local)" Date: Fri, 25 Nov 2011 12:13:40 -0800 Subject: [PATCH] Add ` modifier to pcb-printf, which forces '.' as a decimal separator This should be used for the gerber exporter and other formats that need to use '.' regardless of locale in order to obey their standards. Note that the %mr specifier (which restricts suffixes to mm and mil so that old pcb versions can read them) uses this by default, so no changes need to be made to file.c. --- src/pcb-printf.c | 12 +++++++++--- src/pcb-printf.h | 9 ++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/pcb-printf.c b/src/pcb-printf.c index f687e067..183ea180 100644 --- a/src/pcb-printf.c +++ b/src/pcb-printf.c @@ -382,7 +382,7 @@ static gchar *CoordsToString(Coord coord[], int n_coords, const char *printf_spe * (+ 2 skips the ", " for first value) */ if (n_coords > 1) g_string_append_c (buff, '('); - if (suffix_type == FILE_MODE) + if (suffix_type == FILE_MODE || suffix_type == FILE_MODE_NO_SUFFIX) { g_ascii_formatd (filemode_buff, sizeof filemode_buff, printf_buff + 2, value[0]); g_string_append_printf (buff, "%s", filemode_buff); @@ -391,7 +391,7 @@ static gchar *CoordsToString(Coord coord[], int n_coords, const char *printf_spe g_string_append_printf (buff, printf_buff + 2, value[0]); for (i = 1; i < n_coords; ++i) { - if (suffix_type == FILE_MODE) + if (suffix_type == FILE_MODE || suffix_type == FILE_MODE_NO_SUFFIX) { g_ascii_formatd (filemode_buff, sizeof filemode_buff, printf_buff, value[i]); g_string_append_printf (buff, "%s", filemode_buff); @@ -407,6 +407,7 @@ static gchar *CoordsToString(Coord coord[], int n_coords, const char *printf_spe switch (suffix_type) { case NO_SUFFIX: + case FILE_MODE_NO_SUFFIX: break; case SUFFIX: g_string_append_printf (buff, " %s", suffix); @@ -479,7 +480,12 @@ gchar *pcb_vprintf(const char *fmt, va_list args) } if(*fmt == '$') { - suffix = SUFFIX; + suffix = (suffix == NO_SUFFIX) ? SUFFIX : FILE_MODE; + fmt++; + } + if(*fmt == '`') + { + suffix = (suffix == SUFFIX) ? FILE_MODE : FILE_MODE_NO_SUFFIX; fmt++; } /* Tack full specifier onto specifier */ diff --git a/src/pcb-printf.h b/src/pcb-printf.h index cbd9bbd5..4b37b381 100644 --- a/src/pcb-printf.h +++ b/src/pcb-printf.h @@ -59,6 +59,8 @@ * # prevents all scaling for %mS/D/1/.../9 (this should * ONLY be used for debug code since its output exposes * pcb's base units). + * ` always use '.' as decimal separator (note that %mr uses + * this by default). * * KNOWN ISSUES: * No support for %zu size_t printf spec @@ -96,7 +98,12 @@ enum e_allow { }; enum e_family { METRIC, IMPERIAL }; -enum e_suffix { NO_SUFFIX, SUFFIX, FILE_MODE }; +enum e_suffix { + NO_SUFFIX, /* no suffix */ + SUFFIX, /* suffix, prefixed with ' ' */ + FILE_MODE_NO_SUFFIX, /* no suffix, force '.' as decimal */ + FILE_MODE /* suffix, force '.' as decimal */ +}; struct unit { int index; /* Index into Unit[] list */ -- 2.11.4.GIT