Ignore:
Timestamp:
Oct 26, 1999, 7:53:43 PM (26 years ago)
Author:
sandervl
Message:

log fixes (FS)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/dsound/misc.cpp

    r1421 r1456  
     1/* $Id: misc.cpp,v 1.2 1999-10-26 17:53:43 sandervl Exp $ */
    12#define INCL_BASE
    23#define INCL_WIN
     
    89#include <string.h>
    910#include <stdarg.h>
    10 #include "misc.h"
    11 
     11#include <misc.h>
     12#include "initterm.h"
    1213
    1314//#define PMPRINTF
     
    235236
    236237
    237 #if 1   /*PLF Mon  97-09-08 20:04:28*/
     238/*****************************************************************************
     239 * Standard Version                                                          *
     240 *****************************************************************************/
     241
    238242static FILE *flog = NULL;   /*PLF Mon  97-09-08 20:00:15*/
    239243static BOOL init = FALSE;
     244static BOOL fLogging = TRUE;
    240245
    241246int SYSTEM EXPORT WriteLog(char *tekst, ...)
    242247{
     248  USHORT  sel = RestoreOS2FS();
    243249  va_list argptr;
     250
    244251  if(!init)
    245252  {
    246253    init = TRUE;
    247     if(!getenv("NODSOUNDLOG"))
    248       flog = fopen("DSOUND.log", "w");
    249   }
    250 
    251   if(flog)
     254
     255    if(!getenv("NODSOUNDLOG")) {
     256        char logname[CCHMAXPATH];
     257
     258        flog = fopen("DSOUND.log", "w");
     259        if(flog == NULL) {//probably running exe on readonly device
     260                sprintf(logname, "%sdsound.log", dsoundPath);
     261                flog = fopen(logname, "w");
     262        }
     263    }
     264    else
     265      fLogging = FALSE;
     266  }
     267
     268  if(fLogging && flog)
    252269  {
    253      va_start(argptr, tekst);
    254      vfprintf(flog, tekst, argptr);
    255      va_end(argptr);
    256      fflush(flog);
    257   }
     270    va_start(argptr, tekst);
     271    vfprintf(flog, tekst, argptr);
     272    va_end(argptr);
     273
     274    if(tekst[strlen(tekst)-1] != '\n')
     275      fprintf(flog, "\n");
     276  }
     277
     278  SetFS(sel);
    258279  return 1;
    259280}
    260 #else   /*PLF Mon  97-09-08 20:04:26*/
    261 /******************************************************************************/
    262 static BOOL init = FALSE;
    263 static BOOL fLog = TRUE;
    264 /******************************************************************************/
    265 int SYSTEM EXPORT WriteLog(char *tekst, ...)
    266 {
    267   ULONG Action, Wrote;
    268   HFILE log;
    269   APIRET rc;
    270   char message[4096];
    271   va_list argptr;
    272   ULONG openFlags = OPEN_ACTION_CREATE_IF_NEW;
    273 
    274   if(fLog == FALSE)
    275     return(FALSE);
    276 
    277   if(!init)
    278   {
    279     init = TRUE;
    280     openFlags |= OPEN_ACTION_REPLACE_IF_EXISTS;
    281     if(getenv("NOWIN32LOG"))
    282       fLog = FALSE;
    283   }
    284   else
    285     openFlags |= OPEN_ACTION_OPEN_IF_EXISTS;
    286 
    287   rc = DosOpen( "win32os2.log",
    288                 &log,           /* file handle returned */
    289                 &Action,
    290                 0L,
    291                 FILE_NORMAL,
    292                 openFlags,
    293                 OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYWRITE,
    294                 (PEAOP2)NULL);
    295 
    296    rc = DosSetFilePtr(log, 0, FILE_END, &Wrote);
    297    va_start(argptr, tekst);
    298    vsprintf(message, tekst, argptr);
    299    va_end(argptr);
    300 
    301    rc = DosWrite(log, message, strlen(message), &Wrote);
    302 
    303    DosClose(log);   /*PLF Mon  97-09-08 20:01:43*/
    304    return(TRUE);
     281//******************************************************************************
     282//NOTE: No need to save/restore FS, as our FS selectors have already been
     283//      destroyed and FS == 0x150B.
     284//******************************************************************************
     285void CloseLogFile()
     286{
     287  fclose(flog);
     288  flog = 0;
    305289}
    306 #endif  /*PLF Mon  97-09-08 20:04:23*/
    307 /******************************************************************************/
    308 /******************************************************************************/
    309 
    310 
    311290#endif
Note: See TracChangeset for help on using the changeset viewer.