diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 912952ca87..1082d22ec1 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,14 @@ +19990914-13:15 GMT+1 Victor Szel + * source/compiler/harbour.y + source/compiler/gen*.c + + Help screen made more Clipper like. + + /f switch changed to /gf, and the whole object generation build + in to the source in a more standard way. It works now. + + /q0 switch added to the help screen. + + All filename composing stuff related to specific output types moved to + the appropriate gen*.c file. This way the code is more modular. + ! One variable made static in genobj32.c + 19990914-11:40 GMT+1 Victor Szel * source/runner/stdalone/external.prg include/external.ch diff --git a/harbour/source/compiler/genc.c b/harbour/source/compiler/genc.c index 6edfece838..e57b80ce83 100644 --- a/harbour/source/compiler/genc.c +++ b/harbour/source/compiler/genc.c @@ -38,8 +38,9 @@ #include "pcode.h" #include "hberrors.h" -void GenCCode( char * szFileName, char * szName ) /* generates the C language output */ +void GenCCode( PHB_FNAME pFileName ) /* generates the C language output */ { + char szFileName[ _POSIX_PATH_MAX ]; PFUNCTION pFunc = functions.pFirst, pFTemp; PCOMSYMBOL pSym = symbols.pFirst; WORD w, wLen, wSym, wVar; @@ -50,7 +51,9 @@ void GenCCode( char * szFileName, char * szName ) /* generates the C langu FILE * yyc; /* file handle for C output */ - HB_SYMBOL_UNUSED( szName ); + if( ! pFileName->szExtension ) + pFileName->szExtension =".c"; + hb_fsFNameMerge( szFileName, pFileName ); yyc = fopen( szFileName, "wb" ); if( ! yyc ) @@ -60,7 +63,7 @@ void GenCCode( char * szFileName, char * szName ) /* generates the C langu } if( ! _bQuiet ) - printf( "\nGenerating C language output to \'%s\'... ", szFileName ); + printf( "\nGenerating C source output to \'%s\'... ", szFileName ); fprintf( yyc, "/* Harbour compiler generated code */\n\n" ); fprintf( yyc, "#include \"hb_vmpub.h\"\n" ); @@ -94,8 +97,8 @@ void GenCCode( char * szFileName, char * szName ) /* generates the C langu /* writes the symbol table */ /* Generate the wrapper that will initialize local symbol table */ - yy_strupr( _pFileName->szName ); - fprintf( yyc, "\n\nHB_INIT_SYMBOLS_BEGIN( hb_vm_SymbolInit_%s%s )\n", _szPrefix, _pFileName->szName ); + yy_strupr( pFileName->szName ); + fprintf( yyc, "\n\nHB_INIT_SYMBOLS_BEGIN( hb_vm_SymbolInit_%s%s )\n", _szPrefix, pFileName->szName ); if( ! _bStartProc ) pSym = pSym->pNext; /* starting procedure is always the first symbol */ @@ -149,8 +152,8 @@ void GenCCode( char * szFileName, char * szName ) /* generates the C langu pSym = pSym->pNext; } - fprintf( yyc, "\nHB_INIT_SYMBOLS_END( hb_vm_SymbolInit_%s%s )\n", _szPrefix, _pFileName->szName ); - fprintf( yyc, "#if ! defined(__GNUC__)\n #pragma startup hb_vm_SymbolInit_%s%s\n#endif\n\n\n", _szPrefix, _pFileName->szName ); + fprintf( yyc, "\nHB_INIT_SYMBOLS_END( hb_vm_SymbolInit_%s%s )\n", _szPrefix, pFileName->szName ); + fprintf( yyc, "#if ! defined(__GNUC__)\n #pragma startup hb_vm_SymbolInit_%s%s\n#endif\n\n\n", _szPrefix, pFileName->szName ); /* Generate functions data */ diff --git a/harbour/source/compiler/genhrb.c b/harbour/source/compiler/genhrb.c index 77ac4898b7..5f9fa48c19 100644 --- a/harbour/source/compiler/genhrb.c +++ b/harbour/source/compiler/genhrb.c @@ -42,8 +42,9 @@ #define SYM_FUNC 1 /* Defined function */ #define SYM_EXTERN 2 /* Previously defined function */ -void GenPortObj( char * szFileName, char * szName ) +void GenPortObj( PHB_FNAME pFileName ) { + char szFileName[ _POSIX_PATH_MAX ]; PFUNCTION pFunc /*= functions.pFirst */; PCOMSYMBOL pSym = symbols.pFirst; WORD w, wLen, wVar; @@ -54,7 +55,9 @@ void GenPortObj( char * szFileName, char * szName ) ULONG ulCodeLength; FILE * yyc; /* file handle for C output */ - HB_SYMBOL_UNUSED( szName ); + if( ! pFileName->szExtension ) + pFileName->szExtension =".hrb"; + hb_fsFNameMerge( szFileName, pFileName ); yyc = fopen( szFileName, "wb" ); if( ! yyc ) @@ -64,7 +67,7 @@ void GenPortObj( char * szFileName, char * szName ) } if( ! _bQuiet ) - printf( "\nGenerating portable object output to \'%s\'... ", szFileName ); + printf( "\nGenerating Harbour Portable Object output to \'%s\'... ", szFileName ); /* writes the symbol table */ diff --git a/harbour/source/compiler/genjava.c b/harbour/source/compiler/genjava.c index 7a974032d1..918a46c66e 100644 --- a/harbour/source/compiler/genjava.c +++ b/harbour/source/compiler/genjava.c @@ -5,7 +5,7 @@ /* Harbour Project source code - Harbour RC Generation. + Harbour Java source Generation. Copyright 1999 Antonio Linares www - http://www.harbour-project.org @@ -38,8 +38,14 @@ #include "pcode.h" #include "hberrors.h" -void GenJava( char * szFileName, char * szName ) +void GenJava( PHB_FNAME pFileName ) { - printf( "\nGenerating Java language output...\n" ); - printf( "%s -> not implemented yet! %s\n", szFileName, szName ); + char szFileName[ _POSIX_PATH_MAX ]; + + if( ! pFileName->szExtension ) + pFileName->szExtension =".java"; + hb_fsFNameMerge( szFileName, pFileName ); + + printf( "\nGenerating Java source output to \'%s\'... ", szFileName ); + printf( "\nNot implemented yet!\n" ); } diff --git a/harbour/source/compiler/genobj32.c b/harbour/source/compiler/genobj32.c index 3168c037b1..37da8c1854 100644 --- a/harbour/source/compiler/genobj32.c +++ b/harbour/source/compiler/genobj32.c @@ -64,20 +64,25 @@ static BYTE prgFunction[] = { 0x68, 0x00, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x 0x00, 0xE8, 0x00, 0x00, 0x00, 0x00, 0x83, 0xC4, 0x08, 0xC3 }; static char * * externNames = 0; -WORD wExternals = 1; /* _hb_vmExecute is always added */ +static WORD wExternals = 1; /* _hb_vmExecute is always added */ -void GenObj32( char * szObjFileName, char * szFileName ) +void GenObj32( PHB_FNAME pFileName ) { + char szFileName[ _POSIX_PATH_MAX ]; FILE * hObjFile; /* file handle for OBJ output */ - if( ! ( hObjFile = fopen( szObjFileName, "wb" ) ) ) + if( ! pFileName->szExtension ) + pFileName->szExtension =".obj"; + hb_fsFNameMerge( szFileName, pFileName ); + + if( ! ( hObjFile = fopen( szFileName, "wb" ) ) ) { GenError( _szCErrors, 'E', ERR_CREATE_OUTPUT, szFileName, NULL ); return; } if( ! _bQuiet ) - printf( "\nGenerating Windows/DOS OBJ 32 bits language output to \'%s\'... ", szObjFileName ); + printf( "\nGenerating Windows/DOS OBJ32 output to \'%s\'... ", szFileName ); CompiledFileName( hObjFile, szFileName ); CompilerVersion( hObjFile, "Harbour" ); diff --git a/harbour/source/compiler/genpas.c b/harbour/source/compiler/genpas.c index 7fef870768..2c893ec05d 100644 --- a/harbour/source/compiler/genpas.c +++ b/harbour/source/compiler/genpas.c @@ -5,7 +5,7 @@ /* Harbour Project source code - Harbour Pascal Generation. + Harbour Pascal source Generation. Copyright 1999 Antonio Linares www - http://www.harbour-project.org @@ -38,8 +38,14 @@ #include "pcode.h" #include "hberrors.h" -void GenPascal( char * szFileName, char * szName ) +void GenPascal( PHB_FNAME pFileName ) { - printf( "\nGenerating Pascal language output...\n" ); - printf( "%s -> not implemented yet! %s\n", szFileName, szName ); + char szFileName[ _POSIX_PATH_MAX ]; + + if( ! pFileName->szExtension ) + pFileName->szExtension =".pas"; + hb_fsFNameMerge( szFileName, pFileName ); + + printf( "\nGenerating Pascal source output to \'%s\'... ", szFileName ); + printf( "\nNot implemented yet!\n" ); } diff --git a/harbour/source/compiler/genrc.c b/harbour/source/compiler/genrc.c index 97cf260810..7114e4c064 100644 --- a/harbour/source/compiler/genrc.c +++ b/harbour/source/compiler/genrc.c @@ -5,7 +5,7 @@ /* Harbour Project source code - Harbour RC Generation. + Harbour Windows resource (.rc) Generation. Copyright 1999 Antonio Linares www - http://www.harbour-project.org @@ -38,8 +38,14 @@ #include "pcode.h" #include "hberrors.h" -void GenRC( char * szFileName, char * szName ) +void GenRC( PHB_FNAME pFileName ) { - printf( "\nGenerating resources output...\n" ); - printf( "%s -> not implemented yet! %s\n", szFileName, szName ); + char szFileName[ _POSIX_PATH_MAX ]; + + if( ! pFileName->szExtension ) + pFileName->szExtension =".rc"; + hb_fsFNameMerge( szFileName, pFileName ); + + printf( "\nGenerating Windows resource output to \'%s\'... ", szFileName ); + printf( "\nNot implemented yet!\n" ); } diff --git a/harbour/source/compiler/harbour.y b/harbour/source/compiler/harbour.y index f5044c527a..9d8ff1c2bc 100644 --- a/harbour/source/compiler/harbour.y +++ b/harbour/source/compiler/harbour.y @@ -253,13 +253,13 @@ void StaticDefEnd( int ); void StaticAssign( void ); /* checks if static variable is initialized with function call */ /* output related functions */ -extern void GenCCode( char *, char * ); /* generates the C language output */ -extern void GenJava( char *, char * ); /* generates the Java language output */ -extern void GenPascal( char *, char * ); /* generates the Pascal language output */ -extern void GenRC( char *, char * ); /* generates the RC language output */ -extern void GenPortObj( char *, char * ); /* generates the portable objects */ +extern void GenCCode( PHB_FNAME ); /* generates the C language output */ +extern void GenJava( PHB_FNAME ); /* generates the Java language output */ +extern void GenPascal( PHB_FNAME ); /* generates the Pascal language output */ +extern void GenRC( PHB_FNAME ); /* generates the RC language output */ +extern void GenPortObj( PHB_FNAME ); /* generates the portable objects */ #ifdef HARBOUR_OBJ_GENERATION -extern void GenObj32( char *, char * ); /* generates OBJ 32 bits */ +extern void GenObj32( PHB_FNAME ); /* generates OBJ 32 bits */ #endif /* argument checking */ @@ -272,6 +272,7 @@ void PrintUsage( char * ); typedef enum { LANG_C, /* C language (by default) */ + LANG_OBJ32, /* DOS/Windows 32 bits */ LANG_JAVA, /* Java */ LANG_PASCAL, /* Pascal */ LANG_RESOURCES, /* Resources */ @@ -459,9 +460,6 @@ WORD _wIfCounter = 0; WORD _wWhileCounter = 0; WORD _wCaseCounter = 0; ULONG _ulMessageFix = 0; /* Position of the message which needs to be changed */ -#ifdef HARBOUR_OBJ_GENERATION -BOOL _bObj32 = FALSE; /* generate OBJ 32 bits */ -#endif int _iStatics = 0; /* number of defined statics variables on the PRG */ PEXTERN pExterns = NULL; PTR_LOOPEXIT pLoops = NULL; @@ -1443,18 +1441,6 @@ int harbour_main( int argc, char * argv[] ) GenError( _szCErrors, 'E', ERR_BADOPTION, &argv[ iArg ][ 0 ], NULL ); break; - -#ifdef HARBOUR_OBJ_GENERATION - case 'f': - case 'F': - { - char * szUpper = yy_strupr( yy_strdup( &argv[ iArg ][ 2 ] ) ); - if( ! strcmp( szUpper, "OBJ32" ) ) - _bObj32 = TRUE; - free( szUpper ); - } - break; -#endif case 'g': case 'G': switch( argv[ iArg ][ 2 ] ) @@ -1464,6 +1450,11 @@ int harbour_main( int argc, char * argv[] ) _iLanguage = LANG_C; break; + case 'f': + case 'F': + _iLanguage = LANG_OBJ32; + break; + case 'j': case 'J': _iLanguage = LANG_JAVA; @@ -1688,11 +1679,7 @@ int harbour_main( int argc, char * argv[] ) } } -#ifdef HARBOUR_OBJ_GENERATION - if( ! _bSyntaxCheckOnly && ! bSkipGen && ! _bObj32 ) -#else if( ! _bSyntaxCheckOnly && ! bSkipGen ) -#endif { if( _pInitFunc ) { @@ -1728,50 +1715,33 @@ int harbour_main( int argc, char * argv[] ) switch( _iLanguage ) { case LANG_C: - if( ! _pFileName->szExtension ) - _pFileName->szExtension =".c"; - hb_fsFNameMerge( szFileName, _pFileName ); - GenCCode( szFileName, _pFileName->szName ); + GenCCode( _pFileName ); + break; + + case LANG_OBJ32: +#ifdef HARBOUR_OBJ_GENERATION + GenObj32( _pFileName ); +#endif break; case LANG_JAVA: - if( ! _pFileName->szExtension ) - _pFileName->szExtension =".java"; - hb_fsFNameMerge( szFileName, _pFileName ); - GenJava( szFileName, _pFileName->szName ); + GenJava( _pFileName ); break; case LANG_PASCAL: - if( ! _pFileName->szExtension ) - _pFileName->szExtension =".pas"; - hb_fsFNameMerge( szFileName, _pFileName ); - GenPascal( szFileName, _pFileName->szName ); + GenPascal( _pFileName ); break; case LANG_RESOURCES: - if( ! _pFileName->szExtension ) - _pFileName->szExtension =".rc"; - hb_fsFNameMerge( szFileName, _pFileName ); - GenRC( szFileName, _pFileName->szName ); + GenRC( _pFileName ); break; case LANG_PORT_OBJ: - if( ! _pFileName->szExtension ) - _pFileName->szExtension =".hrb"; - hb_fsFNameMerge( szFileName, _pFileName ); - GenPortObj( szFileName, _pFileName->szName ); + GenPortObj( _pFileName ); break; } } -#ifdef HARBOUR_OBJ_GENERATION - if( _bObj32 ) - { - if( ! _pFileName->szExtension ) - _pFileName->szExtension = ".obj"; - hb_fsFNameMerge( szFileName, _pFileName ); - GenObj32( szFileName, _pFileName->szName ); - } -#endif + if( _bPPO ) fclose( yyppo ); } @@ -1794,42 +1764,42 @@ int harbour_main( int argc, char * argv[] ) */ void PrintUsage( char * szSelf ) { - printf( "Syntax: %s [options]\n" - "\nOptions: \n" - "\t/a\t\tautomatic memvar declaration\n" - "\t/b\t\tdebug info\n" - "\t/d[=]\t#define \n" - "\t/es[]\tset exit severity\n" + printf( "\nSyntax: %s [options]" + "\n" + "\nOptions: /a automatic memvar declaration" + "\n /b debug info" + "\n /d[=] #define " + "\n /es[] set exit severity" + "\n /g output type generated is (see below)" + "\n /gc output type: C source (.c) (default)" #ifdef HARBOUR_OBJ_GENERATION - "\t/f\t\tgenerated object file\n" - "\t\t\t /fobj32 --> Windows/Dos 32 bits OBJ\n" + "\n /gf output type: Windows/DOS OBJ32 (.obj)" #endif - "\t/g\t\tgenerated output language\n" - "\t\t\t /gc (C default) --> \n" - "\t\t\t /gh (HRB file) --> \n" - "\t\t\t /gj (Java) --> \n" - "\t\t\t /gp (Pascal) --> \n" - "\t\t\t /gr (Resources) --> \n" - "\t/i\tadd #include file search path\n" - "\t/l\t\tsuppress line number information\n" -/* TODO: "\t/m\t\tcompile module only\n" */ - "\t/n\t\tno implicit starting procedure\n" - "\t/o\tobject file drive and/or path\n" - "\t/p\t\tgenerate pre-processed output (.ppo) file\n" - "\t/q\t\tquiet\n" -/* TODO: "\t/r[]\trequest linker to search (or none)\n" */ - "\t/s\t\tsyntax check only\n" -/* TODO: "\t/t\tpath for temp file creation\n" */ -/* TODO: "\t/u[]\tuse command def set in (or none)\n" */ - "\t/v\t\tvariables are assumed M->\n" - "\t/w\t\tenable warnings\n" - "\t/x[]\tset symbol init function name prefix\n" + "\n /gh output type: Harbour Portable Object (.hrb)" + "\n /gj output type: Java source (.java)" + "\n /gp output type: Pascal source (.pas)" + "\n /gr output type: Windows resource (.rc)" + "\n /i add #include file search path" + "\n /l suppress line number information" +/* TODO: "\n /m compile module only" */ + "\n /n no implicit starting procedure" + "\n /o object file drive and/or path" + "\n /p generate pre-processed output (.ppo) file" + "\n /q quiet" + "\n /q0 quiet and don't display program header" +/* TODO: "\n /r[] request linker to search (or none)" */ + "\n /s syntax check only" +/* TODO: "\n /t path for temp file creation" */ +/* TODO: "\n /u[] use command def set in (or none)" */ + "\n /v variables are assumed M->" + "\n /w enable warnings" + "\n /x[] set symbol init function name prefix (for .c only)" #ifdef YYDEBUG - "\t/y\t\ttrace lex & yacc activity\n" + "\n /y trace lex & yacc activity" #endif - "\t/z\t\tsuppress shortcutting (.and. & .or.)\n" - "\t/10\t\trestrict symbol length to 10 characters\n" -/* TODO: "\t @\tcompile list of modules in \n" */ + "\n /z suppress shortcutting (.and. & .or.)" + "\n /10 restrict symbol length to 10 characters" +/* TODO: "\n @ compile list of modules in " */ , szSelf ); }