コード例 #1
0
ファイル: logfile.c プロジェクト: tedhale/hottub
/*
   Log

   Writes a message to the previously opened log file.

   Passed in a format string and variable number of parameters,
   in the format used by printf.
*/
void Log(char *format, ... ) 
{
	char dtbuf[30];
	va_list arglist;
    struct tm *today;
    time_t now;

	time(&now);
    today = localtime(&now);

	if( Julian != today->tm_yday+1 ) {
		LogClose();
		LogOpen( FileName );
	}

	if (logfp==NULL) return;

	sprintf(dtbuf,"%02d/%02d/%04d %02d:%02d:%02d",today->tm_mon+1,today->tm_mday,
		today->tm_year+1900,today->tm_hour,today->tm_min,today->tm_sec);
	fprintf(logfp, "%5lu  %s ",LineNum++,dtbuf);
	va_start ( arglist, format );
	vfprintf (logfp, format, arglist );
	//if (format[strlen(format)-1]<' ')
		//format[strlen(format)-1] = 0;
	fprintf(logfp,"\r\n");
	fflush ( logfp );
}
コード例 #2
0
static void
at_exit_cleanup(void)
{
	listFini(&pattern_rules);
	VectorDestroy(report);
	LogClose();
	fini_db();
}
コード例 #3
0
ファイル: InitOutput.c プロジェクト: 4eremuxa/xserver
/* See Porting Layer Definition - p. 57 */
void
ddxGiveUp (enum ExitCode error)
{
  int		i;

#if CYGDEBUG
  winDebug ("ddxGiveUp\n");
#endif

  /* Perform per-screen deinitialization */
  for (i = 0; i < g_iNumScreens; ++i)
    {
      /* Delete the tray icon */
      if (!g_ScreenInfo[i].fNoTrayIcon && g_ScreenInfo[i].pScreen)
 	winDeleteNotifyIcon (winGetScreenPriv (g_ScreenInfo[i].pScreen));
    }

#ifdef XWIN_MULTIWINDOW
  /* Notify the worker threads we're exiting */
  winDeinitMultiWindowWM ();
#endif

#ifdef HAS_DEVWINDOWS
  /* Close our handle to our message queue */
  if (g_fdMessageQueue != WIN_FD_INVALID)
    {
      /* Close /dev/windows */
      close (g_fdMessageQueue);

      /* Set the file handle to invalid */
      g_fdMessageQueue = WIN_FD_INVALID;
    }
#endif

  if (!g_fLogInited) {
    g_pszLogFile = LogInit (g_pszLogFile, NULL);
    g_fLogInited = TRUE;
  }  
  LogClose (error);

  /*
   * At this point we aren't creating any new screens, so
   * we are guaranteed to not need the DirectDraw functions.
   */
  winReleaseDDProcAddresses();
  
  /* Free concatenated command line */
  free(g_pszCommandLine);
  g_pszCommandLine = NULL;

  /* Remove our keyboard hook if it is installed */
  winRemoveKeyboardHookLL ();

  /* Tell Windows that we want to end the app */
  PostQuitMessage (0);
}
コード例 #4
0
ファイル: job control.cpp プロジェクト: zootella/backup
// The job is done
void JobDone() {
    sectionitem section;

    // Change the stage
    if (Job.stage != JobStageRunning) return; // Can only stop when running
    Job.stage = JobStageDone;

    // Calculate how long the job took
    Job.time = GetTickCount() - Job.time;

    // Clear the last task it did, this would show up in status
    JobTask(L"");

    // Write the footer and close the error log file
    LogClose(Job.log);
}
コード例 #5
0
// main get called every time a process is spawned  
BOOL APIENTRY DllMain(HINSTANCE hModule,  DWORD  ul_reason_for_call, LPVOID lpReserved) {
	switch (ul_reason_for_call) {
	case DLL_PROCESS_ATTACH:
		DisableThreadLibraryCalls(hModule);
		hinstance = hModule;

		memset(&g_config, 0, sizeof(g_config));
		LoadConfig(g_config);

		{ //LG
		g_game.modX = (float)displaymode_options[g_config.displaymode].resX/640.0f;
		g_game.modY = (float)displaymode_options[g_config.displaymode].resY/480.0f;
		g_game.mod = (g_game.modX > g_game.modY ? g_game.modY : g_game.modX);
		float width = (float)displaymode_options[g_config.displaymode].resX;
		float height = (float)displaymode_options[g_config.displaymode].resY;

		if(g_game.modX > g_game.modY) {
			//4:3, 16:10, 16:9 etc.
			width = 640.0f*g_game.modY;
			if((UINT)(floor(width))%2==1) g_game.width = (DWORD)ceil(width);
			else g_game.width = (DWORD)floor(width);
			g_game.height = (DWORD)height;
		} else {
			//1:1, 1:2 etc. (not really used but it can never hurt...)
			g_game.width = (DWORD)width;
			height = 480.0f*g_game.modX;
			if((UINT)(floor(height))%2==1) g_game.height = (DWORD)ceil(height);
			else g_game.height = (DWORD)floor(height);
		}
		}

		Log("DLL injected into FF8.exe\n");
		HookAPICalls(DLLHooks, cDLLHooks);
		break;

	case DLL_THREAD_ATTACH:
		break;

	case DLL_THREAD_DETACH:
		break;

	case DLL_PROCESS_DETACH:
		LogClose();
		break;
	}
	return TRUE;
}
コード例 #6
0
ファイル: winerror.c プロジェクト: alown/xorg-server
/*
 * os/util.c/FatalError () calls our vendor ErrorF, so the message
 * from a FatalError will be logged.  Thus, the message for the
 * fatal error is not passed to this function.
 *
 * Attempt to do last-ditch, safe, important cleanup here.
 */
void
OsVendorFatalError(const char *f, va_list args)
{
    /* Don't give duplicate warning if UseMsg was called */
    if (g_fSilentFatalError)
        return;

    if (!g_fLogInited) {
        g_fLogInited = TRUE;
        g_pszLogFile = LogInit(g_pszLogFile, NULL);
    }
    LogClose(EXIT_ERR_ABORT);

    winMessageBoxF("A fatal error has occurred and " PROJECT_NAME
                   " will now exit.\n" "Please open %s for more information.\n",
                   MB_ICONERROR, (g_pszLogFile ? g_pszLogFile : "the logfile"));
}
コード例 #7
0
ファイル: log_io.cpp プロジェクト: rauls/iReporter
short ValidateFile( char *filetocheck )
{
	//struct	stat	fileStat;
	long	hnd;

	if ( IsURL( filetocheck ) ){
		return 1;
	} else {
		hnd = LogOpen( filetocheck, NULL );
	}
	//err = stat( filetocheck, &fileStat );

	if ( hnd ){
		LogClose( hnd, filetocheck );
		return 1;
	}
	return 0;
}
コード例 #8
0
int
LogOpen(const char *fname)
{
	LogClose();

	if (fname == NULL || strcmp("(standard error)", fname) == 0)
		logFile = stderr;

	else if (strcmp("(standard output)", fname) == 0)
		logFile = stdout;

	else if ((logFile = fopen(fname, "ab")) == NULL) {
		LogError("failed to open log file \"%s\"", fname);
		return -1;
	}
#if defined(__BORLANDC__) || defined(__CYGWIN__) || defined(__MINGW32__)
	setmode(fileno(logFile), O_BINARY);
#endif
	return 0;
}
コード例 #9
0
ファイル: InitOutput.c プロジェクト: csulmone/X11
/* See Porting Layer Definition - p. 57 */
void
ddxUseMsg(void)
{
    /* Set a flag so that FatalError won't give duplicate warning message */
    g_fSilentFatalError = TRUE;

    winUseMsg();

    /* Log file will not be opened for UseMsg unless we open it now */
    if (!g_fLogInited) {
        g_pszLogFile = LogInit(g_pszLogFile, NULL);
        g_fLogInited = TRUE;
    }
    LogClose(EXIT_NO_ERROR);

    /* Notify user where UseMsg text can be found. */
    if (!g_fNoHelpMessageBox)
        winMessageBoxF("The " PROJECT_NAME " help text has been printed to "
                       "%s.\n"
                       "Please open %s to read the help text.\n",
                       MB_ICONINFORMATION, g_pszLogFile, g_pszLogFile);
}
コード例 #10
0
ファイル: winerror.c プロジェクト: Agnesa/xserver
/*
 * os/log.c:FatalError () calls our vendor ErrorF, so the message
 * from a FatalError will be logged.
 *
 * Attempt to do last-ditch, safe, important cleanup here.
 */
void
OsVendorFatalError(const char *f, va_list args)
{
    char errormsg[1024] = "";

    /* Don't give duplicate warning if UseMsg was called */
    if (g_fSilentFatalError)
        return;

    if (!g_fLogInited) {
        g_fLogInited = TRUE;
        g_pszLogFile = LogInit(g_pszLogFile, NULL);
    }
    LogClose(EXIT_ERR_ABORT);

    /* Format the error message */
    vsnprintf(errormsg, sizeof(errormsg), f, args);

    /*
       Sometimes the error message needs a bit of cosmetic cleaning
       up for use in a dialog box...
     */
    {
        char *s;

        while ((s = strstr(errormsg, "\n\t")) != NULL) {
            s[0] = ' ';
            s[1] = '\n';
        }
    }

    winMessageBoxF("A fatal error has occurred and " PROJECT_NAME " will now exit.\n\n"
                   "%s\n\n"
                   "Please open %s for more information.\n",
                   MB_ICONERROR,
                   errormsg,
                   (g_pszLogFile ? g_pszLogFile : "the logfile"));
}
コード例 #11
0
ファイル: main.cpp プロジェクト: s-alexander/UPGM
void CleanUp()
{
	#ifdef ENABLE_BACKTRACE
		onexit();
	#endif
		sem_wait(&payguide::free_workers_lock);
		/* Cleaning up and exit */
		
		/* Clean operators rules */
		LoadModules(NULL);
		LoadOperators(NULL);
		
		if (payguide::modules_list!=NULL)
		{
			delete payguide::modules_list;
			payguide::modules_list=NULL;
		}
		if (payguide::operators_list!=NULL)
		{
			
			delete payguide::operators_list;
			payguide::operators_list=NULL;
		}
		
		if (payguide::workers_list!=NULL)
		{
			delete payguide::workers_list;
			payguide::workers_list=NULL;
		}
		UnLoadAllInitSO();
		
		
		LogWrite(LOGMSG_SYSTEM, "(Clean up complete sucessful.)");
		LogClose();
		sem_post(&payguide::free_workers_lock);
		
}
コード例 #12
0
ファイル: dbi.cpp プロジェクト: mingpen/OpenNT
DBI1::~DBI1()
{
#if defined(INSTRUMENTED)
    if (log) {
        LogNoteEvent(log, "DBI", 0, letypeEvent,
                     "cModules:%d cSymbols:%d cTypesMapped:%d",
                     info.cModules, info.cSymbols, info.cTypesMapped);
        LogNoteEvent(log, "DBI", 0, letypeEvent,
                     "cTypesMappedRec.:%d cTypesQueried:%d cTypesAdded:%d",
                     info.cTypesMappedRecursively, info.cTypesQueried, info.cTypesAdded);
        LogNoteEvent(log, "DBI", 0, letypeEvent, "cTMTS:%d cTMR:%d cTMPCT:%d",
                     info.cTMTS, info.cTMR, info.cTMPCT);
        LogNoteEvent(log, "DBI", 0, letypeEnd, 0);
        LogClose(log);
    }
#endif

#ifdef INSTRUMENTED
	DumpSymbolPages();
#endif

	if (potmTSHead)
		delete potmTSHead;
	if (potmPCTHead)
		delete potmPCTHead;

    // dtor pmodi's
    for (IMOD imod = 0; imod < imodMac; imod++) {
        MODI* pmodi = pmodiForImod(imod);
        if (pmodi)
            pmodi->~MODI();
    }

    if (pbvSymRecPgs)
        delete pbvSymRecPgs;
}
コード例 #13
0
ファイル: engine.cpp プロジェクト: Alyoshak/wix3
extern "C" HRESULT EngineRun(
    __in HINSTANCE hInstance,
    __in_z_opt LPCWSTR wzCommandLine,
    __in int nCmdShow,
    __out DWORD* pdwExitCode
    )
{
    HRESULT hr = S_OK;
    BOOL fComInitialized = FALSE;
    BOOL fLogInitialized = FALSE;
    BOOL fRegInitialized = FALSE;
    BOOL fWiuInitialized = FALSE;
    BOOL fXmlInitialized = FALSE;
    OSVERSIONINFOEXW ovix = { };
    LPWSTR sczExePath = NULL;
    BOOL fRunNormal = FALSE;
    BOOL fRestart = FALSE;

    BURN_ENGINE_STATE engineState = { };

    hr = InitializeEngineState(&engineState);
    ExitOnFailure(hr, "Failed to initialize engine state.");

    engineState.command.nCmdShow = nCmdShow;

    // Ensure that log contains approriate level of information
#ifdef _DEBUG
    LogSetLevel(REPORT_DEBUG, FALSE);
#else
    LogSetLevel(REPORT_VERBOSE, FALSE); // FALSE means don't write an additional text line to the log saying the level changed
#endif

    // initialize platform layer
    PlatformInitialize();

    // initialize COM
    hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
    ExitOnFailure(hr, "Failed to initialize COM.");
    fComInitialized = TRUE;

    // Initialize dutil.
    LogInitialize(::GetModuleHandleW(NULL));
    fLogInitialized = TRUE;

    hr = RegInitialize();
    ExitOnFailure(hr, "Failed to initialize Regutil.");
    fRegInitialized = TRUE;

    hr = WiuInitialize();
    ExitOnFailure(hr, "Failed to initialize Wiutil.");
    fWiuInitialized = TRUE;

    hr = XmlInitialize();
    ExitOnFailure(hr, "Failed to initialize XML util.");
    fXmlInitialized = TRUE;

    ovix.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
    if (!::GetVersionExW((LPOSVERSIONINFOW)&ovix))
    {
        ExitWithLastError(hr, "Failed to get OS info.");
    }

    PathForCurrentProcess(&sczExePath, NULL); // Ignore failure.
    LogId(REPORT_STANDARD, MSG_BURN_INFO, szVerMajorMinorBuild, ovix.dwMajorVersion, ovix.dwMinorVersion, ovix.dwBuildNumber, ovix.wServicePackMajor, sczExePath, wzCommandLine ? wzCommandLine : L"");
    ReleaseNullStr(sczExePath);

    // initialize core
    hr = CoreInitialize(wzCommandLine, &engineState);
    ExitOnFailure(hr, "Failed to initialize core.");

    // select run mode
    switch (engineState.mode)
    {
    case BURN_MODE_NORMAL:
        fRunNormal = TRUE;

        hr = RunNormal(hInstance, &engineState);
        ExitOnFailure(hr, "Failed to run per-user mode.");
        break;

    case BURN_MODE_ELEVATED:
        hr = RunElevated(hInstance, wzCommandLine, &engineState);
        ExitOnFailure(hr, "Failed to run per-machine mode.");
        break;

    case BURN_MODE_EMBEDDED:
        fRunNormal = TRUE;

        hr = RunEmbedded(hInstance, &engineState);
        ExitOnFailure(hr, "Failed to run embedded mode.");
        break;

    case BURN_MODE_RUNONCE:
        hr = RunRunOnce(wzCommandLine, nCmdShow);
        ExitOnFailure(hr, "Failed to run RunOnce mode.");
        break;

    default:
        hr = E_UNEXPECTED;
        ExitOnFailure(hr, "Invalid run mode.");
    }

    // set exit code and remember if we are supposed to restart.
    *pdwExitCode = engineState.userExperience.dwExitCode;
    fRestart = engineState.fRestart;

LExit:
    ReleaseStr(sczExePath);

    // If anything went wrong but the log was never open, try to open a "failure" log
    // and that will dump anything captured in the log memory buffer to the log.
    if (FAILED(hr) && BURN_LOGGING_STATE_CLOSED == engineState.log.state)
    {
        LogOpen(NULL, L"Setup", L"_Failed", L"txt", FALSE, FALSE, NULL);
    }

    UserExperienceRemove(&engineState.userExperience);

    CacheRemoveWorkingFolder(engineState.registration.sczId);

    // If this is a related bundle (but not an update) suppress restart and return the standard restart error code.
    if (fRestart && BOOTSTRAPPER_RELATION_NONE != engineState.command.relationType && BOOTSTRAPPER_RELATION_UPDATE != engineState.command.relationType)
    {
        LogId(REPORT_STANDARD, MSG_RESTART_ABORTED, LoggingRelationTypeToString(engineState.command.relationType));

        fRestart = FALSE;
        hr = HRESULT_FROM_WIN32(ERROR_SUCCESS_REBOOT_REQUIRED);
    }

    UninitializeEngineState(&engineState);

    if (fXmlInitialized)
    {
        XmlUninitialize();
    }

    if (fWiuInitialized)
    {
        WiuUninitialize();
    }

    if (fRegInitialized)
    {
        RegUninitialize();
    }

    if (fComInitialized)
    {
        ::CoUninitialize();
    }

    if (fRunNormal)
    {
        LogId(REPORT_STANDARD, MSG_EXITING, FAILED(hr) ? (int)hr : *pdwExitCode, LoggingBoolToString(fRestart));

        if (fRestart)
        {
            LogId(REPORT_STANDARD, MSG_RESTARTING);
        }
    }

    if (fLogInitialized)
    {
        LogClose(FALSE);
    }

    if (fRestart)
    {
        Restart();
    }

    if (fLogInitialized)
    {
        LogUninitialize(FALSE);
    }

    return hr;
}
コード例 #14
0
ファイル: signal-logging.c プロジェクト: MrKepzie/xserver
static void logging_format(void)
{
    const char *log_file_path = "/tmp/Xorg-logging-test.log";
    const char *str = "%s %d %u %% %p %i";
    char buf[1024];
    int i;
    unsigned int ui;
    long li;
    unsigned long lui;
    FILE *f;
    char read_buf[2048];
    char *logmsg;
    uintptr_t ptr;

    /* set up buf to contain ".....end" */
    memset(buf, '.', sizeof(buf));
    strcpy(&buf[sizeof(buf) - 4], "end");

    LogInit(log_file_path, NULL);
    assert(f = fopen(log_file_path, "r"));

#define read_log_msg(msg) \
    fgets(read_buf, sizeof(read_buf), f); \
    msg = strchr(read_buf, ']') + 2; /* advance past [time.stamp] */

    /* boring test message */
    LogMessageVerbSigSafe(X_ERROR, -1, "test message\n");
    read_log_msg(logmsg);
    assert(strcmp(logmsg, "(EE) test message\n") == 0);

    /* long buf is truncated to "....en\n" */
    LogMessageVerbSigSafe(X_ERROR, -1, buf);
    read_log_msg(logmsg);
    assert(strcmp(&logmsg[strlen(logmsg) - 3], "en\n") == 0);

    /* same thing, this time as string substitution */
    LogMessageVerbSigSafe(X_ERROR, -1, "%s", buf);
    read_log_msg(logmsg);
    assert(strcmp(&logmsg[strlen(logmsg) - 3], "en\n") == 0);

    /* strings containing placeholders should just work */
    LogMessageVerbSigSafe(X_ERROR, -1, "%s\n", str);
    read_log_msg(logmsg);
    assert(strcmp(logmsg, "(EE) %s %d %u %% %p %i\n") == 0);

    /* literal % */
    LogMessageVerbSigSafe(X_ERROR, -1, "test %%\n");
    read_log_msg(logmsg);
    assert(strcmp(logmsg, "(EE) test %\n") == 0);

    /* character */
    LogMessageVerbSigSafe(X_ERROR, -1, "test %c\n", 'a');
    read_log_msg(logmsg);
    assert(strcmp(logmsg, "(EE) test a\n") == 0);

    /* something unsupported % */
    LogMessageVerbSigSafe(X_ERROR, -1, "test %Q\n");
    read_log_msg(logmsg);
    assert(strstr(logmsg, "BUG") != NULL);
    LogMessageVerbSigSafe(X_ERROR, -1, "\n");
    fseek(f, 0, SEEK_END);

    /* string substitution */
    LogMessageVerbSigSafe(X_ERROR, -1, "%s\n", "substituted string");
    read_log_msg(logmsg);
    assert(strcmp(logmsg, "(EE) substituted string\n") == 0);

    /* Invalid format */
    LogMessageVerbSigSafe(X_ERROR, -1, "%4", 4);
    read_log_msg(logmsg);
    assert(strcmp(logmsg, "(EE) ") == 0);
    LogMessageVerbSigSafe(X_ERROR, -1, "\n");
    fseek(f, 0, SEEK_END);

    /* %hld is bogus */
    LogMessageVerbSigSafe(X_ERROR, -1, "%hld\n", 4);
    read_log_msg(logmsg);
    assert(strstr(logmsg, "BUG") != NULL);
    LogMessageVerbSigSafe(X_ERROR, -1, "\n");
    fseek(f, 0, SEEK_END);

    /* number substitution */
    ui = 0;
    do {
        char expected[30];
        sprintf(expected, "(EE) %u\n", ui);
        LogMessageVerbSigSafe(X_ERROR, -1, "%u\n", ui);
        read_log_msg(logmsg);
        assert(strcmp(logmsg, expected) == 0);

        sprintf(expected, "(EE) %x\n", ui);
        LogMessageVerbSigSafe(X_ERROR, -1, "%x\n", ui);
        read_log_msg(logmsg);
        assert(strcmp(logmsg, expected) == 0);

        if (ui == 0)
            ui = 1;
        else
            ui <<= 1;
    } while(ui);

    lui = 0;
    do {
        char expected[30];
        sprintf(expected, "(EE) %lu\n", lui);
        LogMessageVerbSigSafe(X_ERROR, -1, "%lu\n", lui);
        read_log_msg(logmsg);

        sprintf(expected, "(EE) %lld\n", (unsigned long long)ui);
        LogMessageVerbSigSafe(X_ERROR, -1, "%lld\n", (unsigned long long)ui);
        read_log_msg(logmsg);
        assert(strcmp(logmsg, expected) == 0);

        sprintf(expected, "(EE) %lx\n", lui);
        printf("%s\n", expected);
        LogMessageVerbSigSafe(X_ERROR, -1, "%lx\n", lui);
        read_log_msg(logmsg);
        assert(strcmp(logmsg, expected) == 0);

        sprintf(expected, "(EE) %llx\n", (unsigned long long)ui);
        LogMessageVerbSigSafe(X_ERROR, -1, "%llx\n", (unsigned long long)ui);
        read_log_msg(logmsg);
        assert(strcmp(logmsg, expected) == 0);

        if (lui == 0)
            lui = 1;
        else
            lui <<= 1;
    } while(lui);

    /* signed number substitution */
    i = 0;
    do {
        char expected[30];
        sprintf(expected, "(EE) %d\n", i);
        LogMessageVerbSigSafe(X_ERROR, -1, "%d\n", i);
        read_log_msg(logmsg);
        assert(strcmp(logmsg, expected) == 0);

        sprintf(expected, "(EE) %d\n", i | INT_MIN);
        LogMessageVerbSigSafe(X_ERROR, -1, "%d\n", i | INT_MIN);
        read_log_msg(logmsg);
        assert(strcmp(logmsg, expected) == 0);

        if (i == 0)
            i = 1;
        else
            i <<= 1;
    } while(i > INT_MIN);

    li = 0;
    do {
        char expected[30];
        sprintf(expected, "(EE) %ld\n", li);
        LogMessageVerbSigSafe(X_ERROR, -1, "%ld\n", li);
        read_log_msg(logmsg);
        assert(strcmp(logmsg, expected) == 0);

        sprintf(expected, "(EE) %ld\n", li | LONG_MIN);
        LogMessageVerbSigSafe(X_ERROR, -1, "%ld\n", li | LONG_MIN);
        read_log_msg(logmsg);
        assert(strcmp(logmsg, expected) == 0);

        sprintf(expected, "(EE) %lld\n", (long long)li);
        LogMessageVerbSigSafe(X_ERROR, -1, "%lld\n", (long long)li);
        read_log_msg(logmsg);
        assert(strcmp(logmsg, expected) == 0);

        sprintf(expected, "(EE) %lld\n", (long long)(li | LONG_MIN));
        LogMessageVerbSigSafe(X_ERROR, -1, "%lld\n", (long long)(li | LONG_MIN));
        read_log_msg(logmsg);
        assert(strcmp(logmsg, expected) == 0);

        if (li == 0)
            li = 1;
        else
            li <<= 1;
    } while(li > LONG_MIN);


    /* pointer substitution */
    /* we print a null-pointer differently to printf */
    LogMessageVerbSigSafe(X_ERROR, -1, "%p\n", NULL);
    read_log_msg(logmsg);
    assert(strcmp(logmsg, "(EE) 0x0\n") == 0);

    ptr = 1;
    do {
        char expected[30];
#ifdef __sun /* Solaris doesn't autoadd "0x" to %p format */
        sprintf(expected, "(EE) 0x%p\n", (void*)ptr);
#else
        sprintf(expected, "(EE) %p\n", (void*)ptr);
#endif
        LogMessageVerbSigSafe(X_ERROR, -1, "%p\n", (void*)ptr);
        read_log_msg(logmsg);
        assert(strcmp(logmsg, expected) == 0);
        ptr <<= 1;
    } while(ptr);


    for (i = 0; i < sizeof(float_tests)/sizeof(float_tests[0]); i++) {
        double d = float_tests[i];
        char expected[30];
        sprintf(expected, "(EE) %.2f\n", d);
        LogMessageVerbSigSafe(X_ERROR, -1, "%f\n", d);
        read_log_msg(logmsg);
        assert(strcmp(logmsg, expected) == 0);

        /* test for length modifiers, we just ignore them atm */
        LogMessageVerbSigSafe(X_ERROR, -1, "%.3f\n", d);
        read_log_msg(logmsg);
        assert(strcmp(logmsg, expected) == 0);

        LogMessageVerbSigSafe(X_ERROR, -1, "%3f\n", d);
        read_log_msg(logmsg);
        assert(strcmp(logmsg, expected) == 0);

        LogMessageVerbSigSafe(X_ERROR, -1, "%.0f\n", d);
        read_log_msg(logmsg);
        assert(strcmp(logmsg, expected) == 0);
    }


    LogClose(EXIT_NO_ERROR);
    unlink(log_file_path);

#undef read_log_msg
}
コード例 #15
0
ファイル: InitOutput.c プロジェクト: Agnarr/xserver
/* See Porting Layer Definition - p. 57 */
void
ddxGiveUp (void)
{
  int		i;

#if CYGDEBUG
  winDebug ("ddxGiveUp\n");
#endif

  /* Perform per-screen deinitialization */
  for (i = 0; i < g_iNumScreens; ++i)
    {
      /* Delete the tray icon */
      if (!g_ScreenInfo[i].fNoTrayIcon && g_ScreenInfo[i].pScreen)
 	winDeleteNotifyIcon (winGetScreenPriv (g_ScreenInfo[i].pScreen));
    }

#ifdef XWIN_MULTIWINDOW
  /* Notify the worker threads we're exiting */
  winDeinitMultiWindowWM ();
#endif

#ifdef HAS_DEVWINDOWS
  /* Close our handle to our message queue */
  if (g_fdMessageQueue != WIN_FD_INVALID)
    {
      /* Close /dev/windows */
      close (g_fdMessageQueue);

      /* Set the file handle to invalid */
      g_fdMessageQueue = WIN_FD_INVALID;
    }
#endif

  if (!g_fLogInited) {
    g_pszLogFile = LogInit (g_pszLogFile, NULL);
    g_fLogInited = TRUE;
  }  
  LogClose ();

  /*
   * At this point we aren't creating any new screens, so
   * we are guaranteed to not need the DirectDraw functions.
   */
  if (g_hmodDirectDraw != NULL)
    {
      FreeLibrary (g_hmodDirectDraw);
      g_hmodDirectDraw = NULL;
      g_fpDirectDrawCreate = NULL;
      g_fpDirectDrawCreateClipper = NULL;
    }

  /* Unload our TrackMouseEvent funtion pointer */
  if (g_hmodCommonControls != NULL)
    {
      FreeLibrary (g_hmodCommonControls);
      g_hmodCommonControls = NULL;
      g_fpTrackMouseEvent = (FARPROC) (void (*)(void))NoopDDA;
    }
  
  /* Free concatenated command line */
  free(g_pszCommandLine);
  g_pszCommandLine = NULL;

  /* Remove our keyboard hook if it is installed */
  winRemoveKeyboardHookLL ();

  /* Tell Windows that we want to end the app */
  PostQuitMessage (0);
}
コード例 #16
0
ファイル: window.cpp プロジェクト: aaedev/bmfontgl
// Simple, generic window init //
int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int iCmdShow)
{
	WNDCLASS wc;

	MSG msg;
	bool Quit = FALSE;
	DWORD       dwExStyle;                      // Window Extended Style
	DWORD       dwStyle;                        // Window Style

	// register window class
	wc.style = CS_OWNDC;
	wc.lpfnWndProc = WndProc;
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hInstance = hInstance;
	wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
	wc.lpszMenuName = NULL;
	wc.lpszClassName = L"BMFontGL";
	RegisterClass(&wc);

	dwExStyle = WS_EX_APPWINDOW;   // Window Extended Style    
	dwStyle = WS_OVERLAPPEDWINDOW | WS_THICKFRAME;                    // Windows Style
	RECT WindowRect;                                                 // Grabs Rectangle Upper Left / Lower Right Values
	WindowRect.left = (long)0;                                         // Set Left Value To 0
	WindowRect.right = (long)WinWidth;                                 // Set Right Value To Requested Width
	WindowRect.top = (long)0;                                          // Set Top Value To 0
	WindowRect.bottom = (long)WinHeight;                               // Set Bottom Value To Requested Height
	AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);      // Adjust Window To True Requested Size


	// Create The Window
	if (!(hWnd = CreateWindowEx(dwExStyle,							// Extended Style For The Window
		L"BMFontGL",							// Class Name
		L"OpenGL BMFont Sample Implementation",						// Window Title
		dwStyle |							// Defined Window Style
		WS_CLIPSIBLINGS |					// Required Window Style
		WS_CLIPCHILDREN,					// Required Window Style
		CW_USEDEFAULT, 0,   				// Window Position
		WindowRect.right - WindowRect.left,	// Calculate Window Width
		WindowRect.bottom - WindowRect.top,	// Calculate Window Height
		NULL,								// No Parent Window
		NULL,								// No Menu
		hInstance,							// Instance
		NULL)))								// Dont Pass Anything To WM_CREATE
	{
		// Reset The Display
		MessageBox(NULL, L"Window Creation Error.", L"ERROR", MB_OK | MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

	//********** Program Initializations *************
	//Enable Logging
	LogOpen("glfonttest.log");
	// enable OpenGL for the window
	CreateGLContext();
	//Basic Window Init
	WRLOG("Starting Program");
	ShowWindow(hWnd, SW_SHOW);                                         // Show The Window
	SetForegroundWindow(hWnd);									    // Slightly Higher Priority
	SetFocus(hWnd);													// Sets Keyboard Focus To The Window
	ReSizeGLScene(WinWidth, WinHeight);										    // Set Up Our Perspective GL Screen
	//Get the Supported OpenGl Version
	CheckGLVersionSupport();
	//Fill in the Window Rect;
	GetClientRect(hWnd, &MyWindow);
	//Set the OpenGl View
	ViewOrtho(WinWidth, WinHeight);

	//Load and Initialize the Fonts
	wrlog("Starting to parse fonts.");

	Lucida = new BMFont(WinWidth, WinHeight);
	if (!Lucida->LoadFont("lucida.fnt"))
	{
		MessageBox(NULL, L"Error, font file not found, exiting", L"File Not Found", MB_ICONERROR | MB_OK);
		Quit = TRUE;
		//PostQuitMessage(-1);
	}
	LOG_DEBUG("Font Loaded Sucessfully");

	Snap = new BMFont(WinWidth, WinHeight);
	if (!Snap->LoadFont("snap.fnt"))
	{
		MessageBox(NULL, L"Error, font file not found, exiting", L"File Not Found", MB_ICONERROR | MB_OK);
		Quit = TRUE;
		//PostQuitMessage(-1);
	}
	LOG_DEBUG("Font Loaded Sucessfully");

	Times = new BMFont(WinWidth, WinHeight);
	if (!Times->LoadFont("times.fnt"))
	{
		MessageBox(NULL, L"Error, font file not found, exiting", L"File Not Found", MB_ICONERROR | MB_OK);
		Quit = TRUE;
		// PostQuitMessage(-1);
	}
	LOG_DEBUG("Font Loaded Sucessfully");

	// ********** Program Main Loop **********

	while (!Quit) {

		// check for messages
		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {

			// handle or dispatch messages
			if (msg.message == WM_QUIT) {
				Quit = TRUE;
			}
			else {
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}

		}
		else {

			// ********** OpenGL drawing code, very simple, just to show off the font. **********

			glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
			glClear(GL_COLOR_BUFFER_BIT);

			// setup texture mapping
			glEnable(GL_TEXTURE_2D);

			glLoadIdentity();
			Times->SetAlign(BMFont::AlignCenter);
			Times->SetScale(1.5f);
			Times->SetColor(250, 251, 252, 255);
			Times->Print(0, 280, "A different font, centered. Kerning: To Ti");

			/*
			Lucida->setColor(250,250,55,254);
			Lucida->PrintCenter(240,"This is another font.");

			Snap->setColor(255,255,255,255);
			Snap->setScale(1.0f);
			Snap->Print(0, 0, "This is standard printing.");
			*/
			Snap->SetColor(RGB_WHITE);
			Snap->SetAngle(0);
			Snap->SetScale(2.0f);
			Snap->SetAlign(BMFont::AlignNear);
			Snap->Print(40.0, 180, "Scaling makes it Big!");

			Snap->SetColor(RGB_WHITE);
			Snap->SetScale(1.0f);
			Snap->SetAngle(90);
			Snap->Print(130.0, 100, "The next line is right here.");
			Snap->SetAngle(0);
			Snap->Print(130.0, 350, "Another long line here.");
			/*
			Snap->setScale(1.0f);
			Snap->Print(2, Snap->getHeight()*4, "Or it can make it smaller!");
			Snap->setScale(1.0f);
			Snap->setColor(25,155,255,255);
			Snap->PrintCenter(320, "Centered printing: To Ti");
		   */
			Times->Render();
			Snap->Render();
			GlSwap();
		}
	}

	// ********** Cleanup and exit gracefully. **********
	// shutdown OpenGL
	delete Lucida;
	delete Snap;
	delete Times;
	DeleteGLContext();
	LogClose();
	// destroy the window 
	DestroyWindow(hWnd);

	return (int)msg.wParam;
}
コード例 #17
0
ファイル: log.c プロジェクト: klamonte/maximus
void cdecl logit(char *format,...)
{
  time_t gmtime;
  struct tm *localt;

  int size;
  char *string;
  char *string2;
  char screen_log;
  char *p;

  va_list var_args;

  int doit;

  /* We may be doing lots of debug logging during file transfers,
   * but don't waste any time if no logging is required.
   */

  if (*format=='@' && !debuglog)
    return;

  if ((string=malloc(LOGIT_SIZE+20))==NULL ||
      (string2=malloc(LOGIT_SIZE))==NULL)
  {
    if (string)
      free(string);
    
    Lputs(GRAY "\r! NoMem: ");
    Lputs(format);
    return;
  }
  
  va_start(var_args,format);
  size=vsprintf(string, format, var_args);
  va_end(var_args);

  /* Did we booboo? */

  if (size >= LOGIT_SIZE-20)
  {
    LogWrite("!****** FATAL: logit() too long.  Please report to author!\n");
    LogWrite("!****** Log was `");
    LogWrite(string);
    LogWrite("'!\n");

    LogFlush();
    LogClose();
    brkuntrap();
    uninstall_24();
    _exit(ERROR_CRITICAL);
  }

  p=string;

  if (*p=='>')
  {
    screen_log=TRUE;
    p++;
  }
  else screen_log=FALSE;

  gmtime=time(NULL);
  localt=localtime(&gmtime);

  doit=FALSE;

  switch(*p)
  {
    case '!':
      doit=TRUE;
      break;

    case '+':
      if (prm.log_mode >= 1)
        doit=TRUE;
      break;

    case '=':
      if (prm.log_mode >= 2)
        doit=TRUE;
      break;

    case ':':
      if (prm.log_mode >= 3)
        doit=TRUE;
      break;

    case '~':
      if (prm.log_mode >= 4)
        doit=TRUE;
      break;

    case '#':
      if (prm.log_mode >= 5)
        doit=TRUE;
      break;

    case '$':
      if (prm.log_mode >= 6)
        doit=TRUE;
      break;

    case ' ':     /* Never log these lines */
      if (prm.log_mode >= 7)
        doit=TRUE;
      break;

    case '@':
      doit=(int)debuglog;
      break;

    default:
      doit=TRUE;
      break;
  }

  /* Create abbreviated version of log string */

  sprintf(string2, "%c %02d:%02d:%02d %s\n",
          *p, localt->tm_hour, localt->tm_min, localt->tm_sec, p+1);


#ifdef MCP
  {
    extern HPIPE hpMCP;

    if (*string2 != '@')
      McpSendMsg(hpMCP, PMSG_LOG, string2, strlen(string2)+1);
  }
#endif


#ifdef MAXSNOOP
  if (*string2 != '@' || debuglog)
    SnWrite(string2);
#endif

  /* Now create real log entry */

  sprintf(string2, logformat, *p, localt->tm_mday, months_ab[localt->tm_mon],
          localt->tm_hour, localt->tm_min, localt->tm_sec, nameabbr, p+1);


  if (doit)
  {
    LogWrite(string2);

    /* Something fishy, make sure it stays on record! */

    if (*string=='!' /*|| *string=='@'*/)
      LogFlush();
    else
    {
      /* Flush each line regardless, if we're running a test version, since *
       * we may need this output if it crashes beforehand.                  */

      #if defined(FLUSH_LOG) && !defined(OS_2)
      LogFlush();
      #endif
    }
  }


  if (log_wfc && displaymode==VIDEO_IBM)
    WFC_LogMsg(string2);
  else if ((!snoop && !local) || !caller_online || in_file_xfer ||
            screen_log || *string2=='!')
  {
/*    if (*string2 != '@' || debuglog)*/
    if (*string2 != '@')
    {
      Lputs(GRAY "\r" CLEOL);
      Lputs(string2);
      vbuf_flush();
    }
  }

  free(string2);
  free(string);
}
コード例 #18
0
ファイル: postproc.cpp プロジェクト: rauls/iReporter
// This now supports gzip or bzip2 to compress with.
long CompressLogFiles( char **logfiles, long n, int type, int deletelog )
{
	long	count,  dataread, dataout, perc;
	char	newlogname[512],
			*logFN;
	long	failed = 1;

	for( count=0; count<n ; count++){
		logFN = logfiles[count];

		if ( strstr( logFN, ".gz" ) && type==0 )
			continue;
		if ( !IsURL(logFN) )
		{
			void *fp;
			void *outfp;
			char *ram, *p;
			long blocksize = 1024*32;

			StopAll( 0 );

			if ( ram = (char*)malloc( blocksize ) ){
				__int64 dataleft, length;

				if ( fp=(void*)LogOpen( logFN, &length ) ){
					int ret;

					sprintf( newlogname, "%s.gz", logFN );

					switch( type ){
						default:
						case COMPRESS_GZIP :
							sprintf( newlogname, "%s.gz", logFN );
							if ( p = strstr( newlogname, ".bz2" ) )
								mystrcpy( p, ".gz" );
							outfp = gzopen( newlogname, "wb6" );
							break;
#ifdef  _BZLIB_H
						// bzip2 is about 15X slower for 1/2 the size files, level6 is the best time-vs-size level roughly
						case COMPRESS_BZIP2 :
							sprintf( newlogname, "%s.bz2", logFN );
							if ( p = strstr( newlogname, ".gz" ) )
								mystrcpy( p, ".bz2" );
							outfp = BZ2_bzopen( newlogname, "wb6" );
							break;
#endif
					}

					dataout = 0;
					if ( outfp ){
						dataleft = length;
						dataread = 1;
						while( dataread>0 && !IsStopped() ){
							//OutDebugs( "dataleft = %d", dataleft );
							perc = (long)(100*((length-dataleft)/(float)length));
							//sprintf( msgtext, "Compressing %s ...", 100*((length-dataleft)/length) );
							ShowProgress( perc, FALSE, NULL );
							StatusSetID( IDS_COMPRESSING, perc, dataout/1024 );

							dataread = LogRead( fp, logFN, ram, blocksize );

							if ( dataread>0 )
							{
								dataleft -= dataread;
	
								if ( type == COMPRESS_GZIP )	dataout+=gzwrite( outfp, ram , dataread );
#ifdef _BZLIB_H
								if ( type == COMPRESS_BZIP2 )	dataout+=BZ2_bzwrite( outfp, ram , dataread );
#endif
							}
						}
						if ( type == COMPRESS_GZIP )	gzclose( outfp );
#ifdef _BZLIB_H
						if ( type == COMPRESS_BZIP2 )	BZ2_bzclose( outfp );
#endif
						if ( !IsStopped() ){
							__int64 newsize;
							FILE *newfp;
							failed = 0;
							if ( (newfp = fopen( newlogname, "ab+" )) ) {
								newsize = GetFPLength( newfp );

								if ( type == COMPRESS_BZIP2 ){
									long value;
									value = 0;
									fwrite( &value, 1, 4, newfp );
									value = (long)length;
									fwrite( &value, 1, 4, newfp );
								}
								fclose(newfp);
							}
							StatusSetID( IDS_COMPRESSDONE, dataout/1024, newsize/1024, 100*newsize/dataout );
						} else
							StatusSet( "Stopped" );

					}
					ret = LogClose( (long)fp, logFN );
					if ( deletelog && !failed){
						remove( logFN );
					}
				}
				free( ram );
			}
		}
	}
	return failed;
}
コード例 #19
0
ファイル: log_io.cpp プロジェクト: rauls/iReporter
// 990525 RS, get the log's raw filesize and log type
__int64 GetLogFileType( char *filename, long *type, long *date1, long *date2, LogSubFormat* logSubFormat/*=0*/ )
{
	DEF_ASSERT(type);

	// If its a URL or some external link, then dont get the info since its too slow
	// accept it as is.
	if ( strstr( filename, "ftp://" ) ||
		 strstr( filename, "http://" ) ||
		 IsFileaFolder( filename ) ||
		 IsURLShortCut( filename )
		){
		if ( date1 && date2 )
			*date1 = *date2 = *type = 0;
		return 0;
	}

	time_t logDays;
	__int64 fileSize;
	CQV5Database::Type v5DBType;

	if( CQV5Database::isV5Database( filename, &logDays, &fileSize, &v5DBType ) )
	{
		*type=LOGFORMAT_V5DATABASE;

		if( date1 )
		{
			*date1=logDays;
		}

		if( logSubFormat )
		{
			*logSubFormat=v5DBType==CQV5Database::Web ? LOGSUBFORMAT_V5DATABASE_WEB : LOGSUBFORMAT_V5DATABASE_STREAMING;
		}

		return fileSize;
	}

	if( logSubFormat )
	{
		*logSubFormat=LOGSUBFORMAT_UNKNOWN;
	}

	long fp=LogOpen( filename, &fileSize );

	if ( fp )
	{
		HitDataRec		Line;
		memset( &Line, 0, sizeof( HitDataRec ) );
		LogGetFormat( fp , &Line, filename );
		LogClose( fp, filename );

		if ( date1 && date2 )
		{
			struct tm		logDate;
			
			*date1 = *date2 = 0;
			if ( Line.date ){
				StringToDaysDate( Line.date, &logDate, 0);
				StringToDaysTime( Line.time, &logDate);
				Date2Days( &logDate, &logDays );
				*date1 = logDays;
			}
			if ( Line.vhost ){
				if ( Line.vhost[0] != '-' )
					logType |= FWA_VHOST_LOG_MASK;					
			}

		}
		*type = logType;
		logType = LOGFORMAT_UNKNOWN;
		return fileSize;
	}
	return -1;
}
コード例 #20
0
ファイル: xf86Helper.c プロジェクト: timon37/xwayland
void
xf86CloseLog(enum ExitCode error)
{
    LogClose(error);
}