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

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: */
                     12: char Log_rcsid[] = "Hatari $Id: log.c,v 1.2 2005/06/05 14:19:39 thothy Exp $";
                     13: 
                     14: #include <stdio.h>
                     15: #include <stdarg.h>
                     16: #include <errno.h>
                     17: 
                     18: #include "main.h"
                     19: #include "configuration.h"
                     20: #include "dialog.h"
                     21: #include "log.h"
                     22: #include "screen.h"
                     23: 
                     24: 
                     25: static FILE *hLogFile = NULL;
                     26: 
                     27: 
                     28: /*-----------------------------------------------------------------------*/
                     29: /*
                     30:   Initialize the logging functions (open the log file etc.).
                     31: */
                     32: void Log_Init(void)
                     33: {
                     34:        /* First check for "stdout" and "stderr" which are special */
                     35:        if (!strcmp(ConfigureParams.Log.sLogFileName, "stdout"))
                     36:        {
                     37:                hLogFile = stdout;
                     38:        }
                     39:        else if (!strcmp(ConfigureParams.Log.sLogFileName, "stderr"))
                     40:        {
                     41:                hLogFile = stderr;
                     42:        }
                     43:        else
                     44:        {
                     45:                /* Open a normal log file */
                     46:                hLogFile = fopen(ConfigureParams.Log.sLogFileName, "w");
                     47:                if (!hLogFile)
                     48:                        fprintf(stderr, "Can't open log file %s: %s\n",
                     49:                                ConfigureParams.Log.sLogFileName, strerror(errno));
                     50:        }
                     51: }
                     52: 
                     53: 
                     54: /*-----------------------------------------------------------------------*/
                     55: /*
                     56:   Un-Initialize - close error log file etc.
                     57: */
                     58: void Log_UnInit(void)
                     59: {
                     60:        if (hLogFile && hLogFile != stdout && hLogFile != stderr)
                     61:        {
                     62:                fclose(hLogFile);
                     63:        }
                     64:        hLogFile = NULL;
                     65: }
                     66: 
                     67: 
                     68: /*-----------------------------------------------------------------------*/
                     69: /*
                     70:   Output string to log file
                     71: */
                     72: void Log_Printf(LOGTYPE nType, const char *psFormat, ...)
                     73: {
                     74:        va_list argptr;
                     75: 
                     76:        if (hLogFile && (int)nType <= ConfigureParams.Log.nTextLogLevel)
                     77:        {
                     78:                va_start(argptr, psFormat);
                     79:                vfprintf(hLogFile, psFormat, argptr);
                     80:                va_end(argptr);
                     81:        }
                     82: }
                     83: 
                     84: 
                     85: /*-----------------------------------------------------------------------*/
                     86: /*
                     87:   Show logging alert dialog box and output string to log file
                     88: */
                     89: void Log_AlertDlg(LOGTYPE nType, const char *psFormat, ...)
                     90: {
                     91:        va_list argptr;
                     92: 
                     93:        /* Output to log file: */
                     94:        if (hLogFile && (int)nType <= ConfigureParams.Log.nTextLogLevel)
                     95:        {
                     96:                va_start(argptr, psFormat);
                     97:                vfprintf(hLogFile, psFormat, argptr);
                     98:                va_end(argptr);
                     99:                /* Add a new-line if necessary: */
                    100:                if (psFormat[strlen(psFormat)-1] != '\n')
                    101:                        fputs("\n", hLogFile);
                    102:        }
                    103: 
                    104:        /* Show alert dialog box: */
                    105:        if (sdlscrn && (int)nType <= ConfigureParams.Log.nAlertDlgLogLevel)
                    106:        {
                    107:                char *psTmpBuf;
                    108:                psTmpBuf = malloc(2048);
                    109:                if (!psTmpBuf)
                    110:                {
                    111:                        perror("Log_AlertDlg");
                    112:                        return;
                    113:                }
                    114:                va_start(argptr, psFormat);
                    115:                vsnprintf(psTmpBuf, 2048, psFormat, argptr);
                    116:                va_end(argptr);
                    117:                DlgAlert_Notice(psTmpBuf);
                    118:                free(psTmpBuf);
                    119:        }
                    120: }

unix.superglobalmegacorp.com

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