From 660be190e71f23e96d7e05ef3755fe7d65a37017 Mon Sep 17 00:00:00 2001 From: "David G. Holm" Date: Tue, 15 Jun 1999 17:36:20 +0000 Subject: [PATCH] See ChangeLog entry 19990615-12:30 EDT David G. Holm --- harbour/ChangeLog | 19 ++++ harbour/source/compiler/makefile.dos | 4 +- harbour/source/hbpp/hbpp.c | 2 + harbour/source/rtl/console.c | 128 +++++++++++++++++++-------- harbour/source/rtl/files.c | 3 +- harbour/source/rtl/set.c | 40 +++++++-- harbour/source/rtl/strcmp.c | 23 ++--- harbour/tests/working/output.prg | 25 +++--- 8 files changed, 168 insertions(+), 76 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 313b61c605..07a2cb4ccf 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,22 @@ +19990615-12:30 EDT David G. Holm + * source/compiler/makefile.dos + - Integrated preprocessor into compiler + * source\hbpp\hbpp.c + - Added braces to avoid implicit else in ParseExpression() + * source/rtl/console.c + - Added HARBOUR HB_SETPOS() + - Improved printer position tracking + - Improved screen position tracking when not using GT API + * source/rtl/files.c + - convert_create_flags no longer returns a value, so declare as void + * source/rtl/set.c + - Logical SET values can now use "ON" for .T. and "OFF" for .F. + * source/rtl/strcmp.c + - hb_stricmp does a case-insensitive compare even when not using a + library function. + * tests/working/output.prg + - Converted to use the preprocessor + 19990615-10:38 Alexander Kresin removed: - source\hbpp\harb.c diff --git a/harbour/source/compiler/makefile.dos b/harbour/source/compiler/makefile.dos index c70b5bc1b7..5213f5226f 100644 --- a/harbour/source/compiler/makefile.dos +++ b/harbour/source/compiler/makefile.dos @@ -9,8 +9,8 @@ TARGET=$(HARBOURDIR)/bin/harbour.exe all: $(TARGET) -$(TARGET): harboury.c harbour.c harbourl.c - $(CC) $(CFLAGS) harboury.c harbour.c harbourl.c -o $(TARGET) +$(TARGET): harboury.c harbour.c harbourl.c $(HARBOURDIR)/include/compiler.h $(HARBOURDIR)/source/hbpp/hbppint.c $(HARBOURDIR)/source/hbpp/hbpp.c $(HARBOURDIR)/source/hbpp/table.c + $(CC) $(CFLAGS) harboury.c harbour.c harbourl.c $(HARBOURDIR)/source/hbpp/hbppint.c $(HARBOURDIR)/source/hbpp/hbpp.c $(HARBOURDIR)/source/hbpp/table.c -o $(TARGET) harboury.c : harbour.y bison -d -v -y harbour.y -o harboury.c diff --git a/harbour/source/hbpp/hbpp.c b/harbour/source/hbpp/hbpp.c index 8f62a1c897..87f320abb5 100644 --- a/harbour/source/hbpp/hbpp.c +++ b/harbour/source/hbpp/hbpp.c @@ -535,6 +535,7 @@ int ParseExpression( char* sLine, char* sOutLine ) i = WorkCommand( sToken, ptri, ptro, ndef ); if ( ipos > 0 ) *(sLine+isdvig+ipos-1) = ';'; if ( i >= 0 ) + { if ( isdvig + ipos > 0 ) { lens = strolen( sLine+isdvig ); @@ -543,6 +544,7 @@ int ParseExpression( char* sLine, char* sOutLine ) } else memcpy ( sLine, sOutLine, i+1); + } rezCom = 1; } else if ( ipos > 0 ) *(sLine+isdvig+ipos-1) = ';'; diff --git a/harbour/source/rtl/console.c b/harbour/source/rtl/console.c index df38835fbd..55d1810ac8 100644 --- a/harbour/source/rtl/console.c +++ b/harbour/source/rtl/console.c @@ -21,7 +21,7 @@ HARBOUR HB___ACCEPT(void); HARBOUR HB_DEVOUT( void ); HARBOUR HB_DEVPOS( void ); -HARBOUR HB_EJECT( void ); +HARBOUR HB___EJECT( void ); HARBOUR HB_MAXCOL( void ); HARBOUR HB_MAXROW( void ); HARBOUR HB_OUTSTD( void ); @@ -29,6 +29,7 @@ HARBOUR HB_OUTERR( void ); HARBOUR HB_PCOL( void ); HARBOUR HB_PROW( void ); HARBOUR HB_SCROLL( void ); +HARBOUR HB_SETPOS( void ); HARBOUR HB_SETPRC( void ); HARBOUR HB_QOUT( void ); HARBOUR HB_QQOUT( void ); @@ -37,7 +38,7 @@ static SYMBOL symbols[] = { { "__ACCEPT", FS_PUBLIC, HB___ACCEPT, 0 }, { "DEVOUT" , FS_PUBLIC, HB_DEVOUT , 0 }, { "DEVPOS" , FS_PUBLIC, HB_DEVPOS , 0 }, -{ "EJECT" , FS_PUBLIC, HB_EJECT , 0 }, +{ "EJECT" , FS_PUBLIC, HB___EJECT , 0 }, { "MAXCOL" , FS_PUBLIC, HB_MAXCOL , 0 }, { "MAXROW" , FS_PUBLIC, HB_MAXROW , 0 }, { "OUTERR" , FS_PUBLIC, HB_OUTERR , 0 }, @@ -45,6 +46,7 @@ static SYMBOL symbols[] = { { "PCOL" , FS_PUBLIC, HB_PCOL , 0 }, { "PROW" , FS_PUBLIC, HB_PROW , 0 }, { "SCROLL" , FS_PUBLIC, HB_SCROLL , 0 }, +{ "SETPOS" , FS_PUBLIC, HB_SETPOS , 0 }, { "SETPRC" , FS_PUBLIC, HB_SETPRC , 0 }, { "QOUT" , FS_PUBLIC, HB_QOUT , 0 }, { "QQOUT" , FS_PUBLIC, HB_QQOUT , 0 } @@ -74,7 +76,7 @@ void InitializeConsole( void ) p_row = p_col = 0; } -USHORT hb_maxrow( void ) +USHORT hb_max_row( void ) { #ifdef USE_GTAPI return _gtMaxRow (); @@ -83,7 +85,7 @@ USHORT hb_maxrow( void ) #endif } -USHORT hb_maxcol( void ) +USHORT hb_max_col( void ) { #ifdef USE_GTAPI return _gtMaxCol (); @@ -92,6 +94,42 @@ USHORT hb_maxcol( void ) #endif } +#ifndef USE_GTAPI +void adjust_pos( char * fpStr, WORD uiLen, USHORT * row, USHORT * col, USHORT max_row, USHORT max_col ) +{ + WORD uiCount; + for( uiCount = 0; uiCount < uiLen; uiCount++ ) + { + switch( fpStr[ uiCount ] ) + { + case 7: + break; + case 8: + if( *col ) (*col)--; + else + { + *col = max_col; + if( *row ) (*row)--; + } + break; + case 10: + if( *row < max_row ) (*row)++; + break; + case 13: + *col = 0; + break; + default: + if( *col < max_col ) (*col)++; + else + { + *col = 0; + if( *row < max_row ) (*row)++; + } + } + } +} +#endif + HARBOUR HB___ACCEPT( void ) /* Internal Clipper function used in ACCEPT command */ /* Basically the simplest Clipper function to */ /* receive data. Parameter : cPrompt. Returns : cRet */ @@ -176,6 +214,8 @@ static void hb_outstd( char * fpStr, WORD uiLen ) dev_col = gtWhereX(); _gtSetPos( dev_row, dev_col ); } +#else + adjust_pos( fpStr, uiLen, &dev_row, &dev_col, hb_max_row(), hb_max_col() ); #endif } @@ -194,6 +234,8 @@ static void hb_outerr( char * fpStr, WORD uiLen ) dev_col = gtWhereX(); _gtSetPos( dev_row, dev_col ); } +#else + adjust_pos( fpStr, uiLen, &dev_row, &dev_col, hb_max_row(), hb_max_col() ); #endif } @@ -210,20 +252,20 @@ static void hb_altout( char * fpStr, WORD uiLen ) WORD uiCount; for( uiCount = 0; uiCount < uiLen; uiCount++ ) printf( "%c", fpStr[ uiCount ] ); - dev_col += uiLen; - if( dev_col > hb_maxcol() ) - { - dev_row += (uiLen / (hb_maxcol() + 1)); - dev_col -= (uiLen % (hb_maxcol() + 1)); - } + adjust_pos( fpStr, uiLen, &dev_row, &dev_col, hb_max_row(), hb_max_col() ); #endif } if( hb_set.HB_SET_ALTERNATE && hb_set_althan >= 0 ) + { /* Print to alternate file if SET ALTERNATE ON and valid alternate file */ write( hb_set_althan, fpStr, uiLen ); + } if( hb_set.HB_SET_PRINTER && hb_set_printhan >= 0 ) + { /* Print to printer if SET PRINTER ON and valid printer file */ write( hb_set_printhan, fpStr, uiLen ); + adjust_pos( fpStr, uiLen, &p_row, &p_col, -1, -1 ); + } } /* Output an item to the screen and/or printer */ @@ -233,7 +275,7 @@ static void hb_devout( char * fpStr, WORD uiLen ) { /* Display to printer if SET DEVICE TO PRINTER and valid printer file */ write( hb_set_printhan, fpStr, uiLen ); - p_col += uiLen; + adjust_pos( fpStr, uiLen, &p_row, &p_col, -1, -1 ); } else { @@ -245,19 +287,28 @@ static void hb_devout( char * fpStr, WORD uiLen ) WORD uiCount; for( uiCount = 0; uiCount < uiLen; uiCount++ ) printf( "%c", fpStr[ uiCount ] ); - dev_col += uiLen; - if( dev_col > hb_maxcol() ) - { - dev_row += (uiLen / (hb_maxcol() + 1)); - dev_col -= (uiLen % (hb_maxcol() + 1)); - } + adjust_pos( fpStr, uiLen, &dev_row, &dev_col, hb_max_row(), hb_max_col() ); #endif } } +void hb_setpos( USHORT row, USHORT col ) +{ + USHORT count; + #ifdef USE_GTAPI + _gtSetPos( row, col ); + #else + for( count = dev_row; count < row; count++ ) printf("\n"); + if( row > dev_row ) dev_col = 0; + for( count = dev_col; count < col; count++ ) printf(" "); + #endif + dev_row = row; + dev_col = col; +} + void hb_devpos( USHORT row, USHORT col ) { - int count; + USHORT count; /* Position printer if SET DEVICE TO PRINTER and valid printer file otherwise position console */ if( hb_stricmp( hb_set.HB_SET_DEVICE, "PRINTER" ) == 0 && hb_set_printhan >= 0 ) @@ -273,18 +324,7 @@ void hb_devpos( USHORT row, USHORT col ) p_row = row; p_col = col; } - else - { - #ifdef USE_GTAPI - _gtSetPos( row, col ); - #else - for( count = dev_row; count < row; count++ ) printf("\n"); - if( row > dev_row ) dev_col = 0; - for( count = dev_col; count < col; count++ ) printf(" "); - #endif - dev_row = row; - dev_col = col; - } + else hb_setpos( row, col ); } HARBOUR HB_OUTSTD( void ) /* writes a list of values to the standard output device */ @@ -330,6 +370,18 @@ HARBOUR HB_QOUT( void ) #endif } +HARBOUR HB_SETPOS( void ) /* Sets the screen position */ +{ + PHB_ITEM pRow, pCol; + if( _pcount() > 1 ) + { + pRow = _param( 1, IT_NUMERIC ); + pCol = _param( 2, IT_NUMERIC ); + if( pRow && pCol ) + hb_setpos( _parni( 1 ), _parni( 2 ) ); + } +} + HARBOUR HB_DEVPOS( void ) /* Sets the screen and/or printer position */ { PHB_ITEM pRow, pCol; @@ -366,11 +418,11 @@ HARBOUR HB_DEVOUT( void ) /* writes a single values to the current device (scree } } -HARBOUR HB_EJECT( void ) /* Ejects the current page from the printer */ +HARBOUR HB___EJECT( void ) /* Ejects the current page from the printer */ { if( hb_stricmp( hb_set.HB_SET_DEVICE, "PRINTER" ) == 0 && hb_set_printhan >= 0 ) { - write( hb_set_printhan, "\x0C", 1 ); + write( hb_set_printhan, "\x0C\x0D", 2 ); p_row = p_col = 0; } } @@ -401,7 +453,7 @@ HARBOUR HB_SETPRC( void ) /* Sets the current printer row and column positions * HARBOUR HB_SCROLL( void ) /* Scrolls a screen region (requires the GT API) */ { - int top = 0, left = 0, bottom = hb_maxrow(), right = hb_maxcol(), + int top = 0, left = 0, bottom = hb_max_row(), right = hb_max_col(), v_scroll = 0, h_scroll = 0; if( _pcount() > 0 && _param( 1, IT_NUMERIC ) ) @@ -420,12 +472,12 @@ HARBOUR HB_SCROLL( void ) /* Scrolls a screen region (requires the GT API) */ #ifdef USE_GTAPI _gtScroll( top, left, bottom, right, v_scroll, h_scroll ); #else - if( top == 0 && bottom == hb_maxrow() - && left == 0 && right == hb_maxcol() + if( top == 0 && bottom == hb_max_row() + && left == 0 && right == hb_max_col() && v_scroll == 0 && h_scroll == 0 ) { int count; - dev_row = hb_maxrow(); + dev_row = hb_max_row(); for( count = 0; count < dev_row ; count++ ) printf( "\n" ); dev_row = dev_col = 0; } @@ -434,12 +486,12 @@ HARBOUR HB_SCROLL( void ) /* Scrolls a screen region (requires the GT API) */ HARBOUR HB_MAXROW( void ) /* Return the maximum screen row number (zero origin) */ { - _retni( hb_maxrow () ); + _retni( hb_max_row () ); } HARBOUR HB_MAXCOL( void ) /* Return the maximum screen column number (zero origin) */ { - _retni( hb_maxcol () ); + _retni( hb_max_col () ); } HARBOUR HB_ROW( void ) /* Return the current screen row position (zero origin) */ diff --git a/harbour/source/rtl/files.c b/harbour/source/rtl/files.c index bfeb4a5f1c..6e9c28d1a3 100644 --- a/harbour/source/rtl/files.c +++ b/harbour/source/rtl/files.c @@ -213,7 +213,7 @@ static int convert_seek_flags( int flags ) return result_flags; } -static convert_create_flags( int flags, int *result_flags, int *result_pmode ) +static void convert_create_flags( int flags, int *result_flags, int *result_pmode ) { /* by default FC_NORMAL is set */ @@ -228,7 +228,6 @@ static convert_create_flags( int flags, int *result_flags, int *result_pmode ) if( flags & FC_SYSTEM ) *result_flags |= 0; - } #endif diff --git a/harbour/source/rtl/set.c b/harbour/source/rtl/set.c index cea879bdc1..b408128031 100644 --- a/harbour/source/rtl/set.c +++ b/harbour/source/rtl/set.c @@ -2,7 +2,7 @@ * $Id$ */ -#if defined(__GNUC__) || defined(__DJGPP__) +#if defined(__GNUC__) #include #endif @@ -42,9 +42,24 @@ void Set__InitSymbols( void ) static BOOL set_logical (PHB_ITEM pItem) { - BOOL logical; + BOOL logical = FALSE; if (IS_LOGICAL (pItem)) logical = pItem->value.iLogical; - else logical = FALSE; + else if (IS_STRING (pItem)) + { + if (pItem->wLength == 2) + { + if (toupper (pItem->value.szText [0]) == 'O' + && toupper (pItem->value.szText [1]) == 'N') + logical = TRUE; + } + else if (pItem->wLength == 3) + { + if (toupper (pItem->value.szText [0]) == 'O' + && toupper (pItem->value.szText [1]) == 'F' + && toupper (pItem->value.szText [2]) == 'F') + logical = FALSE; + } + } return (logical); } @@ -228,12 +243,19 @@ HARBOUR HB_SETFIXED (void) if ( pItem && IS_LOGICAL (pItem)) hb_set_fixed = pItem->value.iLogical; else if ( pItem && IS_STRING (pItem)) { - if (pItem->wLength == 2 && toupper (pItem->value.szText [0]) == 'O' - && toupper (pItem->value.szText [1]) == 'N') - hb_set_fixed = TRUE; - else if (pItem->wLength == 3 && toupper (pItem->value.szText [0]) == 'O' - && toupper (pItem->value.szText [1]) == 'F' && toupper (pItem->value.szText [2]) == 'F') - hb_set_fixed = FALSE; + if (pItem->wLength == 2) + { + if (toupper (pItem->value.szText [0]) == 'O' + && toupper (pItem->value.szText [1]) == 'N') + hb_set_fixed = TRUE; + } + else if (pItem->wLength == 3) + { + if (toupper (pItem->value.szText [0]) == 'O' + && toupper (pItem->value.szText [1]) == 'F' + && toupper (pItem->value.szText [2]) == 'F') + hb_set_fixed = FALSE; + } } } diff --git a/harbour/source/rtl/strcmp.c b/harbour/source/rtl/strcmp.c index 1f59a56f7b..c7d7b9e213 100644 --- a/harbour/source/rtl/strcmp.c +++ b/harbour/source/rtl/strcmp.c @@ -2,6 +2,7 @@ * $Id$ */ +#include #include #include @@ -13,22 +14,22 @@ int hb_stricmp( const char *s1, const char *s2 ) #ifdef strcasecmp return( strcasecmp( s1, s2 ) ); #else - int rc = 0; - USHORT c1, c2, count; - c1 = strlen( s1 ); - c2 = strlen( s2 ); - if( c1 < c2 ) count = c1; - else count = c2; + int rc = 0, c1, c2; + USHORT l1, l2, count; + l1 = strlen( s1 ); + l2 = strlen( s2 ); + if( l1 < l2 ) count = l1; + else count = l2; while( rc == 0 && count > 0 ) { - if( *s1 != *s2 ) rc = ( *s1 < *s2 ? -1 : 1 ); - s1++; - s2++; count--; + c1 = toupper( *s1++ ); + c2 = toupper( *s2++ ); + if( c1 != c2 ) rc = ( c1 < c2 ? -1 : 1 ); } - if( rc == 0 && c1 != c2 ) + if( rc == 0 && l1 != l2 ) { - if( c1 < c2 ) rc = -1; + if( l1 < l2 ) rc = -1; else rc = 1; } return rc; diff --git a/harbour/tests/working/output.prg b/harbour/tests/working/output.prg index 0612b741a5..9b8b70e341 100644 --- a/harbour/tests/working/output.prg +++ b/harbour/tests/working/output.prg @@ -1,4 +1,4 @@ -// Testing Harbour dates management. +// Testing Harbour device management. #include "set.ch" #define cNewLine CHR( 13 ) + CHR( 10 ) @@ -6,22 +6,19 @@ function Main() OUTSTD (cNewLine, "Testing Harbour device management on", DATE()) - SET (_SET_ALTFILE, "output", .T.) - SET (_SET_PRINTFILE, "output", .T.) + SET ALTERNATE TO OUTPUT ADDITIVE + SET PRINTER TO OUTPUT ADDITIVE QOUT ("SCREEN, NOT ALTERNATE, NOT PRINTER") - DEVPOS (5, 5) - DEVOUT ("SCREEN, NOT ALTERNATE NOT PRINTER") - SET (_SET_ALTERNATE, .T.) - SET (_SET_PRINTER, .T.) + @ 5,5 SAY "SCREEN, NOT ALTERNATE NOT PRINTER" + SET ALTERNATE ON + SET PRINTER ON QOUT ("SCREEN, ALTERNATE AND PRINTER") - DEVPOS (10, 10) - DEVOUT ("SCREEN, NOT ALTERNATE, NOT PRINTER") - SET (_SET_DEVICE, "PRINTER") + @ 10,10 SAY "SCREEN, NOT ALTERNATE, NOT PRINTER" + SET DEVICE TO PRINTER QOUT ("SCREEN, ALTERNATE AND PRINTER AGAIN") - SET (_SET_PRINTER, .F.) + SET PRINTER OFF QOUT ("SCREEN AND ALTERNATE, BUT NOT PRINTER") - DEVPOS (15, 15) - DEVOUT ("PRINTER, NOT SCREEN, NOT ALTERNATE") - EJECT() + @ 15,15 SAY "PRINTER, NOT SCREEN, NOT ALTERNATE" + EJECT return nil