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
00033
00034
00035
00036
00037
00038
00039
00040 #include <stdio.h>
00041 #include <cmplrs/rcodes.h>
00042 #include "errors.h"
00043 #include "string_utils.h"
00044
00045 status_codes error_status = RC_OKAY;
00046 int internal_error_occurred;
00047 char *program_name;
00048 boolean print_warnings = TRUE;
00049 boolean fullwarn = FALSE;
00050 boolean pass_exit_codes = FALSE;
00051
00052 static int errors = 0;
00053 static int previous_errors = 0;
00054
00055 string_list_t *error_list = NULL;
00056
00057 void
00058 init_error_list(void)
00059 {
00060 error_list = init_string_list();
00061 }
00062
00063 static void
00064 set_error_status (status_codes e)
00065 {
00066 if (pass_exit_codes) {
00067 if (e > error_status) {
00068 error_status = e;
00069 }
00070 }
00071 else {
00072 if (error_status == RC_OKAY) {
00073 error_status = e;
00074 }
00075 }
00076 }
00077
00078 void
00079 vlog_error(char *format, va_list ap)
00080 {
00081 char *msg;
00082
00083 if (vasprintf(&msg, format, ap) == -1)
00084 return;
00085
00086 add_string(error_list, msg);
00087 }
00088
00089 void
00090 log_error(char *format, ...)
00091 {
00092 va_list ap;
00093
00094 va_start(ap, format);
00095 vlog_error(format, ap);
00096 va_end(ap);
00097 }
00098
00099 void
00100 error(char *format, ...)
00101 {
00102 va_list args;
00103 va_start (args, format);
00104 fprintf(stderr, "%s ERROR: ", program_name);
00105 vfprintf(stderr, format, args);
00106 fprintf(stderr, "\n");
00107 va_end (args);
00108 set_error_status(RC_USER_ERROR);
00109 errors++;
00110 }
00111
00112 void
00113 parse_error (const char *name, const char *msg)
00114 {
00115 fprintf(stderr, "%s ERROR parsing %s: %s\n",
00116 program_name, name, msg);
00117 set_error_status(RC_USER_ERROR);
00118 errors++;
00119 }
00120
00121 void
00122 warning (char *format, ...)
00123 {
00124 va_list args;
00125 if (!print_warnings) return;
00126 va_start (args, format);
00127 fprintf(stderr, "%s WARNING: ", program_name);
00128 vfprintf(stderr, format, args);
00129 fprintf(stderr, "\n");
00130 va_end (args);
00131 }
00132
00133 void
00134 warn_ignored (char *name)
00135 {
00136 warning("%s is ignored", name);
00137 }
00138
00139 void
00140 warn_nyi (char *name)
00141 {
00142 warning("%s is not yet implemented", name);
00143 }
00144
00145 void
00146 warn_no_longer_needed (char *name)
00147 {
00148 warning("%s is no longer needed", name);
00149 }
00150
00151 void
00152 warn_no_longer_supported (char *name)
00153 {
00154 warning("%s is no longer supported", name);
00155 }
00156
00157 void
00158 warn_no_longer_supported2 (char *name, char *newname)
00159 {
00160 warning("%s is no longer supported, use %s instead", name, newname);
00161 }
00162
00163 void
00164 internal_error (char *format, ...)
00165 {
00166 va_list args;
00167 va_start (args, format);
00168 fprintf(stderr, "%s INTERNAL ERROR: ", program_name);
00169 vfprintf(stderr, format, args);
00170 fprintf(stderr, "\n");
00171 va_end (args);
00172
00173 va_start (args, format);
00174 vlog_error (format, args);
00175 va_end (args);
00176
00177 internal_error_occurred = 1;
00178 set_error_status(RC_INTERNAL_ERROR);
00179 errors++;
00180 }
00181
00182
00183 void
00184 nomsg_error (int status)
00185 {
00186 set_error_status(status);
00187 errors++;
00188 }
00189
00190 boolean
00191 has_errors(void)
00192 {
00193 return (errors > 0 || previous_errors > 0);
00194 }
00195
00196 boolean
00197 has_current_errors(void)
00198 {
00199 return (errors > 0);
00200 }
00201
00202 void
00203 clear_current_errors(void)
00204 {
00205 previous_errors = errors;
00206 errors = 0;
00207 }