Diff for /np2/win9x/trace.cpp between versions 1.15 and 1.16

version 1.15, 2005/03/24 04:40:33 version 1.16, 2005/04/01 15:35:49
Line 1 Line 1
 #include        "compiler.h"  #include        "compiler.h"
 #include        <stdarg.h>  #include        <stdarg.h>
 #include        "strres.h"  #include        "strres.h"
   #include        "textfile.h"
   #include        "oemtext.h"
 #include        "dosio.h"  #include        "dosio.h"
 #include        "ini.h"  #include        "ini.h"
   
   
 #ifdef TRACE  #ifdef TRACE
   
 // #define FILEBUFSIZE                  (1 << 20)  
 // #define FILELASTBUFONLY  
   
 #ifdef STRICT  #ifdef STRICT
 #define SUBCLASSPROC    WNDPROC  #define SUBCLASSPROC    WNDPROC
 #else  #else
Line 24 Line 23
 #define VIEW_SIZE               12  #define VIEW_SIZE               12
   
 typedef struct {  typedef struct {
         UINT8   en;          UINT8           en;
         FILEH   fh;          TEXTFILEH       tf;
         HWND    hwnd;          HWND            hwnd;
 } TRACEWIN;  } TRACEWIN;
   
 typedef struct {  typedef struct {
Line 50  enum { Line 49  enum {
 static const TCHAR ProgTitle[] = _T("console");  static const TCHAR ProgTitle[] = _T("console");
 static const TCHAR ClassName[] = _T("TRACE-console");  static const TCHAR ClassName[] = _T("TRACE-console");
 static const TCHAR ClassEdit[] = _T("EDIT");  static const TCHAR ClassEdit[] = _T("EDIT");
   static const TCHAR viewfont[] = _T(VIEW_TEXT);
 static const TCHAR trace1[] = _T("TRACE");  static const TCHAR trace1[] = _T("TRACE");
 static const TCHAR trace2[] = _T("VERBOSE");  static const TCHAR trace2[] = _T("VERBOSE");
 static const TCHAR traceen[] = _T("Enable");  static const TCHAR traceen[] = _T("Enable");
 static const TCHAR tracefh[] = _T("File out");  static const TCHAR tracefh[] = _T("File out");
 static const TCHAR tracecl[] = _T("Clear");  static const TCHAR tracecl[] = _T("Clear");
 static const TCHAR fontface[] = _T(VIEW_TEXT);  static const OEMCHAR crlf[] = OEMTEXT("\r\n");
 static const TCHAR crlf[] = _T("\r\n");  
   
 static  TRACEWIN        tracewin;  static  TRACEWIN        tracewin;
 static  HWND            hView = NULL;  static  HWND            hView = NULL;
Line 94  static void View_ClrString(void) { Line 93  static void View_ClrString(void) {
         SetWindowText(hView, viewbuf);          SetWindowText(hView, viewbuf);
 }  }
   
 static void View_AddString(const TCHAR *string) {  static void View_AddString(const OEMCHAR *string) {
   
         int             slen;          int             slen;
         int             vpos;          int             vpos;
         int             vlen;          int             vlen;
         TCHAR   c;          TCHAR   c;
   
   #if defined(OEMCHAR_SAME_TCHAR)
         slen = lstrlen(string);          slen = lstrlen(string);
   #else
           slen = oemtotchar(NULL, 0, string, (UINT)-1) - 1;
   #endif
         if ((slen == 0) || ((slen + 3) > VIEW_BUFFERSIZE)) {          if ((slen == 0) || ((slen + 3) > VIEW_BUFFERSIZE)) {
                 return;                  return;
         }          }
Line 123  static void View_AddString(const TCHAR * Line 126  static void View_AddString(const TCHAR *
                         viewpos = 0;                          viewpos = 0;
                 }                  }
         }          }
   #if defined(OEMCHAR_SAME_TCHAR)
         CopyMemory(viewbuf + vpos + vlen, string, slen * sizeof(TCHAR));          CopyMemory(viewbuf + vpos + vlen, string, slen * sizeof(TCHAR));
   #else
           oemtotchar(viewbuf + vpos + vlen, slen + 1, string, (UINT)-1);
   #endif
         vlen += slen;          vlen += slen;
         viewbuf[vpos + vlen + 0] = '\r';          viewbuf[vpos + vlen + 0] = '\r';
         viewbuf[vpos + vlen + 1] = '\n';          viewbuf[vpos + vlen + 1] = '\n';
Line 136  static void View_AddString(const TCHAR * Line 143  static void View_AddString(const TCHAR *
   
 // ----  // ----
   
 #if defined(FILEBUFSIZE)  
 static  TCHAR   filebuf[FILEBUFSIZE];  
 static  UINT32  filebufpos;  
 #endif  
   
 static void trfh_close(void) {  
   
         FILEH   fh;  
   
         fh = tracewin.fh;  
         tracewin.fh = FILEH_INVALID;  
         if (fh != FILEH_INVALID) {  
 #if defined(FILEBUFSIZE)  
                 UINT size = filebufpos & (FILEBUFSIZE - 1);  
 #if defined(FILELASTBUFONLY)  
                 if (filebufpos >= FILEBUFSIZE) {  
                         file_write(fh, filebuf + size, FILEBUFSIZE - size);  
                 }  
 #endif  
                 if (size) {  
                         file_write(fh, filebuf, size);  
                 }  
 #endif  
                 file_close(fh);  
         }  
 }  
   
 static void trfh_open(const OEMCHAR *fname) {  
   
         trfh_close();  
         tracewin.fh = file_create(fname);  
 #if defined(FILEBUFSIZE)  
         filebufpos = 0;  
 #endif  
 }  
   
 static void trfh_add(const TCHAR *buf) {  
   
         UINT    size;  
   
         size = lstrlen(buf);  
 #if defined(FILEBUFSIZE)  
         while(size) {  
                 UINT pos = filebufpos & (FILEBUFSIZE - 1);  
                 UINT rem = FILEBUFSIZE - pos;  
                 if (size >= rem) {  
                         CopyMemory(filebuf + pos, buf, rem);  
                         filebufpos += rem;  
                         buf += rem;  
                         size -= rem;  
 #if !defined(FILELASTBUFONLY)  
                         file_write(tracewin.fh, filebuf, FILEBUFSIZE);  
 #endif  
                 }  
                 else {  
                         CopyMemory(filebuf + pos, buf, size);  
                         filebufpos += size;  
                         break;  
                 }  
         }  
 #else  
         file_write(tracewin.fh, buf, size);  
 #endif  
 }  
   
   
 // ----  
   
 static LRESULT CALLBACK traceproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {  static LRESULT CALLBACK traceproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
   
         RECT    rc;          RECT    rc;
Line 246  static LRESULT CALLBACK traceproc(HWND h Line 185  static LRESULT CALLBACK traceproc(HWND h
   
                         hfView = CreateFont(VIEW_SIZE, 0, 0, 0, 0, 0, 0, 0,                           hfView = CreateFont(VIEW_SIZE, 0, 0, 0, 0, 0, 0, 0, 
                                         SHIFTJIS_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,                                          SHIFTJIS_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
                                         DEFAULT_QUALITY, FIXED_PITCH, fontface);                                          DEFAULT_QUALITY, FIXED_PITCH, viewfont);
                         if (!hfView) {                          if (!hfView) {
                                 break;                                  break;
                         }                          }
Line 280  static LRESULT CALLBACK traceproc(HWND h Line 219  static LRESULT CALLBACK traceproc(HWND h
                                         break;                                          break;
   
                                 case IDM_TRACEFH:                                  case IDM_TRACEFH:
                                         if (tracewin.fh != FILEH_INVALID) {                                          if (tracewin.tf != NULL) {
                                                 trfh_close();                                                  textfile_close(tracewin.tf);
                                                   tracewin.tf = NULL;
                                         }                                          }
                                         else {                                          else {
                                                 trfh_open(OEMTEXT("traceout.txt"));                                                  tracewin.tf = textfile_create(OEMTEXT("traceout.txt"),
                                                                                                                                                   0x800);
                                         }                                          }
                                         hmenu = GetSystemMenu(hWnd, FALSE);                                          hmenu = GetSystemMenu(hWnd, FALSE);
                                         CheckMenuItem(hmenu, IDM_TRACEFH,                                          CheckMenuItem(hmenu, IDM_TRACEFH,
                                                                         (tracewin.fh != FILEH_INVALID)?                                                                          (tracewin.tf)?MF_CHECKED:MF_UNCHECKED);
                                                                                                         MF_CHECKED:MF_UNCHECKED);  
                                         break;                                          break;
   
                                 case IDM_TRACECL:                                  case IDM_TRACECL:
Line 379  void trace_init(void) { Line 319  void trace_init(void) {
                 wc.hCursor = LoadCursor(NULL, IDC_ARROW);                  wc.hCursor = LoadCursor(NULL, IDC_ARROW);
                 wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);                  wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
                 wc.lpszMenuName = NULL;                  wc.lpszMenuName = NULL;
                 wc.lpszClassName = (LPCTSTR)ClassName;                  wc.lpszClassName = ClassName;
                 if (!RegisterClass(&wc)) {                  if (!RegisterClass(&wc)) {
                         return;                          return;
                 }                  }
         }          }
   
 #if 1  
         tracewin.en = 4;          tracewin.en = 4;
 #else  
         tracewin.en = 0;  
 #endif  
         tracewin.fh = FILEH_INVALID;  
   
         tracecfg.posx = CW_USEDEFAULT;          tracecfg.posx = CW_USEDEFAULT;
         tracecfg.posy = CW_USEDEFAULT;          tracecfg.posy = CW_USEDEFAULT;
         tracecfg.width = CW_USEDEFAULT;          tracecfg.width = CW_USEDEFAULT;
         tracecfg.height = CW_USEDEFAULT;          tracecfg.height = CW_USEDEFAULT;
         ini_read(file_getcd(np2trace), inititle, initbl, 4);          ini_read(file_getcd(np2trace), inititle, initbl, NELEMENTS(initbl));
   
         hwnd = CreateWindowEx(WS_EX_CONTROLPARENT,          hwnd = CreateWindowEx(WS_EX_CONTROLPARENT,
                                                         ClassName, ProgTitle,                                                          ClassName, ProgTitle,
Line 414  void trace_init(void) { Line 349  void trace_init(void) {
   
 void trace_term(void) {  void trace_term(void) {
   
         if (tracewin.fh != FILEH_INVALID) {          if (tracewin.tf != NULL) {
                 trfh_close();                  textfile_close(tracewin.tf);
                   tracewin.tf = NULL;
         }          }
         if (tracewin.hwnd) {          if (tracewin.hwnd) {
                 DestroyWindow(tracewin.hwnd);                  DestroyWindow(tracewin.hwnd);
                 tracewin.hwnd = NULL;                  tracewin.hwnd = NULL;
                 ini_write(file_getcd(np2trace), inititle, initbl, 4);                  ini_write(file_getcd(np2trace), inititle, initbl, NELEMENTS(initbl));
         }          }
 }  }
   
Line 431  void trace_fmt(const char *fmt, ...) { Line 367  void trace_fmt(const char *fmt, ...) {
         OEMCHAR buf[0x1000];          OEMCHAR buf[0x1000];
   
         en = (tracewin.en & 1) &&          en = (tracewin.en & 1) &&
                 ((tracewin.en & 4) || (tracewin.fh != FILEH_INVALID));                  ((tracewin.en & 4) || (tracewin.tf != NULL));
         if (en) {          if (en) {
                 va_start(ap, fmt);                  va_start(ap, fmt);
 #if defined(_UNICODE)  #if defined(OSLANG_UCS2)
                 TCHAR cnvfmt[0x800];                  OEMCHAR cnvfmt[0x800];
                 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, fmt, -1,                  MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, fmt, -1,
                                                                                                 cnvfmt, NELEMENTS(cnvfmt));                                                                                                  cnvfmt, NELEMENTS(cnvfmt));
                 vswprintf(buf, cnvfmt, ap);                  vswprintf(buf, cnvfmt, ap);
Line 446  void trace_fmt(const char *fmt, ...) { Line 382  void trace_fmt(const char *fmt, ...) {
                 if ((tracewin.en & 4) && (hView)) {                  if ((tracewin.en & 4) && (hView)) {
                         View_AddString(buf);                          View_AddString(buf);
                 }                  }
                 if (tracewin.fh != FILEH_INVALID) {                  if (tracewin.tf != NULL) {
                         trfh_add(buf);                          textfile_write(tracewin.tf, buf);
                         trfh_add(crlf);                          textfile_write(tracewin.tf, crlf);
                 }                  }
         }          }
 }  }
Line 460  void trace_fmt2(const char *fmt, ...) { Line 396  void trace_fmt2(const char *fmt, ...) {
         OEMCHAR buf[0x1000];          OEMCHAR buf[0x1000];
   
         en = (tracewin.en & 2) &&          en = (tracewin.en & 2) &&
                 ((tracewin.en & 4) || (tracewin.fh != FILEH_INVALID));                  ((tracewin.en & 4) || (tracewin.tf != NULL));
         if (en) {          if (en) {
                 va_start(ap, fmt);                  va_start(ap, fmt);
 #if defined(_UNICODE)  #if defined(OSLANG_UCS2)
                 TCHAR cnvfmt[0x800];                  OEMCHAR cnvfmt[0x800];
                 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, fmt, -1,                  MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, fmt, -1,
                                                                                                 cnvfmt, NELEMENTS(cnvfmt));                                                                                                  cnvfmt, NELEMENTS(cnvfmt));
                 vswprintf(buf, cnvfmt, ap);                  vswprintf(buf, cnvfmt, ap);
Line 475  void trace_fmt2(const char *fmt, ...) { Line 411  void trace_fmt2(const char *fmt, ...) {
                 if ((tracewin.en & 4) && (hView)) {                  if ((tracewin.en & 4) && (hView)) {
                         View_AddString(buf);                          View_AddString(buf);
                 }                  }
                 if (tracewin.fh != FILEH_INVALID) {                  if (tracewin.tf != FILEH_INVALID) {
                         trfh_add(buf);                          textfile_write(tracewin.tf, buf);
                         trfh_add(crlf);                          textfile_write(tracewin.tf, crlf);
                 }                  }
         }          }
 }  }
Line 487  void trace_char(char c) { Line 423  void trace_char(char c) {
         if ((c == 0x0a) || (c == 0x0d)) {          if ((c == 0x0a) || (c == 0x0d)) {
                 if (devpos) {                  if (devpos) {
                         devstr[devpos] = '\0';                          devstr[devpos] = '\0';
 #if defined(_UNICODE)  #if defined(OSLANG_UCS2)
                         TCHAR pdevstr[0x800];                          TCHAR pdevstr[0x800];
                         MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, devstr, -1,                          MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, devstr, -1,
                                                                                                 pdevstr, NELEMENTS(pdevstr));                                                                                                  pdevstr, NELEMENTS(pdevstr));
 #else  #else
                         const TCHAR *pdevstr = devstr;                          const OEMCHAR *pdevstr = devstr;
 #endif  #endif
                         if ((tracewin.en & 4) && (hView)) {                          if ((tracewin.en & 4) && (hView)) {
                                 View_AddString(pdevstr);                                  View_AddString(pdevstr);
                         }                          }
                         if (tracewin.fh != FILEH_INVALID) {                          if (tracewin.tf != NULL) {
                                 trfh_add(pdevstr);                                  textfile_write(tracewin.tf, pdevstr);
                                 trfh_add(crlf);                                  textfile_write(tracewin.tf, crlf);
                         }                          }
                         devpos = 0;                          devpos = 0;
                 }                  }

Removed from v.1.15  
changed lines
  Added in v.1.16


RetroPC.NET-CVS <cvs@retropc.net>