--- a/errorlog.c Mon Feb 16 18:09:03 2004 +0100 +++ b/errorlog.c Mon Feb 16 18:50:28 2004 +0100 @@ -21,107 +21,107 @@ static void add_to_log(ErrorLog *el, const char *message, int l) { - if(message==NULL) - return; - - /* Also write to stderr */ - fwrite(message, sizeof(char), l, stderr); + if(message==NULL) + return; + + /* Also write to stderr */ + fwrite(message, sizeof(char), l, stderr); - if(el==NULL) - return; - - if(el->file!=NULL){ - el->errors=TRUE; - fwrite(message, sizeof(char), l, el->file); - return; - } + if(el==NULL) + return; + + if(el->file!=NULL){ + el->errors=TRUE; + fwrite(message, sizeof(char), l, el->file); + return; + } - if(el->msgs==NULL){ - el->msgs=ALLOC_N(char, ERRORLOG_MAX_SIZE); - if(el->msgs==NULL){ - fprintf(stderr, "%s: %s\n", prog_execname(), strerror(errno)); - return; - } - el->msgs[0]=0; - el->msgs_len=0; - } - - el->errors=TRUE; - - if(l+el->msgs_len>ERRORLOG_MAX_SIZE-1){ - int n=0; - if(l<ERRORLOG_MAX_SIZE-1){ - n=ERRORLOG_MAX_SIZE-1-l; - memmove(el->msgs, el->msgs+el->msgs_len-n, n); - } - memcpy(el->msgs+n, message+l-(ERRORLOG_MAX_SIZE-1-n), - ERRORLOG_MAX_SIZE-1-n); - el->msgs[ERRORLOG_MAX_SIZE]='\0'; - el->msgs_len=ERRORLOG_MAX_SIZE-1; - }else{ - memcpy(el->msgs+el->msgs_len, message, l); - el->msgs[el->msgs_len+l]='\0'; - el->msgs_len+=l; - } + if(el->msgs==NULL){ + el->msgs=ALLOC_N(char, ERRORLOG_MAX_SIZE); + if(el->msgs==NULL){ + fprintf(stderr, "%s: %s\n", prog_execname(), strerror(errno)); + return; + } + el->msgs[0]=0; + el->msgs_len=0; + } + + el->errors=TRUE; + + if(l+el->msgs_len>ERRORLOG_MAX_SIZE-1){ + int n=0; + if(l<ERRORLOG_MAX_SIZE-1){ + n=ERRORLOG_MAX_SIZE-1-l; + memmove(el->msgs, el->msgs+el->msgs_len-n, n); + } + memcpy(el->msgs+n, message+l-(ERRORLOG_MAX_SIZE-1-n), + ERRORLOG_MAX_SIZE-1-n); + el->msgs[ERRORLOG_MAX_SIZE]='\0'; + el->msgs_len=ERRORLOG_MAX_SIZE-1; + }else{ + memcpy(el->msgs+el->msgs_len, message, l); + el->msgs[el->msgs_len+l]='\0'; + el->msgs_len+=l; + } } static void log_warn_handler(const char *message) { - const char *p=strchr(message, '\n'); - static int lineno=0; - int alternat=0; - - add_to_log(current_log, lineno==0 ? ">> " : " ", 3); - - if(p!=NULL){ - add_to_log(current_log, message, p-message+1); - lineno++; - log_warn_handler(p+1); - lineno--; - return; - } - - add_to_log(current_log, message, strlen(message)); - add_to_log(current_log, "\n", 1); + const char *p=strchr(message, '\n'); + static int lineno=0; + int alternat=0; + + add_to_log(current_log, lineno==0 ? ">> " : " ", 3); + + if(p!=NULL){ + add_to_log(current_log, message, p-message+1); + lineno++; + log_warn_handler(p+1); + lineno--; + return; + } + + add_to_log(current_log, message, strlen(message)); + add_to_log(current_log, "\n", 1); } - + void errorlog_begin_file(ErrorLog *el, FILE *file) { - el->msgs=NULL; - el->msgs_len=0; - el->file=file; - el->prev=current_log; - el->errors=FALSE; - el->old_handler=set_warn_handler(log_warn_handler); - current_log=el; + el->msgs=NULL; + el->msgs_len=0; + el->file=file; + el->prev=current_log; + el->errors=FALSE; + el->old_handler=set_warn_handler(log_warn_handler); + current_log=el; } void errorlog_begin(ErrorLog *el) { - errorlog_begin_file(el, NULL); + errorlog_begin_file(el, NULL); } bool errorlog_end(ErrorLog *el) { - current_log=el->prev; - set_warn_handler(el->old_handler); - el->prev=NULL; - el->old_handler=NULL; - return el->errors; + current_log=el->prev; + set_warn_handler(el->old_handler); + el->prev=NULL; + el->old_handler=NULL; + return el->errors; } void errorlog_deinit(ErrorLog *el) { - if(el->msgs!=NULL) - free(el->msgs); - el->msgs=NULL; - el->msgs_len=0; - el->file=NULL; - el->errors=FALSE; + if(el->msgs!=NULL) + free(el->msgs); + el->msgs=NULL; + el->msgs_len=0; + el->file=NULL; + el->errors=FALSE; }