From d45ede2a3237a62c711e97acf970108a5a866a17 Mon Sep 17 00:00:00 2001 From: Ryszard Glab Date: Sat, 19 Jun 1999 12:14:05 +0000 Subject: [PATCH] See ChangeLog 19990619-12:22 --- harbour/ChangeLog | 15 +++++++++++++++ harbour/include/hbsetup.h | 3 +++ harbour/source/rtl/console.c | 31 ++++++++++++++++++++++++++----- harbour/source/rtl/dir.c | 4 ++-- 4 files changed, 46 insertions(+), 7 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index a8563444e5..6a7d0bc390 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,18 @@ +19990619-12:22 Ryszard Glab + +* include/hbsetup.h + + added automatic definition of settings that can be used for OS specific code + OS_UNIX_COMPATIBLE -for UNIX like systems + OS_DOS_COMPATIBLE -for DOS like systems + +* source/rtl/console.c + + added calls for fgets instead of gets for GCC on UNIX-es + TODO: check if this change can be applied on DOS also + * changed CR/LF use to LF for GCC on UNIX-es + +* source/rtl/dir.c + * changed to use OS_UNIX_COMPATIBLE/OS_DOS_COMPATIBLE settings + 19990619-10:42 Ryszard Glab * tests/working/Makefile diff --git a/harbour/include/hbsetup.h b/harbour/include/hbsetup.h index ac9c3c80a8..66ed127d70 100644 --- a/harbour/include/hbsetup.h +++ b/harbour/include/hbsetup.h @@ -47,14 +47,17 @@ /* The DJGPP port of GNU C is used - for DOS platform */ #define OS_PATH_LIST_SEPARATOR ';' #define OS_PATH_DELIMITER '\\' + #define OS_DOS_COMPATIBLE #else #define OS_PATH_LIST_SEPARATOR ':' #define OS_PATH_DELIMITER '/' + #define OS_UNIX_COMPATIBLE #endif #else /* we are assuming here the DOS compatible OS */ #define OS_PATH_LIST_SEPARATOR ';' #define OS_PATH_DELIMITER '\\' + #define OS_DOS_COMPATIBLE #endif #endif /* HBSETUP_H_ */ diff --git a/harbour/source/rtl/console.c b/harbour/source/rtl/console.c index 9b1f063a60..933572e475 100644 --- a/harbour/source/rtl/console.c +++ b/harbour/source/rtl/console.c @@ -6,6 +6,7 @@ #include #endif +#include #include #include #include @@ -22,6 +23,14 @@ #include #endif +#define ACCEPT_BUFFER_LEN 256 /*length of input buffer for ACCEPT command */ + +#if defined(OS_UNIX_COMPATIBLE) +#define CRLF_BUFFER_LEN 2 /*length of buffer for CR/LF characters */ +#else +#define CRLF_BUFFER_LEN 3 /*length of buffer for CR/LF characters */ +#endif + HARBOUR HB___ACCEPT(void); HARBOUR HB_COL( void ); HARBOUR HB_DEVOUT( void ); @@ -66,13 +75,19 @@ void Console__InitSymbols( void ) } static unsigned short dev_row, dev_col, p_row, p_col; -static char CrLf [3]; +static char CrLf [ CRLF_BUFFER_LEN ]; void InitializeConsole( void ) { +#if defined(OS_DOS_COMPATIBLE) CrLf [0] = 13; CrLf [1] = 10; CrLf [2] = 0; +#else + CrLf [0] = 10; + CrLf [1] = 0; +#endif + #ifdef USE_GTAPI dev_row = gtWhereY(); dev_col = gtWhereX(); @@ -142,7 +157,7 @@ HARBOUR HB___ACCEPT( void ) /* Internal Clipper function used in ACCEPT command /* Basically the simplest Clipper function to */ /* receive data. Parameter : cPrompt. Returns : cRet */ { - char *szResult = ( char * ) hb_xgrab(256); /* Return parameter. Limited to 255 chars */ + char *szResult = ( char * ) hb_xgrab(ACCEPT_BUFFER_LEN); /* Return parameter. */ char *szPrompt = hb_parc(1); /* Pass prompt */ long lLen = hb_parclen(1); /* Please change to long later on */ @@ -154,7 +169,13 @@ HARBOUR HB___ACCEPT( void ) /* Internal Clipper function used in ACCEPT command Do( 1 ); /* 1 parameter supplied. Invoke the virtual machine */ } - gets( szResult ); /* Read the data. Using gets() */ +#ifdef OS_UNIX_COMPATIBLE + fgets( szResult, ACCEPT_BUFFER_LEN, stdin ); /* Read the data. Using fgets() */ +#else +/*TODO: check if it can be replaced with fgets() function +*/ + gets( szResult ); /* Read the data. using gets(). Note; it doesn't check for buffer overflow */ +#endif hb_retc( szResult ); hb_xfree( szResult ); } @@ -325,7 +346,7 @@ void hb_devpos( USHORT row, USHORT col ) write( hb_set_printhan, "\x0C", 1 ); p_row = p_col = 0; } - for( count = p_row; count < row; count++ ) write( hb_set_printhan, CrLf, strlen (CrLf) ); + for( count = p_row; count < row; count++ ) write( hb_set_printhan, CrLf, CRLF_BUFFER_LEN-1 ); if( row > p_row ) p_col = 0; col += hb_set.HB_SET_MARGIN; for( count = p_col; count < col; count++ ) write( hb_set_printhan, " ", 1 ); @@ -374,7 +395,7 @@ HARBOUR HB_QOUT( void ) MessageBox( 0, hb_parc( 1 ), "Harbour", 0 ); #else int count; - hb_altout( CrLf, strlen (CrLf) ); + hb_altout( CrLf, CRLF_BUFFER_LEN-1 ); if( hb_set.HB_SET_PRINTER && hb_set_printhan >= 0 ) { p_row++; diff --git a/harbour/source/rtl/dir.c b/harbour/source/rtl/dir.c index 701bcd4b52..989ad44ffc 100644 --- a/harbour/source/rtl/dir.c +++ b/harbour/source/rtl/dir.c @@ -2,11 +2,11 @@ * $Id$ */ +#include #include #include #include #include -#include #if defined(__GNUC__) #include @@ -262,7 +262,7 @@ HARBOUR HB_DIRECTORY( void ) while(0==getchar()); */ -#if defined(__GNUC__) && !defined(__DJGPP__) +#if defined(OS_UNIX_COMPATIBLE) /* GNU C on Linux or on other UNIX */ aatrib[ 0 ] = '\0'; if( S_ISREG(statbuf.st_mode) )