2009-01-21 10:02 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl)

* harbour/ChangeLog
    * cleaned some typos

  * harbour/common.mak
  * harbour/source/rtl/Makefile
  + harbour/source/rtl/strtoexp.c
  * harbour/source/rtl/valtostr.c
    * moved my HB_STRTOEXP() function to separate file

  * harbour/common.mak
  * harbour/source/rtl/Makefile
  + harbour/source/rtl/strc.c
    + added two new functions to operate on C like strings:
      HB_STRDECODESCAPE( <cEscSeqStr> ) -> <cStr>
         Decode string with \ escape sequences.
      HB_STRCDECODE( <cStr> [, @<lCont> ] ) -> <cResult> | NIL
         Decode string using C compiler rules.
         If second parameter <lCont> is passed by reference then it allows
         to decode multiline strings. In such case <lCont> is set to .T.
         if string ends with unclosed "" quoting and next call to this
         function with lCont parameter continue string decoding.
         Function returns decoded string or NIL on syntax error.
      They will be helper functions for decoding .pot files.

  * harbour/source/rtl/hbi18n.c
  * harbour/source/rtl/hbstrsh.c
    % small optimizations
This commit is contained in:
Przemyslaw Czerpak
2009-01-21 08:59:24 +00:00
parent 4ba2c27af5
commit 079f7c9859
8 changed files with 376 additions and 122 deletions

View File

@@ -8,6 +8,35 @@
2008-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org)
*/
2009-01-21 10:02 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/ChangeLog
* cleaned some typos
* harbour/common.mak
* harbour/source/rtl/Makefile
+ harbour/source/rtl/strtoexp.c
* harbour/source/rtl/valtostr.c
* moved my HB_STRTOEXP() function to separate file
* harbour/common.mak
* harbour/source/rtl/Makefile
+ harbour/source/rtl/strc.c
+ added two new functions to operate on C like strings:
HB_STRDECODESCAPE( <cEscSeqStr> ) -> <cStr>
Decode string with \ escape sequences.
HB_STRCDECODE( <cStr> [, @<lCont> ] ) -> <cResult> | NIL
Decode string using C compiler rules.
If second parameter <lCont> is passed by reference then it allows
to decode multiline strings. In such case <lCont> is set to .T.
if string ends with unclosed "" quoting and next call to this
function with lCont parameter continue string decoding.
Function returns decoded string or NIL on syntax error.
They will be helper functions for decoding .pot files.
* harbour/source/rtl/hbi18n.c
* harbour/source/rtl/hbstrsh.c
% small optimizations
2009-01-20 23:04 UTC+0100 Viktor Szakats (harbour.01 syenar hu)
* contrib/hbcrypt/sha1.c
! Fixed some BCC warnings.
@@ -1815,7 +1844,7 @@
will want to make some direct modifications on active i18n set
internals).
When thread change active i18n set then it effects only this thread
and new threads which will be create later. It does not change i18n
and new threads which will be created later. It does not change i18n
in other existing threads.
+ added functions to set/get pointer to active i18n set in HVM
void * hb_vmI18N( void )
@@ -1862,11 +1891,11 @@
<pI18N> - I18N translation set,
if it's not given then currently active I18N set is used
<cNewCP> - new CP ID. Must be linked with application
<lBase> - when it's .T. then get/set base massages CP instead of
translated massages CP
<lBase> - when it's .T. then get/set base massages' CP instead of
translated massages' CP
<lTranslate> - if it's .T. then translate base (<lBase>==.T.) or
final messages in I18N set from previous CP to
given one. Base messages translation in synced
given one. Base messages translation is synced
with context ID translation.
HB_I18N_PLURALFORM( [<pI18N>,] [<cNewForm>|<bNewForm>], [<lBase>] )
@@ -1880,8 +1909,8 @@
<bNewForm> - codeblock used to calculate plural form indexes.
can be used instead of character representation but
it's not storred in serialized I18N set
<lBase> - when it's .T. then get/set base massages plural form
instead of translated massages one.
<lBase> - when it's .T. then get/set base massages' plural form
instead of translated massages' one.
HB_I18N_DESCRIPTION( [<pI18N>,] [<cNewDescription>] )
-> <cOldDescription>
@@ -1918,7 +1947,7 @@
HB_I18N_RESTORETABLE( <cTable> )
-> <pI18N> | NIL
Restores I18N translation set from strin item.
Restores I18N translation set from string item.
<cTable> - I18N translation set in string representation
On success it returns new <pI18N> set otherwise NIL if <cTable>
is not valid item created by HB_I18N_SAVETABLE() or it's corrupted.
@@ -1931,7 +1960,7 @@
-> <lValid>
<cTable> - i18n translation set serialized by HB_I18N_SAVETABLE
<cHeader> - header of i18n translation set
( LEFT( <cTable>, HB_I18N_HEADERSIZE() )
( LEFT( <cTable>, HB_I18N_HEADERSIZE() ) )
<cDescription> - optional parameter passed by reference where
will be sored i18n translation set description
extracted from valid header
@@ -1998,7 +2027,7 @@
can have his own implementation but it would help in adding new
translations by final users to any Harbour application which will
respect them. We can use LANG envvar to extract preferred language
and use the same path as executed application looking for files
and use the same path as executed application looking for
<appname>-<lang>.hil files though it may create some problems for
OSes which support only 8.3 file names so we can also define that
HB_I18N envvar has higher priority and points to expected translation

View File

@@ -611,9 +611,11 @@ RTL_LIB_OBJS = \
$(OBJ_DIR)\space$(OBJEXT) \
$(OBJ_DIR)\spfiles$(OBJEXT) \
$(OBJ_DIR)\str$(OBJEXT) \
$(OBJ_DIR)\strpeek$(OBJEXT) \
$(OBJ_DIR)\strc$(OBJEXT) \
$(OBJ_DIR)\strcase$(OBJEXT) \
$(OBJ_DIR)\strmatch$(OBJEXT) \
$(OBJ_DIR)\strpeek$(OBJEXT) \
$(OBJ_DIR)\strtoexp$(OBJEXT) \
$(OBJ_DIR)\strtran$(OBJEXT) \
$(OBJ_DIR)\strzero$(OBJEXT) \
$(OBJ_DIR)\stuff$(OBJEXT) \

View File

@@ -132,9 +132,11 @@ C_SOURCES=\
space.c \
spfiles.c \
str.c \
strc.c \
strcase.c \
strmatch.c \
strpeek.c \
strtoexp.c \
strtran.c \
strzero.c \
stuff.c \

View File

@@ -249,9 +249,9 @@ static PHB_I18N_TRANS hb_i18n_new( void )
pI18N->table = hb_hashNew( hb_itemNew( NULL ) );
pI18N->context_table = hb_hashNew( hb_itemNew( NULL ) );
pI18N->default_context = hb_hashNew( hb_itemNew( NULL ) );
pKey = hb_itemPutC( NULL, "CONTEXT" );
pKey = hb_itemPutCConst( NULL, "CONTEXT" );
hb_hashAdd( pI18N->table, pKey, pI18N->context_table );
pKey = hb_itemPutC( pKey, "" );
pKey = hb_itemPutC( pKey, NULL );
hb_hashAdd( pI18N->context_table, pKey, pI18N->default_context );
hb_itemRelease( pKey );
@@ -310,11 +310,11 @@ static PHB_I18N_TRANS hb_i18n_initialize( PHB_ITEM pTable )
{
PHB_ITEM pKey, pContext, pDefContext = NULL, pValue;
pKey = hb_itemPutC( NULL, "CONTEXT" );
pKey = hb_itemPutCConst( NULL, "CONTEXT" );
pContext = hb_hashGetItemPtr( pTable, pKey, 0 );
if( pContext )
{
pKey = hb_itemPutC( pKey, "" );
pKey = hb_itemPutC( pKey, NULL );
pDefContext = hb_hashGetItemPtr( pContext, pKey, 0 );
}
@@ -327,32 +327,32 @@ static PHB_I18N_TRANS hb_i18n_initialize( PHB_ITEM pTable )
pI18N->context_table = hb_itemNew( pContext );
pI18N->default_context = hb_itemNew( pDefContext );
pKey = hb_itemPutC( pKey, "BASE_CODEPAGE" );
pKey = hb_itemPutCConst( pKey, "BASE_CODEPAGE" );
pValue = hb_hashGetItemPtr( pTable, pKey, 0 );
if( pValue )
pI18N->base_cdpage = hb_cdpFind( hb_itemGetCPtr( pValue ) );
pKey = hb_itemPutC( pKey, "CODEPAGE" );
pKey = hb_itemPutCConst( pKey, "CODEPAGE" );
pValue = hb_hashGetItemPtr( pTable, pKey, 0 );
if( pValue )
pI18N->cdpage = hb_cdpFind( hb_itemGetCPtr( pValue ) );
pKey = hb_itemPutC( pKey, "BASE_LANG" );
pKey = hb_itemPutCConst( pKey, "BASE_LANG" );
pValue = hb_hashGetItemPtr( pTable, pKey, 0 );
if( pValue )
pI18N->base_plural_form = hb_i18n_pluralformfind( hb_itemGetCPtr( pValue ) );
pKey = hb_itemPutC( pKey, "LANG" );
pKey = hb_itemPutCConst( pKey, "LANG" );
pValue = hb_hashGetItemPtr( pTable, pKey, 0 );
if( pValue )
pI18N->plural_form = hb_i18n_pluralformfind( hb_itemGetCPtr( pValue ) );
pKey = hb_itemPutC( pKey, "BASE_PLURAL_EXP" );
pKey = hb_itemPutCConst( pKey, "BASE_PLURAL_EXP" );
pValue = hb_hashGetItemPtr( pTable, pKey, 0 );
if( pValue )
pI18N->base_plural_block = hb_i18n_pluralexp_compile( pValue );
pKey = hb_itemPutC( pKey, "PLURAL_EXP" );
pKey = hb_itemPutCConst( pKey, "PLURAL_EXP" );
pValue = hb_hashGetItemPtr( pTable, pKey, 0 );
if( pValue )
pI18N->plural_block = hb_i18n_pluralexp_compile( pValue );
@@ -382,7 +382,7 @@ static PHB_ITEM hb_i18n_serialize( PHB_I18N_TRANS pI18N )
HB_PUT_LE_UINT32( &pI18Nbuffer[ HB_I18N_SIZE_OFFSET ], ulSize );
HB_PUT_LE_UINT32( &pI18Nbuffer[ HB_I18N_CRC_OFFSET ], ulCRC );
pKey = hb_itemPutC( NULL, "DESCRIPTION" );
pKey = hb_itemPutCConst( NULL, "DESCRIPTION" );
pValue = hb_hashGetItemPtr( pI18N->table, pKey, 0 );
if( pValue )
hb_strncpy( &pI18Nbuffer[ HB_I18N_TXT_OFFSET ],
@@ -502,7 +502,7 @@ static BOOL hb_i18n_getpluralform( PHB_I18N_TRANS pI18N, PHB_ITEM pOldForm,
else if( iForm )
hb_itemPutC( pOldForm, hb_i18n_pluralformid( iForm ) );
else
hb_itemPutC( pOldForm, "EN" ); /* default is ENGLISH */
hb_itemPutCConst( pOldForm, "EN" ); /* default is ENGLISH */
}
fResult = TRUE;
}
@@ -666,7 +666,7 @@ static const char * hb_i18n_description( PHB_I18N_TRANS pI18N, PHB_ITEM pItem )
{
if( pI18N )
{
PHB_ITEM pKey = hb_itemPutC( NULL, "DESCRIPTION" ), pValue;
PHB_ITEM pKey = hb_itemPutCConst( NULL, "DESCRIPTION" ), pValue;
pValue = hb_hashGetItemPtr( pI18N->table, pKey, 0 );
if( pItem )
@@ -1051,12 +1051,15 @@ HB_FUNC( HB_I18N_CHECK )
HB_FUNC( __I18N_HASHTABLE )
{
PHB_I18N_TRANS pI18N;
PHB_ITEM pTable = hb_param( 1, HB_IT_HASH );
if( ISHASH( 1 ) )
if( pTable )
{
pI18N = hb_i18n_initialize( hb_param( 1, HB_IT_HASH ) );
pI18N = hb_i18n_initialize( hb_itemNew( pTable ) );
if( pI18N )
hb_itemReturnRelease( hb_i18n_newitem( pI18N ) );
else
hb_itemRelease( pTable );
}
else
{

View File

@@ -68,9 +68,10 @@ HB_FUNC( HB_STRSHRINK )
lLen -= lShrinkBy;
else
lLen = 0;
hb_retclen( hb_itemGetCPtr( pText ), lLen );
}
hb_retclen( hb_itemGetCPtr( pText ), lLen );
else
hb_itemReturn( pText );
}
else
hb_retc( NULL );

164
harbour/source/rtl/strc.c Normal file
View File

@@ -0,0 +1,164 @@
/*
* $Id$
*/
/*
* Harbour Project source code:
* HB_STRDECODESCAPE() - decode string with \ escape sequences
* HB_STRCDECODE() - decode string using C compiler rules
*
* Copyright 2009 Przemyslaw Czerpak <druzus / at / priv.onet.pl>
* 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.
*
*/
#include "hbapi.h"
#include "hbapiitm.h"
#include "hbapierr.h"
/* HB_STRDECODESCAPE( <cEscSeqStr> ) -> <cStr>
* decode string with \ escape sequences
*/
HB_FUNC( HB_STRDECODESCAPE )
{
PHB_ITEM pText = hb_param( 1, HB_IT_STRING );
if( pText )
{
ULONG ulLen = hb_itemGetCLen( pText );
if( ulLen > 0 )
{
char * str = ( char * ) hb_xgrab( ulLen + 1 );
hb_xmemcpy( str, hb_itemGetCPtr( pText ), ulLen + 1 );
hb_strRemEscSeq( str, &ulLen );
hb_retclen_buffer( str, ulLen );
}
else
hb_itemReturn( pText );
}
else
hb_errRT_BASE_SubstR( EG_ARG, 1099, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
/* HB_STRCDECODE( <cStr> [, @<lCont> ] ) -> <cResult> | NIL
* decode string using C compiler rules
* if second parameter <lCont> is passed by reference then it allows
* to decode multiline strings. In such case <lCont> is set to .T.
* if string ends with unclosed "" quoting.
* Function returns decoded string or NIL on syntax error.
*/
HB_FUNC( HB_STRCDECODE )
{
PHB_ITEM pText = hb_param( 1, HB_IT_STRING );
if( pText )
{
ULONG ulLen = hb_itemGetCLen( pText );
BOOL fCont = ISLOG( 2 ) && hb_parl( 2 );
if( ulLen > 0 )
{
const char * pszSrc = hb_itemGetCPtr( pText );
char * pszDst = ( char * ) hb_xgrab( ulLen + 1 );
ULONG ulDst = 0, ul;
for( ;; )
{
if( !fCont )
{
while( ulLen && HB_ISSPACE( *pszSrc ) )
{
++pszSrc;
--ulLen;
}
if( ulLen && *pszSrc == '"' )
{
++pszSrc;
--ulLen;
fCont = TRUE;
}
}
if( !fCont || !ulLen )
break;
ul = 0;
while( ul < ulLen )
{
char c = pszSrc[ ul ];
if( c == '"' )
{
fCont = FALSE;
break;
}
pszDst[ ulDst + ul ] = c;
if( ++ul < ulLen && c == '\\' )
{
pszDst[ ulDst + ul ] = pszSrc[ ul ];
++ul;
}
}
if( ul > 0 )
{
pszSrc += ul;
ulLen -= ul;
hb_strRemEscSeq( pszDst + ulDst, &ul );
ulDst += ul;
}
if( !fCont )
{
++pszSrc;
--ulLen;
}
}
if( ulLen == 0 && ( !fCont || ISBYREF( 2 ) ) )
{
hb_retclen_buffer( pszDst, ulDst );
hb_storl( fCont, 2 );
}
else
hb_xfree( pszDst );
}
else if( fCont )
hb_itemReturn( pText );
}
else
hb_errRT_BASE_SubstR( EG_ARG, 1099, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}

View File

@@ -0,0 +1,148 @@
/*
* $Id$
*/
/*
* Harbour Project source code:
* HB_STRTOEXP() function - convert string to valid macrocompiler expression
*
* Copyright 2009 Przemyslaw Czerpak <druzus / at / priv.onet.pl>
* 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.
*
*/
#include "hbapi.h"
HB_FUNC( HB_STRTOEXP )
{
const char * pszString = hb_parc( 1 );
if( pszString )
{
ULONG ulLen = hb_parclen( 1 ), ulRet, ul, uQ = 0;
int iType = 0;
char ch, * pDst, * pszResult;
for( ul = 0; ul < ulLen; ++ul )
{
switch( pszString[ ul ] )
{
case '\\':
++uQ;
break;
case '"':
++uQ;
iType |= 1;
break;
case '\'':
iType |= 2;
break;
case ']':
iType |= 4;
break;
case '\r':
case '\n':
iType |= 7;
++uQ;
break;
case '\0':
iType |= 7;
uQ += 3;
break;
}
}
if( iType == 7 || ( ISLOG( 2 ) && hb_parl( 2 ) ) )
{
ulRet = ulLen + 3 + uQ;
pDst = pszResult = ( char * ) hb_xgrab( ulRet + 1 );
*pDst++ = 'e';
*pDst++ = '"';
for( ul = 0; ul < ulLen; ++ul )
{
ch = pszString[ ul ];
switch( ch )
{
case '\r':
*pDst++ = '\\';
*pDst++ = 'r';
break;
case '\n':
*pDst++ = '\\';
*pDst++ = 'n';
break;
case '\0':
*pDst++ = '\\';
*pDst++ = '0';
*pDst++ = '0' + ( ch >> 3 );
*pDst++ = '0' + ( ch & 7 );
break;
case '\\':
case '"':
*pDst++ = '\\';
default:
*pDst++ = ch;
break;
}
}
*pDst++ = '"';
}
else
{
ulRet = ulLen + 2;
pDst = pszResult = ( char * ) hb_xgrab( ulRet + 1 );
if( ( iType & 1 ) == 0 )
*pDst++ = ch = '"';
else if( ( iType & 2 ) == 0 )
*pDst++ = ch = '\'';
else
{
*pDst++ = '[';
ch = ']';
}
memcpy( pDst, pszString, ulLen );
pDst += ulLen;
*pDst++ = ch;
}
*pDst = '\0';
hb_retclen_buffer( pszResult, ulRet );
}
}

View File

@@ -64,98 +64,3 @@ HB_FUNC( HB_VALTOSTR )
else
hb_retclen( buffer, ulLen );
}
HB_FUNC( HB_STRTOEXP )
{
const char * pszString = hb_parc( 1 );
if( pszString )
{
ULONG ulLen = hb_parclen( 1 ), ulRet, ul, uQ = 0;
int iType = 0;
char ch, * pDst, * pszResult;
for( ul = 0; ul < ulLen; ++ul )
{
switch( pszString[ ul ] )
{
case '\\':
++uQ;
break;
case '"':
++uQ;
iType |= 1;
break;
case '\'':
iType |= 2;
break;
case ']':
iType |= 4;
break;
case '\r':
case '\n':
iType |= 7;
++uQ;
break;
case '\0':
iType |= 7;
uQ += 3;
break;
}
}
if( iType == 7 )
{
ulRet = ulLen + 3 + uQ;
pDst = pszResult = ( char * ) hb_xgrab( ulRet + 1 );
*pDst++ = 'e';
*pDst++ = '"';
for( ul = 0; ul < ulLen; ++ul )
{
ch = pszString[ ul ];
switch( ch )
{
case '\r':
*pDst++ = '\\';
*pDst++ = 'r';
break;
case '\n':
*pDst++ = '\\';
*pDst++ = 'n';
break;
case '\0':
*pDst++ = '\\';
*pDst++ = '0';
*pDst++ = '0' + ( ch >> 3 );
*pDst++ = '0' + ( ch & 7 );
break;
case '\\':
case '"':
*pDst++ = '\\';
default:
*pDst++ = ch;
break;
}
}
*pDst++ = '"';
}
else
{
ulRet = ulLen + 2;
pDst = pszResult = ( char * ) hb_xgrab( ulRet + 1 );
if( ( iType & 1 ) == 0 )
*pDst++ = ch = '"';
else if( ( iType & 2 ) == 0 )
*pDst++ = ch = '\'';
else
{
*pDst++ = '[';
ch = ']';
}
memcpy( pDst, pszString, ulLen );
pDst += ulLen;
*pDst++ = ch;
}
*pDst = '\0';
hb_retclen_buffer( pszResult, ulRet );
}
}