Output format depends on the POSIX locale LC_NUMERIC #740

Closed
opened 2026-01-29 16:52:27 +00:00 by claunia · 7 comments
Owner

Originally created by @v-chvila on GitHub (Feb 28, 2023).

For example: b488126d09/src/lib_ccx/ccx_encoders_smptett.c (L221)
sprintf() is configured by LC_NUMERIC. See: https://linux.die.net/man/3/sprintf Format of the format string
Final output is inconsistent and it is hard to parse. Do you consider some better solution?

Originally created by @v-chvila on GitHub (Feb 28, 2023). For example: https://github.com/CCExtractor/ccextractor/blob/b488126d09de590268a49d6bb18f6c8285147cbf/src/lib_ccx/ccx_encoders_smptett.c#L221 `sprintf()` is configured by LC_NUMERIC. See: https://linux.die.net/man/3/sprintf `Format of the format string` Final output is inconsistent and it is hard to parse. Do you consider some better solution?
claunia added the GSOC-2023 label 2026-01-29 16:52:27 +00:00
Author
Owner

@marcybelardo commented on GitHub (Mar 19, 2023):

We can specify a locale before using sprintf to get the formatting we want, and then immediately return locale to C afterwards I believe?

@marcybelardo commented on GitHub (Mar 19, 2023): We can specify a locale before using sprintf to get the formatting we want, and then immediately return locale to C afterwards I believe?
Author
Owner

@marcybelardo commented on GitHub (Mar 19, 2023):

The more I research, the more I think locales are a nightmare. I might try a fix for this, but wow

@marcybelardo commented on GitHub (Mar 19, 2023): The more I research, the more I think locales are a nightmare. I might try a fix for this, but wow
Author
Owner

@cfsmp3 commented on GitHub (Mar 19, 2023):

The more I research, the more I think locales are a nightmare. I might try a fix for this, but wow

The simplest solution is two just don't use float and use two ints instead. Here's what ChatGPT suggest (I haven't tried, but it gives you an idea)

sprintf(str, "      <p begin=\"%02u:%02u:%02u.%03u\" end=\"%02u:%02u:%02u.%03u\" tts:origin=\"%d.%03d%% %d.%03d%%\">\n        <span>",
        h1, m1, s1, ms1, h2, m2, s2, ms2, (int)(col1), (int)((col1 - (int)col1) * 1000), (int)(row1), (int)((row1 - (int)row1) * 1000));

Forget about locales :-)

@cfsmp3 commented on GitHub (Mar 19, 2023): > The more I research, the more I think locales are a nightmare. I might try a fix for this, but wow The simplest solution is two just don't use float and use two ints instead. Here's what ChatGPT suggest (I haven't tried, but it gives you an idea) ``` sprintf(str, " <p begin=\"%02u:%02u:%02u.%03u\" end=\"%02u:%02u:%02u.%03u\" tts:origin=\"%d.%03d%% %d.%03d%%\">\n <span>", h1, m1, s1, ms1, h2, m2, s2, ms2, (int)(col1), (int)((col1 - (int)col1) * 1000), (int)(row1), (int)((row1 - (int)row1) * 1000)); ``` Forget about locales :-)
Author
Owner

@marcybelardo commented on GitHub (Mar 20, 2023):

Oh I see! I thought that they had to stay as floats :P

@marcybelardo commented on GitHub (Mar 20, 2023): Oh I see! I thought that they had to stay as floats :P
Author
Owner

@cfsmp3 commented on GitHub (Mar 20, 2023):

Oh I see! I thought that they had to stay as floats :P

No - just make sure the output is correct, i.e. always 3 digits (test for numbers ending in 0, 00, 000)...

@cfsmp3 commented on GitHub (Mar 20, 2023): > Oh I see! I thought that they had to stay as floats :P No - just make sure the output is correct, i.e. always 3 digits (test for numbers ending in 0, 00, 000)...
Author
Owner

@cfsmp3 commented on GitHub (Mar 22, 2023):

@v-chvila Could you see if it's fixed for you in master?

@cfsmp3 commented on GitHub (Mar 22, 2023): @v-chvila Could you see if it's fixed for you in master?
Author
Owner

@cfsmp3 commented on GitHub (Mar 27, 2023):

Closing. @v-chvila feel free to reopen if you still have problems.

@cfsmp3 commented on GitHub (Mar 27, 2023): Closing. @v-chvila feel free to reopen if you still have problems.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/ccextractor#740