2007-03-08 04:03:40 +08:00
|
|
|
/**********************************************************************
|
|
|
|
* File: tprintf.c
|
|
|
|
* Description: Trace version of printf - portable between UX and NT
|
|
|
|
* Author: Phil Cheatle
|
|
|
|
* Created: Wed Jun 28 15:01:15 BST 1995
|
|
|
|
*
|
|
|
|
* (C) Copyright 1995, Hewlett-Packard Ltd.
|
|
|
|
** Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
** you may not use this file except in compliance with the License.
|
|
|
|
** You may obtain a copy of the License at
|
|
|
|
** http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
** Unless required by applicable law or agreed to in writing, software
|
|
|
|
** distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
** See the License for the specific language governing permissions and
|
|
|
|
** limitations under the License.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
2010-05-28 20:03:45 +08:00
|
|
|
|
2010-07-22 02:11:00 +08:00
|
|
|
#include "mfcpch.h" //precompiled headers
|
|
|
|
|
2010-11-24 02:34:14 +08:00
|
|
|
// Include automatically generated configuration file if running autoconf.
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config_auto.h"
|
|
|
|
#endif
|
|
|
|
|
2007-03-08 04:03:40 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include "strngs.h"
|
2010-11-24 02:34:14 +08:00
|
|
|
#include "params.h"
|
2007-03-08 04:03:40 +08:00
|
|
|
#include "tprintf.h"
|
2009-07-11 10:50:24 +08:00
|
|
|
#include "ccutil.h"
|
2007-03-08 04:03:40 +08:00
|
|
|
|
|
|
|
#define MAX_MSG_LEN 1024
|
|
|
|
|
|
|
|
#define EXTERN
|
2010-11-24 02:34:14 +08:00
|
|
|
// Since tprintf is protected by a mutex, these parameters can rmain global.
|
2011-08-19 00:45:01 +08:00
|
|
|
DLLSYM STRING_VAR(debug_file, "", "File to send tprintf output to");
|
2007-03-08 04:03:40 +08:00
|
|
|
|
|
|
|
DLLSYM void
|
|
|
|
tprintf ( //Trace printf
|
|
|
|
const char *format, ... //special message
|
|
|
|
) {
|
2009-07-11 10:50:24 +08:00
|
|
|
tesseract::tprintfMutex.Lock();
|
2007-03-08 04:03:40 +08:00
|
|
|
va_list args; //variable args
|
|
|
|
static FILE *debugfp = NULL; //debug file
|
|
|
|
//debug window
|
2008-04-22 08:23:41 +08:00
|
|
|
inT32 offset = 0; //into message
|
2007-03-08 04:03:40 +08:00
|
|
|
static char msg[MAX_MSG_LEN + 1];
|
|
|
|
|
|
|
|
va_start(args, format); //variable list
|
|
|
|
#ifdef __MSW32__
|
|
|
|
//Format into msg
|
|
|
|
offset += _vsnprintf (msg + offset, MAX_MSG_LEN - offset, format, args);
|
|
|
|
#else
|
|
|
|
//Format into msg
|
|
|
|
offset += vsprintf (msg + offset, format, args);
|
|
|
|
#endif
|
|
|
|
va_end(args);
|
|
|
|
|
2011-08-19 00:45:01 +08:00
|
|
|
if (debugfp == NULL && strlen (debug_file.string ()) > 0) {
|
2011-08-12 05:42:13 +08:00
|
|
|
debugfp = fopen (debug_file.string (), "wb");
|
2011-08-19 00:45:01 +08:00
|
|
|
} else if (debugfp != NULL && strlen (debug_file.string ()) == 0) {
|
2007-03-08 04:03:40 +08:00
|
|
|
fclose(debugfp);
|
|
|
|
debugfp = NULL;
|
|
|
|
}
|
|
|
|
if (debugfp != NULL)
|
2011-08-19 00:45:01 +08:00
|
|
|
fprintf(debugfp, "%s", msg);
|
|
|
|
else
|
|
|
|
fprintf(stderr, "%s", msg);
|
2009-07-11 10:50:24 +08:00
|
|
|
tesseract::tprintfMutex.Unlock();
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* pause_continue()
|
|
|
|
* UI for a debugging pause - to see an intermediate state
|
|
|
|
* Returns TRUE to continue as normal to the next pause in the current mode;
|
|
|
|
* FALSE to quit the current pausing mode.
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
DLLSYM BOOL8
|
|
|
|
//special message
|
|
|
|
pause_continue (const char *format, ...
|
|
|
|
) {
|
|
|
|
va_list args; //variable args
|
|
|
|
char msg[1000];
|
|
|
|
STRING str = STRING ("DEBUG PAUSE:\n");
|
|
|
|
|
|
|
|
va_start(args, format); //variable list
|
|
|
|
vsprintf(msg, format, args); //Format into msg
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
#ifdef GRAPHICS_DISABLED
|
|
|
|
// No interaction allowed -> simply go on
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
|
|
|
|
#ifdef __UNIX__
|
|
|
|
printf ("%s\n", msg);
|
|
|
|
printf ("Type \"c\" to cancel, anything else to continue: ");
|
|
|
|
char c = getchar ();
|
|
|
|
return (c != 'c');
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __MSW32__
|
|
|
|
str +=
|
|
|
|
STRING (msg) + STRING ("\nUse OK to continue, CANCEL to stop pausing");
|
|
|
|
// return AfxMessageBox( str.string(), MB_OKCANCEL ) == IDOK;
|
|
|
|
return::MessageBox (NULL, msg, "IMGAPP",
|
|
|
|
MB_APPLMODAL | MB_OKCANCEL) == IDOK;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|