debug.c

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <string.h>
00004 #include <stdarg.h>
00005 #include "gis.h"
00006 
00024 static int grass_debug_level = -1;
00025 
00026 int G_debug (int level, char *msg,...)
00027 {
00028 #ifdef GDEBUG
00029     char    *lstr, *filen;
00030     va_list ap;
00031     FILE    *fd;
00032    
00033     if (grass_debug_level < 0) {
00034         lstr = G__getenv( "DEBUG" );
00035 
00036         if ( lstr != NULL )
00037             grass_debug_level = atoi ( lstr );
00038         else
00039             grass_debug_level = 0;
00040     }
00041         
00042     if ( grass_debug_level >= level ) {
00043         va_start(ap, msg);
00044 
00045         filen =  getenv("GRASS_DEBUG_FILE"); 
00046         if ( filen != NULL ) {
00047             fd = fopen (filen,"a");
00048             if ( !fd ) {
00049                 G_warning ( "Cannot open debug file '%s'", filen);
00050                 return 0;
00051             }
00052         } else {
00053             fd = stderr;
00054         }
00055         
00056         fprintf (fd, "D%d/%d: ", level, grass_debug_level);
00057         vfprintf (fd, msg, ap);
00058         fprintf (fd, "\n");
00059         
00060         if ( filen != NULL ) fclose ( fd );
00061         
00062         va_end(ap);
00063     }
00064 #endif
00065 
00066     return 1;
00067 }
00068 

Generated on Sat Jul 22 22:06:14 2006 for GRASS by  doxygen 1.4.7