bugGNU gettext - Bugs: bug #42206, xgettext concatenates lines in C...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #42206: xgettext concatenates lines in C files when it shouldn't

Submitter:  Armijn Hemel <armijn>
Submitted:  Sun 27 Apr 2014 04:59:09 PM UTC
   
 
Category:  C Severity:  3 - Normal
Item Group:  None Status:  Not a Bug
Privacy:  Public Assigned to:  haible
Open/Closed:  Closed

Jump to the original submission

Wed 15 Mar 2023 10:52:35 PM UTC, comment #7: 

Given that

  • the use-case is not internationalization, but "to extract identifiers that could end up in binaries for fingerprinting", and
  • unlike the use-case of internationalization, where we have an entire doc chapter "Preparing Program Sources", here the reporter does not want to modify the sources, and
  • it would be complex to implement,

I'm not going to make this change.

For the use-case of internationalization, the programmer should restructure his code a bit, so as to move complete function calls into the #if/#else branches.

Bruno Haible <haible>
Group administrator
Wed 15 Mar 2023 10:47:20 PM UTC, comment #6: 

If we would want to treat #if lines correctly, we would need to
1) handle the #else case as an alternative,
2) handles contexts correctly,
3) handle different #ifs in different ngettext arguments correctly.

To illustrate the complexity of 1) and 2): The attached init2.c, when processed through
$ xgettext -o - --no-location --omit-header -kmessage:2 -kcmessage:1c,2 init2.c
would need to produce


msgid "The system is halted. You may reboot now."
msgstr ""

msgid "The system is halted. Press Reset or turn off power"
msgstr ""

msgctxt "log"
msgid "You may reboot now."
msgstr ""

msgctxt "log"
msgid "Press Reset or turn off power"
msgstr ""


Currently, with Daiki's patch, it produces


msgid "The system is halted. You may reboot now."
msgstr ""

msgctxt "log"
msgid "You may reboot now."
msgstr ""


In the implementation (x-c.c), this would imply to keep track of several alternative argparsers, where the code currently uses a single argparser.

This is quite complex.

Bruno Haible <haible>
Group administrator
Wed 30 Apr 2014 06:42:40 AM UTC, comment #5: 

Thanks for the background info, perhaps the attached patch might meet your use-case.  However, I doubt if it is generally useful, since there is no way to extract the second string (after #else).


(file #31280)

Daiki Ueno <ueno>
Group administrator
Mon 28 Apr 2014 07:56:43 AM UTC, comment #4: 

Thanks for your swift reply. Unfortunately for me that workaround will not work as my use case is a bit different. Please let me explain. I am using xgettext to analyse vast amounts of source code and to extract identifiers that could end up in binaries for fingerprinting. Because xgettext concatenates these two strings fingerprinting (partially) fails. It is not my intention to modify the source code that I analyse.

It would be great if #if #elif #else #endif and friends could be taken into account by xgettext, if possible.

Armijn Hemel <armijn>
Sun 27 Apr 2014 11:59:14 PM UTC, comment #3: 

Can't it be easily worked around by modifying the code a bit:


#if #cpu(s390)
        /* Seems the s390 console is Wierd(tm). */
        message(CONSOLE | LOG, "The system is halted. You may reboot now.");
#else
        message(CONSOLE | LOG, "The system is halted. Press Reset or turn off power");
#endif


Daiki Ueno <ueno>
Group administrator
Sun 27 Apr 2014 05:01:25 PM UTC, comment #2: 

and also with 0.18.3. Apologies for the noise.

Armijn Hemel <armijn>
Sun 27 Apr 2014 05:00:18 PM UTC, comment #1: 

I forgot to add:

$ xgettext -V
xgettext (GNU gettext-tools) 0.18.2

Armijn Hemel <armijn>
Sun 27 Apr 2014 04:59:09 PM UTC, original submission:  

xgettext concatenates lines in C files when it shouldn't. The following snippet is from init/init.c from BusyBox 1.1.0 (around line 770):


#if #cpu(s390)
            /* Seems the s390 console is Wierd(tm). */
            "The system is halted. You may reboot now."
#else
            "The system is halted. Press Reset or turn off power"
#endif

xgettext produces the following result:

#: init.c:770
msgid ""
"The system is halted. You may reboot now.The system is halted. Press Reset "
"or turn off power"

It would make more sense to report these as two separate strings, if possible.

Armijn Hemel <armijn>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #54493:  init2.c added by haible (465B - text/x-csrc)
file #31280:  gettext-cpp-ifelse.patch added by ueno (1KiB - text/x-patch)
file #31258:  init.c added by armijn (29KiB - text/plain - init.c from BusyBox 1.1.0)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by haible (Updated the item)
  • -email is unavailable- added by ueno (Posted a comment)
  • -email is unavailable- added by armijn (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 9 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2023-03-15 haible StatusNone Not a Bug
        Assigned toNone haible
        Open/ClosedOpen Closed
    2023-03-15 haible Attached File#54494 Removed
    2023-03-15 haible Attached File- Added init2.c, #54493
        Attached File- Added init2.c, #54494
    2016-11-27 haible CategoryNone C
    2014-04-30 ueno Attached File- Added gettext-cpp-ifelse.patch, #31280
    2014-04-27 armijn Attached File- Added init.c, #31258

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code