NO

Author Topic: Unicode and Wide characters in Terminal apps using Pelles C  (Read 9857 times)

Offline stbradley

  • Member
  • *
  • Posts: 1
Unicode and Wide characters in Terminal apps using Pelles C
« on: November 04, 2021, 08:43:39 PM »
Greetings,

I have occasionally wanted to create a Terminal program that uses Greek letters, superscript and subscript numbers and some scientific symbols. I found that this can easily be done using Unicode. Additionally, C and C++ handle Unicode as wide characters (wchar_t) and have many functions available for handling them. So, naively, I thought this would easily solve my problem and I could write my program. But I'm not so lucky. And thus began the 2020 Console Video project (COVID-20). (2020 because I started working on it in 2020).  ;D

As anyone who has tried to use Unicode or wide characters in C or C++ will soon discover your Terminal will not display Unicode or wide characters correctly. It turns out that not only does displaying these characters properly depend on what OS you are using, it depends on what compiler you use. So I have created the single header "unicoder.h" that hides the dirty work from you by figuring out what OS (Windows or Linux) and compilers, IDEs (Pelles C or see listing included in documentation for others) you are using and then setting things up so that you can display wide characters and Unicode easily. It also includes many definitions of Unicode characters for your convenience.

I have also added some features to Unicoder that let you turn on/off underline, bold fonts and color font/background, etc..

On the off chance someone might be interested in using Unicode or wide characters you can find Unicoder here:
https://github.com/sthomasbradley/Unicoder

I am announcing this here solely because I included Pelles C as one of the IDEs I tested.  I am aware that Pelles C does quite a nice job handling Unicode.
See Ya
STB

Grincheux

  • Guest
Re: Unicode and Wide characters in Terminal apps using Pelles C
« Reply #1 on: November 04, 2021, 09:02:05 PM »
Thank for the comments and the source code.
I will have a look because Unicode is not what I know the best.
Now, we have no choice for usng Unicode, starting with an example is welcome.

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: Unicode and Wide characters in Terminal apps using Pelles C
« Reply #2 on: November 06, 2021, 10:45:43 AM »
Good job.
Thanks for info e for the sharing  :)
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

Offline John Z

  • Member
  • *
  • Posts: 865
Re: Unicode and Wide characters in Terminal apps using Pelles C
« Reply #3 on: November 06, 2021, 02:55:51 PM »
Hi stbradley,

I don't know if I'll need this but I want to applaud you for the documentation you provide for the Unicoder project!
Excellent work with examples etc.  This will definitely make the capability you are providing more usable.

Well Done!

John Z

Offline Midykm

  • Member
  • *
  • Posts: 1
Re: Unicode and Wide characters in Terminal apps using Pelles C
« Reply #4 on: September 04, 2024, 01:18:30 PM »
Years later, another response to your post?
Indeed!
It was only yesterday that I found a link to your post on Pelle's forum, and I downloaded Unicoder version 21.11 via GitHub.
I haven't tried Unicoder.h yet, but I'm sure it will work as expected, and I didn't want to wait and say thanks!
I'm just a hobby programmer. I'm just brushing up on my C skills, and the Unicode problems I experienced left me all alone, amazed and helpless.
In addition to Pelles C, I also work with Open Watcom and Visual Studio.
Thanks again for your work!


Online Vortex

  • Member
  • *
  • Posts: 870
    • http://www.vortex.masmcode.com
Re: Unicode and Wide characters in Terminal apps using Pelles C
« Reply #5 on: September 04, 2024, 08:22:03 PM »
Hello,

I tried to build the code below but I received some error messages :

Code: [Select]
#include <wchar.h>
#include "unicoder.h"

int wmain(int argc, wchar_t **argv)
{
wcharOn(); // Turn on wide character mode.
wprintf(L"This is a test.");

return 0;
}

Code: [Select]
Building UniCoder.obj.
E:\PellesC\UniCoder\unicoder.h(775): warning #2234: Argument 4 to 'swprintf' does not match the format string; expected 'unsigned long long int' but found 'unsigned long int'.
E:\PellesC\UniCoder\UniCoder.c(6): warning #2018: Undeclared function 'wcharOn' (did you mean: ?); assuming 'extern' returning 'int'.
E:\PellesC\UniCoder\unicoder.h(164): warning #2135: Static '__color' is not referenced.
Building UniCoder.exe.
POLINK: error: Unresolved external symbol '_wcharOn' - referenced from 'E:\PellesC\UniCoder\output\UniCoder.obj'.
POLINK: fatal error: 1 unresolved external(s).
*** Error code: 1 ***
Done.

unicoder.h and the documentation does not refer to the function wcharOn().
Code it... That's all...

Offline John Z

  • Member
  • *
  • Posts: 865
Re: Unicode and Wide characters in Terminal apps using Pelles C
« Reply #6 on: September 04, 2024, 11:05:46 PM »
It looks like maybe somewhere along the way he changed the procedure name and did not update all of the example source files.  The example myfirst.c source file does not match the documentation myfirst.c program in the documentation, page 4 shown below.  Give this a try

Code: [Select]
#include "unicoder.h"
int main(void)
{
umode_t oldmode;
oldmode = udispOn(); // Turn on unicode display mode.
wprintf(L"Unicode: f(x) = %lc%lc+ %lc%lc\n",U_alpha,U_squared,U_beta,U_cubed);
//udispOff(oldmode); //document 'readme' says this does not work with Pelles C
return 0;
}
Looks like wcharOn() was replaced with udispOn()

Nowhere is the DOC is wcharOn mentioned either .... only udispOn and udispOff are used

John Z
« Last Edit: September 05, 2024, 05:59:48 AM by John Z »

Online Vortex

  • Member
  • *
  • Posts: 870
    • http://www.vortex.masmcode.com
Re: Unicode and Wide characters in Terminal apps using Pelles C
« Reply #7 on: September 05, 2024, 08:46:46 PM »
Hi John,

The source code need to be maintained, compiling the example code above :

Quote
Unicode: f(x) = ?²+ ß³

Code: [Select]
Building UniCoder.obj.
E:\PellesC\UniCoder\unicoder.h(775): warning #2234: Argument 4 to 'swprintf' does not match the format string; expected 'unsigned long long int' but found 'unsigned long int'.
E:\PellesC\UniCoder\unicoder.h(164): warning #2135: Static '__color' is not referenced.
Building UniCoder.exe.
Code it... That's all...

Offline John Z

  • Member
  • *
  • Posts: 865
Re: Unicode and Wide characters in Terminal apps using Pelles C
« Reply #8 on: September 05, 2024, 11:46:48 PM »
The source code need to be maintained, ....

Agree!  No update in 3 years on GitHub.  There is an e-mail in the documents so maybe he would update.  Maybe an interested party, and heavy console user, would assume it with a fork or other method under GPL3 -

Also I do not see any switches to account for Pelles C in 64 bit vs 32 bit.  I'm guessing you did 64 bit.

John Z

Online Vortex

  • Member
  • *
  • Posts: 870
    • http://www.vortex.masmcode.com
Re: Unicode and Wide characters in Terminal apps using Pelles C
« Reply #9 on: September 06, 2024, 12:54:03 PM »
Hi John,

It was a 32-bit testing but I don't think that 64-bit would be different.
Code it... That's all...