Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » al_set_debug_file [submitting idea and code]

Credits go to BAF for helping out!
This thread is locked; no one can reply to it. rss feed Print
al_set_debug_file [submitting idea and code]
GullRaDriel
Member #3,861
September 2003
avatar

[EDIT: COMMENTS ARE WELCOME]

Every time I use TRACE I am worried that I can not specify the output file.
Today I choose to add my own ( not really difficult ) function to allegro.

I did the following modification:


debug.h, inserted at line 28

AL_FUNC(void, al_set_debug_file, (AL_CONST char *tracefilename , AL_CONST char *assertfilename ) );



allegro.c, inserted at line 576

1/* al_set_debug_file:
2 * Set a specific file for debug output. If tracefilename or assertfilename file is NULL, then it uses the allegro default.
3 */
4void al_set_debug_file(AL_CONST char *tracefilename , AL_CONST char *assertfilename )
5{
6 if( tracefilename != NULL )
7 {
8 trace_file = fopen( tracefilename , "w" );
9
10 if( !trace_file )
11 {
12 allegro_exit();
13 fprintf(stderr, "Impossible to open trace logging file %s\n", tracefilename );
14 abort();
15 }
16
17 debug_trace_virgin = FALSE ;
18 }
19
20 if( assertfilename != NULL )
21 {
22 assert_file = fopen( assertfilename , "w" );
23
24 if( !assert_file )
25 {
26 allegro_exit();
27 fprintf(stderr, "Impossible to open assert logging file %s\n", assertfilename );
28 abort();
29 }
30
31 debug_assert_virgin = FALSE ;
32 }
33
34 if( assertfilename == NULL && tracefilename == NULL )
35 {
36 allegro_exit();
37 fprintf(stderr, "Please specify at least one filename for debug output\n");
38 abort();
39 }
40
41}


I did a /misc/fixdll.sh, and a mingw32-make all, mingw32-make installall.


My test program look like this:

1int main( void )
2{
3 
4 al_set_debug_file( "serveur.log" , NULL );
5 
6 set_uformat(U_ASCII);
7 
8 allegro_init();
9 
10 install_timer();
11 
12 ShowWindow(win_get_window(),SW_HIDE);
13 
14 TRACE( "\nNILOREA Console Server\n\nVersion: SERVER %s\n ENGINE %s\n\n", _SERVER_ , _N_ENGINE_VER_ );
15 
16/* other stuff there */
17 
18}END_OF_MAIN()

As expected, this is working fine, TRACE use the specified filename and ASSERT is keeping default.
You only need to call the function before any call to TRACE or AL_TRACE.
I do not know if there are any uncovered issue with the function as I only need it for TRACE.

Everyone, any comments, are you interested by such a feature ? I was thinking that this was laking in Allegro.

EDITED: Adding assert_file inside the function. Edited one more time for names conflict && differentiation.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

BAF
Member #2,981
December 2002
avatar

Quote:

if( tracefile != NULL )

Wouldn't you have to close the file if it wasn't NULL? Also, you only open the file if tracefile is not NULL? I'm not sure I understand that part of the code.

GullRaDriel
Member #3,861
September 2003
avatar

Because I do not want to force people to specify both trace output filename and assert output filename.

If they want they can just pass NULL and it will let the default.

If you only want to have a specific assert file, then pass NULL,"myassertfile"
If you only want to have a specific trace file, then pass "mytracefile",NULL
If you are silly or your program pass two NULL, then it aborts.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

BAF
Member #2,981
December 2002
avatar

Ah, okay. I see now. I didn't read carefully enough, and assumed tracefile was the actual FILE*.

GullRaDriel
Member #3,861
September 2003
avatar

Yeah the name are not goodly choosen ... Sorry :-[

EDIT: I edited the firt post for better reading. now tracefile is tracefilename and assertfile is assertfilename.

EDIT: Thanks BAF for taking the time to put some comments.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Go to: