2009-03-02 09:36 UTC+0100 Viktor Szakats (harbour.01 syenar hu)
* source/rtl/Makefile
* include/hbextern.ch
+ source/rtl/hbstrfmt.c
+ Added HB_STRFORMAT() sprintf()-like formatting.
+ Added hb_StrFormat() C level function.
; Work of Mindaugas sent to the list, with some minor
cleanups applied. Please test on your platform/compiler.
* contrib/examples/uhttpd/uhttpd.prg
* contrib/examples/uhttpd/cgifunc.prg
* contrib/examples/uhttpd/session.prg
* contrib/examples/uhttpd/uhttpd.hbm
* xhb compatibility cleanups.
- xhb lib and header dependency removed.
* utils/hbmk2/hbmk2.prg
* Changed so that libs won't inherit their .hbm file paths.
+ Embedded .hbm files will inherit their parents dir.
This commit is contained in:
@@ -8,6 +8,26 @@
|
||||
2009-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org)
|
||||
*/
|
||||
|
||||
2009-03-02 09:36 UTC+0100 Viktor Szakats (harbour.01 syenar hu)
|
||||
* source/rtl/Makefile
|
||||
* include/hbextern.ch
|
||||
+ source/rtl/hbstrfmt.c
|
||||
+ Added HB_STRFORMAT() sprintf()-like formatting.
|
||||
+ Added hb_StrFormat() C level function.
|
||||
; Work of Mindaugas sent to the list, with some minor
|
||||
cleanups applied. Please test on your platform/compiler.
|
||||
|
||||
* contrib/examples/uhttpd/uhttpd.prg
|
||||
* contrib/examples/uhttpd/cgifunc.prg
|
||||
* contrib/examples/uhttpd/session.prg
|
||||
* contrib/examples/uhttpd/uhttpd.hbm
|
||||
* xhb compatibility cleanups.
|
||||
- xhb lib and header dependency removed.
|
||||
|
||||
* utils/hbmk2/hbmk2.prg
|
||||
* Changed so that libs won't inherit their .hbm file paths.
|
||||
+ Embedded .hbm files will inherit their parents dir.
|
||||
|
||||
2009-03-02 08:30 UTC+0100 Viktor Szakats (harbour.01 syenar hu)
|
||||
* INSTALL
|
||||
* Updates.
|
||||
|
||||
@@ -50,6 +50,10 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __XHARBOUR__
|
||||
#include "hbcompat.ch"
|
||||
#else
|
||||
|
||||
//#include "xhb.ch"
|
||||
#include "common.ch"
|
||||
#include "error.ch"
|
||||
@@ -64,7 +68,7 @@
|
||||
MEMVAR _SERVER, _GET, _POST, _COOKIE, _REQUEST, _HTTP_REQUEST
|
||||
|
||||
FUNCTION uhttpd_GetVars( cFields, cSeparator )
|
||||
LOCAL hHashVars := Hash()
|
||||
LOCAL hHashVars := hb_Hash()
|
||||
LOCAL aField, cField, aFields
|
||||
LOCAL cName, xValue
|
||||
DEFAULT cSeparator TO "&"
|
||||
@@ -136,7 +140,7 @@ FUNCTION uhttpd_SplitUrl( cUrl )
|
||||
LOCAL cProto, cHost, cPort, nPort, cUser, cPass, cPath, cQuery, cFragment
|
||||
|
||||
// Prevents case matching
|
||||
HSetCaseMatch( hUrl, FALSE )
|
||||
hb_HSetCaseMatch( hUrl, FALSE )
|
||||
|
||||
cTemp := cUrl
|
||||
|
||||
@@ -251,7 +255,7 @@ FUNCTION uhttpd_SplitUrl( cUrl )
|
||||
hb_hSet( hUrl, "FRAGMENT", cFragment )
|
||||
|
||||
// Prevents externals to add something else to this Hash
|
||||
HSetAutoAdd( hUrl, FALSE )
|
||||
hb_HSetAutoAdd( hUrl, FALSE )
|
||||
RETURN hUrl
|
||||
|
||||
|
||||
@@ -858,4 +862,3 @@ FUNCTION uhttpd_HGetValue( hHash, cKey )
|
||||
ENDIF
|
||||
//RETURN IIF( cKey IN hHash:Keys, hHash[ cKey ], NIL )
|
||||
RETURN xVal
|
||||
|
||||
|
||||
@@ -50,7 +50,10 @@
|
||||
*
|
||||
*/
|
||||
|
||||
//#include "hbcompat.ch"
|
||||
#ifdef __XHARBOUR__
|
||||
#include "hbcompat.ch"
|
||||
#else
|
||||
|
||||
#include "common.ch"
|
||||
#include "hbclass.ch"
|
||||
#include "fileio.ch"
|
||||
@@ -637,7 +640,7 @@ METHOD SessionDestroy( cID ) CLASS uhttpd_Session
|
||||
//TraceLog( "SessionDestroy() - cID", cID )
|
||||
DEFAULT cID TO ::cSID
|
||||
|
||||
_SESSION := Hash()
|
||||
_SESSION := hb_Hash()
|
||||
::oCookie:DeleteCookie( ::cName )
|
||||
|
||||
//TraceLog( "SessionDestroy() - cID, oCGI:h_Session", cID, DumpValue( oCGI:h_Session ) )
|
||||
@@ -744,14 +747,14 @@ RETURN IIF( !Empty( aSerial ), HB_Serialize( aSerial ), NIL )
|
||||
|
||||
METHOD Decode( cData ) CLASS uhttpd_Session
|
||||
LOCAL lOk := TRUE
|
||||
LOCAL cSerial := HB_DeserialBegin( cData )
|
||||
LOCAL cSerial := cData
|
||||
LOCAL xVal, aElem
|
||||
//LOCAL cKey
|
||||
|
||||
//TraceLog( "Decode - cSerial", cSerial )
|
||||
//::oCGI:ToLogFile( "Decode - cSerial = " + hb_cStr( cSerial ), "/pointtoit/tmp/log.txt" )
|
||||
|
||||
DO WHILE ( xVal := HB_DeserialNext( @cSerial ) ) <> NIL
|
||||
DO WHILE ( xVal := HB_Deserialize( @cSerial ) ) <> NIL
|
||||
//TraceLog( "Decode - xVal", DumpValue( xVal ) )
|
||||
//::oCGI:ToLogFile( "Decode - xVal = " + hb_cStr( xVal ) + ", ValType( xVal ) = " + ValType( xVal ), "/pointtoit/tmp/log.txt" )
|
||||
|
||||
@@ -813,4 +816,3 @@ PROCEDURE DestroyObject() CLASS uhttpd_Session
|
||||
//::oCGI:ToLogFile( "Session destroyed" )
|
||||
//::oCGI := NIL
|
||||
RETURN
|
||||
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
# $Id$
|
||||
#
|
||||
|
||||
-n -mt -gui uhttpd.prg cgifunc.prg cookie.prg session.prg uhttpdc.c socket.c -lxhb -lhbct
|
||||
-n -mt -gui uhttpd.prg cgifunc.prg cookie.prg session.prg uhttpdc.c socket.c -lhbct
|
||||
|
||||
@@ -75,11 +75,17 @@
|
||||
|
||||
*/
|
||||
|
||||
// comment out this line to activate hb_toOutDebug()
|
||||
#define DEBUG_ACTIVE
|
||||
// remove comment to activate hb_toOutDebug()
|
||||
//#define DEBUG_ACTIVE
|
||||
|
||||
#ifndef _XHARBOUR_
|
||||
#include "hbcompat.ch"
|
||||
#ifdef __XHARBOUR__
|
||||
#include "hbcompat.ch"
|
||||
#xtranslate hb_StrFormat( [<x,...>] ) => hb_sprintf( <x> )
|
||||
#else
|
||||
/* TRY / CATCH / FINALLY / END */
|
||||
#xcommand TRY => BEGIN SEQUENCE WITH {|oErr| Break( oErr )}
|
||||
#xcommand CATCH [<!oErr!>] => RECOVER [USING <oErr>] <-oErr->
|
||||
#xcommand FINALLY => ALWAYS
|
||||
#endif
|
||||
#include "fileio.ch"
|
||||
#include "common.ch"
|
||||
@@ -135,20 +141,17 @@
|
||||
#define CR_LF (CHR(13)+CHR(10))
|
||||
#define HB_IHASH() HB_HSETCASEMATCH( {=>}, FALSE )
|
||||
|
||||
#ifndef _XHARBOUR_
|
||||
#ifndef __XHARBOUR__
|
||||
|
||||
#ifdef __PLATFORM__WINDOWS
|
||||
REQUEST HB_GT_WVT_DEFAULT
|
||||
REQUEST HB_GT_WIN
|
||||
REQUEST HB_GT_NUL
|
||||
#ifdef HB_MT_VM
|
||||
#define THREAD_GT hb_gtVersion()
|
||||
#endif
|
||||
#else
|
||||
REQUEST HB_GT_STD_DEFAULT
|
||||
REQUEST HB_GT_NUL
|
||||
#define THREAD_GT "XWC"
|
||||
#endif
|
||||
#define THREAD_GT hb_gtVersion()
|
||||
|
||||
#else
|
||||
|
||||
@@ -221,7 +224,7 @@ FUNCTION MAIN( ... )
|
||||
|
||||
// Check GT version - if I have started app with //GT:NUL then I have to disable
|
||||
// console
|
||||
cGT := HB_GT_VERSION()
|
||||
cGT := HB_GTVERSION()
|
||||
IF ( cGT == "NUL" )
|
||||
lConsole := FALSE
|
||||
ENDIF
|
||||
@@ -510,9 +513,9 @@ FUNCTION MAIN( ... )
|
||||
IF hSocket == NIL
|
||||
|
||||
#ifdef USE_HB_INET
|
||||
WriteToConsole( hb_sprintf( "accept() error" ) )
|
||||
WriteToConsole( hb_StrFormat( "accept() error" ) )
|
||||
#else
|
||||
WriteToConsole( hb_sprintf( "accept() error: %s", socket_error() ) )
|
||||
WriteToConsole( hb_StrFormat( "accept() error: %s", socket_error() ) )
|
||||
#endif
|
||||
|
||||
ELSE
|
||||
@@ -919,7 +922,7 @@ STATIC FUNCTION ParseRequest( cRequest )
|
||||
// RFC2616
|
||||
aRequest := uhttpd_split( CR_LF, cRequest )
|
||||
|
||||
//hb_ToOutDebug( "aRequest = %s\n\r", hb_ValToExp( aRequest ) )
|
||||
//hb_toOutDebug( "aRequest = %s\n\r", hb_ValToExp( aRequest ) )
|
||||
|
||||
WriteToConsole( aRequest[1] )
|
||||
aLine := uhttpd_split( " ", aRequest[1] )
|
||||
@@ -1216,7 +1219,7 @@ STATIC FUNCTION CGIExec( cProc, /*@*/ cOutPut )
|
||||
|
||||
//hb_toOutDebug( "Launching process: %s\n\r", cProc )
|
||||
// No hIn, hErr == hOut
|
||||
t_hProc := HB_OpenProcess( cProc, , @hOut, @hOut, .T. ) // .T. = Detached Process (Hide Window)
|
||||
t_hProc := hb_processOpen( cProc, , @hOut, @hOut, .T. ) // .T. = Detached Process (Hide Window)
|
||||
|
||||
IF t_hProc > -1
|
||||
//hb_toOutDebug( "Process handler: %s\n\r", t_hProc )
|
||||
@@ -1421,7 +1424,7 @@ STATIC FUNCTION sendReply( hSocket, cSend )
|
||||
DO WHILE LEN( cSend ) > 0
|
||||
IF ( nLen := hb_InetSendAll( hSocket, cSend ) ) == -1
|
||||
? "send() error:", hb_InetErrorCode( hSocket ), HB_InetErrorDesc( hSocket )
|
||||
WriteToConsole( hb_sprintf( "ProcessConnection() - send() error: %s, cSend = %s, hSocket = %s", hb_InetErrorDesc( hSocket ), cSend, hSocket ) )
|
||||
WriteToConsole( hb_StrFormat( "ProcessConnection() - send() error: %s, cSend = %s, hSocket = %s", hb_InetErrorDesc( hSocket ), cSend, hSocket ) )
|
||||
EXIT
|
||||
ELSEIF nLen > 0
|
||||
cSend := SUBSTR( cSend, nLen + 1 )
|
||||
@@ -1431,7 +1434,7 @@ STATIC FUNCTION sendReply( hSocket, cSend )
|
||||
DO WHILE LEN( cSend ) > 0
|
||||
IF ( nLen := socket_send( hSocket, cSend ) ) == -1
|
||||
? "send() error:", socket_error()
|
||||
WriteToConsole( hb_sprintf( "ServiceConnection() - send() error: %s, cSend = %s, hSocket = %s", socket_error(), cSend, hSocket ) )
|
||||
WriteToConsole( hb_StrFormat( "ServiceConnection() - send() error: %s, cSend = %s, hSocket = %s", socket_error(), cSend, hSocket ) )
|
||||
EXIT
|
||||
ELSEIF nLen > 0
|
||||
cSend := SUBSTR( cSend, nLen + 1 )
|
||||
|
||||
@@ -898,6 +898,7 @@ EXTERNAL HB_GETREADVAR
|
||||
EXTERNAL HB_DISABLEWAITLOCKS
|
||||
EXTERNAL HB_MACROBLOCK
|
||||
EXTERNAL HB_MMIDDLEDOWN
|
||||
EXTERNAL HB_STRFORMAT
|
||||
|
||||
EXTERNAL HB_INISETCOMMENT
|
||||
EXTERNAL HB_INIREAD
|
||||
|
||||
@@ -73,6 +73,7 @@ C_SOURCES=\
|
||||
hbregex.c \
|
||||
hbregexc.c \
|
||||
hbrunfun.c \
|
||||
hbstrfmt.c \
|
||||
hbstrsh.c \
|
||||
hbtoken.c \
|
||||
hbzlib.c \
|
||||
|
||||
479
harbour/source/rtl/hbstrfmt.c
Normal file
479
harbour/source/rtl/hbstrfmt.c
Normal file
@@ -0,0 +1,479 @@
|
||||
/*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
/*
|
||||
* HB_STRFORMAT()/hb_StrFormat() functions.
|
||||
*
|
||||
* Copyright 2008 Mindaugas Kavaliauskas <dbtopas at dbtopas.lt>
|
||||
* 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"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char * pData;
|
||||
ULONG ulLen;
|
||||
ULONG ulMax;
|
||||
} BUFFERTYPE;
|
||||
|
||||
static void bufadd( BUFFERTYPE * pBuf, char * pAdd, ULONG ulLen )
|
||||
{
|
||||
if( pBuf->ulLen + ulLen >= pBuf->ulMax )
|
||||
{
|
||||
pBuf->ulMax += ( pBuf->ulMax >> 1 ) + ulLen;
|
||||
pBuf->pData = ( char * ) hb_xrealloc( pBuf->pData, pBuf->ulMax );
|
||||
}
|
||||
memcpy( pBuf->pData + pBuf->ulLen, pAdd, ulLen );
|
||||
pBuf->ulLen += ulLen;
|
||||
pBuf->pData[ pBuf->ulLen ] = '\0';
|
||||
}
|
||||
|
||||
PHB_ITEM hb_StrFormat( PHB_ITEM pItemReturn, PHB_ITEM pItemFormat, int iCount, PHB_ITEM * pItemArray )
|
||||
{
|
||||
BUFFERTYPE buffer;
|
||||
PHB_ITEM pItem;
|
||||
char *pFmt, *pFmtEnd, *pFmtSave;
|
||||
int i, iParam, iParamNo, iWidth, iDec;
|
||||
ULONG ulSize;
|
||||
BOOL fLeftAlign, fForceSign, fPadZero, fSpaceSign;
|
||||
|
||||
pFmt = hb_itemGetCPtr( pItemFormat );
|
||||
ulSize = hb_itemGetCLen( pItemFormat );
|
||||
pFmtEnd = pFmt + ulSize;
|
||||
|
||||
buffer.ulMax = ulSize + 16;
|
||||
buffer.ulLen = 0;
|
||||
buffer.pData = ( char* ) hb_xgrab( buffer.ulMax );
|
||||
buffer.pData[ 0 ] = '\0';
|
||||
|
||||
iParam = 0;
|
||||
while( pFmt < pFmtEnd )
|
||||
{
|
||||
if( *pFmt != '%' )
|
||||
{
|
||||
bufadd( &buffer, pFmt++, 1 );
|
||||
continue;
|
||||
}
|
||||
|
||||
pFmtSave = pFmt;
|
||||
|
||||
if( ++pFmt >= pFmtEnd )
|
||||
continue;
|
||||
|
||||
if( *pFmt == '%' )
|
||||
{
|
||||
bufadd( &buffer, pFmt++, 1 );
|
||||
continue;
|
||||
}
|
||||
|
||||
iWidth = iDec = -1;
|
||||
fLeftAlign = fForceSign = fPadZero = fSpaceSign = 0;
|
||||
|
||||
/* parse parameter number */
|
||||
iParamNo = 0;
|
||||
while( HB_ISDIGIT( *pFmt ) )
|
||||
iParamNo = iParamNo * 10 + *pFmt++ - '0';
|
||||
|
||||
if( iParamNo > 0 && *pFmt == '$' )
|
||||
{
|
||||
pFmt++;
|
||||
}
|
||||
else
|
||||
{
|
||||
iParamNo = -1;
|
||||
pFmt = pFmtSave + 1;
|
||||
}
|
||||
|
||||
/* Parse flags */
|
||||
do
|
||||
{
|
||||
switch( *pFmt )
|
||||
{
|
||||
case '-':
|
||||
fLeftAlign = 1;
|
||||
continue;
|
||||
case '+':
|
||||
fForceSign = 1;
|
||||
continue;
|
||||
case ' ':
|
||||
fSpaceSign = 1;
|
||||
continue;
|
||||
case '0':
|
||||
fPadZero = 1;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
} while( * ++pFmt );
|
||||
|
||||
/* Parse width */
|
||||
if( HB_ISDIGIT( *pFmt ) )
|
||||
{
|
||||
iWidth = 0;
|
||||
while( HB_ISDIGIT( *pFmt ) )
|
||||
iWidth = iWidth * 10 + *pFmt++ - '0';
|
||||
}
|
||||
|
||||
/* Parse decimals */
|
||||
if( *pFmt == '.' )
|
||||
{
|
||||
pFmt++;
|
||||
iDec = 0;
|
||||
if( HB_ISDIGIT( *pFmt ) )
|
||||
{
|
||||
while( HB_ISDIGIT( *pFmt ) )
|
||||
iDec = iDec * 10 + *pFmt++ - '0';
|
||||
}
|
||||
}
|
||||
|
||||
/* Parse specifier */
|
||||
if( *pFmt == 'c' || *pFmt == 'd' || *pFmt == 'f' || *pFmt == 's' )
|
||||
{
|
||||
if( iParamNo == -1 )
|
||||
iParamNo = ++iParam;
|
||||
|
||||
if( iParamNo > iCount )
|
||||
{
|
||||
hb_xfree( buffer.pData );
|
||||
hb_errRT_BASE_SubstR( EG_ARG, 1099, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pItem = pItemArray[ iParamNo - 1 ];
|
||||
}
|
||||
else
|
||||
pItem = NULL;
|
||||
|
||||
switch( *pFmt )
|
||||
{
|
||||
case 'c':
|
||||
{
|
||||
char buf[ 1 ];
|
||||
|
||||
buf[ 0 ] = ( char ) hb_itemGetNI( pItem );
|
||||
if( fLeftAlign )
|
||||
{
|
||||
bufadd( &buffer, buf, 1 );
|
||||
}
|
||||
if( iWidth > 1 )
|
||||
{
|
||||
for( i = 1; i < iWidth; i++ )
|
||||
bufadd( &buffer, " ", 1 );
|
||||
}
|
||||
if( ! fLeftAlign )
|
||||
{
|
||||
bufadd( &buffer, buf, 1 );
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 'd':
|
||||
{
|
||||
char * pStr = NULL, * pStr2;
|
||||
int iSize, iExtra;
|
||||
|
||||
if( HB_IS_NUMERIC( pItem ) )
|
||||
{
|
||||
iSize = sizeof( HB_LONG ) * 3 + 1;
|
||||
pStr2 = pStr = ( char * ) hb_xgrab( iSize + 1 );
|
||||
hb_itemStrBuf( pStr, pItem, iSize, 0 );
|
||||
while( *pStr2 == ' ' )
|
||||
pStr2++;
|
||||
iSize = strlen( pStr2 );
|
||||
}
|
||||
else if( HB_IS_LOGICAL( pItem ) )
|
||||
{
|
||||
iSize = 1;
|
||||
if( hb_itemGetL( pItem ) )
|
||||
pStr2 = "1";
|
||||
else
|
||||
pStr2 = "0";
|
||||
}
|
||||
else
|
||||
{
|
||||
iSize = 1;
|
||||
pStr2 = "0";
|
||||
}
|
||||
|
||||
iExtra = 0;
|
||||
if( ( fForceSign || fSpaceSign ) && *pStr2 != '-' )
|
||||
iExtra = 1;
|
||||
|
||||
if( fLeftAlign )
|
||||
{
|
||||
/* Zero padding is ignored on left Align */
|
||||
if( *pStr2 != '-' )
|
||||
{
|
||||
/* ForceSign has priority over SpaceSign */
|
||||
if( fForceSign )
|
||||
bufadd( &buffer, "+", 1 );
|
||||
else
|
||||
{
|
||||
if( fSpaceSign )
|
||||
bufadd( &buffer, " ", 1 );
|
||||
}
|
||||
}
|
||||
bufadd( &buffer, pStr2, ( ULONG ) iSize );
|
||||
for( i = iSize + iExtra; i < iWidth; i++ )
|
||||
bufadd( &buffer, " ", 1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Right align */
|
||||
if( fPadZero )
|
||||
{
|
||||
if( *pStr2 == '-' )
|
||||
{
|
||||
bufadd( &buffer, pStr2++, 1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* ForceSign has priority over SpaceSign */
|
||||
if( fForceSign )
|
||||
bufadd( &buffer, "+", 1 );
|
||||
else
|
||||
{
|
||||
if( fSpaceSign )
|
||||
bufadd( &buffer, " ", 1 );
|
||||
}
|
||||
}
|
||||
for( i = iSize + iExtra; i < iWidth; i++ )
|
||||
bufadd( &buffer, "0", 1 );
|
||||
|
||||
bufadd( &buffer, pStr2, strlen( pStr2 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
for( i = iSize + iExtra; i < iWidth; i++ )
|
||||
bufadd( &buffer, " ", 1 );
|
||||
|
||||
if( *pStr2 != '-' )
|
||||
{
|
||||
/* ForceSign has priority over SpaceSign */
|
||||
if( fForceSign )
|
||||
bufadd( &buffer, "+", 1 );
|
||||
else
|
||||
{
|
||||
if( fSpaceSign )
|
||||
bufadd( &buffer, " ", 1 );
|
||||
}
|
||||
}
|
||||
bufadd( &buffer, pStr2, ( ULONG ) iSize );
|
||||
}
|
||||
}
|
||||
|
||||
if( pStr )
|
||||
hb_xfree( pStr );
|
||||
break;
|
||||
}
|
||||
|
||||
case 'f':
|
||||
{
|
||||
char * pStr = NULL, * pStr2;
|
||||
int iSize, iExtra, iD;
|
||||
|
||||
if( HB_IS_NUMERIC( pItem ) )
|
||||
{
|
||||
hb_itemGetNLen( pItem, &iSize, &iD );
|
||||
|
||||
if( iDec != -1 )
|
||||
{
|
||||
iSize += iDec - iD + 1;
|
||||
iD = iDec;
|
||||
}
|
||||
|
||||
/* Let 255 be a limit for number length */
|
||||
if( iSize > 255 )
|
||||
iSize = 255;
|
||||
if( iD > 253 )
|
||||
iD = 253;
|
||||
if( iSize < iD + 2 )
|
||||
iSize = iD + 2;
|
||||
|
||||
pStr2 = pStr = ( char * ) hb_xgrab( iSize + 1 );
|
||||
hb_itemStrBuf( pStr, pItem, iSize, iD );
|
||||
|
||||
if( pStr[ 0 ] == '*' && iSize < 255 )
|
||||
{
|
||||
pStr2 = pStr = ( char * ) hb_xrealloc( pStr, 256 );
|
||||
hb_itemStrBuf( pStr, pItem, 255, iD );
|
||||
}
|
||||
while( *pStr2 == ' ' )
|
||||
pStr2++;
|
||||
iSize = strlen( pStr2 );
|
||||
}
|
||||
else
|
||||
{
|
||||
iSize = 1;
|
||||
pStr2 = "0";
|
||||
}
|
||||
|
||||
iExtra = 0;
|
||||
if( ( fForceSign || fSpaceSign ) && *pStr2 != '-' )
|
||||
iExtra = 1;
|
||||
|
||||
if( fLeftAlign )
|
||||
{
|
||||
/* Zero padding is ignored on left Align */
|
||||
if( *pStr2 != '-' )
|
||||
{
|
||||
/* ForceSign has priority over SpaceSign */
|
||||
if( fForceSign )
|
||||
bufadd( &buffer, "+", 1 );
|
||||
else
|
||||
{
|
||||
if( fSpaceSign )
|
||||
bufadd( &buffer, " ", 1 );
|
||||
}
|
||||
}
|
||||
bufadd( &buffer, pStr2, ( ULONG ) iSize );
|
||||
for( i = iSize + iExtra; i < iWidth; i++ )
|
||||
bufadd( &buffer, " ", 1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Right align */
|
||||
if( fPadZero )
|
||||
{
|
||||
if( *pStr2 == '-' )
|
||||
{
|
||||
bufadd( &buffer, pStr2++, 1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* ForceSign has priority over SpaceSign */
|
||||
if( fForceSign )
|
||||
bufadd( &buffer, "+", 1 );
|
||||
else
|
||||
{
|
||||
if( fSpaceSign )
|
||||
bufadd( &buffer, " ", 1 );
|
||||
}
|
||||
}
|
||||
for( i = iSize + iExtra; i < iWidth; i++ )
|
||||
bufadd( &buffer, "0", 1 );
|
||||
|
||||
bufadd( &buffer, pStr2, strlen( pStr2 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
for( i = iSize + iExtra; i < iWidth; i++ )
|
||||
bufadd( &buffer, " ", 1 );
|
||||
|
||||
if( *pStr2 != '-' )
|
||||
{
|
||||
/* ForceSign has priority over SpaceSign */
|
||||
if( fForceSign )
|
||||
bufadd( &buffer, "+", 1 );
|
||||
else
|
||||
{
|
||||
if( fSpaceSign )
|
||||
bufadd( &buffer, " ", 1 );
|
||||
}
|
||||
}
|
||||
bufadd( &buffer, pStr2, ( ULONG ) iSize );
|
||||
}
|
||||
}
|
||||
|
||||
if( pStr )
|
||||
hb_xfree( pStr );
|
||||
break;
|
||||
}
|
||||
|
||||
case 's':
|
||||
{
|
||||
char * pStr = hb_itemGetCPtr( pItem );
|
||||
|
||||
ulSize = hb_itemGetCLen( pItem );
|
||||
if( fLeftAlign )
|
||||
bufadd( &buffer, pStr, ulSize );
|
||||
|
||||
if( iWidth > 1 )
|
||||
{
|
||||
for( i = ( int ) ulSize; i < iWidth; i++ )
|
||||
bufadd( &buffer, " ", 1 );
|
||||
}
|
||||
|
||||
if( ! fLeftAlign )
|
||||
bufadd( &buffer, pStr, ulSize );
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
bufadd( &buffer, pFmtSave, pFmt - pFmtSave + 1 );
|
||||
}
|
||||
pFmt++;
|
||||
}
|
||||
|
||||
pItemReturn = hb_itemPutCL( pItemReturn, buffer.pData, buffer.ulLen );
|
||||
hb_xfree( buffer.pData );
|
||||
return pItemReturn;
|
||||
}
|
||||
|
||||
HB_FUNC( HB_STRFORMAT )
|
||||
{
|
||||
PHB_ITEM pFormat = hb_param( 1, HB_IT_STRING );
|
||||
int i, iParams = hb_pcount();
|
||||
PHB_ITEM * pItemArray = NULL;
|
||||
|
||||
if( pFormat )
|
||||
{
|
||||
if( iParams > 1 )
|
||||
{
|
||||
pItemArray = ( PHB_ITEM * ) hb_xgrab( ( iParams - 1 ) * sizeof( PHB_ITEM ) );
|
||||
for( i = 1; i < iParams; i++ )
|
||||
pItemArray[ i - 1 ] = hb_param( i + 1, HB_IT_ANY );
|
||||
}
|
||||
|
||||
hb_itemReturnRelease( hb_StrFormat( NULL, pFormat, iParams - 1, pItemArray ) );
|
||||
|
||||
if( iParams > 1 )
|
||||
hb_xfree( pItemArray );
|
||||
}
|
||||
else
|
||||
hb_errRT_BASE_SubstR( EG_ARG, 1099, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
|
||||
}
|
||||
@@ -784,7 +784,7 @@ FUNCTION Main( ... )
|
||||
|
||||
cParam := ArchCompFilter( SubStr( cParam, 3 ) )
|
||||
IF ! Empty( cParam )
|
||||
AAdd( s_aLIBUSER, PathSepToTarget( PathProc( cParam, aParam[ _PAR_cFileName ] ) ) )
|
||||
AAdd( s_aLIBUSER, PathSepToTarget( cParam ) )
|
||||
ENDIF
|
||||
|
||||
CASE FN_ExtGet( cParamL ) == ".lib" .OR. ;
|
||||
@@ -792,7 +792,7 @@ FUNCTION Main( ... )
|
||||
|
||||
cParam := ArchCompFilter( cParam )
|
||||
IF ! Empty( cParam )
|
||||
AAdd( s_aLIBUSER, PathSepToTarget( PathProc( cParam, aParam[ _PAR_cFileName ] ) ) )
|
||||
AAdd( s_aLIBUSER, PathSepToTarget( cParam ) )
|
||||
ENDIF
|
||||
|
||||
CASE Left( cParam, 1 ) == "-"
|
||||
@@ -2514,14 +2514,14 @@ STATIC PROCEDURE HBM_Load( aParams, cFileName, /* @ */ nEmbedLevel )
|
||||
IF ! Empty( cParam )
|
||||
DO CASE
|
||||
CASE ( Len( cParam ) >= 1 .AND. Left( cParam, 1 ) == "@" )
|
||||
IF !( SubStr( cParam, 2 ) == cFileName ) .AND. nEmbedLevel < 3
|
||||
IF nEmbedLevel < 3
|
||||
nEmbedLevel++
|
||||
HBM_Load( aParams, SubStr( cParam, 2 ), @nEmbedLevel ) /* Load parameters from script file */
|
||||
HBM_Load( aParams, PathProc( SubStr( cParam, 2 ), cFileName ), @nEmbedLevel ) /* Load parameters from script file */
|
||||
ENDIF
|
||||
CASE Lower( FN_ExtGet( cParam ) ) == ".hbm"
|
||||
IF !( cParam == cFileName ) .AND. nEmbedLevel < 3
|
||||
IF nEmbedLevel < 3
|
||||
nEmbedLevel++
|
||||
HBM_Load( aParams, cParam, @nEmbedLevel ) /* Load parameters from script file */
|
||||
HBM_Load( aParams, PathProc( cParam, cFileName ), @nEmbedLevel ) /* Load parameters from script file */
|
||||
ENDIF
|
||||
OTHERWISE
|
||||
AAdd( aParams, { cParam, cFileName, cLine:__enumIndex() } )
|
||||
|
||||
Reference in New Issue
Block a user