From 3d08bef043939621944e4de414917feb9c9ae935 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 17 Sep 2012 12:11:23 +0000 Subject: [PATCH] 2012-09-17 14:03 UTC+0200 Viktor Szakats (harbour syenar.net) + contrib/hbwin/oemansi.c * contrib/hbwin/hbwin.hbp * contrib/hbwin/hbwin.hbx + added WIN_OEMTOANSI() and WIN_ANSITOOEM(). These are compatible with current core HB_OEMTOANSI()/HB_ANSITOOEM() Usage of them is not recommended. * contrib/hbxpp/oemansix.c * CONVTOANSICP()/CONVTOOEMCP() changed to use local implementation instead of relying on now deprecated core OEM/ANSI functions * src/rtl/oemansi.c * HB_OEMTOANSI()/HB_ANSITOOEM() Windows-specific functions deprecated with HB_LEGACY_LEVEL4 (meaning they will disappear after next stable release). Either avoid these calls completely (recommended) or change them to hbwin or hbxbp equivalents. * contrib/hbtip/thtml.prg * contrib/hbtip/hbtip.hbx * deprecated HtmlToAnsi(), HtmlToOem(), AnsiToHtml(), OemToHtml() functions with HB_LEGACY_LEVEL4. + added TIP_STRTOHTML(), TIP_HTMLTOSTR() functions which cover major above functionality, but in a portable and CP agnostic way. Code untested, if you need it, test it and provide feedback and/or fix. --- harbour/ChangeLog | 43 ++++++-- harbour/contrib/hbtip/hbtip.hbx | 2 + harbour/contrib/hbtip/thtml.prg | 178 ++++++++++++++++++++++++++++++- harbour/contrib/hbwin/hbwin.hbp | 1 + harbour/contrib/hbwin/hbwin.hbx | 5 + harbour/contrib/hbwin/oemansi.c | 112 +++++++++++++++++++ harbour/contrib/hbxpp/oemansix.c | 64 ++++++++++- harbour/src/rtl/oemansi.c | 4 + 8 files changed, 397 insertions(+), 12 deletions(-) create mode 100644 harbour/contrib/hbwin/oemansi.c diff --git a/harbour/ChangeLog b/harbour/ChangeLog index c440a02ebd..b23361abf9 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,35 @@ The license applies to all entries newer than 2009-04-28. */ +2012-09-17 14:03 UTC+0200 Viktor Szakats (harbour syenar.net) + + contrib/hbwin/oemansi.c + * contrib/hbwin/hbwin.hbp + * contrib/hbwin/hbwin.hbx + + added WIN_OEMTOANSI() and WIN_ANSITOOEM(). These are + compatible with current core HB_OEMTOANSI()/HB_ANSITOOEM() + Usage of them is not recommended. + + * contrib/hbxpp/oemansix.c + * CONVTOANSICP()/CONVTOOEMCP() changed to use local + implementation instead of relying on now deprecated + core OEM/ANSI functions + + * src/rtl/oemansi.c + * HB_OEMTOANSI()/HB_ANSITOOEM() Windows-specific functions + deprecated with HB_LEGACY_LEVEL4 (meaning they will + disappear after next stable release). Either avoid + these calls completely (recommended) or change them to + hbwin or hbxbp equivalents. + + * contrib/hbtip/thtml.prg + * contrib/hbtip/hbtip.hbx + * deprecated HtmlToAnsi(), HtmlToOem(), AnsiToHtml(), OemToHtml() + functions with HB_LEGACY_LEVEL4. + + added TIP_STRTOHTML(), TIP_HTMLTOSTR() functions which cover + major above functionality, but in a portable and CP agnostic + way. Code untested, if you need it, test it and provide feedback + and/or fix. + 2012-09-17 12:23 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * harbour/contrib/hbwin/hbwinole.h * harbour/contrib/hbwin/olecore.c @@ -42,25 +71,25 @@ integers. Warning! this modification is not backward compatible. If some needs previous behavior then he should change create conversion - functions. + functions. [INCOMPATIBLE] ; Please test it. I made all this modifications in Linux without any real tests. 2012-09-16 16:47 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) * contrib/gtwvg/gtwvg.c - + hb_gtInfo( HB_GTI_SETPOSANDSIZE ) returns the existing position + + hb_gtInfo( HB_GTI_SETPOSANDSIZE ) returns the existing position and size: { nX, nY, nWidth, nHeight } in pixels. * contrib/hbqt/hbmk2_qt.hb - + someObject:setHtml( cHtmlCode ) now reads the html text correctly - off a .ui file. This makes possible to draft html pages in - Qt creator itself and assigned to an relevant object, like + + someObject:setHtml( cHtmlCode ) now reads the html text correctly + off a .ui file. This makes possible to draft html pages in + Qt creator itself and assigned to an relevant object, like QLabel, QTextEdit, QTextBrowser, etc. 2012-09-14 21:07 UTC+0200 Firstname Lastname (me domain.net) * utils/hbmk2/hbmk2.prg - * hbmk_OutStdRaw() and hb_OutErrRaw() hbmk2 plugin - API functions parameter list modified so that now they + * hbmk_OutStdRaw() and hb_OutErrRaw() hbmk2 plugin + API functions parameter list modified so that now they expect hbmk context as first parameter. INCOMPATIBLE. ! made sure that hbmk_OutStdRaw() and hbmk_OutErrRaw() diff --git a/harbour/contrib/hbtip/hbtip.hbx b/harbour/contrib/hbtip/hbtip.hbx index 386baa12c3..7e9db9dd70 100644 --- a/harbour/contrib/hbtip/hbtip.hbx +++ b/harbour/contrib/hbtip/hbtip.hbx @@ -64,11 +64,13 @@ DYNAMIC TIP_GETENCODER DYNAMIC TIP_GETNAMEEMAIL DYNAMIC TIP_GETRAWEMAIL DYNAMIC TIP_HTMLSPECIALCHARS +DYNAMIC TIP_HTMLTOSTR DYNAMIC TIP_JSONSPECIALCHARS DYNAMIC TIP_MIMETYPE DYNAMIC TIP_QPDECODE DYNAMIC TIP_QPENCODE DYNAMIC TIP_SSL +DYNAMIC TIP_STRTOHTML DYNAMIC TIP_TIMESTAMP DYNAMIC TIP_URLDECODE DYNAMIC TIP_URLENCODE diff --git a/harbour/contrib/hbtip/thtml.prg b/harbour/contrib/hbtip/thtml.prg index 28955d9205..f32161c27f 100644 --- a/harbour/contrib/hbtip/thtml.prg +++ b/harbour/contrib/hbtip/thtml.prg @@ -93,6 +93,8 @@ THREAD STATIC t_aHtmlAttr // data for HTML attributes THREAD STATIC t_hTagTypes // data for HTML tags +THREAD STATIC t_cHtmlCP := "" +THREAD STATIC t_aHtmlEntities // HTML character entities THREAD STATIC t_aHtmlAnsiEntities // HTML character entities (ANSI character set) THREAD STATIC t_lInit := .F. // initilization flag for HTML data @@ -4515,6 +4517,8 @@ STATIC FUNCTION THtmlAttr_XMP() t_aHtmlAttr[ HTML_ATTR_UNKNOWN ] ; } +#ifdef HB_LEGACY_LEVEL4 + // Converts an HTML formatted text string to the ANSI character set FUNCTION HtmlToAnsi( cHtmlText ) @@ -4615,7 +4619,7 @@ FUNCTION OemToHtml( cOemText ) // This function returs the HTML character entities that are exchangeable between ANSI and OEM character sets -STATIC PROCEDURE _Init_Html_AnsiCharacterEntities +STATIC PROCEDURE _Init_Html_AnsiCharacterEntities() t_aHtmlAnsiEntities := ; { ; @@ -4698,3 +4702,175 @@ STATIC PROCEDURE _Init_Html_AnsiCharacterEntities } RETURN + +#endif + +// Converts an HTML formatted text string to the ANSI character set + +FUNCTION tip_HtmlToStr( cHtmlText ) + + LOCAL aEntity + + _Init_Html_CharacterEntities() + + FOR EACH aEntity IN t_aHtmlEntities + IF aEntity[ 2 ] $ cHtmlText + cHtmlText := StrTran( cHtmlText, aEntity[ 2 ], aEntity[ 1 ] ) + ENDIF + NEXT + IF " " $ cHtmlText + cHtmlText := StrTran( cHtmlText, " ", " " ) + ENDIF + + RETURN cHtmlText + +// Inserts HTML character entities into an ANSI text string + +FUNCTION tip_StrToHtml( cAnsiText ) + + LOCAL cHtmlText := "" + LOCAL parser := P_PARSER( cAnsiText ) + LOCAL nStart := 1 + LOCAL aEntity, cEntity, cText, cChr, nEnd + + _Init_Html_CharacterEntities() + + // Convert to Html but ignore all html character entities + DO WHILE P_SEEK( parser, "&" ) > 0 + nEnd := parser:p_pos + cText := SubStr( parser:p_str, nStart, nEnd - nStart ) + + DO WHILE ! ( ( cChr := P_NEXT( parser ) ) $ "; " ) .AND. ! Empty( cChr ) .AND. parser:p_pos != 0 + ENDDO + + SWITCH cChr + CASE ";" + // HTML character entity found + nStart := nEnd + nEnd := parser:p_pos + 1 + cEntity := SubStr( parser:p_str, nStart, nEnd - nStart ) + parser:p_end := parser:p_pos + parser:p_pos ++ + EXIT + CASE " " + // "&" character found + cHtmlText += cText + nStart := nEnd + nEnd := parser:p_pos + 1 + cText := SubStr( parser:p_str, nStart, nEnd - nStart ) + nStart := nEnd + cHtmlText += "&" + SubStr( cText, 2 ) + LOOP + OTHERWISE + cEntity := NIL + ENDSWITCH + + IF cEntity != NIL + nStart := parser:p_pos + FOR EACH aEntity IN t_aHtmlEntities + IF aEntity[ 1 ] $ cText + cText := StrTran( cText, aEntity[ 1 ], aEntity[ 2 ] ) + ENDIF + NEXT + + cHtmlText += cText + cEntity + ENDIF + ENDDO + + cText := SubStr( parser:p_str, nStart ) + FOR EACH aEntity IN t_aHtmlEntities + IF aEntity[ 1 ] $ cText + cText := StrTran( cText, aEntity[ 1 ], aEntity[ 2 ] ) + ENDIF + NEXT + cHtmlText += cText + + RETURN cHtmlText + +STATIC PROCEDURE _Init_Html_CharacterEntities() + + IF t_aHtmlEntities == NIL .OR. !( t_cHtmlCP == hb_cdpSelect() ) + t_cHtmlCP := hb_cdpSelect() + t_aHtmlEntities := ; + { ; + { hb_UTF8ToStr( "&" ), "&" }, ; // ampersand + { hb_UTF8ToStr( "<" ), "<" }, ; // less-than sign + { hb_UTF8ToStr( ">" ), ">" }, ; // greater-than sign + { hb_UTF8ToStr( "¢" ), "¢" }, ; // cent sign + { hb_UTF8ToStr( "£" ), "£" }, ; // pound sign + { hb_UTF8ToStr( "¥" ), "¥" }, ; // yen sign + { hb_UTF8ToStr( "¦" ), "¦" }, ; // broken bar + { hb_UTF8ToStr( "§" ), "§" }, ; // section sign + { hb_UTF8ToStr( "©" ), "©" }, ; // copyright sign + { hb_UTF8ToStr( "®" ), "®" }, ; // registered sign + { hb_UTF8ToStr( "°" ), "°" }, ; // degree sign + { hb_UTF8ToStr( "¿" ), "¿" }, ; // inverted question mark + { hb_UTF8ToStr( "À" ), "À" }, ; // Latin capital letter a with grave + { hb_UTF8ToStr( "Á" ), "Á" }, ; // Latin capital letter a with acute + { hb_UTF8ToStr( "Â" ), "Â" }, ; // Latin capital letter a with circumflex + { hb_UTF8ToStr( "Ã" ), "Ã" }, ; // Latin capital letter a with tilde + { hb_UTF8ToStr( "Ä" ), "Ä" }, ; // Latin capital letter a with diaeresis + { hb_UTF8ToStr( "Å" ), "Å" }, ; // Latin capital letter a with ring above + { hb_UTF8ToStr( "Æ" ), "Æ" }, ; // Latin capital letter ae + { hb_UTF8ToStr( "Ç" ), "Ç" }, ; // Latin capital letter c with cedilla + { hb_UTF8ToStr( "È" ), "È" }, ; // Latin capital letter e with grave + { hb_UTF8ToStr( "É" ), "É" }, ; // Latin capital letter e with acute + { hb_UTF8ToStr( "Ê" ), "Ê" }, ; // Latin capital letter e with circumflex + { hb_UTF8ToStr( "Ë" ), "Ë" }, ; // Latin capital letter e with diaeresis + { hb_UTF8ToStr( "Ì" ), "Ì" }, ; // Latin capital letter i with grave + { hb_UTF8ToStr( "Í" ), "Í" }, ; // Latin capital letter i with acute + { hb_UTF8ToStr( "Î" ), "Î" }, ; // Latin capital letter i with circumflex + { hb_UTF8ToStr( "Ï" ), "Ï" }, ; // Latin capital letter i with diaeresis + { hb_UTF8ToStr( "Ð" ), "Ð" }, ; // Latin capital letter eth + { hb_UTF8ToStr( "Ñ" ), "Ñ" }, ; // Latin capital letter n with tilde + { hb_UTF8ToStr( "Ò" ), "Ò" }, ; // Latin capital letter o with grave + { hb_UTF8ToStr( "Ó" ), "Ó" }, ; // Latin capital letter o with acute + { hb_UTF8ToStr( "Ô" ), "Ô" }, ; // Latin capital letter o with circumflex + { hb_UTF8ToStr( "Õ" ), "Õ" }, ; // Latin capital letter o with tilde + { hb_UTF8ToStr( "Ö" ), "Ö" }, ; // Latin capital letter o with diaeresis + { hb_UTF8ToStr( "Ø" ), "Ø" }, ; // Latin capital letter o with stroke + { hb_UTF8ToStr( "Ù" ), "Ù" }, ; // Latin capital letter u with grave + { hb_UTF8ToStr( "Ú" ), "Ú" }, ; // Latin capital letter u with acute + { hb_UTF8ToStr( "Û" ), "Û" }, ; // Latin capital letter u with circumflex + { hb_UTF8ToStr( "Ü" ), "Ü" }, ; // Latin capital letter u with diaeresis + { hb_UTF8ToStr( "Ý" ), "Ý" }, ; // Latin capital letter y with acute + { hb_UTF8ToStr( "Þ" ), "Þ" }, ; // Latin capital letter thorn + { hb_UTF8ToStr( "ß" ), "ß" }, ; // Latin small letter sharp s (German Eszett) + { hb_UTF8ToStr( "à" ), "à" }, ; // Latin small letter a with grave + { hb_UTF8ToStr( "á" ), "á" }, ; // Latin small letter a with acute + { hb_UTF8ToStr( "â" ), "â" }, ; // Latin small letter a with circumflex + { hb_UTF8ToStr( "ã" ), "ã" }, ; // Latin small letter a with tilde + { hb_UTF8ToStr( "ä" ), "ä" }, ; // Latin small letter a with diaeresis + { hb_UTF8ToStr( "å" ), "å" }, ; // Latin small letter a with ring above + { hb_UTF8ToStr( "æ" ), "æ" }, ; // Latin lowercase ligature ae + { hb_UTF8ToStr( "ç" ), "ç" }, ; // Latin small letter c with cedilla + { hb_UTF8ToStr( "è" ), "è" }, ; // Latin small letter e with grave + { hb_UTF8ToStr( "é" ), "é" }, ; // Latin small letter e with acute + { hb_UTF8ToStr( "ê" ), "ê" }, ; // Latin small letter e with circumflex + { hb_UTF8ToStr( "ë" ), "ë" }, ; // Latin small letter e with diaeresis + { hb_UTF8ToStr( "ì" ), "ì" }, ; // Latin small letter i with grave + { hb_UTF8ToStr( "í" ), "í" }, ; // Latin small letter i with acute + { hb_UTF8ToStr( "î" ), "î" }, ; // Latin small letter i with circumflex + { hb_UTF8ToStr( "ï" ), "ï" }, ; // Latin small letter i with diaeresis + { hb_UTF8ToStr( "ð" ), "ð" }, ; // Latin small letter eth + { hb_UTF8ToStr( "ñ" ), "ñ" }, ; // Latin small letter n with tilde + { hb_UTF8ToStr( "ò" ), "ò" }, ; // Latin small letter o with grave + { hb_UTF8ToStr( "ó" ), "ó" }, ; // Latin small letter o with acute + { hb_UTF8ToStr( "ô" ), "ô" }, ; // Latin small letter o with circumflex + { hb_UTF8ToStr( "õ" ), "õ" }, ; // Latin small letter o with tilde + { hb_UTF8ToStr( "ö" ), "ö" }, ; // Latin small letter o with diaeresis + { hb_UTF8ToStr( "ø" ), "ø" }, ; // Latin small letter o with stroke + { hb_UTF8ToStr( "ù" ), "ù" }, ; // Latin small letter u with grave + { hb_UTF8ToStr( "ú" ), "ú" }, ; // Latin small letter u with acute + { hb_UTF8ToStr( "û" ), "û" }, ; // Latin small letter u with circumflex + { hb_UTF8ToStr( "ü" ), "ü" }, ; // Latin small letter u with diaeresis + { hb_UTF8ToStr( "ý" ), "ý" }, ; // Latin small letter y with acute + { hb_UTF8ToStr( "þ" ), "þ" }, ; // Latin small letter thorn + { hb_UTF8ToStr( "ÿ" ), "ÿ" }, ; // Latin small letter y with diaeresis + { hb_UTF8ToStr( "^" ), "ˆ" }, ; // modifier letter circumflex accent + { hb_UTF8ToStr( "~" ), "˜" } ; // small tilde + } + ENDIF + + RETURN + diff --git a/harbour/contrib/hbwin/hbwin.hbp b/harbour/contrib/hbwin/hbwin.hbp index 6b9075248b..86f0d09ad6 100644 --- a/harbour/contrib/hbwin/hbwin.hbp +++ b/harbour/contrib/hbwin/hbwin.hbp @@ -32,6 +32,7 @@ hbwin.hbx axcore.c mapi.c +oemansi.c olecore.c oleuuid.c{watcom} hbolesrv.c diff --git a/harbour/contrib/hbwin/hbwin.hbx b/harbour/contrib/hbwin/hbwin.hbx index 965c2bf28d..82a226f630 100644 --- a/harbour/contrib/hbwin/hbwin.hbx +++ b/harbour/contrib/hbwin/hbwin.hbx @@ -281,6 +281,7 @@ DYNAMIC WCE_SIMREADPHONEBOOKENTRY DYNAMIC WCE_SIMWRITEPHONEBOOKENTRY DYNAMIC WCE_SMSSENDMESSAGE DYNAMIC WIN_ABORTDOC +DYNAMIC WIN_ANSITOOEM DYNAMIC WIN_ANSITOWIDE DYNAMIC WIN_ARC DYNAMIC WIN_AXGETCONTROL @@ -339,6 +340,7 @@ DYNAMIC WIN_LOWORD DYNAMIC WIN_MAPISENDMAIL DYNAMIC WIN_N2P DYNAMIC WIN_NCMDSHOW +DYNAMIC WIN_OEMTOANSI DYNAMIC WIN_OLEAUTO DYNAMIC WIN_OLEAUTO___ONERROR DYNAMIC WIN_OLEAUTO___OPINDEX @@ -427,6 +429,9 @@ DYNAMIC __OLEINVOKEGET DYNAMIC __OLEINVOKEMETHOD DYNAMIC __OLEINVOKEPUT DYNAMIC __OLEISDISP +DYNAMIC __OLEVARIANT +DYNAMIC __OLEVARIANTTYPE +DYNAMIC __OLEVARIANTVALUE DYNAMIC __WAPI_DEVMODE_GET DYNAMIC __WAPI_DEVMODE_NEW DYNAMIC __WAPI_DEVMODE_SET diff --git a/harbour/contrib/hbwin/oemansi.c b/harbour/contrib/hbwin/oemansi.c new file mode 100644 index 0000000000..3bc3163b01 --- /dev/null +++ b/harbour/contrib/hbwin/oemansi.c @@ -0,0 +1,112 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * OEM <-> ANSI string conversion functions (Windows specific, Xbase++ ext.) + * + * Copyright 1999-2010 Viktor Szakats (harbour syenar.net) + * www - http://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. + * + */ + +#include "hbapi.h" +#include "hbapiitm.h" + +#include + +HB_FUNC( WIN_ANSITOOEM ) +{ + PHB_ITEM pString = hb_param( 1, HB_IT_STRING ); + + if( pString ) + { + int nLen = ( int ) hb_itemGetCLen( pString ); + const char * pszSrc = hb_itemGetCPtr( pString ); + + int nWideLen = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, pszSrc, nLen, NULL, 0 ); + LPWSTR pszWide = ( LPWSTR ) hb_xgrab( ( nWideLen + 1 ) * sizeof( wchar_t ) ); + + char * pszDst; + + MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, pszSrc, nLen, pszWide, nWideLen ); + + nLen = WideCharToMultiByte( CP_OEMCP, 0, pszWide, nWideLen, NULL, 0, NULL, NULL ); + pszDst = ( char * ) hb_xgrab( nLen + 1 ); + + WideCharToMultiByte( CP_OEMCP, 0, pszWide, nWideLen, pszDst, nLen, NULL, NULL ); + + hb_xfree( pszWide ); + hb_retclen_buffer( pszDst, nLen ); + } + else + hb_retc_null(); +} + +HB_FUNC( WIN_OEMTOANSI ) +{ + PHB_ITEM pString = hb_param( 1, HB_IT_STRING ); + + if( pString ) + { + int nLen = ( int ) hb_itemGetCLen( pString ); + const char * pszSrc = hb_itemGetCPtr( pString ); + + int nWideLen = MultiByteToWideChar( CP_OEMCP, MB_PRECOMPOSED, pszSrc, nLen, NULL, 0 ); + LPWSTR pszWide = ( LPWSTR ) hb_xgrab( ( nWideLen + 1 ) * sizeof( wchar_t ) ); + + char * pszDst; + + MultiByteToWideChar( CP_OEMCP, MB_PRECOMPOSED, pszSrc, nLen, pszWide, nWideLen ); + + nLen = WideCharToMultiByte( CP_ACP, 0, pszWide, nWideLen, NULL, 0, NULL, NULL ); + pszDst = ( char * ) hb_xgrab( nLen + 1 ); + + WideCharToMultiByte( CP_ACP, 0, pszWide, nWideLen, pszDst, nLen, NULL, NULL ); + + hb_xfree( pszWide ); + hb_retclen_buffer( pszDst, nLen ); + } + else + hb_retc_null(); +} diff --git a/harbour/contrib/hbxpp/oemansix.c b/harbour/contrib/hbxpp/oemansix.c index f209fc4661..60eedcea8f 100644 --- a/harbour/contrib/hbxpp/oemansix.c +++ b/harbour/contrib/hbxpp/oemansix.c @@ -51,16 +51,72 @@ */ #include "hbapi.h" +#include "hbapiitm.h" -HB_FUNC_EXTERN( HB_ANSITOOEM ); -HB_FUNC_EXTERN( HB_OEMTOANSI ); +#if defined( HB_OS_WIN ) + #include +#endif HB_FUNC( CONVTOOEMCP ) { - HB_FUNC_EXEC( HB_ANSITOOEM ); + PHB_ITEM pString = hb_param( 1, HB_IT_STRING ); + + if( pString ) +#if defined( HB_OS_WIN ) + { + int nLen = ( int ) hb_itemGetCLen( pString ); + const char * pszSrc = hb_itemGetCPtr( pString ); + + int nWideLen = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, pszSrc, nLen, NULL, 0 ); + LPWSTR pszWide = ( LPWSTR ) hb_xgrab( ( nWideLen + 1 ) * sizeof( wchar_t ) ); + + char * pszDst; + + MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, pszSrc, nLen, pszWide, nWideLen ); + + nLen = WideCharToMultiByte( CP_OEMCP, 0, pszWide, nWideLen, NULL, 0, NULL, NULL ); + pszDst = ( char * ) hb_xgrab( nLen + 1 ); + + WideCharToMultiByte( CP_OEMCP, 0, pszWide, nWideLen, pszDst, nLen, NULL, NULL ); + + hb_xfree( pszWide ); + hb_retclen_buffer( pszDst, nLen ); + } +#else + hb_itemReturn( pString ); +#endif + else + hb_retc_null(); } HB_FUNC( CONVTOANSICP ) { - HB_FUNC_EXEC( HB_OEMTOANSI ); + PHB_ITEM pString = hb_param( 1, HB_IT_STRING ); + + if( pString ) +#if defined( HB_OS_WIN ) + { + int nLen = ( int ) hb_itemGetCLen( pString ); + const char * pszSrc = hb_itemGetCPtr( pString ); + + int nWideLen = MultiByteToWideChar( CP_OEMCP, MB_PRECOMPOSED, pszSrc, nLen, NULL, 0 ); + LPWSTR pszWide = ( LPWSTR ) hb_xgrab( ( nWideLen + 1 ) * sizeof( wchar_t ) ); + + char * pszDst; + + MultiByteToWideChar( CP_OEMCP, MB_PRECOMPOSED, pszSrc, nLen, pszWide, nWideLen ); + + nLen = WideCharToMultiByte( CP_ACP, 0, pszWide, nWideLen, NULL, 0, NULL, NULL ); + pszDst = ( char * ) hb_xgrab( nLen + 1 ); + + WideCharToMultiByte( CP_ACP, 0, pszWide, nWideLen, pszDst, nLen, NULL, NULL ); + + hb_xfree( pszWide ); + hb_retclen_buffer( pszDst, nLen ); + } +#else + hb_itemReturn( pString ); +#endif + else + hb_retc_null(); } diff --git a/harbour/src/rtl/oemansi.c b/harbour/src/rtl/oemansi.c index d2d598ab5b..2b1d94dc1c 100644 --- a/harbour/src/rtl/oemansi.c +++ b/harbour/src/rtl/oemansi.c @@ -56,6 +56,8 @@ #include "hbapi.h" #include "hbapiitm.h" +#ifdef HB_LEGACY_LEVEL4 + #if defined( HB_OS_WIN ) #include #endif @@ -123,3 +125,5 @@ HB_FUNC( HB_OEMTOANSI ) else hb_retc_null(); } + +#endif