From 8fdb5c558b332908791b0be0c2b4087c9b2749cc Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 12 Jun 2012 19:56:14 +0000 Subject: [PATCH] 2012-06-12 21:55 UTC+0200 Viktor Szakats (vszakats syenar.net) - examples/hbapollo - examples/hbbtree - examples/hscript - examples/misc - examples/terminal - deleted obsolete and/or unmaintained components --- harbour/ChangeLog | 8 + harbour/examples/hbapollo/apollo.c | 327 --- harbour/examples/hbapollo/apollo.ch | 148 -- harbour/examples/hbapollo/apollo1.prg | 68 - harbour/examples/hbapollo/hbapollo.hbc | 13 - harbour/examples/hbapollo/hbapollo.hbp | 23 - harbour/examples/hbapollo/readme.txt | 28 - harbour/examples/hbapollo/tests/apollo.prg | 158 -- harbour/examples/hbapollo/tests/hbmk.hbm | 7 - harbour/examples/hbbtree/doc/en/hb_btree.txt | 869 -------- harbour/examples/hbbtree/hb_btree.c | 2069 ------------------ harbour/examples/hbbtree/hb_btree.ch | 70 - harbour/examples/hbbtree/hb_btree.h | 63 - harbour/examples/hbbtree/hbbtree.hbc | 8 - harbour/examples/hbbtree/hbbtree.hbp | 16 - harbour/examples/hbbtree/tbtree.prg | 78 - harbour/examples/hbbtree/tests/ctest.c | 224 -- harbour/examples/hbbtree/tests/hbmk.hbm | 7 - harbour/examples/hbbtree/tests/test.hbp | 11 - harbour/examples/hbbtree/tests/test.prg | 329 --- harbour/examples/hbbtree/tests/ttest.prg | 198 -- harbour/examples/hscript/cgi.ch | 28 - harbour/examples/hscript/dir.hs | 54 - harbour/examples/hscript/hello.hs | 43 - harbour/examples/hscript/hscript.hbp | 5 - harbour/examples/hscript/hscript.prg | 220 -- harbour/examples/hscript/multiply.hs | 54 - harbour/examples/hscript/readme.txt | 89 - harbour/examples/hscript/ugly.hs | 19 - harbour/examples/misc/guess.prg | 57 - harbour/examples/misc/mankala.prg | 173 -- harbour/examples/terminal/readme.txt | 134 -- harbour/examples/terminal/terminal.hbc | 7 - harbour/examples/terminal/terminal.prg | 517 ----- harbour/examples/terminal/trm_app.hbp | 8 - harbour/examples/terminal/trm_app.prg | 195 -- harbour/examples/terminal/trm_cli.hbp | 7 - harbour/examples/terminal/trm_cli.prg | 808 ------- harbour/examples/terminal/trm_srv.hbp | 7 - harbour/examples/terminal/trm_srv.prg | 437 ---- 40 files changed, 8 insertions(+), 7576 deletions(-) delete mode 100644 harbour/examples/hbapollo/apollo.c delete mode 100644 harbour/examples/hbapollo/apollo.ch delete mode 100644 harbour/examples/hbapollo/apollo1.prg delete mode 100644 harbour/examples/hbapollo/hbapollo.hbc delete mode 100644 harbour/examples/hbapollo/hbapollo.hbp delete mode 100644 harbour/examples/hbapollo/readme.txt delete mode 100644 harbour/examples/hbapollo/tests/apollo.prg delete mode 100644 harbour/examples/hbapollo/tests/hbmk.hbm delete mode 100644 harbour/examples/hbbtree/doc/en/hb_btree.txt delete mode 100644 harbour/examples/hbbtree/hb_btree.c delete mode 100644 harbour/examples/hbbtree/hb_btree.ch delete mode 100644 harbour/examples/hbbtree/hb_btree.h delete mode 100644 harbour/examples/hbbtree/hbbtree.hbc delete mode 100644 harbour/examples/hbbtree/hbbtree.hbp delete mode 100644 harbour/examples/hbbtree/tbtree.prg delete mode 100644 harbour/examples/hbbtree/tests/ctest.c delete mode 100644 harbour/examples/hbbtree/tests/hbmk.hbm delete mode 100644 harbour/examples/hbbtree/tests/test.hbp delete mode 100644 harbour/examples/hbbtree/tests/test.prg delete mode 100644 harbour/examples/hbbtree/tests/ttest.prg delete mode 100644 harbour/examples/hscript/cgi.ch delete mode 100644 harbour/examples/hscript/dir.hs delete mode 100644 harbour/examples/hscript/hello.hs delete mode 100644 harbour/examples/hscript/hscript.hbp delete mode 100644 harbour/examples/hscript/hscript.prg delete mode 100644 harbour/examples/hscript/multiply.hs delete mode 100644 harbour/examples/hscript/readme.txt delete mode 100644 harbour/examples/hscript/ugly.hs delete mode 100644 harbour/examples/misc/guess.prg delete mode 100644 harbour/examples/misc/mankala.prg delete mode 100644 harbour/examples/terminal/readme.txt delete mode 100644 harbour/examples/terminal/terminal.hbc delete mode 100644 harbour/examples/terminal/terminal.prg delete mode 100644 harbour/examples/terminal/trm_app.hbp delete mode 100644 harbour/examples/terminal/trm_app.prg delete mode 100644 harbour/examples/terminal/trm_cli.hbp delete mode 100644 harbour/examples/terminal/trm_cli.prg delete mode 100644 harbour/examples/terminal/trm_srv.hbp delete mode 100644 harbour/examples/terminal/trm_srv.prg diff --git a/harbour/ChangeLog b/harbour/ChangeLog index b3a84b3313..6882f29360 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,14 @@ The license applies to all entries newer than 2009-04-28. */ +2012-06-12 21:55 UTC+0200 Viktor Szakats (vszakats syenar.net) + - examples/hbapollo + - examples/hbbtree + - examples/hscript + - examples/misc + - examples/terminal + - deleted obsolete and/or unmaintained components + 2012-06-12 21:14 UTC+0200 Viktor Szakats (harbour syenar.net) * examples/hbbtree/tests/ctest.c ! converted Windows type to Harbour one diff --git a/harbour/examples/hbapollo/apollo.c b/harbour/examples/hbapollo/apollo.c deleted file mode 100644 index f0a0ddf283..0000000000 --- a/harbour/examples/hbapollo/apollo.c +++ /dev/null @@ -1,327 +0,0 @@ -/* - * $Id$ - */ - -/* - * Harbour Project source code: - * VistaSoftware's Apollo database driver. See http://www.VistaSoftware.com - * - * Copyright 2001 Patrick Mast - * www - http://harbour-project.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this software; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). - * - * As a special exception, the Harbour Project gives permission for - * additional uses of the text contained in its release of Harbour. - * - * The exception is that, if you link the Harbour libraries with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the Harbour library code into it. - * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. - * - * This exception applies only to the code released by the Harbour - * Project under the name Harbour. If you copy code from other - * Harbour Project or Free Software Foundation releases into a copy of - * Harbour, as the General Public License permits, the exception does - * not apply to the code that you add in this way. To avoid misleading - * anyone as to the status of such modified files, you must delete - * this exception notice from them. - * - * If you write modifications of your own for Harbour, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. - * - */ - -/* -----------------29/12/2001 19:23----------------- - * NOTE: Functions are listed alfabetically - * --------------------------------------------------*/ - -/* NOTE: This hack is needed to suppress 'non-ANSI - keyword' warnings inside Sde61.h. */ -#if defined( __BORLANDC__ ) || defined( __WATCOMC__ ) - #define _declspec __declspec -#endif - -#include "hbapi.h" - -#if defined( HB_OS_WIN ) - #include -#endif - -#if defined( HB_WITH_APOLLO_VER61 ) - #include "Sde61.h" -#else - #include "sde7.h" -#endif - -/* Uncomment for previous version */ -/* */ - -HB_FUNC( SX_APPENDBLANK ) -{ - sx_AppendBlank(); -} - -HB_FUNC( SX_CLOSE ) -{ - sx_Close(); -} - -HB_FUNC( SX_COMMIT ) -{ - sx_Commit(); -} - -HB_FUNC( SX_CREATEEXEC ) -{ - sx_CreateExec(); -} - -/* -----------------29/12/2001 19:18----------------- - * sx_CreateField() - * --------------------------------------------------*/ -HB_FUNC( SX_CREATEFIELD ) -{ - sx_CreateField( ( PBYTE ) hb_parc( 1 ), /* Field name */ - ( PBYTE ) hb_parc( 2 ), /* Field type */ - ( SHORT ) hb_parni( 3 ), /* Field lenght */ - ( SHORT ) hb_parni( 4 ) ); /* Field decimals */ -} - -/* -----------------29/12/2001 19:59----------------- - * sx_CreateNew() - * => The work area number assigned to the database. - * --------------------------------------------------*/ -HB_FUNC( SX_CREATENEW ) -{ - hb_retni( - sx_CreateNew( ( PBYTE ) hb_parc( 1 ), /* Field name */ - ( PBYTE ) hb_parc( 2 ), /* Alias */ - ( SHORT ) hb_parni( 3 ), /* RDE Type */ - ( SHORT ) hb_parni( 4 ) ) ); /* The maximum number of fields to be added to the file structure */ -} - -HB_FUNC( SX_EOF ) -{ - hb_retl( sx_Eof() ); -} - -/* -----------------29/12/2001 20:13----------------- - * sx_GetDateJulian() => The date expressed as a long integer. Useful for date arithmetic. - * Extracts the contents of a date field as a Julian number. - * This number is equal to the number of days since January 1, 4713 BC. - * However, only JULIAN dates equal or greater than January 1, 1000 are supported. - * --------------------------------------------------*/ -HB_FUNC( SX_GETDATEJULIAN ) -{ - hb_retni( sx_GetDateJulian( ( PBYTE ) hb_parc( 1 ) ) ); /* Field name */ -} - -/* -----------------30/12/2001 13:04----------------- - * sx_GetLogical() => True if the field evaluates as True, and False if not. - * Determines whether a logical field contains a True or False value. - * --------------------------------------------------*/ -HB_FUNC( SX_GETLOGICAL ) -{ - hb_retl( sx_GetLogical( ( PBYTE ) hb_parc( 1 ) ) ); /* Field name */ -} - -HB_FUNC( SX_GETSTRING ) -{ - hb_retc( ( char * ) sx_GetString( ( PBYTE ) hb_parc( 1 ) ) ); /* Field name */ -} - -/* -----------------30/12/2001 12:21----------------- - * sx_GetVariant() => Character fields are returned as untrimmed strings. - * --------------------------------------------------*/ -HB_FUNC( SX_GETVARIANT ) -{ - hb_retc( ( char * ) sx_GetVariant( ( PBYTE ) hb_parc( 1 ) ) ); /* Field name */ -} - -HB_FUNC( SX_GO ) -{ - sx_Go( hb_parni( 1 ) ); -} - -HB_FUNC( SX_GOBOTTOM ) -{ - sx_GoBottom(); -} - -HB_FUNC( SX_GOTOP ) -{ - sx_GoTop(); -} - -HB_FUNC( SX_INDEXTAG ) -{ - hb_retni( - sx_IndexTag( ( PBYTE ) hb_parc( 1 ), /* Field name */ - ( PBYTE ) hb_parc( 2 ), /* Tag name */ - ( PBYTE ) hb_parc( 3 ), /* Index expression as a string */ - ( SHORT ) hb_parni( 4 ), /* Option (0=Standard) (1=Unique) (2=Roll-Your-Own) */ - hb_parl( 5 ), /* True for a descend index */ - ( PBYTE ) hb_parc( 6) ) ); /* Condition */ -} - -HB_FUNC( SX_RECCOUNT ) -{ - hb_retni( sx_RecCount() ); -} - -HB_FUNC( SX_RECNO ) -{ - hb_retni( sx_RecNo() ); -} - -HB_FUNC( SX_REINDEX ) -{ - sx_Reindex(); -} - -HB_FUNC( SX_REPLACE ) -{ - switch( hb_parni( 2 ) ) - { - case R_INTEGER : - case R_JULIAN : sx_Replace( ( PBYTE ) hb_parc( 1 ), ( SHORT ) hb_parni( 2 ), ( void * ) hb_parni( 3 ) ); break; - case R_LOGICAL : sx_Replace( ( PBYTE ) hb_parc( 1 ), ( SHORT ) hb_parni( 2 ), ( void * ) hb_parni( 3 ) ); break; /* TODO: somthing is wrong here... */ - case R_LONG : sx_Replace( ( PBYTE ) hb_parc( 1 ), ( SHORT ) hb_parni( 2 ), ( void * ) hb_parnl( 3 ) ); break; - case R_DOUBLE : - { - double d = hb_parnd( 3 ); - sx_Replace( ( PBYTE ) hb_parc( 1 ), ( SHORT ) hb_parni( 2 ), ( void * ) &d ); - break; - } - case R_CHAR : - case R_DATESTR : - case R_MEMO : - case R_BITMAP : - case R_BLOBFILE: - case R_BLOBPTR : sx_Replace( ( PBYTE ) hb_parc( 1 ), ( SHORT ) hb_parni( 2 ), ( void * ) hb_parc( 3 ) ); break; - default: sx_Replace( ( PBYTE ) hb_parc( 1 ), ( SHORT ) hb_parni( 2 ), ( void * ) hb_parc( 3 ) ); - } -} - -HB_FUNC( SX_RLOCK ) -{ - sx_Rlock( hb_parni( 1 ) ); /* The physical record number of the record to be locked. */ -} - -HB_FUNC( SX_SEEK ) -{ - hb_retl( sx_Seek( ( PBYTE ) hb_parc( 1 ) ) ); /* The value to search for as a string */ -} - -/* -----------------20/01/2002 13:36----------------- - * sx_Select() => The previous select area is returned. - * If there was no previous area active, zero is returned. - * --------------------------------------------------*/ -HB_FUNC( SX_SELECT ) -{ - hb_retni( sx_Seek( ( PBYTE ) hb_parc( 1 ) ) ); /* The work area number returned when the file was opened. */ -} - -/* -----------------30/12/2001 12:30----------------- - * sx_SetCentury() => NILL - * Indicates whether or not the two digits of the year designating - * century are to be returned by sx_GetDateString as part of a date - * string formatted according to the sx_SetDateFormat setting. - * --------------------------------------------------*/ -HB_FUNC( SX_SETCENTURY ) -{ - sx_SetCentury( hb_parl( 1 ) ? 1 : 0 ); /* If True, the century digits will be returned. - * If False, they will not. */ -} - -/* -----------------30/12/2001 12:32----------------- - * sx_SetDateFormat() => NILL - * Defines the format of date strings returned by sx_GetDateString. - * --------------------------------------------------*/ -HB_FUNC( SX_SETDATEFORMAT ) -{ - sx_SetDateFormat( hb_parl( 1 ) ? 1 : 0 ); /* If True, the century digits will be returned. - * If False, they will not. */ -} - -HB_FUNC( SX_SETMEMOBLOCKSIZE ) -{ - sx_SetMemoBlockSize( ( WORD ) hb_parni( 1 ) ); /* The new default block size. - * The size must be a value from 1 through 1024. */ -} - -/* -----------------20/01/2002 13:33----------------- - * sx_SetOrder() => The previous index order identifier in use is returned. - * If zero, there was no previous index order in use. - * --------------------------------------------------*/ -HB_FUNC( SX_SETORDER ) -{ - hb_retni( sx_SetOrder( ( SHORT ) hb_parni( 1 ) ) ); /* Selects an existing order as the controlling index order. */ -} - -HB_FUNC( SX_SETSOFTSEEK ) -{ - sx_SetSoftSeek( hb_parl( 1 ) ? 1 : 0 ); /* True to set softseek ON */ -} - -HB_FUNC( SX_SKIP ) -{ - sx_Skip( hb_parnl( 1 ) ); /* Number of records to skip */ -} - -/* -----------------20/01/2002 14:2----------------- - * sx_SysProp() => Varies depending on the type of data being requested. - * LONG SDEAPI WINAPI sx_SysProp (WORD uiSysItem, PVOID vpData); - * --------------------------------------------------*/ -HB_FUNC( SX_SYSPROP ) -{ - int i = hb_parni( 2 ); - hb_retni( - sx_SysProp( ( WORD ) hb_parni( 1 ), /* One of the predefined constant values. See Apollo.ch */ - ( void * ) &i ) ); -} -/* -HB_FUNC( SX_DISABLEAUTOOPEN ) -{ - int i = 1; - sx_SysProp( 1013, ( void * ) &i ); -} -*/ - -HB_FUNC( SX_USE ) -{ - hb_retni( - sx_Use( ( PBYTE ) hb_parc( 1 ), /* Filename */ - ( PBYTE ) hb_parc( 2 ), /* Alias */ - ( SHORT ) hb_parni( 3 ), /* OpenMode */ - ( SHORT ) hb_parni( 4 ) ) ); /* RDE Type */ -} - -HB_FUNC( SX_VERSION ) -{ - hb_retc( ( char * ) sx_Version() ); -} - -HB_FUNC( SX_ZAP ) -{ - sx_Zap(); -} diff --git a/harbour/examples/hbapollo/apollo.ch b/harbour/examples/hbapollo/apollo.ch deleted file mode 100644 index 1ba97e244d..0000000000 --- a/harbour/examples/hbapollo/apollo.ch +++ /dev/null @@ -1,148 +0,0 @@ -/* - * $Id$ - */ - -/* - * Harbour Project source code: - * Apollo SIXNSX defines - * - * Copyright 2001 Patrick Mast - * www - http://harbour-project.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this software; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). - * - * As a special exception, the Harbour Project gives permission for - * additional uses of the text contained in its release of Harbour. - * - * The exception is that, if you link the Harbour libraries with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the Harbour library code into it. - * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. - * - * This exception applies only to the code released by the Harbour - * Project under the name Harbour. If you copy code from other - * Harbour Project or Free Software Foundation releases into a copy of - * Harbour, as the General Public License permits, the exception does - * not apply to the code that you add in this way. To avoid misleading - * anyone as to the status of such modified files, you must delete - * this exception notice from them. - * - * If you write modifications of your own for Harbour, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. - * - */ - -/* ************* */ -/* date types */ -/* ************* */ -#define SX_AMERICAN 0 -#define SX_ANSI 1 -#define SX_BRITISH 2 -#define SX_FRENCH 3 -#define SX_GERMAN 4 -#define SX_ITALIAN 5 -#define SX_SPANISH 6 - -/* ************************************ */ -/* Data type identifiers for sx_Replace */ -/* ************************************ */ -#define SX_R_INTEGER 1 -#define SX_R_LONG 2 -#define SX_R_DOUBLE 8 -#define SX_R_JULIAN 32 -#define SX_R_LOGICAL 128 -#define SX_R_CHAR 1024 -#define SX_R_DATESTR 1056 -#define SX_R_MEMO 3072 -#define SX_R_BITMAP 4096 -#define SX_R_BLOBFILE 8192 -#define SX_R_BLOBPTR 8193 -#define SX_R_GENERAL 8195 - -#define SX_SDENTX 1 // CA-Cl*pper compatible DBF-NTX driver -#define SX_SDEFOX 2 // FoxPro compatible DBF-IDX/CDX driver -#define SX_SDENSX 3 // Vista DBF-NSX driver - -#define SX_READWRITE 0 -#define SX_READONLY 1 -#define SX_EXCLUSIVE 2 - - -/* ******************************** */ -/* sx_SysProp Constants */ -/* ******************************** */ -// Global Task Information -// Gets should always be even numbers -#define SDE_SP_GETSOFTSEEK 1000 // Get the softseek flag -#define SDE_SP_SETSOFTSEEK 1001 // Set the softseek flag -#define SDE_SP_GETEXACT 1002 // Get the extact flag -#define SDE_SP_SETEXACT 1003 // Set the extact flag -#define SDE_SP_GETDELETED 1006 // Get the deleted flag -#define SDE_SP_PUTOBUFFER 1007 // Write the optimistic buffer on commit -#define SDE_SP_GETOBUFFER 1008 // Get the optimistic buffer flag -#define SDE_SP_SETOBUFFER 1009 // Set the optimistic buffer flag -#define SDE_SP_GETSTRINGTYPE 1010 // Get the stringtype flag -#define SDE_SP_SETSTRINGTYPE 1011 // Set the stringtype flag -#define SDE_SP_GETDISABLEAUTO 1012 // Get the disable auto open flag -#define SDE_SP_SETDISABLEAUTO 1013 // Set the disable auto open flag - -#define SDE_SP_SETOEMCOLLATE 1101 // Set the collation sequence for OEM tables. -#define SDE_SP_GETOEMCOLLATE 1111 // Get the collation sequence for OEM tables. -#define SDE_SP_SETCHRCOLLATE 1102 // Set the collation sequence for Win tables. -#define SDE_SP_GETCHRCOLLATE 1122 // Get the collation sequence for Win tables. -#define SDE_SP_SETLGTRCOLLATE 1103 // Set the ligatures collation dimmension -#define SDE_SP_GETLGTRCOLLATE 1133 // Get the ligatures collation dimmension - -#define SDE_SP_SETSPECIALCOLLATE 1108 // Set the international collation like DUDEN collate flag -#define SDE_SP_GETSPECIALCOLLATE 1109 // Set the international collation like DUDEN collate flag -#define SDE_SP_GETLANGUAGECOLLATE 1110 // Get language, according to collation done - -#define SDE_SP_GETDUDENCOLLATE 1104 // get the German DUDEN collate flag -#define SDE_SP_SETDUDENCOLLATE 1105 // set the German DUDEN collate flag -#define SDE_SP_GETLIMITCASECONV 1106 // limit case conv to A-Z, a-z if TRUE -#define SDE_SP_SETLIMITCASECONV 1107 // limit case conv to A-Z, a-z if TRUE - -// Behavior settings which bridge the differences between 1.40 and 2.00 -#define SDE_SP_GETADDQUERY 1300 // Get the AddQueryFlag -#define SDE_SP_SETADDQUERY 1301 // Set the AddQueryFlag -#define SDE_SP_GETUSECONDITIONAL 1302 // Get the bUseConditional flag -#define SDE_SP_SETUSECONDITIONAL 1303 // Get the bUseConditional flag -#define SDE_SP_SETWRITEBLOBHDR 1305 // Set the bWriteBlobHdr -#define SDE_SP_GETQUERYRELAXFLAG 1306 // Get flag that dictates rules of query -#define SDE_SP_SETQUERYRELAXFLAG 1307 // Set flag that dictates rules of query - -// WorkArea information -#define SDE_SP_GETDRIVER 2000 // Get the active driver - -#define SDE_SP_SETSTRDEFLEN 2001 // Set the default lenght for STR, if 2nd parameter is absent and field lenght zero -#define SDE_SP_SETSTRDEFDEC 2002 // Set the default decimals for STR, if 3d parameter is absent and field lenght zero - -#define SDE_SP_SETDEFAPPEND 2003 // Set default behavior for ordering ordering for non-unique key like FOX/Clipper -#define SDE_SP_SETMEMOMIXED 2004 // Set pure Clipper's memo for NSX driver -#define SDE_SP_BDESPECIFIC 2005 // Set the treatment of LIKE operator in accoring to BDE -#define SDE_SP_DBASEDATEHEADER 2006 // Set the using of DBF header in according to DbaseIII+ specification -#define SDE_SP_SETAUTOPAD 2007 -#define SDE_SP_GETAUTOPAD 2008 - -// Index information for current workarea -#define SDE_SP_GETINDEXCOUNT 3000 // Get the number of indexes -#define SDE_SP_GETDESCENDING 3002 // Get the descending flag -#define SDE_SP_GETEMPTY 3004 // Get the empty index flag diff --git a/harbour/examples/hbapollo/apollo1.prg b/harbour/examples/hbapollo/apollo1.prg deleted file mode 100644 index bf151639d2..0000000000 --- a/harbour/examples/hbapollo/apollo1.prg +++ /dev/null @@ -1,68 +0,0 @@ -/* - * $Id$ - */ - -/* - * Harbour Project source code: - * VistaSoftware's Apollo database driver. See http://www.VistaSoftware.com - * - * Copyright 2001 Patrick Mast - * www - http://harbour-project.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this software; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). - * - * As a special exception, the Harbour Project gives permission for - * additional uses of the text contained in its release of Harbour. - * - * The exception is that, if you link the Harbour libraries with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the Harbour library code into it. - * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. - * - * This exception applies only to the code released by the Harbour - * Project under the name Harbour. If you copy code from other - * Harbour Project or Free Software Foundation releases into a copy of - * Harbour, as the General Public License permits, the exception does - * not apply to the code that you add in this way. To avoid misleading - * anyone as to the status of such modified files, you must delete - * this exception notice from them. - * - * If you write modifications of your own for Harbour, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. - * - */ - -#include "rddsys.ch" - -/* ANNOUNCE APOLLO */ - -INIT PROCEDURE ApolloInit - -/* - REQUEST _Apollo - - rddRegister( "Apollo", RDT_FULL ) -*/ - - RETURN - -FUNCTION sx_GetVal( x ) - RETURN Val( sx_Getvariant( x ) ) diff --git a/harbour/examples/hbapollo/hbapollo.hbc b/harbour/examples/hbapollo/hbapollo.hbc deleted file mode 100644 index 1ea99fdf48..0000000000 --- a/harbour/examples/hbapollo/hbapollo.hbc +++ /dev/null @@ -1,13 +0,0 @@ -# -# $Id$ -# - -{dos}skip=yes - -incpaths=. -libpaths=lib/${hb_plat}/${hb_comp} - -libs=${hb_name} - -libs={win&&HB_WITH_APOLLO_VER61}sde61 -libs={win&&!HB_WITH_APOLLO_VER61}sde7 diff --git a/harbour/examples/hbapollo/hbapollo.hbp b/harbour/examples/hbapollo/hbapollo.hbp deleted file mode 100644 index f90f535644..0000000000 --- a/harbour/examples/hbapollo/hbapollo.hbp +++ /dev/null @@ -1,23 +0,0 @@ -# -# $Id$ -# - --hblib --inc - --olib/${hb_plat}/${hb_comp}/${hb_name} - --w3 -es2 - -{HB_WITH_APOLLO_VER61}-depkeyhead=apollo:Sde61.h -{!HB_WITH_APOLLO_VER61}-depkeyhead=apollo:Sde7.h --depcontrol=apollo:${HB_WITH_APOLLO} --depincpath=apollo:/usr/include --depincpath=apollo:/boot/common/include - -{HB_WITH_APOLLO_VER61}-cflags=-DHB_WITH_APOLLO_VER61 - --instfile=inc:apollo.ch - -apollo.c -apollo1.prg diff --git a/harbour/examples/hbapollo/readme.txt b/harbour/examples/hbapollo/readme.txt deleted file mode 100644 index 4eaccb7eea..0000000000 --- a/harbour/examples/hbapollo/readme.txt +++ /dev/null @@ -1,28 +0,0 @@ -/* - * $Id$ - */ - - RDD for VistaSoftware's Apollo Database Engine - (Server and/or Local) - Patrick Mast - - To build hbapollo.lib you need these files: - - sde62.dll ( you need this to build sde62.lib ) - - sde62.lib ( build it using implib sde62.lib sde62.dll ) - - sde62.h ( SDE C/C++ header file for sde62.dll ) - - Don't forget to include hbapollo.lib and sde62.lib to your - the make file or link script to build executables. - - To use a application that uses hbapollo.lib you need this file: - - sde62.dll ( The Apollo Engine ) - The SDE is VistaSoftware's 32-bit database engine which contains - the database technology that all Apollo products rely on to - perform the low-level data management and manipulation. - - - Be aware that this is a work in progress. Any comments are welcome. - More to come! ;-) - - Patrick Mast - December 2001 diff --git a/harbour/examples/hbapollo/tests/apollo.prg b/harbour/examples/hbapollo/tests/apollo.prg deleted file mode 100644 index 930a9f4e2c..0000000000 --- a/harbour/examples/hbapollo/tests/apollo.prg +++ /dev/null @@ -1,158 +0,0 @@ -/* - * $Id$ - */ - -/* - * Harbour Project source code: - * Test VistaSoftware's Apollo database driver. See http://www.VistaSoftware.com - * - * Copyright 2001 Patrick Mast - * 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 "apollo.ch" - - -PROCEDURE Main() -LOCAL nAlias -LOCAL f - - SET DATE FRENCH - SET CENTURY ON - - sx_SetMemoBlockSize( 32 ) - sx_SetDateFormat( SX_FRENCH ) - sx_SetCentury( .T. ) - - ? "Apollo version " + sx_Version() - - ? "" - ? "Cleaning up files.." - FErase( "test.dbf" ) - FErase( "test.smt" ) - FErase( "test.nsx" ) - ? "OK!" - - ? "" - ? "Creating a new database file.." - nAlias := sx_CreateNew("test.dbf",; // full path filename - "test1",; // Alias - SX_SDENSX,; // rdeType - 6) // Maximum fields added by sx_CreateField - IF nAlias == 0 - ? "Error creating database" - RETURN - ENDIF - - sx_CreateField("FIRST" ,"C",40,0) - sx_CreateField("LAST" ,"C",40,0) - sx_CreateField("NOTES" ,"M",10,0) - sx_CreateField("AGE" ,"N", 4,0) - sx_CreateField("MARRIED" ,"L", 1,0) - sx_CreateField("BIRTDATE","D", 8,0) - - sx_CreateExec() - sx_Close() - ?? "OK!" - - nAlias := sx_Use("test.dbf","test2",SX_EXCLUSIVE,SX_SDENSX) - sx_Zap() - IF Valtype(nAlias) == "N" .AND. nAlias != 0 - ? "OK opening 'test.dbf'" - - - ? "Adding 1000 records..." - FOR f := 1 to 1000 - sx_AppendBlank() - sx_Replace("FIRST" , SX_R_CHAR , "Patrick " + Str( f ) ) - sx_Replace("LAST" , SX_R_CHAR , LTrim( Str( f ) ) + " Mast" ) - sx_Replace("NOTES" , SX_R_MEMO , "This is record " + LTrim( Str( f ) ) ) - sx_Replace("AGE" , SX_R_DOUBLE , f ) - sx_Replace("BIRTDATE" , SX_R_DATESTR, DtoC( Date() ) ) - // sx_Replace("MARRIED" , SX_R_LOGICAL, iif(f%5==2,1,0) ) /* Logical does not work yet.. */ - sx_Commit() - NEXT - - - ? "Creating Index..." - sx_IndexTag(,"LAST","LAST+FIRST",0) - ? "Created a HiPer-Six index. See 'test.nsx'" - - - sx_GoTop() - WHILE !sx_Eof() - ? "" - ? "RecNo...... : " + LTrim( Str( sx_RecNo() ) ) - ? "Last name.. : " + sx_GetVariant( "LAST" ) - ? "Birth date. : " + sx_GetVariant( "BIRTDATE" ) - ? "Married.... : " + iif( sx_GetLogical( "MARRIED" ) , "Yes", "No, SINGLE!!") - sx_Skip(1) - ENDDO - - - ? "" - sx_GoTop() - sx_SetSoftSeek( .F. ) // SetSoftSeek OFF - IF sx_Seek( "928 Mast" ) - ? "String '928 Mast' found in record number "+ LTrim( Str( sx_RecNo() ) ) - ELSE - ? "String '928 Mast' NOT Found..." - ENDIF - - - ? "" - ? "There are "+LTrim( Str( sx_RecCount() ) )+" records in the database" - - ? - ? "Reindexing now..." - sx_ReIndex() - ?? "OK!" - - - sx_Close() - - ELSE - ? "ERROR Opening 'test.dbf'" - ENDIF - -return diff --git a/harbour/examples/hbapollo/tests/hbmk.hbm b/harbour/examples/hbapollo/tests/hbmk.hbm deleted file mode 100644 index a7ca888e69..0000000000 --- a/harbour/examples/hbapollo/tests/hbmk.hbm +++ /dev/null @@ -1,7 +0,0 @@ -# -# $Id$ -# - -../hbapollo.hbc - --w3 -es2 diff --git a/harbour/examples/hbbtree/doc/en/hb_btree.txt b/harbour/examples/hbbtree/doc/en/hb_btree.txt deleted file mode 100644 index f7f39bcc99..0000000000 --- a/harbour/examples/hbbtree/doc/en/hb_btree.txt +++ /dev/null @@ -1,869 +0,0 @@ -/* - $Id$ -*/ - -/* - * Harbour Project source code: - * HB_BTree C and Harbour API documentation. - * - * Copyright 2002 April White - * 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 of the License, or - * (at your option) any later version, with one exception: - * - * The exception is that if you link the Harbour Runtime Library (HRL) - * and/or the Harbour Virtual Machine (HVM) 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 HRL - * and/or HVM code into it. - * - * 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 program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit - * their web site at http://www.gnu.org/). - * - */ - -/* $DOC$ - * $FUNCNAME$ - * BTree Notes - * $CATEGORY$ - * BTree API - * $ONELINER$ - * Prentice Hall (publisher) letter of approval - * $DESCRIPTION$ - * Subject: RE: B-tree request - * Date: 10 Jul 2000 09:18:50 -0400 - * From: Petra_Recter@prenhall.com - * To: awhite@user.rose.com [now april@users.sourceforge.net] - * - * Dear April: - * - * I have consulted the author and I am happy to grant permission to your request. - * Pls. take my email as formal approval. - * - * Sincerely, - * - * Petra Recter - * Senior Acquisitions Editor, Computer Science - * Prentice Hall - * One Lake Street - #3F66 - * Upper Saddle River, NJ 07458 - * - * Email: petra_recter@prenhall.com - * Tel: (201) 236-7186 Fax: (201) 236-7170 - * - * -----Original Message----- - * From: awhite@user.rose.com [mailto:awhite@user.rose.com] - * Sent: Thursday, June 29, 2000 6:55 PM - * To: webmaster@prenhall.com - * Subject: request for use of copyright material - * - * regarding ISBN 0-13-725649-3 "Data Structures and Program Design in C" - * by Kruse Robert L., Leung Bruce P., and Tondo Clovis L.; (c) 1991 - * Prentice-Hall Inc - * - * Within a chapter of this book (section 10-3, External Searching: - * B-Trees) there are very clear examples for the manipulation of b-trees. - * I have successfully converted this code to perform true file i/o - * (whereas the examples use in-memory b-trees). - * - * I am a member of a group of programmers developing an Open Source - * compiler called 'Harbour'. This compiler is intended as a replacement - * for a commercial product called 'Clipper' (Computer Associates). If you - * are interested in learning more about Harbour, please see - * http://www.harbour-project.org/ - * - * The Harbour project is governed by the GNU Public License [GPL] (please - * see http://www.gnu.org/) with a caveat that applications produced by - * the Harbour compiler may not be covered by GPL. - * - * I wish to contribute my version of the code and possibly code more akin - * to the examples in the book (to create in-memory b-trees). I am willing - * to submit a copy of my code to Prentice-Hall for you perusal. - * - * If you have any questions that I cannot answer myself, I will forward - * them to the project leaders for their consideration. - * - * I eagerly wait your favourable reply. - * - * Thank you, - * April White - * $END$ - */ - -/* $DOC$ - * $FUNCNAME$ - * BTree Flags - * $CATEGORY$ - * BTree API - * $ONELINER$ - * Description of flags used to control access of a BTree file - * $DESCRIPTION$ - * BTree file creation/access flags: - * - * HB_BTREE_READONLY: - * - * hb_BTreeNew() - when set, the file I/O mode FC_READONLY is used, creating - * a file with the read-only attribute set; insertions and deletions are - * permitted - * - * hb_BTreeOpen() - when set, the file I/O mode FO_READONLY is used, - * preventing insertions or deletions to the BTree; if the BTree file - * has the read-only file attribute set, the flag HB_BTREE_EXCLUSIVE is - * assumed and activates internal API optimizations - * - * HB_BTREE_EXCLUSIVE - when set, the file I/O mode FO_EXCLUSIVE is used, - * preventing shared access, and activates internal API optimizations - * - * HB_BTREE_SHARED - when set, the file I/O mode FO_SHARED is used, and - * disables all internal API optimizations. This flag cannot be used - * with the HB_BTREE_READONLY flag when calling hb_BTreeNew() - in this - * case, HB_BTREE_READONLY has precedance over HB_BTREE_SHARED - * - * BTree control flags: - * - * HB_BTREE_UNIQUE - when set, the key and data together determine uniqueness; - * when not set, the key alone determines uniqueness. This flag cannot - * be used with the HB_BTREE_INMEMORY flag! - * - * HB_BTREE_CASELESS - when set, comparison of keys is done in a case-insensitive - * manner; when not set, comparisons are case sensitive - * - * HB_BTREE_INMEMORY - when set, the BTree is built and maintained entirely - * in memory; when not set, the BTree is built and maintained as a file. - * The use of this flag precludes the use of the creation/access flags listed - * above - an in-memory BTree cannot be shared, made read-only, and is also - * exclusive by definition. This flag cannot be used with hb_BTreeOpen(). - * This flag is mutually exclusive of the HB_BTREE_UNIQUE. - * $SEEALSO$ - * hb_BTreeNew(), hb_BTreeOpen() - * $END$ - */ - -/* $DOC$ - * $FUNCNAME$ - * hb_BTreeNew() - * $CATEGORY$ - * BTree API - * $ONELINER$ - * Create a new BTree file - * $SYNTAX$ - * C Prototype - * - * #include "hb_btree.api" - * hb_BTreeNew( CHAR , int , int , [ ULONG ], [ USHORT =1 ] ) -> ( struct hb_BTree * )pHBTree - * - * Harbour Prototype - * - * hb_BTreeNew( CHAR , , , [ ], [ =1 ] ) -> ( int )hb_BTree_Handle - * - * Harbour Class Prototype - * - * TBTreeNew( CHAR , , , [ ], [ =1 ] ) -> - * $ARGUMENTS$ - * Name of BTree file to create. This parameter is optional - * if the flag HB_BTREE_INMEMORY is used - * - * Number of bytes one file 'page' is to be; must be a multiple of 2048. - * If the hb_btree library is compiled with the value HB_BTREE_HEADERSIZE - * defined to another value, that is used in place of 2048 - * - * Number of bytes a key value is to be; must be 8 bytes or greater - * - * Flags that determine the file access mode(s) and BTree mode(s) - * - * Number of internal I/O buffers to use - not currently supported for shared/dynamic use - * $RETURNS$ - * C Prototype - * - * A pointer to an hb_BTree structure, to be used by other hb_BTree C API calls - * - * Harbour Prototype - * - * A handle, to be used by other hb_BTree Harbour API calls - * - * Harbour Class Prototype - * - * An instance of the TBTree class - * $DESCRIPTION$ - * - * $EXAMPLES$ - * - * $FILES$ - * Library is hb_btree - * Header is hb_btree.ch - * C Header is hb_btree.api - * $PLATFORMS$ - * All - * $SEEALSO$ - * BTree Flags - * $END$ - */ - -/* $DOC$ - * $FUNCNAME$ - * hb_BTreeOpen() - * $CATEGORY$ - * BTree API - * $ONELINER$ - * Open an existing BTree file - * $SYNTAX$ - * C Prototype - * - * #include "hb_btree.api" - * hb_BTreeOpen( CHAR , [ ULONG ], [ USHORT =1 ] ] ) -> ( struct hb_BTree * )pHBTree - * - * Harbour Prototype - * - * hb_BTreeOpen( , [ ], [ =1 ] ) -> ( int )hb_BTree_Handle - * - * Harbour Class Prototype - * - * TBTreeOpen( , [ ], [ =1 ] ) -> - * $ARGUMENTS$ - * Name of BTree file to open - * - * Flags that determine the file access mode(s) and BTree mode(s) - * - * Number of internal I/O buffers to use - not currently supported for shared/dynamic use - * $RETURNS$ - * C Prototype - * - * A pointer to an hb_BTree structure, to be used by other hb_BTree C API calls - * - * Harbour Prototype - * - * A handle, to be used by other hb_BTree Harbour API calls - * - * Harbour Class Prototype - * - * An instance of the TBTree class - * $DESCRIPTION$ - * - * $EXAMPLES$ - * - * $FILES$ - * Library is hb_btree - * Header is hb_btree.ch - * C Header is hb_btree.api - * $PLATFORMS$ - * All - * $SEEALSO$ - * BTree Flags - * $END$ - */ - -/* $DOC$ - * $FUNCNAME$ - * hb_BTreeClose() - * $CATEGORY$ - * BTree API - * $ONELINER$ - * Close an active BTree file - * $SYNTAX$ - * C Prototype - * - * #include "hb_btree.api" - * hb_BTreeClose( struct hb_BTree * ) -> NIL - * - * Harbour Prototype - * - * hb_BTreeClose( ) -> NIL - * - * Harbour Class Prototype - * - * :Close() -> Nil - * $ARGUMENTS$ - * C Prototype - * - * A pointer to an hb_BTree structure, returned from hb_BTreeOpen() or hb_BTreeNew() - * - * Harbour Prototype - * - * A handle, returned from hb_BTreeOpen() or hb_BTreeNew() - * - * Harbour Class Prototype - * - * An instance of the TBTree class - * $RETURNS$ - * Nothing. - * $DESCRIPTION$ - * - * $EXAMPLES$ - * - * $FILES$ - * Library is hb_btree - * Header is hb_btree.ch - * C Header is hb_btree.api - * $PLATFORMS$ - * All - * $SEEALSO$ - * - * $END$ - */ - -/* $DOC$ - * $FUNCNAME$ - * hb_BTreeInsert() - * $CATEGORY$ - * BTree API - * $ONELINER$ - * Insert a key/data element into an active BTree file - * $SYNTAX$ - * C Prototype - * - * #include "hb_btree.api" - * hb_BTreeInsert( struct hb_BTree * , CHAR , LONG ) -> - * - * Harbour Prototype - * - * hb_BTreeInsert( , , | ) -> - * - * Harbour Class Prototype - * - * :Insert( , | ) -> - * $ARGUMENTS$ - * C Prototype - * - * A pointer to an hb_BTree structure, returned from hb_BTreeOpen() or hb_BTreeNew() - * - * A pointer to a CHAR buffer, representing a key value to be inserted - * - * A long data value to associate with the value - * - * Harbour Prototype - * - * A handle, returned from hb_BTreeOpen() or hb_BTreeNew() - * - * A string, representing a key value to be inserted - * - * A numeric data value to associate with the value, or - * Any value to associate with the value - * - * Harbour Class Prototype - * - * An instance of the TBTree class - * - * A string, representing a key value to be inserted - * - * A numeric data value to associate with the value, or - * Any value to associate with the value - * $RETURNS$ - * Logical value indicating whether the operation succeeded - * $DESCRIPTION$ - * - * $EXAMPLES$ - * - * $FILES$ - * Library is hb_btree - * Header is hb_btree.ch - * C Header is hb_btree.api - * $PLATFORMS$ - * All - * $SEEALSO$ - * - * $END$ - */ - -/* $DOC$ - * $FUNCNAME$ - * hb_BTreeDelete() - * $CATEGORY$ - * BTree API - * $ONELINER$ - * Delete a key/data element from an active BTree file - * $SYNTAX$ - * C Prototype - * - * #include "hb_btree.api" - * hb_BTreeDelete( struct hb_BTree * , CHAR , LONG ) -> - * - * Harbour Prototype - * - * hb_BTreeDelete( , , ) -> - * - * Harbour Class Prototype - * - * :Delete( , ) -> - * $ARGUMENTS$ - * C Prototype - * - * A pointer to an hb_BTree structure, returned from hb_BTreeOpen() or hb_BTreeNew() - * - * A string, representing a key value to be deleted - * - * A numeric data value to associate with the value - * - * Harbour Prototype - * - * A handle, returned from hb_BTreeOpen() or hb_BTreeNew() - * - * A string, representing a key value to be deleted - * - * A numeric data value to associate with the value - * - * Harbour Class Prototype - * - * An instance of the TBTree class - * - * A string, representing a key value to be deleted - * - * A numeric data value to associate with the value - * $RETURNS$ - * Logical value indicating whether the operation succeeded - * $DESCRIPTION$ - * - * $EXAMPLES$ - * - * $FILES$ - * Library is hb_btree - * Header is hb_btree.ch - * C Header is hb_btree.api - * $PLATFORMS$ - * All - * $SEEALSO$ - * - * $END$ - */ - -/* $DOC$ - * $FUNCNAME$ - * hb_BtreeKey() - * $CATEGORY$ - * BTree API - * $ONELINER$ - * Returns active key of an active BTree file - * $SYNTAX$ - * C Prototype - * - * #include "hb_btree.api" - * hb_BtreeKey( struct hb_BTree * ) -> CHAR - * - * Harbour Prototype - * - * hb_BtreeKey( ) -> - * - * Harbour Class Prototype - * - * :Key() -> - * $ARGUMENTS$ - * C Prototype - * - * A pointer to an hb_BTree structure, returned from hb_BTreeOpen() or hb_BTreeNew() - * - * Harbour Prototype - * - * A handle, returned from hb_BTreeOpen() or hb_BTreeNew() - * - * Harbour Class Prototype - * - * An instance of the TBTree class - * $RETURNS$ - * C Prototype - * - * A pointer to a CHAR buffer containing the active key value - * - * Harbour Prototype - * - * A string containing the active key value - * - * Harbour Class Prototype - * - * A string containing the active key value - * $DESCRIPTION$ - * - * $EXAMPLES$ - * - * $FILES$ - * Library is hb_btree - * Header is hb_btree.ch - * C Header is hb_btree.api - * $PLATFORMS$ - * All - * $SEEALSO$ - * - * $END$ - */ - -/* $DOC$ - * $FUNCNAME$ - * hb_BtreeData() - * $CATEGORY$ - * BTree API - * $ONELINER$ - * Returns the active data value for an active BTree file - * $SYNTAX$ - * C Prototype - * - * #include "hb_btree.api" - * hb_BtreeData( struct hb_BTree * ) -> LONG - * - * Harbour Prototype - * - * hb_BtreeData( ) -> | - * - * Harbour Class Prototype - * - * :Data() -> | - * $ARGUMENTS$ - * C Prototype - * - * A pointer to an hb_BTree structure, returned from hb_BTreeOpen() or hb_BTreeNew() - * - * Harbour Prototype - * - * A handle, returned from hb_BTreeOpen() or hb_BTreeNew() - * - * Harbour Class Prototype - * - * An instance of the TBTree class - * $RETURNS$ - * C Prototype - * - * The long value associated with the active key - * - * Harbour Prototype - * - * The numeric value associated with the active key, or - * The value associated with an active key of an in-memory btree - * - * Harbour Class Prototype - * - * The numeric value associated with the active key, or - * The value associated with an active key of an in-memory btree - * $DESCRIPTION$ - * - * $EXAMPLES$ - * - * $FILES$ - * Library is hb_btree - * Header is hb_btree.ch - * C Header is hb_btree.api - * $PLATFORMS$ - * All - * $SEEALSO$ - * hb_BtreeDataItem() - * $END$ - */ - -/* $DOC$ - * $FUNCNAME$ - * hb_BtreeDataItem() - * $CATEGORY$ - * BTree C API - * $ONELINER$ - * Returns the active data value for an active BTree file - * $SYNTAX$ - * #include "hb_btree.api" - * hb_BtreeDataItem( struct hb_BTree * ) -> PHB_ITEM - * $ARGUMENTS$ - * A pointer to an hb_BTree structure, returned from hb_BTreeOpen() or hb_BTreeNew() - * $RETURNS$ - * A pointer to a constant PHB_ITEM value, or NIL if none was assigned - * $DESCRIPTION$ - * - * $EXAMPLES$ - * - * $FILES$ - * Library is hb_btree - * C Header is hb_btree.api - * $PLATFORMS$ - * All - * $SEEALSO$ - * hb_BtreeData() - * $END$ - */ - -/* $DOC$ - * $FUNCNAME$ - * hb_BTreeGoTop() - * $CATEGORY$ - * BTree API - * $ONELINER$ - * Position an active BTree file at its logical first key/data entry - * $SYNTAX$ - * C Prototype - * - * #include "hb_btree.api" - * hb_BTreeGoTop( struct hb_BTree * ) -> void - * - * Harbour Prototype - * - * hb_BTreeGoTop( ) -> NIL - * - * Harbour Class Prototype - * - * :GoTop() -> NIL - * $ARGUMENTS$ - * C Prototype - * - * A pointer to an hb_BTree structure, returned from hb_BTreeOpen() or hb_BTreeNew() - * - * Harbour Prototype - * - * A handle, returned from hb_BTreeOpen() or hb_BTreeNew() - * - * Harbour Class Prototype - * - * An instance of the TBTree class - * $RETURNS$ - * Nothing. - * $DESCRIPTION$ - * - * $EXAMPLES$ - * - * $FILES$ - * Library is hb_btree - * Header is hb_btree.ch - * C Header is hb_btree.api - * $PLATFORMS$ - * All - * $SEEALSO$ - * - * $END$ - */ - -/* $DOC$ - * $FUNCNAME$ - * hb_BTreeGoBottom() - * $CATEGORY$ - * BTree API - * $ONELINER$ - * Position an active BTree file at its logical last key/data entry - * $SYNTAX$ - * C Prototype - * - * #include "hb_btree.api" - * hb_BTreeGoBottom( struct hb_BTree * ) -> void - * - * Harbour Prototype - * - * hb_BTreeGoBottom( ) -> NIL - * - * Harbour Class Prototype - * - * :GoBottom() -> NIL - * $ARGUMENTS$ - * C Prototype - * - * A pointer to an hb_BTree structure, returned from hb_BTreeOpen() or hb_BTreeNew() - * - * Harbour Prototype - * - * A handle, returned from hb_BTreeOpen() or hb_BTreeNew() - * - * Harbour Class Prototype - * - * An instance of the TBTree class - * $RETURNS$ - * Nothing. - * $DESCRIPTION$ - * - * $EXAMPLES$ - * - * $FILES$ - * Library is hb_btree - * Header is hb_btree.ch - * C Header is hb_btree.api - * $PLATFORMS$ - * All - * $SEEALSO$ - * - * $END$ - */ - -/* $DOC$ - * $FUNCNAME$ - * hb_BTreeSkip() - * $CATEGORY$ - * BTree API - * $ONELINER$ - * Position an active BTree file forward or backward relative to the active key/data entry - * $SYNTAX$ - * C Prototype - * - * #include "hb_btree.api" - * hb_BTreeSkip( struct hb_BTree * , LONG ) -> LONG - * - * Harbour Prototype - * - * hb_BTreeSkip( , LONG ) -> - * - * Harbour Class Prototype - * - * :Skip( LONG ) -> - * $ARGUMENTS$ - * C Prototype - * - * A pointer to an hb_BTree structure, returned from hb_BTreeOpen() or hb_BTreeNew() - * - * Number of BTree entries to skip over - * - * Harbour Prototype - * - * A handle, returned from hb_BTreeOpen() or hb_BTreeNew() - * - * Number of BTree entries to skip over - * - * Harbour Class Prototype - * - * An instance of the TBTree class - * - * Number of BTree entries to skip over - * $RETURNS$ - * Number of records actually skipped - * $DESCRIPTION$ - * - * $EXAMPLES$ - * - * $FILES$ - * Library is hb_btree - * Header is hb_btree.ch - * C Header is hb_btree.api - * $PLATFORMS$ - * All - * $SEEALSO$ - * - * $END$ - */ - -/* $DOC$ - * $FUNCNAME$ - * hb_BTreeSeek() - * $CATEGORY$ - * BTree API - * $ONELINER$ - * Position an active BTree file using the passed key/data value - * $SYNTAX$ - * C Prototype - * - * #include "hb_btree.api" - * hb_BTreeSeek( struct hb_BTree * , CHAR , LONG , BOOL ) -> BOOL - * - * Harbour Prototype - * - * hb_BTreeSeek( , , , [ ] ) -> - * - * Harbour Class Prototype - * - * :Seek( , , ) - * $ARGUMENTS$ - * C Prototype - * - * A pointer to an hb_BTree structure, returned from hb_BTreeOpen() or hb_BTreeNew() - * - * A pointer to a CHAR buffer containing the key to locate - * - * The long value associated with the key. This may be passed as 0 - * if the flag HB_BTREE_UNIQUE is not used (which is also implied when the - * flag HB_BTREE_INMEMORY is used) - * - * Optional. Is a 'soft seek' method to be used? - * - * Harbour Prototype - * - * A handle, returned from hb_BTreeOpen() or hb_BTreeNew() - * - * A string containing the key to locate - * - * The long value associated with the key. This may be passed as 0 - * if the flag HB_BTREE_UNIQUE is not used (which is also implied when the - * flag HB_BTREE_INMEMORY is used) - * - * Optional. Is a 'soft seek' method to be used? - * - * Harbour Class Prototype - * - * An instance of the TBTree class - * - * A string containing the key to locate - * - * The long value associated with the key. This may be passed as 0 - * if the flag HB_BTREE_UNIQUE is not used (which is also implied when the - * flag HB_BTREE_INMEMORY is used) - * - * Optional. Is a 'soft seek' method to be used? - * $RETURNS$ - * Logical value indicating whether the operation succeeded - * $DESCRIPTION$ - * Note that when a soft seek is used, if a partial match is made, the - * function returns TRUE; this is contrary to the soft seek return value - * of the RDD system! - * $EXAMPLES$ - * - * $FILES$ - * Library is hb_btree - * Header is hb_btree.ch - * C Header is hb_btree.api - * $PLATFORMS$ - * All - * $SEEALSO$ - * - * $END$ - */ - -/* $DOC$ - * $FUNCNAME$ - * hb_BTreeInfo() - * $CATEGORY$ - * BTree API - * $ONELINER$ - * Return information about an active BTree file - * $SYNTAX$ - * Harbour Prototype - * - * hb_BTreeInfo( , [ ] ) -> | | - * - * Harbour Class Prototype - * - * :Info( ) -> | | - * $ARGUMENTS$ - * Harbour Prototype - * - * A handle, returned from hb_BTreeOpen() or hb_BTreeNew() - * - * Optional. One of: - * HB_BTREEINFO_ALL (0) - default value - * HB_BTREEINFO_FILENAME (1) - * HB_BTREEINFO_PAGESIZE (2) - * HB_BTREEINFO_KEYSIZE (3) - * HB_BTREEINFO_MAXKEYS (4) - * HB_BTREEINFO_MINKEYS (5) - * HB_BTREEINFO_FLAGS (6) - * HB_BTREEINFO_KEYCOUNT (7) - * - * Harbour Class Prototype - * - * An instance of the TBTree class - * - * (see above) - * $RETURNS$ - * For the index HB_BTREEINFO_ALL, an array containing all information elements, ordered as for the index values. - * - * For the index HB_BTREEINFO_FILENAME, a string containing the file name of the BTree file is returned. - * - * For all other index values, the numeric value corresponding to the index name (ie. page size, etc). - * $DESCRIPTION$ - * - * $EXAMPLES$ - * - * $FILES$ - * Library is hb_btree - * Header is hb_btree.ch - * C Header is hb_btree.api - * $PLATFORMS$ - * All - * $SEEALSO$ - * - * $END$ - */ diff --git a/harbour/examples/hbbtree/hb_btree.c b/harbour/examples/hbbtree/hb_btree.c deleted file mode 100644 index b700854db9..0000000000 --- a/harbour/examples/hbbtree/hb_btree.c +++ /dev/null @@ -1,2069 +0,0 @@ -/* - $Id$ - */ - -/* - * Harbour Project source code: - * HB_BTree source. - * - * Copyright 2002-2010 April White - * www - http://harbour-project.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version, with one exception: - * - * The exception is that if you link the Harbour Runtime Library (HRL) - * and/or the Harbour Virtual Machine (HVM) 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 HRL - * and/or HVM code into it. - * - * 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 program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit - * their web site at http://www.gnu.org/). - * - */ - -/* - TODO: - - determine how to handle page buffers in a multi-user environment - - replace some of the for..next loops through the key/branches that - move them around with memmove() - - this may not be feasible - in a multi-user environ, the stack - would become invalid; I would have to save the current key and then - locate the next/prev as needed, locking the file for the duration - (as well, page buffering would not be allowed because a page in - memory would become invalid) - - complete Move() API - - when move right/left, follow any branch down - - when hit end of a node, pop from stack - - increment the position and follow branch down - - impliment ulFlags within hb_btreeopen() - see warning above - - clear im-memory flag - - get unique flag from file header - - detect change to header, only write the header as needed - - build page output buffer then write it - - read page input buffer then split it - - make MT safe - - TOFIX: - - remove UNION's as they hide 32/64 size problems - - use HB_U32 as the standard data type of file reading/writing - - in-memory btree's cause a fatal error; this is a work in progress - */ - -#include "hbvm.h" -#include "hbapi.h" -#include "hbapiitm.h" -#include "hbapifs.h" -#include "hbapierr.h" -#include "hbinit.h" - -#include "hb_btree.h" - -HB_EXTERN_BEGIN - -#if ! defined( DEBUG ) && ! defined( NDEBUG ) - #define NDEBUG -#else - #define PrintCRLF() hb_conOutStd( hb_conNewLine(), strlen( hb_conNewLine() ) ) -#endif - -#if defined( __GNUC__ ) - - #if 0 - #define STRINGIFY_2( n ) #n - #define STRINGIFY_1( n ) STRINGIFY_2( n ) - #define SRCLINENO __FUNCTION__ " (" STRINGIFY_1( __LINE__ ) ")" - #define FILESRCLINENO __FILE__ "." SRCLINENO - #elif 0 - #define SRCLINENO __FUNCTION__ - #else - #define SRCLINENO "%s (%d)", __FUNCTION__, __LINE__ - #endif - -#else -/* - #define STRINGIFY_2( n ) #n - #define STRINGIFY_1( n ) STRINGIFY_2( n ) - #define SRCLINENO ( __FILE__ " (" STRINGIFY_1( __LINE__ ) ")" ) - */ - #define SRCLINENO "" -#endif - -#define HEADER_ID "BTR\x10" - -#define NULLPAGE 0L - -#define BTREENODEISNULL( pBTree, node ) ( HB_BOOL ) ( ( node ) == NULLPAGE ) -#define READPAGE_IF_NEEDED( pBTree, node ) if( node != \ - pBTree->ioBuffer->xPage.ulPage ) ioBufferScan( \ - pBTree, node ) -#define CLEARKEYDATA( pBTree ) ( ( pBTree )->pThisKeyData->szKey[ 0 ] = '\0', \ - ( pBTree )->pThisKeyData->xData.lData = 0, \ - ( pBTree )->pThisKeyData->xData.pData = NULL ) - -#undef HB_BTREE_HEADERSIZE -#define HB_BTREE_HEADERSIZE 2048 - -typedef struct stack_item -{ - HB_ULONG ulNode; - int iPosition; -} BTreeStackItem; - -typedef struct stack_tag -{ - HB_USHORT usCount; - BTreeStackItem items[ 1 ]; -} BTreeStack; - -#define STACKNODE( pStack ) ( *pStack )->items[ ( *pStack )->usCount - 1 ].ulNode -#define STACKPOSITION( pStack ) ( *pStack )->items[ ( *pStack )->usCount - 1 ].iPosition - -/* TODO: create two structs, one for in-memory, one for files */ -typedef struct ioBuffer_tag -{ - struct ioBuffer_tag * prev, * next; - union - { - HB_ULONG ulPage; /* not in-memory */ - struct ioBuffer_tag * pPage; /* in-memory */ - } xPage; - HB_BOOL IsDirty; - - /* was: Buffer_T pBuffer; */ - HB_ULONG * pulPageCount; /* TODO: use LE get macro to retrieve this; better yet, dont use this */ - HB_ULONG * pulBranch; - union - { - HB_LONG * plData; /* not in-memory */ - PHB_ITEM * ppData; /* in-memory */ - } xData; - HB_BYTE * szKey; - HB_BYTE Buffer[ 1 ]; -} ioBuffer_T; - -typedef int hb_BTreeFlags_T; - - -#define IsNormal 0 - -/* btree file access flags */ -#define IsReadOnly HB_BTREE_READONLY -#define IsExclusive HB_BTREE_EXCLUSIVE -#define IsShared HB_BTREE_SHARED - -/* btree control flags */ -#define IsUnique HB_BTREE_UNIQUE -#define IsCaseLess HB_BTREE_CASELESS -#define IsInMemory HB_BTREE_INMEMORY - -/* internal flags */ -#define IsRecordFound ( 1 << 16 ) -#define IsDuplicateKey ( 1 << 17 ) -#define IsMultiBuffers ( 1 << 18 ) -#define IsOptimized ( 1 << 19 ) - -#define GETFLAG( pBTree, flag ) ( HB_BOOL ) ( ( ( int ) ( pBTree )->ulFlags & ( flag ) ) == \ - ( flag ) ) -#define SETFLAG( pBTree, flag ) ( ( pBTree )->ulFlags |= ( flag ) ) -#define RESETFLAG( pBTree, flag ) ( ( pBTree )->ulFlags &= ~( flag ) ) - -/* TODO: if 64 bit the size of the union may be different so this code will fail to work as expected */ -typedef struct hb_KeyData_Tag -{ - union - { - HB_LONG lData; /* lData is placed first for alignment, thought it is secondary */ - PHB_ITEM pData; - } xData; - HB_BYTE szKey[ 1 ]; -} hb_KeyData_T; - -typedef int ( *BTreeCmpFunc )( const char * l, const char * r, size_t n ); - -struct hb_BTree -{ - char * szFileName; - HB_FHANDLE hFile; - HB_ULONG ulRootPage; - HB_ULONG ulFreePage; - HB_USHORT usPageSize; - HB_USHORT usKeySize; - HB_USHORT usMaxKeys; - HB_USHORT usMinKeys; - hb_BTreeFlags_T ulFlags; - HB_ULONG ulKeyCount; - hb_KeyData_T * pThisKeyData; - BTreeStack * pStack; - ioBuffer_T * ioBuffer; - void * BufferEnd; - HB_BOOL IsDirtyFlagAssignment; /* replaces const TRUE, and !GETFLAG( pBTree, IsInMemory ) */ - - BTreeCmpFunc pStrCompare; -}; - -#if ! defined( DEBUG ) && ! defined( NDEBUG ) -HB_BOOL IsDebugging = HB_FALSE; -#else - #define IsDebugging HB_FALSE -#endif - -static struct hb_BTree ** s_BTree_List = NULL; -static int s_BTree_List_Count = 0; - -/* forward declarations */ - -static HB_USHORT CountGet( struct hb_BTree * pBTree, HB_ULONG ulNode ); -static hb_KeyData_T * KeyGet( struct hb_BTree * pBTree, HB_ULONG ulNode, int iPosition, - hb_KeyData_T * buffer ); -static HB_ULONG BranchGet( struct hb_BTree * pBTree, HB_ULONG ulNode, int iPosition ); - -/* end of forward declarations */ - -static void raiseError( HB_ULONG ulGenCode, HB_ULONG ulSubCode, const char * szDescription, - const char * szOperation, - int uiArguments ) -{ - PHB_ITEM pErr = hb_errRT_New( - ES_ERROR /* HB_USHORT uiSeverity */, - "HB_BTREE" /* const char * szSubSystem */, - ulGenCode /* HB_ULONG ulGenCode */, - ulSubCode /* HB_ULONG ulSubCode */, - szDescription /* const char * szDescription */, - szOperation /* const char * szOperation */, - 0 /* HB_ERRCODE uiOsCode */, - EF_NONE /* HB_USHORT uiFlags */ - ); - - if( uiArguments > 0 ) - { - hb_errPutArgs( pErr, uiArguments, hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( - 3 ), hb_paramError( 4 ), hb_paramError( 5 ) ); - } - - hb_errLaunch( pErr ); - hb_errRelease( pErr ); -} - -static void * BufferRealloc( void * buffer, HB_ULONG size ) -{ - void * tmpBuffer = hb_xgrab( size ); - - if( buffer ) - { - hb_xmemcpy( tmpBuffer, buffer, size ); - hb_xfree( buffer ); - } -/* else - hb_xmemset( tmpBuffer, '\0', size );*/ - - return tmpBuffer; -} - -#define BufferAlloc( n ) BufferRealloc( NULL, ( n ) ) -#define BufferRelease( b ) hb_xfree( b ) - - -static ioBuffer_T * ioOneBufferAlloc( struct hb_BTree * pBTree, ioBuffer_T * prev, - ioBuffer_T * next ) -{ - ioBuffer_T * thisptr; - - thisptr = ( ioBuffer_T * ) BufferAlloc( sizeof( ioBuffer_T ) + pBTree->usPageSize ); - hb_xmemset( thisptr, '\0', sizeof( ioBuffer_T ) + pBTree->usPageSize ); - - thisptr->pulPageCount = ( HB_ULONG * ) ( thisptr->Buffer ); - thisptr->pulBranch = ( HB_ULONG * ) &thisptr->pulPageCount[ 1 ]; - - if( GETFLAG( pBTree, IsInMemory ) ) - { - thisptr->xData.ppData = ( PHB_ITEM * ) &thisptr->pulBranch[ pBTree->usMaxKeys + 1 ]; - thisptr->szKey = ( HB_BYTE * ) &thisptr->xData.ppData[ pBTree->usMaxKeys ]; - } - else - { - thisptr->xData.plData = ( HB_LONG * ) &thisptr->pulBranch[ pBTree->usMaxKeys + 1 ]; - thisptr->szKey = ( HB_BYTE * ) &thisptr->xData.plData[ pBTree->usMaxKeys ]; - } - - thisptr->xPage.ulPage = NULLPAGE; - thisptr->xPage.pPage = 0; - thisptr->IsDirty = HB_FALSE; - - thisptr->prev = prev; - thisptr->next = next; - - return thisptr; -} - -/* a link list 'most recently access' page buffering system */ -static void ioBufferAlloc( struct hb_BTree * pBTree, HB_ULONG ulBuffers ) -{ - ioBuffer_T * thisptr = NULL, * last = NULL; - - if( ulBuffers == 0 ) - ulBuffers = 1; - - if( ulBuffers > 1 || GETFLAG( pBTree, IsInMemory ) ) - { - SETFLAG( pBTree, IsMultiBuffers ); - } - else - { - RESETFLAG( pBTree, IsMultiBuffers ); - } - - while( ulBuffers-- > 0 ) - { - thisptr = ioOneBufferAlloc( pBTree, NULL, last ); - if( last ) - last->prev = thisptr; - last = thisptr; - } - - pBTree->ioBuffer = thisptr; -} - -static void ioBufferWrite( struct hb_BTree * pBTree, ioBuffer_T * thisptr ) -{ - hb_fsSeek( pBTree->hFile, thisptr->xPage.ulPage, FS_SET ); - if( hb_fsWrite( pBTree->hFile, thisptr->Buffer, pBTree->usPageSize ) != pBTree->usPageSize ) - { - raiseError( EG_WRITE, HB_BTREE_EC_WRITEERROR, "write error", "ioBufferWrite*", 0 ); - } - thisptr->IsDirty = HB_FALSE; -} - -static void ioBufferRead( struct hb_BTree * pBTree, HB_ULONG ulNode ) -{ - ioBuffer_T * thisptr = pBTree->ioBuffer; - - if( thisptr->IsDirty ) - { - ioBufferWrite( pBTree, thisptr ); - thisptr->IsDirty = HB_FALSE; - } - thisptr->xPage.ulPage = ulNode; - hb_fsSeek( pBTree->hFile, thisptr->xPage.ulPage, FS_SET ); - hb_fsRead( pBTree->hFile, thisptr->Buffer, pBTree->usPageSize ); -} - -static void ioBufferRelease( struct hb_BTree * pBTree ) -{ - ioBuffer_T * next, * thisptr; - HB_ULONG n; - - for( thisptr = pBTree->ioBuffer; thisptr; thisptr = next ) - { - next = thisptr->next; - if( thisptr->IsDirty ) /* cannot be in-memory in this case */ - { - ioBufferWrite( pBTree, thisptr ); - } - else if( GETFLAG( pBTree, IsInMemory ) ) - { - for( n = 0; n < *thisptr->pulPageCount; n++ ) - { -/* { printf( "%p", thisptr->xData.ppData[ n ] ); PrintCRLF(); }*/ - hb_itemRelease( thisptr->xData.ppData[ n ] ); - } - } - BufferRelease( thisptr ); - } - pBTree->ioBuffer = NULL; -} - -#if 0 /* keep just in case, but its functionality is built into ioBufferRelease */ -static void ioBufferFlush( struct hb_BTree * pBTree ) -{ - ioBuffer_T * thisptr; - - for( thisptr = pBTree->ioBuffer; thisptr; thisptr = thisptr->next ) - { - if( thisptr->IsDirty ) - ioBufferWrite( pBTree, thisptr ); - } -} -#endif - -static void ioBufferScan( struct hb_BTree * pBTree, HB_ULONG page ) -{ - ioBuffer_T * thisptr; - ioBuffer_T * thisnext, * thisprev; - - /* locate either the buffer the page is in, the first empty buffer, - or the last buffer in the list */ - for( thisptr = pBTree->ioBuffer; - thisptr && - ! BTREENODEISNULL( pBTree, - thisptr->xPage.ulPage ) && thisptr->xPage.ulPage != page && - thisptr->next; - thisptr = thisptr->next ) - { - } - - /* only shuffle the buffers if the target buffer is not the root buffer */ - if( thisptr != pBTree->ioBuffer ) - { - /* minimize writes */ - if( thisptr->xPage.ulPage != page && thisptr->IsDirty ) - { - ioBufferWrite( pBTree, thisptr ); - } - - thisprev = thisptr->prev; - thisnext = thisptr->next; - - if( thisnext ) - thisnext->prev = thisprev; - if( thisprev ) - thisprev->next = thisnext; - - thisptr->prev = NULL; - thisptr->next = pBTree->ioBuffer; - pBTree->ioBuffer->prev = thisptr; - pBTree->ioBuffer = thisptr; - } - else if( thisptr->IsDirty ) - ioBufferWrite( pBTree, thisptr ); - - /* Grow() will call this with a null page, to flush & shuffle buffers */ - if( ! BTREENODEISNULL( pBTree, - page ) && thisptr->xPage.ulPage != page && ! GETFLAG( pBTree, IsInMemory ) ) - { - ioBufferRead( pBTree, page ); - } -} - -static void StackNew( BTreeStack ** pStack ) -{ - *pStack = ( BTreeStack * ) BufferRealloc( *pStack, sizeof( **pStack ) ); - ( *pStack )->usCount = 0; -} - -static void StackPush( BTreeStack ** pStack, HB_ULONG ulNode, int iPosition ) -{ - *pStack = - ( BTreeStack * ) BufferRealloc( - *pStack, sizeof( **pStack ) + - ( ( *pStack )->usCount + 1 ) * sizeof( ( *pStack )->items[ 0 ] ) ); - ( *pStack )->items[ ( *pStack )->usCount ].ulNode = ulNode; - ( *pStack )->items[ ( *pStack )->usCount ].iPosition = iPosition; - ( *pStack )->usCount++; -} - -static void StackPop( BTreeStack ** pStack, HB_ULONG * pulNode, int * piPosition ) -{ - if( ( *pStack )->usCount ) - { - ( *pStack )->usCount--; - *pulNode = ( *pStack )->items[ ( *pStack )->usCount ].ulNode; - *piPosition = ( *pStack )->items[ ( *pStack )->usCount ].iPosition; - *pStack = - ( BTreeStack * ) BufferRealloc( - *pStack, sizeof( **pStack ) + - ( ( *pStack )->usCount + 1 ) * sizeof( ( *pStack )->items[ 0 ] ) ); - } -} - -static void StackPeek( BTreeStack ** pStack, HB_ULONG * pulNode, int * piPosition ) -{ - if( ( *pStack )->usCount ) - { - *pulNode = ( *pStack )->items[ ( *pStack )->usCount - 1 ].ulNode; - *piPosition = ( *pStack )->items[ ( *pStack )->usCount - 1 ].iPosition; - } - else - { - *pulNode = 0; - *piPosition = 0; - } -} - -static HB_LONG StackSkip( struct hb_BTree * pBTree, BTreeStack ** pStack, HB_LONG records ) -{ - HB_ULONG ulNode; - int iPosition; - HB_LONG recordsskipped = 0; - - if( ( *pStack )->usCount == 0 ) - { - /* todo: raise an error? */ - raiseError( EG_CORRUPTION, HB_BTREE_EC_STACKSKIP, "internal stack skip error", "StackSkip*", - 0 ); - } - - if( records == 0 ) - { - StackPeek( pStack, &ulNode, &iPosition ); - } - else if( records > 0 ) - { - while( records-- > 0 ) - { - ulNode = BranchGet( pBTree, STACKNODE( pStack ), STACKPOSITION( pStack ) ); - if( ! BTREENODEISNULL( pBTree, ulNode ) ) - { - StackPush( pStack, ulNode, STACKPOSITION( pStack ) ); - while( ! BTREENODEISNULL( pBTree, ( ulNode = BranchGet( pBTree, ulNode, 0 ) ) ) ) - { -/* StackPush( pStack, BranchGet( pBTree, ulNode, 0 ), 0 );*/ - StackPush( pStack, ulNode, 0 ); - } - STACKPOSITION( pStack ) = 1; - recordsskipped++; - } - else if( STACKPOSITION( pStack ) < CountGet( pBTree, STACKNODE( pStack ) ) ) - { - STACKPOSITION( pStack )++; - recordsskipped++; - } - else - { - StackPop( pStack, &ulNode, &iPosition ); - if( ( *pStack )->usCount == 0 ) - { - break; - } - else if( STACKPOSITION( pStack ) < CountGet( pBTree, STACKNODE( pStack ) ) ) - { - STACKPOSITION( pStack )++; - recordsskipped++; - } - else - { - STACKPOSITION( pStack )++; - records++; /* force the loop to retry */ - } - } - } - StackPeek( pStack, &ulNode, &iPosition ); - } - else /*if ( records < 0 )*/ - { - while( records++ < 0 ) - { - if( STACKPOSITION( pStack ) > 0 ) - ulNode = BranchGet( pBTree, STACKNODE( pStack ), --STACKPOSITION( pStack ) ); - else - ulNode = NULLPAGE; - if( ! BTREENODEISNULL( pBTree, ulNode ) ) - { - StackPush( pStack, ulNode, CountGet( pBTree, ulNode ) ); - while( ! BTREENODEISNULL( pBTree, - ( ulNode = - BranchGet( pBTree, ulNode, CountGet( pBTree, ulNode ) ) ) ) ) - { - StackPush( pStack, ulNode, CountGet( pBTree, ulNode ) ); - } - recordsskipped--; - } - else if( STACKPOSITION( pStack ) > 0 ) - { - recordsskipped--; - } - else - { - StackPop( pStack, &ulNode, &iPosition ); - if( ( *pStack )->usCount == 0 ) - { - break; - } - else if( STACKPOSITION( pStack ) > 0 ) - { - recordsskipped--; - } - else - { - records--; /* force the loop to retry */ - } - } - } - StackPeek( pStack, &ulNode, &iPosition ); - } - - if( ulNode == 0 && iPosition == 0 ) - CLEARKEYDATA( pBTree ); - else - KeyGet( pBTree, ulNode, iPosition, pBTree->pThisKeyData ); - - return recordsskipped; -} - -static void StackRelease( BTreeStack ** pStack ) -{ - if( *pStack ) - { - BufferRelease( *pStack ); - *pStack = NULL; - } -} - -static void HeaderWrite( struct hb_BTree * pBTree ) -{ - HB_BYTE TmpHeader[ HB_BTREE_HEADERSIZE ]; - HB_BYTE * pHeader = &TmpHeader[ 0 ]; - HB_U32 uiHeaderSize = HB_BTREE_HEADERSIZE; - - /* - header [4 bytes] - ulFreePage [4 bytes, little endian] - usPageSize [2 bytes, little endian] - usKeySize [2 bytes, little endian] - ulRootPage [4 bytes, little endian] - ulFlags [4 bytes, little endian] - ulKeyCount [4 bytes, little endian] - */ - - hb_xmemset( TmpHeader, '\0', sizeof( TmpHeader ) ); - - hb_xmemcpy( pHeader, HEADER_ID, sizeof( HEADER_ID ) - 1 ); pHeader += sizeof( HEADER_ID ) - 1; - HB_PUT_LE_UINT32( pHeader, uiHeaderSize ); pHeader += 4; - HB_PUT_LE_UINT32( pHeader, ( HB_U32 ) pBTree->usPageSize ); pHeader += 4; - HB_PUT_LE_UINT32( pHeader, ( HB_U32 ) pBTree->usKeySize ); pHeader += 4; - HB_PUT_LE_UINT32( pHeader, ( HB_U32 ) pBTree->usMaxKeys ); pHeader += 4; - HB_PUT_LE_UINT32( pHeader, ( HB_U32 ) pBTree->usMinKeys ); pHeader += 4; - HB_PUT_LE_UINT32( pHeader, pBTree->ulFlags ); - - pHeader = &TmpHeader[ 64 ]; - HB_PUT_LE_UINT32( pHeader, pBTree->ulRootPage ); pHeader += 4; - HB_PUT_LE_UINT32( pHeader, pBTree->ulFreePage ); pHeader += 4; - HB_PUT_LE_UINT32( pHeader, pBTree->ulKeyCount ); - - hb_fsSeek( pBTree->hFile, 0, FS_SET ); - if( hb_fsWrite( pBTree->hFile, TmpHeader, sizeof( TmpHeader ) ) != sizeof( TmpHeader ) ) - { - raiseError( EG_WRITE, HB_BTREE_EC_WRITEERROR, "write error", "HeaderWrite*", 0 ); - } -} - -static HB_ULONG Grow( struct hb_BTree * pBTree ) -{ - HB_TRACE( HB_TR_DEBUG, ( SRCLINENO ) ); - - if( GETFLAG( pBTree, IsInMemory ) ) - { - ioBuffer_T * thisptr; - - thisptr = ioOneBufferAlloc( pBTree, NULL, pBTree->ioBuffer ); - thisptr->xPage.pPage = thisptr; - if( pBTree->ioBuffer ) - pBTree->ioBuffer->prev = thisptr; - pBTree->ioBuffer = thisptr; - } - else - { - /* locate a page to use */ - ioBufferScan( pBTree, NULLPAGE ); - - if( BTREENODEISNULL( pBTree, pBTree->ulFreePage ) ) - { - HB_BYTE * buffer = pBTree->ioBuffer->Buffer; - - pBTree->ioBuffer->xPage.ulPage = hb_fsSeek( pBTree->hFile, 0, FS_END ); - hb_xmemset( buffer, '\0', pBTree->usPageSize ); - if( pBTree->usPageSize != hb_fsWrite( pBTree->hFile, buffer, pBTree->usPageSize ) ) - { - raiseError( EG_WRITE, HB_BTREE_EC_WRITEERROR, "write error", "Grow*", 0 ); - } - } - else - { - char buffer[ sizeof( pBTree->ulFreePage ) ]; - pBTree->ioBuffer->xPage.ulPage = hb_fsSeek( pBTree->hFile, pBTree->ulFreePage, FS_SET ); - hb_fsRead( pBTree->hFile, buffer, sizeof( pBTree->ulFreePage ) ); - pBTree->ulFreePage = HB_GET_LE_UINT32( buffer ); - } - pBTree->ioBuffer->IsDirty = HB_TRUE; - } - - return pBTree->ioBuffer->xPage.ulPage; -} - -static void Prune( struct hb_BTree * pBTree, HB_ULONG ulNode ) -{ - if( GETFLAG( pBTree, IsInMemory ) ) - { - ioBuffer_T * thisptr; - HB_ULONG n; - - for( thisptr = pBTree->ioBuffer; thisptr && thisptr->xPage.ulPage != ulNode; - thisptr = thisptr->next ) - { - } - - if( thisptr->prev ) - thisptr->prev->next = thisptr->next; - if( thisptr->next ) - thisptr->next->prev = thisptr->prev; - - if( thisptr == pBTree->ioBuffer ) /* root page */ - pBTree->ioBuffer = thisptr->next; - - for( n = 0; n < *thisptr->pulPageCount; n++ ) - { - hb_itemRelease( thisptr->xData.ppData[ n ] ); - } - hb_xfree( thisptr ); - } - else - { - char buffer[ sizeof( pBTree->ulFreePage ) ]; - hb_fsSeek( pBTree->hFile, ulNode, FS_SET ); - HB_PUT_LE_UINT32( buffer, pBTree->ulFreePage ); - if( hb_fsWrite( pBTree->hFile, buffer, - sizeof( pBTree->ulFreePage ) ) != sizeof( pBTree->ulFreePage ) ) - { - raiseError( EG_WRITE, HB_BTREE_EC_WRITEERROR, "write error", "Prune*", 0 ); - } - pBTree->ulFreePage = ulNode; - } -} - -static HB_USHORT CountGet( struct hb_BTree * pBTree, HB_ULONG ulNode ) -{ - READPAGE_IF_NEEDED( pBTree, ulNode ); - return ( HB_USHORT ) ( *pBTree->ioBuffer->pulPageCount ); -} - -static void CountSet( struct hb_BTree * pBTree, HB_ULONG ulNode, HB_ULONG newPageCount ) -{ - READPAGE_IF_NEEDED( pBTree, ulNode ); - *pBTree->ioBuffer->pulPageCount = newPageCount; - pBTree->ioBuffer->IsDirty = pBTree->IsDirtyFlagAssignment; -} - -static HB_USHORT CountAdj( struct hb_BTree * pBTree, HB_ULONG ulNode, HB_LONG adjPageCount ) -{ - READPAGE_IF_NEEDED( pBTree, ulNode ); - - *pBTree->ioBuffer->pulPageCount += adjPageCount; - pBTree->ioBuffer->IsDirty = pBTree->IsDirtyFlagAssignment; - - return ( HB_USHORT ) *pBTree->ioBuffer->pulPageCount; -} - -static void NodeCopy( struct hb_BTree * pBTree, HB_ULONG toNode, int toPosition, HB_ULONG fromNode, - int fromPosition, - hb_KeyData_T * buffer ) -{ - HB_ULONG ulBranch; - HB_LONG lData = 0; - PHB_ITEM pData = NULL; - - READPAGE_IF_NEEDED( pBTree, fromNode ); - ulBranch = pBTree->ioBuffer->pulBranch[ fromPosition ]; - - if( GETFLAG( pBTree, IsInMemory ) ) - { - pData = pBTree->ioBuffer->xData.ppData[ fromPosition - 1 ]; - } - else - { - lData = pBTree->ioBuffer->xData.plData[ fromPosition - 1 ]; - } - - hb_xmemcpy( buffer->szKey, pBTree->ioBuffer->szKey + ( fromPosition - 1 ) * pBTree->usKeySize, - pBTree->usKeySize ); - buffer->szKey[ pBTree->usKeySize ] = '\0'; - - READPAGE_IF_NEEDED( pBTree, toNode ); - pBTree->ioBuffer->pulBranch[ toPosition ] = ulBranch; - if( GETFLAG( pBTree, IsInMemory ) ) - { - pBTree->ioBuffer->xData.ppData[ toPosition - 1 ] = pData; - } - else - { - pBTree->ioBuffer->xData.plData[ toPosition - 1 ] = lData; - } - hb_xmemcpy( pBTree->ioBuffer->szKey + ( toPosition - 1 ) * pBTree->usKeySize, buffer->szKey, - pBTree->usKeySize ); - pBTree->ioBuffer->IsDirty = pBTree->IsDirtyFlagAssignment; -} - -static HB_ULONG BranchGet( struct hb_BTree * pBTree, HB_ULONG ulNode, int iPosition ) -{ - READPAGE_IF_NEEDED( pBTree, ulNode ); - return pBTree->ioBuffer->pulBranch[ iPosition ]; -} - -#if defined( DEBUG ) -static void Chk4Loop( struct hb_BTree * pBTree, HB_ULONG ulNode, int iPosition, HB_ULONG ulBranch ) -{ -/* - int i; - for ( i = 0; i < CountGet( pBTree, ulNode ); i++ ) - if ( i != iPosition && pBTree->ioBuffer->pulBranch[ i ] == ulBranch && ulBranch ) - { - HB_TRACE( HB_TR_ERROR, "Chk4Loop( nbranch %ld exists in page %ld (position %d, found at %d, count %d) )", - ( long )ulBranch, - ( long )ulNode, - ( int )iPosition, - ( int )i, - CountGet( pBTree, ulNode ) ); - } - */ - if( ulBranch > filelength( pBTree->hFile ) ) - HB_TRACE( HB_TR_ERROR, - "Chk4Loop( nbranch %ld exceeds file size in page %ld (position %d, count %d) )", - ( long ) ulBranch, - ( long ) ulNode, - ( int ) iPosition, - ( int ) CountGet( pBTree, - ulNode ) ); -} -#endif - -static void BranchSet( struct hb_BTree * pBTree, HB_ULONG ulNode, int iPosition, HB_ULONG ulBranch ) -{ - READPAGE_IF_NEEDED( pBTree, ulNode ); -/* - if ( ulBranch > filelength( pBTree->hFile ) ) - HB_TRACE( HB_TR_ERROR, "BranchSet( nbranch set %ld exceeds file size in page %ld (position %d, count %d) )", - ( long )ulBranch, - ( long )ulNode, - ( int )iPosition, - CountGet( pBTree, ulNode ) ); - */ - - pBTree->ioBuffer->pulBranch[ iPosition ] = ulBranch; - pBTree->ioBuffer->IsDirty = pBTree->IsDirtyFlagAssignment; -} - -/* if the parameter is null, allocate a buffer - it is the */ -/* callers responsibility to release the buffer */ - -static hb_KeyData_T * KeyGet( struct hb_BTree * pBTree, HB_ULONG ulNode, int iPosition, - hb_KeyData_T * buffer ) -{ - READPAGE_IF_NEEDED( pBTree, ulNode ); - - if( buffer == NULL ) - buffer = ( hb_KeyData_T * ) BufferAlloc( sizeof( hb_KeyData_T ) + pBTree->usKeySize + 1 ); - - hb_xmemcpy( buffer->szKey, pBTree->ioBuffer->szKey + ( iPosition - 1 ) * pBTree->usKeySize, - pBTree->usKeySize ); - buffer->szKey[ pBTree->usKeySize ] = '\0'; - if( GETFLAG( pBTree, IsInMemory ) ) - { - buffer->xData.pData = pBTree->ioBuffer->xData.ppData[ iPosition - 1 ]; - } - else - { - buffer->xData.lData = pBTree->ioBuffer->xData.plData[ iPosition - 1 ]; - } - - return buffer; -} - -static void KeySet( struct hb_BTree * pBTree, HB_ULONG ulNode, int iPosition, hb_KeyData_T * key ) -{ - READPAGE_IF_NEEDED( pBTree, ulNode ); - -/* if ( pBTree->ioBuffer->szKey + ( iPosition - 1 ) * pBTree->usKeySize + pBTree->usKeySize > pBTree->ioBuffer->Buffer + pBTree->usPageSize ) */ - hb_xmemcpy( pBTree->ioBuffer->szKey + ( iPosition - 1 ) * pBTree->usKeySize, key->szKey, - pBTree->usKeySize ); - if( GETFLAG( pBTree, IsInMemory ) ) - { - pBTree->ioBuffer->xData.ppData[ iPosition - 1 ] = key->xData.pData; - } - else - { - pBTree->ioBuffer->xData.plData[ iPosition - 1 ] = key->xData.lData; - } - pBTree->ioBuffer->IsDirty = pBTree->IsDirtyFlagAssignment; -} - -static HB_LONG KeyCompare( struct hb_BTree * pBTree, hb_KeyData_T * left, hb_KeyData_T * right ) -{ -/* HB_LONG lResults = strnicmp( left->szKey, right->szKey, pBTree->usKeySize );*/ - HB_LONG lResults = - ( pBTree->pStrCompare )( ( const char * ) left->szKey, ( const char * ) right->szKey, - pBTree->usKeySize ); - - if( lResults == 0 && GETFLAG( pBTree, IsUnique ) ) - { - lResults = ( left->xData.lData - right->xData.lData ); - } - - return lResults; -} - -static HB_BOOL SearchNode( struct hb_BTree * pBTree, hb_KeyData_T * target, HB_ULONG ulNode, - int * iPosition ) -{ - HB_BOOL results; - hb_KeyData_T * buffer = ( hb_KeyData_T * ) BufferAlloc( - sizeof( hb_KeyData_T ) + pBTree->usKeySize + 1 ); - - READPAGE_IF_NEEDED( pBTree, ulNode ); - - if( KeyCompare( pBTree, target, KeyGet( pBTree, ulNode, 1, buffer ) ) < 0 ) - { - *iPosition = 0; - results = HB_FALSE; - } - else - { - *iPosition = CountGet( pBTree, ulNode ); - while( KeyCompare( pBTree, target, - KeyGet( pBTree, ulNode, *iPosition, buffer ) ) < 0 && *iPosition > 1 ) - ( *iPosition )--; - - results = ( HB_BOOL ) ( KeyCompare( pBTree, target, buffer ) == 0 ); - -/* TODO: change the linear search (above) into a binary search */ -#if 0 - if( 1 || IsDebugging ) - { - short int lower_, upper_, middle_, results_; - - lower_ = 1; - upper_ = CountGet( pBTree, ulNode ); - do - { - middle_ = ( upper_ + lower_ ) / 2; - results_ = KeyCompare( pBTree, target, KeyGet( pBTree, ulNode, middle_, buffer ) ); - if( results_ < 0 ) - upper_ = middle_ - 1; - else if( results_ > 0 ) - lower_ = middle_ + 1; - } - while( results_ != 0 && upper_ >= lower_ ); - if( ! ( results == - ( HB_BOOL ) ( results_ == - 0 ) && *iPosition != results_ == 0 ? middle_ : upper_ ) ) - HB_TRACE( HB_TR_ERROR, - ( "SearchNode( results=%d results_=%d *iPosition=%d myposition=%d )", - results, ( HB_BOOL ) ( results_ == 0 ), *iPosition, - results_ == 0 ? middle_ : upper_ ) ); - - /* results = ( HB_BOOL )( results_ == 0 ); - *iPosition = results == 0 ? middle_ : upper_; */ - } -#endif - } - - BufferRelease( buffer ); - return results; -} - -static HB_ULONG hb_BTreeSearch( struct hb_BTree * pBTree, hb_KeyData_T * target, int * targetpos, - BTreeStack ** pStack ) -{ - HB_ULONG ulNode = pBTree->ulRootPage; - - while( ulNode && ! SearchNode( pBTree, target, ulNode, targetpos ) ) - { - if( pStack && *pStack ) - { - StackPush( pStack, ulNode, *targetpos ); - } - ulNode = BranchGet( pBTree, ulNode, *targetpos ); - } - - if( ulNode && pStack && *pStack ) - { - StackPush( pStack, ulNode, *targetpos ); - } - - return ulNode; -} - -static void PushIn( struct hb_BTree * pBTree, hb_KeyData_T * xkey, HB_ULONG xbranch, - HB_ULONG ulNode, - int iPosition ) -{ - hb_KeyData_T * buffer = ( hb_KeyData_T * ) BufferAlloc( - sizeof( hb_KeyData_T ) + pBTree->usKeySize + 1 ); - int i; - - for( i = CountGet( pBTree, ulNode ); i > iPosition; i-- ) - { - NodeCopy( pBTree, ulNode, i + 1, ulNode, i, buffer ); - } - - KeySet( pBTree, ulNode, iPosition + 1, xkey ); - BranchSet( pBTree, ulNode, iPosition + 1, xbranch ); - ( void ) CountAdj( pBTree, ulNode, +1 ); - BufferRelease( buffer ); -} - -static void Split( struct hb_BTree * pBTree, hb_KeyData_T * xkey, HB_ULONG xbranch, HB_ULONG ulNode, - int iPosition, hb_KeyData_T ** ykey, - HB_ULONG * ybranch ) -{ - int i; - int median; - hb_KeyData_T * buffer = ( hb_KeyData_T * ) BufferAlloc( - sizeof( hb_KeyData_T ) + pBTree->usKeySize + 1 ); - - if( iPosition <= pBTree->usMinKeys ) - median = pBTree->usMinKeys; - else - median = pBTree->usMinKeys + 1; - - *ybranch = Grow( pBTree ); - for( i = median + 1; i <= pBTree->usMaxKeys; i++ ) - { - NodeCopy( pBTree, *ybranch, i - median, ulNode, i, buffer ); - } - - CountSet( pBTree, *ybranch, pBTree->usMaxKeys - median ); - CountSet( pBTree, ulNode, median ); - - if( iPosition <= pBTree->usMinKeys ) - PushIn( pBTree, xkey, xbranch, ulNode, iPosition ); - else - PushIn( pBTree, xkey, xbranch, *ybranch, iPosition - median ); - -/* hb_xmemcpy( *ykey, KeyGet( pBTree, ulNode, CountGet( pBTree, ulNode ), buffer ), pBTree->usKeySize ); */ - KeyGet( pBTree, ulNode, CountGet( pBTree, ulNode ), *ykey ); - -/* *ykey = KeyGet( pBTree, ulNode, CountGet( pBTree, ulNode ) );*/ - BranchSet( pBTree, *ybranch, 0, BranchGet( pBTree, ulNode, CountGet( pBTree, ulNode ) ) ); - ( void ) CountAdj( pBTree, ulNode, -1 ); - BufferRelease( buffer ); -} - -#ifdef DEBUG -static HB_ULONG sulMaxPushDownDepth = 0; -#endif -static HB_BOOL PushDown( struct hb_BTree * pBTree, hb_KeyData_T * newkey, HB_ULONG ulNode, - hb_KeyData_T ** xkey, - HB_ULONG * xbranch ) -{ - int iPosition; - -#ifdef DEBUG - static HB_ULONG PushDownDepth = 0; - - if( ++PushDownDepth > sulMaxPushDownDepth ) - { - sulMaxPushDownDepth = PushDownDepth; - } -#endif - - if( BTREENODEISNULL( pBTree, ulNode ) ) - { - HB_TRACE( HB_TR_DEBUG, ( SRCLINENO ) ); - hb_xmemcpy( *xkey, newkey, sizeof( hb_KeyData_T ) + pBTree->usKeySize + 1 ); /* *xkey = newkey;*/ - *xbranch = NULLPAGE; - return HB_TRUE; - } - else - { - HB_TRACE( HB_TR_DEBUG, ( SRCLINENO ) ); - if( SearchNode( pBTree, newkey, ulNode, &iPosition ) ) - { - SETFLAG( pBTree, IsDuplicateKey ); - return HB_FALSE; /* error */ - } - - if( PushDown( pBTree, newkey, BranchGet( pBTree, ulNode, iPosition ), xkey, xbranch ) ) - { - if( CountGet( pBTree, ulNode ) < pBTree->usMaxKeys ) - { - PushIn( pBTree, *xkey, *xbranch, ulNode, iPosition ); - return HB_FALSE; - } - else - { - Split( pBTree, *xkey, *xbranch, ulNode, iPosition, xkey, xbranch ); - return HB_TRUE; - } - } - return HB_FALSE; - } -} - -HB_BOOL hb_BTreeInsert( struct hb_BTree * pBTree, const char * szKey, PHB_ITEM pData ) -{ - hb_KeyData_T * xkey = ( hb_KeyData_T * ) BufferAlloc( - sizeof( hb_KeyData_T ) + pBTree->usKeySize + 1 ); - HB_ULONG xbranch; - HB_ULONG newnode; - - HB_TRACE( HB_TR_DEBUG, ( SRCLINENO ) ); - - RESETFLAG( pBTree, IsDuplicateKey ); - - hb_xmemcpy( pBTree->pThisKeyData->szKey, szKey, pBTree->usKeySize ); - pBTree->pThisKeyData->szKey[ pBTree->usKeySize ] = '\0'; - - if( GETFLAG( pBTree, IsInMemory ) ) - { - pBTree->pThisKeyData->xData.pData = hb_itemNew( pData ); -/*printf( "[%p %p] ", pBTree->pThisKeyData->xData.pData, pData );PrintCRLF();*/ - } - else - { - pBTree->pThisKeyData->xData.lData = hb_itemGetNL( pData ); - } - - if( PushDown( pBTree, pBTree->pThisKeyData, pBTree->ulRootPage, &xkey, &xbranch ) ) - { - newnode = Grow( pBTree ); - CountSet( pBTree, newnode, 1 ); - KeySet( pBTree, newnode, 1, xkey ); - BranchSet( pBTree, newnode, 0, pBTree->ulRootPage ); - BranchSet( pBTree, newnode, 1, xbranch ); - pBTree->ulRootPage = newnode; - } - - HB_TRACE( HB_TR_DEBUG, ( SRCLINENO ) ); - BufferRelease( xkey ); - HB_TRACE( HB_TR_DEBUG, ( SRCLINENO ) ); - - if( ! GETFLAG( pBTree, IsDuplicateKey ) ) - pBTree->ulKeyCount++; - - return ! GETFLAG( pBTree, IsDuplicateKey ); -} - -static void MoveRight( struct hb_BTree * pBTree, HB_ULONG ulNode, int iPosition ) -{ - int c; - HB_ULONG tmpnode; - hb_KeyData_T * buffer = ( hb_KeyData_T * ) BufferAlloc( - sizeof( hb_KeyData_T ) + pBTree->usKeySize + 1 ); - - tmpnode = BranchGet( pBTree, ulNode, iPosition ); - for( c = CountGet( pBTree, tmpnode ); c > 0; c-- ) - { - NodeCopy( pBTree, tmpnode, c + 1, tmpnode, c, buffer ); - } - - BranchSet( pBTree, tmpnode, 1, BranchGet( pBTree, tmpnode, 0 ) ); - ( void ) CountAdj( pBTree, tmpnode, +1 ); - KeySet( pBTree, tmpnode, 1, KeyGet( pBTree, ulNode, iPosition, buffer ) ); - - tmpnode = BranchGet( pBTree, ulNode, iPosition - 1 ); - KeySet( pBTree, ulNode, iPosition, - KeyGet( pBTree, tmpnode, CountGet( pBTree, tmpnode ), buffer ) ); - BranchSet( pBTree, - BranchGet( pBTree, ulNode, - iPosition ), 0, BranchGet( pBTree, tmpnode, CountGet( pBTree, tmpnode ) ) ); - ( void ) CountAdj( pBTree, tmpnode, -1 ); - BufferRelease( buffer ); -} - -static void MoveLeft( struct hb_BTree * pBTree, HB_ULONG ulNode, int iPosition ) -{ - int c, c_count; - HB_ULONG tmpnode; - hb_KeyData_T * buffer = ( hb_KeyData_T * ) BufferAlloc( - sizeof( hb_KeyData_T ) + pBTree->usKeySize + 1 ); - - tmpnode = BranchGet( pBTree, ulNode, iPosition - 1 ); - c_count = CountAdj( pBTree, tmpnode, +1 ); - KeySet( pBTree, tmpnode, c_count, KeyGet( pBTree, ulNode, iPosition, buffer ) ); - BranchSet( pBTree, tmpnode, c_count, - BranchGet( pBTree, BranchGet( pBTree, ulNode, iPosition ), 0 ) ); - - tmpnode = BranchGet( pBTree, ulNode, iPosition ); - KeySet( pBTree, ulNode, iPosition, KeyGet( pBTree, tmpnode, 1, buffer ) ); - BranchSet( pBTree, tmpnode, 0, BranchGet( pBTree, tmpnode, 1 ) ); - c_count = CountAdj( pBTree, tmpnode, -1 ); - - for( c = 1; c <= c_count; c++ ) - { - NodeCopy( pBTree, tmpnode, c, tmpnode, c + 1, buffer ); - } - - BufferRelease( buffer ); -} - -static void Combine( struct hb_BTree * pBTree, HB_ULONG ulNode, int iPosition ) -{ - int c, c_count; - HB_ULONG tmpnode; - HB_ULONG leftnode; - HB_ULONG leftpagecount; - hb_KeyData_T * buffer = ( hb_KeyData_T * ) BufferAlloc( - sizeof( hb_KeyData_T ) + pBTree->usKeySize + 1 ); - - tmpnode = BranchGet( pBTree, ulNode, iPosition ); - leftnode = BranchGet( pBTree, ulNode, iPosition - 1 ); - leftpagecount = CountAdj( pBTree, leftnode, +1 ); - KeySet( pBTree, leftnode, leftpagecount, KeyGet( pBTree, ulNode, iPosition, buffer ) ); - BranchSet( pBTree, leftnode, leftpagecount, BranchGet( pBTree, tmpnode, 0 ) ); - - c_count = CountGet( pBTree, tmpnode ); - for( c = 1; c <= c_count; c++ ) - { - leftpagecount = CountAdj( pBTree, leftnode, +1 ); - NodeCopy( pBTree, leftnode, leftpagecount, tmpnode, c, buffer ); - } - - c_count = CountGet( pBTree, ulNode ); - for( c = iPosition; c < c_count; c++ ) - { - NodeCopy( pBTree, ulNode, c, ulNode, c + 1, buffer ); - } - ( void ) CountAdj( pBTree, ulNode, -1 ); - - Prune( pBTree, tmpnode ); - BufferRelease( buffer ); -} - -static void Restore( struct hb_BTree * pBTree, HB_ULONG ulNode, int iPosition ) -{ - READPAGE_IF_NEEDED( pBTree, ulNode ); - - if( iPosition == 0 ) /* left-most key */ - { - if( CountGet( pBTree, BranchGet( pBTree, ulNode, 1 ) ) > pBTree->usMinKeys ) - { - MoveLeft( pBTree, ulNode, 1 ); - } - else - { - Combine( pBTree, ulNode, 1 ); - } - } - else if( iPosition == CountGet( pBTree, ulNode ) ) /* right-most key */ - { - if( CountGet( pBTree, BranchGet( pBTree, ulNode, iPosition - 1 ) ) > pBTree->usMinKeys ) - { - MoveRight( pBTree, ulNode, iPosition ); - } - else - { - Combine( pBTree, ulNode, iPosition ); - } - } - else if( CountGet( pBTree, BranchGet( pBTree, ulNode, iPosition - 1 ) ) > pBTree->usMinKeys ) - { - MoveRight( pBTree, ulNode, iPosition ); - } - else if( CountGet( pBTree, BranchGet( pBTree, ulNode, iPosition + 1 ) ) > pBTree->usMinKeys ) - { - MoveLeft( pBTree, ulNode, iPosition + 1 ); - } - else - Combine( pBTree, ulNode, iPosition ); -} - -static void Remove( struct hb_BTree * pBTree, HB_ULONG ulNode, int iPosition ) -{ - int c, c_count; - hb_KeyData_T * buffer = ( hb_KeyData_T * ) BufferAlloc( - sizeof( hb_KeyData_T ) + pBTree->usKeySize + 1 ); - - c_count = CountGet( pBTree, ulNode ); - for( c = iPosition + 1; c <= c_count; c++ ) - { - NodeCopy( pBTree, ulNode, c - 1, ulNode, c, buffer ); - } - ( void ) CountAdj( pBTree, ulNode, -1 ); - BufferRelease( buffer ); -} - -static void Successor( struct hb_BTree * pBTree, HB_ULONG ulNode, int iPosition ) -{ - HB_ULONG tmpnode; - hb_KeyData_T * buffer; - - for( tmpnode = BranchGet( pBTree, ulNode, iPosition ); - ! BTREENODEISNULL( pBTree, BranchGet( pBTree, tmpnode, 0 ) ); - tmpnode = BranchGet( pBTree, tmpnode, 0 ) ) - { - } - - KeySet( pBTree, ulNode, iPosition, ( buffer = KeyGet( pBTree, tmpnode, 1, NULL ) ) ); - BufferRelease( buffer ); -} - -#ifdef DEBUG -static HB_ULONG sulMaxRecDeleteDepth = 0; -#endif -static HB_BOOL RecDelete( struct hb_BTree * pBTree, hb_KeyData_T * target, HB_ULONG ulNode ) -{ -#ifdef DEBUG - static HB_ULONG RecDeleteDepth = 0; -#endif - - int iPosition; - HB_BOOL found; - - if( BTREENODEISNULL( pBTree, ulNode ) ) - { - /* todo: hitting an empty pBTree is an error */ - return HB_FALSE; - } - else - { -#ifdef DEBUG - if( ++RecDeleteDepth > sulMaxRecDeleteDepth ) - { - sulMaxRecDeleteDepth = RecDeleteDepth; - if( RecDeleteDepth > 10 ) - { - HB_TRACE( HB_TR_ERROR, ( "RecDelete( Exiting 2! )" ) ); exit( 0 ); - } - } -#endif - /* inline assignment & comparision was generating a Borland warning */ - found = SearchNode( pBTree, target, ulNode, &iPosition ); - if( found ) - { - if( ! BTREENODEISNULL( pBTree, BranchGet( pBTree, ulNode, iPosition - 1 ) ) ) - { - Successor( pBTree, ulNode, iPosition ); /* move successor to this iPosition */ - KeyGet( pBTree, ulNode, iPosition, target ); - found = RecDelete( pBTree, target, BranchGet( pBTree, ulNode, iPosition ) ); -#if 0 - if( ! found ) - error( "key not found" ); /* key exists, so this shouldn't occur*/ -#endif - } - else - Remove( pBTree, ulNode, iPosition ); - } - else - found = RecDelete( pBTree, target, BranchGet( pBTree, ulNode, iPosition ) ); - - /* the recursive call has returned */ - if( found && ! BTREENODEISNULL( pBTree, BranchGet( pBTree, ulNode, iPosition ) ) ) - if( CountGet( pBTree, BranchGet( pBTree, ulNode, iPosition ) ) < pBTree->usMinKeys ) - Restore( pBTree, ulNode, iPosition ); -#ifdef DEBUG - --RecDeleteDepth; -#endif - return found; - } -} - -#if 0 -static HB_BOOL __RecDelete( struct hb_BTree * pBTree, hb_KeyData_T target, HB_ULONG ulNode ) -{ - static HB_ULONG RecDeleteDepth = 0; - HB_BOOL found = HB_FALSE; - - if( ++RecDeleteDepth > sulMaxRecDeleteDepth ) - { - sulMaxRecDeleteDepth = RecDeleteDepth; - } - - if( ! BTREENODEISNULL( pBTree, ulNode ) ) - { - int iPosition; - /* hb_KeyData_T tmpTarget; */ - /* */ - /* tmpTarget = BufferAlloc( sizeof( hb_KeyData_T ) + pBTree->usKeySize + 1 ); */ - /* hb_xmemcpy( tmpTarget, target, pBTree->usKeySize ); */ - - #define tmpTarget target - - /* inline assignment & comparision was generating a Borland warning */ - found = SearchNode( pBTree, tmpTarget, ulNode, &iPosition ) - if( found ) - { - if( ! BTREENODEISNULL( pBTree, BranchGet( pBTree, ulNode, iPosition - 1 ) ) ) - { - Successor( pBTree, ulNode, iPosition ); - hb_xmemcpy( tmpTarget, KeyGet( pBTree, ulNode, iPosition ), pBTree->usKeySize ); - /*if ( !( found =*/ RecDelete( pBTree, tmpTarget, BranchGet( pBTree, ulNode, iPosition ) ); /*) )*/ - /* RESETFLAG( pBTree, IsRecordFound )*/ /*pBTree->bRecordNotFound = HB_TRUE*/; /* error */ - } - else - { - Remove( pBTree, ulNode, iPosition ); - } - } - else - { - if( ! ( found = RecDelete( pBTree, tmpTarget, BranchGet( pBTree, ulNode, iPosition ) ) ) ) - RESETFLAG( pBTree, IsRecordFound ); /* error */ - } - - /* if ( GETFLAG( pBTree, IsRecordFound )*/ /*!tree->bRecordNotFound )*/ - { - HB_ULONG tmpNode; - - tmpNode = BranchGet( pBTree, ulNode, iPosition ); - if( ! BTREENODEISNULL( pBTree, tmpNode ) ) - if( CountGet( pBTree, tmpNode ) < pBTree->usMinKeys ) - Restore( pBTree, ulNode, iPosition ); - } - - /*BufferRelease( tmpTarget );*/ - #undef tmpTarget - } - else - RESETFLAG( pBTree, IsRecordFound ); /* error */ - - --RecDeleteDepth; - - return found; -} -#endif - -HB_BOOL hb_BTreeDelete( struct hb_BTree * pBTree, const char * target, HB_LONG lData ) -{ - HB_ULONG ulNode; - int iPosition; - hb_KeyData_T * tmpTarget; - HB_BOOL found = HB_FALSE; - - SETFLAG( pBTree, IsRecordFound ); - CLEARKEYDATA( pBTree ); - - tmpTarget = ( hb_KeyData_T * ) BufferAlloc( sizeof( hb_KeyData_T ) + pBTree->usKeySize + 1 ); - hb_xmemcpy( tmpTarget->szKey, target, pBTree->usKeySize ); - tmpTarget->xData.lData = lData; - - if( hb_BTreeSearch( pBTree, tmpTarget, &iPosition, NULL ) ) - { - if( RecDelete( pBTree, tmpTarget, pBTree->ulRootPage ) ) - { - found = HB_TRUE; - if( CountGet( pBTree, pBTree->ulRootPage ) == 0 ) - { - ulNode = pBTree->ulRootPage; - pBTree->ulRootPage = BranchGet( pBTree, pBTree->ulRootPage, 0 ); - Prune( pBTree, ulNode ); - } - } -#if 0 - else - { - } /* error - key does not exist */ -#endif - } - else - RESETFLAG( pBTree, IsRecordFound ); - - BufferRelease( tmpTarget ); - - if( found ) - pBTree->ulKeyCount--; - - return found; /*!tree->bRecordNotFound;*/ -} - -void hb_BTreeGoTop( struct hb_BTree * pBTree ) -{ - HB_ULONG ulNode; - HB_ULONG ulLastNode; - - for( ulLastNode = ulNode = pBTree->ulRootPage; ! BTREENODEISNULL( pBTree, ulNode ); - ulLastNode = ulNode, ulNode = BranchGet( pBTree, ulNode, 0 ) ) - { - } - - if( BTREENODEISNULL( pBTree, ulLastNode ) ) - CLEARKEYDATA( pBTree ); - else - KeyGet( pBTree, ulLastNode, 1, pBTree->pThisKeyData ); -} - -void hb_BTreeGoBottom( struct hb_BTree * pBTree ) -{ - HB_ULONG ulNode; - HB_ULONG ulLastNode; - - for( ulLastNode = ulNode = pBTree->ulRootPage; ! BTREENODEISNULL( pBTree, ulNode ); - ulLastNode = ulNode, ulNode = BranchGet( pBTree, ulNode, CountGet( pBTree, ulNode ) ) ) - { - } - - if( BTREENODEISNULL( pBTree, ulLastNode ) ) - CLEARKEYDATA( pBTree ); - else - KeyGet( pBTree, ulLastNode, CountGet( pBTree, ulLastNode ), pBTree->pThisKeyData ); -} - -HB_LONG hb_BTreeSkip( struct hb_BTree * pBTree, HB_LONG records ) -{ - HB_LONG results = 0; - int iPosition; - hb_KeyData_T * keydata; - BTreeStack * pStack = NULL; - - if( BTREENODEISNULL( pBTree, pBTree->ulRootPage ) ) - { - CLEARKEYDATA( pBTree ); - return 0; - } - - keydata = ( hb_KeyData_T * ) BufferAlloc( sizeof( hb_KeyData_T ) + pBTree->usKeySize + 1 ); - hb_xmemcpy( keydata->szKey, pBTree->pThisKeyData->szKey, pBTree->usKeySize ); - keydata->xData.lData = pBTree->pThisKeyData->xData.lData; - - StackNew( &pStack ); - if( ! BTREENODEISNULL( pBTree, hb_BTreeSearch( pBTree, keydata, &iPosition, &pStack ) ) ) - { - results = StackSkip( pBTree, &pStack, records ); - } - else - { - CLEARKEYDATA( pBTree ); - } - - StackRelease( &pStack ); - BufferRelease( keydata ); - - return results; -} - -HB_BOOL hb_BTreeSeek( struct hb_BTree * pBTree, const char * szKey, HB_LONG lData, - HB_BOOL bSoftSeek ) -{ - HB_BOOL results = HB_FALSE; - int iPosition; - hb_KeyData_T * tmpTarget; - BTreeStack * pStack = NULL; - - tmpTarget = ( hb_KeyData_T * ) BufferAlloc( sizeof( hb_KeyData_T ) + pBTree->usKeySize + 1 ); - hb_xmemcpy( tmpTarget->szKey, szKey, pBTree->usKeySize ); - tmpTarget->xData.lData = lData; - - StackNew( &pStack ); - if( ! BTREENODEISNULL( pBTree, hb_BTreeSearch( pBTree, tmpTarget, &iPosition, &pStack ) ) || - ( bSoftSeek && pStack->usCount > 0 && ( 1 == StackSkip( pBTree, &pStack, 1 ) ) ) ) - { - KeyGet( pBTree, STACKNODE( &pStack ), STACKPOSITION( &pStack ), pBTree->pThisKeyData ); - results = HB_TRUE; - } - else - { - CLEARKEYDATA( pBTree ); - } - - StackRelease( &pStack ); - BufferRelease( tmpTarget ); - - return results; -} - - -static int hb_BTstrncmp( const char * s1, const char * s2, size_t n ) -{ - return strncmp( s1, s2, n ); -} - -/* allocate hb_BTree structure */ -struct hb_BTree * hb_BTreeNew( const char * FileName, HB_USHORT usPageSize, HB_USHORT usKeySize, - HB_ULONG ulFlags, - HB_ULONG ulBuffers ) -{ - struct hb_BTree * pBTree = ( struct hb_BTree * ) BufferAlloc( sizeof( struct hb_BTree ) ); - int iFileIOmode; - - HB_TRACE( HB_TR_DEBUG, ( SRCLINENO ) ); - - /* correct parameters to default values */ - if( usKeySize < 8 ) - usKeySize = 8; - if( usPageSize % HB_BTREE_HEADERSIZE ) - usPageSize -= ( usPageSize % HB_BTREE_HEADERSIZE ); - if( usPageSize < HB_BTREE_HEADERSIZE ) - usPageSize = HB_BTREE_HEADERSIZE; - - /* - number of keys is: - ( usPageSize - ( sizeof count + sizeof branch[0] ) ) / ( sizeof branch[0] + sizeof key ) - 1 - */ - - /* this assumes that the count field and a branch field are HB_U32 */ - #define MAXKEYS( pagesize, keysize, flags ) \ - ( ( ( pagesize ) - ( sizeof( HB_U32 ) + sizeof( HB_U32 ) ) ) / \ - ( sizeof( HB_U32 ) \ - + ( ( ( flags ) & HB_BTREE_INMEMORY ) == HB_BTREE_INMEMORY \ - ? sizeof( PHB_ITEM * ) \ - : ( keysize ) ) ) - 1 \ - ) - #define MINKEYS( maxkeys ) ( ( maxkeys + 1 ) / 2 - ( maxkeys % 2 ) ) - - if( ( ulFlags & HB_BTREE_INMEMORY ) == HB_BTREE_INMEMORY ) - { - pBTree->hFile = 0; - pBTree->szFileName = NULL; - pBTree->IsDirtyFlagAssignment = HB_FALSE; /* replaces const value for assignment */ - } - else - { - pBTree->IsDirtyFlagAssignment = HB_TRUE; /* replaces const value for assignment */ - - if( ( ulFlags & ( HB_BTREE_READONLY ) ) == HB_BTREE_READONLY ) - { - iFileIOmode = FC_READONLY; - ulFlags &= ~HB_BTREE_READONLY; - ulFlags &= ~HB_BTREE_SHARED; - } - else - { - iFileIOmode = FC_NORMAL; - } - - pBTree->hFile = hb_fsCreate( FileName, iFileIOmode ); - if( pBTree->hFile == -1 ) - { - BufferRelease( pBTree ); - return NULL; - } - - if( ( ulFlags & ( HB_BTREE_SHARED ) ) == HB_BTREE_SHARED ) - { - hb_fsClose( pBTree->hFile ); - pBTree->hFile = hb_fsOpen( FileName, FO_READWRITE | FO_SHARED ); - if( pBTree->hFile == -1 ) - { - BufferRelease( pBTree ); - return NULL; - } - } - - pBTree->szFileName = hb_strdup( FileName ); - } - - pBTree->ulFreePage = NULLPAGE; - pBTree->ulRootPage = NULLPAGE; - pBTree->usPageSize = usPageSize; - pBTree->usKeySize = usKeySize; - pBTree->usMaxKeys = ( HB_USHORT ) MAXKEYS( usPageSize, usKeySize, ulFlags ); - pBTree->usMinKeys = ( HB_USHORT ) MINKEYS( pBTree->usMaxKeys ); - pBTree->ulFlags = ulFlags; - pBTree->ulKeyCount = 0; - pBTree->pStack = NULL; -/* TODO: use stack optimization if flags warrant: if ( flag... ) StackNew( &pBTree->pStack ); */ - pBTree->pThisKeyData = ( hb_KeyData_T * ) BufferAlloc( - sizeof( hb_KeyData_T ) + pBTree->usKeySize + 1 ); - CLEARKEYDATA( pBTree ); - ioBufferAlloc( pBTree, ulBuffers ); - - if( GETFLAG( pBTree, IsCaseLess ) ) - { - pBTree->pStrCompare = ( BTreeCmpFunc ) hb_strnicmp; - } - else - { - pBTree->pStrCompare = ( BTreeCmpFunc ) hb_BTstrncmp; - } - - if( GETFLAG( pBTree, IsInMemory ) == HB_FALSE ) - { - HeaderWrite( pBTree ); - } - else /* IsInMemory == HB_TRUE */ - { - RESETFLAG( pBTree, HB_BTREE_UNIQUE ); /* clear this flag */ - } - - return pBTree; -} - -/* open an existing structure */ -struct hb_BTree * hb_BTreeOpen( const char * FileName, HB_ULONG ulFlags, HB_ULONG ulBuffers ) -{ - struct hb_BTree * pBTree = ( struct hb_BTree * ) BufferAlloc( sizeof( struct hb_BTree ) ); - HB_BYTE TmpHeader[ HB_BTREE_HEADERSIZE ]; - HB_BYTE * pHeader = &TmpHeader[ 0 ]; - - HB_TRACE( HB_TR_DEBUG, ( SRCLINENO ) ); - - pBTree->szFileName = hb_strdup( FileName ); - pBTree->hFile = - hb_fsOpen( pBTree->szFileName, ( ( ulFlags & HB_BTREE_READONLY ) ? FO_READ : FO_READWRITE ) ); - if( pBTree->hFile == -1 ) - { - BufferRelease( pBTree ); - return NULL; - } - - hb_fsRead( pBTree->hFile, TmpHeader, sizeof( TmpHeader ) ); - if( memcmp( TmpHeader, HEADER_ID, sizeof( HEADER_ID ) ) != 0 ) - { - hb_fsClose( pBTree->hFile ); - BufferRelease( pBTree ); - return NULL; - } - - pHeader += sizeof( HEADER_ID ) - 1; /* the trailing null byte */ - pHeader += sizeof( HB_U32 ); /* skip over the header size (HB_BTREE_HEADERSIZE) field */ - pBTree->usPageSize = ( HB_U16 ) HB_GET_LE_UINT32( pHeader ); pHeader += 4; - pBTree->usKeySize = ( HB_U16 ) HB_GET_LE_UINT32( pHeader ); pHeader += 4; - pBTree->usMaxKeys = ( HB_U16 ) HB_GET_LE_UINT32( pHeader ); pHeader += 4; - pBTree->usMinKeys = ( HB_U16 ) HB_GET_LE_UINT32( pHeader ); pHeader += 4; - pBTree->ulFlags = HB_GET_LE_UINT32( pHeader ) | ( ulFlags & HB_BTREE_READONLY ); - - pHeader = &TmpHeader[ 64 ]; - pBTree->ulRootPage = HB_GET_LE_UINT32( pHeader ); pHeader += 4; - pBTree->ulFreePage = HB_GET_LE_UINT32( pHeader ); pHeader += 4; - pBTree->ulKeyCount = HB_GET_LE_UINT32( pHeader ); - - pBTree->pThisKeyData = ( hb_KeyData_T * ) BufferAlloc( - sizeof( hb_KeyData_T ) + pBTree->usKeySize + 1 ); - CLEARKEYDATA( pBTree ); - pBTree->pStack = NULL; -/* TODO: use stack optimization if flags warrant: if ( flag... ) StackNew( &pBTree->pStack ); */ - ioBufferAlloc( pBTree, ulBuffers ); - - RESETFLAG( pBTree, HB_BTREE_INMEMORY ); /* clear this flag */ - pBTree->IsDirtyFlagAssignment = HB_TRUE; /* replaces const value for assignment */ - - if( GETFLAG( pBTree, IsCaseLess ) ) - { - pBTree->pStrCompare = ( BTreeCmpFunc ) hb_strnicmp; - } - else - { - pBTree->pStrCompare = ( BTreeCmpFunc ) hb_BTstrncmp; - } - - return pBTree; -} - -void hb_BTreeClose( struct hb_BTree * pBTree ) -{ - HB_TRACE( HB_TR_DEBUG, ( SRCLINENO ) ); - - ioBufferRelease( pBTree ); - - if( GETFLAG( pBTree, IsInMemory ) == HB_FALSE && - GETFLAG( pBTree, IsReadOnly ) == HB_FALSE ) - { - HeaderWrite( pBTree ); - } - - if( pBTree->hFile != 0 ) - { - hb_fsClose( pBTree->hFile ); - } - - if( pBTree->szFileName != NULL ) - { - BufferRelease( pBTree->szFileName ); - } - - StackRelease( &pBTree->pStack ); - BufferRelease( pBTree->pThisKeyData ); - BufferRelease( pBTree ); -} - -const char * hb_BTreeKey( struct hb_BTree * pBTree ) -{ - return ( const char * ) pBTree->pThisKeyData->szKey; -} - -HB_LONG hb_BTreeData( struct hb_BTree * pBTree ) -{ - return pBTree->pThisKeyData->xData.lData; -} - -PHB_ITEM hb_BTreeDataItem( struct hb_BTree * pBTree ) -{ - return ( PHB_ITEM ) pBTree->pThisKeyData->xData.pData; -} - -static int BTree_SetTreeIndex( struct hb_BTree * pBTree ) -{ - int n; - - HB_TRACE( HB_TR_DEBUG, ( SRCLINENO ) ); - - if( pBTree == NULL ) - return -1; - - for( n = 0; n < s_BTree_List_Count && s_BTree_List[ n ] != NULL; n++ ) - { - } - - if( n == s_BTree_List_Count ) - { - s_BTree_List = ( struct hb_BTree ** ) BufferRealloc( - s_BTree_List, ++s_BTree_List_Count * sizeof( s_BTree_List[ 0 ] ) ); - } - - s_BTree_List[ n ] = pBTree; - - return n + 1; -} - -static struct hb_BTree * BTree_GetTreeIndex( const char * GetSource ) -{ - int index; - - HB_TRACE( HB_TR_DEBUG, ( SRCLINENO ) ); - - index = hb_parni( 1 ); - if( index < 1 || index > s_BTree_List_Count || s_BTree_List[ index - 1 ] == NULL ) - { - raiseError( EG_ARG, HB_BTREE_EC_TREEHANDLE, "Bad HB_BTree handle", GetSource, 1 ); - return NULL; - } - else - return s_BTree_List[ index - 1 ]; -} - -HB_FUNC( HB_BTREEOPEN ) /* hb_BTreeOpen( CHAR cFileName, HB_ULONG ulFlags [ , int nBuffers=1 ] ) -> hb_Btree_Handle */ -{ - HB_TRACE( HB_TR_DEBUG, ( SRCLINENO ) ); - if( HB_ISCHAR( 1 ) && hb_parclen( 1 ) > 0 ) - { - hb_retni( BTree_SetTreeIndex( hb_BTreeOpen( hb_parc( 1 ), hb_parnl( 2 ), hb_parnl( 3 ) ) ) ); - } - else - { - raiseError( EG_ARG, HB_BTREE_EC_INVALIDARG, "Bad argument(s)", HB_ERR_FUNCNAME, hb_pcount() ); - hb_retni( 0 ); - } -} - -HB_FUNC( HB_BTREENEW ) /* hb_BTreeNew( CHAR cFileName, int nPageSize, int nKeySize, [ HB_ULONG ulFlags ], [ int nBuffers=1 ] ) -> hb_Btree_Handle */ -{ - int iPageSize = hb_parni( 2 ); - int iKeySize = hb_parni( 3 ); - HB_ULONG ulFlags = hb_parnl( 4 ); - int iMaxKeys = MAXKEYS( ( HB_U32 ) iPageSize, ( HB_U32 ) iKeySize, ulFlags ); - int iMinKeys = MINKEYS( iMaxKeys ); - - HB_TRACE( HB_TR_DEBUG, ( SRCLINENO ) ); - if( ( ( ulFlags & HB_BTREE_INMEMORY ) == HB_BTREE_INMEMORY || - ( HB_ISCHAR( 1 ) && hb_parclen( 1 ) > 0 ) ) && - ( HB_ISNUM( 2 ) && iPageSize >= 1024 && iPageSize < ( int ) USHRT_MAX ) && - ( ( ulFlags & HB_BTREE_INMEMORY ) == HB_BTREE_INMEMORY || - ( HB_ISNUM( 3 ) && iKeySize >= 4 && iMinKeys > 0 && iMaxKeys > 2 ) ) && - ( 1 == 1 ) ) - { - hb_retni( BTree_SetTreeIndex( hb_BTreeNew( hb_parc( 1 ), ( HB_USHORT ) iPageSize, - ( HB_USHORT ) iKeySize, ulFlags, hb_parnl( 5 ) ) ) ); - } - else - { - raiseError( EG_ARG, HB_BTREE_EC_INVALIDARG, "Bad argument(s)", HB_ERR_FUNCNAME, hb_pcount() ); - hb_retni( 0 ); - } -} - -HB_FUNC( HB_BTREECLOSE ) /* hb_BTreeClose( hb_BTree_Handle ) -> NIL */ -{ - HB_TRACE( HB_TR_DEBUG, ( SRCLINENO ) ); - hb_BTreeClose( BTree_GetTreeIndex( "hb_btreeclose" ) ); - s_BTree_List[ hb_parni( 1 ) - 1 ] = NULL; -} - -HB_FUNC( HB_BTREEINSERT ) /* hb_BTreeInsert( hb_BTree_Handle, CHAR cKey, HB_LONG lData | ANY xData ) -> lSuccess */ -{ - struct hb_BTree * pBTree = BTree_GetTreeIndex( "hb_btreeinsert" ); - - /* PHB_ITEM pKeyCode = hb_param( 1, HB_IT_NUMERIC ); */ - - HB_TRACE( HB_TR_DEBUG, ( SRCLINENO ) ); - if( HB_ISNUM( 1 ) && HB_ISCHAR( 2 ) && - ( hb_pcount() == 2 || GETFLAG( pBTree, IsInMemory ) || HB_ISNUM( 3 ) ) ) - { - if( GETFLAG( pBTree, IsReadOnly ) == HB_FALSE ) - { - hb_retl( hb_BTreeInsert( pBTree, hb_parc( 2 ), hb_paramError( 3 ) ) ); - } - else - { - raiseError( EG_WRITE, HB_BTREE_EC_WRITEERROR, "Cannot insert into a read-only file", - HB_ERR_FUNCNAME, - hb_pcount() ); - hb_retl( HB_FALSE ); - } - } - else - { - raiseError( EG_ARG, HB_BTREE_EC_INVALIDARG, "Bad argument(s)", HB_ERR_FUNCNAME, hb_pcount() ); - hb_retl( HB_FALSE ); - } -} - -HB_FUNC( HB_BTREEDELETE ) /* hb_BTreeDelete( hb_BTree_Handle, CHAR cKey, HB_LONG lData ) -> lSuccess */ -{ - HB_TRACE( HB_TR_DEBUG, ( SRCLINENO ) ); - if( HB_ISNUM( 1 ) && HB_ISCHAR( 2 ) && ( hb_pcount() == 2 || HB_ISNUM( 3 ) ) ) - { - struct hb_BTree * pBTree = BTree_GetTreeIndex( "hb_btreedelete" ); - if( GETFLAG( pBTree, IsReadOnly ) == HB_FALSE ) - { - hb_retl( hb_BTreeDelete( pBTree, hb_parc( 2 ), hb_parnl( 3 ) ) ); - } - else - { - raiseError( EG_WRITE, HB_BTREE_EC_WRITEERROR, "Cannot delete from a read-only file", - HB_ERR_FUNCNAME, - hb_pcount() ); - hb_retl( HB_FALSE ); - } - } - else - { - raiseError( EG_ARG, HB_BTREE_EC_INVALIDARG, "Bad argument(s)", HB_ERR_FUNCNAME, hb_pcount() ); - hb_retl( HB_FALSE ); - } -} - -HB_FUNC( HB_BTREEKEY ) /* hb_BTreeKey( hb_BTree_Handle ) -> CHAR cKey */ -{ - HB_TRACE( HB_TR_DEBUG, ( SRCLINENO ) ); - hb_retc( ( char * ) BTree_GetTreeIndex( "hb_btreekey" )->pThisKeyData->szKey ); -} - -HB_FUNC( HB_BTREEDATA ) /* hb_BtreeData( hb_BTree_Handle ) -> HB_LONG lOldData | xOldData */ -{ /*, [ HB_LONG lNewData | ANY xNewData ] ??? */ - struct hb_BTree * pBTree = BTree_GetTreeIndex( "hb_btreeinfo" ); - - HB_TRACE( HB_TR_DEBUG, ( SRCLINENO ) ); - if( GETFLAG( pBTree, IsInMemory ) ) - { - if( pBTree->pThisKeyData->xData.pData ) - { - hb_itemReturn( pBTree->pThisKeyData->xData.pData ); - } - else - { - hb_ret(); - } - } - else - { - hb_retnl( pBTree->pThisKeyData->xData.lData ); - } -} - -HB_FUNC( HB_BTREEGOTOP ) /* hb_BTreeGoTop( hb_BTree_Handle ) --> NIL */ -{ - HB_TRACE( HB_TR_DEBUG, ( SRCLINENO ) ); - hb_BTreeGoTop( BTree_GetTreeIndex( "hb_btreegotop" ) ); -} - -HB_FUNC( HB_BTREEGOBOTTOM ) /* hb_BTreeGoBottom( hb_BTree_Handle ) --> NIL */ -{ - HB_TRACE( HB_TR_DEBUG, ( SRCLINENO ) ); - hb_BTreeGoBottom( BTree_GetTreeIndex( "hb_btreegobottom" ) ); -} - -HB_FUNC( HB_BTREESKIP ) /* hb_BTreeSkip( hb_BTree_Handle, HB_LONG nRecords ) -> HB_LONG nRecordsSkipped */ -{ - HB_TRACE( HB_TR_DEBUG, ( SRCLINENO ) ); - if( HB_ISNUM( 1 ) && ( hb_pcount() == 1 || HB_ISNUM( 2 ) ) ) - { - HB_LONG nSkip = hb_pcount() == 1 ? 1 : hb_parnl( 2 ); - hb_retnl( hb_BTreeSkip( BTree_GetTreeIndex( "hb_btreeskip" ), nSkip ) ); - } - else - { - raiseError( EG_ARG, HB_BTREE_EC_INVALIDARG, "Bad argument(s)", HB_ERR_FUNCNAME, hb_pcount() ); - hb_retnl( 0 ); - } -} - -HB_FUNC( HB_BTREESEEK ) /* hb_BTreeSeek( hb_BTree_Handle, CHAR cKey, HB_LONG lData, BOOL lSoftSeek ) -> lSuccess */ -{ - HB_TRACE( HB_TR_DEBUG, ( SRCLINENO ) ); - if( HB_ISNUM( 1 ) && HB_ISCHAR( 2 ) ) - hb_retl( hb_BTreeSeek( BTree_GetTreeIndex( "hb_btreeseek" ), hb_parc( 2 ), hb_parnl( 3 ), - hb_parl( 4 ) ) ); - else - { - raiseError( EG_ARG, HB_BTREE_EC_INVALIDARG, "Bad argument(s)", HB_ERR_FUNCNAME, hb_pcount() ); - hb_retl( HB_FALSE ); - } -} - -HB_FUNC( HB_BTREEINFO ) /* hb_BTreeInfo( hb_BTree_Handle, [index] ) -> aResults | cResults | nResults */ -{ - struct hb_BTree * pBTree = BTree_GetTreeIndex( "hb_btreeinfo" ); - - HB_TRACE( HB_TR_DEBUG, ( SRCLINENO ) ); - - if( pBTree ) - switch( hb_parni( 2 ) ) - { - case HB_BTREEINFO_FILENAME: hb_retc( pBTree->szFileName ); break; - case HB_BTREEINFO_PAGESIZE: hb_retni( pBTree->usPageSize ); break; - case HB_BTREEINFO_KEYSIZE: hb_retni( pBTree->usKeySize ); break; - case HB_BTREEINFO_MAXKEYS: hb_retni( pBTree->usMaxKeys ); break; - case HB_BTREEINFO_MINKEYS: hb_retni( pBTree->usMinKeys ); break; - case HB_BTREEINFO_FLAGS: hb_retnl( pBTree->ulFlags ); break; - case HB_BTREEINFO_KEYCOUNT: hb_retnl( pBTree->ulKeyCount ); break; - case HB_BTREEINFO_ALL: - default: /* build an array and store all elements from above into it */ - { - PHB_ITEM info = hb_itemArrayNew( HB_BTREEINFO__SIZE ); - - hb_arraySetC( info, HB_BTREEINFO_FILENAME, pBTree->szFileName ); - hb_arraySetNI( info, HB_BTREEINFO_PAGESIZE, pBTree->usPageSize ); - hb_arraySetNI( info, HB_BTREEINFO_KEYSIZE, pBTree->usKeySize ); - hb_arraySetNI( info, HB_BTREEINFO_MAXKEYS, pBTree->usMaxKeys ); - hb_arraySetNI( info, HB_BTREEINFO_MINKEYS, pBTree->usMinKeys ); - hb_arraySetNL( info, HB_BTREEINFO_FLAGS, pBTree->ulFlags ); - hb_arraySetNL( info, HB_BTREEINFO_KEYCOUNT, pBTree->ulKeyCount ); - - hb_itemReturnRelease( info ); - } - } -} - -#if 0 -HB_FUNB( HB_BTREEEVAL ) /* hb_BTreeEval( hb_BTree_Handle, bBlock, [bForCondition], [bWhileCondition], [nNextRecords], [nRecord], [lRest] ) -- NIL */ -{ - if( HB_ISNUM( 1 ) && HB_ISBLOCK( 2 ) ) - hb_BTreeEval( BTree_GetTreeIndex( "hb_btreeeval" ), 0 ); - else - raiseError( EG_ARG, HB_BTREE_EC_INVALIDARG, "Bad argument(s)", HB_ERR_FUNCNAME, hb_pcount() ); -} -#endif - - -static void hb_BTree_Initialize( void * cargo ) -{ - /* TODO: initialization code */ - - HB_TRACE( HB_TR_DEBUG, ( SRCLINENO ) ); - - HB_SYMBOL_UNUSED( cargo ); - -} - -static void hb_BTree_Terminate( void * cargo ) -{ - /* TODO: termination (cleanup) code */ - - int n; - - HB_TRACE( HB_TR_DEBUG, ( SRCLINENO ) ); - - HB_SYMBOL_UNUSED( cargo ); - - for( n = 0; n < s_BTree_List_Count; n++ ) - { - if( s_BTree_List[ n ] ) - hb_BTreeClose( s_BTree_List[ n ] ); - } - - if( s_BTree_List_Count > 0 ) - BufferRelease( s_BTree_List ); -} - -HB_CALL_ON_STARTUP_BEGIN( _hb_BTree_Initialize_ ) -hb_vmAtInit( hb_BTree_Initialize, NULL ); -hb_vmAtExit( hb_BTree_Terminate, NULL ); -HB_CALL_ON_STARTUP_END( _hb_BTree_Initialize_ ) - -#if defined( HB_PRAGMA_STARTUP ) - #pragma startup _hb_BTree_Initialize_ -#elif defined( HB_DATASEG_STARTUP ) - #define HB_DATASEG_BODY HB_DATASEG_FUNC( _hb_BTree_Initialize_ ) - #include "hbiniseg.h" -#endif - -HB_EXTERN_END diff --git a/harbour/examples/hbbtree/hb_btree.ch b/harbour/examples/hbbtree/hb_btree.ch deleted file mode 100644 index 203b14588b..0000000000 --- a/harbour/examples/hbbtree/hb_btree.ch +++ /dev/null @@ -1,70 +0,0 @@ -/* - $Id$ -*/ - -/* - * Harbour Project source code: - * HB_BTree Harbour API header. - * - * Copyright 2002-2010 April White - * www - http://harbour-project.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version, with one exception: - * - * The exception is that if you link the Harbour Runtime Library (HRL) - * and/or the Harbour Virtual Machine (HVM) 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 HRL - * and/or HVM code into it. - * - * 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 program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit - * their web site at http://www.gnu.org/). - * - */ - -#ifndef HB_BTREE_CH -#define HB_BTREE_CH - -/* NOTE: This file is also used by C code. */ - -/* creation/open control flags */ -#define HB_BTREE_READONLY 1 /* for new: creates file w/ RO attrib; for create: opens file for read */ -#define HB_BTREE_EXCLUSIVE 2 -#define HB_BTREE_SHARED 4 - -#define HB_BTREE_UNIQUE 128 -#define HB_BTREE_CASELESS 256 -#define HB_BTREE_INMEMORY 512 - -#define HB_BTREEINFO_ALL 0 -#define HB_BTREEINFO_FILENAME 1 -#define HB_BTREEINFO_PAGESIZE 2 -#define HB_BTREEINFO_KEYSIZE 3 -#define HB_BTREEINFO_MAXKEYS 4 -#define HB_BTREEINFO_MINKEYS 5 -#define HB_BTREEINFO_FLAGS 6 -#define HB_BTREEINFO_KEYCOUNT 7 -#define HB_BTREEINFO__SIZE 7 /* do not use! */ - -/* error codes (SubCode) */ -#define HB_BTREE_EC_UNKNOWN 1 -#define HB_BTREE_EC_INVALIDARG 2 -#define HB_BTREE_EC_TREEHANDLE 3 -#define HB_BTREE_EC_WRITEERROR 4 -#define HB_BTREE_EC_STACKSKIP 5 - - -/* TODO: add commands/translates */ - -#endif diff --git a/harbour/examples/hbbtree/hb_btree.h b/harbour/examples/hbbtree/hb_btree.h deleted file mode 100644 index 554ba0f7f8..0000000000 --- a/harbour/examples/hbbtree/hb_btree.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - $Id$ - */ - -/* - * Harbour Project source code: - * HB_BTree Harbour C API header. - * - * Copyright 2002-2010 April White - * www - http://harbour-project.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version, with one exception: - * - * The exception is that if you link the Harbour Runtime Library (HRL) - * and/or the Harbour Virtual Machine (HVM) 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 HRL - * and/or HVM code into it. - * - * 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 program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit - * their web site at http://www.gnu.org/). - * - */ - -#ifndef HB_BTREE_API -#define HB_BTREE_API - -HB_EXTERN_BEGIN - -#include "hb_btree.ch" - -struct hb_BTree; - -struct hb_BTree * hb_BTreeNew( const char * FileName, HB_USHORT usPageSize, HB_USHORT usKeySize, - HB_ULONG ulFlags, - HB_ULONG ulBuffers ); -struct hb_BTree * hb_BTreeOpen( const char * FileName, HB_ULONG ulFlags, HB_ULONG ulBuffers ); -void hb_BTreeClose( struct hb_BTree * pBTree ); -HB_BOOL hb_BTreeInsert( struct hb_BTree * pBTree, const char * szKey, PHB_ITEM pData ); -HB_BOOL hb_BTreeDelete( struct hb_BTree * pBTree, const char * szKey, HB_LONG lData ); -void hb_BTreeGoTop( struct hb_BTree * pBTree ); -void hb_BTreeGoBottom( struct hb_BTree * pBTree ); -HB_BOOL hb_BTreeSeek( struct hb_BTree * pBTree, const char * szKey, HB_LONG lData, - HB_BOOL bSoftSeek ); -HB_LONG hb_BTreeSkip( struct hb_BTree * pBTree, HB_LONG records ); -const char * hb_BTreeKey( struct hb_BTree * pBTree ); -HB_LONG hb_BTreeData( struct hb_BTree * pBTree ); -PHB_ITEM hb_BTreeDataItem( struct hb_BTree * pBTree ); - -HB_EXTERN_END - -#endif diff --git a/harbour/examples/hbbtree/hbbtree.hbc b/harbour/examples/hbbtree/hbbtree.hbc deleted file mode 100644 index f4d06b7f71..0000000000 --- a/harbour/examples/hbbtree/hbbtree.hbc +++ /dev/null @@ -1,8 +0,0 @@ -# -# $Id$ -# - -incpaths=. -libpaths=lib/${hb_plat}/${hb_comp} - -libs=${hb_name} diff --git a/harbour/examples/hbbtree/hbbtree.hbp b/harbour/examples/hbbtree/hbbtree.hbp deleted file mode 100644 index cff0d67344..0000000000 --- a/harbour/examples/hbbtree/hbbtree.hbp +++ /dev/null @@ -1,16 +0,0 @@ -# -# $Id$ -# - --hblib --inc - --olib/${hb_plat}/${hb_comp}/${hb_name} - --w3 -es2 - --instfile=inc:hb_btree.ch --instfile=inc:hb_btree.h - -hb_btree.c -tbtree.prg diff --git a/harbour/examples/hbbtree/tbtree.prg b/harbour/examples/hbbtree/tbtree.prg deleted file mode 100644 index 29325eba51..0000000000 --- a/harbour/examples/hbbtree/tbtree.prg +++ /dev/null @@ -1,78 +0,0 @@ -/* - * $Id$ - */ - -/* - * Harbour Project source code: - * HB_BTree class. - * - * Copyright 2002-2010 April White - * www - http://harbour-project.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version, with one exception: - * - * The exception is that if you link the Harbour Runtime Library (HRL) - * and/or the Harbour Virtual Machine (HVM) 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 HRL - * and/or HVM code into it. - * - * 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 program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit - * their web site at http://www.gnu.org/). - * - */ - -#include "hbclass.ch" -#include "hb_btree.ch" - -CREATE CLASS TBTree STATIC - - HIDDEN: - DATA nHandle /* hb_btree handle */ - METHOD Open( cFileName, nFlags, nBuffers ) - METHOD New( cFileName, nPageSize, nKeySize, nFlags, nBuffers ) CONSTRUCTOR - - EXPORTED: - METHOD Close() INLINE hb_BTreeClose( ::nHandle ) , ::nHandle := 0 - METHOD Insert( cKey, lData ) INLINE hb_BTreeInsert( ::nHandle, cKey, lData ) - METHOD Delete( cKey, lData ) INLINE hb_BTreeDelete( ::nHandle, cKey, lData ) - METHOD Key() INLINE hb_BTreeKey( ::nHandle ) - METHOD Data() INLINE hb_BTreeData( ::nHandle ) - METHOD GoTop() INLINE hb_BTreeGoTop( ::nHandle ) - METHOD GoBottom() INLINE hb_BTreeGoBottom( ::nHandle ) - METHOD Skip( nRecords ) INLINE hb_BTreeSkip( ::nHandle, nRecords ) - METHOD Seek( cKey, lData, lSoftSeek ) INLINE hb_BTreeSeek( ::nHandle, cKey, lData, lSoftSeek ) - METHOD Info( nIndex ) INLINE hb_BTreeInfo( ::nHandle, nIndex ) - -ENDCLASS - -METHOD New( cFileName, nPageSize, nKeySize, nFlags, nBuffers ) CLASS TBTree - ::nHandle := hb_btreenew( cFileName, nPageSize, nKeySize, nFlags, nBuffers ) - IF ::nHandle >= 1 - RETURN SELF - ENDIF - RETURN NIL - -METHOD Open( cFileName, nFlags, nBuffers ) CLASS TBTree - ::nHandle := hb_btreeopen( cFileName, nFlags, nBuffers ) - IF ::nHandle >= 1 - RETURN SELF - ENDIF - RETURN NIL - -FUNCTION TBTreeNew( FileName, PageSize, KeySize, nFlags, Buffers ) - RETURN TBTree():New( FileName, PageSize, KeySize, nFlags, Buffers ) - -FUNCTION TBTreeOpen( FileName, nFlags, Buffers ) - RETURN TBTree():Open( FileName, nFlags, Buffers ) diff --git a/harbour/examples/hbbtree/tests/ctest.c b/harbour/examples/hbbtree/tests/ctest.c deleted file mode 100644 index 22983545d7..0000000000 --- a/harbour/examples/hbbtree/tests/ctest.c +++ /dev/null @@ -1,224 +0,0 @@ -/* - * $Id$ - */ - -/* - * Harbour Project source code: - * hb_BTree api test - * - * Copyright 2000 April White - * 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 of the License, or - * (at your option) any later version, with one exception: - * - * The exception is that if you link the Harbour Runtime Library (HRL) - * and/or the Harbour Virtual Machine (HVM) 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 HRL - * and/or HVM code into it. - * - * 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 program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit - * their web site at http://www.gnu.org/). - * - */ - -#include "hbapi.h" -#include "hbapiitm.h" - -#include "hb_btree.h" - -static void display( const char *cKey, HB_LONG lData, HB_BOOL NewLine ) -{ - int n; - char buffer[ 80 ]; - - if( *cKey ) - n = hb_snprintf( buffer, sizeof( buffer ), "%s %ld", cKey, lData ); - else - n = hb_snprintf( buffer, sizeof( buffer ), "%ld", lData ); - - hb_conOutStd( buffer, n ); - - if( NewLine ) - hb_conOutStd( hb_conNewLine(), strlen( hb_conNewLine() ) ); -} - - -static void insertdata( struct hb_BTree * pBTree ) -{ - PHB_ITEM data = hb_itemNew( NULL ); - - hb_BTreeInsert( pBTree, "fuweqgsz", hb_itemPutNL( data, 1 ) ); - hb_BTreeInsert( pBTree, "sjruexrd", hb_itemPutNL( data, 2 ) ); - hb_BTreeInsert( pBTree, "fvveitnz", hb_itemPutNL( data, 3 ) ); - hb_BTreeInsert( pBTree, "aqgksjxe", hb_itemPutNL( data, 4 ) ); - hb_BTreeInsert( pBTree, "oonrehvj", hb_itemPutNL( data, 5 ) ); - hb_BTreeInsert( pBTree, "gvowjwtr", hb_itemPutNL( data, 6 ) ); - hb_BTreeInsert( pBTree, "xxidwtvn", hb_itemPutNL( data, 7 ) ); - hb_BTreeInsert( pBTree, "rwjbxesd", hb_itemPutNL( data, 8 ) ); - hb_BTreeInsert( pBTree, "yaznsaek", hb_itemPutNL( data, 9 ) ); - hb_BTreeInsert( pBTree, "wbdhfkfy", hb_itemPutNL( data, 10 ) ); - hb_BTreeInsert( pBTree, "lryaezia", hb_itemPutNL( data, 11 ) ); - hb_BTreeInsert( pBTree, "tspmnrvk", hb_itemPutNL( data, 12 ) ); - hb_BTreeInsert( pBTree, "hpxryhdj", hb_itemPutNL( data, 13 ) ); - hb_BTreeInsert( pBTree, "sztcqaby", hb_itemPutNL( data, 14 ) ); - hb_BTreeInsert( pBTree, "fcyzsqja", hb_itemPutNL( data, 15 ) ); - hb_BTreeInsert( pBTree, "uccxumvg", hb_itemPutNL( data, 16 ) ); - hb_BTreeInsert( pBTree, "amwuoout", hb_itemPutNL( data, 17 ) ); - hb_BTreeInsert( pBTree, "yaytseln", hb_itemPutNL( data, 18 ) ); - hb_BTreeInsert( pBTree, "sfiiozej", hb_itemPutNL( data, 19 ) ); - hb_BTreeInsert( pBTree, "xuvsoljy", hb_itemPutNL( data, 20 ) ); - hb_BTreeInsert( pBTree, "qmqjbedm", hb_itemPutNL( data, 21 ) ); - hb_BTreeInsert( pBTree, "cctzzrkz", hb_itemPutNL( data, 22 ) ); - hb_BTreeInsert( pBTree, "ikytgdon", hb_itemPutNL( data, 23 ) ); - hb_BTreeInsert( pBTree, "pksobcwu", hb_itemPutNL( data, 24 ) ); - hb_BTreeInsert( pBTree, "vmurindj", hb_itemPutNL( data, 25 ) ); - hb_BTreeInsert( pBTree, "elvybqwg", hb_itemPutNL( data, 26 ) ); - hb_BTreeInsert( pBTree, "ixchaztx", hb_itemPutNL( data, 27 ) ); - hb_BTreeInsert( pBTree, "nzpztlhd", hb_itemPutNL( data, 28 ) ); - hb_BTreeInsert( pBTree, "aucrchiw", hb_itemPutNL( data, 29 ) ); - hb_BTreeInsert( pBTree, "munrytse", hb_itemPutNL( data, 30 ) ); - hb_BTreeInsert( pBTree, "kqkhcmls", hb_itemPutNL( data, 31 ) ); - hb_BTreeInsert( pBTree, "abqhurbi", hb_itemPutNL( data, 32 ) ); - hb_BTreeInsert( pBTree, "ymrldckr", hb_itemPutNL( data, 33 ) ); - hb_BTreeInsert( pBTree, "rhsmfflc", hb_itemPutNL( data, 34 ) ); - hb_BTreeInsert( pBTree, "apyfkvee", hb_itemPutNL( data, 35 ) ); - hb_BTreeInsert( pBTree, "cdntyzrf", hb_itemPutNL( data, 36 ) ); - hb_BTreeInsert( pBTree, "iacblqrh", hb_itemPutNL( data, 37 ) ); - hb_BTreeInsert( pBTree, "xvewqana", hb_itemPutNL( data, 38 ) ); - hb_BTreeInsert( pBTree, "xmybqytj", hb_itemPutNL( data, 39 ) ); - hb_BTreeInsert( pBTree, "dnowympf", hb_itemPutNL( data, 40 ) ); - hb_BTreeInsert( pBTree, "smloihft", hb_itemPutNL( data, 41 ) ); - hb_BTreeInsert( pBTree, "zumppmis", hb_itemPutNL( data, 42 ) ); - hb_BTreeInsert( pBTree, "jirucnxu", hb_itemPutNL( data, 43 ) ); - hb_BTreeInsert( pBTree, "ecdzikcv", hb_itemPutNL( data, 44 ) ); - hb_BTreeInsert( pBTree, "slbwvnpg", hb_itemPutNL( data, 45 ) ); - hb_BTreeInsert( pBTree, "yaftlkmz", hb_itemPutNL( data, 46 ) ); - hb_BTreeInsert( pBTree, "blcepksd", hb_itemPutNL( data, 47 ) ); - hb_BTreeInsert( pBTree, "xufowlpl", hb_itemPutNL( data, 48 ) ); - hb_BTreeInsert( pBTree, "xegtjtqc", hb_itemPutNL( data, 49 ) ); - hb_BTreeInsert( pBTree, "yplcqumq", hb_itemPutNL( data, 50 ) ); - hb_BTreeInsert( pBTree, "vdoycauz", hb_itemPutNL( data, 51 ) ); - hb_BTreeInsert( pBTree, "uhqkjuph", hb_itemPutNL( data, 52 ) ); - hb_BTreeInsert( pBTree, "prllaeyi", hb_itemPutNL( data, 53 ) ); - hb_BTreeInsert( pBTree, "ybzgmwzm", hb_itemPutNL( data, 54 ) ); - hb_BTreeInsert( pBTree, "kkvyllnp", hb_itemPutNL( data, 55 ) ); - hb_BTreeInsert( pBTree, "nberwsrb", hb_itemPutNL( data, 56 ) ); - hb_BTreeInsert( pBTree, "wgetahua", hb_itemPutNL( data, 57 ) ); - hb_BTreeInsert( pBTree, "yxcyehcv", hb_itemPutNL( data, 58 ) ); - hb_BTreeInsert( pBTree, "oacormks", hb_itemPutNL( data, 59 ) ); - hb_BTreeInsert( pBTree, "mcadkdxo", hb_itemPutNL( data, 60 ) ); - hb_BTreeInsert( pBTree, "ycsalwqw", hb_itemPutNL( data, 61 ) ); - hb_BTreeInsert( pBTree, "qmpysvjl", hb_itemPutNL( data, 62 ) ); - hb_BTreeInsert( pBTree, "iqikamew", hb_itemPutNL( data, 63 ) ); - hb_BTreeInsert( pBTree, "iaparrva", hb_itemPutNL( data, 64 ) ); - hb_BTreeInsert( pBTree, "casbvtay", hb_itemPutNL( data, 65 ) ); - hb_BTreeInsert( pBTree, "blaksexr", hb_itemPutNL( data, 66 ) ); - hb_BTreeInsert( pBTree, "tbosrbql", hb_itemPutNL( data, 67 ) ); - hb_BTreeInsert( pBTree, "ifkywsyt", hb_itemPutNL( data, 68 ) ); - hb_BTreeInsert( pBTree, "gvklwevy", hb_itemPutNL( data, 69 ) ); - hb_BTreeInsert( pBTree, "krpmpbud", hb_itemPutNL( data, 70 ) ); - hb_BTreeInsert( pBTree, "rdvlwbwm", hb_itemPutNL( data, 71 ) ); - hb_BTreeInsert( pBTree, "apnvdkww", hb_itemPutNL( data, 72 ) ); - hb_BTreeInsert( pBTree, "euqdocvm", hb_itemPutNL( data, 73 ) ); - hb_BTreeInsert( pBTree, "ksmkjcwp", hb_itemPutNL( data, 74 ) ); - hb_BTreeInsert( pBTree, "bztgclzc", hb_itemPutNL( data, 75 ) ); - hb_BTreeInsert( pBTree, "awkdnuxa", hb_itemPutNL( data, 76 ) ); - hb_BTreeInsert( pBTree, "abavnpod", hb_itemPutNL( data, 77 ) ); - hb_BTreeInsert( pBTree, "dvwvhjmh", hb_itemPutNL( data, 78 ) ); - hb_BTreeInsert( pBTree, "dmfmivqb", hb_itemPutNL( data, 79 ) ); - hb_BTreeInsert( pBTree, "ewsxanon", hb_itemPutNL( data, 80 ) ); - hb_itemRelease( data ); -} - -HB_FUNC( CTEST ) -{ - struct hb_BTree * pBTree; - - display( "Harbour API test", 0, HB_TRUE ); - pBTree = hb_BTreeNew( "test_3.out", 2048, 90, HB_BTREE_UNIQUE, 0 ); - if ( pBTree != NULL ) - { -/* - a := hb_BTreeInfo( pBTree ); - display( "File", a[ hb_BTreeINFO_FILENAME ], HB_FALSE ); - display( "Page", a[ hb_BTreeINFO_PAGESIZE ], HB_FALSE ); - display( "Key ", a[ hb_BTreeINFO_KEYSIZE ], HB_FALSE ); - display( "Max ", a[ hb_BTreeINFO_MAXKEYS ], HB_FALSE ); - display( "Min ", a[ hb_BTreeINFO_MINKEYS ], HB_FALSE ); - display( "Flag", a[ hb_BTreeINFO_FLAGS ], HB_FALSE ); - display( "Keys", a[ hb_BTreeINFO_KEYCOUNT ], HB_TRUE ); -*/ - insertdata( pBTree ); -/* - display( "Keys", hb_BTreeInfo( pBTree, hb_BTreeINFO_KEYCOUNT ), HB_TRUE ); -*/ - display( "Forward traversal", 0, HB_TRUE ); - hb_BTreeGoTop( pBTree ); - while ( HB_TRUE ) - { - display( ( char * ) hb_BTreeKey( pBTree ), hb_BTreeData( pBTree ), HB_TRUE ); - - if ( 1 != hb_BTreeSkip( pBTree, 1 ) ) - break; - } - - hb_conOutStd( hb_conNewLine(), strlen( hb_conNewLine() ) ); - display( "Reverse traversal", 0, HB_TRUE ); - hb_BTreeGoBottom( pBTree ); - while ( HB_TRUE ) - { - display( ( char * ) hb_BTreeKey( pBTree ), hb_BTreeData( pBTree ), HB_TRUE ); - - if ( -1 != hb_BTreeSkip( pBTree, -1 ) ) - break; - } - - hb_conOutStd( hb_conNewLine(), strlen( hb_conNewLine() ) ); - display( "Test SEEK", 0, HB_TRUE ); - display( hb_BTreeSeek( pBTree, "cdntyzrf", 36, HB_FALSE ) == 1 ? ".T." : ".F.", 0, HB_TRUE ); - display( ( char * ) hb_BTreeKey( pBTree ), hb_BTreeData( pBTree ), HB_TRUE ); - hb_BTreeSkip( pBTree, 1 ); - display( ( char * ) hb_BTreeKey( pBTree ), hb_BTreeData( pBTree ), HB_FALSE ); - display( " dmfmivqb ?", 0, HB_TRUE ); - hb_conOutStd( hb_conNewLine(), strlen( hb_conNewLine() ) ); - display( "Test soft SEEK of a short key", 0, HB_TRUE ); - display( hb_BTreeSeek( pBTree, "cd", 0, HB_TRUE ) == 1 ? ".T." : ".F.", 0, HB_TRUE ); - display( ( char * ) hb_BTreeKey( pBTree ), hb_BTreeData( pBTree ), HB_TRUE ); - hb_BTreeSkip( pBTree, 1 ); - display( ( char * ) hb_BTreeKey( pBTree ), hb_BTreeData( pBTree ), HB_FALSE ); - display( " dmfmivqb ?", 0, HB_TRUE ); - - hb_conOutStd( hb_conNewLine(), strlen( hb_conNewLine() ) ); - display( "Test soft SEEK of an existing key", 0, HB_TRUE ); - display( hb_BTreeSeek( pBTree, "cdntyzrf", 0, HB_TRUE ) == 1 ? ".T." : ".F.", 0, HB_TRUE ); - display( ( char * ) hb_BTreeKey( pBTree ), hb_BTreeData( pBTree ), HB_TRUE ); - hb_BTreeSkip( pBTree, 1 ); - display( ( char * ) hb_BTreeKey( pBTree ), hb_BTreeData( pBTree ), HB_FALSE ); - display( " dmfmivqb ?", 0, HB_TRUE ); - - hb_conOutStd( hb_conNewLine(), strlen( hb_conNewLine() ) ); - display( "Test soft SEEK of a missing key, that should force EOF", 0, HB_TRUE ); - display( hb_BTreeSeek( pBTree, "zzzzzz", 0, HB_FALSE ) == 1 ? ".T." : ".F.", 0, HB_TRUE ); - display( ( char * ) hb_BTreeKey( pBTree ), hb_BTreeData( pBTree ), HB_TRUE ); - hb_BTreeSkip( pBTree, 1 ); - display( ( char * ) hb_BTreeKey( pBTree ), hb_BTreeData( pBTree ), HB_FALSE ); - display( " dmfmivqb ?", 0, HB_TRUE ); - - hb_conOutStd( hb_conNewLine(), strlen( hb_conNewLine() ) ); - hb_BTreeClose( pBTree ); - } - else - display( "error / failure", 0, HB_TRUE ); -} diff --git a/harbour/examples/hbbtree/tests/hbmk.hbm b/harbour/examples/hbbtree/tests/hbmk.hbm deleted file mode 100644 index a231d367f3..0000000000 --- a/harbour/examples/hbbtree/tests/hbmk.hbm +++ /dev/null @@ -1,7 +0,0 @@ -# -# $Id$ -# - -../hbbtree.hbc - --w3 -es2 diff --git a/harbour/examples/hbbtree/tests/test.hbp b/harbour/examples/hbbtree/tests/test.hbp deleted file mode 100644 index 32a08e86d0..0000000000 --- a/harbour/examples/hbbtree/tests/test.hbp +++ /dev/null @@ -1,11 +0,0 @@ -# -# $Id$ -# - --q0 - --nulrdd - --gtstd - -test.prg ttest.prg ctest.c diff --git a/harbour/examples/hbbtree/tests/test.prg b/harbour/examples/hbbtree/tests/test.prg deleted file mode 100644 index 1bfe9e1aad..0000000000 --- a/harbour/examples/hbbtree/tests/test.prg +++ /dev/null @@ -1,329 +0,0 @@ -/* - * $Id$ - */ - -/* - * Harbour Project source code: - * hb_btree api test - * - * Copyright 2000 April White - * 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 of the License, or - * (at your option) any later version, with one exception: - * - * The exception is that if you link the Harbour Runtime Library (HRL) - * and/or the Harbour Virtual Machine (HVM) 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 HRL - * and/or HVM code into it. - * - * 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 program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit - * their web site at http://www.gnu.org/). - * - */ - -#include "simpleio.ch" -#include "hb_btree.ch" -#include "fileio.ch" - -Procedure Main() - local c - local attr - - // _2 is from ttest.prg; _3 is from ctest.c - FOR EACH c IN { "test_1.out", "test_1a.out", "test_1b.out", "test_2.out", "test_3.out" } - hb_FGetAttr( c, @attr ) - if attr == 1 + 32 - hb_FSetAttr( c, 32 ) - endif - ferase( c ) - NEXT - - testInMemory() - testInFile() - -return - -static procedure insertdata( n, s ) - if s == NIL ; s := 1; endif - hb_btreeinsert( n, "fuweqgsz", 1 / s ) - hb_btreeinsert( n, "sjruexrd", 2 / s ) - hb_btreeinsert( n, "fvveitnz", 3 / s ) - hb_btreeinsert( n, "aqgksjxe", 4 / s ) - hb_btreeinsert( n, "oonrehvj", 5 / s ) - hb_btreeinsert( n, "gvowjwtr", 6 / s ) - hb_btreeinsert( n, "xxidwtvn", 7 / s ) - hb_btreeinsert( n, "rwjbxesd", 8 / s ) - hb_btreeinsert( n, "yaznsaek", 9 / s ) - hb_btreeinsert( n, "wbdhfkfy", 10 / s ) - hb_btreeinsert( n, "lryaezia", 11 / s ) - hb_btreeinsert( n, "tspmnrvk", 12 / s ) - hb_btreeinsert( n, "hpxryhdj", 13 / s ) - hb_btreeinsert( n, "sztcqaby", 14 / s ) - hb_btreeinsert( n, "fcyzsqja", 15 / s ) - hb_btreeinsert( n, "uccxumvg", 16 / s ) - hb_btreeinsert( n, "amwuoout", 17 / s ) - hb_btreeinsert( n, "yaytseln", 18 / s ) - hb_btreeinsert( n, "sfiiozej", 19 / s ) - hb_btreeinsert( n, "xuvsoljy", 20 / s ) - hb_btreeinsert( n, "qmqjbedm", 21 / s ) - hb_btreeinsert( n, "cctzzrkz", 22 / s ) - hb_btreeinsert( n, "ikytgdon", 23 / s ) - hb_btreeinsert( n, "pksobcwu", 24 / s ) - hb_btreeinsert( n, "vmurindj", 25 / s ) - hb_btreeinsert( n, "elvybqwg", 26 / s ) - hb_btreeinsert( n, "ixchaztx", 27 / s ) - hb_btreeinsert( n, "nzpztlhd", 28 / s ) - hb_btreeinsert( n, "aucrchiw", 29 / s ) - hb_btreeinsert( n, "munrytse", 30 / s ) - hb_btreeinsert( n, "kqkhcmls", 31 / s ) - hb_btreeinsert( n, "abqhurbi", 32 / s ) - hb_btreeinsert( n, "ymrldckr", 33 / s ) - hb_btreeinsert( n, "rhsmfflc", 34 / s ) - hb_btreeinsert( n, "apyfkvee", 35 / s ) - hb_btreeinsert( n, "cdntyzrf", 36 / s ) - hb_btreeinsert( n, "iacblqrh", 37 / s ) - hb_btreeinsert( n, "xvewqana", 38 / s ) - hb_btreeinsert( n, "xmybqytj", 39 / s ) - hb_btreeinsert( n, "dnowympf", 40 / s ) - hb_btreeinsert( n, "smloihft", 41 / s ) - hb_btreeinsert( n, "zumppmis", 42 / s ) - hb_btreeinsert( n, "jirucnxu", 43 / s ) - hb_btreeinsert( n, "ecdzikcv", 44 / s ) - hb_btreeinsert( n, "slbwvnpg", 45 / s ) - hb_btreeinsert( n, "yaftlkmz", 46 / s ) - hb_btreeinsert( n, "blcepksd", 47 / s ) - hb_btreeinsert( n, "xufowlpl", 48 / s ) - hb_btreeinsert( n, "xegtjtqc", 49 / s ) - hb_btreeinsert( n, "yplcqumq", 50 / s ) - hb_btreeinsert( n, "vdoycauz", 51 / s ) - hb_btreeinsert( n, "uhqkjuph", 52 / s ) - hb_btreeinsert( n, "prllaeyi", 53 / s ) - hb_btreeinsert( n, "ybzgmwzm", 54 / s ) - hb_btreeinsert( n, "kkvyllnp", 55 / s ) - hb_btreeinsert( n, "nberwsrb", 56 / s ) - hb_btreeinsert( n, "wgetahua", 57 / s ) - hb_btreeinsert( n, "yxcyehcv", 58 / s ) - hb_btreeinsert( n, "oacormks", 59 / s ) - hb_btreeinsert( n, "mcadkdxo", 60 / s ) - hb_btreeinsert( n, "ycsalwqw", 61 / s ) - hb_btreeinsert( n, "qmpysvjl", 62 / s ) - hb_btreeinsert( n, "iqikamew", 63 / s ) - hb_btreeinsert( n, "iaparrva", 64 / s ) - hb_btreeinsert( n, "casbvtay", 65 / s ) - hb_btreeinsert( n, "blaksexr", 66 / s ) - hb_btreeinsert( n, "tbosrbql", 67 / s ) - hb_btreeinsert( n, "ifkywsyt", 68 / s ) - hb_btreeinsert( n, "gvklwevy", 69 / s ) - hb_btreeinsert( n, "krpmpbud", 70 / s ) - hb_btreeinsert( n, "rdvlwbwm", 71 / s ) - hb_btreeinsert( n, "apnvdkww", 72 / s ) - hb_btreeinsert( n, "euqdocvm", 73 / s ) - hb_btreeinsert( n, "ksmkjcwp", 74 / s ) - hb_btreeinsert( n, "bztgclzc", 75 / s ) - hb_btreeinsert( n, "awkdnuxa", 76 / s ) - hb_btreeinsert( n, "abavnpod", 77 / s ) - hb_btreeinsert( n, "dvwvhjmh", 78 / s ) - hb_btreeinsert( n, "dmfmivqb", 79 / s ) - hb_btreeinsert( n, "ewsxanon", 80 / s ) -return - -STATIC PROCEDURE testInMemory() - LOCAL n - LOCAL c - - ? "Harbour API test: in-memory" - n := hb_btreenew( , 2048, 90, HB_BTREE_READONLY + HB_BTREE_INMEMORY ) - if n > 0 - ? "successfully opened" - insertdata( n, 100 ) - ? "# keys", hb_btreeinfo( n, HB_BTREEINFO_KEYCOUNT ) - - ? "skip to EOF test" - hb_btreegobottom( n ) - ? hb_btreekey( n ), hb_btreedata( n ) - ? hb_btreeskip( n, 1 ) - ? "skip to EOF test end" - - ? "Forward traversal" - hb_btreegotop( n ) - c := 0 - while .t. - ? hb_btreekey( n ), hb_btreedata( n ), ++c - if 1 != hb_btreeskip( n, 1 )// .or. c == hb_btreeinfo( n, HB_BTREEINFO_KEYCOUNT )-1 - exit - endif - end - ? "Forward traversal end" - ? - - ? "Reverse traversal" - hb_btreegobottom( n ) - c := 0 - while .t. - ? hb_btreekey( n ), hb_btreedata( n ), ++c - if -1 != hb_btreeskip( n, -1 )// .or. c == hb_btreeinfo( n, HB_BTREEINFO_KEYCOUNT )-1 - exit - endif - end - ? "Reverse traversal end" - ? - - ? "Test SEEK of 'cdntyzrf'" - ? hb_btreeseek( n, "cdntyzrf" ) - ? hb_btreekey( n ), hb_btreedata( n ) - hb_btreeskip( n, 1 ) - ? hb_btreekey( n ), hb_btreedata( n ), "dmfmivqb ?" - - ? - ? "Test soft SEEK of short key 'cd'" - ? hb_btreeseek( n, "cd", , .t. ) - ? hb_btreekey( n ), hb_btreedata( n ) - hb_btreeskip( n, 1 ) - ? hb_btreekey( n ), hb_btreedata( n ), "dmfmivqb ?" - - ? - ? "Test soft SEEK of an existing key 'cdntyzrf'" - ? hb_btreeseek( n, "cdntyzrf", , .t. ) - ? hb_btreekey( n ), hb_btreedata( n ) - hb_btreeskip( n, 1 ) - ? hb_btreekey( n ), hb_btreedata( n ), "dmfmivqb ?" - - ? - ? "Test soft SEEK of a missing key, that should force EOF ('zzzzzz')" - ? hb_btreeseek( n, "zzzzzz" ) - ? hb_btreekey( n ), hb_btreedata( n ) - hb_btreeskip( n, 1 ) - ? hb_btreekey( n ), hb_btreedata( n ), "dmfmivqb ?" - - ? - hb_btreeclose( n ) - else - ? "error / failure" - wait - endif - - ? "Harbour API test: in-memory end" - -STATIC PROCEDURE testInFile() - LOCAL n - LOCAL c - LOCAL a - - ? "Harbour API test" - n := hb_btreenew( "test_1.out", 2048, 90, HB_BTREE_READONLY ) - if n > 0 - - ? valtype( a := hb_btreeinfo( n ) ) - ? "File", a[ HB_BTREEINFO_FILENAME ] - ? "Page", a[ HB_BTREEINFO_PAGESIZE ] - ? "Key ", a[ HB_BTREEINFO_KEYSIZE ] - ? "Max ", a[ HB_BTREEINFO_MAXKEYS ] - ? "Min ", a[ HB_BTREEINFO_MINKEYS ] - ? "Flag", a[ HB_BTREEINFO_FLAGS ] - ? "Keys", a[ HB_BTREEINFO_KEYCOUNT ] - ? - - insertdata( n ) - - ? "Keys", hb_btreeinfo( n, HB_BTREEINFO_KEYCOUNT ) - - ? - ? "Forward traversal" - hb_btreegotop( n ) - c := 0 - while .t. - ? hb_btreekey( n ), hb_btreedata( n ), ++c - if 1 != hb_btreeskip( n, 1 ) - exit - endif - end - - ? - ? "Reverse traversal" - hb_btreegobottom( n ) - c := 0 - while .t. - ? hb_btreekey( n ), hb_btreedata( n ), ++c - if -1 != hb_btreeskip( n, -1 ) - exit - endif - end - - ? - ? "Test SEEK" - ? hb_btreeseek( n, "cdntyzrf" ) - ? hb_btreekey( n ), hb_btreedata( n ) - hb_btreeskip( n, 1 ) - ? hb_btreekey( n ), hb_btreedata( n ), "dmfmivqb ?" - - ? - ? "Test soft SEEK of a short key" - ? hb_btreeseek( n, "cd", , .t. ) - ? hb_btreekey( n ), hb_btreedata( n ) - hb_btreeskip( n, 1 ) - ? hb_btreekey( n ), hb_btreedata( n ), "dmfmivqb ?" - - ? - ? "Test soft SEEK of an existing key" - ? hb_btreeseek( n, "cdntyzrf", , .t. ) - ? hb_btreekey( n ), hb_btreedata( n ) - hb_btreeskip( n, 1 ) - ? hb_btreekey( n ), hb_btreedata( n ), "dmfmivqb ?" - - ? - ? "Test soft SEEK of a missing key, that should force EOF" - ? hb_btreeseek( n, "zzzzzz" ) - ? hb_btreekey( n ), hb_btreedata( n ) - hb_btreeskip( n, 1 ) - ? hb_btreekey( n ), hb_btreedata( n ), "dmfmivqb ?" - - ? - - hb_btreeclose( n ) - - TTest() - CTest() - - else - ? "error / failure" - endif - - ? - ? "Harbour caseless sensitivity API test" - n := hb_btreenew( "test_1a.out", 2048, 90, HB_BTREE_CASELESS ) - if n > 0 - hb_btreeinsert( n, "alpha", 0 ) - if hb_btreeinsert( n, "ALPHA", 0 ) - ? "inserted 'ALPHA', test failed" - else - ? "could not insert 'ALPHA', test passed" - endif - hb_btreeclose( n ) - endif - - ? - ? "Harbour case sensitivity API test" - n := hb_btreenew( "test_1b.out", 2048, 90 ) - if n > 0 - hb_btreeinsert( n, "alpha", 0 ) - if hb_btreeinsert( n, "ALPHA", 0 ) - ? "inserted 'ALPHA', test passed" - else - ? "could not insert 'ALPHA', test failed" - endif - hb_btreeclose( n ) - endif - - ? diff --git a/harbour/examples/hbbtree/tests/ttest.prg b/harbour/examples/hbbtree/tests/ttest.prg deleted file mode 100644 index ba28b3adc9..0000000000 --- a/harbour/examples/hbbtree/tests/ttest.prg +++ /dev/null @@ -1,198 +0,0 @@ -* - * $Id$ - */ - -/* - * Harbour Project source code: - * hb_btree api test - * - * Copyright 2000 April White - * 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 of the License, or - * (at your option) any later version, with one exception: - * - * The exception is that if you link the Harbour Runtime Library (HRL) - * and/or the Harbour Virtual Machine (HVM) 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 HRL - * and/or HVM code into it. - * - * 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 program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit - * their web site at http://www.gnu.org/). - * - */ - -#include "simpleio.ch" -#include "hb_btree.ch" - -Procedure TTest() - local n, a - - ? "Harbour TBTree API test" - n := TBTreeNew( "test_2.out", 2048, 90 ) - if n != NIL - - ? valtype( a := n:info() ) - ? "File", a[ HB_BTREEINFO_FILENAME ] - ? "Page", a[ HB_BTREEINFO_PAGESIZE ] - ? "Key ", a[ HB_BTREEINFO_KEYSIZE ] - ? "Max ", a[ HB_BTREEINFO_MAXKEYS ] - ? "Min ", a[ HB_BTREEINFO_MINKEYS ] - ? "Flag", a[ HB_BTREEINFO_FLAGS ] - ? "Keys", a[ HB_BTREEINFO_KEYCOUNT ] - ? - - insertdata( n ) - - ? "Keys", n:info( HB_BTREEINFO_KEYCOUNT ) - - ? - ? "Forward traversal" - n:gotop() - while .t. - ? n:key(), n:data() - if 1 != n:skip( 1 ) - exit - endif - end - - ? - ? "Reverse traversal" - n:gobottom() - while .t. - ? n:key(), n:data() - if -1 != n:skip( -1 ) - exit - endif - end - - ? - ? "Test SEEK" - ? n:seek( "cdntyzrf" ) - ? n:key(), n:data() - n:skip( 1 ) - ? n:key(), n:data(), "dmfmivqb ?" - - ? - ? "Test soft SEEK of a short key" - ? n:seek( "cd", ,.t. ) - ? n:key(), n:data() - n:skip( 1 ) - ? n:key(), n:data(), "dmfmivqb ?" - - ? - ? "Test soft SEEK of an existing key" - ? n:seek( "cdntyzrf", , .t. ) - ? n:key(), n:data() - n:skip( 1 ) - ? n:key(), n:data(), "dmfmivqb ?" - - ? - ? "Test soft SEEK of a missing key, that should force EOF" - ? n:seek( "zzzzzz" ) - ? n:key(), n:data() - n:skip( 1 ) - ? n:key(), n:data(), "dmfmivqb ?" - - ? - - n:close() - else - ? "error" - endif - -return - -static procedure insertdata( n ) - n:insert( "fuweqgsz", 1 ) - n:insert( "sjruexrd", 2 ) - n:insert( "fvveitnz", 3 ) - n:insert( "aqgksjxe", 4 ) - n:insert( "oonrehvj", 5 ) - n:insert( "gvowjwtr", 6 ) - n:insert( "xxidwtvn", 7 ) - n:insert( "rwjbxesd", 8 ) - n:insert( "yaznsaek", 9 ) - n:insert( "wbdhfkfy", 10 ) - n:insert( "lryaezia", 11 ) - n:insert( "tspmnrvk", 12 ) - n:insert( "hpxryhdj", 13 ) - n:insert( "sztcqaby", 14 ) - n:insert( "fcyzsqja", 15 ) - n:insert( "uccxumvg", 16 ) - n:insert( "amwuoout", 17 ) - n:insert( "yaytseln", 18 ) - n:insert( "sfiiozej", 19 ) - n:insert( "xuvsoljy", 20 ) - n:insert( "qmqjbedm", 21 ) - n:insert( "cctzzrkz", 22 ) - n:insert( "ikytgdon", 23 ) - n:insert( "pksobcwu", 24 ) - n:insert( "vmurindj", 25 ) - n:insert( "elvybqwg", 26 ) - n:insert( "ixchaztx", 27 ) - n:insert( "nzpztlhd", 28 ) - n:insert( "aucrchiw", 29 ) - n:insert( "munrytse", 30 ) - n:insert( "kqkhcmls", 31 ) - n:insert( "abqhurbi", 32 ) - n:insert( "ymrldckr", 33 ) - n:insert( "rhsmfflc", 34 ) - n:insert( "apyfkvee", 35 ) - n:insert( "cdntyzrf", 36 ) - n:insert( "iacblqrh", 37 ) - n:insert( "xvewqana", 38 ) - n:insert( "xmybqytj", 39 ) - n:insert( "dnowympf", 40 ) - n:insert( "smloihft", 41 ) - n:insert( "zumppmis", 42 ) - n:insert( "jirucnxu", 43 ) - n:insert( "ecdzikcv", 44 ) - n:insert( "slbwvnpg", 45 ) - n:insert( "yaftlkmz", 46 ) - n:insert( "blcepksd", 47 ) - n:insert( "xufowlpl", 48 ) - n:insert( "xegtjtqc", 49 ) - n:insert( "yplcqumq", 50 ) - n:insert( "vdoycauz", 51 ) - n:insert( "uhqkjuph", 52 ) - n:insert( "prllaeyi", 53 ) - n:insert( "ybzgmwzm", 54 ) - n:insert( "kkvyllnp", 55 ) - n:insert( "nberwsrb", 56 ) - n:insert( "wgetahua", 57 ) - n:insert( "yxcyehcv", 58 ) - n:insert( "oacormks", 59 ) - n:insert( "mcadkdxo", 60 ) - n:insert( "ycsalwqw", 61 ) - n:insert( "qmpysvjl", 62 ) - n:insert( "iqikamew", 63 ) - n:insert( "iaparrva", 64 ) - n:insert( "casbvtay", 65 ) - n:insert( "blaksexr", 66 ) - n:insert( "tbosrbql", 67 ) - n:insert( "ifkywsyt", 68 ) - n:insert( "gvklwevy", 69 ) - n:insert( "krpmpbud", 70 ) - n:insert( "rdvlwbwm", 71 ) - n:insert( "apnvdkww", 72 ) - n:insert( "euqdocvm", 73 ) - n:insert( "ksmkjcwp", 74 ) - n:insert( "bztgclzc", 75 ) - n:insert( "awkdnuxa", 76 ) - n:insert( "abavnpod", 77 ) - n:insert( "dvwvhjmh", 78 ) - n:insert( "dmfmivqb", 79 ) - n:insert( "ewsxanon", 80 ) -return diff --git a/harbour/examples/hscript/cgi.ch b/harbour/examples/hscript/cgi.ch deleted file mode 100644 index 11a71c7b40..0000000000 --- a/harbour/examples/hscript/cgi.ch +++ /dev/null @@ -1,28 +0,0 @@ -/* - * $Id$ - */ - -//+ -// 99.05.31 initial posting. -//- - -#define CGI_SERVER_SOFTWARE 01 -#define CGI_SERVER_NAME 02 -#define CGI_GATEWAY_INTERFACE 03 -#define CGI_SERVER_PROTOCOL 04 -#define CGI_SERVER_PORT 05 -#define CGI_REQUEST_METHOD 06 -#define CGI_HTTP_ACCEPT 07 -#define CGI_HTTP_USER_AGENT 08 -#define CGI_HTTP_REFERER 09 -#define CGI_PATH_INFO 10 -#define CGI_PATH_TRANSLATED 11 -#define CGI_SCRIPT_NAME 12 -#define CGI_QUERY_STRING 13 -#define CGI_REMOTE_HOST 14 -#define CGI_REMOTE_ADDR 15 -#define CGI_REMOTE_USER 16 -#define CGI_AUTH_TYPE 17 -#define CGI_CONTENT_TYPE 18 -#define CGI_CONTENT_LENGTH 19 -#define CGI_ANNOTATION_SERVER 20 diff --git a/harbour/examples/hscript/dir.hs b/harbour/examples/hscript/dir.hs deleted file mode 100644 index f1a58232eb..0000000000 --- a/harbour/examples/hscript/dir.hs +++ /dev/null @@ -1,54 +0,0 @@ -<% -/* - * $Id$ - */ - -/* -* Written by Felipe Coury -* www - http://harbour-project.org -* -*/ -FUNCTION Start() - - LOCAL aDir := Directory( "*.*" ) - LOCAL i - - IF !Empty( GetEnv( "SERVER_NAME" ) ) - OutStd( "HTTP/1.0 200 OK" + chr(10) ) - OutStd( "CONTENT-TYPE: TEXT/HTML" + chr(10) + chr(10) ) - ENDIF - - ASort( aDir,,, { |x, y| x[1] < y[1] } ) -%> - -dir.hs - HarourScript demo of active context - - - - - - - - - - -<% - FOR i := 1 TO Len( aDir ) -%> - - - - - - - -<% - NEXT -%> -
File NameSizeDateTimeAttributes
<% OutStd( aDir[i,1] ) %><% OutStd( aDir[i,2] ) %><% OutStd( aDir[i,3] ) %><% OutStd( aDir[i,4] ) %><% OutStd( aDir[i,5] ) %>
- - -<% - - RETURN NIL -%> diff --git a/harbour/examples/hscript/hello.hs b/harbour/examples/hscript/hello.hs deleted file mode 100644 index ebe3443d2b..0000000000 --- a/harbour/examples/hscript/hello.hs +++ /dev/null @@ -1,43 +0,0 @@ -<% -/* - * $Id$ - */ - -/* -* -* Famous "Hello World"! -* -* Written by Felipe Coury -* www - http://harbour-project.org -* -*/ - -FUNCTION Start() - - // Add content-type parameter if using active page on a Web Server - IF !empty( GetEnv( "SERVER_NAME" ) ) - OutStd( "HTTP/1.0 200 OK" + chr(10) ) - OutStd( "CONTENT-TYPE: TEXT/HTML" + chr(10) + chr(10) ) - ENDIF - -%> - - -Hello world! - - - -<% - // Now saying hello to the world in 3 different ways: - // 1. Pure harbour: - OutStd( "

Hello world!

" ) - - // 2. Hybrid harbour-html: -%> -

<% OutStd( "Hello world!" ) %>

-<% - // 3. Pure html: -%> -

Hello world!

- - diff --git a/harbour/examples/hscript/hscript.hbp b/harbour/examples/hscript/hscript.hbp deleted file mode 100644 index b0d0a90e2c..0000000000 --- a/harbour/examples/hscript/hscript.hbp +++ /dev/null @@ -1,5 +0,0 @@ -# -# $Id$ -# - -hscript.prg -lhbnf diff --git a/harbour/examples/hscript/hscript.prg b/harbour/examples/hscript/hscript.prg deleted file mode 100644 index 62555eaa4b..0000000000 --- a/harbour/examples/hscript/hscript.prg +++ /dev/null @@ -1,220 +0,0 @@ -/* - * $Id$ - */ - -/* - * hscript.prg - * HarbourScript translation engine - * - * Copyright (C) 1999 Felipe Coury - * www - http://harbour-project.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this software; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). - * - * As a special exception, the Harbour Project gives permission for - * additional uses of the text contained in its release of Harbour. - * - * The exception is that, if you link the Harbour libraries with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the Harbour library code into it. - * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. - * - * This exception applies only to the code released by the Harbour - * Project under the name Harbour. If you copy code from other - * Harbour Project or Free Software Foundation releases into a copy of - * Harbour, as the General Public License permits, the exception does - * not apply to the code that you add in this way. To avoid misleading - * anyone as to the status of such modified files, you must delete - * this exception notice from them. - * - * If you write modifications of your own for Harbour, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. - * - */ - -#include "cgi.ch" - -REQUEST __HB_EXTERN__ - -#define IF_BUFFER 65535 - -PROCEDURE Main( cScript ) - - LOCAL aHRSHandle := {} // Handle for script lines - LOCAL aResult := {} // Handle for transl'd lines - LOCAL cLocation // Location of scripts - LOCAL cHarbourDir := GetEnv( "HARBOURDIR" ) // harbour executable dir with '\' - LOCAL cHost := StrTran( AllTrim( ; // Random (not et al) - Str( Seconds() ) ), '.' ) // file name - LOCAL cScriptName, cFile, cLine, cTrans, c - LOCAL hFile, i, lOpen, nLen - - DO WHILE .T. - - IF Empty( GetEnv( "SERVER_NAME" ) ) - cScriptName := cScript - cLocation := cHarbourDir - - ELSE - cScriptName := GetEnv( "QUERY_STRING" ) - IF At( "=", cScriptName ) != 0 - cScriptName := ParseString( cScriptName, "=", 2 ) - ENDIF - cLocation := GetEnv( "PATH_TRANSLATED" ) + ; - StrTran( GetEnv( "SCRIPT_NAME" ), "/", "\" ) - cLocation := SubStr( cLocation, 1, RAt( "\", cLocation ) ) - cHarbourDir := cLocation - - ENDIF - - IF Empty( cScriptName ) - IF !Empty( GetEnv( "SERVER_NAME" ) ) - OutStd( "content-type: text/html" + hb_eol() ) - OutStd( hb_eol() ) - OutStd( "

Server Error

" + hb_eol() ) - OutStd( "Must specify scriptname using hscript.exe?script=" + hb_eol() ) - OutStd( "" + hb_eol() ) - ELSE - OutStd( "Please give .hs name" + hb_eol() ) - ENDIF - EXIT - ENDIF - - // Script not found - IF !File( cScriptName ) - IF !Empty( GetEnv( "SERVER_NAME" ) ) - OutStd( "CONTENT-TYPE: text/html" + hb_eol() ) - ENDIF - OutStd( "

Server Error

Script not found: " + cScriptName + hb_eol() ) - EXIT - ENDIF - - lOpen := .f. - ft_FUse( cScriptName ) - DO WHILE !ft_FEof() - - cLine := AllTrim( ft_FReadLn() ) - cTrans := "" - nLen := Len( cLine ) - - IF lOpen - cTrans += "OutStd( '" - ENDIF - - FOR i := 1 TO nLen - - c := SubStr( cLine, i, 1 ) - - IF c == "%" .AND. SubStr( cLine, i + 1, 1 ) == ">" - IF lOpen - // Error - Already in htm mode - ELSE - // Abre script - IF i > 1 - //cTrans += " ; " - cTrans += hb_eol() - ENDIF - IF i + 1 < nLen - cTrans += "OutStd( '" - ENDIF - lOpen := .t. - - ENDIF - i++ - - ELSEIF c == "<" .AND. SubStr( cLine, i + 1, 1 ) == "%" - IF !lOpen - // Error - Not in htm mode - ELSE - // Fecha script - cTrans += "' + chr(10) )" - lOpen := .f. - IF i < nLen - // cTrans += " ; " - cTrans += hb_eol() - ENDIF - - ENDIF - i++ - - ELSE - cTrans += c - ENDIF - NEXT - - IF lOpen .AND. !( SubStr( cLine, nLen - 1, 2 ) == "%>" ) - cTrans += "' + Chr(10) )" - ENDIF - - AAdd( aResult, cTrans ) - - ft_FSkip() - - ENDDO - ft_FUse() - - cFile := cLocation + cHost + ".prg" // Output file name - hFile := FCreate( cFile ) - FOR i := 1 TO Len( aResult ) - FWrite( hFile, aResult[i] + hb_eol() ) - NEXT - FClose( hFile ) - - // Creates the temporary .hrb, erases the .prg - hb_Run( cHarbourDir + "harbour " + cFile + " -q -n -gh -o" + Left( cHarbourDir, Len( cHarbourDir ) - 1 ) + iif( !Empty( Left( cHarbourDir, Len( cHarbourDir ) - 1 ) ), "\", "" ) ) - FErase( cFile ) - - // Runs using Tugboat - cFile := StrTran( Lower( cFile ), ".prg", ".hrb" ) - hb_hrbRun( cFile ) - // Erases the .hrb file - FErase( cFile ) - - // That's all, folks! - EXIT - - ENDDO - - RETURN - -FUNCTION ParseString( cString, cDelim, nRet ) - - LOCAL cBuf, aElem, nPosFim, nSize, i - - nSize := Len( cString ) - Len( StrTran( cString, cDelim, '' ) ) + 1 - aElem := Array( nSize ) - - cBuf := cString - - FOR i := 1 TO nSize - nPosFim := At( cDelim, cBuf ) - - IF nPosFim > 0 - aElem[i] := SubStr( cBuf, 1, nPosFim - 1 ) - ELSE - aElem[i] := cBuf - ENDIF - - cBuf := SubStr( cBuf, nPosFim + 1, Len( cBuf ) ) - - NEXT - - RETURN aElem[ nRet ] diff --git a/harbour/examples/hscript/multiply.hs b/harbour/examples/hscript/multiply.hs deleted file mode 100644 index 35f561fe10..0000000000 --- a/harbour/examples/hscript/multiply.hs +++ /dev/null @@ -1,54 +0,0 @@ -<% -/* - * $Id$ - */ - -/* -* -* HarbourScript Test -* -* Written by Felipe Coury -* www - http://harbour-project.org -* -*/ - -FUNCTION Start() - - LOCAL i, j - - IF !empty( GetEnv( "SERVER_NAME" ) ) - OutStd( "HTTP/1.0 200 OK" + chr(10) ) - OutStd( "CONTENT-TYPE: TEXT/HTML" + chr(10) + chr(10) ) - ENDIF -%> - - -Testing script - - -

<% OutStd( "HarbourScript Test!" ) %>

- - -<% - FOR i := 1 TO 10 -%> - - -<% - FOR j := 1 TO 10 -%> - - - - -<% - NEXT -%> -
<% OutStd( str( i, 2 ) + " x " + str( j, 2 ) ) %><% OutStd( i*j ) %>
-
-<% - NEXT -%> - - - diff --git a/harbour/examples/hscript/readme.txt b/harbour/examples/hscript/readme.txt deleted file mode 100644 index 2953a48e58..0000000000 --- a/harbour/examples/hscript/readme.txt +++ /dev/null @@ -1,89 +0,0 @@ -/* - * $Id$ - */ - -WARNING -------- - -This document has serious bugs related to English Language. -I take no responsabilities for any misinformation in any form. - - - -HarbourScript Alfa Edition --------------------------- - -Inside this .zip file you will find HarbourScript package. This -should be unzipped to /tests/working/hscript directory in order -to work w/o any changes. - -To make the HarbourScript Translator, hscript.exe, use hbmk2. -If you are going to test offline, there's no need to make it, -it will be done automatically for you (Batch Power). To test it, -you'll have the following options: - - -Testing HarbourScript using MS-Personal Web Server --------------------------------------------------- - -(and maybe IIS 3.0+ too!) - -1. Copy hscript.exe and harbour.exe to your cgi-bin directory -(or any other with Scripting allowed) - -2. Copy all the scripts that you want to the same directory - -3. You can now test Harbour Script using -http://localhost/cgi-bin/hscript?script=