Author Topic: Can I commit my DEBUG generator?  (Read 1413 times)

0 Members and 1 Guest are viewing this topic.

Offline RandomTiger

  • Senior Member
  • 211
Can I commit my DEBUG generator?
Hello. Me again. I've been having problems with my videos so I've bashed together a module for generating a debug file. Its been very useful to me so far. Debug build of fs2 crashes for me.

It can be compiled out very easily and is off by default.
Anyone got anything against me commiting it?
Its not meant to be efficent its meant to be quick and simple and powerful. Using this I can get people to run my exe and simply give me the resulting file.

I guess everyone thinks Im test mad but all my work has been graphical and:

# OS types * # gfx card types = so many potential errors :shaking:

heres the code:

-------------------------------------------------------------
Code: [Select]

#ifndef _DBUGFILE_HEADER_
#define _DBUGFILE_HEADER_

void dbugfile_init();
void dbugfile_deinit();
void dbugfile_sprintf(int line, char *file, const char *format, ...);

#ifdef DBUGFILE_ACTIVE

#define DBUGFILE_INIT()   dbugfile_init();
#define DBUGFILE_DEINIT() dbugfile_deinit();

#define DBUGFILE_OUTPUT_0(t) dbugfile_sprintf(__LINE__, __FILE__, t);
#define DBUGFILE_OUTPUT_1(t,a) dbugfile_sprintf(__LINE__, __FILE__, t,a);
#define DBUGFILE_OUTPUT_2(t,a,b) dbugfile_sprintf(__LINE__, __FILE__, t,a,b);
#define DBUGFILE_OUTPUT_3(t,a,b,c) dbugfile_sprintf(__LINE__, __FILE__, t,a,b,c);
#define DBUGFILE_OUTPUT_4(t,a,b,c,d) dbugfile_sprintf(__LINE__, __FILE__, t,a,b,c,d);
#define DBUGFILE_OUTPUT_5(t,a,b,c,d,e) dbugfile_sprintf(__LINE__, __FILE__, t,a,b,c,d,e);
#define DBUGFILE_OUTPUT_6(t,a,b,c,d,e,f) dbugfile_sprintf(__LINE__, __FILE__, t,a,b,c,d,e,f;
#define DBUGFILE_OUTPUT_7(t,a,b,c,d,e,f,g) dbugfile_sprintf(__LINE__, __FILE__, t,a,b,c,d,e,f,g);
#define DBUGFILE_OUTPUT_9(t,a,b,c,d,e,f,g,h) dbugfile_sprintf(__LINE__, __FILE__, t,a,b,c,d,e,f,g,h);

#else

#define DBUGFILE_INIT()   ;
#define DBUGFILE_DEINIT() ;

#define DBUGFILE_OUTPUT_0(t) ;
#define DBUGFILE_OUTPUT_1(t,a) ;
#define DBUGFILE_OUTPUT_2(t,a,b) ;
#define DBUGFILE_OUTPUT_3(t,a,b,c) ;
#define DBUGFILE_OUTPUT_4(t,a,b,c,d) ;
#define DBUGFILE_OUTPUT_5(t,a,b,c,d,e) ;
#define DBUGFILE_OUTPUT_6(t,a,b,c,d,e,f) ;
#define DBUGFILE_OUTPUT_7(t,a,b,c,d,e,f,g) ;
#define DBUGFILE_OUTPUT_9(t,a,b,c,d,e,f,g,h) ;

#endif

#endif

-------------------------------------------------------------

#ifdef _WIN32
#include
#endif

#include
#include
#include
#include

#include "dbugfile.h"

bool dbugfile_init_var = false;

char dbugfile_filename[512];

void dbugfile_output(char *buffer)
{
if(dbugfile_init_var == false)
{
return;
}


FILE *fp = fopen(dbugfile_filename, "a");

if(fp == NULL)
{
return;
}

fwrite(buffer, sizeof(char) * strlen(buffer), 1, fp);
fclose(fp);
}

void dbugfile_init()
{
char big_buffer[1000];
char temp_buff[512];

strcpy(dbugfile_filename, "DBUG-");
strcpy(big_buffer, "DBUGFILE Active: ");

#ifdef _WIN32
{
unsigned long len = 512;
GetUserName(temp_buff, &len);

strcat(dbugfile_filename, temp_buff);
strcat(big_buffer, temp_buff);

strcat(dbugfile_filename, "-");
strcat(big_buffer, " ");
}
#endif

    _tzset();

    // Display operating system-style date and time.
    _strtime( temp_buff);
strcat(dbugfile_filename, "(");
strcat(dbugfile_filename,temp_buff);
strcat(big_buffer,temp_buff);

strcat(dbugfile_filename, ")-(");
strcat(big_buffer, " ");
    _strdate( temp_buff);
strcat(dbugfile_filename,temp_buff);
strcat(big_buffer,temp_buff);

strcat(dbugfile_filename, ").txt");
strcat(big_buffer, "\n");

// Remove invalid slash chars
int len = strlen(dbugfile_filename);
while(len >= 0)
{
if(dbugfile_filename[len] == '/' || dbugfile_filename[len] == ':')
{
dbugfile_filename[len] = '-';
}
len--;
}

// open file
FILE *fp = fopen(dbugfile_filename, "w");

if(fp == NULL)
{
return;
}

fwrite(big_buffer, sizeof(char) * strlen(big_buffer), 1, fp);

#ifdef _WIN32

// detect OS type

OSVERSIONINFO version_info;
version_info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);

if(GetVersionEx(&version_info) != false)
{
char *error = "Error in detecting OS version";
char *version = error;

switch(version_info.dwMajorVersion)
{
case 4:
{
if(version_info.dwMinorVersion == 0)
{
version = "Windows 95";
}
else if(version_info.dwMinorVersion == 10)
{
version = "Windows 98";  
}
else if(version_info.dwMinorVersion == 90)
{
version = "Windows Me";
}
break;
}
case 5:
{
if(version_info.dwMinorVersion == 0)
{
version = "Windows 2000";
}
else if(version_info.dwMinorVersion == 1)
{
version = "Windows XP";
}
break;
}
}

sprintf(big_buffer, "OS: %s\n", version);
}  

fwrite(big_buffer, sizeof(char) * strlen(big_buffer), 1, fp);

#endif

fclose(fp);

dbugfile_init_var = true;
}

void dbugfile_deinit()
{
dbugfile_output("Normal end");
dbugfile_init_var = false;
}

void dbugfile_sprintf(int line, char *file, const char *format, ...)
{
if(dbugfile_init_var == false)
{
return;
}

// find last slash (for PC) to crop file path
char *ptr = strrchr(file, '\\');

if(ptr == NULL)
{
ptr = file;
}
else
{
ptr++;
}

char buffer[1000];
int i =  sprintf(buffer, "[%s,%4d] ", ptr, line);

va_list ap;
char *p, *sval;
long ival;
double dval;

// Add each extra parameter to string
va_start(ap, format);

for(p = (char *) format; *p; p++)
{
if(*p != '%')
{
*(buffer + i) = *p;
i++;
continue;
}

p++;

switch(*p)
{
case 'd':
{
ival = va_arg(ap, int);
i += sprintf(buffer+i,"%d", ival);
break;
}
case 'c':
{
ival = va_arg(ap, char);
buffer[i] = (char) ival;
i++;
break;
}
case 'x':
{
ival = va_arg(ap, int);
i += sprintf(buffer+i,"%x", ival);
break;
}

case 'f':
{
dval = va_arg(ap, double);
i += sprintf(buffer+i,"%f", dval);
break;
}
case 's':
{
for(sval = va_arg(ap, char *); *sval; sval++)
{
*(buffer + i++) = *sval;
}
break;
}
default:
{
i += sprintf(buffer+i,"N/A: %%%c", *p);
break;
}
}
}

va_end(ap);

i += sprintf(buffer + i, "\n");

dbugfile_output(buffer);
}


 

Offline rambler

  • 22
Can I commit my DEBUG generator?
The DebugSpew system in FS2 seems to be fairly good as it is. I had to play around with it a bit to get it to dump while the game is running.
If you cannot compile in Debug, you would probably have to play around a bit more to get it to dump in Release mode.

I think it would be better to get DebugSpew to dump to a file (not sure if this is already built in...) instead of adding another debug module. Besides, DebugSpew already dumps a whole bunch of interesting asserts and such.