summaryrefslogtreecommitdiff
path: root/cscmd/error.c
diff options
context:
space:
mode:
Diffstat (limited to 'cscmd/error.c')
-rw-r--r--cscmd/error.c92
1 files changed, 92 insertions, 0 deletions
diff --git a/cscmd/error.c b/cscmd/error.c
new file mode 100644
index 0000000..ec469c9
--- /dev/null
+++ b/cscmd/error.c
@@ -0,0 +1,92 @@
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdarg.h>
+#include <limits.h>
+#include <locale.h>
+#include <wchar.h>
+#include <wctype.h>
+
+#include <defs.h>
+
+#include <error.h>
+#include <msglog.h>
+#include <utf8ing.h>
+#include <lex.h>
+
+
+extern char *config_fname;
+
+int errors = 0;
+int warnings = 0;
+
+
+void error( char *fmt, ... )
+{
+ va_list arg_ptr;
+ char buf[MAX_ERROR_MSG_SIZE];
+ char msg[MAX_ERROR_MSG_SIZE];
+ char *format = "%s:%d:%d: %s";
+
+ va_start( arg_ptr, fmt );
+
+ vsnprintf( msg, MAX_ERROR_MSG_SIZE, (const void *)fmt, arg_ptr );
+
+ va_end( arg_ptr ); /* Reset variable arguments. */
+
+ snprintf( buf, MAX_ERROR_MSG_SIZE, format, config_fname, lineno, colno, msg );
+
+ ERROR( "%s", buf );
+
+ ++errors;
+}
+
+void warning( char *fmt, ... )
+{
+ va_list arg_ptr;
+ char buf[MAX_ERROR_MSG_SIZE];
+ char msg[MAX_ERROR_MSG_SIZE];
+ char *format = "%s:%d:%d: %s";
+
+ va_start( arg_ptr, fmt );
+
+ vsnprintf( msg, MAX_ERROR_MSG_SIZE, (const void *)fmt, arg_ptr );
+
+ va_end( arg_ptr ); /* Reset variable arguments. */
+
+ snprintf( buf, MAX_ERROR_MSG_SIZE, format, config_fname, lineno, colno, msg );
+
+ WARNING( "%s", buf );
+
+ ++warnings;
+}
+
+void no_space( void )
+{
+ char buf[MAX_ERROR_MSG_SIZE];
+ char *format = "%s: Cannot allocate memory";
+
+ snprintf( buf, MAX_ERROR_MSG_SIZE, format, config_fname );
+
+ FATAL_ERROR( "%s", buf );
+
+ ++errors;
+}
+
+void unterminated_comment( void )
+{
+ char buf[MAX_ERROR_MSG_SIZE];
+ char *format = "%s:%d:%d: Unterminated comment";
+
+ snprintf( buf, MAX_ERROR_MSG_SIZE, format, config_fname, lineno, colno );
+
+ ERROR( "%s", buf );
+
+ ++errors;
+}