home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / harbb30g.zip / INCLUDE / extend.h < prev    next >
C/C++ Source or Header  |  1999-09-20  |  19KB  |  406 lines

  1. /*
  2.  * $Id: extend.h,v 1.97 1999/09/20 19:51:04 vszel Exp $
  3.  */
  4.  
  5. /*
  6.  * Harbour Project source code:
  7.  * Header file for the Extend API, Array API, misc API and base declarations
  8.  *
  9.  * Copyright 1999 Antonio Linares <alinares@fivetech.com>
  10.  * www - http://www.harbour-project.org
  11.  *
  12.  * This program is free software; you can redistribute it and/or modify
  13.  * it under the terms of the GNU General Public License as published by
  14.  * the Free Software Foundation; either version 2 of the License, or
  15.  * (at your option) any later version, with one exception:
  16.  *
  17.  * The exception is that if you link the Harbour Runtime Library (HRL)
  18.  * and/or the Harbour Virtual Machine (HVM) with other files to produce
  19.  * an executable, this does not by itself cause the resulting executable
  20.  * to be covered by the GNU General Public License. Your use of that
  21.  * executable is in no way restricted on account of linking the HRL
  22.  * and/or HVM code into it.
  23.  *
  24.  * This program is distributed in the hope that it will be useful,
  25.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  27.  * GNU General Public License for more details.
  28.  *
  29.  * You should have received a copy of the GNU General Public License
  30.  * along with this program; if not, write to the Free Software
  31.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit
  32.  * their web site at http://www.gnu.org/).
  33.  *
  34.  */
  35.  
  36. #ifndef HB_EXTEND_H_
  37. #define HB_EXTEND_H_
  38.  
  39. #include "hbdefs.h"
  40. #include "hb_vmpub.h"
  41.  
  42. /* items types and type checking macros */
  43. #define IT_NIL          ( ( USHORT ) 0x0000 )
  44. #define IT_INTEGER      ( ( USHORT ) 0x0002 )
  45. #define IT_LONG         ( ( USHORT ) 0x0008 )
  46. #define IT_DOUBLE       ( ( USHORT ) 0x0010 )
  47. #define IT_DATE         ( ( USHORT ) 0x0020 )
  48. #define IT_LOGICAL      ( ( USHORT ) 0x0080 )
  49. #define IT_SYMBOL       ( ( USHORT ) 0x0100 )
  50. #define IT_ALIAS        ( ( USHORT ) 0x0200 )
  51. #define IT_STRING       ( ( USHORT ) 0x0400 )
  52. #define IT_MEMOFLAG     ( ( USHORT ) 0x0800 )
  53. #define IT_MEMO         ( IT_MEMOFLAG & IT_STRING )
  54. #define IT_BLOCK        ( ( USHORT ) 0x1000 )
  55. #define IT_BYREF        ( ( USHORT ) 0x2000 )
  56. #define IT_MEMVAR       ( ( USHORT ) 0x4000 )
  57. #define IT_ARRAY        ( ( USHORT ) 0x8000 )
  58. #define IT_OBJECT       IT_ARRAY
  59. #define IT_NUMERIC      ( ( USHORT ) ( IT_INTEGER | IT_LONG | IT_DOUBLE ) )
  60. #define IT_ANY          ( ( USHORT ) 0xFFFF )
  61.  
  62. #define IS_BYREF( p )      ( ( p )->type & IT_BYREF )
  63. #define IS_OF_TYPE( p, t ) ( ( ( p )->type & ~IT_BYREF ) == t )
  64. #define IS_ARRAY( p )      IS_OF_TYPE( p, IT_ARRAY )
  65. #define IS_NIL( p )        IS_OF_TYPE( p, IT_NIL )
  66. #define IS_BLOCK( p )      IS_OF_TYPE( p, IT_BLOCK )
  67. #define IS_DATE( p )       IS_OF_TYPE( p, IT_DATE )
  68. #define IS_DOUBLE( p )     IS_OF_TYPE( p, IT_DOUBLE )
  69. #define IS_INTEGER( p )    IS_OF_TYPE( p, IT_INTEGER )
  70. #define IS_LOGICAL( p )    IS_OF_TYPE( p, IT_LOGICAL )
  71. #define IS_LONG( p )       IS_OF_TYPE( p, IT_LONG )
  72. #define IS_NUMERIC( p )    ( ( p )->type & IT_NUMERIC )
  73. #define IS_OBJECT( p )     IS_OF_TYPE( p, IT_OBJECT )
  74. #define IS_STRING( p )     IS_OF_TYPE( p, IT_STRING )
  75. #define IS_SYMBOL( p )     IS_OF_TYPE( p, IT_SYMBOL )
  76. #define IS_MEMVAR( p )     IS_OF_TYPE( p, IT_MEMVAR )
  77.  
  78. #define ISNIL( n )         ( hb_param( n, IT_NIL ) != NULL )
  79. #define ISCHAR( n )        ( hb_param( n, IT_STRING ) != NULL )
  80. #define ISNUM( n )         ( hb_param( n, IT_NUMERIC ) != NULL )
  81. #define ISLOG( n )         ( hb_param( n, IT_LOGICAL ) != NULL )
  82. #define ISDATE( n )        ( hb_param( n, IT_DATE ) != NULL )
  83. #define ISMEMO( n )        ( hb_param( n, IT_MEMO ) != NULL )
  84. #define ISBYREF( n )       ( hb_parinfo( n ) & IT_BYREF ) /* NOTE: Intentionally using a different method */
  85. #define ISARRAY( n )       ( hb_param( n, IT_ARRAY ) != NULL )
  86.  
  87. #define PCOUNT             hb_pcount()
  88. #define ALENGTH( n )       hb_parinfa( n, 0 )
  89.  
  90. /* forward declarations */
  91. struct _HB_CODEBLOCK;
  92. struct _HB_BASEARRAY;
  93. struct _HB_ITEM;
  94. struct _HB_VALUE;
  95.  
  96. /* Internal structures that holds data */
  97. struct hb_struArray
  98. {
  99.    struct _HB_BASEARRAY * value;
  100. };
  101.  
  102. struct hb_struBlock
  103. {
  104.    LONG statics;
  105.    USHORT lineno;
  106.    USHORT paramcnt;
  107.    struct _HB_CODEBLOCK * value;
  108. };
  109.  
  110. struct hb_struDate
  111. {
  112.    LONG value;
  113. };
  114.  
  115. struct hb_struDouble
  116. {
  117.    USHORT length;
  118.    USHORT decimal;
  119.    double value;
  120. };
  121.  
  122. struct hb_struInteger
  123. {
  124.    USHORT length;
  125.    int value;
  126. };
  127.  
  128. struct hb_struLogical
  129. {
  130.    BOOL value;
  131. };
  132.  
  133. struct hb_struLong
  134. {
  135.    USHORT length;
  136.    long value;
  137. };
  138.  
  139. struct hb_struMemvar
  140. {
  141.    struct _HB_VALUE * *itemsbase;
  142.    LONG offset;
  143.    LONG value;
  144. };
  145.  
  146. struct hb_struPointer
  147. {
  148.    void * value;
  149. };
  150.  
  151. struct hb_struRefer
  152. {
  153.    struct _HB_ITEM * *itemsbase;
  154.    LONG offset;
  155.    LONG value;
  156. };
  157.  
  158. struct hb_struString
  159. {
  160.    ULONG length;
  161.    char * value;
  162. };
  163.  
  164. struct hb_struSymbol
  165. {
  166.    LONG stackbase;
  167.    USHORT lineno;
  168.    USHORT paramcnt;
  169.    PHB_SYMB value;
  170. };
  171.  
  172. /* items hold at the virtual machine stack */
  173. typedef struct _HB_ITEM
  174. {
  175.    USHORT type;
  176.    union
  177.    {
  178.       struct hb_struArray   asArray;
  179.       struct hb_struBlock   asBlock;
  180.       struct hb_struDate    asDate;
  181.       struct hb_struDouble  asDouble;
  182.       struct hb_struInteger asInteger;
  183.       struct hb_struLogical asLogical;
  184.       struct hb_struLong    asLong;
  185.       struct hb_struMemvar  asMemvar;
  186.       struct hb_struPointer asPointer;
  187.       struct hb_struRefer   asRefer;
  188.       struct hb_struString  asString;
  189.       struct hb_struSymbol  asSymbol;
  190.    } item;
  191. }
  192. HB_ITEM, * PHB_ITEM, * HB_ITEM_PTR;
  193.  
  194. typedef struct _HB_BASEARRAY
  195. {
  196.    PHB_ITEM pItems;       /* pointer to the array items */
  197.    ULONG    ulLen;        /* number of items in the array */
  198.    USHORT   uiHolders;    /* number of holders of this array */
  199.    USHORT   uiClass;      /* offset to the classes base if it is an object */
  200.    BOOL     bSuperCast;   /* is it a super cast ? */
  201. } BASEARRAY, * PBASEARRAY, * BASEARRAY_PTR;
  202.  
  203. /* stack managed by the virtual machine */
  204. typedef struct
  205. {
  206.    PHB_ITEM pItems;       /* pointer to the stack items */
  207.    PHB_ITEM pPos;         /* pointer to the latest used item */
  208.    LONG     wItems;       /* total items that may be holded on the stack */
  209.    HB_ITEM  Return;       /* latest returned value */
  210.    PHB_ITEM pBase;        /* stack frame position for the current function call */
  211.    PHB_ITEM pEvalBase;    /* stack frame position for the evaluated codeblock */
  212.    int      iStatics;     /* statics base for the current function call */
  213.    char     szDate[ 9 ];  /* last returned date from _pards() yyyymmdd format */
  214. } STACK;
  215.  
  216. /* internal structure for codeblocks */
  217. typedef struct _HB_CODEBLOCK
  218. {
  219.    BYTE *   pCode;        /* codeblock pcode */
  220.    PHB_ITEM pLocals;      /* table with referenced local variables */
  221.    USHORT   uiLocals;     /* number of referenced local variables */
  222.    PHB_SYMB pSymbols;     /* codeblocks symbols */
  223.    ULONG    ulCounter;    /* numer of references to this codeblock */
  224. } HB_CODEBLOCK, * PHB_CODEBLOCK, * HB_CODEBLOCK_PTR;
  225.  
  226. typedef struct _HB_VALUE
  227. {
  228.    HB_ITEM   item;
  229.    ULONG     counter;
  230.    HB_HANDLE hPrevMemvar;
  231. } HB_VALUE, * PHB_VALUE, * HB_VALUE_PTR;
  232.  
  233. extern STACK stack;
  234. extern HB_SYMB symEval;
  235. extern HB_ITEM aStatics;
  236.  
  237. /* Extend API */
  238. extern char *   hb_parc( int iParam, ... );  /* retrieve a string parameter */
  239. extern ULONG    hb_parclen( int iParam, ... ); /* retrieve a string parameter length */
  240. extern ULONG    hb_parcsiz( int iParam, ... );
  241. extern char *   hb_pards( int iParam, ... ); /* retrieve a date as a string yyyymmdd */
  242. extern ULONG    hb_parinfa( int iParamNum, ULONG uiArrayIndex );
  243. extern int      hb_parinfo( int iParam ); /* Determine the param count or data type */
  244. extern int      hb_parl( int iParam, ... ); /* retrieve a logical parameter as an int */
  245. extern double   hb_parnd( int iParam, ... ); /* retrieve a numeric parameter as a double */
  246. extern int      hb_parni( int iParam, ... ); /* retrieve a numeric parameter as a integer */
  247. extern long     hb_parnl( int iParam, ... ); /* retrieve a numeric parameter as a long */
  248. extern PHB_ITEM hb_param( int iParam, int iMask ); /* retrieve a generic parameter */
  249. extern int      hb_pcount( void );          /* returns the number of suplied parameters */
  250.  
  251. extern void     hb_ret( void );             /* post a NIL return value */
  252. extern void     hb_retc( char * szText );   /* returns a string */
  253. extern void     hb_retclen( char * szText, ULONG ulLen ); /* returns a string with a specific length */
  254. extern void     hb_retds( char * szDate );  /* returns a date, must use yyyymmdd format */
  255. extern void     hb_retl( int iTrueFalse );  /* returns a logical integer */
  256. extern void     hb_retnd( double dNumber ); /* returns a double */
  257. extern void     hb_retni( int iNumber );    /* returns a integer number */
  258. extern void     hb_retnl( long lNumber );   /* returns a long number */
  259. extern void     hb_retnlen( double dNumber, int iWidth, int iDec ); /* returns a double, with specific width and decimals */
  260. extern void     hb_retndlen( double dNumber, int iWidth, int iDec ); /* returns a double, with specific width and decimals */
  261. extern void     hb_retnilen( int iNumber, int iWidth ); /* returns a integer number, with specific width */
  262. extern void     hb_retnllen( long lNumber, int iWidth ); /* returns a long number, with specific width */
  263. extern void     hb_reta( ULONG ulLen );  /* returns an array with a specific length */
  264.  
  265. extern void     hb_storc( char * szText, int iParam, ... ); /* stores a szString on a variable by reference */
  266. extern void     hb_storclen( char * szText, ULONG ulLength, int iParam, ... ); /* stores a fixed length string on a variable by reference */
  267. extern void     hb_stords( char * szDate, int iParam, ... );   /* szDate must have yyyymmdd format */
  268. extern void     hb_storl( int iLogical, int iParam, ... ); /* stores a logical integer on a variable by reference */
  269. extern void     hb_storni( int iValue, int iParam, ... ); /* stores an integer on a variable by reference */
  270. extern void     hb_stornl( long lValue, int iParam, ... ); /* stores a long on a variable by reference */
  271. extern void     hb_stornd( double dValue, int iParam, ... ); /* stores a double on a variable by reference */
  272.  
  273. extern void     hb_xinit( void );                         /* Initialize fixed memory subsystem */
  274. extern void     hb_xexit( void );                         /* Deinitialize fixed memory subsystem */
  275. extern void *   hb_xalloc( ULONG ulSize );                /* allocates memory, returns NULL on failure */
  276. extern void *   hb_xgrab( ULONG ulSize );                 /* allocates memory, exists on failure */
  277. extern void     hb_xfree( void * pMem );                  /* frees memory */
  278. extern void *   hb_xrealloc( void * pMem, ULONG ulSize ); /* reallocates memory */
  279. extern ULONG    hb_xsize( void * pMem );                  /* returns the size of an allocated memory block */
  280. extern void *   hb_xmemcpy( void * pDestArg, void * pSourceArg, ULONG ulLen ); /* copy more than memcpy() can */
  281. extern void *   hb_xmemset( void * pDestArg, int iFill, ULONG ulLen ); /* set more than memset() can */
  282.  
  283. /* array management */
  284. extern BOOL     hb_arrayError( PHB_ITEM pArray, ULONG ulIndex, BOOL bAssign ); /* Checks if the passed parameters are valid, launches runtim error if needed */
  285. extern BOOL     hb_arrayNew( PHB_ITEM pItem, ULONG ulLen ); /* creates a new array */
  286. extern ULONG    hb_arrayLen( PHB_ITEM pArray ); /* retrives the array len */
  287. extern BOOL     hb_arrayIsObject( PHB_ITEM pArray ); /* retrives if the array is an object */
  288. extern BOOL     hb_arrayAdd( PHB_ITEM pArray, PHB_ITEM pItemValue );
  289. extern BOOL     hb_arrayIns( PHB_ITEM pArray, ULONG ulIndex );
  290. extern BOOL     hb_arrayDel( PHB_ITEM pArray, ULONG ulIndex );
  291. extern BOOL     hb_arraySize( PHB_ITEM pArray, ULONG ulLen ); /* sets the array total length */
  292. extern BOOL     hb_arrayLast( PHB_ITEM pArray, PHB_ITEM pResult );
  293. extern BOOL     hb_arrayRelease( PHB_ITEM pArray ); /* releases an array - don't call it - use ItemRelease() !!! */
  294. extern BOOL     hb_arraySet( PHB_ITEM pArray, ULONG ulIndex, PHB_ITEM pItem ); /* sets an array element */
  295. extern BOOL     hb_arrayGet( PHB_ITEM pArray, ULONG ulIndex, PHB_ITEM pItem ); /* retrieves an item */
  296. extern PHB_ITEM hb_arrayGetItemPtr( PHB_ITEM pArray, ULONG ulIndex ); /* returns pointer to specified element of the array */
  297. extern ULONG    hb_arrayCopyC( PHB_ITEM pArray, ULONG ulIndex, char * szBuffer, ULONG ulLen );
  298. extern char *   hb_arrayGetC( PHB_ITEM pArray, ULONG ulIndex ); /* retrieves the string contained on an array element */
  299. extern char *   hb_arrayGetCPtr( PHB_ITEM pArray, ULONG ulIndex ); /* retrieves the string pointer on an array element */
  300. extern ULONG    hb_arrayGetCLen( PHB_ITEM pArray, ULONG ulIndex ); /* retrieves the string length contained on an array element */
  301. extern BOOL     hb_arrayGetL( PHB_ITEM pArray, ULONG ulIndex ); /* retrieves the logical value contained on an array element */
  302. extern int      hb_arrayGetNI( PHB_ITEM pArray, ULONG ulIndex ); /* retrieves the int value contained on an array element */
  303. extern long     hb_arrayGetNL( PHB_ITEM pArray, ULONG ulIndex ); /* retrieves the long numeric value contained on an array element */
  304. extern double   hb_arrayGetND( PHB_ITEM pArray, ULONG ulIndex ); /* retrieves the double value contained on an array element */
  305. extern char *   hb_arrayGetDS( PHB_ITEM pArray, ULONG ulIndex, char * szDate ); /* retrieves the date value contained on an array element */
  306. extern USHORT   hb_arrayGetType( PHB_ITEM pArray, ULONG ulIndex );
  307. extern BOOL     hb_arrayFill( PHB_ITEM pArray, PHB_ITEM pValue, ULONG * pulStart, ULONG * pulCount );
  308. extern ULONG    hb_arrayScan( PHB_ITEM pArray, PHB_ITEM pValue, ULONG * pulStart, ULONG * pulCount );
  309. extern BOOL     hb_arrayEval( PHB_ITEM pArray, PHB_ITEM bBlock, ULONG * pulStart, ULONG * pulCount );
  310. extern BOOL     hb_arrayCopy( PHB_ITEM pSrcArray, PHB_ITEM pDstArray, ULONG * pulStart, ULONG * pulCount, ULONG * pulTarget );
  311. extern PHB_ITEM hb_arrayClone( PHB_ITEM pArray );
  312.  
  313. /* string management */
  314.  
  315. #define HB_STRGREATER_EQUAL     0
  316. #define HB_STRGREATER_LEFT      1
  317. #define HB_STRGREATER_RIGHT     2
  318.  
  319. extern int      hb_stricmp( const char * s1, const char * s2 );
  320. extern int      hb_strnicmp( const char * s1, const char * s2, ULONG ulLen );
  321. extern int      hb_strgreater( char * szText1, char * szText2 );
  322. extern void     hb_strupr( char * szText );
  323. extern BOOL     hb_strMatchRegExp( char * szString, char * szMask );
  324. extern BOOL     hb_strEmpty( char * szText, ULONG ulLen );
  325. extern void     hb_strDescend( char * szStringTo, char * szStringFrom, ULONG ulLen );
  326. extern ULONG    hb_strAt( char * szSub, ULONG ulSubLen, char * szText, ULONG ulLen );
  327. extern char *   hb_strUpper( char * szText, ULONG ulLen );
  328. extern char *   hb_strLower( char * szText, ULONG ulLen );
  329. extern char *   hb_strncpyUpper( char * pDest, char * pSource, ULONG ulLen );
  330.  
  331. extern double   hb_numRound( double dResult, int iDec );
  332.  
  333. /* class management */
  334. extern void     hb_clsReleaseAll( void );    /* releases all defined classes */
  335.  
  336. /* object management */
  337. extern char *   hb_objGetClsName( PHB_ITEM pObject ); /* retrieves an object class name */
  338. extern PHB_FUNC hb_objGetMethod( PHB_ITEM pObject, PHB_SYMB pSymMsg ); /* returns the method pointer of a object class */
  339. extern ULONG    hb_objHasMsg( PHB_ITEM pObject, char *szString );
  340.  
  341. /* dynamic symbol table management */
  342. extern PHB_DYNS hb_dynsymGet( char * szName );    /* finds and creates a dynamic symbol if not found */
  343. extern PHB_DYNS hb_dynsymNew( PHB_SYMB pSymbol ); /* creates a new dynamic symbol based on a local one */
  344. extern PHB_DYNS hb_dynsymFind( char * szName );   /* finds a dynamic symbol */
  345. extern PHB_DYNS hb_dynsymFindName( char * szName );   /* converts to uppercase and finds a dynamic symbol */
  346. extern void     hb_dynsymLog( void );             /* displays all dynamic symbols */
  347. extern void     hb_dynsymRelease( void );         /* releases the memory of the dynamic symbol table */
  348. extern void     hb_dynsymEval( PHB_DYNS_FUNC, void * );   /* enumerates all dynamic symbols */
  349.  
  350. /* Command line and environment argument management */
  351. extern void     hb_cmdargInit( int argc, char * argv[] );
  352. extern int      hb_cmdargARGC( void );
  353. extern char **  hb_cmdargARGV( void );
  354. extern BOOL     hb_cmdargIsInternal( const char * szArg );
  355. extern BOOL     hb_cmdargCheck( const char * pszName ); /* Check if a given internal switch (like //INFO) was set */
  356. extern char *   hb_cmdargString( const char * pszName ); /* Returns the string value of an internal switch (like //TEMPPATH:"C:\") */
  357. extern int      hb_cmdargNum( const char * pszName ); /* Returns the numeric value of an internal switch (like //F:90) */
  358.  
  359. /* Symbol management */
  360. extern PHB_SYMB hb_symbolNew( char * szName );
  361.  
  362. /* Codeblock management */
  363. extern HB_CODEBLOCK_PTR hb_codeblockNew( BYTE *, USHORT, USHORT *, PHB_SYMB );
  364. extern void     hb_codeblockDelete( PHB_ITEM );
  365. extern PHB_ITEM hb_codeblockGetVar( PHB_ITEM, LONG );
  366. extern PHB_ITEM hb_codeblockGetRef( PHB_ITEM, PHB_ITEM );
  367. extern void     hb_codeblockEvaluate( PHB_ITEM );
  368. extern void     hb_codeblockCopy( PHB_ITEM, PHB_ITEM );
  369.  
  370. /* memvars subsystem */
  371. extern HB_HANDLE hb_memvarValueNew( PHB_ITEM, BOOL );
  372. extern HB_VALUE_PTR * hb_memvarValueBaseAddress( void );
  373. extern void     hb_memvarsInit( void );
  374. extern void     hb_memvarsRelease( void );
  375. extern void     hb_memvarValueIncRef( HB_HANDLE );
  376. extern void     hb_memvarValueDecRef( HB_HANDLE );
  377. extern void     hb_memvarSetValue( PHB_SYMB, HB_ITEM_PTR );
  378. extern void     hb_memvarGetValue( HB_ITEM_PTR, PHB_SYMB );
  379. extern void     hb_memvarGetRefer( HB_ITEM_PTR, PHB_SYMB );
  380. extern ULONG    hb_memvarGetPrivatesBase( void );
  381. extern void     hb_memvarSetPrivatesBase( ULONG );
  382.  
  383. /* console I/O subsystem */
  384. extern void     hb_consoleInitialize( void );
  385. extern void     hb_consoleRelease( void );
  386. extern char *   hb_consoleGetNewLine( void );
  387. extern void     hb_outstd( char * pStr, ULONG ulLen );
  388. extern void     hb_outerr( char * pStr, ULONG ulLen );
  389.  
  390. extern void     hb_tone( double dFrequency, double dDuration );
  391. extern char *   hb_setColor( char * );
  392.  
  393. /* misc */
  394. extern char *   hb_version( USHORT uiMode );
  395.  
  396. /* Please leave these at the bottom of this file */
  397.  
  398. #ifdef HARBOUR_STRICT_CLIPPER_COMPATIBILITY
  399.    /* Clipper includes these from extend.h */
  400.    #include "extend.api"
  401.    #include "fm.api"
  402. #endif
  403.  
  404. #endif /* HB_EXTEND_H_ */
  405.  
  406.