PageRenderTime 73ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

/tags/build38/harbour/source/pp/ppcore.c

#
C | 2292 lines | 1817 code | 280 blank | 195 comment | 623 complexity | 51abb1a638d82f7f85404e6dabdd1a39 MD5 | raw file
Possible License(s): AGPL-1.0, BSD-3-Clause, CC-BY-SA-3.0, LGPL-3.0, GPL-2.0, LGPL-2.0, LGPL-2.1
  1. /*
  2. * $Id: ppcore.c 4754 2001-12-14 09:32:52Z vszakats $
  3. */
  4. /*
  5. * Harbour Project source code:
  6. * Preprocessor core module
  7. *
  8. * Copyright 1999 Alexander S.Kresin <alex@belacy.belgorod.su>
  9. * www - http://www.harbour-project.org
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2, or (at your option)
  14. * any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this software; see the file COPYING. If not, write to
  23. * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  24. * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
  25. *
  26. * As a special exception, the Harbour Project gives permission for
  27. * additional uses of the text contained in its release of Harbour.
  28. *
  29. * The exception is that, if you link the Harbour libraries with other
  30. * files to produce an executable, this does not by itself cause the
  31. * resulting executable to be covered by the GNU General Public License.
  32. * Your use of that executable is in no way restricted on account of
  33. * linking the Harbour library code into it.
  34. *
  35. * This exception does not however invalidate any other reasons why
  36. * the executable file might be covered by the GNU General Public License.
  37. *
  38. * This exception applies only to the code released by the Harbour
  39. * Project under the name Harbour. If you copy code from other
  40. * Harbour Project or Free Software Foundation releases into a copy of
  41. * Harbour, as the General Public License permits, the exception does
  42. * not apply to the code that you add in this way. To avoid misleading
  43. * anyone as to the status of such modified files, you must delete
  44. * this exception notice from them.
  45. *
  46. * If you write modifications of your own for Harbour, it is your choice
  47. * whether to permit this exception to apply to your modifications.
  48. * If you do not wish that, delete this exception notice.
  49. *
  50. */
  51. /*
  52. * The following parts are Copyright of the individual authors.
  53. * www - http://www.harbour-project.org
  54. *
  55. * Copyright 1999-2001 Viktor Szakats <viktor.szakats@syenar.hu>
  56. * __DATE__, __TIME__, __HB_MAIN__ support
  57. *
  58. * Copyright 2000 Ron Pinkas <Ron@Profit-Master.com>
  59. *
  60. * hb_pp_SetRules() and related code for supportting
  61. * replaceable rules with -w switch
  62. *
  63. * See doc/license.txt for licensing terms.
  64. *
  65. */
  66. /*
  67. * Avoid tracing in preprocessor/compiler.
  68. */
  69. #if ! defined(HB_TRACE_UTILS)
  70. #if defined(HB_TRACE_LEVEL)
  71. #undef HB_TRACE_LEVEL
  72. #endif
  73. #endif
  74. #include <time.h>
  75. #include <errno.h>
  76. #include "hbpp.h"
  77. #include "hbcomp.h"
  78. #if defined( OS_UNIX_COMPATIBLE )
  79. #include <sys/timeb.h>
  80. #else
  81. #include <sys\timeb.h>
  82. #endif
  83. int hb_pp_ParseDefine( char * ); /* Process #define directive */
  84. static COMMANDS * AddCommand( char * ); /* Add new #command to an array */
  85. static COMMANDS * AddTranslate( char * ); /* Add new #translate to an array */
  86. static DEFINES * DefSearch( char *, BOOL * );
  87. static COMMANDS * ComSearch( char *, COMMANDS * );
  88. static COMMANDS * TraSearch( char *, COMMANDS * );
  89. static int ParseUndef( char * ); /* Process #undef directive */
  90. static int ParseIfdef( char *, int ); /* Process #ifdef directive */
  91. static void ParseCommand( char *, BOOL, BOOL ); /* Process #command or #translate directive */
  92. static void ConvertPatterns( char *, int, char *, int ); /* Converting result pattern in #command and #translate */
  93. static int WorkDefine( char **, char *, DEFINES * ); /* Replace fragment of code with a #defined result text */
  94. static int WorkPseudoF( char **, char *, DEFINES * ); /* Replace pseudofunction with a #defined result text */
  95. static int WorkCommand( char *, char *, COMMANDS * );
  96. static int WorkTranslate( char *, char *, COMMANDS *, int * );
  97. static int CommandStuff( char *, char *, char *, int *, BOOL, BOOL );
  98. static int RemoveSlash( char * );
  99. static int WorkMarkers( char **, char **, char *, int *, BOOL );
  100. static int getExpReal( char *, char **, BOOL, int, BOOL );
  101. static BOOL isExpres( char *, BOOL );
  102. static BOOL TestOptional( char *, char * );
  103. static BOOL CheckOptional( char *, char *, char *, int *, BOOL, BOOL );
  104. static void SkipOptional( char ** );
  105. static void SearnRep( char *, char *, int, char *, int * );
  106. static int ReplacePattern( char, char *, int, char *, int );
  107. static void pp_rQuotes( char *, char * );
  108. static int md_strAt( char *, int, char *, BOOL, BOOL, BOOL );
  109. static char * PrevSquare( char * , char *, int * );
  110. static int IsInStr( char, char * );
  111. static int stroncpy( char *, char *, int );
  112. static int strincpy( char *, char * );
  113. static BOOL truncmp( char **, char **, BOOL );
  114. static BOOL strincmp( char *, char **, BOOL );
  115. static int strotrim( char *, BOOL ); /* Ron Pinkas 2001-02-14 added 2nd parameter */
  116. static int NextWord( char **, char *, BOOL );
  117. static int NextName( char **, char * );
  118. static int NextParm( char **, char * );
  119. static BOOL OpenInclude( char *, HB_PATHNAMES *, PHB_FNAME, BOOL bStandardOnly, char * );
  120. static BOOL IsIdentifier( char *szProspect );
  121. #define ISNAME( c ) ( isalnum( ( int ) c ) || ( c ) == '_' || ( c ) > 0x7E )
  122. #define MAX_NAME 255
  123. #define MAX_EXP 2048
  124. #define PATTERN_SIZE 2048
  125. #define STATE_INIT 0
  126. #define STATE_NORMAL 1
  127. #define STATE_COMMENT 2
  128. #define STATE_QUOTE1 3
  129. #define STATE_QUOTE2 4
  130. #define STATE_QUOTE3 5
  131. #define STATE_ID_END 6
  132. #define STATE_ID 7
  133. #define STATE_EXPRES 8
  134. #define STATE_EXPRES_ID 9
  135. #define STATE_BRACKET 10
  136. #define IT_EXPR 1
  137. #define IT_ID 2
  138. #define IT_COMMA 3
  139. #define IT_ID_OR_EXPR 4
  140. #define HB_PP_MAX_INCLUDES FOPEN_MAX - 5 - 1
  141. /* Ron Pinkas added 2000-01-24 */
  142. #define IS_2CHAR_OPERATOR( p ) ( p[0] && p[1] && ( strncmp( p, ":=", 2 ) == 0 || \
  143. strncmp( p, "+=", 2 ) == 0 || \
  144. strncmp( p, "-=", 2 ) == 0 || \
  145. strncmp( p, "*=", 2 ) == 0 || \
  146. strncmp( p, "/=", 2 ) == 0 || \
  147. strncmp( p, "^=", 2 ) == 0 || \
  148. strncmp( p, "==", 2 ) == 0 || \
  149. strncmp( p, "<>", 2 ) == 0 || \
  150. strncmp( p, "<=", 2 ) == 0 || \
  151. strncmp( p, ">=", 2 ) == 0 || \
  152. strncmp( p, "++", 2 ) == 0 || \
  153. strncmp( p, "--", 2 ) == 0 || \
  154. strncmp( p, "->", 2 ) == 0 ) )
  155. /* END, Ron Pinkas added 2000-01-24 */
  156. static int s_kolAddDefs = 0;
  157. static int s_kolAddComs = 0;
  158. static int s_kolAddTras = 0;
  159. static int s_ParseState;
  160. static int s_maxCondCompile;
  161. static int s_aIsRepeate[ 5 ];
  162. static int s_Repeate;
  163. static BOOL s_bReplacePat = TRUE;
  164. static int s_numBrackets;
  165. static char s_groupchar;
  166. static char s_prevchar;
  167. int * hb_pp_aCondCompile = NULL;
  168. int hb_pp_nCondCompile = 0;
  169. char * hb_pp_STD_CH = NULL;
  170. /* Ron Pinkas added 2000-11-21 */
  171. static BOOL s_bArray = FALSE;
  172. #if defined(__WATCOMC__)
  173. extern BOOL hb_pp_bInline;
  174. extern int hb_pp_LastOutLine;
  175. #endif
  176. /* Table with parse errors */
  177. char * hb_pp_szErrors[] =
  178. {
  179. "Can\'t open #include file: \'%s\'; %s",
  180. "#else does not match #ifdef",
  181. "#endif does not match #ifdef",
  182. "Bad filename in #include",
  183. "#define without parameters",
  184. "Missing => in #translate/#command \'%s\' [%s]'",
  185. "Error in pattern definition",
  186. "Cycled #define",
  187. "Invalid name follows #: \'%s\'",
  188. "\'%s\'",
  189. "Memory allocation error",
  190. "Memory reallocation error",
  191. "Freeing a NULL memory pointer",
  192. "Value out of range in #pragma directive",
  193. "Can\'t open command definitions file: \'%s\'",
  194. "Invalid command definitions file name: \'%s\'",
  195. "Too many nested #includes, can\'t open: \'%s\'",
  196. "Input buffer overflow"
  197. };
  198. /* Table with warnings */
  199. char * hb_pp_szWarnings[] =
  200. {
  201. "1Redefinition or duplicate definition of #define %s",
  202. "1No directives in command definitions file"
  203. };
  204. void hb_pp_SetRules( HB_INCLUDE_FUNC_PTR hb_compInclude, BOOL hb_comp_bQuiet )
  205. {
  206. HB_TRACE(HB_TR_DEBUG, ("hb_pp_SetRules()"));
  207. if( hb_pp_STD_CH )
  208. {
  209. if( *hb_pp_STD_CH > ' ' )
  210. {
  211. hb_comp_pFileName = hb_fsFNameSplit( hb_pp_STD_CH );
  212. if( hb_comp_pFileName->szName )
  213. {
  214. char szFileName[ _POSIX_PATH_MAX ];
  215. if( ! hb_comp_pFileName->szExtension )
  216. hb_comp_pFileName->szExtension = ".ch";
  217. hb_fsFNameMerge( szFileName, hb_comp_pFileName );
  218. if( (* hb_compInclude)( szFileName, hb_comp_pIncludePath ) )
  219. {
  220. /*
  221. printf( "Loading Standard Rules from: \'%s\'\n", szFileName );
  222. */
  223. hb_pp_Init();
  224. hb_pp_ReadRules();
  225. /*
  226. {
  227. COMMANDS * stcmd;
  228. DEFINES * stdef;
  229. stcmd = hb_pp_topCommand;
  230. while ( stcmd )
  231. {
  232. printf( "Command: %s Pattern: %s\n", stcmd->name, stcmd->mpatt );
  233. stcmd = stcmd->last;
  234. }
  235. stcmd = hb_pp_topTranslate;
  236. while ( stcmd )
  237. {
  238. printf( "Translate: %s \nPattern: %s\n", stcmd->name, stcmd->mpatt );
  239. stcmd = stcmd->last;
  240. }
  241. stdef = hb_pp_topDefine;
  242. while ( stdef && s_kolAddDefs > 3 )
  243. {
  244. printf( "Define: %s Value: %s\n", stdef->name, stdef->value );
  245. stdef = stdef->last;
  246. s_kolAddDefs--;
  247. }
  248. }
  249. */
  250. if ( s_kolAddComs || s_kolAddTras || s_kolAddDefs > 3 )
  251. {
  252. if( ! hb_comp_bQuiet )
  253. printf( "Loaded: %i Commands, %i Translates, %i Defines from: %s\n", s_kolAddComs, s_kolAddTras, s_kolAddDefs - 3, szFileName );
  254. }
  255. else
  256. {
  257. hb_compGenWarning( hb_pp_szWarnings, 'I', HB_PP_WARN_NO_DIRECTIVES, NULL /*szFileName*/, NULL );
  258. }
  259. fclose( hb_comp_files.pLast->handle );
  260. hb_xfree( hb_comp_files.pLast->pBuffer );
  261. hb_xfree( hb_comp_files.pLast );
  262. hb_comp_files.pLast = NULL;
  263. hb_comp_files.iFiles = 0;
  264. hb_xfree( ( void * ) hb_comp_pFileName );
  265. hb_comp_pFileName = NULL;
  266. s_kolAddComs = 0;
  267. s_kolAddTras = 0;
  268. s_kolAddDefs = 0;
  269. }
  270. else
  271. {
  272. hb_compGenError( hb_pp_szErrors, 'F', HB_PP_ERR_CANNOT_OPEN_RULES, szFileName, NULL );
  273. }
  274. }
  275. else
  276. {
  277. hb_compGenError( hb_pp_szErrors, 'F', HB_PP_ERR_BAD_RULES_FILE_NAME, hb_pp_STD_CH, NULL );
  278. }
  279. }
  280. else
  281. {
  282. if( ! hb_comp_bQuiet )
  283. printf( "Standard command definitions excluded.\n" );
  284. hb_pp_Init();
  285. }
  286. }
  287. else
  288. {
  289. hb_pp_Table();
  290. hb_pp_Init();
  291. }
  292. }
  293. void hb_pp_Free( void )
  294. {
  295. DEFINES * stdef;
  296. COMMANDS * stcmd;
  297. HB_TRACE(HB_TR_DEBUG, ("hb_pp_Free()"));
  298. while( s_kolAddDefs )
  299. {
  300. stdef = hb_pp_topDefine;
  301. if( stdef->pars ) hb_xfree( stdef->pars );
  302. if( stdef->value ) hb_xfree( stdef->value );
  303. if( stdef->name ) hb_xfree( stdef->name );
  304. hb_pp_topDefine = stdef->last;
  305. hb_xfree( stdef );
  306. s_kolAddDefs--;
  307. }
  308. while( s_kolAddComs )
  309. {
  310. stcmd = hb_pp_topCommand;
  311. if( stcmd->mpatt ) hb_xfree( stcmd->mpatt );
  312. if( stcmd->value ) hb_xfree( stcmd->value );
  313. hb_xfree( stcmd->name );
  314. hb_pp_topCommand = stcmd->last;
  315. hb_xfree( stcmd );
  316. s_kolAddComs--;
  317. }
  318. while( s_kolAddTras )
  319. {
  320. stcmd = hb_pp_topTranslate;
  321. if( stcmd->mpatt ) hb_xfree( stcmd->mpatt );
  322. if( stcmd->value ) hb_xfree( stcmd->value );
  323. hb_xfree( stcmd->name );
  324. hb_pp_topTranslate = stcmd->last;
  325. hb_xfree( stcmd );
  326. s_kolAddTras--;
  327. }
  328. }
  329. void hb_pp_Init( void )
  330. {
  331. HB_TRACE(HB_TR_DEBUG, ("hb_pp_Init()"));
  332. hb_pp_Free();
  333. s_ParseState = 0;
  334. s_maxCondCompile = 5;
  335. s_bReplacePat = TRUE;
  336. s_prevchar = 'A';
  337. if( !hb_pp_aCondCompile )
  338. hb_pp_aCondCompile = ( int * ) hb_xgrab( sizeof( int ) * 5 );
  339. hb_pp_nCondCompile = 0;
  340. {
  341. char szResult[ 6 ];
  342. USHORT usHarbour = ( 256 * HB_VER_MAJOR ) + HB_VER_MINOR;
  343. /*
  344. This updates __HARBOUR__ on every change of HB_VER_MAJOR / HB_VER_MINOR
  345. HIBYTE is the HB_VER_MAJOR value and the LOBYTE is the HB_VER_MINOR value.
  346. The check below is to ensure that __HARBOUR__ gets the
  347. value of 1 by default
  348. */
  349. sprintf( szResult, "%05d", ( usHarbour ? usHarbour : 1 ) );
  350. hb_pp_AddDefine( "__HARBOUR__", szResult );
  351. }
  352. {
  353. char szResult[ 11 ];
  354. time_t t;
  355. struct tm * oTime;
  356. time( &t );
  357. oTime = localtime( &t );
  358. sprintf( szResult, "\"%04d%02d%02d\"", oTime->tm_year + 1900, oTime->tm_mon + 1, oTime->tm_mday );
  359. hb_pp_AddDefine( "__DATE__", szResult );
  360. sprintf( szResult, "\"%02d:%02d:%02d\"", oTime->tm_hour, oTime->tm_min, oTime->tm_sec );
  361. hb_pp_AddDefine( "__TIME__", szResult );
  362. }
  363. #ifdef HARBOUR_START_PROCEDURE
  364. hb_pp_AddDefine( "__HB_MAIN__", HARBOUR_START_PROCEDURE );
  365. #endif
  366. }
  367. /* Table with parse warnings */
  368. /* NOTE: The first character stores the warning's level that triggers this
  369. * warning. The warning's level is set by -w<n> command line option.
  370. */
  371. int hb_pp_ParseDirective( char * sLine )
  372. {
  373. char sDirective[ MAX_NAME ];
  374. char szInclude[ _POSIX_PATH_MAX ];
  375. int i;
  376. HB_TRACE(HB_TR_DEBUG, ("hb_pp_ParseDirective(%s)", sLine));
  377. i = NextName( &sLine, sDirective );
  378. hb_strupr( sDirective );
  379. HB_SKIPTABSPACES(sLine);
  380. if( i == 4 && memcmp( sDirective, "ELSE", 4 ) == 0 )
  381. { /* --- #else --- */
  382. if( hb_pp_nCondCompile == 0 )
  383. hb_compGenError( hb_pp_szErrors, 'F', HB_PP_ERR_DIRECTIVE_ELSE, NULL, NULL );
  384. else if( hb_pp_nCondCompile == 1 || hb_pp_aCondCompile[hb_pp_nCondCompile-2] )
  385. hb_pp_aCondCompile[hb_pp_nCondCompile-1] = 1 - hb_pp_aCondCompile[hb_pp_nCondCompile-1];
  386. }
  387. else if( i >= 4 && i <= 5 && memcmp( sDirective, "ENDIF", i ) == 0 )
  388. { /* --- #endif --- */
  389. if( hb_pp_nCondCompile == 0 )
  390. hb_compGenError( hb_pp_szErrors, 'F', HB_PP_ERR_DIRECTIVE_ENDIF, NULL, NULL );
  391. else hb_pp_nCondCompile--;
  392. }
  393. else if( i >= 4 && i <= 5 && memcmp( sDirective, "IFDEF", i ) == 0 )
  394. ParseIfdef( sLine, TRUE ); /* --- #ifdef --- */
  395. else if( i >= 4 && i <= 6 && memcmp( sDirective, "IFNDEF", i ) == 0 )
  396. ParseIfdef( sLine, FALSE ); /* --- #ifndef --- */
  397. else if( hb_pp_nCondCompile==0 || hb_pp_aCondCompile[hb_pp_nCondCompile-1])
  398. {
  399. if( i >= 4 && i <= 7 && memcmp( sDirective, "INCLUDE", i ) == 0 )
  400. { /* --- #include --- */
  401. char cDelimChar;
  402. if( *sLine != '\"' && *sLine != '\'' && *sLine != '<' )
  403. hb_compGenError( hb_pp_szErrors, 'F', HB_PP_ERR_WRONG_NAME, NULL, NULL );
  404. cDelimChar = *sLine;
  405. if( cDelimChar == '<' )
  406. cDelimChar = '>';
  407. else if( cDelimChar == '`' )
  408. cDelimChar = '\'';
  409. sLine++; i = 0;
  410. while( *(sLine+i) != '\0' && *(sLine+i) != cDelimChar ) i++;
  411. if( *(sLine+i) != cDelimChar )
  412. hb_compGenError( hb_pp_szErrors, 'F', HB_PP_ERR_WRONG_NAME, NULL, NULL );
  413. *(sLine+i) = '\0';
  414. if( !OpenInclude( sLine, hb_comp_pIncludePath, hb_comp_pFileName, ( cDelimChar == '>' ), szInclude ) )
  415. {
  416. if( errno == 0 || errno == EMFILE )
  417. hb_compGenError( hb_pp_szErrors, 'F', HB_PP_ERR_TOO_MANY_INCLUDES, sLine, NULL );
  418. else
  419. {
  420. #if defined(__CYGWIN__) || defined(__IBMCPP__)
  421. hb_compGenError( hb_pp_szErrors, 'F', HB_PP_ERR_CANNOT_OPEN, sLine, "" );
  422. #else
  423. hb_compGenError( hb_pp_szErrors, 'F', HB_PP_ERR_CANNOT_OPEN, sLine, sys_errlist[ errno ] );
  424. #endif
  425. }
  426. }
  427. }
  428. else if( i >= 4 && i <= 6 && memcmp( sDirective, "DEFINE", i ) == 0 )
  429. hb_pp_ParseDefine( sLine ); /* --- #define --- */
  430. else if( i >= 4 && i <= 5 && memcmp( sDirective, "UNDEF", i ) == 0 )
  431. ParseUndef( sLine ); /* --- #undef --- */
  432. else if( (i >= 4 && i <= 7 && memcmp( sDirective, "COMMAND", i ) == 0) ||
  433. (i >= 4 && i <= 8 && memcmp( sDirective, "XCOMMAND", i ) == 0) )
  434. /* --- #command --- */
  435. ParseCommand( sLine, (i==7)? FALSE:TRUE, TRUE );
  436. else if( (i >= 4 && i <= 9 && memcmp( sDirective, "TRANSLATE", i ) == 0) ||
  437. (i >= 4 && i <= 10 && memcmp( sDirective, "XTRANSLATE", i ) == 0) )
  438. /* --- #translate --- */
  439. ParseCommand( sLine, (i==9)? FALSE:TRUE, FALSE );
  440. else if( i >= 4 && i <= 6 && memcmp( sDirective, "STDOUT", i ) == 0 )
  441. printf( "%s\n", sLine ); /* --- #stdout --- */
  442. else if( i >= 4 && i <= 5 && memcmp( sDirective, "ERROR", i ) == 0 )
  443. /* --- #error --- */
  444. hb_compGenError( hb_pp_szErrors, 'E', HB_PP_ERR_EXPLICIT, sLine, NULL );
  445. else if( i == 4 && memcmp( sDirective, "LINE", 4 ) == 0 )
  446. return -1;
  447. else if( i == 6 && memcmp( sDirective, "PRAGMA", 6 ) == 0 )
  448. hb_pp_ParsePragma( sLine ); /* --- #pragma --- */
  449. else
  450. hb_compGenError( hb_pp_szErrors, 'F', HB_PP_ERR_WRONG_DIRECTIVE, sDirective, NULL );
  451. }
  452. return 0;
  453. }
  454. int hb_pp_ParseDefine( char * sLine )
  455. {
  456. char defname[ MAX_NAME ], pars[ MAX_NAME ];
  457. int i, npars = -1;
  458. DEFINES * lastdef;
  459. HB_TRACE(HB_TR_DEBUG, ("hb_pp_ParseDefine(%s)", sLine));
  460. HB_SKIPTABSPACES( sLine );
  461. if( ISNAME( *sLine ) )
  462. {
  463. NextName( &sLine, defname );
  464. if( *sLine == '(' ) /* If pseudofunction was found */
  465. {
  466. sLine++; i = 0;
  467. npars = 0;
  468. while( *sLine != '\0' && *sLine != ')')
  469. {
  470. if( *sLine == ',' ) npars++;
  471. if( *sLine != ' ' && *sLine != '\t' ) *(pars+i++) = *sLine;
  472. sLine++;
  473. }
  474. if( i > 0 ) npars++;
  475. *(pars+i) = '\0';
  476. sLine++;
  477. }
  478. HB_SKIPTABSPACES(sLine);
  479. lastdef = hb_pp_AddDefine( defname, ( *sLine == '\0' ) ? NULL : sLine );
  480. lastdef->npars = npars;
  481. lastdef->pars = ( npars <= 0 ) ? NULL : hb_strdup( pars );
  482. }
  483. else
  484. hb_compGenError( hb_pp_szErrors, 'F', HB_PP_ERR_DEFINE_ABSENT, NULL, NULL );
  485. return 0;
  486. }
  487. DEFINES * hb_pp_AddDefine( char * defname, char * value )
  488. {
  489. BOOL isNew;
  490. DEFINES * stdef;
  491. HB_TRACE(HB_TR_DEBUG, ("hb_pp_AddDefine(%s, %s)", defname, value));
  492. stdef = DefSearch( defname, &isNew );
  493. if( stdef != NULL )
  494. {
  495. hb_compGenWarning( hb_pp_szWarnings, 'I', HB_PP_WARN_DEFINE_REDEF, defname, NULL );
  496. if( isNew )
  497. {
  498. if( stdef->pars ) hb_xfree( stdef->pars );
  499. if( stdef->value ) hb_xfree( stdef->value );
  500. }
  501. }
  502. else
  503. {
  504. stdef = ( DEFINES * ) hb_xgrab( sizeof( DEFINES ) );
  505. stdef->last = hb_pp_topDefine;
  506. hb_pp_topDefine = stdef;
  507. stdef->name = hb_strdup( defname );
  508. stdef->npars = -1;
  509. s_kolAddDefs++;
  510. }
  511. stdef->value = ( value == NULL ) ? NULL : hb_strdup( value );
  512. stdef->pars = NULL;
  513. return stdef;
  514. }
  515. static int ParseUndef( char * sLine )
  516. {
  517. char defname[ MAX_NAME ];
  518. DEFINES * stdef;
  519. BOOL isNew;
  520. HB_TRACE(HB_TR_DEBUG, ("ParseUndef(%s)", sLine));
  521. NextWord( &sLine, defname, FALSE );
  522. if( ( stdef = DefSearch(defname, &isNew ) ) != NULL )
  523. {
  524. if( isNew )
  525. {
  526. if( stdef->pars ) hb_xfree( stdef->pars );
  527. if( stdef->value ) hb_xfree( stdef->value );
  528. hb_xfree( stdef->name );
  529. }
  530. stdef->pars = NULL;
  531. stdef->value = NULL;
  532. stdef->name = NULL;
  533. }
  534. return 0;
  535. }
  536. static int ParseIfdef( char * sLine, int usl )
  537. {
  538. char defname[ MAX_NAME ];
  539. DEFINES * stdef;
  540. HB_TRACE(HB_TR_DEBUG, ("ParseIfdef(%s, %d)", sLine, usl));
  541. if( hb_pp_nCondCompile==0 || hb_pp_aCondCompile[hb_pp_nCondCompile-1])
  542. {
  543. NextWord( &sLine, defname, FALSE );
  544. if( *defname == '\0' )
  545. hb_compGenError( hb_pp_szErrors, 'F', HB_PP_ERR_DEFINE_ABSENT, NULL, NULL );
  546. }
  547. if( hb_pp_nCondCompile == s_maxCondCompile )
  548. {
  549. s_maxCondCompile += 5;
  550. hb_pp_aCondCompile = (int*)hb_xrealloc( hb_pp_aCondCompile, sizeof( int ) * s_maxCondCompile );
  551. }
  552. if( hb_pp_nCondCompile==0 || hb_pp_aCondCompile[hb_pp_nCondCompile-1])
  553. {
  554. if( ( (stdef = DefSearch(defname,NULL)) != NULL && usl )
  555. || ( stdef == NULL && !usl ) ) hb_pp_aCondCompile[hb_pp_nCondCompile] = 1;
  556. else hb_pp_aCondCompile[hb_pp_nCondCompile] = 0;
  557. }
  558. else
  559. hb_pp_aCondCompile[ hb_pp_nCondCompile ] = 0;
  560. hb_pp_nCondCompile++;
  561. return 0;
  562. }
  563. static DEFINES * DefSearch( char * defname, BOOL * isNew )
  564. {
  565. int kol = 0,j;
  566. DEFINES * stdef = hb_pp_topDefine;
  567. HB_TRACE(HB_TR_DEBUG, ("DefSearch(%s)", defname));
  568. while( stdef != NULL )
  569. {
  570. kol++;
  571. if( stdef->name != NULL )
  572. {
  573. for( j=0; *(stdef->name+j) == *(defname+j) &&
  574. *(stdef->name+j) != '\0'; j++ );
  575. if( *(stdef->name+j) == *(defname+j) )
  576. {
  577. if( isNew ) *isNew = ( s_kolAddDefs >= kol );
  578. return stdef;
  579. }
  580. }
  581. stdef = stdef->last;
  582. }
  583. return NULL;
  584. }
  585. static COMMANDS * ComSearch( char * cmdname, COMMANDS * stcmdStart )
  586. {
  587. COMMANDS * stcmd = ( stcmdStart ) ? stcmdStart : hb_pp_topCommand;
  588. HB_TRACE(HB_TR_DEBUG, ("ComSearch(%s, %p)", cmdname, stcmdStart));
  589. while( stcmd != NULL )
  590. {
  591. int j;
  592. for( j=0; (*(stcmd->name+j)==toupper(*(cmdname+j))) &&
  593. (*(stcmd->name+j)!='\0') &&
  594. ((stcmd->com_or_xcom)? 1:(j<4 || ISNAME(*(cmdname+j+1)))); j++ );
  595. if( (*(stcmd->name+j)==toupper(*(cmdname+j))) ||
  596. ( !stcmd->com_or_xcom && j >= 4 && *(stcmd->name+j)!='\0'
  597. && *(cmdname+j) == '\0' ) )
  598. break;
  599. stcmd = stcmd->last;
  600. }
  601. return stcmd;
  602. }
  603. static COMMANDS * TraSearch( char * cmdname, COMMANDS * sttraStart )
  604. {
  605. int j;
  606. COMMANDS *sttra = ( sttraStart ) ? sttraStart : hb_pp_topTranslate;
  607. HB_TRACE(HB_TR_DEBUG, ("TraSearch(%s, %p)", cmdname, sttraStart));
  608. while( sttra != NULL )
  609. {
  610. for( j=0; *(sttra->name+j)==toupper(*(cmdname+j)) &&
  611. *(sttra->name+j)!='\0' &&
  612. ((sttra->com_or_xcom)? 1:(j<4 || ISNAME(*(cmdname+j+1)))); j++ );
  613. if( *(sttra->name+j)==toupper(*(cmdname+j)) ||
  614. ( !sttra->com_or_xcom && j >= 4 &&
  615. *(sttra->name+j)!='\0' && *(cmdname+j) == '\0' ) )
  616. break;
  617. sttra = sttra->last;
  618. }
  619. return sttra;
  620. }
  621. static void ParseCommand( char * sLine, BOOL com_or_xcom, BOOL com_or_tra )
  622. {
  623. static char mpatt[ PATTERN_SIZE ];
  624. static char rpatt[ PATTERN_SIZE ];
  625. char cmdname[ MAX_NAME ];
  626. COMMANDS * stcmd;
  627. int mlen,rlen;
  628. int ipos;
  629. /* Ron Pinkas added 2000-12-03 */
  630. BOOL bOk = FALSE;
  631. HB_TRACE(HB_TR_DEBUG, ("ParseCommand(%s, %d, %d)", sLine, com_or_xcom, com_or_tra));
  632. HB_SKIPTABSPACES( sLine );
  633. ipos = 0;
  634. /* JFL 2000-09-19 */
  635. /* This was the original line as Alexander wrote it */
  636. /* while( *sLine != '\0' && *sLine != ' ' && *sLine != '\t' && *sLine != '<' && *sLine != '=' && ( *sLine != '(' || ipos == 0 ) ) */
  637. /* Now the line #xtranslate = name(.. => will be allowed */
  638. /* I changed it to the following to allow < and = to be the first char within a translate or xtranslate */
  639. while( *sLine != '\0' && *sLine != ' ' && *sLine != '\t' && ( *sLine != '<' || ipos == 0 ) && ( *sLine != '=' || ipos == 0 ) && ( *sLine != '(' || ipos == 0 ) )
  640. {
  641. /* Ron Pinkas added 2000-01-24 */
  642. if( ! ISNAME( *sLine ) )
  643. {
  644. if( IS_2CHAR_OPERATOR( sLine ) )
  645. {
  646. *(cmdname+ipos++) = *sLine++;
  647. *(cmdname+ipos++) = *sLine++;
  648. break;
  649. }
  650. else
  651. {
  652. *(cmdname+ipos++) = *sLine++;
  653. break;
  654. }
  655. }
  656. /* END, Ron Pinkas added 2000-01-24 */
  657. *(cmdname+ipos++) = *sLine++;
  658. }
  659. *(cmdname+ipos) = '\0';
  660. if( !ipos )
  661. {
  662. return;
  663. }
  664. hb_strupr( cmdname );
  665. HB_SKIPTABSPACES(sLine);
  666. /* Ron Pinkas added 2000-12-03 */
  667. ipos = 0;
  668. while( *sLine )
  669. {
  670. mpatt[ipos++] = *sLine;
  671. if( *sLine == '=' )
  672. {
  673. int i = ipos;
  674. sLine++;
  675. mpatt[i++] = *sLine;
  676. while( *sLine && ( *sLine == ' ' || *sLine == '\t' ) )
  677. {
  678. sLine++;
  679. mpatt[i++] = *sLine;
  680. }
  681. if( *sLine == '>' )
  682. {
  683. ipos = ipos - 2;
  684. while( mpatt[ipos] == ' ' || mpatt[ipos] == '\t' )
  685. {
  686. ipos--;
  687. }
  688. mpatt[ipos + 1] = '\0';
  689. sLine++;
  690. bOk = TRUE;
  691. break;
  692. }
  693. ipos = i;
  694. }
  695. sLine++;
  696. }
  697. /* End - Ron Pinkas added 2000-12-03 */
  698. /* Ron Pinkas modified 2000-12-03
  699. if( (ipos = hb_strAt( "=>", 2, sLine, strlen(sLine) )) > 0 ) */
  700. if( bOk )
  701. {
  702. /* Ron Pinkas removed 2000-12-03
  703. stroncpy( mpatt, sLine, ipos-1 ); */
  704. RemoveSlash( mpatt );
  705. mlen = strotrim( mpatt, TRUE );
  706. /* Ron Pinkas removed 2000-12-03
  707. sLine += ipos + 1; */
  708. HB_SKIPTABSPACES(sLine);
  709. hb_pp_strocpy( rpatt, sLine );
  710. rlen = strotrim( rpatt, TRUE );
  711. ConvertPatterns( mpatt, mlen, rpatt, rlen );
  712. if( com_or_tra )
  713. stcmd = AddCommand( cmdname );
  714. else
  715. stcmd = AddTranslate( cmdname );
  716. stcmd->com_or_xcom = com_or_xcom;
  717. stcmd->mpatt = hb_strdup( mpatt );
  718. stcmd->value = ( rlen > 0 ) ? hb_strdup( rpatt ) : NULL;
  719. /* JFL */
  720. /*
  721. printf( "Parsecommand Name: %s Pat: %s Val: %s\n", stcmd->name, stcmd->mpatt, stcmd->value );
  722. */
  723. }
  724. else
  725. {
  726. sLine -= ( ipos + 1 );
  727. hb_compGenError( hb_pp_szErrors, 'F', HB_PP_ERR_COMMAND_DEFINITION, cmdname, sLine );
  728. }
  729. }
  730. /* ConvertPatterns()
  731. * Converts result pattern in #command and #translate to inner format
  732. */
  733. static void ConvertPatterns( char * mpatt, int mlen, char * rpatt, int rlen )
  734. {
  735. int i = 0, ipos, ifou;
  736. int explen, rmlen;
  737. char exppatt[ MAX_NAME ], expreal[ 5 ] = "\1 0";
  738. char lastchar = '@', exptype;
  739. char * ptr;
  740. HB_TRACE(HB_TR_DEBUG, ("ConvertPatterns(%s, %d, %s, %d)", mpatt, mlen, rpatt, rlen));
  741. while( *(mpatt+i) != '\0' )
  742. {
  743. if( *(mpatt+i) == '<' )
  744. { /* Drag match marker, determine it type */
  745. explen = 0; ipos = i; i++; exptype = '0';
  746. while( *(mpatt+i) == ' ' || *(mpatt+i) == '\t' ) i++;
  747. if( *(mpatt+i) == '*' ) /* Wild match marker */
  748. { exptype = '3'; i++; }
  749. else if( *(mpatt+i) == '(' ) /* Extended expression match marker */
  750. { exptype = '4'; i++; }
  751. else if( *(mpatt+i) == '!' ) /* Extended expression match marker */
  752. { exptype = '5'; i++; }
  753. ptr = mpatt + i;
  754. while( *ptr != '>' )
  755. {
  756. if( *ptr == '\0' || *ptr == '<' || *ptr == '[' || *ptr == ']' )
  757. {
  758. hb_compGenError( hb_pp_szErrors, 'F', HB_PP_ERR_PATTERN_DEFINITION, NULL, NULL );
  759. return;
  760. }
  761. ptr++;
  762. }
  763. while( *(mpatt+i) != '>' )
  764. {
  765. if( *(mpatt+i) == ',' ) /* List match marker */
  766. {
  767. exptype = '1';
  768. while( *(mpatt+i) != '>' ) i++;
  769. break;
  770. }
  771. else if( *(mpatt+i) == ':' ) /* Restricted match marker */
  772. {
  773. exptype = '2';
  774. *(mpatt+i--) = ' ';
  775. break;
  776. }
  777. if( *(mpatt+i) != ' ' && *(mpatt+i) != '\t' )
  778. *(exppatt+explen++) = *(mpatt+i);
  779. i++;
  780. }
  781. if( exptype == '3' )
  782. {
  783. if( *(exppatt+explen-1) == '*' ) explen--;
  784. else
  785. hb_compGenError( hb_pp_szErrors, 'F', HB_PP_ERR_PATTERN_DEFINITION, NULL, NULL );
  786. }
  787. else if( exptype == '4' )
  788. {
  789. if( *(exppatt+explen-1) == ')' ) explen--;
  790. else
  791. hb_compGenError( hb_pp_szErrors, 'F', HB_PP_ERR_PATTERN_DEFINITION, NULL, NULL );
  792. }
  793. else if( exptype == '5' )
  794. {
  795. if( *(exppatt+explen-1) == '!' ) explen--;
  796. else
  797. hb_compGenError( hb_pp_szErrors, 'F', HB_PP_ERR_PATTERN_DEFINITION, NULL, NULL );
  798. }
  799. rmlen = i - ipos + 1;
  800. /* Convert match marker into inner format */
  801. lastchar = (lastchar!='Z') ? ( (char) ( (unsigned int)lastchar + 1 ) ):
  802. 'a';
  803. expreal[1] = lastchar;
  804. expreal[2] = exptype;
  805. hb_pp_Stuff( expreal, mpatt+ipos, 4, rmlen, mlen );
  806. mlen += 4 - rmlen;
  807. i += 4 - rmlen;
  808. /* Look for appropriate result markers */
  809. ptr = rpatt;
  810. while( (ifou = hb_strAt( exppatt, explen, ptr, rlen-(ptr-rpatt) )) > 0 )
  811. {
  812. /* Convert result marker into inner format */
  813. ptr += ifou;
  814. if( *(ptr-2) == '<' && *(ptr+explen-1) == '>' &&
  815. *(ptr-3) != '\\' && *(ptr+explen-2) != '\\' ) /* <...> */
  816. {
  817. if( *(ptr-3) == '#' && *(ptr-4) != '\\' ) /* #<...> */
  818. { exptype = '1'; ptr -= 3; rmlen = explen+3; }
  819. else
  820. { exptype = '0'; ptr -= 2; rmlen = explen+2; }
  821. }
  822. else if( *(ptr-3) == '<' && *(ptr+explen) == '>' &&
  823. *(ptr-4) != '\\' && *(ptr+explen-1) != '\\' ) /* < ... > */
  824. {
  825. ptr -= 2;
  826. if( *ptr == '\"' ) exptype = '2';
  827. else if( *ptr == '(' ) exptype = '3';
  828. else if( *ptr == '{' ) exptype = '4';
  829. else if( *ptr == '.' ) exptype = '5';
  830. else if( *ptr == '-' ) exptype = '6';
  831. ptr--;
  832. rmlen = explen+4;
  833. }
  834. else continue;
  835. expreal[2] = exptype;
  836. hb_pp_Stuff( expreal, ptr, 4, rmlen, rlen );
  837. rlen += 4 - rmlen;
  838. }
  839. }
  840. i++;
  841. }
  842. }
  843. static COMMANDS * AddCommand( char * cmdname )
  844. {
  845. COMMANDS * stcmd;
  846. HB_TRACE(HB_TR_DEBUG, ("AddCommand(%s)", cmdname));
  847. stcmd = ( COMMANDS * ) hb_xgrab( sizeof( COMMANDS ) );
  848. stcmd->last = hb_pp_topCommand;
  849. hb_pp_topCommand = stcmd;
  850. stcmd->name = hb_strdup( cmdname );
  851. s_kolAddComs++;
  852. return stcmd;
  853. }
  854. static COMMANDS* AddTranslate( char * traname )
  855. {
  856. COMMANDS * sttra;
  857. HB_TRACE(HB_TR_DEBUG, ("AddTranslate(%s)", traname));
  858. sttra = ( COMMANDS * ) hb_xgrab( sizeof( COMMANDS ) );
  859. sttra->last = hb_pp_topTranslate;
  860. hb_pp_topTranslate = sttra;
  861. sttra->name = hb_strdup( traname );
  862. s_kolAddTras++;
  863. return sttra;
  864. }
  865. int hb_pp_ParseExpression( char * sLine, char * sOutLine )
  866. {
  867. char sToken[MAX_NAME];
  868. char * ptri, * ptro, * ptrb;
  869. int lenToken, i, ipos, isdvig, lens;
  870. int ifou;
  871. int rezDef, rezTra, rezCom, kolpass = 0;
  872. DEFINES * stdef;
  873. COMMANDS * stcmd;
  874. HB_TRACE(HB_TR_DEBUG, ("hb_pp_ParseExpression(%s, %s)", sLine, sOutLine));
  875. #if 0
  876. printf( "Line: >%s<\n", sLine );
  877. #endif
  878. do
  879. {
  880. strotrim( sLine, FALSE );
  881. #if 0
  882. printf( "Trimed: >%s<\n", sLine );
  883. #endif
  884. rezDef = 0; rezTra = 0; rezCom = 0;
  885. isdvig = 0;
  886. do
  887. {
  888. ptro = sOutLine;
  889. ptri = sLine + isdvig;
  890. ipos = md_strAt( ";", 1, ptri, TRUE, FALSE, FALSE );
  891. if( ipos > 0 )
  892. {
  893. *(ptri+ipos-1) = '\0';
  894. }
  895. HB_SKIPTABSPACES( ptri );
  896. if( *ptri == '#' )
  897. {
  898. hb_pp_ParseDirective( ptri+1 );
  899. if( ipos > 0 )
  900. {
  901. *( sLine + isdvig + ipos - 1 ) = ';';
  902. }
  903. lens = strlen( sLine + isdvig );
  904. hb_pp_Stuff( " ", sLine + isdvig, 0, (ipos)? ipos:lens, lens );
  905. if( ipos > 0 )
  906. {
  907. ipos = 1;
  908. }
  909. }
  910. else
  911. { /* Look for macros from #define */
  912. while( ( lenToken = NextName( &ptri, sToken ) ) > 0 )
  913. {
  914. #if 0
  915. printf( "Token: >%s< Line: >%s<\n", sToken, sLine );
  916. #endif
  917. if( (stdef=DefSearch(sToken,NULL)) != NULL )
  918. {
  919. ptrb = ptri - lenToken;
  920. if( ( i = WorkDefine( &ptri, ptro, stdef ) ) >= 0 )
  921. {
  922. rezDef++;
  923. lens = strlen( ptrb );
  924. if( ipos > 0 )
  925. {
  926. *(ptrb+lens) = ';';
  927. lens += strlen( ptrb+lens+1 );
  928. }
  929. hb_pp_Stuff( ptro, ptrb, i, ptri-ptrb, lens+1 );
  930. if( ipos > 0 )
  931. {
  932. ipos += i - (ptri-ptrb);
  933. *(sLine + isdvig + ipos - 1) = '\0';
  934. }
  935. ptri += i - (ptri-ptrb);
  936. }
  937. }
  938. }
  939. #if 0
  940. if( *sOutLine )
  941. printf( "*After #defines: >%s<\n", sOutLine );
  942. else
  943. printf( "After #defines: >%s<\n", sLine );
  944. #endif
  945. /* Look for definitions from #translate */
  946. stcmd = hb_pp_topTranslate;
  947. while( stcmd != NULL )
  948. {
  949. ptri = sLine + isdvig;
  950. lenToken = strlen(stcmd->name);
  951. while( ( ifou = md_strAt( stcmd->name, lenToken, ptri, TRUE, FALSE, FALSE )) > 0 )
  952. {
  953. ptri += ifou -1;
  954. if( ( i = WorkTranslate( ptri+lenToken, ptro, stcmd, &lens ) ) >= 0 )
  955. {
  956. lens += lenToken;
  957. while( lens > 0 && (*(ptri+lens-1)==' ' || *(ptri+lens-1)=='\t') )
  958. {
  959. lens--;
  960. }
  961. if( ipos > 0 )
  962. {
  963. *(sLine+isdvig+ipos-1) = ';';
  964. }
  965. hb_pp_Stuff( ptro, ptri, i, lens, strlen(ptri) );
  966. rezTra = 1;
  967. if( ipos > 0 )
  968. {
  969. ipos += i - lens;
  970. *(sLine+isdvig+ipos-1) = '\0';
  971. }
  972. ptri += i;
  973. }
  974. else
  975. {
  976. ptri += lenToken;
  977. }
  978. }
  979. stcmd = stcmd->last;
  980. }
  981. #if 0
  982. if( *sOutLine )
  983. printf( "*After #translate: >%s<\n", sOutLine );
  984. else
  985. printf( "After #translate: >%s<\n", sLine );
  986. #endif
  987. /* Look for definitions from #command */
  988. /* JFL ! Was 3 but insufficient in most cases */
  989. /* I know this is a new hardcoded limit ... any better idea's welcome */
  990. if( kolpass < 20 )
  991. {
  992. ptri = sLine + isdvig;
  993. HB_SKIPTABSPACES( ptri );
  994. if( ISNAME( *ptri ) )
  995. {
  996. NextName( &ptri, sToken );
  997. }
  998. else
  999. {
  1000. /* Ron Pinkas commented 2000-01-24
  1001. i = 0;
  1002. while( *ptri != ' ' && *ptri != '\t' && *ptri != '\0' && *ptri != '\"' && *ptri != '\'' && *ptri != '(' && !ISNAME(*ptri) )
  1003. {
  1004. *(sToken+i) = *ptri++;
  1005. i++;
  1006. }
  1007. *(sToken+i) = '\0';
  1008. */
  1009. /* Ron Pinkas added 2000-01-24 */
  1010. if( IS_2CHAR_OPERATOR( ptri ) )
  1011. {
  1012. sToken[0] = *ptri++;
  1013. sToken[1] = *ptri++;
  1014. sToken[2] = '\0';
  1015. }
  1016. else
  1017. {
  1018. sToken[0] = *ptri++;
  1019. sToken[1] = '\0';
  1020. }
  1021. /* END, Ron Pinkas added 2000-01-24 */
  1022. }
  1023. HB_SKIPTABSPACES( ptri );
  1024. #if 0
  1025. printf( "Token: %s\n", sToken );
  1026. #endif
  1027. if( ( *ptri == '\0' || ( *ptri != '=' && (!IsInStr(*ptri,":/+*-%^") || *(ptri+1) != '=') &&
  1028. ( *ptri != '-' || *(ptri+1) != '>' ) ) ) && ( stcmd = ComSearch(sToken,NULL) ) != NULL )
  1029. {
  1030. ptro = sOutLine;
  1031. i = WorkCommand( ptri, ptro, stcmd );
  1032. ptri = sLine + isdvig;
  1033. if( ipos > 0 )
  1034. {
  1035. *(ptri+ipos-1) = ';';
  1036. }
  1037. if( i >= 0 )
  1038. {
  1039. if( isdvig + ipos > 0 )
  1040. {
  1041. lens = strlen( sLine+isdvig );
  1042. hb_pp_Stuff( ptro, sLine+isdvig, i, (ipos)? ipos-1:lens, lens );
  1043. if( ipos > 0 )
  1044. {
  1045. ipos = i + 1;
  1046. }
  1047. }
  1048. else
  1049. {
  1050. memcpy( sLine, sOutLine, i+1);
  1051. }
  1052. }
  1053. rezCom = 1;
  1054. }
  1055. else if( ipos > 0 )
  1056. {
  1057. *(sLine+isdvig+ipos-1) = ';';
  1058. }
  1059. }
  1060. else if( ipos > 0 )
  1061. {
  1062. *(sLine+isdvig+ipos-1) = ';';
  1063. }
  1064. }
  1065. isdvig += ipos;
  1066. }
  1067. while( ipos != 0 );
  1068. kolpass++;
  1069. if( kolpass > 20 && rezDef )
  1070. {
  1071. hb_compGenError( hb_pp_szErrors, 'F', HB_PP_ERR_RECURSE, NULL, NULL );
  1072. break;
  1073. }
  1074. }
  1075. while( rezDef || rezTra || rezCom );
  1076. #if 0
  1077. if( *sOutLine )
  1078. printf( "Out: >%s<\n", sOutLine );
  1079. else
  1080. printf( "Out: >%s<\n", sLine );
  1081. #endif
  1082. return 0;
  1083. }
  1084. static int WorkDefine( char ** ptri, char * ptro, DEFINES * stdef )
  1085. {
  1086. int npars, lens;
  1087. char * ptr;
  1088. HB_TRACE(HB_TR_DEBUG, ("WorkDefine(%p, %s, %p)", ptri, ptro, stdef));
  1089. if( stdef->npars < 0 )
  1090. {
  1091. lens = hb_pp_strocpy( ptro,stdef->value );
  1092. }
  1093. else
  1094. {
  1095. HB_SKIPTABSPACES( *ptri );
  1096. if( **ptri == '(' )
  1097. {
  1098. npars = 0; ptr = *ptri;
  1099. do
  1100. {
  1101. ptr++;
  1102. if( NextParm( &ptr, NULL ) > 0 )
  1103. {
  1104. npars++;
  1105. }
  1106. }
  1107. while( *ptr != ')' && *ptr != '\0' );
  1108. if( *ptr == ')' && stdef->npars == npars )
  1109. {
  1110. /* Ron Pinkas added 2000-11-21 */
  1111. char *pTmp = ptr + 1;
  1112. while( *pTmp && ( *pTmp == ' ' || *pTmp == '\t' ) )
  1113. {
  1114. pTmp++;
  1115. }
  1116. if( *pTmp == '[' )
  1117. {
  1118. s_bArray = TRUE;
  1119. }
  1120. /* END - Ron Pinkas added 2000-11-21 */
  1121. lens = WorkPseudoF( ptri, ptro, stdef );
  1122. }
  1123. else
  1124. {
  1125. return -1;
  1126. }
  1127. }
  1128. else
  1129. {
  1130. return -1;
  1131. }
  1132. }
  1133. return lens;
  1134. }
  1135. static int WorkPseudoF( char ** ptri, char * ptro, DEFINES * stdef )
  1136. {
  1137. char parfict[ MAX_NAME ], * ptrreal;
  1138. char * ptrb;
  1139. int ipos, ifou, ibeg;
  1140. int lenfict, lenreal, lenres;
  1141. HB_TRACE(HB_TR_DEBUG, ("WorkPseudoF(%p, %s, %p)", ptri, ptro, stdef));
  1142. lenres = hb_pp_strocpy( ptro, stdef->value ); /* Copying value of macro to destination string */
  1143. if( stdef->pars )
  1144. {
  1145. ipos = 0; ibeg = 0;
  1146. do /* Parsing through parameters */
  1147. { /* in macro definition */
  1148. if( *(stdef->pars+ipos) == ',' || *(stdef->pars+ipos) == '\0' )
  1149. {
  1150. *(parfict+ipos-ibeg) = '\0';
  1151. lenfict = ipos - ibeg;
  1152. if( **ptri != ')' )
  1153. {
  1154. (*ptri)++; /* Get next real parameter */
  1155. HB_SKIPTABSPACES( *ptri );
  1156. ptrreal = *ptri;
  1157. lenreal = NextParm( ptri, NULL);
  1158. ptrb = ptro;
  1159. while( (ifou = hb_strAt( parfict, lenfict, ptrb, lenres-(ptrb-ptro) )) > 0 )
  1160. {
  1161. ptrb = ptrb+ifou-1;
  1162. if( !ISNAME(*(ptrb-1)) && !ISNAME(*(ptrb+lenfict)) )
  1163. {
  1164. hb_pp_Stuff( ptrreal, ptrb, lenreal, lenfict, lenres );
  1165. lenres += lenreal - lenfict;
  1166. ptrb += lenreal;
  1167. }
  1168. else
  1169. {
  1170. ptrb++;
  1171. }
  1172. }
  1173. ibeg = ipos+1;
  1174. }
  1175. }
  1176. else
  1177. {
  1178. *(parfict+ipos-ibeg) = *(stdef->pars+ipos);
  1179. }
  1180. if( *(stdef->pars+ipos) == '\0' )
  1181. {
  1182. break;
  1183. }
  1184. ipos++;
  1185. }
  1186. while( 1 );
  1187. }
  1188. else
  1189. {
  1190. while( **ptri != ')' )
  1191. {
  1192. (*ptri)++;
  1193. }
  1194. }
  1195. (*ptri)++;
  1196. return lenres;
  1197. }
  1198. static int WorkCommand( char * ptri, char * ptro, COMMANDS * stcmd )
  1199. {
  1200. int rez;
  1201. int lenres;
  1202. char * ptrmp;
  1203. char * sToken = stcmd->name;
  1204. HB_TRACE(HB_TR_DEBUG, ("WorkCommand(%s, %s, %p)", ptri, ptro, stcmd));
  1205. do
  1206. {
  1207. lenres = hb_pp_strocpy( ptro, stcmd->value ); /* Copying result pattern */
  1208. ptrmp = stcmd->mpatt; /* Pointer to a match pattern */
  1209. s_Repeate = 0;
  1210. s_groupchar = '@';
  1211. rez = CommandStuff( ptrmp, ptri, ptro, &lenres, TRUE, stcmd->com_or_xcom );
  1212. stcmd = stcmd->last;
  1213. if( rez < 0 && stcmd != NULL ) stcmd = ComSearch(sToken, stcmd);
  1214. }
  1215. while( rez < 0 && stcmd != NULL );
  1216. *(ptro+lenres) = '\0';
  1217. if( rez >= 0 ) return lenres;
  1218. return -1;
  1219. }
  1220. static int WorkTranslate( char * ptri, char * ptro, COMMANDS * sttra, int * lens )
  1221. {
  1222. int rez;
  1223. int lenres;
  1224. char * ptrmp;
  1225. char * sToken = sttra->name;
  1226. HB_TRACE(HB_TR_DEBUG, ("WorkTranslate(%s, %s, %p, %p)", ptri, ptro, sttra, lens));
  1227. do
  1228. {
  1229. lenres = hb_pp_strocpy( ptro, sttra->value );
  1230. ptrmp = sttra->mpatt;
  1231. s_Repeate = 0;
  1232. s_groupchar = '@';
  1233. rez = CommandStuff( ptrmp, ptri, ptro, &lenres, FALSE, sttra->com_or_xcom );
  1234. sttra = sttra->last;
  1235. if( rez < 0 && sttra != NULL )
  1236. {
  1237. sttra = TraSearch(sToken, sttra);
  1238. }
  1239. }
  1240. while( rez < 0 && sttra != NULL );
  1241. *(ptro+lenres) = '\0';
  1242. if( rez >= 0 )
  1243. {
  1244. *lens = rez;
  1245. return lenres;
  1246. }
  1247. return -1;
  1248. }
  1249. static int CommandStuff( char * ptrmp, char * inputLine, char * ptro, int * lenres, BOOL com_or_tra, BOOL com_or_xcom )
  1250. {
  1251. BOOL endTranslation = FALSE;
  1252. int ipos;
  1253. char * lastopti[ 3 ], * strtopti = NULL, * strtptri = NULL;
  1254. char * ptri = inputLine, * ptr, tmpname[ MAX_NAME ];
  1255. int isWordInside = 0;
  1256. /*
  1257. printf( "MP: >%s<\nIn: >%s<\n", ptrmp, ptri );
  1258. */
  1259. HB_TRACE(HB_TR_DEBUG, ("CommandStuff(%s, %s, %s, %p, %d, %d)", ptrmp, inputLine, ptro, lenres, com_or_tra, com_or_xcom));
  1260. s_numBrackets = 0;
  1261. HB_SKIPTABSPACES( ptri );
  1262. if( ptrmp == NULL ) { if( *ptri != '\0' ) return -1; }
  1263. else
  1264. while( *ptri != '\0' && !endTranslation )
  1265. {
  1266. HB_SKIPTABSPACES( ptrmp );
  1267. if( *ptrmp == '[' && !s_numBrackets && !strtopti )
  1268. strtopti = ptrmp;
  1269. if( !s_numBrackets && strtopti && strtptri != ptri &&
  1270. ( ISNAME( *ptri ) || *ptri=='&' ) )
  1271. {
  1272. strtptri = ptri;
  1273. ptrmp = strtopti;
  1274. ptr = ptri;
  1275. ipos = NextName( &ptr, tmpname );
  1276. ipos = md_strAt( tmpname, ipos, strtopti, TRUE, TRUE, TRUE );
  1277. if( ipos && TestOptional( strtopti, strtopti+ipos-2 ) )
  1278. {
  1279. ptr = strtopti+ipos-2;
  1280. ptr = PrevSquare( ptr, strtopti, NULL );
  1281. if( ptr )
  1282. ptrmp = ptr;
  1283. }
  1284. }
  1285. switch( *ptrmp ) {
  1286. case '[':
  1287. if( !s_numBrackets ) isWordInside = 0;
  1288. s_numBrackets++;
  1289. s_aIsRepeate[ s_Repeate ] = 0;
  1290. lastopti[s_Repeate++] = ptrmp;
  1291. ptrmp++;
  1292. if( !CheckOptional( ptrmp, ptri, ptro, lenres, com_or_tra, com_or_xcom ) )
  1293. SkipOptional( &ptrmp );
  1294. break;
  1295. case ']':
  1296. if( s_Repeate )
  1297. {
  1298. s_Repeate--;
  1299. if( s_aIsRepeate[ s_Repeate ] )
  1300. {
  1301. if( ISNAME(*ptri) )
  1302. {
  1303. ptr = ptri;
  1304. ipos = NextName( &ptr, tmpname );
  1305. ipos = md_strAt( tmpname, ipos, ptrmp, TRUE, TRUE, TRUE );
  1306. if( ipos && TestOptional( ptrmp+1, ptrmp+ipos-2 ) )
  1307. {
  1308. ptr = PrevSquare( ptrmp+ipos-2, ptrmp+1, NULL );
  1309. if( !ptr || CheckOptional( ptrmp+1, ptri, ptro, lenres, com_or_tra, com_or_xcom ) )
  1310. {
  1311. ptrmp = lastopti[s_Repeate];
  1312. ptrmp++;
  1313. s_Repeate++;
  1314. SkipOptional( &ptrmp );
  1315. s_numBrackets++;
  1316. ptrmp++;
  1317. strtptri = ptri;
  1318. }
  1319. else
  1320. ptrmp = lastopti[s_Repeate];
  1321. }
  1322. else
  1323. ptrmp = lastopti[s_Repeate];
  1324. }
  1325. else
  1326. ptrmp = lastopti[s_Repeate];
  1327. }
  1328. else
  1329. {
  1330. if( !isWordInside ) strtopti = NULL;
  1331. ptrmp++;
  1332. }
  1333. s_numBrackets--;
  1334. }
  1335. else
  1336. {
  1337. if( !isWordInside ) strtopti = NULL;
  1338. s_numBrackets--; ptrmp++;
  1339. }
  1340. break;
  1341. case ',':
  1342. if( s_numBrackets == 1 ) isWordInside = 1;
  1343. if( !s_numBrackets ) strtopti = NULL;
  1344. if( *ptri == ',' ) { ptrmp++; ptri++; }
  1345. else
  1346. {
  1347. if( s_numBrackets )
  1348. {
  1349. SkipOptional( &ptrmp );
  1350. }
  1351. else return -1;
  1352. }
  1353. break;
  1354. case '\1': /* Match marker */
  1355. if( !s_numBrackets ) strtopti = NULL;
  1356. if( s_numBrackets == 1 && *(ptrmp+2) == '2' ) isWordInside = 1; /* restricted match marker */
  1357. if( !WorkMarkers( &ptrmp, &ptri, ptro, lenres, com_or_xcom ) )
  1358. {
  1359. if( s_numBrackets )
  1360. {
  1361. SkipOptional( &ptrmp );
  1362. }
  1363. else return -1;
  1364. }
  1365. break;
  1366. case '\0':
  1367. if( com_or_tra )
  1368. return -1;
  1369. else endTranslation = TRUE;
  1370. break;
  1371. default: /* Key word */
  1372. if( s_numBrackets == 1 ) isWordInside = 1;
  1373. if( !s_numBrackets ) strtopti = NULL;
  1374. ptr = ptri;
  1375. if( *ptri == ',' || truncmp( &ptri, &ptrmp, !com_or_xcom ) )
  1376. {
  1377. ptri = ptr;
  1378. if( s_numBrackets )
  1379. {
  1380. SkipOptional( &ptrmp );
  1381. }
  1382. else return -1;
  1383. }
  1384. }
  1385. HB_SKIPTABSPACES( ptri );
  1386. };
  1387. if( *ptrmp != '\0' )
  1388. {
  1389. if( s_Repeate ) { s_Repeate = 0; ptrmp = lastopti[0]; }
  1390. s_numBrackets = 0;
  1391. do
  1392. {
  1393. HB_SKIPTABSPACES( ptrmp );
  1394. if( *ptrmp != '\0' )
  1395. switch( *ptrmp ) {
  1396. case '[':
  1397. ptrmp++;
  1398. SkipOptional( &ptrmp );
  1399. ptrmp++;
  1400. break;
  1401. case ']': ptrmp++; break;
  1402. default:
  1403. return -1;
  1404. }
  1405. }
  1406. while( *ptrmp != '\0' );
  1407. }
  1408. SearnRep( "\1","",0,ptro,lenres);
  1409. *(ptro + *lenres) = '\0';
  1410. *lenres = RemoveSlash( ptro ); /* Removing '\' from result string */
  1411. if( com_or_tra ) return 1; else return (ptri-inputLine);
  1412. }
  1413. static int RemoveSlash( char * stroka )
  1414. {
  1415. char *ptr = stroka;
  1416. int State = STATE_INIT;
  1417. BOOL bDirective = FALSE;
  1418. int lenres = strlen( stroka );
  1419. HB_TRACE(HB_TR_DEBUG, ("RemoveSlash(%s)", stroka));
  1420. while( *ptr != '\0' )
  1421. {
  1422. switch( State ) {
  1423. case STATE_INIT:
  1424. if( *ptr != ' ' && *ptr != '\t' ) State = STATE_NORMAL;
  1425. if( *ptr == '#' ) bDirective = TRUE;
  1426. case STATE_NORMAL:
  1427. if( *ptr == '\'' ) State = STATE_QUOTE1;
  1428. else if( *ptr == '\"' ) State = STATE_QUOTE2;
  1429. else if( *ptr == '[' ) State = STATE_QUOTE3;
  1430. else if( *ptr == ';' )
  1431. {
  1432. State = STATE_INIT;
  1433. bDirective = FALSE;
  1434. }
  1435. else if( !bDirective )
  1436. {
  1437. if( *ptr == '\\' && ( *(ptr+1) == '[' || *(ptr+1) == ']' ||
  1438. *(ptr+1) == '{' || *(ptr+1) == '}' || *(ptr+1) == '<' ||
  1439. *(ptr+1) == '>' || *(ptr+1) == '\'' || *(ptr+1) == '\"' ) )
  1440. {
  1441. hb_pp_Stuff( "", ptr, 0, 1, lenres - (ptr - stroka) );
  1442. lenres--;
  1443. }
  1444. }
  1445. break;
  1446. case STATE_QUOTE1:
  1447. if( *ptr == '\'' ) State = STATE_NORMAL;
  1448. break;
  1449. case STATE_QUOTE2:
  1450. if( *ptr == '\"' ) State = STATE_NORMAL;
  1451. break;
  1452. case STATE_QUOTE3:
  1453. if( *ptr == ']' ) State = STATE_NORMAL;
  1454. break;
  1455. }
  1456. ptr++;
  1457. }
  1458. return lenres;
  1459. }
  1460. static int WorkMarkers( char ** ptrmp, char ** ptri, char * ptro, int * lenres, BOOL com_or_xcom )
  1461. {
  1462. static char expreal[ MAX_EXP ];
  1463. char exppatt[ MAX_NAME ];
  1464. int lenreal = 0, maxlenreal = HB_PP_STR_SIZE, lenpatt;
  1465. int rezrestr, ipos, nBra;
  1466. char * ptr, * ptrtemp;
  1467. HB_TRACE(HB_TR_DEBUG, ("WorkMarkers(%p, %p, %s, %p)", ptrmp, ptri, ptro, lenres));
  1468. /* Copying a match pattern to 'exppatt' */
  1469. lenpatt = stroncpy( exppatt, *ptrmp, 4 );
  1470. *ptrmp += 4;
  1471. HB_SKIPTABSPACES( *ptrmp );
  1472. /* JFL removed 12/11/2001 to allow param like (,,3) as allowed by clipper */
  1473. /*
  1474. if( **ptri == ',' )
  1475. {
  1476. if( s_numBrackets )
  1477. {
  1478. return 0;
  1479. }
  1480. }*/
  1481. ptrtemp = *ptrmp;
  1482. if( *(exppatt+2) != '2' && *ptrtemp == ']' )
  1483. {
  1484. ptrtemp++;
  1485. HB_SKIPTABSPACES( ptrtemp );
  1486. while( *ptrtemp == '[' )
  1487. {
  1488. nBra = 0;
  1489. ptrtemp++;
  1490. while( ( *ptrtemp != ']' || nBra ) && *ptrtemp != '\0')
  1491. {
  1492. if( *ptrtemp == '[' )
  1493. {
  1494. nBra++;
  1495. }
  1496. else if( *ptrtemp == ']' )
  1497. {
  1498. nBra --;
  1499. }
  1500. ptrtemp++;
  1501. }
  1502. ptrtemp++;
  1503. HB_SKIPTABSPACES( ptrtemp );
  1504. }
  1505. }
  1506. if( *(exppatt+2) != '2' && *ptrtemp != '\1' && *ptrtemp != ',' && *ptrtemp != '[' && *ptrtemp != ']' && *ptrtemp != '\0' )
  1507. {
  1508. lenreal = strincpy( expreal, ptrtemp );
  1509. if( (ipos = md_strAt( expreal, lenreal, *ptri, TRUE, TRUE, FALSE )) > 0 )
  1510. {
  1511. if( ptrtemp > *ptrmp )
  1512. {
  1513. if( ipos == 1 )
  1514. {
  1515. if( s_numBrackets )
  1516. {
  1517. return 0;
  1518. }
  1519. }
  1520. else
  1521. {
  1522. maxlenreal = ipos - 1;
  1523. lenreal = 0;
  1524. }
  1525. }
  1526. else
  1527. {
  1528. /*
  1529. printf( "\nFound: '%s' Len: %i In: '%s' At: %i \n", expreal, lenreal, *ptri, ipos );
  1530. */
  1531. lenreal = stroncpy( expreal, *ptri, ipos-1 );
  1532. #if 0
  1533. printf( "\nExpr: '%s' ptrtemp: '%s' exppat: '%s'\n", expreal, ptrtemp, exppatt );
  1534. #endif
  1535. if( ipos > 1 )
  1536. {
  1537. if( *(exppatt+2) == '5' ) /* ---- Minimal match marker */
  1538. {
  1539. if( IsIdentifier( expreal ) )
  1540. {
  1541. /*
  1542. printf( "Accepted ID: >%s<\n", expreal );
  1543. */
  1544. *ptri += lenreal;
  1545. }
  1546. }
  1547. else if( isExpres( expreal, *(exppatt+2) == '1' ) )
  1548. {
  1549. /*
  1550. printf( "Accepted: >%s<\n", expreal );
  1551. */
  1552. *ptri += lenreal;
  1553. }
  1554. }
  1555. else
  1556. {
  1557. if( s_numBrackets )
  1558. {
  1559. return 0;
  1560. }
  1561. else
  1562. {
  1563. lenreal = 0;
  1564. }
  1565. }
  1566. }
  1567. }
  1568. else
  1569. {
  1570. if( s_numBrackets )
  1571. {
  1572. return 0;
  1573. }
  1574. else
  1575. {
  1576. lenreal = 0;
  1577. }
  1578. }
  1579. }
  1580. if( *(exppatt+2) == '4' ) /* ---- extended match marker */
  1581. {
  1582. if( !lenreal ) lenreal = getExpReal( expreal, ptri, FALSE, maxlenreal, FALSE );
  1583. {
  1584. SearnRep( exppatt,expreal,lenreal,ptro,lenres);
  1585. }
  1586. }
  1587. else if( *(exppatt+2) == '3' ) /* ---- wild match marker */
  1588. {
  1589. lenreal = hb_pp_strocpy( expreal, *ptri );
  1590. *ptri += lenreal;
  1591. SearnRep( exppatt,expreal,lenreal,ptro,lenres);
  1592. }
  1593. else if( *(exppatt+2) == '2' ) /* ---- restricted match marker */
  1594. {
  1595. while( **ptrmp != '>' )
  1596. {
  1597. *(exppatt+lenpatt++) = *((*ptrmp)++);
  1598. }
  1599. *(exppatt+lenpatt) = '\0';
  1600. (*ptrmp)++;
  1601. ptr = exppatt + 4;
  1602. rezrestr = 0;
  1603. while( *ptr != '\0' )
  1604. {
  1605. if( *ptr == '&' )
  1606. {
  1607. if( **ptri == '&' )
  1608. {
  1609. rezrestr = 1;
  1610. /* (*ptri)++; */
  1611. lenreal = getExpReal( expreal, ptri, FALSE, maxlenreal, FALSE );
  1612. SearnRep( exppatt,expreal,lenreal,ptro,lenres);
  1613. break;
  1614. }
  1615. else
  1616. {
  1617. ptr++;
  1618. }
  1619. }
  1620. else
  1621. {
  1622. HB_SKIPTABSPACES( ptr );
  1623. /* Comparing real parameter and restriction value */
  1624. ptrtemp = ptr;
  1625. if( !strincmp( *ptri, &ptr, !com_or_xcom ) )
  1626. {
  1627. lenreal = stroncpy( expreal, *ptri, (ptr-ptrtemp) );
  1628. *ptri += lenreal;
  1629. SearnRep( exppatt,expreal,lenreal,ptro,lenres);
  1630. rezrestr = 1;
  1631. break;
  1632. }
  1633. else
  1634. {
  1635. while( *ptr != ',' && *ptr != '\0' )
  1636. {
  1637. ptr++;
  1638. }
  1639. if( *ptr == ',' )
  1640. {
  1641. ptr++;
  1642. }
  1643. }
  1644. }
  1645. }
  1646. if( rezrestr == 0 )
  1647. {
  1648. /* If restricted match marker doesn't correspond to real parameter */
  1649. if( s_numBrackets )
  1650. {
  1651. return 0;
  1652. }
  1653. else
  1654. {
  1655. return 0;
  1656. }
  1657. }
  1658. }
  1659. else if( *(exppatt+2) == '1' ) /* ---- list match marker */
  1660. {
  1661. if( !lenreal )
  1662. {
  1663. lenreal = getExpReal( expreal, ptri, TRUE, maxlenreal, FALSE );
  1664. }
  1665. if( lenreal )
  1666. {
  1667. SearnRep( exppatt,expreal,lenreal,ptro,lenres);
  1668. }
  1669. else
  1670. {
  1671. return 0;
  1672. }
  1673. }
  1674. else /* ---- regular match marker */
  1675. {
  1676. /* Copying a real expression to 'expreal' */
  1677. if( !lenreal )
  1678. {
  1679. lenreal = getExpReal( expreal, ptri, FALSE, maxlenreal, FALSE );
  1680. }
  1681. /*
  1682. printf("Len: %i Pat: %s Exp: %s\n", lenreal, exppatt, expreal );
  1683. */
  1684. if( lenreal )
  1685. {
  1686. SearnRep( exppatt,expreal,lenreal,ptro,lenres);
  1687. }
  1688. else
  1689. {
  1690. return 0;
  1691. }
  1692. }
  1693. return 1;
  1694. }
  1695. static int getExpReal( char * expreal, char ** ptri, BOOL prlist, int maxrez, BOOL bStrict )
  1696. {
  1697. int lens = 0;
  1698. char * sZnaki = "+-=><*/$.:#%!^";
  1699. int State;
  1700. int StBr1 = 0, StBr2 = 0, StBr3 = 0;
  1701. BOOL rez = FALSE;
  1702. /* Ron Pinkas added 2000-06-02 */
  1703. BOOL bMacro = FALSE;
  1704. /* Ron Pinkas end 2000-06-02 */
  1705. /* Ron Pinkas added 2000-06-17 */
  1706. char cLastChar = '\0';
  1707. /* Ron Pinkas end 2000-06-17 */
  1708. HB_TRACE(HB_TR_DEBUG, ("getExpReal(%s, %p, %d, %d, %d)", expreal, ptri, prlist, maxrez, bStrict));
  1709. HB_SKIPTABSPACES( *ptri );
  1710. State = ( **ptri=='\'' || **ptri=='\"' || **ptri=='[' ) ? STATE_EXPRES: STATE_ID;
  1711. while( **ptri != '\0' && !rez && lens < maxrez )
  1712. {
  1713. /* Added by Ron Pinkas 2000-11-08 ( removed lots of related scattered logic below! */
  1714. if( State == STATE_EXPRES || ( cLastChar && strchr( "({[.|,$!#=<>^%*/+-", cLastChar ) ) ) /* Ron Pinkas added if on State 2001-05-02 to avoid multiple strings concatination. */
  1715. {
  1716. if( **ptri == '"' )
  1717. {
  1718. if( expreal != NULL )
  1719. {
  1720. *expreal++ = **ptri;
  1721. }
  1722. (*ptri)++;
  1723. lens++;
  1724. while( **ptri != '\0' && lens < maxrez )
  1725. {
  1726. if( expreal != NULL )
  1727. {
  1728. *expreal++ = **ptri;
  1729. }
  1730. if( **ptri == '"' )
  1731. {
  1732. break;
  1733. }
  1734. (*ptri)++;
  1735. lens++;
  1736. }
  1737. (*ptri)++;
  1738. lens++;
  1739. cLastChar = '"';
  1740. State = ( StBr1==0 && StBr2==0 && StBr3==0 )? STATE_ID_END: STATE_BRACKET;
  1741. continue;
  1742. }
  1743. else if( **ptri == '\'' )
  1744. {
  1745. char *pString;
  1746. if( expreal != NULL )
  1747. {
  1748. *expreal++ = **ptri;
  1749. }
  1750. (*ptri)++;
  1751. lens++;
  1752. pString = expreal;
  1753. while( **ptri != '\0' && lens < maxrez )
  1754. {
  1755. if( expreal != NULL )
  1756. {
  1757. *expreal++ = **ptri;
  1758. }
  1759. if( **ptri == '\'' )
  1760. {
  1761. break;
  1762. }
  1763. (*ptri)++;
  1764. lens++;
  1765. }
  1766. if( expreal != NULL )
  1767. {
  1768. *(expreal - 1) = '\0';
  1769. if( strchr( pString, '"' ) == NULL )
  1770. {
  1771. *(pString - 1) = '"';
  1772. *(expreal - 1) = '"';
  1773. }
  1774. else
  1775. {
  1776. *(expreal - 1) = '\'';
  1777. }
  1778. }
  1779. (*ptri)++;
  1780. lens++;
  1781. cLastChar = '\'';
  1782. State = ( StBr1==0 && StBr2==0 && StBr3==0 )? STATE_ID_END: STATE_BRACKET;
  1783. continue;
  1784. }
  1785. else if( **ptri == '[' /* ( see below 5-2-2001 && ( State == STATE_EXPRES || ( strchr( ")]}.", cLastChar ) == NULL && ! ISNAME( cLastChar ) ) )*/ )
  1786. {
  1787. char *pString;
  1788. if( expreal != NULL )
  1789. {
  1790. *expreal++ = **ptri;
  1791. }
  1792. (*ptri)++;
  1793. lens++;
  1794. pString = expreal;
  1795. while( **ptri != '\0' && lens < maxrez )
  1796. {
  1797. if( expreal != NULL )
  1798. {
  1799. *expreal++ = **ptri;
  1800. }
  1801. if( **ptri == ']' )
  1802. {
  1803. break;
  1804. }
  1805. (*ptri)++;
  1806. lens++;
  1807. }
  1808. if( expreal != NULL )
  1809. {
  1810. *(expreal - 1) = '\0';
  1811. if( strchr( pString, '"' ) == NULL )
  1812. {
  1813. *(pString - 1) = '"';
  1814. *(expreal - 1) = '"';
  1815. }
  1816. else if( strchr( pString, '\'' ) == NULL )
  1817. {
  1818. *(pString - 1) = '\'';
  1819. *(expreal - 1) = '\'';
  1820. }
  1821. else
  1822. {
  1823. *(expreal - 1) = ']';
  1824. }
  1825. }
  1826. (*ptri)++;
  1827. lens++;
  1828. cLastChar = ']';
  1829. State = ( StBr1==0 && StBr2==0 && StBr3==0 )? STATE_ID_END: STATE_BRACKET;
  1830. continue;
  1831. }
  1832. /* Added by Ron Pinkas 2001-05-02 ( removed lots of related scattered logic below! */
  1833. }
  1834. else if( strchr( "'\"", **ptri ) ) /* New String, can't belong to extracted expression. */
  1835. {
  1836. break;
  1837. }
  1838. else if( **ptri == '[' && ( strchr( ")]}.", cLastChar ) == NULL && ! ISNAME( cLastChar ) ) ) /* New String, can't belong to extracted expression. */
  1839. {
  1840. break;
  1841. }
  1842. /* End - END - Added by Ron Pinkas 2000-11-05 */
  1843. #if 0
  1844. printf( "State: %i Char:%c\n", State, **ptri );
  1845. #endif
  1846. switch( State )
  1847. {
  1848. case STATE_BRACKET:
  1849. {
  1850. if( **ptri == '(' )
  1851. {
  1852. StBr1++;
  1853. }
  1854. else if( **ptri == '[' )
  1855. {
  1856. StBr2++;
  1857. }
  1858. else if( **ptri == '{' )
  1859. {
  1860. StBr3++;
  1861. }
  1862. else if( **ptri == ')' )
  1863. {
  1864. StBr1--;
  1865. if( StBr1==0 && StBr2==0 && StBr3==0 )
  1866. {
  1867. State = STATE_ID_END;
  1868. }
  1869. }
  1870. else if( **ptri == ']' )
  1871. {
  1872. StBr2--;
  1873. if( StBr1==0 && StBr2==0 && StBr3==0 )
  1874. {
  1875. State = STATE_ID_END;
  1876. }
  1877. }
  1878. else if( **ptri == '}' )
  1879. {
  1880. StBr3--;
  1881. if( StBr1==0 && StBr2==0 && StBr3==0 )
  1882. {
  1883. State = STATE_ID_END;
  1884. }
  1885. }
  1886. break;
  1887. }
  1888. case STATE_ID:
  1889. case STATE_ID_END:
  1890. {
  1891. if( ( (ISNAME(**ptri) || **ptri=='\\' || **ptri=='&') && State == STATE_ID_END ) || **ptri==',' )
  1892. {
  1893. if( **ptri == ',' )
  1894. {
  1895. if( ! prlist )
  1896. {
  1897. rez = TRUE;
  1898. }
  1899. else
  1900. {
  1901. State = STATE_EXPRES;
  1902. }
  1903. }
  1904. else
  1905. {
  1906. rez = TRUE;
  1907. }
  1908. }
  1909. else if( IsInStr( **ptri, sZnaki ) )
  1910. {
  1911. /* Ron Pinkas added 2000-06-02 */
  1912. if( **ptri=='.' && bMacro )
  1913. {
  1914. /* Macro terminator '.' */
  1915. if( *(*ptri+1) == ' ' )
  1916. {
  1917. State = STATE_ID_END;
  1918. }
  1919. bMacro = FALSE;
  1920. /* Ron Pinkas added 2000-05-03 */
  1921. /* Macro terminator is NOT a coninutation char unlike '.' of logical operators, so we don't want it recorded as cLastChar! */
  1922. if( expreal != NULL )
  1923. {
  1924. *expreal++ = **ptri;
  1925. }
  1926. (*ptri)++;
  1927. lens++;
  1928. continue;
  1929. /* END - Ron Pinkas added 2000-05-03 */
  1930. }
  1931. else
  1932. /* Ron Pinkas end 2000-06-02 */
  1933. State = STATE_EXPRES;
  1934. }
  1935. else if( **ptri == '(' )
  1936. {
  1937. State = STATE_BRACKET;
  1938. StBr1 = 1;
  1939. }
  1940. else if( **ptri == '[' )
  1941. {
  1942. StBr2++;
  1943. State = STATE_BRACKET;
  1944. }
  1945. else if( **ptri == '{' )
  1946. {
  1947. State = STATE_BRACKET;
  1948. StBr3 = 1;
  1949. }
  1950. /* Ron Pinkas added 2001-01-08 */
  1951. else if( **ptri == ')' && StBr1 == 0 )
  1952. {
  1953. rez = TRUE;
  1954. }
  1955. /* Ron Pinkas added 2000-06-02 */
  1956. else if( **ptri == '&' )
  1957. {
  1958. bMacro = TRUE;
  1959. }
  1960. /* Ron Pinkas end 2000-06-02 */
  1961. else if( **ptri == ' ' )
  1962. {
  1963. State = STATE_ID_END;
  1964. /* Ron Pinkas added 2000-06-02 */
  1965. bMacro = FALSE;
  1966. /* Ron Pinkas end 2000-06-02 */
  1967. }
  1968. break;
  1969. }
  1970. case STATE_EXPRES:
  1971. case STATE_EXPRES_ID:
  1972. {
  1973. if( **ptri == '[' )
  1974. {
  1975. StBr2++;
  1976. State = STATE_BRACKET;
  1977. }
  1978. else if( ISNAME(**ptri) )
  1979. {
  1980. State = STATE_EXPRES_ID;
  1981. }
  1982. else if( **ptri == ' ' )
  1983. {
  1984. if( State == STATE_EXPRES_ID )
  1985. {
  1986. State = STATE_ID_END;
  1987. }
  1988. els