00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
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
00042 #define avr_message(fmt, args...) \
00043 private_avr_message(__FILE__, __LINE__, fmt, ## args)
00044
00045
00046 #define avr_warning(fmt, args...) \
00047 private_avr_warning(__FILE__, __LINE__, fmt, ## args)
00048
00049
00050 #define avr_error(fmt, args...) \
00051 private_avr_error(__FILE__, __LINE__, fmt, ## args)
00052
00053 #else
00054
00055 #if 1
00056 static char *
00057 strip_dir (char *path)
00058 {
00059 char *p = path;
00060
00061
00062
00063 while (*p++)
00064 ;
00065
00066
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);
00144 }
00145
00146 #endif