diff --git a/harbour/ChangeLog b/harbour/ChangeLog index c6f08b8c06..b5d9f287a5 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,12 @@ +19990705-14:10 Alexander Kresin + * source\hbpp\hbpp.c + * source\hbpp\table.c + * source\hbpp\hbppmain.c + * source\hbpp\hbppint.c + * include\hberrors.h + * Implemented genError() for preprocessor + + Added copyright and license information + 19990707-23:10 EDT David G. Holm + harbour.b31 + Separate harbour.exe makefile, so that it is possible to build diff --git a/harbour/include/hberrors.h b/harbour/include/hberrors.h index 5f11d5e3b6..8bc0156d26 100644 --- a/harbour/include/hberrors.h +++ b/harbour/include/hberrors.h @@ -41,6 +41,18 @@ #define WARN_LOGICAL_SUSPECT 10 #define WARN_NUMERIC_SUSPECT 11 +/* + * Errors generated by Harbour preprocessor + */ +#define ERR_CANNOT_OPEN 1 +#define ERR_DIRECTIVE_ELSE 2 +#define ERR_DIRECTIVE_ENDIF 3 +#define ERR_WRONG_NAME 4 +#define ERR_DEFINE_ABSENT 5 +#define ERR_COMMAND_DEFINITION 6 +#define ERR_PATTERN_DEFINITION 7 +#define ERR_RECURSE 8 + void GenError( char* _szErrors[], char, int, char*, char * ); /* generic parsing error management function */ void GenWarning( int, char*, char * ); /* generic parsing warning management function */ diff --git a/harbour/source/hbpp/hbpp.c b/harbour/source/hbpp/hbpp.c index a548cd7df5..c6069d303c 100644 --- a/harbour/source/hbpp/hbpp.c +++ b/harbour/source/hbpp/hbpp.c @@ -1,9 +1,28 @@ /* * $Id$ - */ -/* Harbour Preprocessor , version 0.99 - author - Alexander Kresin */ + Harbour Project source code + + This file contains the main part of preprocessor implementation. + + Copyright 1999 Alexander S.Kresin + 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: + + 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/). + */ #if defined(__GNUC__) #include @@ -20,6 +39,7 @@ #include #include #include "harb.h" +#include "hberrors.h" int Hp_Parse( FILE*, FILE* ); int ParseDirective( char* ); @@ -112,6 +132,17 @@ int kolcommands = 0, maxcommands = INITIAL_ACOM_SIZE; TRANSLATES *aTranslates ; int koltranslates = 0, maxtranslates = 50; +/* Table with parse errors */ +char * _szPErrors[] = { "Can\'t open include file \"%s\"", + "#else does not match #if", + "#endif does not match #if", + "Error in include file name", + "#define without parameters", + "Absent \"=>\" in command definition", + "Error in pattern definition", + "Cycled #define" + }; + int ParseDirective( char* sLine ) { char sDirective[MAX_NAME]; @@ -123,28 +154,33 @@ int ParseDirective( char* sLine ) if ( i == 4 && memcmp ( sDirective, "else", 4 ) == 0 ) { /* --- #else --- */ - if ( nCondCompile == 0 ) return 3001; + if ( nCondCompile == 0 ) + GenError( _szPErrors, 'P', ERR_DIRECTIVE_ELSE, NULL, NULL ); else aCondCompile[nCondCompile-1] = 1 - aCondCompile[nCondCompile-1]; } else if ( i == 5 && memcmp ( sDirective, "endif", 5 ) == 0 ) { /* --- #endif --- */ - if ( nCondCompile == 0 ) return 3001; else nCondCompile--; + if ( nCondCompile == 0 ) + GenError( _szPErrors, 'P', ERR_DIRECTIVE_ENDIF, NULL, NULL ); + else nCondCompile--; } else if ( nCondCompile==0 || aCondCompile[nCondCompile-1]) { if ( i == 7 && memcmp ( sDirective, "include", 7 ) == 0 ) { /* --- #include --- */ - if ( *sLine != '\"' ) return 1000; + if ( *sLine != '\"' ) + GenError( _szPErrors, 'P', ERR_WRONG_NAME, NULL, NULL ); sLine++; i = 0; while ( *(sLine+i) != '\0' && *(sLine+i) != '\"' ) i++; - if ( *(sLine+i) != '\"' ) return 1000; + if ( *(sLine+i) != '\"' ) + GenError( _szPErrors, 'P', ERR_WRONG_NAME, NULL, NULL ); *(sLine+i) = '\0'; /* if ((handl_i = fopen(sLine, "r")) == NULL) */ if ( !OpenInclude( sLine, _pIncludePath, &handl_i ) ) - { printf("\nCan't open %s\n",sLine); return 1001; } + GenError( _szPErrors, 'P', ERR_CANNOT_OPEN, sLine, NULL ); lInclude++; Hp_Parse(handl_i, 0 ); lInclude--; @@ -270,7 +306,8 @@ int ParseIfdef( char* sLine, int usl) DEFINES *stdef; NextWord( &sLine, defname, FALSE ); - if ( *defname == '\0' ) return 3000; + if ( *defname == '\0' ) + GenError( _szPErrors, 'P', ERR_DEFINE_ABSENT, NULL, NULL ); if ( nCondCompile == maxCondCompile ) { maxCondCompile += 5; @@ -357,7 +394,7 @@ int ParseCommand( char* sLine, int com_or_xcom, int com_or_tra ) if ( (ipos = hb_strAt( "=>", 2, sLine, strolen(sLine) )) > 0 ) stroncpy( mpatt, sLine, ipos-1 ); - else return 4000; /* Quit, if '=>' absent */ + else GenError( _szPErrors, 'P', ERR_COMMAND_DEFINITION, NULL, NULL ); mlen = strotrim( mpatt ); sLine += ipos + 1; @@ -412,9 +449,15 @@ int ConvertPatterns ( char *mpatt, int mlen, char *rpatt, int rlen ) *(exppatt+explen++) = *(mpatt+i++); } if ( exptype == '3' ) - { if ( *(exppatt+explen-1) == '*' ) explen--; else return 4001; } + { + if ( *(exppatt+explen-1) == '*' ) explen--; + else GenError( _szPErrors, 'P', ERR_PATTERN_DEFINITION, NULL, NULL ); + } else if ( exptype == '4' ) - { if ( *(exppatt+explen-1) == ')' ) explen--; else return 4001; } + { + if ( *(exppatt+explen-1) == ')' ) explen--; + else GenError( _szPErrors, 'P', ERR_PATTERN_DEFINITION, NULL, NULL ); + } rmlen = i - ipos + 1; /* Replace match marker with new marker */ lastchar = (char) ( (unsigned int)lastchar + 1 ); @@ -500,7 +543,10 @@ int ParseExpression( char* sLine, char* sOutLine ) if ( (stdef=DefSearch(sToken)) != NULL ) { for(i=0;i + 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: + + 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/). */ #if defined(__GNUC__) diff --git a/harbour/source/hbpp/hbppmain.c b/harbour/source/hbpp/hbppmain.c index 9cdf200a93..2e377f40c3 100644 --- a/harbour/source/hbpp/hbppmain.c +++ b/harbour/source/hbpp/hbppmain.c @@ -1,5 +1,28 @@ /* * $Id$ + + Harbour Project source code + + This file contains some functions of preprocessor, which need for + standalone version ( including main() function ). + + Copyright 1999 Alexander S.Kresin + 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: + + 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/). */ #if defined(__DJGPP__) || defined(__GNUC__) @@ -371,3 +394,13 @@ void _xfree( void * pMem ) /* frees fixed memory */ if( pMem ) free( pMem ); } + +void GenError( char* _szErrors[], char cPrefix, int iError, char * szError1, char * szError2 ) +{ + char * szLine = ( char * ) OurMalloc( 160 ); /*2 lines of text */ + /* printf( "\r%s(%i) ", files.pLast->szFileName, iLine ); */ + printf( "Error %c%i ", cPrefix, iError ); + sprintf( szLine, _szErrors[ iError - 1 ], szError1, szError2 ); + printf( "%s\n\n", szLine ); + exit( 1 ); +} \ No newline at end of file diff --git a/harbour/source/hbpp/table.c b/harbour/source/hbpp/table.c index 5ea3f64047..c617121451 100644 --- a/harbour/source/hbpp/table.c +++ b/harbour/source/hbpp/table.c @@ -1,5 +1,28 @@ /* * $Id$ + + Harbour Project source code + + This file contains the tables of predefined #define and #command + statements of preprocessor. + + Copyright 1999 Alexander S.Kresin + 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: + + 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