avrerror.c
Go to the documentation of this file.
1 /*
2  * $Id: avrerror.c,v 1.8 2004/01/30 07:09:56 troth Exp $
3  *
4  ****************************************************************************
5  *
6  * simulavr - A simulator for the Atmel AVR family of microcontrollers.
7  * Copyright (C) 2001, 2002, 2003, 2004 Theodore A. Roth
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  *
23  ****************************************************************************
24  */
25 
26 /**
27  \file avrerror.c
28  \brief Functions for printing messages, warnings and errors.
29 
30  This module provides output printing facilities. */
31 
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <stdarg.h>
35 #include <string.h>
36 
37 #include "avrerror.h"
38 
39 #if MACRO_DOCUMENTATION
40 
41 /** \brief Print an ordinary message to stdout. */
42 #define avr_message(fmt, args...) \
43  private_avr_message(__FILE__, __LINE__, fmt, ## args)
44 
45 /** \brief Print a warning message to stderr. */
46 #define avr_warning(fmt, args...) \
47  private_avr_warning(__FILE__, __LINE__, fmt, ## args)
48 
49 /** \brief Print an error message to stderr and terminate program. */
50 #define avr_error(fmt, args...) \
51  private_avr_error(__FILE__, __LINE__, fmt, ## args)
52 
53 #else /* Not Documentation */
54 
55 #if 1
56 static char *
57 strip_dir (char *path)
58 {
59  char *p = path;
60 
61  /* Find the end. */
62 
63  while (*p++)
64  ;
65 
66  /* Find the last '/'. */
67 
68  while (p != path)
69  {
70  if (*p == '/')
71  {
72  p++;
73  break;
74  }
75 
76  p--;
77  }
78 
79  return p;
80 }
81 #else
82 # define strip_dir(path) (path)
83 #endif
84 
85 #define FLUSH_OUTPUT 1
86 
87 void
88 private_avr_message (char *file, int line, char *fmt, ...)
89 {
90  va_list ap;
91  char ffmt[128];
92 
93  snprintf (ffmt, sizeof (ffmt), "%s:%d: MESSAGE: %s", strip_dir (file),
94  line, fmt);
95  ffmt[127] = '\0';
96 
97  va_start (ap, fmt);
98  vfprintf (stdout, ffmt, ap);
99  va_end (ap);
100 
101 #if defined (FLUSH_OUTPUT)
102  fflush (stdout);
103 #endif
104 }
105 
106 void
107 private_avr_warning (char *file, int line, char *fmt, ...)
108 {
109  va_list ap;
110  char ffmt[128];
111 
112  snprintf (ffmt, sizeof (ffmt), "%s:%d: WARNING: %s", strip_dir (file),
113  line, fmt);
114  ffmt[127] = '\0';
115 
116  va_start (ap, fmt);
117  vfprintf (stderr, ffmt, ap);
118  va_end (ap);
119 
120 #if defined (FLUSH_OUTPUT)
121  fflush (stderr);
122 #endif
123 }
124 
125 void
126 private_avr_error (char *file, int line, char *fmt, ...)
127 {
128  va_list ap;
129  char ffmt[128];
130 
131  snprintf (ffmt, sizeof (ffmt), "\n%s:%d: ERROR: %s\n\n", strip_dir (file),
132  line, fmt);
133  ffmt[127] = '\0';
134 
135  va_start (ap, fmt);
136  vfprintf (stderr, ffmt, ap);
137  va_end (ap);
138 
139 #if defined (FLUSH_OUTPUT)
140  fflush (stderr);
141 #endif
142 
143  exit (1); /* exit instead of abort */
144 }
145 
146 #endif /* Not documenation */

Automatically generated by Doxygen 1.8.2 on Mon Mar 10 2014.