Menu

DIsplay Euro sign and others Italian characters at screen position

2025-03-29
2025-04-14
  • Maurizio Bongini

    Hi
    Env :
    Linux kernel 6.8.0-49 LUbuntu 2404 LXQT
    Gnucobol just compiled last source version downloaded from this site
    cobc (GnuCOBOL) 3.2.0
    Built Mar 16 2025 16:41:54 Packaged Jul 28 2023 17:02:56 UTC
    C version "13.2.0"
    loading standard configuration file 'default.conf'
    I Attach the code of a sample program to reproduce the problem

          IDENTIFICATION DIVISION.
           PROGRAM-ID. eur.
           ENVIRONMENT DIVISION.
           CONFIGURATION SECTION.
           SOURCE-COMPUTER. COBTEST.
           OBJECT-COMPUTER. COBTEST.
           SPECIAL-NAMES. DECIMAL-POINT IS COMMA.
           INPUT-OUTPUT SECTION.
           FILE-CONTROL.
           DATA DIVISION.
           FILE SECTION.
           WORKING-STORAGE SECTION.
    
           01 DEBUG PIC X .
           01 EURO1 PIC X(3) .
           01 EURO2 PIC X(3) VALUE '€' .
          *Linux utf-8 
           01 EURO3 PIC X(4) VALUE X'E282AC' .
          * Windows cp 1252 
          *01 EURO3 PIC X(4) VALUE '<80>' .  
    
           SCREEN SECTION.
    
           01 S-BLANK BLANK SCREEN .
           PROCEDURE DIVISION.
           MOVE '€' TO EURO1 .
    
           DISPLAY '$'           .
           DISPLAY '€'           .
           DISPLAY EURO1         .
           DISPLAY EURO2         .
           DISPLAY EURO3         .
           ACCEPT DEBUG          .
    
           DISPLAY S-BLANK.
    
           DISPLAY '$'         AT 0102  .
           DISPLAY '€'         AT 0202  .
           DISPLAY EURO1       AT 0302  .
           DISPLAY EURO2       AT 0402 .
           DISPLAY EURO3       AT 0502 .
           ACCEPT DEBUG        AT 0602 .
           STOP RUN .
           END PROGRAM eur.
    

    Program was able to display all the euro signs at the console...
    But euro signs does not display when program clears screen and try to place them with "AT" position.. Dollars prints correctly.. i tried with UXTerm
    here output of my "locale" command, i use US english as LANG and all other locale as italian

    LANG=en_US.UTF-8
    LANGUAGE=
    LC_CTYPE=it_IT.UTF-8
    LC_NUMERIC=it_IT.UTF-8
    LC_TIME=it_IT.UTF-8
    LC_COLLATE=it_IT.UTF-8
    LC_MONETARY=it_IT.UTF-8
    LC_MESSAGES="en_US.UTF-8"
    LC_PAPER=it_IT.UTF-8
    LC_NAME=it_IT.UTF-8
    LC_ADDRESS=it_IT.UTF-8
    LC_TELEPHONE=it_IT.UTF-8
    LC_MEASUREMENT=it_IT.UTF-8
    LC_IDENTIFICATION=it_IT.UTF-8
    LC_ALL=

    Gnucobol was compiled with extended screen I/O : ncursesw
    Source pgm file was correctly saved as UTF-8
    Whats wrong ?
    It may be related to ncursesw ?
    Thanks in advance for your support
    Maurizio

     

    Last edit: Maurizio Bongini 2025-03-29
  • Maurizio Bongini

    further data to investigate
    gnucobol was built with
    libncurses-dev
    ubuntu repository does not provide
    libncursesw6-dev

     

    Last edit: Maurizio Bongini 2025-03-31
  • Chuck Haatvedt

    Chuck Haatvedt - 2025-03-30

    On Windows 10 here in the USA I found that when NOT using extended screen I/O, that GNUCOBOL used the default code for the windows console which is 437, However GNUCOBOL with CURSES uses the locale which for the USA is 1252, this results in some of the same behavior which you are reporting.

    I think that there is a function which will return the CURRENCY SYMBOL based on the locale being used in your environment.

    Simon would probably be able to address this better than I can.

          Chuck Haatvedt
    
     
  • Maurizio Bongini

    Hi
    the problem is not the currency sign .. i'm not able to display also other italian alphabet characters
    like "à" an a with accent, many italian words ending with this letter...
    i forget to delete windows code, i put an asterisk to column 7 , but in windows environment this pgm function very well with cp1252 ... i have problem in linux env only when i place text on the screen , so problem interfacing ncurses .. all characters are displayed correctly at the linux terminal using the dirst part of the code

     

    Last edit: Maurizio Bongini 2025-03-31
  • Maurizio Bongini

    Hi
    I add here further data to help
    not only the euro sign does not work with ncurses but also other special italian characters
    i

        DISPLAY 'à è ò ù'     .
    

    added to first part of my pgm works

         DISPLAY 'à è ò ù'   AT 0802 .
    

    Does not works, nothing displayed
    it seems a problem related to ncurses

     

    Last edit: Maurizio Bongini 2025-03-31
  • Maurizio Bongini

    I put in the attachment output of c Program
    i create also this other small c program to display € at console output

    #include <stdio.h>
    
    int main()
    {
           int RC ;
           char enter ;
    
           printf("€");
           RC = scanf("%c",&enter);    /* Wait for user input */
           return 0;
    }
    

    and it works correctly

     
  • Maurizio Bongini

    Hi
    i was able to display € sign and other italian characters with C Language using ncursesw , in the following post i will put the code

     

    Last edit: Maurizio Bongini 2025-03-31
  • Maurizio Bongini

    define  _XOPEN_SOURCE_EXTENDED
    #include <locale.h>
    #include "/usr/include/ncursesw/curses.h"
    
    int main()
    {
           setlocale(LC_CTYPE, "") ;
           initscr();                  /* Start curses mode                 */
           move(2, 2);
           printw("line 1 ");          /* Print               */
           move(3, 2);
           printw("à è ò ù");          /* Print               */
           move(4, 2);
           printw("€");                /* Print               */
           move(5, 2);
           printw("\xe2\x82\xac\n");
           refresh();                  /* Print it on to the real screen */
           getch();                    /* Wait for user input */
           endwin();                   /* End curses mode            */
    
           return 0;
    }
    
    
    // gcc -Wall ncurses.c -o hello  -lncursesw
    

    in the last line i wrote gcc compile parameters
    when i run ./hello i get the correct output.. (see attached file)
    At this point, if C language is able to work correctly with ncursesw with my system settings
    IMHO the problem is into Gnucobol , let me know if u have to compile again Gnucobol and reinstall because the LC_CTYPE was not setted or if i have to fo further testing for you
    Thanks in advance
    Maurizio

     
    • Simon Sobisch

      Simon Sobisch - 2025-03-31

      Just to ensure that there's not a bad comparison: what is the output of cobcrun --verbose --info?

      In any case the main difference is the way the characters are handled. To follow COBOL rules and expectations we have to get one char out, step by step (and we want to bring it to a specific curses window).

      As you can see in https://sourceforge.net/p/gnucobol/code/5469/tree/branches/gnucobol-3.x/libcob/screenio.c#l1783 this is not done with printw() but with waddch ().
      But the part where the error likely happens is where we get the COBOL data and pass that to curses: https://sourceforge.net/p/gnucobol/code/5469/tree/branches/gnucobol-3.x/libcob/screenio.c#l1961 - we take the COBOL data, byte by byte, casting it to a chtype.
      Doing so with UTF8 data (multi-byte) likely won't work; for the equivalence to your printw, it the code possibly needs to call wadd_wch(), but then the input likely needs to be converted via mbtowc...

      Your source is encoded in UTF8, right? (A plain DISPLAY to that UTF8 terminal works, which only outputs each character to the stdout buffer and the terminal then reads that buffer for display.)
      I guess you'd then need to indeed use the wide character functions, and possibly that would mean to convert the data (at least for a portable curses solution, I think you can just cast a char in ncurses and it still would work).

      Maybe you want to give that a try, by adjusting the GnuCOBOL sources ? In this case have a look at the nightly build under download and take the 3.x tarball.

       
  • Maurizio Bongini

    Hi Simon
    Here command output

    bong@notebook:~/MyPgm/Cobol/work$ cobcrun --verbose --info 
    libcob (GnuCOBOL) 3.2.0
    Copyright (C) 2023 Free Software Foundation, Inc.
    License LGPLv3+: GNU LGPL version 3 or later <https://gnu.org/licenses/lgpl.html>
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    Written by Keisuke Nishida, Roger While, Ron Norman, Simon Sobisch, Edward Hart
    Built     Mar 31 2025 22:41:50
    Packaged  Jul 28 2023 17:02:56 UTC
    
    build information
    build environment        : x86_64-pc-linux-gnu
    CC                       : gcc
    C version                : "13.3.0"
    CPPFLAGS                 : 
    CFLAGS                   : -O2 -pipe -finline-functions -fsigned-char -Wall
                               -Wwrite-strings -Wmissing-prototypes
                               -Wno-format-y2k
    LD                       : /usr/bin/ld -m elf_x86_64
    LDFLAGS                  :  -Wl,-z,relro,-z,now,-O1
    
    GnuCOBOL information
    COB_MODULE_EXT           : so
    dynamic loading          : system
    "CBL_" param check       : disabled
    64bit-mode               : yes
    BINARY-C-LONG            : 8 bytes
    endianness               : little-endian
    native EBCDIC            : no
    variable file format     : 0
    sequential file handler  : built-in
    indexed file handler     : BDB, version 5.3.28
    mathematical library     : GMP, version 6.3.0
    XML library              : libxml2, version 2.9.14
    JSON library             : cJSON, version 1.7.17
    extended screen I/O      : ncursesw, version 6.4.20240113 (CHTYPE=32, WIDE=1)
                               xterm with 256 colors
    mouse support            : yes
    

    Next
    As you can see from dates, i re-install the original Gnucobol ... but i still have the problem
    Yes source file was saved UTF-8
    i use Vim to edit and i save with

    :w ++enc=utf-8
    

    Now here is very late, i will study your post tomorrow
    Thanks for the support
    Maurizio

     

    Last edit: Maurizio Bongini 2025-03-31
  • Maurizio Bongini

    Hi Simon
    Let me know when the ightly build with the above changes is available

     
    • Simon Sobisch

      Simon Sobisch - 2025-04-01

      I don't have time to do anything myself in this area - but you're invited to give it a go, starting with the nightly build.

       

      Last edit: Simon Sobisch 2025-04-01
  • Klaus Siebke

    Klaus Siebke - 2025-04-01

    Could you please try this:

    1. Save the source in a codepage specific to your language (in my case it's German, so I use ISO-8859-15).
    2. Compile the source with: cobc -x cobtest.cbl -lncurses
    3. Run the program with: luit -encoding ISO-8859-15 -x ./cobtest

    Here (I am running Fedora 40 Linux) it's showing all Euro signs correcty, except the UTF-8 one, but that is also correct as we are using another codepage.

     

    Last edit: Klaus Siebke 2025-04-01
  • Maurizio Bongini

    Hi Klaus
    My Lubuntu 24.04 does not provide luit, it has x11-utils..

     
  • Maurizio Bongini

    Updated ..
    Hi Simon
    English is not my mother tongue.. i want to avoid misunderstanding..
    Some years ago, i installed gnucobol, and old version to a debian machine, also this machine configured to have language en_US and all locale to italian.. and all function properly
    i did not write the C test program because i feel myself a guru , but only for problem determination
    A create the small cobol program to test some italian characters..
    all characters displays correctly if i direct output to console. i immagine is stdout
    None of the same set of characters display when use screen..
    To check if there are problem in my installation i generate the sample C code..
    at this point is clear than the issue is between Gnucobol ,and ncursesw
    but i never write in my life a pgm interfacing with ncurses.. this is the first one
    you show me the two instructions involved in the problem and explain me that i cannot simply change the waddch (mywin, c); with a printw ...
    if i correctly understand i have to change waddch (mywin, c) with an wadd_wch() and when calling cob_addch_no_trunc_check i have to add a mbtowc
    searching gnucobol nighty build goggle direct me to a sourceforge site where there is
    version 3.2 stable, i think is the same i installed , and version 3.3 stable and another version 4
    but try to download 3,3 end 4.0 i geta "forbid" message...
    I miss something.. but if the problem is in the gnucobol source, are there some developpers ?
    Please explain me the situation
    regards.. Maurizio

     

    Last edit: Maurizio Bongini 2025-04-01
  • Maurizio Bongini

     

    Last edit: Maurizio Bongini 2025-04-02
  • Maurizio Bongini

    Hi...
    I'm Trying to understand...
    I take a look on the code i used to install gnucobol
    i browse libcob/screenio.c
    and i find the following ...

    1637 /* Use only when raise_ec_on_truncation is called beforehand. */
    1638 static void                 
    1639 cob_addch_no_trunc_check (const chtype c)
    1640 {                           
    1641        addch (c);                  
    1642 }   
    i have an addch() instruction and not a waddch() as the link of your code... 
    

    So i'm working with a different code ...

     
  • Maurizio Bongini

    I recheck again, i'm working with the latest stable version .. how can i download the version you linked to me ? Please let me know otherwise i'm lost
    can you contact one of the developper ? Please

     
  • Maurizio Bongini

    i'm working on ... i have not experience with ncurses at all , i will try to write a small program that perform this function, i do not grant anything to anyone ,, in the mean time i converted my screen sections to use ASCII character set ..

     

    Last edit: Maurizio Bongini 2025-04-04
  • Maurizio Bongini

    Hi Simon
    I successfully write a C program to parse UTF-8 chars of different length from a string and to write, one by one to the screen, using wadd_wch
    the program is very simple.. few instructions .. but sincerely i do not kow how to insert it on screenio.c .. it seems cob_screen_puts uses one byte ASCII character at time.. UTF-8 instead can range form 1 to 4 bytes long ...
    i attached in this post the source of my pgm
    compile it with

    gcc -Wall widechar.c -o wc -lncursesw
    

    can you pass this source to people who wrote screenio.c ? So they can merge correctly the code
    At this moment i need italian utf-8 characters displayed at SCREEN SECTION
    Thanks in advance..
    Maurizio

     

    Last edit: Maurizio Bongini 2025-04-09
  • Maurizio Bongini

    Hi Simon
    Any news ?
    my needs is only to put utf-8 support at screen section and display command
    in the mean time i take a look to IBM and they use PIC N to describe multibyte characters field..
    i immagine this is an hard work...
    IMHO .. is better to specify at installation time that utf-8 characters not yet supported when working with screen
    Regards.
    Maurizio

     
    • Simon Sobisch

      Simon Sobisch - 2025-04-14

      IBM has PIC N for multibyte - which then applies to all characters (PIC N = 2 bytes per character, possibly split with combination chars) and PIC U for utf8, which is 1-4 bytes per character (btw: that is currently under work to be added to ISO COBOL).

      GnuCOBOL has a rough support for those (mostly data storage, INSPECT REPLACING of utf with a different size won't work, utf8 and national literals may not work well (though support in 3.3 is already better and there's last year's GSOC to be integrated which improves that further) - but screenio just handles single-byte PIC X ("plain" DISPLAY to a terminal that has utf8 locale is likely to work, but that's more a co-incidence).

       

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.