harbour / core

Portable, xBase compatible programming language and environment
https://harbour.github.io/
Other
324 stars 207 forks source link

IBM858 Codepages for Euro Currency sign missing #201

Closed df7be closed 4 years ago

df7be commented 4 years ago

Hello, the Euro currency symbol was invented in many european countries, in germany in 2002. For this, there are some Codepage modifications in Windows systems done. CP 858: is identical CP 850, but the Euro sign was changed to oxD5 or CHR(213) UTF-8 : Euro = U+20AC (dez 8364) , CHR(130) + CHR(172) In Java: \u20ac WIN1252: 0x80 CHR(128) (Alt + on number block 0128 or AltGr + E) ISO-8859-15: 0xA4 CHR(164) HTML (not official): € ( € for UTF-8 ) For many business application this sign needed urgent.

The code mapping works well in Harbour (i coded my application with HWGUI, only worj is to REQUEST the Codepage and set them first as database codepage and second the OS codepage to translate the dbf-Codepage for display). Very good !!!

MNI TNX es 73 es 55 de DF7BE (translate the HAM radio abbreviations: many thanks , greetings an good success )

alcz commented 4 years ago

I think there is currently no "DE858" codepage exposed in Harbour. "DE850" of course does not include euro char. For "DEWIN" translation works. Little example:

PROCEDURE Main
   LOCAL v

   hb_cdpSelect("UTF8EX")

   v := "€"

   ? v
   ? hb_numToHex( hb_ucode( v ) )
   ? hb_strToHex( v := hb_translate( v, "UTF8", "DE850" ) )
   ? hb_numToHex( hb_ucode( v := hb_translate( v, "DE850", "UTF8" ) ) )

   ? v := hb_uchar( 8364 )
   ? hb_numToHex( hb_ucode( v ) )
   ? hb_strToHex( v := hb_translate( v, "UTF8", "DE850" ) )
   ? hb_numToHex( hb_ucode( v := hb_translate( v, "DE850", "UTF8" ) ) )

   ? v := hb_uchar( 8364 )
   ? hb_numToHex( hb_ucode( v ) )
   ? hb_strToHex( v := hb_translate( v, "UTF8", "DEWIN" ) )
   ? hb_numToHex( hb_ucode( v := hb_translate( v, "DEWIN", "UTF8" ) ) )

that outputs

€
20AC
3F
3F
€
20AC
3F
3F
€
20AC
80
20AC

Another note is that a general translation table for IBM858 is included https://github.com/harbour/core/blob/068a923d6f9b2edebac5bfec9ced2334ac887223/src/codepage/uc858.c

So it wouldn't be that hard to define DE858 too, but the question remains... if you're already using HWGUI, then why not just use windows encoding in databases?

df7be commented 4 years ago

Hello Alesksander, i hope, you received my mail from 20.01.20, 21:26. I think, you have at lot of work to, so you could not answer until now. For my application, i need only the Codepages DE858 an DE858M, for other languages the cp's could be coded later, if there is time.

I think, only this files are needed to add or modify: include\hbcpage.hbx (mod) src\codepage\cpde858.c (new, modified copy of cpde850.c ) src\codepage\cpde858m.c (new, modified copy of cpde850m.c) src\codepage\Makefile (mod) src\codepage\l_de.h (mod) ==> ready, appendend

List complete or more files be added or modified ? l_de.zip

Have you always started the item ? If not, may i crate a branch (need permission ??, please grant if not possible) ? (I read it in the WIKI for Howto create a branch and a pull request, if ready)

I am retired so i can spent some time for this issue

MNI TNX (many thanks) and with regards

Wilfried, DF7BE l_de.zip

alcz commented 4 years ago

Hi Wilfried.

Do we really need DE858M? It would be somewhat DE850M mdxger.obj based, but Harbour doesn't include support for .mdx indexes. I don't know if there is any sense to have it with .cdx/.ntx.

df7be commented 4 years ago

Hello Aleksander, MNI TNX for the quick answer ! Yes, in the mail i appended the file l_de.h, it is only a text file. But i uploaded it again in the issue comment in a zip file.

In my application CLLOG i use NTX indexes, so DE858M is not necessary.

I'm translating the error messages in src/lang: l_de.c and l_de_at.c. I think, tomorrow i can open a new issue with uploading the 2 files ready for checkin.

73 es 55, with best regards

DF7BE Wilfried

Additional info: OS for test: Windows 10 with MinGW Ubuntu 18.04 LTS MintLINUX 19.2 Cinnamon. Adress of my application CLLOG: https://sourceforge.net/projects/cllog/ compilable, but can not run. Have to some files and documentation.

log.prg is the main program for Harbour, logw.prg main for HWGUI Files with 87 in file name are for Clipper Summer 1987

alcz commented 4 years ago

Looking at the contents of your [l_de.zip], i don't think we need or should alter HB_CP_LOWER definition. The sorting of "€" will be based already on unicode tables reduced to IBM858 scope automatically. If i'm not forgetting something. We'll see the result while testing.

There were no other files in that .zip, so i've made this simple patch:

diff --git a/include/hbcpage.hbx b/include/hbcpage.hbx
index a11249248a..f6c3e264ed 100644
--- a/include/hbcpage.hbx
+++ b/include/hbcpage.hbx
@@ -38,6 +38,7 @@ DYNAMIC HB_CODEPAGE_CSKAMC
 DYNAMIC HB_CODEPAGE_CSWIN
 DYNAMIC HB_CODEPAGE_DE850
 DYNAMIC HB_CODEPAGE_DE850M
+DYNAMIC HB_CODEPAGE_DE858
 DYNAMIC HB_CODEPAGE_DEISO
 DYNAMIC HB_CODEPAGE_DEWIN
 DYNAMIC HB_CODEPAGE_DK865
diff --git a/src/codepage/Makefile b/src/codepage/Makefile
index 932a7016db..373ef55d1a 100644
--- a/src/codepage/Makefile
+++ b/src/codepage/Makefile
@@ -17,6 +17,7 @@ C_SOURCES := \
    cpcswin.c \
    cpde850.c \
    cpde850m.c \
+   cpde858.c \
    cpdeiso.c \
    cpdewin.c \
    cpdk865.c \
diff --git a/src/harbour.def b/src/harbour.def
index 21c6153b1a..647f996c27 100644
--- a/src/harbour.def
+++ b/src/harbour.def
@@ -349,6 +349,7 @@ HB_FUN_HB_CODEPAGE_CSKAMC
 HB_FUN_HB_CODEPAGE_CSWIN
 HB_FUN_HB_CODEPAGE_DE850
 HB_FUN_HB_CODEPAGE_DE850M
+HB_FUN_HB_CODEPAGE_DE858
 HB_FUN_HB_CODEPAGE_DEISO
 HB_FUN_HB_CODEPAGE_DEWIN
 HB_FUN_HB_CODEPAGE_DK865

plus that new cpde858.c

#define HB_CP_ID        DE858
#define HB_CP_INFO      "German CP-858"
#define HB_CP_UNITB     HB_UNITB_858
#define HB_CP_ACSORT    HB_CDP_ACSORT_NONE
#include "l_de.h"
#define HB_CP_UTF8

/* include CP registration code */
#include "hbcdpreg.h"

I'll commit it in a while.

alcz commented 4 years ago

Commited. My messy sample:

REQUEST HB_CODEPAGE_DE858
REQUEST HB_CODEPAGE_DEWIN
REQUEST HB_CODEPAGE_UTF8EX

PROCEDURE Main
   LOCAL v

   hb_cdpSelect("UTF8EX")

   v := "€"

   ? v := hb_uchar( 8364 )
   ? hb_numToHex( hb_ucode( v ) )
   ? hb_strToHex( v := hb_translate( v, "UTF8", "DEWIN" ) )
   ? hb_numToHex( hb_ucode( v := hb_translate( v, "DEWIN", "UTF8" ) ) )
   ? "--"
   ? v := hb_uchar( 8364 )
   ? hb_numToHex( hb_ucode( v ) )
   ? hb_strToHex( v := hb_translate( v, "UTF8", "DE858" ) )
   ? hb_numToHex( hb_ucode( v := hb_translate( v, "DE858", "UTF8" ) ) )

now outputs

€
20AC
80
20AC
--
€
20AC
D5
20AC

Please test your database scenario with updated Harbour.

Thank you very much for your ongoing work on translating src/lang/l_de.c and l_de_at.c.

If you want to start with branches, you should probably fork Harbour on GitHub and make some experiments there. Forking itself is easy, but the rest is up to you.

If the patch is simple, i'm fine if you upload it before taking those git lessons.

df7be commented 4 years ago

Hello Aleksander, MNI TNX for the quick answer. I'll test the CP858 ASAP in the next day (at least until next friday) and give you a feedbakc of my Text on Win 10 and LINUX(Ubuntu and Mint) Now i'll create the issue with the translation of error messages ... With regards DF7BE Wilfried

df7be commented 4 years ago

Hello Aleksander, MNI TNX for the quick processing of the issue. Here my feedback: Fantastic ! The issue could be closed. I can send to all users of my app: "The feature Support for Euro currency sign implemented". I tested it successfully with my app CLLOG: https://sourceforge.net/p/cllog/code/HEAD/tree/ log.prg: The main module of pure Harbour app in Terminal logw.prg: The main module of HWGUI program. Tested with OS: Windows 10/MinGW MintLINUX 19.2 Cinnamon Ubuntu 16.02 TLS

I am confused a little bit about this code in cpde850.c:

if 0 / VERIFIED: 20091116 /

define HB_CP_RAW

static const unsigned char s_flags[ 256 ] = { [...]

endif

Now it seems, that code is not necessary in recent and future versions of Harbour. In many files this code is not existent, for example: cpes850.c cpdeiso.c

With regards, 73 es 55 de DF7BE, Wilfried

alcz commented 4 years ago

Thanks for the feedback, closing. This #if 0 [...] HB_CP_RAW code comes from earlier version of Harbour which didn't support unicode and is left as a reference. Also, anyone that wants quickly add own codepage to your application, please see this post by Przemyslaw: https://groups.google.com/d/msg/harbour-users/UJZALHfKylk/S-Jnx187BQAJ Below an example copied from this link:


REQUEST HB_CODEPAGE_ENWIN
PROCEDURE Main()
   Set( _SET_CODEPAGE, "ENWIN" )
   ? Set( _SET_CODEPAGE ), hb_cdpUniID( Set( _SET_CODEPAGE ) )
   ? "Abschöpfung.jpg:", file( "Abschöpfung.jpg" )
RETURN

#pragma begindump
#define HB_CP_ID        ENWIN
#define HB_CP_INFO      "English CP-1252"
#define HB_CP_UNITB     HB_UNITB_1252
#define HB_CP_ACSORT    HB_CDP_ACSORT_NONE
#define HB_CP_UPPER     "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define HB_CP_LOWER     "abcdefghijklmnopqrstuvwxyz"
#define HB_CP_UTF8
#include "hbcdpreg.h"   /* include CP registration code */
#pragma enddump