2001-07-23 20:10 MEST Martin Vogel <vogel@inttec.de>
This commit is contained in:
@@ -1,3 +1,16 @@
|
||||
2001-07-23 20:10 MEST Martin Vogel <vogel@inttec.de>
|
||||
|
||||
+ contrib/libct/count.c
|
||||
+ COUNTLEFT() & COUNTRIGHT() functions
|
||||
+ contrib/libct/justify.c
|
||||
+ JUSTLEFT() & JUSTRIGHT() functions
|
||||
+ contrib/libct/relation.c
|
||||
+ CHARRELA() & CHARRELREP() functions
|
||||
* contrib/libct/Makefile
|
||||
* contrib/libct/makefile.bc
|
||||
* contrib/libct/makefile.vc
|
||||
+ count.c, justify.c and relation.c added
|
||||
|
||||
2001-07-23 17:37 GMT Dave Pearson <davep@davep.org>
|
||||
* source/rtl/profiler.prg
|
||||
* Replace old profile reporting code with an OO approach.
|
||||
|
||||
@@ -21,6 +21,7 @@ C_SOURCES = \
|
||||
charrepl.c \
|
||||
charsort.c \
|
||||
charswap.c \
|
||||
count.c \
|
||||
ct.c \
|
||||
ctmath.c \
|
||||
ctset.c \
|
||||
@@ -30,8 +31,10 @@ C_SOURCES = \
|
||||
ctcrypt.c \
|
||||
ctposupp.c \
|
||||
finan.c \
|
||||
justify.c \
|
||||
math.c \
|
||||
num1.c \
|
||||
relation.c \
|
||||
token1.c \
|
||||
trig.c \
|
||||
wordrepl.c \
|
||||
|
||||
214
harbour/contrib/libct/count.c
Normal file
214
harbour/contrib/libct/count.c
Normal file
@@ -0,0 +1,214 @@
|
||||
/*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
/*
|
||||
* Harbour Project source code:
|
||||
* COUNTLEFT() and COUNTRIGHT() CT3 string functions
|
||||
*
|
||||
* Copyright 2001 IntTec GmbH, Neunlindenstr 32, 79106 Freiburg, Germany
|
||||
* Author: Martin Vogel <vogel@inttec.de>
|
||||
*
|
||||
* 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 "ct.h"
|
||||
|
||||
|
||||
/* defines */
|
||||
#define DO_COUNT_COUNTLEFT 0
|
||||
#define DO_COUNT_COUNTRIGHT 1
|
||||
|
||||
/* helper function for the countxxx functions */
|
||||
static void do_count (int iSwitch)
|
||||
{
|
||||
|
||||
/* param check */
|
||||
if (ISCHAR (1))
|
||||
{
|
||||
|
||||
char *pcString = hb_parc (2);
|
||||
size_t sStrLen = (size_t)hb_parclen (2);
|
||||
size_t sRetVal;
|
||||
char *pc;
|
||||
char cSearch;
|
||||
|
||||
if (hb_parclen (2) > 0)
|
||||
cSearch = *(hb_parc (2));
|
||||
else if (ISNUM (2))
|
||||
cSearch = hb_parnl (2) % 256;
|
||||
else
|
||||
cSearch = 0x20;
|
||||
|
||||
sRetVal = 0;
|
||||
|
||||
switch (iSwitch)
|
||||
{
|
||||
case DO_COUNT_COUNTLEFT:
|
||||
{
|
||||
pc = pcString;
|
||||
while ((*pc == cSearch) && (pc < pcString+sStrLen))
|
||||
{
|
||||
sRetVal++;
|
||||
pc++;
|
||||
}
|
||||
}; break;
|
||||
|
||||
case DO_COUNT_COUNTRIGHT:
|
||||
{
|
||||
pc = pcString+sStrLen-1;
|
||||
while ((*pc == cSearch) && (pc >= pcString))
|
||||
{
|
||||
sRetVal++;
|
||||
pc--;
|
||||
}
|
||||
}; break;
|
||||
|
||||
}
|
||||
|
||||
hb_retnl (sRetVal);
|
||||
|
||||
}
|
||||
else /* if (ISCHAR (1)) */
|
||||
{
|
||||
PHB_ITEM pSubst = NULL;
|
||||
int iArgErrorMode = ct_getargerrormode();
|
||||
if (iArgErrorMode != CT_ARGERR_IGNORE)
|
||||
{
|
||||
pSubst = ct_error_subst ((USHORT)iArgErrorMode, EG_ARG,
|
||||
(iSwitch == DO_COUNT_COUNTLEFT ? CT_ERROR_COUNTLEFT : CT_ERROR_COUNTRIGHT),
|
||||
NULL,
|
||||
(iSwitch == DO_COUNT_COUNTLEFT ? "COUNTLEFT" : "COUNTRIGHT"),
|
||||
0, EF_CANSUBSTITUTE, 2,
|
||||
hb_paramError (1), hb_paramError (2));
|
||||
}
|
||||
|
||||
if (pSubst != NULL)
|
||||
{
|
||||
hb_itemReturn (pSubst);
|
||||
hb_itemRelease (pSubst);
|
||||
}
|
||||
else
|
||||
{
|
||||
hb_retnl (0);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* $DOC$
|
||||
* $FUNCNAME$
|
||||
* COUNTLEFT()
|
||||
* $CATEGORY$
|
||||
* CT3 string functions
|
||||
* $ONELINER$
|
||||
* Count a certain character at the beginning of a string
|
||||
* $SYNTAX$
|
||||
* COUNTLEFT (<cString>, [<cSearch|nSearch>]) -> nCount
|
||||
* $ARGUMENTS$
|
||||
* $RETURNS$
|
||||
* $DESCRIPTION$
|
||||
* TODO: add documentation
|
||||
* $EXAMPLES$
|
||||
* $TESTS$
|
||||
* $STATUS$
|
||||
* Started
|
||||
* $COMPLIANCE$
|
||||
* COUNTLEFT() is compatible with CT3's COUNTLEFT().
|
||||
* $PLATFORMS$
|
||||
* All
|
||||
* $FILES$
|
||||
* Source is count.c, library is libct.
|
||||
* $SEEALSO$
|
||||
* COUNTRIGHT()
|
||||
* $END$
|
||||
*/
|
||||
|
||||
HB_FUNC (COUNTLEFT)
|
||||
{
|
||||
|
||||
do_count (DO_COUNT_COUNTLEFT);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* $DOC$
|
||||
* $FUNCNAME$
|
||||
* COUNTRIGHT()
|
||||
* $CATEGORY$
|
||||
* CT3 string functions
|
||||
* $ONELINER$
|
||||
* Count a certain character at the end of a string
|
||||
* $SYNTAX$
|
||||
* COUNTRIGHT (<cString>, [<cSearch|nSearch>]) -> nCount
|
||||
* $ARGUMENTS$
|
||||
* $RETURNS$
|
||||
* $DESCRIPTION$
|
||||
* TODO: add documentation
|
||||
* $EXAMPLES$
|
||||
* $TESTS$
|
||||
* $STATUS$
|
||||
* Started
|
||||
* $COMPLIANCE$
|
||||
* COUNTRIGHT() is compatible with CT3's COUNTRIGHT().
|
||||
* $PLATFORMS$
|
||||
* All
|
||||
* $FILES$
|
||||
* Source is count.c, library is libct.
|
||||
* $SEEALSO$
|
||||
* COUNTLEFT()
|
||||
* $END$
|
||||
*/
|
||||
|
||||
HB_FUNC (COUNTRIGHT)
|
||||
{
|
||||
|
||||
do_count (DO_COUNT_COUNTRIGHT);
|
||||
return;
|
||||
|
||||
}
|
||||
@@ -191,8 +191,8 @@ CHARONE ;R;
|
||||
CHARONLY ;R;
|
||||
CHAROR ;R;
|
||||
CHARPACK ;N;
|
||||
CHARRELA ;N;
|
||||
CHARRELREP ;N;
|
||||
CHARRELA ;S;
|
||||
CHARRELREP ;S;
|
||||
CHARREM ;R;
|
||||
CHARREPL ;R;
|
||||
CHARRLL ;R; !NEW!
|
||||
@@ -207,14 +207,14 @@ CHARSWAP ;R;
|
||||
CHARUNPACK ;N;
|
||||
CHARXOR ;R;
|
||||
CHECKSUM ;R;
|
||||
COUNTLEFT ;N;
|
||||
COUNTRIGHT ;N;
|
||||
COUNTLEFT ;S;
|
||||
COUNTRIGHT ;S;
|
||||
CRYPT ;R;
|
||||
CSETATMUPA ;R;
|
||||
CSETREF ;R;
|
||||
EXPAND ;N;
|
||||
JUSTLEFT ;N;
|
||||
JUSTRIGHT ;N;
|
||||
JUSTLEFT ;S;
|
||||
JUSTRIGHT ;S;
|
||||
LIKE ;N;
|
||||
LTOC ;R;
|
||||
MAXLINE ;N;
|
||||
|
||||
246
harbour/contrib/libct/justify.c
Normal file
246
harbour/contrib/libct/justify.c
Normal file
@@ -0,0 +1,246 @@
|
||||
/*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
/*
|
||||
* Harbour Project source code:
|
||||
* JUSTLEFT() and JUSTRIGHT() CT3 string functions
|
||||
*
|
||||
* Copyright 2001 IntTec GmbH, Neunlindenstr 32, 79106 Freiburg, Germany
|
||||
* Author: Martin Vogel <vogel@inttec.de>
|
||||
*
|
||||
* 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 "ct.h"
|
||||
|
||||
|
||||
/* defines */
|
||||
#define DO_JUSTIFY_JUSTLEFT 0
|
||||
#define DO_JUSTIFY_JUSTRIGHT 1
|
||||
|
||||
/* helper function for the justxxx() functions */
|
||||
static void do_justify (int iSwitch)
|
||||
{
|
||||
|
||||
int iNoRet;
|
||||
|
||||
iNoRet = ct_getref();
|
||||
|
||||
if (ISCHAR (1))
|
||||
{
|
||||
|
||||
char *pcString = hb_parc (1);
|
||||
size_t sStrLen = hb_parclen (1);
|
||||
char cJustChar;
|
||||
char *pc, *pcRet;
|
||||
size_t sJustOffset, sCnt;
|
||||
|
||||
if (hb_parclen (2) > 0)
|
||||
cJustChar = *(hb_parc (2));
|
||||
else if (ISNUM (2))
|
||||
cJustChar = hb_parnl (2) % 256;
|
||||
else
|
||||
cJustChar = 0x20;
|
||||
|
||||
pcRet = hb_xgrab (sStrLen);
|
||||
|
||||
switch (iSwitch)
|
||||
{
|
||||
case DO_JUSTIFY_JUSTLEFT:
|
||||
{
|
||||
pc = pcString;
|
||||
sJustOffset = 0;
|
||||
while ((*pc == cJustChar) && (pc < pcString+sStrLen))
|
||||
{
|
||||
sJustOffset++;
|
||||
pc++;
|
||||
}
|
||||
|
||||
hb_xmemcpy (pcRet, pcString+sJustOffset, sStrLen-sJustOffset);
|
||||
for (pc = pcRet+sStrLen-sJustOffset; pc < pcRet+sStrLen; pc++)
|
||||
{
|
||||
*pc = cJustChar;
|
||||
}
|
||||
|
||||
}; break;
|
||||
|
||||
case DO_JUSTIFY_JUSTRIGHT:
|
||||
{
|
||||
pc = pcString+sStrLen-1;
|
||||
sJustOffset = 0;
|
||||
while ((*pc == cJustChar) && (pc >= pcString))
|
||||
{
|
||||
sJustOffset++;
|
||||
pc--;
|
||||
}
|
||||
|
||||
for (pc = pcRet; pc < pcRet+sJustOffset; pc++)
|
||||
{
|
||||
*pc = cJustChar;
|
||||
}
|
||||
hb_xmemcpy (pcRet+sJustOffset, pcString, sStrLen-sJustOffset);
|
||||
|
||||
}; break;
|
||||
|
||||
}
|
||||
|
||||
if (ISBYREF (1))
|
||||
hb_storclen (pcRet, sStrLen, 1);
|
||||
|
||||
if (iNoRet)
|
||||
hb_ret();
|
||||
else
|
||||
hb_retclen (pcRet, sStrLen);
|
||||
|
||||
hb_xfree (pcRet);
|
||||
|
||||
}
|
||||
else /* ISCHAR (1) */
|
||||
{
|
||||
PHB_ITEM pSubst = NULL;
|
||||
int iArgErrorMode = ct_getargerrormode();
|
||||
if (iArgErrorMode != CT_ARGERR_IGNORE)
|
||||
{
|
||||
pSubst = ct_error_subst ((USHORT)iArgErrorMode, EG_ARG,
|
||||
(iSwitch == DO_JUSTIFY_JUSTLEFT ? CT_ERROR_JUSTLEFT : CT_ERROR_JUSTRIGHT),
|
||||
NULL,
|
||||
(iSwitch == DO_JUSTIFY_JUSTLEFT ? "JUSTLEFT" : "JUSTRIGHT"),
|
||||
0, EF_CANSUBSTITUTE, 2,
|
||||
hb_paramError (1), hb_paramError (2));
|
||||
}
|
||||
|
||||
if (pSubst != NULL)
|
||||
{
|
||||
hb_itemReturn (pSubst);
|
||||
hb_itemRelease (pSubst);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (iNoRet)
|
||||
hb_ret();
|
||||
else
|
||||
hb_retc ("");
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* $DOC$
|
||||
* $FUNCNAME$
|
||||
* JUSTLEFT()
|
||||
* $CATEGORY$
|
||||
* CT3 string functions
|
||||
* $ONELINER$
|
||||
* Move characters from the beginning to the end of a string
|
||||
* $SYNTAX$
|
||||
* JUSTLEFT (<[@]cString>, [<cChar>|<nChar>]) -> cJustifiedString
|
||||
* $ARGUMENTS$
|
||||
* $RETURNS$
|
||||
* $DESCRIPTION$
|
||||
* TODO: add documentation
|
||||
* $EXAMPLES$
|
||||
* $TESTS$
|
||||
* $STATUS$
|
||||
* Started
|
||||
* $COMPLIANCE$
|
||||
* JUSTLEFT() is compatible with CT3's JUSTLEFT().
|
||||
* $PLATFORMS$
|
||||
* All
|
||||
* $FILES$
|
||||
* Source is justify.c, library is libct.
|
||||
* $SEEALSO$
|
||||
* JUSTRIGHT()
|
||||
* $END$
|
||||
*/
|
||||
|
||||
HB_FUNC (JUSTLEFT)
|
||||
{
|
||||
|
||||
do_justify (DO_JUSTIFY_JUSTLEFT);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* $DOC$
|
||||
* $FUNCNAME$
|
||||
* JUSTRIGHT()
|
||||
* $CATEGORY$
|
||||
* Harbour Tools string functions
|
||||
* $ONELINER$
|
||||
* Move characters from the end to the beginning of a string
|
||||
* $SYNTAX$
|
||||
* JUSTRIGHT (<[@]cString>, [<cChar>|<nChar>]) -> cJustifiedString
|
||||
* $ARGUMENTS$
|
||||
* $RETURNS$
|
||||
* $DESCRIPTION$
|
||||
* TODO: add documentation
|
||||
* $EXAMPLES$
|
||||
* $TESTS$
|
||||
* $STATUS$
|
||||
* Started
|
||||
* $COMPLIANCE$
|
||||
* JUSTRIGHT() is compatible with CT3's JUSTRIGHT().
|
||||
* $PLATFORMS$
|
||||
* All
|
||||
* $FILES$
|
||||
* Source is justify.c, library is libct.
|
||||
* $SEEALSO$
|
||||
* JUSTLEFT()
|
||||
* $END$
|
||||
*/
|
||||
|
||||
HB_FUNC (JUSTRIGHT)
|
||||
{
|
||||
|
||||
do_justify (DO_JUSTIFY_JUSTRIGHT);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -106,6 +106,7 @@ TOOLS_LIB_OBJS = \
|
||||
$(OBJ_DIR)\charrepl.obj \
|
||||
$(OBJ_DIR)\charsort.obj \
|
||||
$(OBJ_DIR)\charswap.obj \
|
||||
$(OBJ_DIR)\count.obj \
|
||||
$(OBJ_DIR)\ct.obj \
|
||||
$(OBJ_DIR)\ctmath.obj \
|
||||
$(OBJ_DIR)\ctset.obj \
|
||||
@@ -115,8 +116,10 @@ TOOLS_LIB_OBJS = \
|
||||
$(OBJ_DIR)\ctcrypt.obj \
|
||||
$(OBJ_DIR)\ctposupp.obj \
|
||||
$(OBJ_DIR)\finan.obj \
|
||||
$(OBJ_DIR)\justify.obj \
|
||||
$(OBJ_DIR)\math.obj \
|
||||
$(OBJ_DIR)\num1.obj \
|
||||
$(OBJ_DIR)\relation.obj \
|
||||
$(OBJ_DIR)\token1.obj \
|
||||
$(OBJ_DIR)\trig.obj \
|
||||
$(OBJ_DIR)\wordrepl.obj \
|
||||
@@ -204,6 +207,10 @@ $(OBJ_DIR)\charswap.obj : $(TOOLS_DIR)\charswap.c
|
||||
$(CC) $(CLIBFLAGS) -o$@ $**
|
||||
tlib $(TOOLS_LIB) $(ARFLAGS) -+$@,,
|
||||
|
||||
$(OBJ_DIR)\count.obj : $(TOOLS_DIR)\count.c
|
||||
$(CC) $(CLIBFLAGS) -o$@ $**
|
||||
tlib $(TOOLS_LIB) $(ARFLAGS) -+$@,,
|
||||
|
||||
$(OBJ_DIR)\ct.obj : $(TOOLS_DIR)\ct.c
|
||||
$(CC) $(CLIBFLAGS) -o$@ $**
|
||||
tlib $(TOOLS_LIB) $(ARFLAGS) -+$@,,
|
||||
@@ -240,6 +247,10 @@ $(OBJ_DIR)\finan.obj : $(TOOLS_DIR)\finan.c
|
||||
$(CC) $(CLIBFLAGS) -o$@ $**
|
||||
tlib $(TOOLS_LIB) $(ARFLAGS) -+$@,,
|
||||
|
||||
$(OBJ_DIR)\justify.obj : $(TOOLS_DIR)\justify.c
|
||||
$(CC) $(CLIBFLAGS) -o$@ $**
|
||||
tlib $(TOOLS_LIB) $(ARFLAGS) -+$@,,
|
||||
|
||||
$(OBJ_DIR)\math.obj : $(TOOLS_DIR)\math.c
|
||||
$(CC) $(CLIBFLAGS) -o$@ $**
|
||||
tlib $(TOOLS_LIB) $(ARFLAGS) -+$@,,
|
||||
@@ -248,6 +259,10 @@ $(OBJ_DIR)\num1.obj : $(TOOLS_DIR)\num1.c
|
||||
$(CC) $(CLIBFLAGS) -o$@ $**
|
||||
tlib $(TOOLS_LIB) $(ARFLAGS) -+$@,,
|
||||
|
||||
$(OBJ_DIR)\relation.obj : $(TOOLS_DIR)\relation.c
|
||||
$(CC) $(CLIBFLAGS) -o$@ $**
|
||||
tlib $(TOOLS_LIB) $(ARFLAGS) -+$@,,
|
||||
|
||||
$(OBJ_DIR)\token1.obj : $(TOOLS_DIR)\token1.c
|
||||
$(CC) $(CLIBFLAGS) -o$@ $**
|
||||
tlib $(TOOLS_LIB) $(ARFLAGS) -+$@,,
|
||||
|
||||
@@ -126,6 +126,7 @@ TOOLS_LIB_OBJS = \
|
||||
$(OBJ_DIR)\charrepl.obj \
|
||||
$(OBJ_DIR)\charsort.obj \
|
||||
$(OBJ_DIR)\charswap.obj \
|
||||
$(OBJ_DIR)\count.obj \
|
||||
$(OBJ_DIR)\ct.obj \
|
||||
$(OBJ_DIR)\ctmath.obj \
|
||||
$(OBJ_DIR)\ctset.obj \
|
||||
@@ -135,8 +136,10 @@ TOOLS_LIB_OBJS = \
|
||||
$(OBJ_DIR)\ctcrypt.obj \
|
||||
$(OBJ_DIR)\ctposupp.obj \
|
||||
$(OBJ_DIR)\finan.obj \
|
||||
$(OBJ_DIR)\justify.obj \
|
||||
$(OBJ_DIR)\math.obj \
|
||||
$(OBJ_DIR)\num1.obj \
|
||||
$(OBJ_DIR)\relation.obj \
|
||||
$(OBJ_DIR)\token1.obj \
|
||||
$(OBJ_DIR)\trig.obj \
|
||||
$(OBJ_DIR)\wordrepl.obj \
|
||||
@@ -168,6 +171,7 @@ CLEAN:
|
||||
-@if exist $(OBJ_DIR)\charrepl.* del $(OBJ_DIR)\charrepl.*
|
||||
-@if exist $(OBJ_DIR)\charsort.* del $(OBJ_DIR)\charsort.*
|
||||
-@if exist $(OBJ_DIR)\charswap.* del $(OBJ_DIR)\charswap.*
|
||||
-@if exist $(OBJ_DIR)\count.* del $(OBJ_DIR)\count.*
|
||||
-@if exist $(OBJ_DIR)\ct.* del $(OBJ_DIR)\ct.*
|
||||
-@if exist $(OBJ_DIR)\ctmath.* del $(OBJ_DIR)\ctmath.*
|
||||
-@if exist $(OBJ_DIR)\ctset.* del $(OBJ_DIR)\ctset.*
|
||||
@@ -177,8 +181,10 @@ CLEAN:
|
||||
-@if exist $(OBJ_DIR)\ctcrypt.* del $(OBJ_DIR)\ctcrypt.*
|
||||
-@if exist $(OBJ_DIR)\ctposupp.* del $(OBJ_DIR)\ctposupp.*
|
||||
-@if exist $(OBJ_DIR)\finan.* del $(OBJ_DIR)\finan.*
|
||||
-@if exist $(OBJ_DIR)\justify.* del $(OBJ_DIR)\justify.*
|
||||
-@if exist $(OBJ_DIR)\math.* del $(OBJ_DIR)\math.*
|
||||
-@if exist $(OBJ_DIR)\num1.* del $(OBJ_DIR)\num1.*
|
||||
-@if exist $(OBJ_DIR)\relation.* del $(OBJ_DIR)\relation.*
|
||||
-@if exist $(OBJ_DIR)\token1.* del $(OBJ_DIR)\token1.*
|
||||
-@if exist $(OBJ_DIR)\trig.* del $(OBJ_DIR)\trig.*
|
||||
-@if exist $(OBJ_DIR)\wordrepl.* del $(OBJ_DIR)\wordrepl.*
|
||||
|
||||
387
harbour/contrib/libct/relation.c
Normal file
387
harbour/contrib/libct/relation.c
Normal file
@@ -0,0 +1,387 @@
|
||||
/*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
/*
|
||||
* Harbour Project source code:
|
||||
* CHARRELA() and CHARRELREP() CT3 string functions
|
||||
*
|
||||
* Copyright 2001 IntTec GmbH, Neunlindenstr 32, 79106 Freiburg, Germany
|
||||
* Author: Martin Vogel <vogel@inttec.de>
|
||||
*
|
||||
* 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 "ct.h"
|
||||
|
||||
|
||||
/* $DOC$
|
||||
* $FUNCNAME$
|
||||
* CHARRELA()
|
||||
* $CATEGORY$
|
||||
* CT3 string functions
|
||||
* $ONELINER$
|
||||
* Character relation of two strings
|
||||
* $SYNTAX$
|
||||
* CHARRELA (<cStringToMatch1>, <cString1>,
|
||||
* <cStringToMatch2>, <cString2>) -> nPosition
|
||||
* $ARGUMENTS$
|
||||
* $RETURNS$
|
||||
* $DESCRIPTION$
|
||||
* TODO: add documentation
|
||||
* $EXAMPLES$
|
||||
* $TESTS$
|
||||
* $STATUS$
|
||||
* Started
|
||||
* $COMPLIANCE$
|
||||
* CHARRELA() is compatible with CT3's CHARRELA().
|
||||
* $PLATFORMS$
|
||||
* All
|
||||
* $FILES$
|
||||
* Source is relation.c, library is libct.
|
||||
* $SEEALSO$
|
||||
* CHARRELREP()
|
||||
* $END$
|
||||
*/
|
||||
|
||||
HB_FUNC (CHARRELA)
|
||||
{
|
||||
|
||||
if (ISCHAR (1) &&
|
||||
ISCHAR (2) &&
|
||||
ISCHAR (3) &&
|
||||
ISCHAR (4))
|
||||
{
|
||||
|
||||
char *pcStringToMatch1 = hb_parc (1);
|
||||
size_t sStrToMatchLen1 = hb_parclen (1);
|
||||
char *pcString1 = hb_parc (2);
|
||||
size_t sStrLen1 = hb_parclen (2);
|
||||
char *pcStringToMatch2 = hb_parc (3);
|
||||
size_t sStrToMatchLen2 = hb_parclen (3);
|
||||
char *pcString2 = hb_parc (4);
|
||||
size_t sStrLen2 = hb_parclen (4);
|
||||
|
||||
char *pc1, *pc2;
|
||||
size_t sOffset1, sOffset2;
|
||||
size_t sMatchStrLen;
|
||||
|
||||
/* check for empty strings */
|
||||
if ((sStrToMatchLen1 == 0) ||
|
||||
(sStrToMatchLen2 == 0))
|
||||
{
|
||||
hb_retnl (0);
|
||||
return;
|
||||
}
|
||||
|
||||
sOffset1 = 0;
|
||||
sOffset2 = 0;
|
||||
|
||||
/* NOTE: this algorithm is not the best since the search that gave
|
||||
the larger relative position in the step before is repeated;
|
||||
try a search algorithm alternating between both strings */
|
||||
while ((sOffset1 < sStrLen1) && (sOffset2 < sStrLen2))
|
||||
{
|
||||
pc1 = ct_at_exact_forward (pcStringToMatch1, sStrToMatchLen1,
|
||||
pcString1+sOffset1, sStrLen1-sOffset1,
|
||||
&sMatchStrLen);
|
||||
pc2 = ct_at_exact_forward (pcStringToMatch2, sStrToMatchLen2,
|
||||
pcString2+sOffset2, sStrLen2-sOffset2,
|
||||
&sMatchStrLen);
|
||||
if ((pc1 != NULL) && (pc2 != NULL))
|
||||
{
|
||||
if ((pc1-pcString1) == (pc2-pcString2))
|
||||
{
|
||||
/* correlation found */
|
||||
hb_retnl ((pc1-pcString1)+1);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((pc1-pcString1) > (pc2-pcString2))
|
||||
{
|
||||
sOffset1 = sOffset2 = (pc1-pcString1);
|
||||
}
|
||||
else
|
||||
{
|
||||
sOffset1 = sOffset2 = (pc2-pcString2);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sOffset1 = sOffset2 = (sStrLen1 < sStrLen2 ? sStrLen1 : sStrLen2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
hb_retnl (0);
|
||||
return;
|
||||
|
||||
}
|
||||
else /* ISCHAR (1) &&
|
||||
ISCHAR (2) &&
|
||||
ISCHAR (3) &&
|
||||
ISCHAR (4) */
|
||||
{
|
||||
PHB_ITEM pSubst = NULL;
|
||||
int iArgErrorMode = ct_getargerrormode();
|
||||
if (iArgErrorMode != CT_ARGERR_IGNORE)
|
||||
{
|
||||
pSubst = ct_error_subst ((USHORT)iArgErrorMode, EG_ARG, CT_ERROR_CHARRELA,
|
||||
NULL, "CHARRELA", 0, EF_CANSUBSTITUTE, 4,
|
||||
hb_paramError (1), hb_paramError (2),
|
||||
hb_paramError (3), hb_paramError (4));
|
||||
}
|
||||
|
||||
if (pSubst != NULL)
|
||||
{
|
||||
hb_itemReturn (pSubst);
|
||||
hb_itemRelease (pSubst);
|
||||
}
|
||||
else
|
||||
{
|
||||
hb_retnl (0);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* $DOC$
|
||||
* $FUNCNAME$
|
||||
* CHARRELREP()
|
||||
* $CATEGORY$
|
||||
* CT3 string functions
|
||||
* $ONELINER$
|
||||
* Relation dependant character replacement
|
||||
* $SYNTAX$
|
||||
* CHARRELREP (<cStringToMatch1>, <cString1>,
|
||||
* <cStringToMatch2>, <[@]cString2>,
|
||||
* <cReplacement>) -> cString
|
||||
* $ARGUMENTS$
|
||||
* $RETURNS$
|
||||
* $DESCRIPTION$
|
||||
* TODO: add documentation
|
||||
* $EXAMPLES$
|
||||
* $TESTS$
|
||||
* $STATUS$
|
||||
* Started
|
||||
* $COMPLIANCE$
|
||||
* CHARRELREP() is compatible with CT3's CHARRELREP().
|
||||
* $PLATFORMS$
|
||||
* All
|
||||
* $FILES$
|
||||
* Source is relation.c, library is libct.
|
||||
* $SEEALSO$
|
||||
* CHARRELA(),CSETREF()
|
||||
* $END$
|
||||
*/
|
||||
|
||||
HB_FUNC (CHARRELREP)
|
||||
{
|
||||
|
||||
int iNoRet;
|
||||
|
||||
iNoRet = ct_getref();
|
||||
|
||||
if (ISCHAR (1) &&
|
||||
ISCHAR (2) &&
|
||||
ISCHAR (3) &&
|
||||
ISCHAR (4) &&
|
||||
ISCHAR (5))
|
||||
{
|
||||
|
||||
char *pcStringToMatch1 = hb_parc (1);
|
||||
size_t sStrToMatchLen1 = hb_parclen (1);
|
||||
char *pcString1 = hb_parc (2);
|
||||
size_t sStrLen1 = hb_parclen (2);
|
||||
char *pcStringToMatch2 = hb_parc (3);
|
||||
size_t sStrToMatchLen2 = hb_parclen (3);
|
||||
char *pcString2 = hb_parc (4);
|
||||
size_t sStrLen2 = hb_parclen (4);
|
||||
char *pcReplace = hb_parc (5);
|
||||
size_t sReplaceLen = hb_parclen (5);
|
||||
|
||||
char *pcRet;
|
||||
|
||||
char *pc1, *pc2;
|
||||
size_t sOffset1, sOffset2;
|
||||
size_t sMatchStrLen;
|
||||
|
||||
/* check for empty strings */
|
||||
if ((sStrToMatchLen1 == 0) ||
|
||||
(sStrToMatchLen2 == 0) ||
|
||||
(sReplaceLen == 0))
|
||||
{
|
||||
if (iNoRet)
|
||||
{
|
||||
hb_ret();
|
||||
}
|
||||
else
|
||||
{
|
||||
hb_retclen (pcString2, sStrLen2);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
pcRet = hb_xgrab (sStrLen2);
|
||||
hb_xmemcpy (pcRet, pcString2, sStrLen2);
|
||||
|
||||
sOffset1 = 0;
|
||||
sOffset2 = 0;
|
||||
|
||||
/* NOTE: this algorithm is not the best since the search that gave
|
||||
the larger relative position in the step before is repeated;
|
||||
try a search algorithm alternating between both strings */
|
||||
while ((sOffset1 < sStrLen1) && (sOffset2 < sStrLen2))
|
||||
{
|
||||
pc1 = ct_at_exact_forward (pcStringToMatch1, sStrToMatchLen1,
|
||||
pcString1+sOffset1, sStrLen1-sOffset1,
|
||||
&sMatchStrLen);
|
||||
pc2 = ct_at_exact_forward (pcStringToMatch2, sStrToMatchLen2,
|
||||
pcString2+sOffset2, sStrLen2-sOffset2,
|
||||
&sMatchStrLen);
|
||||
if ((pc1 != NULL) && (pc2 != NULL))
|
||||
{
|
||||
if ((pc1-pcString1) == (pc2-pcString2))
|
||||
{
|
||||
/* correlation found -> start replacement */
|
||||
size_t sCurr;
|
||||
|
||||
for (sCurr = 1; sCurr <= sStrToMatchLen1; sCurr++)
|
||||
{
|
||||
/* check if pcString2 is long enough */
|
||||
if ((pc2-pcString2)+sCurr >= sStrLen2)
|
||||
{
|
||||
size_t sStr2Offset, sReplOffset;
|
||||
sStr2Offset = (sStrToMatchLen2 < sCurr ? sStrToMatchLen2 : sCurr);
|
||||
sReplOffset = (sReplaceLen < sCurr ? sReplaceLen : sCurr);
|
||||
|
||||
/* do the characters in pcString2 and pcStrToMatch2 match ? */
|
||||
if (*(pc2+sCurr-1) == *(pcStringToMatch2+sStr2Offset-1))
|
||||
{
|
||||
*(pcRet+(pc2-pcString2)+sCurr-1) = *(pcReplace+sReplOffset-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
sOffset1 = sOffset2 = (pc1-pcString1)+1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((pc1-pcString1) > (pc2-pcString2))
|
||||
{
|
||||
sOffset1 = sOffset2 = (pc1-pcString1);
|
||||
}
|
||||
else
|
||||
{
|
||||
sOffset1 = sOffset2 = (pc2-pcString2);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sOffset1 = sOffset2 = (sStrLen1 < sStrLen2 ? sStrLen1 : sStrLen2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (ISBYREF (4))
|
||||
{
|
||||
hb_storclen (pcRet, sStrLen2, 4);
|
||||
}
|
||||
|
||||
if (iNoRet)
|
||||
{
|
||||
hb_ret();
|
||||
}
|
||||
else
|
||||
{
|
||||
hb_retclen (pcRet, sStrLen2);
|
||||
}
|
||||
|
||||
hb_xfree (pcRet);
|
||||
|
||||
}
|
||||
else /* ISCHAR (1) &&
|
||||
ISCHAR (2) &&
|
||||
ISCHAR (3) &&
|
||||
ISCHAR (4) &&
|
||||
ISCHAR (5) */
|
||||
{
|
||||
PHB_ITEM pSubst = NULL;
|
||||
int iArgErrorMode = ct_getargerrormode();
|
||||
if (iArgErrorMode != CT_ARGERR_IGNORE)
|
||||
{
|
||||
pSubst = ct_error_subst ((USHORT)iArgErrorMode, EG_ARG, CT_ERROR_CHARRELREP,
|
||||
NULL, "CHARRELREP", 0, EF_CANSUBSTITUTE, 5, hb_paramError (1),
|
||||
hb_paramError (2), hb_paramError (3),
|
||||
hb_paramError (4), hb_paramError (5));
|
||||
}
|
||||
|
||||
if (pSubst != NULL)
|
||||
{
|
||||
hb_itemReturn (pSubst);
|
||||
hb_itemRelease (pSubst);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (iNoRet)
|
||||
{
|
||||
hb_ret();
|
||||
}
|
||||
else
|
||||
{
|
||||
hb_retc ("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user