Annotation of hatari/src/log.c, revision 1.1.1.3

1.1       root        1: /*
                      2:   Hatari - log.c
                      3: 
                      4:   This file is distributed under the GNU Public License, version 2 or at
                      5:   your option any later version. Read the file gpl.txt for details.
                      6: 
                      7:   Logger functions.
                      8: 
                      9:   When Hatari runs, it can output information, debug, warning and error texts
                     10:   to the error log file and/or displays them in alert dialog boxes.
                     11: */
1.1.1.3 ! root       12: const char Log_rcsid[] = "Hatari $Id: log.c,v 1.5 2007/02/25 21:20:10 eerot Exp $";
1.1       root       13: 
                     14: #include <stdio.h>
                     15: #include <stdarg.h>
                     16: 
                     17: #include "main.h"
                     18: #include "configuration.h"
                     19: #include "dialog.h"
                     20: #include "log.h"
                     21: #include "screen.h"
1.1.1.3 ! root       22: #include "file.h"
1.1       root       23: 
                     24: static FILE *hLogFile = NULL;
                     25: 
                     26: 
                     27: /*-----------------------------------------------------------------------*/
1.1.1.3 ! root       28: /**
        !            29:  * Initialize the logging functions (open the log file etc.).
        !            30:  */
1.1       root       31: void Log_Init(void)
                     32: {
1.1.1.3 ! root       33:        hLogFile = File_Open(ConfigureParams.Log.sLogFileName, "w");
1.1       root       34: }
                     35: 
                     36: 
                     37: /*-----------------------------------------------------------------------*/
1.1.1.3 ! root       38: /**
        !            39:  * Un-Initialize - close error log file etc.
        !            40:  */
1.1       root       41: void Log_UnInit(void)
                     42: {
1.1.1.3 ! root       43:        hLogFile = File_Close(hLogFile);
1.1       root       44: }
                     45: 
                     46: 
                     47: /*-----------------------------------------------------------------------*/
1.1.1.3 ! root       48: /**
        !            49:  * Output string to log file
        !            50:  */
1.1       root       51: void Log_Printf(LOGTYPE nType, const char *psFormat, ...)
                     52: {
                     53:        va_list argptr;
                     54: 
                     55:        if (hLogFile && (int)nType <= ConfigureParams.Log.nTextLogLevel)
                     56:        {
                     57:                va_start(argptr, psFormat);
                     58:                vfprintf(hLogFile, psFormat, argptr);
                     59:                va_end(argptr);
                     60:        }
                     61: }
                     62: 
                     63: 
                     64: /*-----------------------------------------------------------------------*/
1.1.1.3 ! root       65: /**
        !            66:  * Show logging alert dialog box and output string to log file
        !            67:  */
1.1       root       68: void Log_AlertDlg(LOGTYPE nType, const char *psFormat, ...)
                     69: {
                     70:        va_list argptr;
                     71: 
                     72:        /* Output to log file: */
                     73:        if (hLogFile && (int)nType <= ConfigureParams.Log.nTextLogLevel)
                     74:        {
                     75:                va_start(argptr, psFormat);
                     76:                vfprintf(hLogFile, psFormat, argptr);
                     77:                va_end(argptr);
                     78:                /* Add a new-line if necessary: */
                     79:                if (psFormat[strlen(psFormat)-1] != '\n')
                     80:                        fputs("\n", hLogFile);
                     81:        }
                     82: 
                     83:        /* Show alert dialog box: */
                     84:        if (sdlscrn && (int)nType <= ConfigureParams.Log.nAlertDlgLogLevel)
                     85:        {
                     86:                char *psTmpBuf;
                     87:                psTmpBuf = malloc(2048);
                     88:                if (!psTmpBuf)
                     89:                {
                     90:                        perror("Log_AlertDlg");
                     91:                        return;
                     92:                }
                     93:                va_start(argptr, psFormat);
                     94:                vsnprintf(psTmpBuf, 2048, psFormat, argptr);
                     95:                va_end(argptr);
                     96:                DlgAlert_Notice(psTmpBuf);
                     97:                free(psTmpBuf);
                     98:        }
                     99: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.