From 80aabeb672cb67b13e83f1f67c5411992efc80ea Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Wed, 19 Apr 2000 03:21:09 +0000 Subject: [PATCH] Modify Win32 tracing mechanism so that it is always compiled in and can be dynamically enabled or disabled. --- v7/src/microcode/ntscreen.c | 60 ++++++++++++++++++------------------- v7/src/microcode/ntscreen.h | 12 ++++---- v7/src/microcode/prntio.c | 52 ++++++++++++++++++++++---------- 3 files changed, 71 insertions(+), 53 deletions(-) diff --git a/v7/src/microcode/ntscreen.c b/v7/src/microcode/ntscreen.c index 7e3215593..34f0529eb 100644 --- a/v7/src/microcode/ntscreen.c +++ b/v7/src/microcode/ntscreen.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: ntscreen.c,v 1.41 2000/01/13 16:27:52 cph Exp $ +$Id: ntscreen.c,v 1.42 2000/04/19 03:21:06 cph Exp $ Copyright (c) 1993-2000 Massachusetts Institute of Technology @@ -191,9 +191,7 @@ extern LRESULT FAR CALLBACK ScreenWndProc (HWND, UINT, WPARAM, LPARAM); static VOID RegisterScreen (SCREEN); static VOID UnregisterScreen (SCREEN); -#ifdef TRACE_SCREEN_MSGS static const char * translate_message_code (UINT); -#endif /* FILE GLOBAL VARIABLES */ @@ -207,9 +205,8 @@ static SCREEN_EVENT_LINK * free_events; static SCREEN_EVENT_LINK * event_queue_head; static SCREEN_EVENT_LINK * event_queue_tail; -#ifdef TRACE_SCREEN_MSGS -FILE * trace_file; -#endif +FILE * win32_trace_file; +unsigned long win32_trace_level; static long screen_x_extra (SCREEN screen) @@ -290,7 +287,8 @@ init_color (char *color_symbol, HWND hWnd, DWORD *color) char * envvar = getenv (color_symbol); if (envvar == NULL) return FALSE; - /* Use GetNearestColor to ensure consistency with the background text color. */ + /* Use GetNearestColor to ensure consistency with the background + text color. */ hdc = GetDC (hWnd); *color = GetNearestColor (hdc, strtoul (envvar, NULL, 0)); ReleaseDC (hWnd, hdc); @@ -366,9 +364,8 @@ Screen_InitApplication (HANDLE hInstance) if (font_name) ScreenSetDefaultFont (font_name); -#ifdef TRACE_SCREEN_MSGS - trace_file = (fopen (TRACE_SCREEN_FILENAME, "w")); -#endif + win32_trace_file = 0; + win32_trace_level = 0; #ifdef WINDOWSLOSES init_MIT_Keyboard (); @@ -512,19 +509,19 @@ ScreenWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { SCREEN screen = GETSCREEN (hWnd); -#ifdef TRACE_SCREEN_MSGS - if (trace_file) + if (win32_trace_level > 0) { const char * name = (translate_message_code (uMsg)); - fprintf (trace_file, "hWnd=0x%x, ", hWnd); + fprintf (win32_trace_file, "ScreenWndProc: "); + fprintf (win32_trace_file, "hWnd=0x%x, ", hWnd); if (name) - fprintf (trace_file, "uMsg=%s, ", name); + fprintf (win32_trace_file, "uMsg=%s, ", name); else - fprintf (trace_file, "uMsg=0x%x, ", uMsg); - fprintf (trace_file, "wParam=0x%x, lParam=0x%x\n", wParam, lParam); - fflush (trace_file); + fprintf (win32_trace_file, "uMsg=0x%x, ", uMsg); + fprintf (win32_trace_file, "wParam=0x%x, lParam=0x%x\n", + wParam, lParam); + fflush (win32_trace_file); } -#endif switch (uMsg) { case WM_CREATE: @@ -2024,13 +2021,15 @@ make_key_event (HWND handle, WPARAM wparam, LPARAM lparam, int ch) ((event -> event.key) . ch) = ch; ((event -> event.key) . control_key_state) = modifiers; -#ifdef TRACE_SCREEN_MSGS - fprintf - (trace_file, - "make_key_event: handle=0x%x keycode=0x%x scancode=0x%x ch=0x%x modifiers=0x%x\n", - handle, wparam, (LP_SCAN_CODE (lparam)), ch, modifiers); - fflush (trace_file); -#endif + if (win32_trace_level > 0) + { + fprintf (win32_trace_file, "make_key_event: "); + fprintf + (win32_trace_file, + "handle=0x%x keycode=0x%x scancode=0x%x ch=0x%x modifiers=0x%x\n", + handle, wparam, (LP_SCAN_CODE (lparam)), ch, modifiers); + fflush (win32_trace_file); + } } /* Process WM_KEYDOWN and WM_SYSKEYDOWN. Return 1 to indicate that @@ -3346,10 +3345,11 @@ int Screen_read_event (SCREEN_EVENT * event) { int result = (read_event (0, 0, 1, event)); -#ifdef TRACE_SCREEN_MSGS - fprintf (trace_file, "Screen_read_event: result=%d\n", result); - fflush (trace_file); -#endif + if (win32_trace_level > 1) + { + fprintf (win32_trace_file, "Screen_read_event: result=%d\n", result); + fflush (win32_trace_file); + } return (result); } @@ -3707,7 +3707,6 @@ ScreenSetBackgroundColour (SCREEN screen, DWORD colour) return change_colour (screen, colour, &screen->rgbBGColour); } -#ifdef TRACE_SCREEN_MSGS static const char * translate_message_code (UINT uMsg) { @@ -3922,4 +3921,3 @@ translate_message_code (UINT uMsg) default: return (0); } } -#endif diff --git a/v7/src/microcode/ntscreen.h b/v7/src/microcode/ntscreen.h index 43e3e7b71..7f469172b 100644 --- a/v7/src/microcode/ntscreen.h +++ b/v7/src/microcode/ntscreen.h @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: ntscreen.h,v 1.19 2000/01/10 04:44:25 cph Exp $ +$Id: ntscreen.h,v 1.20 2000/04/19 03:21:07 cph Exp $ Copyright (c) 1993-2000 Massachusetts Institute of Technology @@ -224,12 +224,10 @@ struct screen_write_char_s /* Do user-level timer interrupts by using WM_TIMER. */ #define USE_WM_TIMER -/* Define this to generate an event trace. */ -#ifdef TRACE_SCREEN_MSGS -extern FILE * trace_file; -#ifndef TRACE_SCREEN_FILENAME -#define TRACE_SCREEN_FILENAME "nttrace.out" -#endif +extern FILE * win32_trace_file; +extern unsigned long win32_trace_level; +#ifndef WIN32_TRACE_FILENAME +#define WIN32_TRACE_FILENAME "w32trace.out" #endif #ifdef __WATCOMC__ diff --git a/v7/src/microcode/prntio.c b/v7/src/microcode/prntio.c index 9909db50e..f40dadd0f 100644 --- a/v7/src/microcode/prntio.c +++ b/v7/src/microcode/prntio.c @@ -1,8 +1,8 @@ /* -*-C-*- -$Id: prntio.c,v 1.11 1999/02/23 06:13:14 cph Exp $ +$Id: prntio.c,v 1.12 2000/04/19 03:21:09 cph Exp $ -Copyright (c) 1993-1999 Massachusetts Institute of Technology +Copyright (c) 1993-2000 Massachusetts Institute of Technology 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 @@ -46,6 +46,28 @@ DEFINE_PRIMITIVE ("CHANNEL-DESCRIPTOR", Prim_channel_descriptor, 1, 1, 0) PRIMITIVE_RETURN (ulong_to_integer (arg_channel (1))); } +DEFINE_PRIMITIVE ("WIN32-GUI-TRACE", Prim_win32_gui_trace, 2, 2, 0) +{ + PRIMITIVE_HEADER (2); + { + unsigned long old_level = win32_trace_level; + win32_trace_level = (arg_ulong_integer (1)); + if (win32_trace_file != 0) + { + fflush (win32_trace_file); + fclose (win32_trace_file); + win32_trace_file = 0; + } + if (win32_trace_level > 0) + win32_trace_file + = (fopen ((((ARG_REF (2)) == SHARP_F) + ? WIN32_TRACE_FILENAME + : (STRING_ARG (2))), + "w")); + } + PRIMITIVE_RETURN (UNSPECIFIC); +} + DEFINE_PRIMITIVE ("NT:MSGWAITFORMULTIPLEOBJECTS", Prim_nt_msgwaitformultipleobjects, 4, 4, 0) { PRIMITIVE_HEADER (4); @@ -109,25 +131,25 @@ static long wait_for_multiple_objects (unsigned long n_channels, Tchannel * channels, long console_index, int blockp) { -#ifdef TRACE_SCREEN_MSGS - fprintf - (trace_file, - "wait_for_multiple_objects: n_channels=%d console_index=%d blockp=%d\n", - n_channels, console_index, blockp); - fflush (trace_file); + if (win32_trace_level > 1) + { + fprintf (win32_trace_file, "wait_for_multiple_objects: "); + fprintf (win32_trace_file, "n_channels=%d console_index=%d blockp=%d\n", + n_channels, console_index, blockp); + fflush (win32_trace_file); + } { long result = (wait_for_multiple_objects_1 (n_channels, channels, console_index, blockp)); - fprintf (trace_file, "wait_for_multiple_objects: result=0x%x\n", result); - fflush (trace_file); + if (win32_trace_level > 1) + { + fprintf (win32_trace_file, "wait_for_multiple_objects: "); + fprintf (win32_trace_file, "result=0x%x\n", result); + fflush (win32_trace_file); + } return (result); } -#else - return - (wait_for_multiple_objects_1 - (n_channels, channels, console_index, blockp)); -#endif } static long -- 2.25.1