Opened 7 years ago

Closed 6 years ago

#9696 closed bug (fixed)

cal command not aware of UTF-8 strings

Reported by: un_spacyar Owned by: nobody
Priority: normal Milestone: R1
Component: Applications Version: R1/alpha4.1
Keywords: cal Cc:
Blocked By: Blocking:
Platform: x86


Hello! When type ' cal ' command in the Terminal, the app show the first row of days misaligned (please, see attachment).

Attachments (2)

cal_command.png (11.2 KB ) - added by un_spacyar 7 years ago.
193148.Capture.log (144 bytes ) - added by siarzhuk 7 years ago.
Output of cal in Galician local

Download all attachments as: .zip

Change History (9)

by un_spacyar, 7 years ago

Attachment: cal_command.png added

comment:1 by anevilyak, 7 years ago

Component: - GeneralKits/Locale Kit
Owner: changed from nobody to pulkomandy

Based on some tests, appears to be locale-specific.

comment:2 by pulkomandy, 7 years ago

Which locale is it ? It looks like the two-letter code for saturday is "s\n" or something similar, leading to the cursor not going to the next line like it should. The day names come from ICU data, maybe we need to update our version of it.

by siarzhuk, 7 years ago

Attachment: 193148.Capture.log added

Output of cal in Galician local

comment:3 by siarzhuk, 7 years ago

No idea what was the original locale, but Galego (Espana) - has the same issue.

the last byte at days names line is 0xC3 that is 11000011. In UTF-8 encoding it should be the first byte of the 2-bytes character - so the next CR is obviously eaten as parto of it. By the way the Terminal capture log show that lines are ended with CRLF that is also looking a bit suspicious. ;-)

comment:4 by pulkomandy, 7 years ago

Component: Kits/Locale KitApplications
Keywords: Terminal removed
Owner: changed from pulkomandy to nobody
Summary: Terminal - cal command show misaligned textcal command not aware of UTF-8 strings

"cal" blindly truncate the (correct) string returned by strftime. I'm not sure what to do, fixing this properly requires use of wchar strings, and I'm not sure we can use them with gcc2 and our old glibc.

We should use wcsftime() to format the days in unicode, and grab 2 unicode chars (not 2 bytes) from that. Or find a way to get 2-letter names for the days in a better way. One solution would be to rewrite cal into C++ and use the Locale Kit and BString. Code could be simpler.

comment:5 by un_spacyar, 7 years ago

in response to pulkomandy; my locale settings are "Spanish (Argentina)". If you need more info or testing, just ask. Thank you!

comment:6 by pulkomandy, 6 years ago

The GNU implementation of cal may be used (as an outsourced package). I tried to find fixes for the version we have elsewhere but I could only find either simpler (in retrobsd) or more complex (openbsd, minix, freebsd) versions.

I'm adding a gci task for writing a recipe for it.

comment:7 by pulkomandy, 6 years ago

Resolution: fixed
Status: newclosed

Fixed in hrev48506. You need to install the gcal package to get the command again.

Note: See TracTickets for help on using tickets.