From b23b8a3657d463c6c7e6b35157d4d148eb896753 Mon Sep 17 00:00:00 2001 From: "Alexander S.Kresin" Date: Fri, 15 Nov 2002 11:24:53 +0000 Subject: [PATCH] 2002-11-15 14:30 UTC+0300 Alexander Kresin --- harbour/ChangeLog | 19 ++++ harbour/include/hbapicdp.h | 12 +++ harbour/makefile.bc | 15 ++++ harbour/makefile.nt | 3 + harbour/makefile.vc | 3 + harbour/source/codepage/Makefile | 3 + harbour/source/codepage/cdp_tpl.c | 96 ++++++++++++++++++++ harbour/source/codepage/cdppl852.c | 97 +++++++++++++++++++++ harbour/source/codepage/cdppliso.c | 97 +++++++++++++++++++++ harbour/source/codepage/cdpplmaz.c | 97 +++++++++++++++++++++ harbour/source/codepage/cdpru866.c | 2 +- harbour/source/codepage/cdprukoi.c | 4 +- harbour/source/codepage/cdpruwin.c | 2 +- harbour/source/rtl/cdpapi.c | 135 +++++++++++++++++++++++++++-- 14 files changed, 575 insertions(+), 10 deletions(-) create mode 100644 harbour/source/codepage/cdp_tpl.c create mode 100644 harbour/source/codepage/cdppl852.c create mode 100644 harbour/source/codepage/cdppliso.c create mode 100644 harbour/source/codepage/cdpplmaz.c diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 05c1db9041..49e0ede646 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,25 @@ 2002-12-01 23:12 UTC+0100 Foo Bar */ +2002-11-15 14:30 UTC+0300 Alexander Kresin + * include/hbcdpapi.c + * source/rtl/cdpapi.c + * source/codepage/cdpru866.c + * source/codepage/cdprukoi.c + * source/codepage/cdpruwin.c + * Some fixes and enhancements + + source/codepage/cdp_tpl.c + + Template file for codepages is added + + source/codepage/cdppl852.c + + source/codepage/cdppliso.c + + source/codepage/cdpplmaz.c + + Codepages for Polish language, provided by Jacek Kubica + * source/codepage/Makefile + * makefile.bc + * makefile.nt + * makefile.vc + * Changed to compile new Polish codepages + 2002-11-13 15:50 UTC-0300 Horacio Roldan * include/hbrddcdx.h * source/rdd/dbfcdx/dbfcdx1.c diff --git a/harbour/include/hbapicdp.h b/harbour/include/hbapicdp.h index 8860f83718..6c3030b0e2 100644 --- a/harbour/include/hbapicdp.h +++ b/harbour/include/hbapicdp.h @@ -67,16 +67,28 @@ #define HB_CODEPAGE_ANNOUNCE( id ) HB_FUNC( HB_CODEPAGE_##id ) {} +typedef struct _HB_MULTICHAR +{ + char cLast[2]; + char cFirst[2]; + int nCode; +} HB_MULTICHAR, * PHB_MULTICHAR; + typedef struct _HB_CODEPAGE { char *id; int nChars; char *CharsUpper; char *CharsLower; + BOOL lAccEqual; + BOOL lAccInterleave; BOOL lSort; BYTE *s_chars; BYTE *s_upper; BYTE *s_lower; + BYTE *s_accent; + int nMulti; + PHB_MULTICHAR multi; } HB_CODEPAGE, * PHB_CODEPAGE; extern BOOL hb_cdpRegister( PHB_CODEPAGE ); diff --git a/harbour/makefile.bc b/harbour/makefile.bc index d929370acd..d04f2491fc 100644 --- a/harbour/makefile.bc +++ b/harbour/makefile.bc @@ -421,6 +421,9 @@ LANG_LIB_OBJS = \ $(OBJ_DIR)\msgzhb5.obj CODEPAGE_LIB_OBJS = \ + $(OBJ_DIR)\cdppl852.obj \ + $(OBJ_DIR)\cdppliso.obj \ + $(OBJ_DIR)\cdpplmaz.obj \ $(OBJ_DIR)\cdpru866.obj \ $(OBJ_DIR)\cdpruwin.obj \ $(OBJ_DIR)\cdprukoi.obj @@ -2154,6 +2157,18 @@ $(OBJ_DIR)\msgzhgb.obj : $(LANG_DIR)\msgzhgb.c # CODEPAGE.LIB dependencies # +$(OBJ_DIR)\cdppl852.obj : $(CODEPAGE_DIR)\cdppl852.c + $(CC) $(CLIBFLAGS) -o$@ $** + tlib $(CODEPAGE_LIB) $(ARFLAGS) -+$@,, + +$(OBJ_DIR)\cdppliso.obj : $(CODEPAGE_DIR)\cdppliso.c + $(CC) $(CLIBFLAGS) -o$@ $** + tlib $(CODEPAGE_LIB) $(ARFLAGS) -+$@,, + +$(OBJ_DIR)\cdpplmaz.obj : $(CODEPAGE_DIR)\cdpplmaz.c + $(CC) $(CLIBFLAGS) -o$@ $** + tlib $(CODEPAGE_LIB) $(ARFLAGS) -+$@,, + $(OBJ_DIR)\cdpru866.obj : $(CODEPAGE_DIR)\cdpru866.c $(CC) $(CLIBFLAGS) -o$@ $** tlib $(CODEPAGE_LIB) $(ARFLAGS) -+$@,, diff --git a/harbour/makefile.nt b/harbour/makefile.nt index bf235924ab..95a79259ed 100644 --- a/harbour/makefile.nt +++ b/harbour/makefile.nt @@ -482,6 +482,9 @@ LANG_LIB_OBJS = \ $(CC) $(CLIBFLAGS) -Fo$(OBJ_DIR)\ $< CODEPAGE_LIB_OBJS = \ + $(OBJ_DIR)\cdppl852.obj \ + $(OBJ_DIR)\cdppliso.obj \ + $(OBJ_DIR)\cdpplmaz.obj \ $(OBJ_DIR)\cdpru866.obj \ $(OBJ_DIR)\cdprukoi.obj \ $(OBJ_DIR)\cdpruwin.obj diff --git a/harbour/makefile.vc b/harbour/makefile.vc index 31d2750f83..cd7da8facb 100644 --- a/harbour/makefile.vc +++ b/harbour/makefile.vc @@ -446,6 +446,9 @@ LANG_LIB_OBJS = \ $(CC) $(CLIBFLAGS) -Fo$(OBJ_DIR)\ $< CODEPAGE_LIB_OBJS = \ + $(OBJ_DIR)\cdppl852.obj \ + $(OBJ_DIR)\cdppliso.obj \ + $(OBJ_DIR)\cdpplmaz.obj \ $(OBJ_DIR)\cdpru866.obj \ $(OBJ_DIR)\cdprukoi.obj \ $(OBJ_DIR)\cdpruwin.obj diff --git a/harbour/source/codepage/Makefile b/harbour/source/codepage/Makefile index 48bf07c18b..54fd10fba0 100644 --- a/harbour/source/codepage/Makefile +++ b/harbour/source/codepage/Makefile @@ -5,6 +5,9 @@ ROOT = ../../ C_SOURCES=\ + cdppl852.c \ + cdppliso.c \ + cdpplmaz.c \ cdpru866.c \ cdprukoi.c \ cdpruwin.c diff --git a/harbour/source/codepage/cdp_tpl.c b/harbour/source/codepage/cdp_tpl.c new file mode 100644 index 0000000000..e7aba497f0 --- /dev/null +++ b/harbour/source/codepage/cdp_tpl.c @@ -0,0 +1,96 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * National Collation Support Module ( template ) + * + * Copyright 2002 Alexander S.Kresin + * www - http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +/* Language name: */ +/* ISO language code (2 chars): (please look it up in /doc/lang_id.txt) */ +/* Codepage: */ + +#include +#include "hbapi.h" +#include "hbapicdp.h" + +#define NUMBER_OF_CHARACTERS 26 /* The number of single characters in the + alphabet, two-as-one aren't considered + here, accented - are considered. */ +#define ACCENTED_EQUAL 0 /* Should be 1, if accented character + has the same weight as appropriate + unaccented. */ +#define ACCENTED_INTERLEAVED 0 /* Should be 1, if accented characters + sort after their unaccented counterparts + only if the unaccented versions of all + characters being compared are the same + ( interleaving ) */ + +/* If ACCENTED_EQUAL or ACCENTED_INTERLEAVED is 1, you need to mark the + accented characters with the symbol '~' before each of them, for example: + a~ + If there is two-character sequence, which is considered as one, it should + be marked with '.' before and after it, for example: + ... h.ch.i ... + + The Upper case string and the Lower case string should be absolutely the + same excepting the characters case, of course. + */ + +static HB_CODEPAGE s_codepage = { "EN",NUMBER_OF_CHARACTERS, + "ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz", + ACCENTED_EQUAL,ACCENTED_INTERLEAVED,0,NULL,NULL,NULL,NULL,0,NULL }; + +HB_CODEPAGE_ANNOUNCE( EN ); + +HB_CALL_ON_STARTUP_BEGIN( hb_codepage_Init_EN ) + hb_cdpRegister( &s_codepage ); +HB_CALL_ON_STARTUP_END( hb_codepage_Init_EN ) +#if ! defined(__GNUC__) && ! defined(_MSC_VER) + #pragma startup hb_codepage_Init_EN +#endif + diff --git a/harbour/source/codepage/cdppl852.c b/harbour/source/codepage/cdppl852.c new file mode 100644 index 0000000000..49e8fa6d5b --- /dev/null +++ b/harbour/source/codepage/cdppl852.c @@ -0,0 +1,97 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * National Collation Support Module ( PL852 ) + * + * Copyright 2002 Alexander S.Kresin + * www - http://www.harbour-project.org + * Polish collating sequence (PL852) CP852 done by Jacek Kubica + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + * Polish CP852 PL852 + * +/* Language name: Polish */ +/* ISO language code (2 chars): PL */ +/* Codepage: 852 */ + +#include +#include "hbapi.h" +#include "hbapicdp.h" + +#define NUMBER_OF_CHARACTERS 34 /* The number of single characters in the + alphabet, two-as-one aren't considered + here, accented - are considered. */ +#define ACCENTED_EQUAL 0 /* Should be 1, if accented character + has the same weight as appropriate + unaccented. */ +#define ACCENTED_INTERLEAVED 0 /* Should be 1, if accented characters + sort after their unaccented counterparts + only if the unaccented versions of all + characters being compared are the same + ( interleaving ) */ + +/* If ACCENTED_EQUAL or ACCENTED_INTERLEAVED is 1, you need to mark the + accented characters with the symbol '~' before each of them, for example: + a~ + If there is two-character sequence, which is considered as one, it should + be marked with '.' before and after it, for example: + ... h.ch.i ... + + The Upper case string and the Lower case string should be absolutely the + same excepting the characters case, of course. + */ + +static HB_CODEPAGE s_codepage = { "PL852",NUMBER_OF_CHARACTERS, + "ABCDEFGHIJKLMNOPQRSTUWXYZ","abcdefghijklmnopqrstuwxyz", + ACCENTED_EQUAL,ACCENTED_INTERLEAVED,0,NULL,NULL,NULL,NULL,0,NULL }; + +HB_CODEPAGE_ANNOUNCE( PL852 ); + +HB_CALL_ON_STARTUP_BEGIN( hb_codepage_Init_PL852 ) + hb_cdpRegister( &s_codepage ); +HB_CALL_ON_STARTUP_END( hb_codepage_Init_PL852 ) +#if ! defined(__GNUC__) && ! defined(_MSC_VER) + #pragma startup hb_codepage_Init_PL852 +#endif + diff --git a/harbour/source/codepage/cdppliso.c b/harbour/source/codepage/cdppliso.c new file mode 100644 index 0000000000..3bea405d8f --- /dev/null +++ b/harbour/source/codepage/cdppliso.c @@ -0,0 +1,97 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * National Collation Support Module ( PLISO ) + * + * Copyright 2002 Alexander S.Kresin + * www - http://www.harbour-project.org + * Polish collating sequence (PLISO) done by Jacek Kubica + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + * Polish ISO-8859-1 PLISO + * +/* Language name: Polish */ +/* ISO language code (2 chars): PL */ +/* Codepage: ISO */ + +#include +#include "hbapi.h" +#include "hbapicdp.h" + +#define NUMBER_OF_CHARACTERS 34 /* The number of single characters in the + alphabet, two-as-one aren't considered + here, accented - are considered. */ +#define ACCENTED_EQUAL 0 /* Should be 1, if accented character + has the same weight as appropriate + unaccented. */ +#define ACCENTED_INTERLEAVED 0 /* Should be 1, if accented characters + sort after their unaccented counterparts + only if the unaccented versions of all + characters being compared are the same + ( interleaving ) */ + +/* If ACCENTED_EQUAL or ACCENTED_INTERLEAVED is 1, you need to mark the + accented characters with the symbol '~' before each of them, for example: + a~ + If there is two-character sequence, which is considered as one, it should + be marked with '.' before and after it, for example: + ... h.ch.i ... + + The Upper case string and the Lower case string should be absolutely the + same excepting the characters case, of course. + */ + +static HB_CODEPAGE s_codepage = { "PLISO",NUMBER_OF_CHARACTERS, + "ABCDEFGHIJKLMNOPQRSTUWXYZ","abcdefghijklmnopqrstuwxyz", + ACCENTED_EQUAL,ACCENTED_INTERLEAVED,0,NULL,NULL,NULL,NULL,0,NULL }; + +HB_CODEPAGE_ANNOUNCE( PLISO ); + +HB_CALL_ON_STARTUP_BEGIN( hb_codepage_Init_PLISO ) + hb_cdpRegister( &s_codepage ); +HB_CALL_ON_STARTUP_END( hb_codepage_Init_PLISO ) +#if ! defined(__GNUC__) && ! defined(_MSC_VER) + #pragma startup hb_codepage_Init_PLISO +#endif + diff --git a/harbour/source/codepage/cdpplmaz.c b/harbour/source/codepage/cdpplmaz.c new file mode 100644 index 0000000000..0c347b38d6 --- /dev/null +++ b/harbour/source/codepage/cdpplmaz.c @@ -0,0 +1,97 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * National Collation Support Module ( PLMAZ ) + * + * Copyright 2002 Alexander S.Kresin + * www - http://www.harbour-project.org + * Polish collating sequence (PLMAZ) Mazovia done by Jacek Kubica + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + * Polish Mazovia PLMAZ + * +/* Language name: Polish */ +/* ISO language code (2 chars): PL */ +/* Codepage: MAZ */ + +#include +#include "hbapi.h" +#include "hbapicdp.h" + +#define NUMBER_OF_CHARACTERS 34 /* The number of single characters in the + alphabet, two-as-one aren't considered + here, accented - are considered. */ +#define ACCENTED_EQUAL 0 /* Should be 1, if accented character + has the same weight as appropriate + unaccented. */ +#define ACCENTED_INTERLEAVED 0 /* Should be 1, if accented characters + sort after their unaccented counterparts + only if the unaccented versions of all + characters being compared are the same + ( interleaving ) */ + +/* If ACCENTED_EQUAL or ACCENTED_INTERLEAVED is 1, you need to mark the + accented characters with the symbol '~' before each of them, for example: + a~ + If there is two-character sequence, which is considered as one, it should + be marked with '.' before and after it, for example: + ... h.ch.i ... + + The Upper case string and the Lower case string should be absolutely the + same excepting the characters case, of course. + */ + +static HB_CODEPAGE s_codepage = { "PLMAZ",NUMBER_OF_CHARACTERS, + "ABCDEFGHIJKLMNOPQRSTUWXYZ","abcdefghijklmnopqrstuwxyz", + ACCENTED_EQUAL,ACCENTED_INTERLEAVED,0,NULL,NULL,NULL,NULL,0,NULL }; + +HB_CODEPAGE_ANNOUNCE( PLMAZ ); + +HB_CALL_ON_STARTUP_BEGIN( hb_codepage_Init_PLMAZ ) + hb_cdpRegister( &s_codepage ); +HB_CALL_ON_STARTUP_END( hb_codepage_Init_PLMAZ ) +#if ! defined(__GNUC__) && ! defined(_MSC_VER) + #pragma startup hb_codepage_Init_PLMAZ +#endif + diff --git a/harbour/source/codepage/cdpru866.c b/harbour/source/codepage/cdpru866.c index fb939a4559..927fe2e498 100644 --- a/harbour/source/codepage/cdpru866.c +++ b/harbour/source/codepage/cdpru866.c @@ -60,7 +60,7 @@ static HB_CODEPAGE s_codepage = { "RU866",32, "","", - 0,NULL,NULL,NULL }; + 0,0,0,NULL,NULL,NULL,NULL,0,NULL }; HB_CODEPAGE_ANNOUNCE( RU866 ); diff --git a/harbour/source/codepage/cdprukoi.c b/harbour/source/codepage/cdprukoi.c index e0064f3ff1..64788a38f4 100644 --- a/harbour/source/codepage/cdprukoi.c +++ b/harbour/source/codepage/cdprukoi.c @@ -59,8 +59,8 @@ #include "hbapicdp.h" static HB_CODEPAGE s_codepage = { "RUKOI8",32, - "","", - 0,NULL,NULL,NULL }; + "..","..", + 0,0,0,NULL,NULL,NULL,NULL,0,NULL }; HB_CODEPAGE_ANNOUNCE( RUKOI8 ); diff --git a/harbour/source/codepage/cdpruwin.c b/harbour/source/codepage/cdpruwin.c index 178ff8fcea..04569f6b0f 100644 --- a/harbour/source/codepage/cdpruwin.c +++ b/harbour/source/codepage/cdpruwin.c @@ -60,7 +60,7 @@ static HB_CODEPAGE s_codepage = { "RU1251",32, "","", - 0,NULL,NULL,NULL }; + 0,0,0,NULL,NULL,NULL,NULL,0,NULL }; HB_CODEPAGE_ANNOUNCE( RU1251 ); diff --git a/harbour/source/rtl/cdpapi.c b/harbour/source/rtl/cdpapi.c index 038cda06a7..d19df1cc54 100644 --- a/harbour/source/rtl/cdpapi.c +++ b/harbour/source/rtl/cdpapi.c @@ -55,7 +55,7 @@ #define HB_CDP_MAX_ 64 -static HB_CODEPAGE s_en_codepage = { "EN",0,NULL,NULL,0,NULL,NULL,NULL }; +static HB_CODEPAGE s_en_codepage = { "EN",0,NULL,NULL,0,0,0,NULL,NULL,NULL,NULL,0,NULL }; static PHB_CODEPAGE s_cdpList[ HB_CDP_MAX_ ]; PHB_CODEPAGE s_cdpage = &s_en_codepage; @@ -93,6 +93,8 @@ BOOL hb_cdpRegister( PHB_CODEPAGE cdpage ) char *ptrUpper = cdpage->CharsUpper; char *ptrLower = cdpage->CharsLower; char *ptr; + HB_MULTICHAR multi[12]; + int nMulti = 0; s_cdpList[ iPos ] = cdpage; @@ -100,17 +102,25 @@ BOOL hb_cdpRegister( PHB_CODEPAGE cdpage ) if( cdpage->nChars ) { cdpage->s_chars = (BYTE*) hb_xgrab(256); + memset( cdpage->s_chars,'\0',256 ); cdpage->s_upper = (BYTE*) hb_xgrab(256); cdpage->s_lower = (BYTE*) hb_xgrab(256); + if( cdpage->lAccInterleave ) + { + cdpage->s_accent = (BYTE*) hb_xgrab(256); + memset( cdpage->s_accent,'\0',256 ); + } + else + cdpage->s_accent = NULL; + for( i=0; i<256; i++ ) { - cdpage->s_chars[i] = 0; cdpage->s_upper[i] = toupper( (BYTE) i&255 ); cdpage->s_lower[i] = tolower( (BYTE) i&255 ); } for( i=1; *ptrUpper; i++,ptrUpper++,ptrLower++ ) { - if( *ptrUpper == '=' ) + if( *ptrUpper == '~' ) { for( ptr=ptrUpper+1; *ptr; ptr++ ) *(ptr-1) = *ptr; @@ -118,10 +128,43 @@ BOOL hb_cdpRegister( PHB_CODEPAGE cdpage ) for( ptr=ptrLower+1; *ptr; ptr++ ) *(ptr-1) = *ptr; *(ptr-1) = '\0'; - i--; + if( cdpage->lAccEqual ) + i--; + if( cdpage->lAccInterleave ) + { + char *ptrtmp; + + ptrtmp = ptrUpper-1; + while( cdpage->s_accent[ (((int)*ptrtmp)&255) ] ) + ptrtmp --; + iu = (((int)*ptrUpper)&255); + cdpage->s_accent[ iu ] = *ptrtmp; + + ptrtmp = ptrLower-1; + while( cdpage->s_accent[ (((int)*ptrtmp)&255) ] ) + ptrtmp --; + il = (((int)*ptrLower)&255); + cdpage->s_accent[ il ] = *ptrtmp; + } } else if( *ptrUpper == '.' ) { + multi[nMulti].cFirst[0] = *(ptrLower+1); + multi[nMulti].cFirst[1] = *(ptrUpper+1); + multi[nMulti].cLast[0] = *(ptrLower+2); + multi[nMulti].cLast[1] = *(ptrUpper+2); + multi[nMulti].nCode = i; + + for( ptr=ptrUpper+4; *ptr; ptr++ ) + *(ptr-4) = *ptr; + *(ptr-4) = '\0'; + for( ptr=ptrLower+4; *ptr; ptr++ ) + *(ptr-4) = *ptr; + *(ptr-4) = '\0'; + + nMulti ++; + ptrUpper --; ptrLower --; + continue; } iu = (((int)*ptrUpper)&255); cdpage->s_chars[ iu ] = i; @@ -136,6 +179,14 @@ BOOL hb_cdpRegister( PHB_CODEPAGE cdpage ) il = ((int)(*ptrUpper))&255; cdpage->s_lower[il] = *ptrLower; } + if( nMulti ) + { + cdpage->multi = (PHB_MULTICHAR) hb_xgrab( sizeof(HB_MULTICHAR)*nMulti ); + memcpy( (BYTE*)cdpage->multi,(BYTE*)multi,sizeof(HB_MULTICHAR)*nMulti ); + cdpage->nMulti = nMulti; + } + else + cdpage->multi = NULL; } // printf( "\n%s %d",s_cdpage->id,s_cdpage->lSort ); return TRUE; @@ -165,7 +216,12 @@ PHB_CODEPAGE hb_cdpSelect( PHB_CODEPAGE cdpage ) HB_TRACE(HB_TR_DEBUG, ("hb_langSelect(%p)", cdpage)); if( cdpage ) + { s_cdpage = cdpage; + printf("Codepage - Yes"); + } + else + printf("Codepage - No"); return cdpOld; } @@ -219,18 +275,81 @@ void hb_cdpnTranslate( char* psz, PHB_CODEPAGE cdpIn, PHB_CODEPAGE cdpOut, unsig int hb_cdpcmp( char* szFirst, char* szSecond, int iLen, PHB_CODEPAGE cdpage ) { int i, iRet = 0, n1, n2; + int lAcc1 = 0, lAcc2 = 0; // printf( "\nhb_cdpcmp-0 %s %s",szFirst,szSecond ); for( i=0; is_chars[ ((int)*szFirst)&255 ] ) == 0 || ( n2 = (int)cdpage->s_chars[ ((int)*szSecond)&255 ] ) == 0 ) - iRet = ( *szFirst < *szSecond )? -1 : 1; + { + /* One of characters doesn't belong to the national characters */ + iRet = ( (((int)*szFirst)&255) < (((int)*szSecond)&255) )? -1 : 1; + // printf( "\n|%c|%c|%d %d %d",*szFirst,*szSecond,((int)*szFirst)&255,((int)*szSecond)&255,iRet ); + break; + } + if( cdpage->nMulti && i ) + { + int j, nd1 = 0, nd2 = 0; + PHB_MULTICHAR pmulti = cdpage->multi; + // printf( "\nhb_cdpcmp-1 %c %c",*szFirst,*szSecond ); + for( j=0; jnMulti; j++,pmulti++ ) + { + if( ( *szFirst == pmulti->cLast[0] || + *szFirst == pmulti->cLast[1] ) && + ( *(szFirst-1) == pmulti->cFirst[0] || + *(szFirst-1) == pmulti->cFirst[1] ) ) + nd1 = pmulti->nCode; + if( ( *szSecond == pmulti->cLast[0] || + *szSecond == pmulti->cLast[1] ) && + ( *(szSecond-1) == pmulti->cFirst[0] || + *(szSecond-1) == pmulti->cFirst[1] ) ) + nd2 = pmulti->nCode; + } + // printf( "\nhb_cdpcmp-2 %d %d",nd1,nd2 ); + if( nd1 && !nd2 ) + { + n2 = (int)cdpage->s_chars[ ((int)*(szSecond-1))&255 ]; + iRet = ( nd1 < n2 )? -1 : 1; + break; + } + else if( !nd1 && nd2 ) + { + n1 = (int)cdpage->s_chars[ ((int)*(szFirst-1))&255 ]; + iRet = ( n1 < nd2 )? -1 : 1; + // printf( "\nhb_cdpcmp-3 %d %d %d",iRet,n1,nd2 ); + break; + } + else if( nd1 && nd2 ) + { + iRet = ( nd1 < nd2 )? -1 : 1; + break; + } + } + if( cdpage->lAccInterleave && !lAcc1 && !lAcc2 ) + { + if( cdpage->s_accent[ ((int)*(szFirst))&255 ] == *((BYTE*)szSecond) ) + lAcc1 = TRUE; + else if( cdpage->s_accent[ ((int)*(szSecond))&255 ] == *((BYTE*)szFirst) ) + lAcc2 = TRUE; + else + { + iRet = ( n1 < n2 )? -1 : 1; + break; + } + } else + { iRet = ( n1 < n2 )? -1 : 1; - break; + break; + } } // printf( " : %d",iRet ); + + if( !iRet && lAcc1 ) + return 1; + else if( !iRet && lAcc2 ) + return -1; return iRet; } @@ -246,6 +365,10 @@ void hb_cdpReleaseAll( void ) hb_xfree( s_cdpList[ iPos ]->s_upper ); if( s_cdpList[ iPos ]->s_lower ) hb_xfree( s_cdpList[ iPos ]->s_lower ); + if( s_cdpList[ iPos ]->s_accent ) + hb_xfree( s_cdpList[ iPos ]->s_accent ); + if( s_cdpList[ iPos ]->multi ) + hb_xfree( s_cdpList[ iPos ]->multi ); iPos ++; } }