Make sure all output code paths set the locale information (Issue #61)

This commit is contained in:
Michael R Sweet 2024-01-27 19:23:51 -05:00
parent e882622233
commit b117959725
No known key found for this signature in database
GPG Key ID: BE67C75EC81F3244
4 changed files with 19 additions and 4 deletions

View File

@ -1,7 +1,7 @@
#
# Makefile for PDFio.
#
# Copyright © 2021-2023 by Michael R Sweet.
# Copyright © 2021-2024 by Michael R Sweet.
#
# Licensed under Apache License v2.0. See the file "LICENSE" for more
# information.
@ -163,7 +163,9 @@ install: $(TARGETS)
# Test everything
test: testpdfio testttf
./testttf 2>test.log
./testpdfio 2>test.log
./testpdfio 2>>test.log
LANG=fr_FR.UTF-8 ./testpdfio 2>>test.log
valgrind: testpdfio
valgrind --leak-check=full ./testpdfio

View File

@ -264,6 +264,9 @@ pdfioFileCreate(
if (!_pdfioFilePrintf(pdf, "%%PDF-%s\n%%PDF\303\254o\n", version))
goto error;
if (pdf->loc)
_pdfioFilePrintf(pdf, "%%decimal_point=\"%s\"\n", pdf->loc->decimal_point);
// Create the pages object...
if ((dict = pdfioDictCreate(pdf)) == NULL)
goto error;
@ -510,6 +513,7 @@ pdfioFileCreateOutput(
return (NULL);
}
pdf->loc = get_lconv();
pdf->filename = strdup("output.pdf");
pdf->version = strdup(version);
pdf->mode = _PDFIO_MODE_WRITE;
@ -789,6 +793,7 @@ pdfioFileCreateTemporary(
break;
}
pdf->loc = get_lconv();
pdf->filename = strdup(buffer);
if (i >= 1000)
@ -1591,6 +1596,8 @@ get_lconv(void)
if ((loc = localeconv()) != NULL)
{
PDFIO_DEBUG("get_lconv: loc=%p, loc->decimal_point=\"%s\"\n", loc, loc->decimal_point);
if (!loc->decimal_point || !strcmp(loc->decimal_point, "."))
loc = NULL;
}

View File

@ -238,6 +238,7 @@ _pdfio_vsnprintf(pdfio_file_t *pdf, // I - PDF file
if ((decptr = strstr(temp, dec)) != NULL)
{
// Convert locale decimal point to "."
PDFIO_DEBUG("_pdfio_vsnprintf: Before \"%s\"\n", temp);
tempptr = decptr + strlen(dec);
if (tempptr > (decptr + 1))
memmove(decptr + 1, tempptr, strlen(tempptr) + 1);
@ -249,6 +250,8 @@ _pdfio_vsnprintf(pdfio_file_t *pdf, // I - PDF file
if (*tempptr == '.')
*tempptr = '\0'; // Strip trailing decimal point
PDFIO_DEBUG("_pdfio_vsnprintf: After \"%s\"\n", temp);
}
// Copy to the output buffer
@ -361,7 +364,7 @@ _pdfio_vsnprintf(pdfio_file_t *pdf, // I - PDF file
*bufptr = '\0';
}
fprintf(stderr, "_pdfio_vsnprintf: %ld \"%s\"\n", (long)bytes, buffer);
PDFIO_DEBUG("_pdfio_vsnprintf: Returning %ld \"%s\"\n", (long)bytes, buffer);
return (bytes);
}

View File

@ -1,7 +1,7 @@
//
// Test program for PDFio.
//
// Copyright © 2021-2023 by Michael R Sweet.
// Copyright © 2021-2024 by Michael R Sweet.
//
// Licensed under Apache License v2.0. See the file "LICENSE" for more
// information.
@ -16,6 +16,7 @@
#include "pdfio-private.h"
#include "pdfio-content.h"
#include <math.h>
#include <locale.h>
#ifndef M_PI
# define M_PI 3.14159265358979323846264338327950288
#endif // M_PI
@ -61,6 +62,8 @@ main(int argc, // I - Number of command-line arguments
int ret = 0; // Return value
fprintf(stderr, "testpdfio: Test locale is \"%s\".\n", setlocale(LC_ALL, getenv("LANG")));
if (argc > 1)
{
int i; // Looping var