gitkerrors.c

Go to the documentation of this file.
00001 
00019 #define GITK_LIB_C
00020 #define GITK_ERRORS_C
00021 
00022 #include "gitkincludes.h"
00023 
00024 
00029 GitkErrorCode gitk_error_code=0;
00034 gchar *gitk_error_str="";
00035 
00042 void gitk_set_error(const GitkErrorCode code, const gchar * const str) {
00043   gitk_log2("%d: %s",code,str);
00044 
00045   gitk_error_code=(GitkErrorCode)code;
00046   gitk_error_str=(gchar *)str;
00047 }
00048 
00053 GitkErrorCode gitk_get_error_code(void) {
00054   return(gitk_error_code);
00055 }
00056 
00061 gchar *gitk_get_error_str(void) {
00062   return(gitk_error_str);
00063 }
00064 
00069 void gitk_log_handler(const gchar * const log_domain, const GLogLevelFlags log_level, const gchar * const message, gpointer const user_data) {
00071   gitk_print_handler(message);
00072 }
00073 
00079 void gitk_print_handler(const gchar * const message) {
00080   FILE *logfile;
00081   gboolean add_nl=FALSE;
00082 
00083   //-- check if messages has no newline 
00084   if(message) {
00085     guint sl=strlen(message);
00086     if((sl>3) && (*message!='\e')) { // <hack>it is not just '..' or a ANSI-code</hack>
00087       if(message[sl-1]!='\n') add_nl=TRUE;
00088     }
00089   }
00090 
00091   if((logfile=fopen(log_file_name, "a")) || (logfile=fopen(log_file_name, "r"))) {
00092     (void)fwrite(message,strlen(message),1,logfile);
00093     if(add_nl) (void)fwrite("\n",1,1,logfile);
00094     fclose(logfile);
00095   }
00096   else { /* Fall back to console output if unable to open file */
00097     printf("%s",message);
00098     if(add_nl) putchar('\n');
00099   }
00100 }
00101 
00105 void gitk_libxmlxslt_error_func(void * const ctx,const char * const msg,...) {
00106   char str[1024];
00107   va_list args;
00108 
00109   //-- add prefix
00110   strncpy(str,ctx,1023);str[1023]='\0';
00111   //-- merge format and args
00112   va_start(args,msg);
00113   vsnprintf(&str[strlen(ctx)],1000,msg,args);
00114   va_end(args);
00115   //-- discard '\n'
00116   str[strlen(str)-1]='\0';
00117   //-- dump
00118   gitk_log(str);
00119 }

Generated on Thu Oct 28 10:59:08 2004 for gitk by doxygen 1.3.6