summaryrefslogtreecommitdiff
path: root/cscmd/error.c
blob: ec469c99f22eec57bb00442cb307e12b7f94033c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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;
}