avrerror.c

Go to the documentation of this file.
00001 /*
00002  * $Id: avrerror.c,v 1.8 2004/01/30 07:09:56 troth Exp $
00003  *
00004  ****************************************************************************
00005  *
00006  * simulavr - A simulator for the Atmel AVR family of microcontrollers.
00007  * Copyright (C) 2001, 2002, 2003, 2004  Theodore A. Roth
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022  *
00023  ****************************************************************************
00024  */
00025 
00026 /**
00027    \file avrerror.c
00028    \brief Functions for printing messages, warnings and errors.
00029 
00030    This module provides output printing facilities. */
00031 
00032 #include <stdio.h>
00033 #include <stdlib.h>
00034 #include <stdarg.h>
00035 #include <string.h>
00036 
00037 #include "avrerror.h"
00038 
00039 #if MACRO_DOCUMENTATION
00040 
00041 /** \brief Print an ordinary message to stdout. */
00042 #define avr_message(fmt, args...) \
00043     private_avr_message(__FILE__, __LINE__, fmt, ## args)
00044 
00045 /** \brief Print a warning message to stderr. */
00046 #define avr_warning(fmt, args...) \
00047     private_avr_warning(__FILE__, __LINE__, fmt, ## args)
00048 
00049 /** \brief Print an error message to stderr and terminate program. */
00050 #define avr_error(fmt, args...) \
00051     private_avr_error(__FILE__, __LINE__, fmt, ## args)
00052 
00053 #else /* Not Documentation */
00054 
00055 #if 1
00056 static char *
00057 strip_dir (char *path)
00058 {
00059     char *p = path;
00060 
00061     /* Find the end. */
00062 
00063     while (*p++)
00064         ;
00065 
00066     /* Find the last '/'. */
00067 
00068     while (p != path)
00069     {
00070         if (*p == '/')
00071         {
00072             p++;
00073             break;
00074         }
00075 
00076         p--;
00077     }
00078 
00079     return p;
00080 }
00081 #else
00082 #  define strip_dir(path) (path)
00083 #endif
00084 
00085 #define FLUSH_OUTPUT 1
00086 
00087 void
00088 private_avr_message (char *file, int line, char *fmt, ...)
00089 {
00090     va_list ap;
00091     char ffmt[128];
00092 
00093     snprintf (ffmt, sizeof (ffmt), "%s:%d: MESSAGE: %s", strip_dir (file),
00094               line, fmt);
00095     ffmt[127] = '\0';
00096 
00097     va_start (ap, fmt);
00098     vfprintf (stdout, ffmt, ap);
00099     va_end (ap);
00100 
00101 #if defined (FLUSH_OUTPUT)
00102     fflush (stdout);
00103 #endif
00104 }
00105 
00106 void
00107 private_avr_warning (char *file, int line, char *fmt, ...)
00108 {
00109     va_list ap;
00110     char ffmt[128];
00111 
00112     snprintf (ffmt, sizeof (ffmt), "%s:%d: WARNING: %s", strip_dir (file),
00113               line, fmt);
00114     ffmt[127] = '\0';
00115 
00116     va_start (ap, fmt);
00117     vfprintf (stderr, ffmt, ap);
00118     va_end (ap);
00119 
00120 #if defined (FLUSH_OUTPUT)
00121     fflush (stderr);
00122 #endif
00123 }
00124 
00125 void
00126 private_avr_error (char *file, int line, char *fmt, ...)
00127 {
00128     va_list ap;
00129     char ffmt[128];
00130 
00131     snprintf (ffmt, sizeof (ffmt), "\n%s:%d: ERROR: %s\n\n", strip_dir (file),
00132               line, fmt);
00133     ffmt[127] = '\0';
00134 
00135     va_start (ap, fmt);
00136     vfprintf (stderr, ffmt, ap);
00137     va_end (ap);
00138 
00139 #if defined (FLUSH_OUTPUT)
00140     fflush (stderr);
00141 #endif
00142 
00143     exit (1);                   /* exit instead of abort */
00144 }
00145 
00146 #endif /* Not documenation */

Automatically generated by Doxygen 1.5.2 on 14 Feb 2008.