19991115-17:21 GMT+1 Victor Szel <info@szelvesz.hu>
This commit is contained in:
@@ -1,3 +1,45 @@
|
||||
19991115-17:21 GMT+1 Victor Szel <info@szelvesz.hu>
|
||||
* source/rtl/transfrm.c
|
||||
! Direct item access changed to Item API calls.
|
||||
% Optimized variable scopes.
|
||||
% Optimized redundant code.
|
||||
% Extend API calls changed to Item API.
|
||||
! Error substitution added.
|
||||
! Direct item access buffer fixed (with picture "@!")
|
||||
! Fixed to accept picture mask characters in lowercase (like in Clipper)
|
||||
! Fixed the interpretation of some mask characters for string expressions.
|
||||
! Fixed handling of "Y" mask for strings.
|
||||
! Fixed handling of @R for strings.
|
||||
! Fixed case when the picture template is wider than the string expression.
|
||||
! Fixed handling of @Z and @B for all types.
|
||||
+ Added support for @D, @DE for strings.
|
||||
+ Other enhancements.
|
||||
* tests/rtl_test.prg
|
||||
+ New TRANSFORM() tests for special and error conditions added. Some of
|
||||
these still fail.
|
||||
! Fixed one SPACE() test.
|
||||
* include/extend.h
|
||||
! ISNIL() macro was not working, fixed. It was only used in TRANSFORM().
|
||||
* source/vm/hvm.c
|
||||
! Mistyped STRICT_CLIPPER_COMP. macro name fixed.
|
||||
* source/rtl/filesys.c
|
||||
! FREAD() is now always strictly compatible, option removed.
|
||||
* include/simpleio.ch
|
||||
include/assert.ch
|
||||
! Made platform independent using hb_OSNewLine() instead of the hard-
|
||||
wired Chr(13)+Chr(10) newlines.
|
||||
* include/box.ch
|
||||
* Formatting.
|
||||
* include/error.ch
|
||||
- EG_ARGCOUNT removed.
|
||||
* include/fileio.ch
|
||||
* The hexa numbers changed to decimals for better cross compiler
|
||||
compatibility, plus some minor cleanups.
|
||||
* include/hbclip.ch
|
||||
include/clipdefs.h
|
||||
include/compiler.h
|
||||
* Minor changes.
|
||||
|
||||
19991113-13:49 GMT+1 Victor Szel <info@szelvesz.hu>
|
||||
* source/rtl/arrays.c
|
||||
source/rtl/console.c
|
||||
|
||||
@@ -45,16 +45,17 @@
|
||||
#else
|
||||
|
||||
#command ASSERT( <exp> [, <msg>] ) => ;
|
||||
IF ( !(<exp>) ) ;
|
||||
; OUTSTD( ;
|
||||
CHR(13) + CHR(10) + PROCNAME(0) + ;
|
||||
"(" + LTRIM(STR(PROCLINE())) + ")" + ;
|
||||
" Assertion failed: " + ;
|
||||
IF( <.msg.>, <msg>, <"exp"> ) ;
|
||||
) ;
|
||||
; QUIT ;
|
||||
IF !(<exp>) ;
|
||||
; OutStd( ;
|
||||
hb_OSNewLine() + ProcName( 0 ) + ;
|
||||
"(" + LTrim( Str( ProcLine() ) ) + ")" + ;
|
||||
" Assertion failed: " + ;
|
||||
iif( <.msg.>, <msg>, <"exp"> ) ;
|
||||
) ;
|
||||
; QUIT ;
|
||||
; ENDIF
|
||||
|
||||
#endif /* NDEBUG */
|
||||
|
||||
#endif /* HB_ASSERT_CH_ */
|
||||
|
||||
|
||||
@@ -39,25 +39,26 @@
|
||||
/* #defines for DISPBOX() */
|
||||
|
||||
/* Single-line */
|
||||
#define B_SINGLE ( Chr(218) + Chr(196) + Chr(191) + Chr(179) + ;
|
||||
Chr(217) + Chr(196) + Chr(192) + Chr(179) )
|
||||
#define B_SINGLE ( Chr( 218 ) + Chr( 196 ) + Chr( 191 ) + Chr( 179 ) + ;
|
||||
Chr( 217 ) + Chr( 196 ) + Chr( 192 ) + Chr( 179 ) )
|
||||
|
||||
/* Double-line */
|
||||
#define B_DOUBLE ( Chr(201) + Chr(205) + Chr(187) + Chr(186) + ;
|
||||
Chr(188) + Chr(205) + Chr(200) + Chr(186) )
|
||||
#define B_DOUBLE ( Chr( 201 ) + Chr( 205 ) + Chr( 187 ) + Chr( 186 ) + ;
|
||||
Chr( 188 ) + Chr( 205 ) + Chr( 200 ) + Chr( 186 ) )
|
||||
|
||||
/* Single-line top, double-line sides */
|
||||
#define B_SINGLE_DOUBLE ( Chr(214) + Chr(196) + Chr(183) + Chr(186) + ;
|
||||
Chr(189) + Chr(196) + Chr(211) + Chr(186) )
|
||||
#define B_SINGLE_DOUBLE ( Chr( 214 ) + Chr( 196 ) + Chr( 183 ) + Chr( 186 ) + ;
|
||||
Chr( 189 ) + Chr( 196 ) + Chr( 211 ) + Chr( 186 ) )
|
||||
|
||||
/* Double-line top, single-line sides */
|
||||
#define B_DOUBLE_SINGLE ( Chr(213) + Chr(205) + Chr(184) + Chr(179) + ;
|
||||
Chr(190) + Chr(205) + Chr(212) + Chr(179) )
|
||||
#define B_DOUBLE_SINGLE ( Chr( 213 ) + Chr( 205 ) + Chr( 184 ) + Chr( 179 ) + ;
|
||||
Chr( 190 ) + Chr( 205 ) + Chr( 212 ) + Chr( 179 ) )
|
||||
|
||||
#define B_THIN ( Chr(219) + Chr(223) + Chr(219) + Chr(219) + ;
|
||||
Chr(219) + Chr(220) + Chr(219) + Chr(219) )
|
||||
#define B_THIN ( Chr( 219 ) + Chr( 223 ) + Chr( 219 ) + Chr( 219 ) + ;
|
||||
Chr( 219 ) + Chr( 220 ) + Chr( 219 ) + Chr( 219 ) )
|
||||
|
||||
#define B_FAT ( Chr(219) + Chr(219) + Chr(219) + Chr(219) + ;
|
||||
Chr(219) + Chr(219) + Chr(219) + Chr(219) )
|
||||
#define B_FAT ( Chr( 219 ) + Chr( 219 ) + Chr( 219 ) + Chr( 219 ) + ;
|
||||
Chr( 219 ) + Chr( 219 ) + Chr( 219 ) + Chr( 219 ) )
|
||||
|
||||
#endif /* _BOX_CH */
|
||||
|
||||
|
||||
@@ -51,49 +51,49 @@ typedef BOOL Boolean;
|
||||
|
||||
/* New types */
|
||||
|
||||
typedef BYTE* BYTEP;
|
||||
typedef BYTE * BYTEP;
|
||||
typedef BYTEP PBYTE;
|
||||
typedef BYTEP BYTEPP;
|
||||
|
||||
typedef SHORT* SHORTP;
|
||||
typedef SHORT * SHORTP;
|
||||
typedef SHORTP PSHORT;
|
||||
|
||||
typedef USHORT* USHORTP;
|
||||
typedef USHORT * USHORTP;
|
||||
typedef USHORTP PUSHORT;
|
||||
|
||||
typedef unsigned int WORD;
|
||||
typedef WORD* WORDP;
|
||||
typedef WORD * WORDP;
|
||||
typedef WORDP PWORD;
|
||||
|
||||
typedef LONG* LONGP;
|
||||
typedef LONG * LONGP;
|
||||
typedef LONGP PLONG;
|
||||
|
||||
typedef ULONG* ULONGP;
|
||||
typedef ULONG * ULONGP;
|
||||
typedef ULONGP PULONG;
|
||||
|
||||
typedef unsigned long DWORD;
|
||||
typedef DWORD* DWORDP;
|
||||
typedef DWORD * DWORDP;
|
||||
typedef DWORDP PDWORD;
|
||||
|
||||
typedef BOOL* BOOLP;
|
||||
typedef BOOL * BOOLP;
|
||||
typedef BOOLP PBOOL;
|
||||
|
||||
typedef void* NEARP;
|
||||
typedef NEARP* NEARPP;
|
||||
typedef void * NEARP;
|
||||
typedef NEARP * NEARPP;
|
||||
|
||||
typedef void* FARP;
|
||||
typedef FARP* FARPP;
|
||||
typedef void * FARP;
|
||||
typedef FARP * FARPP;
|
||||
|
||||
typedef FARP VOIDP;
|
||||
typedef FARP PVOID;
|
||||
|
||||
typedef void* HANDLE;
|
||||
typedef void * HANDLE;
|
||||
typedef ERRCODE IHELP;
|
||||
typedef ERRCODE ICODE;
|
||||
|
||||
/* default func ptr -- USHORT return, USHORT param */
|
||||
typedef USHORT ( * FUNCP )( USHORT param, ...);
|
||||
typedef FUNCP* FUNCPP;
|
||||
typedef FUNCP * FUNCPP;
|
||||
|
||||
#define HIDE static
|
||||
#define CLIPPER HARBOUR
|
||||
|
||||
@@ -97,7 +97,7 @@ typedef struct
|
||||
} SYMBOLS;
|
||||
|
||||
extern PFUNCTION GetFunction( char * szFunName ); /* locates a previously defined function */
|
||||
extern USHORT GetFunctionPos( char * szSymbolName ); /* returns the index + 1 of a function on the functions defined list */
|
||||
extern USHORT GetFunctionPos( char * szSymbolName ); /* returns the index + 1 of a function on the functions defined list */
|
||||
|
||||
extern void * hb_xgrab( ULONG lSize ); /* allocates memory, exists on failure */
|
||||
extern void * hb_xrealloc( void * pMem, ULONG lSize ); /* reallocates memory */
|
||||
@@ -106,10 +106,6 @@ extern void hb_xfree( void * pMem ); /* frees memory */
|
||||
char * yy_strdup( char * p ); /* this will exit if there is not enough memory */
|
||||
char * yy_strupr( char * p );
|
||||
|
||||
#if 0
|
||||
static void __yy_memcpy( char * from, char * to, int count ); /* Bison prototype */
|
||||
#endif
|
||||
|
||||
extern USHORT FixSymbolPos( USHORT ); /* converts symbol's compile-time position into generation-time position */
|
||||
extern PFUNCTION GetFuncall( char * szFunName ); /* locates a previously defined called function */
|
||||
extern PVAR GetVar( PVAR pVars, USHORT wOrder ); /* returns a variable if defined or zero */
|
||||
@@ -126,7 +122,6 @@ extern BOOL _bQuiet;
|
||||
extern BOOL _bStartProc;
|
||||
extern char _szPrefix[ 20 ]; /* holds the prefix added to the generated symbol init function name (in C output currently) */
|
||||
extern BOOL _bGenCVerbose;
|
||||
|
||||
extern char * _szCErrors[];
|
||||
|
||||
#define VS_LOCAL 1
|
||||
@@ -137,14 +132,12 @@ extern char * _szCErrors[];
|
||||
#define VS_PUBLIC 128
|
||||
#define VS_MEMVAR ( VS_PUBLIC | VS_PRIVATE )
|
||||
|
||||
/*
|
||||
* flags for bFlags member
|
||||
*/
|
||||
#define FUN_STATEMENTS 1 /* Function have at least one executable statement */
|
||||
#define FUN_USES_STATICS 2 /* Function uses static variables */
|
||||
#define FUN_PROCEDURE 4 /* This is a procedure that shouldn't return value */
|
||||
#define FUN_ILLEGAL_INIT 8 /* Attempt to initialize static variable with a function call */
|
||||
#define FUN_USES_LOCAL_PARAMS 16 /* parameters are declared using () */
|
||||
#define FUN_WITH_RETURN 32 /* there was RETURN statement in previous line */
|
||||
/* flags for bFlags member */
|
||||
#define FUN_STATEMENTS 1 /* Function have at least one executable statement */
|
||||
#define FUN_USES_STATICS 2 /* Function uses static variables */
|
||||
#define FUN_PROCEDURE 4 /* This is a procedure that shouldn't return value */
|
||||
#define FUN_ILLEGAL_INIT 8 /* Attempt to initialize static variable with a function call */
|
||||
#define FUN_USES_LOCAL_PARAMS 16 /* parameters are declared using () */
|
||||
#define FUN_WITH_RETURN 32 /* there was RETURN statement in previous line */
|
||||
|
||||
#endif /* HB_COMPILER_H_ */
|
||||
|
||||
@@ -84,7 +84,6 @@
|
||||
#define EG_APPENDLOCK 40
|
||||
#define EG_LOCK 41
|
||||
|
||||
#define EG_ARGCOUNT 45 /* Harbour special */
|
||||
#define EG_ARRACCESS 46 /* Harbour special */
|
||||
#define EG_ARRASSIGN 47 /* Harbour special */
|
||||
#define EG_ARRDIMENSION 48 /* Harbour special */
|
||||
|
||||
@@ -75,7 +75,7 @@
|
||||
#define IS_SYMBOL( p ) IS_OF_TYPE( p, IT_SYMBOL )
|
||||
#define IS_MEMVAR( p ) IS_OF_TYPE( p, IT_MEMVAR )
|
||||
|
||||
#define ISNIL( n ) ( hb_param( n, IT_NIL ) != NULL )
|
||||
#define ISNIL( n ) ( IS_NIL( hb_param( n, IT_ANY ) ) )
|
||||
#define ISCHAR( n ) ( hb_param( n, IT_STRING ) != NULL )
|
||||
#define ISNUM( n ) ( hb_param( n, IT_NUMERIC ) != NULL )
|
||||
#define ISLOG( n ) ( hb_param( n, IT_LOGICAL ) != NULL )
|
||||
|
||||
@@ -52,35 +52,35 @@
|
||||
#define _FILEIO_CH
|
||||
|
||||
/* File create flags */
|
||||
#define FC_NORMAL 0x0000 /* No file attributes are set */
|
||||
#define FC_READONLY 0x0001 /* Read-only file attribute is set */
|
||||
#define FC_HIDDEN 0x0002 /* Hidden file attribute is set */
|
||||
#define FC_SYSTEM 0x0004 /* System file attribute is set */
|
||||
#define FC_NORMAL 0 /* No file attributes are set */
|
||||
#define FC_READONLY 1 /* Read-only file attribute is set */
|
||||
#define FC_HIDDEN 2 /* Hidden file attribute is set */
|
||||
#define FC_SYSTEM 4 /* System file attribute is set */
|
||||
|
||||
/* File access flags */
|
||||
#define FO_READ 0x0000 /* File is opened for reading */
|
||||
#define FO_WRITE 0x0001 /* File is opened for writing */
|
||||
#define FO_READWRITE 0x0002 /* File is opened for reading and writing */
|
||||
#define FO_READ 0 /* File is opened for reading */
|
||||
#define FO_WRITE 1 /* File is opened for writing */
|
||||
#define FO_READWRITE 2 /* File is opened for reading and writing */
|
||||
|
||||
/* File sharing flags */
|
||||
#define FO_COMPAT 0x0000 /* No sharing specified */
|
||||
#define FO_EXCLUSIVE 0x0010 /* Deny further attempts to open the file */
|
||||
#define FO_DENYWRITE 0x0020 /* Deny further attempts to open the file for writing */
|
||||
#define FO_DENYREAD 0x0030 /* Deny further attempts to open the file for reading */
|
||||
#define FO_DENYNONE 0x0040 /* Do not deny any further attempts to open the file */
|
||||
#define FO_COMPAT 0 /* No sharing specified */
|
||||
#define FO_EXCLUSIVE 16 /* Deny further attempts to open the file */
|
||||
#define FO_DENYWRITE 32 /* Deny further attempts to open the file for writing */
|
||||
#define FO_DENYREAD 48 /* Deny further attempts to open the file for reading */
|
||||
#define FO_DENYNONE 64 /* Do not deny any further attempts to open the file */
|
||||
#define FO_SHARED FO_DENYNONE
|
||||
|
||||
/* File seek mode flags */
|
||||
#define FS_SET 0x0000 /* Seek from beginning of file */
|
||||
#define FS_RELATIVE 0x0001 /* Seek from current file poitner */
|
||||
#define FS_END 0x0002 /* Seek from end of file */
|
||||
#define FS_SET 0 /* Seek from beginning of file */
|
||||
#define FS_RELATIVE 1 /* Seek from current file poitner */
|
||||
#define FS_END 2 /* Seek from end of file */
|
||||
|
||||
/* File mode flags */
|
||||
#define FD_BINARY 1 /* Binary mode (raw) */
|
||||
#define FD_RAW 1
|
||||
#define FD_RAW FD_BINARY
|
||||
#define FD_TEXT 2 /* Text mode (cooked) */
|
||||
#define FD_COOKED 2
|
||||
#define FD_ASCII 2
|
||||
#define FD_COOKED FD_TEXT
|
||||
#define FD_ASCII FD_TEXT
|
||||
|
||||
/* File system error codes */
|
||||
#define F_ERROR ( -1 ) /* Unspecified error */
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
#ifndef HB_CLIP_CH_
|
||||
#define HB_CLIP_CH_
|
||||
|
||||
#xtranslate hb_OSNewLine() => Chr( 13 ) + Chr( 10 )
|
||||
#xtranslate hb_OSNewLine() => ( Chr( 13 ) + Chr( 10 ) )
|
||||
|
||||
#endif /* HB_CLIP_CH_ */
|
||||
|
||||
|
||||
@@ -37,13 +37,13 @@
|
||||
#define _SIMPLEIO_CH
|
||||
|
||||
#command ? [ <xList,...> ] => ;
|
||||
( OutStd( Chr(13) + Chr(10) ) [, OutStd(<xList>)] )
|
||||
( OutStd( hb_OSNewLine() ) [, OutStd(<xList>)] )
|
||||
|
||||
#command ?? [ <xList,...> ] => ;
|
||||
OutStd( <xList> )
|
||||
|
||||
#command ACCEPT TO <idVar> => ;
|
||||
<idVar> := StrTran( FReadStr(0, 256), Chr(13) + Chr(10) )
|
||||
<idVar> := StrTran( FReadStr( 0, 256 ), hb_OSNewLine() )
|
||||
|
||||
#command ACCEPT <cPrompt> TO <idVar> => ;
|
||||
? <cPrompt> ; ACCEPT TO <idVar>
|
||||
|
||||
@@ -1328,24 +1328,17 @@ HARBOUR HB_FREAD( void )
|
||||
{
|
||||
ulRead = hb_parnl( 3 );
|
||||
|
||||
#ifdef HARBOUR_STRICT_CLIPPER_COMPATIBILITY
|
||||
/* CA-Clipper determines the maximum size by calling _parcsiz() instead */
|
||||
/* of hb_parclen(), this means that the maximum read length will be one */
|
||||
/* more then the length of the passed buffer, because the terminating */
|
||||
/* zero could be used if needed */
|
||||
/* NOTE: CA-Clipper determines the maximum size by calling _parcsiz() */
|
||||
/* instead of hb_parclen(), this means that the maximum read length */
|
||||
/* will be one more then the length of the passed buffer, because */
|
||||
/* the terminating zero could be used if needed. [vszel] */
|
||||
|
||||
if( ulRead <= hb_parcsiz( 2 ) )
|
||||
#else
|
||||
if( ulRead <= hb_parclen( 2 ) )
|
||||
#endif
|
||||
{
|
||||
/* NOTE: Warning, the read buffer will be directly modified,
|
||||
this is normal here ! [vszel] */
|
||||
|
||||
ulRead = hb_fsReadLarge( hb_parni( 1 ),
|
||||
( BYTE * ) hb_parc( 2 ),
|
||||
ulRead );
|
||||
}
|
||||
else
|
||||
ulRead = 0;
|
||||
}
|
||||
|
||||
@@ -45,26 +45,18 @@
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#include "extend.h"
|
||||
#include "itemapi.h"
|
||||
#include "errorapi.h"
|
||||
#include "dates.h"
|
||||
#include "set.h"
|
||||
|
||||
/* */
|
||||
/* Transform( xValue, cPicture ) */
|
||||
/* */
|
||||
/* Date : 29/04/1999 */
|
||||
/* */
|
||||
|
||||
/* Function flags */
|
||||
|
||||
/* Picture function flags */
|
||||
#define PF_LEFT 0x0001 /* @B */
|
||||
#define PF_CREDIT 0x0002 /* @C */
|
||||
#define PF_DEBIT 0x0004 /* @X */
|
||||
#ifndef HARBOUR_STRICT_CLIPPER_COMPATIBILITY
|
||||
#define PF_ZERO 0x0008 /* @0 */
|
||||
#endif
|
||||
#define PF_ZERO 0x0008 /* @0 */ /* NOTE: This is a Harbour extension [vszel] */
|
||||
#define PF_PARNEG 0x0010 /* @( */
|
||||
#define PF_REMAIN 0x0020 /* @R */
|
||||
#define PF_UPPER 0x0040 /* @! */
|
||||
@@ -72,101 +64,106 @@
|
||||
#define PF_BRITISH 0x0100 /* @E */
|
||||
#define PF_EXCHANG 0x0100 /* @E. Also means exchange . and , */
|
||||
#define PF_EMPTY 0x0200 /* @Z */
|
||||
#define PF_NUMDATE 0x0400 /* Internal flag. Ignore decimal dot */
|
||||
|
||||
/* Date settings */
|
||||
|
||||
#define DF_CENTOFF 0
|
||||
#define DF_CENTURY 1
|
||||
|
||||
#define DF_DMY 0
|
||||
#define DF_MDY 1
|
||||
#define DF_YMD 2
|
||||
#define DF_EOT 3 /* End of table for Century */
|
||||
#define PF_NUMDATE 0x0400 /* Internal flag. Ignore decimal dot */
|
||||
|
||||
/*
|
||||
PictFunc -> Analyze function flags and return binary flags bits
|
||||
|
||||
szPict : Pointer to the picture
|
||||
ulPicLen : Pointer to the length. Changed during execution.
|
||||
pszPic : Pointer to the picture
|
||||
pulPicLen : Pointer to the length. Changed during execution.
|
||||
pulPicStart : Pointer to the starting position of the picture template.
|
||||
*/
|
||||
static USHORT PictFunc( char ** szPict, ULONG * pulPicLen )
|
||||
static USHORT PictFunc( char ** pszPic, ULONG * pulPicLen, ULONG * pulPicStart )
|
||||
{
|
||||
BOOL bDone = FALSE;
|
||||
USHORT uiPicFlags = 0;
|
||||
ULONG ulPicLen = *pulPicLen;
|
||||
|
||||
char * szPic = *szPict;
|
||||
HB_TRACE(HB_TR_DEBUG, ("PictFunc(%p, %p)", pszPic, pulPicLen));
|
||||
|
||||
HB_TRACE(HB_TR_DEBUG, ("PictFunc(%p, %p)", szPict, pulPicLen));
|
||||
/* If an "@" char is at the first pos, we have picture function */
|
||||
|
||||
szPic++;
|
||||
( *pulPicLen )--;
|
||||
while( *pulPicLen && ! bDone )
|
||||
if( **pszPic == '@' )
|
||||
{
|
||||
switch( toupper( *szPic ) )
|
||||
{
|
||||
case ' ': /* End of function string */
|
||||
bDone = TRUE;
|
||||
break;
|
||||
case '!':
|
||||
uiPicFlags |= PF_UPPER;
|
||||
break;
|
||||
case '(':
|
||||
uiPicFlags |= PF_PARNEG;
|
||||
break;
|
||||
#ifndef HARBOUR_STRICT_CLIPPER_COMPATIBILITY
|
||||
case '0':
|
||||
uiPicFlags |= PF_ZERO;
|
||||
break;
|
||||
#endif
|
||||
case 'B':
|
||||
uiPicFlags |= PF_LEFT;
|
||||
break;
|
||||
case 'C':
|
||||
uiPicFlags |= PF_CREDIT;
|
||||
break;
|
||||
case 'D':
|
||||
uiPicFlags |= PF_DATE;
|
||||
break;
|
||||
case 'E':
|
||||
uiPicFlags |= PF_BRITISH;
|
||||
break;
|
||||
case 'R':
|
||||
uiPicFlags |= PF_REMAIN;
|
||||
break;
|
||||
case 'X':
|
||||
uiPicFlags |= PF_DEBIT;
|
||||
break;
|
||||
case 'Z':
|
||||
uiPicFlags |= PF_EMPTY;
|
||||
break;
|
||||
}
|
||||
szPic++;
|
||||
/* Skip the "@" char */
|
||||
|
||||
( *pszPic )++;
|
||||
( *pulPicLen )--;
|
||||
|
||||
/* Go through all function chars, until the end of the picture string
|
||||
or any whitespace found. */
|
||||
|
||||
while( *pulPicLen && ! bDone )
|
||||
{
|
||||
switch( toupper( **pszPic ) )
|
||||
{
|
||||
case HB_CHAR_HT:
|
||||
case ' ':
|
||||
bDone = TRUE; /* End of function string */
|
||||
break;
|
||||
case '!':
|
||||
uiPicFlags |= PF_UPPER;
|
||||
break;
|
||||
case '(':
|
||||
uiPicFlags |= PF_PARNEG;
|
||||
break;
|
||||
case '0':
|
||||
uiPicFlags |= PF_ZERO;
|
||||
break;
|
||||
case 'B':
|
||||
uiPicFlags |= PF_LEFT;
|
||||
break;
|
||||
case 'C':
|
||||
uiPicFlags |= PF_CREDIT;
|
||||
break;
|
||||
case 'D':
|
||||
uiPicFlags |= PF_DATE;
|
||||
break;
|
||||
case 'E':
|
||||
uiPicFlags |= PF_BRITISH;
|
||||
break;
|
||||
case 'R':
|
||||
uiPicFlags |= PF_REMAIN;
|
||||
break;
|
||||
case 'X':
|
||||
uiPicFlags |= PF_DEBIT;
|
||||
break;
|
||||
case 'Z':
|
||||
uiPicFlags |= PF_EMPTY;
|
||||
break;
|
||||
}
|
||||
|
||||
( *pszPic )++;
|
||||
( *pulPicLen )--;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get start pos of template */
|
||||
*pulPicStart = ulPicLen - *pulPicLen;
|
||||
|
||||
return uiPicFlags;
|
||||
}
|
||||
|
||||
/*
|
||||
NumPicture -> Handle a numeric picture.
|
||||
NumPicture -> Handle a numeric picture.
|
||||
|
||||
szPic : Picture
|
||||
lPic : Length of picture
|
||||
uiPicFlags : Function flags. NUM_DATE tells whether its a number or date
|
||||
dValue : Number to picture
|
||||
lRetSize : The size of the returned string is passed here !
|
||||
iOrigWidth : Original width
|
||||
iOrigDec : Original decimals
|
||||
szPic : Picture
|
||||
ulPicLen : Length of picture
|
||||
puiPicFlags : Function flags. NUM_DATE tells whether its a number or date
|
||||
dValue : Number to picture
|
||||
pulResultLen : The size of the returned string is passed here !
|
||||
iOrigWidth : Original width
|
||||
iOrigDec : Original decimals
|
||||
*/
|
||||
static char * NumPicture( char * szPic, ULONG ulPic, USHORT uiPicFlags, double dValue,
|
||||
ULONG * pulRetSize, int iOrigWidth, int iOrigDec )
|
||||
static char * NumPicture( char * szPic, ULONG ulPicLen, USHORT * puiPicFlags, double dValue,
|
||||
ULONG * pulResultLen, int iOrigWidth, int iOrigDec )
|
||||
{
|
||||
int iWidth; /* Width of string */
|
||||
int iDec; /* Number of decimals */
|
||||
ULONG i;
|
||||
int iCount = 0;
|
||||
|
||||
char * szRet;
|
||||
char * szResult;
|
||||
char * szStr;
|
||||
char cPic;
|
||||
|
||||
@@ -175,15 +172,15 @@ static char * NumPicture( char * szPic, ULONG ulPic, USHORT uiPicFlags, double d
|
||||
PHB_ITEM pDec;
|
||||
|
||||
BOOL bFound = FALSE;
|
||||
BOOL bEmpty; /* Suppress empty string */
|
||||
|
||||
USHORT uiPicFlags = *puiPicFlags;
|
||||
double dPush;
|
||||
|
||||
HB_TRACE(HB_TR_DEBUG, ("NumPicture(%s, %lu, %hu, %lf)", szPic, ulPic, uiPicFlags, dValue));
|
||||
HB_TRACE(HB_TR_DEBUG, ("NumPicture(%s, %lu, %p, %lf)", szPic, ulPicLen, puiPicFlags, dValue));
|
||||
|
||||
szRet = ( char * ) hb_xgrab( ulPic + 4 ); /* Grab enough */
|
||||
*szRet = '\0';
|
||||
for( i = 0; i < ulPic && !bFound; i++ ) /* Count number in front */
|
||||
szResult = ( char * ) hb_xgrab( ulPicLen + 4 ); /* Grab enough */
|
||||
*szResult = '\0';
|
||||
for( i = 0; i < ulPicLen && !bFound; i++ ) /* Count number in front */
|
||||
{
|
||||
if( szPic[ i ] == '.' )
|
||||
bFound = !( uiPicFlags & PF_NUMDATE ); /* Exit when numeric */
|
||||
@@ -197,10 +194,12 @@ static char * NumPicture( char * szPic, ULONG ulPic, USHORT uiPicFlags, double d
|
||||
{
|
||||
iDec = 0;
|
||||
iWidth++; /* Also adjust iWidth */
|
||||
for( ; i < ulPic; i++ )
|
||||
for( ; i < ulPicLen; i++ )
|
||||
{
|
||||
if( szPic[ i ] == '9' || szPic[ i ] == '#' ||
|
||||
szPic[ i ] == '$' || szPic[ i ] == '*' )
|
||||
if( szPic[ i ] == '9' ||
|
||||
szPic[ i ] == '#' ||
|
||||
szPic[ i ] == '$' ||
|
||||
szPic[ i ] == '*' )
|
||||
{
|
||||
iWidth++;
|
||||
iDec++;
|
||||
@@ -215,7 +214,9 @@ static char * NumPicture( char * szPic, ULONG ulPic, USHORT uiPicFlags, double d
|
||||
else
|
||||
dPush = dValue;
|
||||
|
||||
bEmpty = !dPush && ( uiPicFlags & PF_EMPTY ); /* Suppress 0 */
|
||||
/* Don't empty the result if the number is not zero */
|
||||
if( dPush != 0 && ( uiPicFlags & PF_EMPTY ) )
|
||||
*puiPicFlags &= ~uiPicFlags;
|
||||
|
||||
if( !iWidth ) /* Width calculated ?? */
|
||||
{
|
||||
@@ -237,394 +238,371 @@ static char * NumPicture( char * szPic, ULONG ulPic, USHORT uiPicFlags, double d
|
||||
{
|
||||
iCount = 0;
|
||||
|
||||
#ifndef HARBOUR_STRICT_CLIPPER_COMPATIBILITY
|
||||
/* Pad with Zero's */
|
||||
if( uiPicFlags & PF_ZERO )
|
||||
{
|
||||
for( i = 0; szStr[ i ] == ' ' && i < iWidth; i++ )
|
||||
szStr[ i ] = '0';
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Suppress empty value */
|
||||
if( bEmpty && strlen( szStr ) > 0 )
|
||||
for( i = 0; i < ulPicLen; i++ )
|
||||
{
|
||||
szStr[ strlen( szStr ) - 1 ] = ' ';
|
||||
}
|
||||
|
||||
/* Left align */
|
||||
if( uiPicFlags & PF_LEFT )
|
||||
{
|
||||
for( i = 0; szStr[ i ] == ' ' && i <= iWidth; i++ );
|
||||
/* Find first non-space */
|
||||
|
||||
if( i && i != ( iWidth + 1 ) ) /* Any found or end of str */
|
||||
cPic = szPic[ i ];
|
||||
if( cPic == '9' || cPic == '#' )
|
||||
szResult[ i ] = szStr[ iCount++ ]; /* Just copy */
|
||||
else if( cPic == '.' )
|
||||
{
|
||||
memcpy( szStr, szStr + i, iWidth - i );
|
||||
for( i = iWidth - i; i < iWidth; i++ )
|
||||
szStr[ i ] = ' '; /* Pad with spaces */
|
||||
}
|
||||
}
|
||||
|
||||
/* TOFIX: iCount seem to always be zero at this point */
|
||||
|
||||
#if 0
|
||||
if( !iCount ) /* No real picture */
|
||||
{
|
||||
hb_xfree( szRet );
|
||||
szRet = ( char * ) hb_xgrab( iWidth + 1 );
|
||||
/* Grab enough */
|
||||
memcpy( szRet, szStr, iWidth );
|
||||
szRet[ iWidth ] = 0; /* Terminate string */
|
||||
}
|
||||
else
|
||||
{
|
||||
#endif
|
||||
for( i = 0; i < ulPic; i++ )
|
||||
{
|
||||
cPic = szPic[ i ];
|
||||
if( cPic == '9' || cPic == '#' )
|
||||
szRet[ i ] = szStr[ iCount++ ]; /* Just copy */
|
||||
else if( cPic == '.' )
|
||||
if( uiPicFlags & PF_NUMDATE ) /* Dot in date */
|
||||
szResult[ i ] = cPic;
|
||||
else /* Dot in number */
|
||||
{
|
||||
if( uiPicFlags & PF_NUMDATE ) /* Dot in date */
|
||||
szRet[ i ] = cPic;
|
||||
else /* Dot in number */
|
||||
if( uiPicFlags & PF_EXCHANG ) /* Exchange . and , */
|
||||
{
|
||||
if( uiPicFlags & PF_EXCHANG ) /* Exchange . and , */
|
||||
{
|
||||
szRet[ i ] = ',';
|
||||
iCount++;
|
||||
}
|
||||
else
|
||||
szRet[ i ] = szStr[ iCount++ ];
|
||||
}
|
||||
}
|
||||
else if( cPic == '$' || cPic == '*' )
|
||||
{
|
||||
if( szStr[ iCount ] == ' ' )
|
||||
{
|
||||
szRet[ i ] = cPic;
|
||||
szResult[ i ] = ',';
|
||||
iCount++;
|
||||
}
|
||||
else
|
||||
szRet[ i ] = szStr[ iCount++ ];
|
||||
szResult[ i ] = szStr[ iCount++ ];
|
||||
}
|
||||
else if( cPic == ',' ) /* Comma */
|
||||
}
|
||||
else if( cPic == '$' || cPic == '*' )
|
||||
{
|
||||
if( szStr[ iCount ] == ' ' )
|
||||
{
|
||||
if( iCount && isdigit( szStr[ iCount - 1 ] ) )
|
||||
{ /* May we place it */
|
||||
if( uiPicFlags & PF_EXCHANG )
|
||||
szRet[ i ] = '.';
|
||||
else
|
||||
szRet[ i ] = ',';
|
||||
}
|
||||
else
|
||||
szRet[ i ] = ' ';
|
||||
szResult[ i ] = cPic;
|
||||
iCount++;
|
||||
}
|
||||
else
|
||||
szRet[ i ] = cPic;
|
||||
szResult[ i ] = szStr[ iCount++ ];
|
||||
}
|
||||
#if 0
|
||||
}
|
||||
#endif
|
||||
if( ( uiPicFlags & PF_CREDIT ) && ( dValue >= 0 ) )
|
||||
{
|
||||
szRet[ i++ ] = ' ';
|
||||
szRet[ i++ ] = 'C';
|
||||
szRet[ i++ ] = 'R';
|
||||
}
|
||||
|
||||
if( ( uiPicFlags & PF_DEBIT ) && ( dValue < 0 ) )
|
||||
{
|
||||
szRet[ i++ ] = ' ';
|
||||
szRet[ i++ ] = 'D';
|
||||
szRet[ i++ ] = 'B';
|
||||
else if( cPic == ',' ) /* Comma */
|
||||
{
|
||||
if( iCount && isdigit( szStr[ iCount - 1 ] ) )
|
||||
{ /* May we place it */
|
||||
if( uiPicFlags & PF_EXCHANG )
|
||||
szResult[ i ] = '.';
|
||||
else
|
||||
szResult[ i ] = ',';
|
||||
}
|
||||
else
|
||||
szResult[ i ] = ' ';
|
||||
}
|
||||
else
|
||||
szResult[ i ] = cPic;
|
||||
}
|
||||
|
||||
if( ( uiPicFlags & PF_PARNEG ) && ( dValue < 0 ) )
|
||||
{
|
||||
if( isdigit( *szRet ) ) /* Overflow */
|
||||
if( isdigit( *szResult ) ) /* Overflow */
|
||||
{
|
||||
for( iCount = 1; iCount < i; iCount++ )
|
||||
{
|
||||
if( isdigit( szRet[ iCount ] ) )
|
||||
szRet[ iCount ] = '*';
|
||||
if( isdigit( szResult[ iCount ] ) )
|
||||
szResult[ iCount ] = '*';
|
||||
}
|
||||
}
|
||||
*szRet = '(';
|
||||
szRet[ i++ ] = ')';
|
||||
*szResult = '(';
|
||||
szResult[ i++ ] = ')';
|
||||
}
|
||||
|
||||
*pulRetSize = i;
|
||||
szRet[ i ] = '\0';
|
||||
if( ( uiPicFlags & PF_CREDIT ) && ( dValue >= 0 ) )
|
||||
{
|
||||
szResult[ i++ ] = ' ';
|
||||
szResult[ i++ ] = 'C';
|
||||
szResult[ i++ ] = 'R';
|
||||
}
|
||||
|
||||
if( ( uiPicFlags & PF_DEBIT ) && ( dValue < 0 ) )
|
||||
{
|
||||
szResult[ i++ ] = ' ';
|
||||
szResult[ i++ ] = 'D';
|
||||
szResult[ i++ ] = 'B';
|
||||
}
|
||||
|
||||
*pulResultLen = i;
|
||||
szResult[ i ] = '\0';
|
||||
|
||||
hb_xfree( szStr );
|
||||
}
|
||||
|
||||
return szRet;
|
||||
}
|
||||
|
||||
/*
|
||||
DatePicture -> Handle dates.
|
||||
|
||||
szDate : Date to handle
|
||||
uiPicFlags : Function flags
|
||||
szResult : Buffer of at least size 11 to hold formatted date
|
||||
*/
|
||||
static char * DatePicture( char * szDate, USHORT uiPicFlags, char * szResult )
|
||||
{
|
||||
HB_TRACE(HB_TR_DEBUG, ("DatePicture(%s, %hu, %s)", szDate, uiPicFlags, szResult));
|
||||
|
||||
if( uiPicFlags & PF_BRITISH )
|
||||
hb_dtoc( szDate, szResult, hb_set.hb_set_century ? "DD/MM/YYYY" : "DD/MM/YY" );
|
||||
else
|
||||
hb_dtoc( szDate, szResult, hb_set.HB_SET_DATEFORMAT );
|
||||
|
||||
return szResult;
|
||||
}
|
||||
|
||||
|
||||
HARBOUR HB_TRANSFORM( void )
|
||||
{
|
||||
PHB_ITEM pExp = hb_param( 1, IT_ANY ); /* Input parameter */
|
||||
PHB_ITEM pPic = hb_param( 2, IT_STRING ); /* Picture string */
|
||||
|
||||
if( ISCHAR( 2 ) && hb_parclen( 2 ) > 0 )
|
||||
BOOL bError = FALSE;
|
||||
|
||||
if( pPic && hb_itemGetCLen( pPic ) > 0 )
|
||||
{
|
||||
PHB_ITEM pPic = hb_param( 2, IT_STRING ); /* Picture string */
|
||||
char * szPic = hb_itemGetCPtr( pPic );
|
||||
ULONG ulPicLen = hb_itemGetCLen( pPic );
|
||||
ULONG ulPicStart; /* Start of template */
|
||||
USHORT uiPicFlags; /* Function flags */
|
||||
|
||||
char *szPic = pPic->item.asString.value;
|
||||
char *szTemp;
|
||||
char *szResult;
|
||||
char *szExp;
|
||||
char * szResult;
|
||||
ULONG ulResultPos;
|
||||
|
||||
ULONG ulPic = pPic->item.asString.length;
|
||||
ULONG ulPicStart = 0; /* Start of template */
|
||||
ULONG ulExpPos = 0;
|
||||
ULONG ulResultPos = 0;
|
||||
ULONG n;
|
||||
uiPicFlags = PictFunc( &szPic, &ulPicLen, &ulPicStart ); /* Evaluate picture string */
|
||||
|
||||
USHORT uiPicFlags = 0; /* Function flags */
|
||||
|
||||
if( *szPic == '@' ) /* Function marker found */
|
||||
if( IS_STRING( pExp ) )
|
||||
{
|
||||
uiPicFlags = PictFunc( &szPic, &ulPic ); /* Get length of function */
|
||||
ulPicStart = pPic->item.asString.length - ulPic;
|
||||
/* Get start of template */
|
||||
}
|
||||
char * szExp = hb_itemGetCPtr( pExp );
|
||||
ULONG ulExpLen = hb_itemGetCLen( pExp );
|
||||
ULONG ulExpPos = 0;
|
||||
|
||||
switch( pExp->type & ~IT_BYREF )
|
||||
{
|
||||
case IT_STRING:
|
||||
char szPicDate[ 11 ];
|
||||
BOOL bAnyPic = FALSE;
|
||||
|
||||
/* Grab enough */
|
||||
szResult = ( char * ) hb_xgrab( ulExpLen + ulPicLen );
|
||||
ulResultPos = 0;
|
||||
|
||||
/* Support date function for strings */
|
||||
if( uiPicFlags & PF_DATE )
|
||||
{
|
||||
szExp = pExp->item.asString.value;
|
||||
szResult = ( char * ) hb_xgrab( ( ( ulPic-ulPicStart ) >
|
||||
pExp->item.asString.length ) ?
|
||||
( ulPic - ulPicStart ) + 64 : pExp->item.asString.length + 64 );
|
||||
/* Grab enough */
|
||||
szPic += ulPicStart; /* Skip functions */
|
||||
hb_dtoc( "XXXXXXXX", szPicDate,
|
||||
( uiPicFlags & PF_BRITISH ) ?
|
||||
( hb_set.hb_set_century ? "DD/MM/YYYY" : "DD/MM/YY" ) :
|
||||
hb_set.HB_SET_DATEFORMAT );
|
||||
|
||||
if( uiPicFlags & PF_UPPER ) /* Function : @! */
|
||||
{
|
||||
szTemp = szExp; /* Convert to upper */
|
||||
for( n = pExp->item.asString.length; n != 0; n-- )
|
||||
{
|
||||
*szTemp = toupper( *szTemp );
|
||||
szTemp++;
|
||||
}
|
||||
}
|
||||
|
||||
if( ulPic ) /* Template string */
|
||||
{
|
||||
while( ulPic && ulExpPos < pExp->item.asString.length )
|
||||
{ /* Analyze picture mask */
|
||||
switch( *szPic )
|
||||
{
|
||||
case '!': /* Upper */
|
||||
{
|
||||
szResult[ ulResultPos++ ] = toupper( szExp[ ulExpPos++ ] );
|
||||
break;
|
||||
}
|
||||
case 'L': /* Ignored */
|
||||
case 'Y':
|
||||
case '*':
|
||||
case '$':
|
||||
case '.':
|
||||
case ',':
|
||||
break;
|
||||
|
||||
case '#': /* Out the character */
|
||||
case '9':
|
||||
case 'A':
|
||||
case 'N':
|
||||
case 'X':
|
||||
case ' ':
|
||||
{
|
||||
szResult[ ulResultPos++ ] = szExp[ ulExpPos++ ];
|
||||
break;
|
||||
}
|
||||
|
||||
default: /* Other choices */
|
||||
{
|
||||
szResult[ ulResultPos++ ] = *szPic;
|
||||
ulExpPos++;
|
||||
}
|
||||
}
|
||||
szPic++;
|
||||
ulPic--;
|
||||
}
|
||||
}
|
||||
else if( uiPicFlags & ( PF_UPPER + PF_REMAIN ) )
|
||||
{ /* Without template */
|
||||
for( n = pExp->item.asString.length; n != 0; n-- )
|
||||
szResult[ ulResultPos++ ] = *szExp++;
|
||||
}
|
||||
|
||||
if( ( uiPicFlags & PF_REMAIN ) && ulPic )
|
||||
{ /* Any chars left */
|
||||
for( n = ulPic; n != 0; n-- )
|
||||
szResult[ ulResultPos++ ] = *szPic;
|
||||
/* Export remainder */
|
||||
}
|
||||
hb_retclen( szResult, ulResultPos );
|
||||
hb_xfree( szResult );
|
||||
break;
|
||||
szPic = szPicDate;
|
||||
ulPicLen = strlen( szPicDate );
|
||||
ulPicStart = 0;
|
||||
}
|
||||
|
||||
case IT_LOGICAL:
|
||||
/* Template string */
|
||||
if( ulPicLen )
|
||||
{
|
||||
BOOL bDone = FALSE;
|
||||
|
||||
szResult = ( char * ) hb_xgrab( ulPic + 1 );
|
||||
/* That's all folks */
|
||||
szPic += ulPicStart; /* Skip functions */
|
||||
ulResultPos = 1;
|
||||
|
||||
if( ulPic ) /* Template string */
|
||||
while( ulPicLen && ulExpPos < ulExpLen ) /* Analyze picture mask */
|
||||
{
|
||||
switch( *szPic )
|
||||
{
|
||||
case 'Y': /* Yes/No */
|
||||
/* Upper */
|
||||
case '!':
|
||||
{
|
||||
*szResult = pExp->item.asLogical.value ? 'Y' : 'N';
|
||||
szPic++;
|
||||
ulPic--;
|
||||
bDone = TRUE; /* Logical written */
|
||||
szResult[ ulResultPos++ ] = toupper( szExp[ ulExpPos++ ] );
|
||||
bAnyPic = TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Out the character */
|
||||
case '#':
|
||||
case 'L': /* True/False */
|
||||
case '9':
|
||||
case 'a':
|
||||
case 'A':
|
||||
case 'l':
|
||||
case 'L':
|
||||
case 'n':
|
||||
case 'N':
|
||||
case 'x':
|
||||
case 'X':
|
||||
{
|
||||
*szResult = pExp->item.asLogical.value ? 'T' : 'F';
|
||||
szPic++;
|
||||
ulPic--;
|
||||
bDone = TRUE;
|
||||
szResult[ ulResultPos++ ] = ( uiPicFlags & PF_UPPER ) ? toupper( szExp[ ulExpPos++ ] ) : szExp[ ulExpPos++ ];
|
||||
bAnyPic = TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Logical */
|
||||
case 'y':
|
||||
case 'Y':
|
||||
{
|
||||
szResult[ ulResultPos++ ] = ( szExp[ ulExpPos ] == 't' ||
|
||||
szExp[ ulExpPos ] == 'T' ||
|
||||
szExp[ ulExpPos ] == 'y' ||
|
||||
szExp[ ulExpPos ] == 'Y' ) ? 'Y' : 'N';
|
||||
ulExpPos++;
|
||||
bAnyPic = TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Other choices */
|
||||
default:
|
||||
{
|
||||
*szResult = *szPic++;
|
||||
ulPic--;
|
||||
szResult[ ulResultPos++ ] = *szPic;
|
||||
|
||||
if( !( uiPicFlags & PF_REMAIN ) )
|
||||
ulExpPos++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if( ( uiPicFlags & PF_REMAIN ) && ulPic )
|
||||
{ /* Any chars left */
|
||||
for( n = ulPic; n; n--) /* Copy remainder */
|
||||
szResult[ ulResultPos++ ] = *szPic++;
|
||||
if( !bDone ) /* Logical written ? */
|
||||
szResult[ ulResultPos++ ] = pExp->item.asLogical.value ? 'T' : 'F';
|
||||
}
|
||||
hb_retclen( szResult, ulResultPos );
|
||||
hb_xfree( szResult );
|
||||
break;
|
||||
}
|
||||
case IT_INTEGER:
|
||||
{
|
||||
szResult = NumPicture( szPic + ulPicStart, ulPic, uiPicFlags,
|
||||
( double ) pExp->item.asInteger.value, &ulResultPos,
|
||||
pExp->item.asInteger.length, 0 );
|
||||
hb_retclen( szResult, ulResultPos );
|
||||
hb_xfree( szResult );
|
||||
break;
|
||||
}
|
||||
case IT_LONG:
|
||||
{
|
||||
szResult = NumPicture( szPic + ulPicStart, ulPic, uiPicFlags,
|
||||
( double ) pExp->item.asLong.value, &ulResultPos,
|
||||
pExp->item.asLong.length, 0 );
|
||||
hb_retclen( szResult, ulResultPos );
|
||||
hb_xfree( szResult );
|
||||
break;
|
||||
}
|
||||
case IT_DOUBLE:
|
||||
{
|
||||
szResult = NumPicture( szPic + ulPicStart, ulPic, uiPicFlags,
|
||||
( double ) pExp->item.asDouble.value, &ulResultPos,
|
||||
pExp->item.asDouble.length, pExp->item.asDouble.decimal );
|
||||
hb_retclen( szResult, ulResultPos );
|
||||
hb_xfree( szResult );
|
||||
break;
|
||||
}
|
||||
case IT_DATE:
|
||||
{
|
||||
char szDate[ 9 ];
|
||||
char szResult[ 11 ];
|
||||
|
||||
DatePicture( hb_pardsbuff( szDate, 1 ), uiPicFlags, szResult );
|
||||
hb_retc( szResult );
|
||||
break;
|
||||
szPic++;
|
||||
ulPicLen--;
|
||||
}
|
||||
}
|
||||
default:
|
||||
hb_errRT_BASE( EG_ARG, 1122, NULL, "TRANSFORM" );
|
||||
else
|
||||
{
|
||||
while( ulExpPos++ < ulExpLen )
|
||||
szResult[ ulResultPos++ ] = ( uiPicFlags & PF_UPPER ) ? toupper( *szExp++ ) : *szExp++;
|
||||
}
|
||||
|
||||
if( ( uiPicFlags & PF_REMAIN ) && ! bAnyPic )
|
||||
{
|
||||
while( ulExpPos++ < ulExpLen )
|
||||
szResult[ ulResultPos++ ] = ( uiPicFlags & PF_UPPER ) ? toupper( *szExp++ ) : *szExp++;
|
||||
}
|
||||
|
||||
/* Any chars left ? */
|
||||
if( ( uiPicFlags & PF_REMAIN ) && ulPicLen )
|
||||
{
|
||||
/* Export remainder */
|
||||
while( ulPicLen-- )
|
||||
szResult[ ulResultPos++ ] = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
else if( IS_NUMERIC( pExp ) )
|
||||
{
|
||||
int iOrigWidth;
|
||||
int iOrigDec;
|
||||
|
||||
hb_itemGetNLen( pExp, &iOrigWidth, &iOrigDec );
|
||||
|
||||
szResult = NumPicture( szPic, ulPicLen, &uiPicFlags,
|
||||
hb_itemGetND( pExp ), &ulResultPos, iOrigWidth, iOrigDec );
|
||||
}
|
||||
|
||||
else if( IS_DATE( pExp ) )
|
||||
{
|
||||
char szDate[ 9 ];
|
||||
|
||||
szResult = ( char * ) hb_xgrab( 11 );
|
||||
|
||||
hb_dtoc( hb_itemGetDS( pExp, szDate ), szResult,
|
||||
( uiPicFlags & PF_BRITISH ) ?
|
||||
( hb_set.hb_set_century ? "DD/MM/YYYY" : "DD/MM/YY" ) :
|
||||
hb_set.HB_SET_DATEFORMAT );
|
||||
|
||||
ulResultPos = strlen( szResult );
|
||||
}
|
||||
|
||||
else if( IS_LOGICAL( pExp ) )
|
||||
{
|
||||
BOOL bDone = FALSE;
|
||||
|
||||
szResult = ( char * ) hb_xgrab( ulPicLen + 1 );
|
||||
ulResultPos = 1;
|
||||
|
||||
if( ulPicLen ) /* Template string */
|
||||
{
|
||||
switch( *szPic )
|
||||
{
|
||||
case 'y': /* Yes/No */
|
||||
case 'Y': /* Yes/No */
|
||||
{
|
||||
*szResult = hb_itemGetL( pExp ) ? 'Y' : 'N';
|
||||
szPic++;
|
||||
ulPicLen--;
|
||||
bDone = TRUE; /* Logical written */
|
||||
break;
|
||||
}
|
||||
|
||||
case '#':
|
||||
case 'l': /* True/False */
|
||||
case 'L': /* True/False */
|
||||
{
|
||||
*szResult = hb_itemGetL( pExp ) ? 'T' : 'F';
|
||||
szPic++;
|
||||
ulPicLen--;
|
||||
bDone = TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
*szResult = *szPic++;
|
||||
ulPicLen--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Any chars left */
|
||||
if( ( uiPicFlags & PF_REMAIN ) && ulPicLen )
|
||||
{
|
||||
/* Copy remainder */
|
||||
while( ulPicLen-- )
|
||||
szResult[ ulResultPos++ ] = *szPic++;
|
||||
|
||||
/* Logical written ? */
|
||||
if( ! bDone )
|
||||
szResult[ ulResultPos++ ] = hb_itemGetL( pExp ) ? 'T' : 'F';
|
||||
}
|
||||
}
|
||||
else
|
||||
bError = TRUE;
|
||||
|
||||
if( ! bError )
|
||||
{
|
||||
/* Trim left and pad with spaces */
|
||||
if( uiPicFlags & PF_LEFT )
|
||||
{
|
||||
ULONG ulFirstChar = 0;
|
||||
|
||||
while( ulFirstChar < ulResultPos && szResult[ ulFirstChar ] == ' ' )
|
||||
ulFirstChar++;
|
||||
|
||||
if( ulFirstChar < ulResultPos )
|
||||
{
|
||||
memmove( szResult, szResult + ulFirstChar, ulResultPos - ulFirstChar );
|
||||
memset( szResult + ulResultPos - ulFirstChar, ' ', ulFirstChar );
|
||||
}
|
||||
}
|
||||
|
||||
if( uiPicFlags & PF_EMPTY )
|
||||
memset( szResult, ' ', ulResultPos );
|
||||
|
||||
hb_retclen( szResult, ulResultPos );
|
||||
hb_xfree( szResult );
|
||||
}
|
||||
}
|
||||
else if( ISCHAR( 2 ) || ISNIL( 2 ) ) /* No picture supplied */
|
||||
else if( pPic || ISNIL( 2 ) ) /* Picture is an empty string or NIL */
|
||||
{
|
||||
switch( pExp->type & ~IT_BYREF ) /* Default behaviour */
|
||||
if( IS_STRING( pExp ) )
|
||||
{
|
||||
case IT_STRING:
|
||||
{
|
||||
hb_retclen( pExp->item.asString.value, pExp->item.asString.length );
|
||||
break;
|
||||
}
|
||||
case IT_LOGICAL:
|
||||
{
|
||||
hb_retc( pExp->item.asLogical.value ? "T" : "F" );
|
||||
break;
|
||||
}
|
||||
case IT_INTEGER:
|
||||
case IT_LONG:
|
||||
case IT_DOUBLE:
|
||||
{
|
||||
char * szStr = hb_itemStr( pExp, NULL, NULL );
|
||||
|
||||
if( szStr )
|
||||
{
|
||||
hb_retc( szStr );
|
||||
hb_xfree( szStr );
|
||||
}
|
||||
else
|
||||
hb_retc( "" );
|
||||
|
||||
break;
|
||||
}
|
||||
case IT_DATE:
|
||||
{
|
||||
char szDate[ 9 ];
|
||||
char szResult[ 11 ];
|
||||
|
||||
DatePicture( hb_pardsbuff( szDate, 1 ), 0, szResult );
|
||||
hb_retc( szResult );
|
||||
break;
|
||||
}
|
||||
default:
|
||||
hb_errRT_BASE( EG_ARG, 1122, NULL, "TRANSFORM" );
|
||||
hb_itemReturn( pExp );
|
||||
}
|
||||
else if( IS_NUMERIC( pExp ) )
|
||||
{
|
||||
char * szStr = hb_itemStr( pExp, NULL, NULL );
|
||||
|
||||
if( szStr )
|
||||
{
|
||||
hb_retc( szStr );
|
||||
hb_xfree( szStr );
|
||||
}
|
||||
else
|
||||
hb_retc( "" );
|
||||
}
|
||||
else if( IS_DATE( pExp ) )
|
||||
{
|
||||
char szDate[ 9 ];
|
||||
char szResult[ 11 ];
|
||||
|
||||
hb_retc( hb_dtoc( hb_itemGetDS( pExp, szDate ), szResult, hb_set.HB_SET_DATEFORMAT ) );
|
||||
}
|
||||
else if( IS_LOGICAL( pExp ) )
|
||||
{
|
||||
hb_retc( hb_itemGetL( pExp ) ? "T" : "F" );
|
||||
}
|
||||
else
|
||||
bError = TRUE;
|
||||
}
|
||||
else
|
||||
hb_errRT_BASE( EG_ARG, 1122, NULL, "TRANSFORM");
|
||||
bError = TRUE;
|
||||
|
||||
/* If there was any parameter error, launch a runtime error */
|
||||
|
||||
if( bError )
|
||||
{
|
||||
PHB_ITEM pResult = hb_errRT_BASE_Subst( EG_ARG, 1122, NULL, "TRANSFORM" );
|
||||
|
||||
if( pResult )
|
||||
{
|
||||
hb_itemReturn( pResult );
|
||||
hb_itemRelease( pResult );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -287,7 +287,7 @@ void hb_vmInit( void )
|
||||
hb_errInternal( 9999, "Can\'t locate the starting procedure: \'%s\'", HARBOUR_START_PROCEDURE, NULL );
|
||||
}
|
||||
#else
|
||||
#ifndef HARBOUR_STRICT_CLIPPER_COMPATIBLE
|
||||
#ifndef HARBOUR_STRICT_CLIPPER_COMPATIBILITY
|
||||
else if( ! s_pSymStart )
|
||||
hb_errInternal( 9999, "No starting procedure", NULL, NULL );
|
||||
#endif
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/* TRANSFORM() tests written by Eddie Runia <eddie@runia.com> */
|
||||
/* TRANSFORM() tests mostly written by Eddie Runia <eddie@runia.com> */
|
||||
/* EMPTY() tests written by Eddie Runia <eddie@runia.com> */
|
||||
/* :class* tests written by Dave Pearson <davep@hagbard.demon.co.uk> */
|
||||
|
||||
@@ -82,6 +82,7 @@ STATIC s_nStartTime
|
||||
STATIC s_nEndTime
|
||||
|
||||
STATIC scString
|
||||
STATIC scStringM
|
||||
STATIC scStringE
|
||||
STATIC scStringZ
|
||||
STATIC scStringW
|
||||
@@ -889,7 +890,7 @@ STATIC FUNCTION Main_HVM()
|
||||
TEST_LINE( Len( "123"+Chr(0)+"456 " ) , 8 )
|
||||
TEST_LINE( Len( saArray ) , 1 )
|
||||
#ifdef __HARBOUR__
|
||||
TEST_LINE( Len( Space( 3000000000 ) ) , 3000000000 )
|
||||
TEST_LINE( Len( Space( 1000000 ) ) , 1000000 )
|
||||
#else
|
||||
TEST_LINE( Len( Space( 40000 ) ) , 40000 )
|
||||
#endif
|
||||
@@ -2088,6 +2089,85 @@ STATIC FUNCTION Main_STRINGS()
|
||||
|
||||
/* TRANSFORM() */
|
||||
|
||||
TEST_LINE( Transform( NIL , NIL ) , "E BASE 1122 Argument error TRANSFORM F:S" )
|
||||
TEST_LINE( Transform( NIL , "" ) , "E BASE 1122 Argument error TRANSFORM F:S" )
|
||||
TEST_LINE( Transform( NIL , "@" ) , "E BASE 1122 Argument error TRANSFORM F:S" )
|
||||
TEST_LINE( Transform( {} , NIL ) , "E BASE 1122 Argument error TRANSFORM F:S" )
|
||||
TEST_LINE( Transform( {} , "" ) , "E BASE 1122 Argument error TRANSFORM F:S" )
|
||||
TEST_LINE( Transform( {} , "@" ) , "E BASE 1122 Argument error TRANSFORM F:S" )
|
||||
TEST_LINE( Transform( ErrorNew(), NIL ) , "E BASE 1122 Argument error TRANSFORM F:S" )
|
||||
TEST_LINE( Transform( ErrorNew(), "" ) , "E BASE 1122 Argument error TRANSFORM F:S" )
|
||||
TEST_LINE( Transform( ErrorNew(), "@" ) , "E BASE 1122 Argument error TRANSFORM F:S" )
|
||||
TEST_LINE( Transform( {|| NIL } , NIL ) , "E BASE 1122 Argument error TRANSFORM F:S" )
|
||||
TEST_LINE( Transform( {|| NIL } , "" ) , "E BASE 1122 Argument error TRANSFORM F:S" )
|
||||
TEST_LINE( Transform( {|| NIL } , "@" ) , "E BASE 1122 Argument error TRANSFORM F:S" )
|
||||
|
||||
TEST_LINE( Transform( "", "" ) , "" )
|
||||
TEST_LINE( Transform( "", "@" ) , "" )
|
||||
TEST_LINE( Transform( "", NIL ) , "" )
|
||||
TEST_LINE( Transform( "", 100 ) , "E BASE 1122 Argument error TRANSFORM F:S" )
|
||||
TEST_LINE( Transform( "hello", "" ) , "hello" )
|
||||
TEST_LINE( Transform( "hello", "@" ) , "hello" )
|
||||
TEST_LINE( Transform( "hello", NIL ) , "hello" )
|
||||
TEST_LINE( Transform( "hello", 100 ) , "E BASE 1122 Argument error TRANSFORM F:S" )
|
||||
TEST_LINE( Transform( 100.2, "" ) , " 100.2" )
|
||||
TEST_LINE( Transform( 100.2, "@" ) , " 100.2" )
|
||||
TEST_LINE( Transform( 100.2, NIL ) , " 100.2" )
|
||||
TEST_LINE( Transform( 100.2, 100 ) , "E BASE 1122 Argument error TRANSFORM F:S" )
|
||||
TEST_LINE( Transform( 100.20, "" ) , " 100.20" )
|
||||
TEST_LINE( Transform( 100.20, "@" ) , " 100.20" )
|
||||
TEST_LINE( Transform( 100.20, NIL ) , " 100.20" )
|
||||
TEST_LINE( Transform( 100.20, 100 ) , "E BASE 1122 Argument error TRANSFORM F:S" )
|
||||
TEST_LINE( Transform( Val("100.2"), "" ) , "100.2" )
|
||||
TEST_LINE( Transform( Val("100.2"), "@" ) , "100.2" )
|
||||
TEST_LINE( Transform( Val("100.2"), NIL ) , "100.2" )
|
||||
TEST_LINE( Transform( Val("100.2"), 100 ) , "E BASE 1122 Argument error TRANSFORM F:S" )
|
||||
TEST_LINE( Transform( Val("100.20"), "" ) , "100.20" )
|
||||
// TEST_LINE( Transform( Val("100.20"), "@" ) , "100.20" )
|
||||
TEST_LINE( Transform( Val("100.20"), NIL ) , "100.20" )
|
||||
TEST_LINE( Transform( Val("100.20"), 100 ) , "E BASE 1122 Argument error TRANSFORM F:S" )
|
||||
TEST_LINE( Transform( sdDate, "" ) , "1980.01.01" )
|
||||
TEST_LINE( Transform( sdDate, "@" ) , "1980.01.01" )
|
||||
TEST_LINE( Transform( sdDate, NIL ) , "1980.01.01" )
|
||||
TEST_LINE( Transform( sdDate, 100 ) , "E BASE 1122 Argument error TRANSFORM F:S" )
|
||||
TEST_LINE( Transform( .T., "" ) , "T" )
|
||||
TEST_LINE( Transform( .T., "@" ) , "T" )
|
||||
TEST_LINE( Transform( .F., NIL ) , "F" )
|
||||
TEST_LINE( Transform( .F., 100 ) , "E BASE 1122 Argument error TRANSFORM F:S" )
|
||||
|
||||
TEST_LINE( Transform( scStringM , "!!!!!" ) , "HELLO" )
|
||||
TEST_LINE( Transform( scStringM , "@!" ) , "HELLO" )
|
||||
#ifdef __HARBOUR__
|
||||
TEST_LINE( Transform( @scStringM, "!!!!!" ) , "HELLO" ) /* Bug in CA-Cl*pper, it returns: "E BASE 1122 Argument error TRANSFORM F:S" */
|
||||
TEST_LINE( Transform( @scStringM, "@!" ) , "HELLO" ) /* Bug in CA-Cl*pper, it returns: "E BASE 1122 Argument error TRANSFORM F:S" */
|
||||
#endif
|
||||
TEST_LINE( Transform( scStringM , "" ) , "Hello" )
|
||||
TEST_LINE( Transform( scStringM , NIL ) , "Hello" )
|
||||
TEST_LINE( Transform( scStringM , 100 ) , "E BASE 1122 Argument error TRANSFORM F:S" )
|
||||
|
||||
TEST_LINE( Transform("abcdef", "@! !lkm!") , "ABkmE" )
|
||||
TEST_LINE( Transform("abcdefghijklmnopqrstuvwxyz", "@! 1234567890"), "12345678I0" )
|
||||
TEST_LINE( Transform("abcdefghijklmnopqrstuvwxyzabcdefg", "@! abcdefghijklmnopqrstuvwxyzabcdefg"), "AbcdefghijkLmNopqrstuvwXYzAbcdefg" )
|
||||
TEST_LINE( Transform("abcdefghijklmnopqrstuvwxyz", "@! `~!@#$% ^&*()_+-={}\|;':") , "`~C@E$% ^&*()_+-={}\|;':" )
|
||||
TEST_LINE( Transform("abcdefghijklmnopqrstuvwxyz", "@! ,./<>?") , ",./<>?" )
|
||||
TEST_LINE( Transform("hello", " @!") , " @L" )
|
||||
|
||||
TEST_LINE( Transform("abcdef", "@R! !lkm!") , "ABkmC" )
|
||||
TEST_LINE( Transform("abcdefghijklmnopqrstuvwxyz", "@R! 1234567890"), "12345678A0" )
|
||||
TEST_LINE( Transform("abcdefghijklmnopqrstuvwxyzabcdefg", "@R! abcdefghijklmnopqrstuvwxyzabcdefg"), "AbcdefghijkBmCopqrstuvwDNzFbcdefg" )
|
||||
TEST_LINE( Transform("abcdefghijklmnopqrstuvwxyz", "@R! `~!@#$% ^&*()_+-={}\|;':") , "`~A@B$% ^&*()_+-={}\|;':" )
|
||||
TEST_LINE( Transform("abcdefghijklmnopqrstuvwxyz", "@R! ,./<>?") , ",./<>?ABCDEFGHIJKLMNOPQRSTUVWXYZ" )
|
||||
TEST_LINE( Transform("hello", " @R!") , " @RL" )
|
||||
|
||||
TEST_LINE( Transform("abc", "@R !!!!") , "ABC " )
|
||||
TEST_LINE( Transform("abc", "@R XXXX") , "abc " )
|
||||
TEST_LINE( Transform("abc", "@R !!") , "AB" )
|
||||
TEST_LINE( Transform("abc", "@R XX") , "ab" )
|
||||
TEST_LINE( Transform("abc", "@!R !!!!") , "ABC " )
|
||||
TEST_LINE( Transform("abc", "@!R XXXX") , "ABC " )
|
||||
TEST_LINE( Transform("abc", "@!R !!") , "AB" )
|
||||
TEST_LINE( Transform("abc", "@!R XX") , "AB" )
|
||||
|
||||
TEST_LINE( Transform( "Hallo ", "!!!!!" ) , "HALLO" )
|
||||
TEST_LINE( Transform( "Hallo ", "!!A!!" ) , "HAlLO" )
|
||||
TEST_LINE( Transform( "Hallo ", "!!A9!" ) , "HAllO" )
|
||||
@@ -2153,6 +2233,7 @@ STATIC FUNCTION Main_STRINGS()
|
||||
|
||||
SET CENTURY ON
|
||||
|
||||
TEST_LINE( Transform( 1 , "@b" ) , "1 " )
|
||||
TEST_LINE( Transform( 1 , "@B" ) , "1 " )
|
||||
TEST_LINE( Transform( 1.0 , "@B" ) , "1.0 " )
|
||||
TEST_LINE( Transform( 15 , "9999" ) , " 15" )
|
||||
@@ -3395,6 +3476,7 @@ STATIC FUNCTION TEST_BEGIN( cParam )
|
||||
( passing by reference, avoid preprocessor bugs, etc. ) */
|
||||
|
||||
scString := "HELLO"
|
||||
scStringM := "Hello"
|
||||
scStringE := ""
|
||||
scStringZ := "A" + Chr( 0 ) + "B"
|
||||
scStringW := Chr(13)+Chr(10)+Chr(141)+Chr(10)+Chr(9)
|
||||
|
||||
Reference in New Issue
Block a user