From 2b158cb673c4b268e3bb21f47f231e3d37acac1b Mon Sep 17 00:00:00 2001 From: "Gonzalo A. Diethelm" Date: Wed, 24 Nov 1999 16:00:49 +0000 Subject: [PATCH] ChangeLogTag:Wed Nov 24 12:45:36 1999 Gonzalo A. Diethelm --- harbour/ChangeLog | 21 +++++++ harbour/doc/tracing.txt | 32 ++++++++++ harbour/include/hbtrace.h | 5 +- harbour/source/common/hbtrace.c | 101 ++++++++++++++++++++------------ harbour/source/rdd/dbf1.c | 2 +- harbour/source/rtl/Makefile | 1 + harbour/source/rtl/inkey.c | 2 + harbour/source/rtl/trace.c | 67 +++++++++++++++++++++ harbour/tests/Makefile | 11 ++-- 9 files changed, 199 insertions(+), 43 deletions(-) create mode 100644 harbour/source/rtl/trace.c diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 99e67c5bb1..541d4aa2a6 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,24 @@ +Wed Nov 24 12:45:36 1999 Gonzalo A. Diethelm + + * include/hbtrace.h: + * source/common/hbtrace.c: + * source/rtl/trace.c: + * source/rtl/Makefile: + * doc/tracing.txt: + Implememted run-time tracing control; thanks to Jose Lalin + for suggesting this. The interface is + described in doc/tracing.txt. + + * source/rdd/dbf1.c: + Fixed a compilation error that only appeared with HB_TR_DEBUG. + + * source/rtl/inkey.c: + Added a guard to avoid a compilation warning. + + * tests/Makefile: + Changed the order of inclusion to make sure you can still do a + make 'PRG_SOURCES=foo.prg'. + 19991123-13:35 EDT David G. Holm * rt_misc.prg diff --git a/harbour/doc/tracing.txt b/harbour/doc/tracing.txt index ebc81385b2..179463e222 100644 --- a/harbour/doc/tracing.txt +++ b/harbour/doc/tracing.txt @@ -133,3 +133,35 @@ recompile the preprocessor/compiler: HB_TRACE_UTILS The value is of no importance. + + +TRACING AND RUNTIME +=================== + +It is also possible to enable and disable tracing at run-time, and to +query and set the trace level. From C code: + +* To turn tracing completely off: + + hb_traceoff(); + +* To turn tracing back on: + + hb_traceon(); + +* To query the current tracing level, and optionally change the + current level to a given value (which should be in the range [0,5], + otherwise the current level remains unchanged): + + hb_tracelevel(level); + + Therefore, to just query the current level, you can safely call + + hb_tracelevel(-1); + + +There are wrapper functions callable from Clipper code: + + TRACEOFF() + TRACEON() + TRACELEVEL(level) diff --git a/harbour/include/hbtrace.h b/harbour/include/hbtrace.h index d8524501ea..415c4b1cdb 100644 --- a/harbour/include/hbtrace.h +++ b/harbour/include/hbtrace.h @@ -122,7 +122,10 @@ extern char * hb_tr_file_; extern int hb_tr_line_; extern int hb_tr_level_; +extern void hb_traceon( void ); +extern void hb_traceoff( void ); +extern int hb_tracelevel( int new_level ); +extern int hb_tr_level( void ); extern void hb_tr_trace( char* fmt, ... ); -extern int hb_tr_level(void); #endif /* HB_TRACE_H_ */ diff --git a/harbour/source/common/hbtrace.c b/harbour/source/common/hbtrace.c index aa5775b200..9f3cc052b0 100644 --- a/harbour/source/common/hbtrace.c +++ b/harbour/source/common/hbtrace.c @@ -43,6 +43,7 @@ char * hb_tr_file_ = ""; int hb_tr_line_ = 0; int hb_tr_level_ = 0; +static int hb_tr_state_ = 1; static FILE* hb_tr_fp_ = 0; static char* slevel[HB_TR_LAST] = { @@ -54,11 +55,75 @@ static char* slevel[HB_TR_LAST] = "HB_TR_DEBUG" }; + +void hb_traceon( void ) +{ + hb_tr_state_ = 1; +} + +void hb_traceoff( void ) +{ + hb_tr_state_ = 0; +} + +int hb_tracelevel( int new_level ) +{ + int old_level = hb_tr_level_; + + if (new_level >= HB_TR_ALWAYS && + new_level < HB_TR_LAST) { + hb_tr_level_ = new_level; + } + + return old_level; +} + +int hb_tr_level(void) +{ + static int level = -1; + int i; + char* env; + char* out; + + if (level != -1) { + return level; + } + + hb_tr_fp_ = stderr; + out = getenv("HB_TR_OUTPUT"); + if (out != 0 && out[0] != '\0') { + hb_tr_fp_ = fopen(out, "w"); + if (hb_tr_fp_ == NULL) { + hb_tr_fp_ = stderr; + } + } + + level = HB_TR_DEFAULT; + env = getenv("HB_TR_LEVEL"); + if (env != 0 && env[0] != '\0') { + for (i = 0; i < HB_TR_LAST; ++i) { + if (strcmp(env, slevel[i]) == 0) { + level = i; + break; + } + } + } + + return level; +} + void hb_tr_trace( char * fmt, ... ) { int i; va_list ap; + /* + * If tracing is disabled, do nothing. + */ + if( ! hb_tr_state_ ) { + return; + } + /* * Clean up the file, so that instead of showing * @@ -100,39 +165,3 @@ void hb_tr_trace( char * fmt, ... ) hb_tr_line_ = -1; hb_tr_level_ = -1; } - -int hb_tr_level(void) -{ - static int level = -1; - int i; - char* env; - char* out; - - if (level != -1) { - return level; - } - - hb_tr_fp_ = stderr; - out = getenv("HB_TR_OUTPUT"); - if (out != 0 && out[0] != '\0') { - hb_tr_fp_ = fopen(out, "w"); - if (hb_tr_fp_ == NULL) { - hb_tr_fp_ = stderr; - } - } - - env = getenv("HB_TR_LEVEL"); - if (env == 0 || env[0] == '\0') { - level = HB_TR_DEFAULT; - } - else { - for (i = 0; i < HB_TR_LAST; ++i) { - if (strcmp(env, slevel[i]) == 0) { - level = i; - break; - } - } - } - - return level; -} diff --git a/harbour/source/rdd/dbf1.c b/harbour/source/rdd/dbf1.c index d5577914c4..242481ae37 100644 --- a/harbour/source/rdd/dbf1.c +++ b/harbour/source/rdd/dbf1.c @@ -298,7 +298,7 @@ static BOOL hb_dbfUpdateRecord( AREAP pArea, ULONG ulRecNo ) LPFIELD pField; BYTE pBuffer[ 1 ]; - HB_TRACE(HB_TR_DEBUG, ("hb_dbfUpdateRecord(%p, %lu)", pArea, lRecNo)); + HB_TRACE(HB_TR_DEBUG, ("hb_dbfUpdateRecord(%p, %lu)", pArea, ulRecNo)); if( ulRecNo > pArea->lpExtendInfo->ulRecCount ) { diff --git a/harbour/source/rtl/Makefile b/harbour/source/rtl/Makefile index c521540031..5b53518e74 100644 --- a/harbour/source/rtl/Makefile +++ b/harbour/source/rtl/Makefile @@ -44,6 +44,7 @@ C_SOURCES=\ soundex.c \ strings.c \ tone.c \ + trace.c \ transfrm.c \ \ gtxxx.c \ diff --git a/harbour/source/rtl/inkey.c b/harbour/source/rtl/inkey.c index 8dd9dbc3fa..934cb416aa 100644 --- a/harbour/source/rtl/inkey.c +++ b/harbour/source/rtl/inkey.c @@ -90,6 +90,7 @@ #include "hbwinapi.h" #if defined(_Windows) || defined(WINNT) +#if ! defined(HARBOUR_USE_CRS_GTAPI) && ! defined(HARBOUR_USE_SLN_GTAPI) #define INPUT_BUFFER_LEN 128 extern BOOL hb_gtBreak; /* This variable is located in source/rtl/gt/gtwin.c */ extern HANDLE hb_gtHInput; /* This variable is located in source/rtl/gt/gtwin.c */ @@ -97,6 +98,7 @@ static DWORD s_cNumIndex = 0; /* ...to the Windows API, which defines DWORD, etc. */ static INPUT_RECORD s_irInBuf[ INPUT_BUFFER_LEN ]; #endif +#endif #define HB_BREAK_FLAG 256 /* 256, because that's what DJGPP returns Ctrl+Break as. Clipper has no key code 256, so it may as well be diff --git a/harbour/source/rtl/trace.c b/harbour/source/rtl/trace.c new file mode 100644 index 0000000000..cd9e3c9f8b --- /dev/null +++ b/harbour/source/rtl/trace.c @@ -0,0 +1,67 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * The Clipper tracing API. + * + * Copyright 1999 Gonzalo A. Diethelm + * 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: + * + * The exception is that if you link the Harbour Runtime Library (HRL) + * and/or the Harbour Virtual Machine (HVM) with other files to produce + * an executable, this does not by itself cause the resulting executable + * to be covered by the GNU General Public License. Your use of that + * executable is in no way restricted on account of linking the HRL + * and/or HVM code into it. + * + * 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/). + * + */ + +/* + * This code is based on a suggestion made by Jose Lalin + * . + * + * See doc/license.txt for licensing terms. + */ + +#include "extend.h" + + +HARBOUR HB_TRACEON( void ) +{ + hb_traceon(); +} + +HARBOUR HB_TRACEOFF( void ) +{ + hb_traceoff(); +} + +HARBOUR HB_TRACELEVEL( void ) +{ + int old_level = 0; + int new_level = -1; + + if( hb_pcount() == 1 ) { + new_level = hb_parni( 1 ); + } + + old_level = hb_tracelevel(new_level); + hb_retni( old_level ); +} diff --git a/harbour/tests/Makefile b/harbour/tests/Makefile index 3b548c6269..6c1d1f03c0 100644 --- a/harbour/tests/Makefile +++ b/harbour/tests/Makefile @@ -26,11 +26,6 @@ endif ifeq ($(PM),) # PM not defined = build all files -DIRS=\ - regress \ - -include $(TOP)$(ROOT)config/dir.cf - PRG_SOURCES=\ ac_test.prg \ adirtest.prg \ @@ -197,3 +192,9 @@ endif include $(TOP)$(ROOT)config/bin.cf endif + + +DIRS=\ + regress \ + +include $(TOP)$(ROOT)config/dir.cf