From 5d680b91c5331b1539ac5bdeda6094101c0076b6 Mon Sep 17 00:00:00 2001 From: "David G. Holm" Date: Thu, 27 May 1999 19:23:12 +0000 Subject: [PATCH] See ChangeLog entry 19990527-14:15 EST David G. Holm --- harbour/ChangeLog | 54 ++++++++++++++++++++++ harbour/include/ctoharb.h | 2 +- harbour/include/gtapi.h | 6 +++ harbour/makefile.b31 | 9 +++- harbour/source/rtl/console.c | 85 ++++++++++++++++++----------------- harbour/source/rtl/files.c | 19 ++++++-- harbour/source/rtl/gt/gtdos.c | 58 +++++++++++++++++++++--- harbour/source/rtl/gt/gtos2.c | 28 +++++++++--- harbour/source/rtl/gt/gtwin.c | 33 ++++++++++---- harbour/source/rtl/gt/gtxxx.c | 12 +++++ harbour/source/rtl/gtapi.c | 48 ++++++++++++++++++-- harbour/source/rtl/set.c | 12 ++++- harbour/source/rtl/transfrm.c | 5 ++- harbour/source/vm/hvm.c | 6 ++- 14 files changed, 301 insertions(+), 76 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 6f4b0c0850..3f0ceee1e6 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,57 @@ +19990527-14:15 EST David G. Holm + * makefile.b31 + - Added gtdos to terminal library + * include/ctoharb.h + - Added word wDec parameter to PushDouble prototype (needed by C++ compilers) + * include/gtapi.h + - Added $Id$ block at top + - Added gtWhereX() + - Added gtWhereY() + * source/rtl/console.c + - Added GT API support + - Added InitializeConsole() to initialize GT API and device screen position + - Added HARBOUR PROW(), PCOL(), and SETPRC() + - Synchronize dev_row and dev_col with GT API screen position + * source/rtl/files.c + - Borland support now takes into account that older compiler versions + don't have the POSIX S_ flags. + * source/rtl/gtapi.c + - Added $Id$ block at top + - Changed #include to #include + - Modified _gtWriteCon() to process control characters + * source/rtl/set.c + - Added default of "PRN" for HB_SET_PRINTFILE + - If SET (_SET_DEVCE, "PRINTER") and printer file not open, then open it + * source/rtl/transfrm.c + - Added use of wDec parameter in calls to PushDouble() + * source/rtl/gt/gtdos.c + - Added $Id$ block at top + - Added gtWhereX() + - Added gtWhereY() + - Removed screen coordinate adjustments (i.e., - 1), because + Clipper (and therefore Harbour) screen origin is (0,0) + * source/rtl/gt/gtos2.c + - Added $Id$ block at top + - Added gtWhereX() + - Added gtWhereY() + - Removed screen coordinate adjustments (i.e., - 1), because + Clipper (and therefore Harbour) screen origin is (0,0) + - Note: Still needs some work - doesn't match output from gtdos.c + * source/rtl/gt/gtwin.c + - Added $Id$ block at top + - Added gtWhereX() + - Added gtWhereY() + - Removed screen coordinate adjustments (i.e., - 1), because + Clipper (and therefore Harbour) screen origin is (0,0) + - Note: Needs to be tested, because I don't have a Windows compiler + * source/rtl/gt/gtxxx.c + - Added $Id$ block at top + - Added gtWhereX() + - Added gtWhereY() + * source/vm/hvm.c + - Added call to InitializeConsole() + - Added prototypes for InitializeConsole() and InitSymbolTable() for C++ compilers + 19990527-19:50 CET Eddie Runia * source/rtl/gt/gtdos.c, source/rtl/gt/gtwin.c, source/rtl/gtapi.c minor changes diff --git a/harbour/include/ctoharb.h b/harbour/include/ctoharb.h index 41cc49774e..ef18775b2f 100644 --- a/harbour/include/ctoharb.h +++ b/harbour/include/ctoharb.h @@ -11,7 +11,7 @@ void PushNil( void ); /* in this case it places nil at self */ /* parameters should come here using Push...() */ void PushInteger( int iNumber ); void PushLong( long lNumber ); -void PushDouble( double dNumber ); +void PushDouble( double dNumber, WORD wDec ); void PushString( char * szText, WORD wLength ); /* pushes a string on to the stack */ void Do( WORD wParams ); /* invokes the virtual machine */ void Function( WORD wParams ); /* invokes the virtual machine */ diff --git a/harbour/include/gtapi.h b/harbour/include/gtapi.h index 85020653e9..622ec5e74b 100644 --- a/harbour/include/gtapi.h +++ b/harbour/include/gtapi.h @@ -1,3 +1,7 @@ +/* + * $Id$ + */ + /* * GTAPI.H; Screen drawing, cursor and keyboard routines for text mode * 16-bit and 32-bit MS-DOS, 16-bit and 32-bit OS/2, and 32-bit @@ -126,6 +130,8 @@ void gtDone(void); char gtGetScreenWidth(void); char gtGetScreenHeight(void); void gtGotoXY(char x, char y); +char gtWhereX(void); +char gtWhereY(void); void gtSetCursorStyle(int style); int gtGetCursorStyle(void); void gtPuts(char x, char y, char attr, char *str, int len); diff --git a/harbour/makefile.b31 b/harbour/makefile.b31 index 1e58427021..3f80902dca 100644 --- a/harbour/makefile.b31 +++ b/harbour/makefile.b31 @@ -24,7 +24,7 @@ harbour.lib : arrays.obj asort.obj classes.obj codebloc.obj dates.obj \ hbtools.lib : datesx.obj debug.obj genobj.obj io.obj mathx.obj \ stringp.obj stringsx.obj -terminal.lib : console.obj +terminal.lib : console.obj gtdos.obj libs\win16\terminal.lib : console.obj @@ -49,7 +49,8 @@ errorsys.obj : errorsys.prg extend.h types.h init.h harbour.exe extend.obj : extend.c extend.h types.h files.obj : extend.c extend.h types.h genobj.obj : source\tools\genobj.c extend.h types.h -gtapi.obj : gtapi.c extend.h types.h +gtapi.obj : gtapi.c extend.h types.h gtapi.h +gtdos.obj : source\rtl\gt\gtdos.c extend.h types.h gtapi.h io.obj : source\tools\io.c extend.h types.h initsymb.obj : source\vm\initsymb.c extend.h types.h itemapi.obj : itemapi.c extend.h types.h @@ -83,6 +84,10 @@ transfrm.obj : transfrm.c extend.h types.h bcc -c $(c_opt) -o$@ $< tlib .\libs\b16\hbtools.lib -+$@,, +{source\rtl\gt}.c{obj}.obj: + bcc -c $(c_opt) -o$@ $< + tlib .\libs\b16\terminal.lib -+$@,, + {source\compiler}.c{obj}.obj: bcc -c $(c_opt) -Isource\compiler -o$@ $< diff --git a/harbour/source/rtl/console.c b/harbour/source/rtl/console.c index 04223ee474..5c71669a7b 100644 --- a/harbour/source/rtl/console.c +++ b/harbour/source/rtl/console.c @@ -4,17 +4,6 @@ #ifdef WINDOWS #include -#else - /* TODO: Remove once the GT API works */ - #if defined(__BORLANDC__) || defined(__TURBOC__) - #include - #define console_printf cprintf - #define console_gotoxy gotoxy - #endif - #if defined(__MSC__) || defined(__MSVC__) - #include - #define console_printf _cprintf - #endif #endif #include @@ -24,7 +13,15 @@ #include #include -static int dev_row = 0, dev_col = 0; +static unsigned short dev_row = 0; +static unsigned short dev_col = 0; + +void InitializeConsole( void ) +{ + dev_row = gtWhereX(); + dev_col = gtWhereY(); + _gtSetPos( dev_row, dev_col ); +} HARBOUR __ACCEPT( void ) /* Internal Clipper function used in ACCEPT command */ /* Basically the simplest Clipper function to */ @@ -116,17 +113,12 @@ static void hb_outerr( char * fpStr, WORD uiLen ) /* Output an item to the screen and/or printer and/or alternate */ static void hb_altout( char * fpStr, WORD uiLen ) { - WORD uiCount = uiLen; - char * fpPtr = fpStr; /* TODO: delete fpPtr once the GT API works */ if( hb_set.HB_SET_CONSOLE ) - /* TODO: Replace with _gtWriteCon( fpStr, uiLen ) once the GT API works */ - while( uiCount-- ) - /* Display to console unless SET CONSOLE OFF */ - #ifdef console_printf - console_printf( "%c", *fpPtr++ ); - #else - printf( "%c", *fpPtr++ ); - #endif + { + _gtWriteCon( fpStr, uiLen ); + if( stricmp( hb_set.HB_SET_DEVICE, "PRINTER" ) || hb_set_printhan < 0 ) + _gtGetPos( &dev_row, &dev_col ); + } 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 ); @@ -138,21 +130,19 @@ static void hb_altout( char * fpStr, WORD uiLen ) /* Output an item to the screen and/or printer */ static void hb_devout( char * fpStr, WORD uiLen ) { - WORD uiCount = uiLen; - char * fpPtr = fpStr; /* TODO: Delete fpPtr once the GT API works */ if( stricmp( hb_set.HB_SET_DEVICE, "PRINTER" ) == 0 && hb_set_printhan >= 0 ) { /* Display to printer if SET DEVICE TO PRINTER and valid printer file */ write( hb_set_printhan, fpStr, uiLen ); dev_col += uiLen; } - #ifdef console_printf else + { /* Otherwise, display to console */ - /* TODO: Replace with _gtWrite( fpStr, uiLen ) once the GT API works */ - while( uiCount-- ) - console_printf( "%c", *fpPtr++ ); - #endif + _gtWrite( fpStr, uiLen ); + if( stricmp( hb_set.HB_SET_DEVICE, "PRINTER" ) || hb_set_printhan < 0 ) + _gtGetPos( &dev_row, &dev_col ); + } } void hb_devpos( int row, int col ) @@ -174,14 +164,7 @@ void hb_devpos( int row, int col ) dev_col = col; } else - { - /*TODO: Replace with _gtSetPos( row, col ) once the GT API works */ - #ifdef console_gotoxy - console_gotoxy( col + 1, row + 1); - #else - ; - #endif - } + _gtSetPos( row, col ); } HARBOUR OUTSTD( void ) /* writes a list of values to the standard output device */ @@ -236,9 +219,7 @@ HARBOUR DEVPOS( void ) /* Sets the screen and/or printer position */ pRow = _param( 1, IT_NUMERIC ); pCol = _param( 2, IT_NUMERIC ); if( pRow && pCol ) - { hb_devpos( _parni( 1 ), _parni( 2 ) ); - } } } @@ -265,9 +246,33 @@ HARBOUR DEVOUT( void ) /* writes a single values to the current device (screen o HARBOUR EJECT( void ) /* Ejects the current page from the printer */ { - if( hb_set_printhan ) + if( stricmp( hb_set.HB_SET_DEVICE, "PRINTER" ) == 0 && hb_set_printhan >= 0 ) { write( hb_set_printhan, "\x0C", 1 ); dev_row = dev_col = 0; } } + +HARBOUR PROW( void ) /* Returns the current printer row position */ +{ + _retni( dev_row ); +} + +HARBOUR PCOL( void ) /* Returns the current printer row position */ +{ + _retni( dev_col ); +} + +HARBOUR SETPRC( void ) /* Sets the current printer row and column positions */ +{ + if( _pcount() > 1 ) + { + PITEM pRow = _param( 1, IT_NUMERIC ); + PITEM pCol = _param( 1, IT_NUMERIC ); + if( pRow && pCol ) + { + dev_row = _parni( 1 ); + dev_col = _parni( 2 ); + } + } +} diff --git a/harbour/source/rtl/files.c b/harbour/source/rtl/files.c index 8e7a293d6e..0c2b083a97 100644 --- a/harbour/source/rtl/files.c +++ b/harbour/source/rtl/files.c @@ -45,6 +45,21 @@ #if !defined(HAVE_POSIX_IO) #define HAVE_POSIX_IO + #ifndef S_IEXEC + #define S_IEXEC 0x0040 /* owner may execute */ + #endif + #ifndef S_IRWXU + #define S_IRWXU 0x01c0 /* RWE permissions mask for owner */ + #endif + #ifndef S_IRUSR + #define S_IRUSR 0x0100 /* owner may read */ + #endif + #ifndef S_IWUSR + #define S_IWUSR 0x0080 /* owner may write */ + #endif + #ifndef S_IXUSR + #define S_IXUSR 0x0040 /* owner may execute */ + #endif #endif #define PATH_SEPARATOR '\\' @@ -151,14 +166,10 @@ static int convert_seek_flags( int flags ) static int convert_create_flags( int flags ) { /* by default FC_NORMAL is set */ - #if ! defined( __WATCOMC__ ) && ! defined( __BORLANDC__ ) int result_flags=S_IWUSR; if( flags & FC_READONLY ) result_flags = result_flags & ~(S_IWUSR); - #else - int result_flags=0; - #endif if( flags & FC_HIDDEN ) result_flags |= 0; diff --git a/harbour/source/rtl/gt/gtdos.c b/harbour/source/rtl/gt/gtdos.c index cf2c88081c..02943cea30 100644 --- a/harbour/source/rtl/gt/gtdos.c +++ b/harbour/source/rtl/gt/gtdos.c @@ -1,3 +1,7 @@ +/* + * $Id$ + */ + /* * GTDOS.C: Video subsystem for DOS compilers. * @@ -112,15 +116,15 @@ void gtGotoXY(char x, char y) #if defined(__TURBOC__) _AH = 0x02; _BH = 0; - _DH = y - 1; - _DL = x - 1; + _DH = y; + _DL = x; geninterrupt(0x10); #else union REGS regs; regs.h.ah = 0x02; regs.h.bh = 0; - regs.h.dh = (unsigned char)(y - 1); - regs.h.dl = (unsigned char)(x - 1); + regs.h.dh = (unsigned char)(y); + regs.h.dl = (unsigned char)(x); #if defined(__WATCOMC__) && defined(__386__) int386(0x10, ®s, ®s); #else @@ -238,7 +242,7 @@ void gtSetCursorStyle(int style) static void gtxGetXY(char x, char y, char *attr, char *ch) { char FAR *p; - p = gtScreenPtr((char)(x - 1), (char)(y - 1)); + p = gtScreenPtr((char)(x), (char)(y)); *ch = *p; *attr = *(p + 1); } @@ -246,7 +250,7 @@ static void gtxGetXY(char x, char y, char *attr, char *ch) void gtxPutch(char x, char y, char attr, char ch) { char FAR *p; - p = gtScreenPtr((char)(x - 1), (char)(y - 1)); + p = gtScreenPtr((char)(x), (char)(y)); *p = ch; *(p + 1) = attr; } @@ -256,7 +260,7 @@ void gtPuts(char x, char y, char attr, char *str, int len) char FAR *p; int i; - p = gtScreenPtr((char)(x - 1), (char)(y - 1)); + p = gtScreenPtr((char)(x), (char)(y)); for(i=0; i +#include #include /* TODO: functions not implemented yet @@ -358,10 +362,46 @@ int _gtWriteAt(USHORT uiRow, USHORT uiCol, char * fpStr, USHORT uiLen) int _gtWriteCon(char * fpStr, USHORT uiLen) { int rc; + USHORT count; + char ch[2]; - if((rc=_gtWrite(fpStr, uiLen)) != 0) - return(rc); - + ch[1] = 0; + for(count = 0; count < uiLen; count++) + { + *ch = fpStr[count]; + switch(*ch) + { + case 7: + break; + case 8: + if(s_uiCurrentCol > 0) s_uiCurrentCol--; + else if(s_uiCurrentRow > 0) + { + s_uiCurrentRow--; + s_uiCurrentCol=_gtMaxCol(); + } + else + { + _gtScroll(0, 0, _gtMaxRow(), _gtMaxCol(), -1, 0); + s_uiCurrentCol=_gtMaxCol(); + } + break; + case 10: + if(s_uiCurrentRow < _gtMaxRow()) s_uiCurrentRow++; + else + { + _gtScroll(0, 0, _gtMaxRow(), _gtMaxCol(), 1, 0); + } + break; + case 13: + s_uiCurrentCol = 0; + break; + default: + rc = _gtWrite(ch, 1); + } + if(rc) + return(rc); + } return(0); } diff --git a/harbour/source/rtl/set.c b/harbour/source/rtl/set.c index ec8a7d2bca..95ea3eaa8b 100644 --- a/harbour/source/rtl/set.c +++ b/harbour/source/rtl/set.c @@ -293,7 +293,14 @@ HARBOUR SET (void) case HB_SET_DEVICE : if (hb_set.HB_SET_DEVICE) _retc (hb_set.HB_SET_DEVICE); else _retc (""); - if (args > 1) hb_set.HB_SET_DEVICE = set_string (pArg2, hb_set.HB_SET_DEVICE); + if (args > 1) + { + /* If the print file is not already open, open it. */ + hb_set.HB_SET_DEVICE = set_string (pArg2, hb_set.HB_SET_DEVICE); + if (stricmp (hb_set.HB_SET_DEVICE, "PRINTER") == 0 && hb_set_printhan < 0 + && hb_set.HB_SET_PRINTFILE && strlen (hb_set.HB_SET_PRINTFILE) > 0) + hb_set_printhan = open_handle (hb_set.HB_SET_PRINTFILE, bFlag, ".prn"); + } break; case HB_SET_EPOCH : _retni (hb_set.HB_SET_EPOCH); @@ -445,7 +452,8 @@ void InitializeSets (void) hb_set.HB_SET_PATH = (char*)_xgrab (1); *hb_set.HB_SET_PATH = 0; hb_set.HB_SET_PRINTER = FALSE; - hb_set.HB_SET_PRINTFILE = 0; /* NULL pointer */ + hb_set.HB_SET_PRINTFILE = (char*)_xgrab (4); + memcpy (hb_set.HB_SET_PRINTFILE, "PRN", 4); /* Default printer device */ hb_set.HB_SET_SCOREBOARD = TRUE; hb_set.HB_SET_SCROLLBREAK = TRUE; hb_set.HB_SET_SOFTSEEK = FALSE; diff --git a/harbour/source/rtl/transfrm.c b/harbour/source/rtl/transfrm.c index 4b195e027d..a9d08f18f8 100644 --- a/harbour/source/rtl/transfrm.c +++ b/harbour/source/rtl/transfrm.c @@ -5,6 +5,7 @@ #include #include #include +#include /* */ /* Transform( xValue, cPicture ) */ @@ -182,7 +183,7 @@ char *NumPicture( char *szPic, long lPic, int iPicFlags, double dValue, PushSymbol ( GetDynSym( "STR" )->pSymbol ); /* Push STR function */ PushNil (); /* Function call. No object */ - PushDouble ( dPush ); /* Push value to transform */ + PushDouble ( dPush, iDecimals ); /* Push value to transform */ PushInteger( iWidth ); /* Push numbers width */ PushInteger( iDecimals ); /* Push decimals */ Function( 3 ); /* 3 Parameters */ @@ -312,7 +313,7 @@ PITEM NumDefault( double dValue ) PushSymbol ( GetDynSym( "STR" )->pSymbol ); /* Push STR function */ PushNil (); /* Function call. No object */ - PushDouble ( dValue ); /* Push value to transform */ + PushDouble ( dValue, hb_set.HB_SET_DECIMALS ); /* Push value to transform */ Function ( 1 ); /* 1 Parameter */ StackPop (); /* Pop return value */ if( stack.pPos->wType != IT_STRING ) /* Is it a string */ diff --git a/harbour/source/vm/hvm.c b/harbour/source/vm/hvm.c index 515d33b578..86fbe863cc 100644 --- a/harbour/source/vm/hvm.c +++ b/harbour/source/vm/hvm.c @@ -31,6 +31,9 @@ HARBOUR EVAL( void ); /* Evaluates a codeblock from Harbour */ HARBOUR MAIN( void ); /* fixed entry point by now */ HARBOUR VALTYPE( void ); /* returns a string description of a value */ +extern void InitializeConsole(void); /* This prototype is needed by C++ compilers */ +extern void InitSymbolTable(void); /* This prototype is needed by C++ compilers */ + /* currently supported virtual machine actions */ void And( void ); /* performs the logical AND on the latest two values, removes them and leaves result on the stack */ void ArrayAt( void ); /* pushes an array element to the stack, removing the array and the index from the stack */ @@ -189,7 +192,8 @@ BYTE bErrorLevel = 0; /* application exit errorlevel */ stack.Return.wType = IT_NIL; StackInit(); NewDynSym( &symEval ); /* initialize dynamic symbol for evaluating codeblocks */ - InitializeSets(); /* initialize Sets */ + InitializeSets(); /* initialize Sets */ + InitializeConsole(); /* initialize Console */ #ifdef HARBOUR_OBJ_GENERATION ProcessObjSymbols(); /* initialize Harbour generated OBJs symbols */ #endif