Re: [AD] Verbose output from init() routines

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


No one responded to my original email so Im not sure if there is any interest in this.. but I wrote a little patch that adds a few debugging statements as long as allegro_debug = 1.

Jon Rafkind wrote:

Occasionally I wonder what Allegro is doing during the init() routines and rather than hack the source to make it display these things I think it would be convienent to have some way to make Allegro do this for me. One way is to have an extra parameter for each init routine. This is good for multi-threading but bad for backwards compatibility and besides, Allegro is hardly multi-threadable.

The other way is to have a global variable, allegro_verbose or allegro_debug, that when set to a non-zero value would make the init() routines printf() some stuff to the screen. Maybe for higher values of the variable the init() routines will be even more verbose.

Just wanted to throw the idea out there before I write some code.


-------------------------------------------------------
This SF.Net email is sponsored by: New Crystal Reports XI.
Version 11 adds new functionality designed to reduce time involved in
creating, integrating, and deploying reporting solutions. Free runtime info,
new features, or free trial, at: http://www.businessobjects.com/devxi/728

Index: include/allegro/base.h
===================================================================
RCS file: /cvsroot/alleg/allegro/include/allegro/base.h,v
retrieving revision 1.32
diff -u -r1.32 base.h
--- include/allegro/base.h	20 Apr 2005 10:35:07 -0000	1.32
+++ include/allegro/base.h	23 Apr 2005 22:27:51 -0000
@@ -78,6 +78,7 @@
 #define AL_ID(a,b,c,d)     (((a)<<24) | ((b)<<16) | ((c)<<8) | (d))
 
 AL_VAR(int *, allegro_errno);
+AL_VAR(int, allegro_debug);
 
 typedef struct _DRIVER_INFO         /* info about a hardware driver */
 {
Index: src/allegro.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/allegro.c,v
retrieving revision 1.50
diff -u -r1.50 allegro.c
--- src/allegro.c	31 Mar 2005 20:16:24 -0000	1.50
+++ src/allegro.c	23 Apr 2005 22:27:52 -0000
@@ -40,6 +40,9 @@
 /* error value, which will work even with DLL linkage */
 int *allegro_errno = NULL;
 
+/* debugging for allegro */
+int allegro_debug = 0;
+
 
 /* flag for how many times we have been initialised */
 int _allegro_count = 0;
@@ -308,6 +311,10 @@
    char tmp1[64], tmp2[64];
    int i;
 
+   if ( allegro_debug ){
+   	printf("*ALLEGRO* Installing..\n");
+   }
+
    #ifndef ALLEGRO_USE_CONSTRUCTOR
       /* call constructor functions manually */
       extern void _initialize_datafile_types();
@@ -327,6 +334,10 @@
    else
       allegro_errno = &errno;
 
+   if ( allegro_debug ){
+   	printf("*ALLEGRO* errno set to %p\n", allegro_errno );
+   }
+
    /* set up default palette structures */
    for (i=0; i<256; i++)
       black_palette[i] = black_rgb;
@@ -358,9 +369,14 @@
 
    reload_config_texts(NULL);
 
-   if (system_id == SYSTEM_AUTODETECT)
+   if (system_id == SYSTEM_AUTODETECT) {
       system_id = get_config_id(uconvert_ascii("system", tmp1), uconvert_ascii("system", tmp2), SYSTEM_AUTODETECT);
 
+      if ( allegro_debug ){
+         printf("*ALLEGRO* Autodetected system type = %d\n", system_id );
+      }
+   }
+
    system_driver = NULL;
 
    /* initialise the system driver */
@@ -372,6 +388,9 @@
 	 system_driver = _system_driver_list[i].driver;
 	 system_driver->name = system_driver->desc = get_config_text(system_driver->ascii_name);
 	 if (system_driver->init() != 0) {
+	    if ( allegro_debug ){
+	       printf("*ALLEGRO* Failed to initialize system driver %s\n", system_driver->name );
+            }
 	    system_driver = NULL;
 	    if (system_id != SYSTEM_AUTODETECT)
 	       break;
@@ -381,8 +400,15 @@
       }
    }
 
-   if (!system_driver)
+   if (!system_driver){
+      if ( allegro_debug ){
+         printf("*ALLEGRO* Failed to load any system driver\n");
+      }
       return -1;
+   }
+   if ( allegro_debug ){
+       printf("*ALLEGRO* Loaded system driver %s\n", system_driver->name );
+   }
 
    /* disable close button */
    set_close_button_callback(NULL);
@@ -394,6 +420,9 @@
    _screensaver_policy = get_config_int(uconvert_ascii("system", tmp1),
                                         uconvert_ascii("disable_screensaver", tmp2),
                                         FULLSCREEN_DISABLED);
+   if ( allegro_debug ){
+      printf("*ALLEGRO* Screensaver policy = %d\n", _screensaver_policy );
+   }
 
    /* install shutdown handler */
    if (_allegro_count == 0) {
@@ -403,6 +432,10 @@
 
    _allegro_count++;
 
+   if ( allegro_debug ){
+      printf("*ALLEGRO* Done installing\n");
+   }
+
    return 0;
 }
 
Index: src/config.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/config.c,v
retrieving revision 1.29
diff -u -r1.29 config.c
--- src/config.c	31 Mar 2005 20:16:24 -0000	1.29
+++ src/config.c	23 Apr 2005 22:27:52 -0000
@@ -22,6 +22,7 @@
 
 #include "allegro.h"
 #include "allegro/internal/aintern.h"
+#include <stdio.h>
 
 
 
@@ -422,6 +423,9 @@
 	 return;
       }
 
+      if ( allegro_debug ){
+         printf("*ALLEGRO* Config [%s] = [%s]\n", name, val );
+      }
       p->name = name;
       p->data = val;
 
@@ -452,6 +456,9 @@
       return;
    }
 
+   if ( allegro_debug ){
+   	printf("*ALLEGRO* Loading config file %s\n", filename );
+   }
    length = file_size(filename);
 
    if (length > 0) {


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/