1 // -*- c++ -*-
2
3 // Package : omniidl
4 // idlerr.cc Created on: 1999/10/11
5 // Author : Duncan Grisby (dpg1)
6 //
7 // Copyright (C) 1999 AT&T Laboratories Cambridge
8 //
9 // This file is part of omniidl.
10 //
11 // omniidl is free software; you can redistribute it and/or modify it
12 // under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
15 //
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 // General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, see http://www.gnu.org/licenses/
23 //
24 // Description:
25 //
26 // IDL compiler error handling
27
28 #include <idlerr.h>
29 #include <idlutil.h>
30 #include <idlconfig.h>
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <stdarg.h>
35 #include <string.h>
36
37 int errorCount = 0;
38 int warningCount = 0;
39
40 void
IdlError(const char * file,int line,const char * fmt...)41 IdlError(const char* file, int line, const char* fmt ...)
42 {
43 errorCount++;
44
45 if (!Config::quiet) {
46 fprintf(stderr, "%s:%d: ", file, line);
47 va_list args;
48 va_start(args, fmt);
49 vfprintf(stderr, fmt, args);
50 va_end(args);
51 fprintf(stderr, "\n");
52 }
53 }
54
55 void
IdlErrorCont(const char * file,int line,const char * fmt...)56 IdlErrorCont(const char* file, int line, const char* fmt ...)
57 {
58 if (!Config::quiet) {
59 fprintf(stderr, "%s:%d: ", file, line);
60 va_list args;
61 va_start(args, fmt);
62 vfprintf(stderr, fmt, args);
63 va_end(args);
64 fprintf(stderr, "\n");
65 }
66 }
67
68 void
IdlSyntaxError(const char * file,int line,const char * mesg)69 IdlSyntaxError(const char* file, int line, const char* mesg)
70 {
71 static char* lastFile = idl_strdup("");
72 static int lastLine = 0;
73 static char* lastMesg = idl_strdup("");
74
75 if (line != lastLine || strcmp(file, lastFile) || strcmp(mesg, lastMesg)) {
76 lastLine = line;
77 if (strcmp(file, lastFile)) {
78 delete [] lastFile;
79 lastFile = idl_strdup(file);
80 }
81 if (strcmp(mesg, lastMesg)) {
82 delete [] lastMesg;
83 lastMesg = idl_strdup(mesg);
84 }
85 IdlError(file, line, mesg);
86 }
87 }
88
IdlWarning(const char * file,int line,const char * fmt...)89 void IdlWarning(const char* file, int line, const char* fmt ...)
90 {
91 warningCount++;
92
93 if (!Config::quiet) {
94 fprintf(stderr, "%s:%d: Warning: ", file, line);
95 va_list args;
96 va_start(args, fmt);
97 vfprintf(stderr, fmt, args);
98 va_end(args);
99 fprintf(stderr, "\n");
100 }
101 }
102
IdlWarningCont(const char * file,int line,const char * fmt...)103 void IdlWarningCont(const char* file, int line, const char* fmt ...)
104 {
105 if (!Config::quiet) {
106 fprintf(stderr, "%s:%d: Warning: ", file, line);
107 va_list args;
108 va_start(args, fmt);
109 vfprintf(stderr, fmt, args);
110 va_end(args);
111 fprintf(stderr, "\n");
112 }
113 }
114
115 IDL_Boolean
IdlReportErrors()116 IdlReportErrors()
117 {
118 if (!Config::quiet) {
119 if (errorCount > 0 || warningCount > 0)
120 fprintf(stderr, "omniidl: ");
121
122 if (errorCount > 0)
123 fprintf(stderr, "%d error%s", errorCount, errorCount == 1 ? "" : "s");
124
125 if (errorCount > 0 && warningCount > 0)
126 fprintf(stderr, " and ");
127
128 if (warningCount > 0)
129 fprintf(stderr, "%d warning%s", warningCount,
130 warningCount == 1 ? "" : "s");
131
132 if (errorCount > 0 || warningCount > 0)
133 fprintf(stderr, ".\n");
134 }
135
136 IDL_Boolean ret = (errorCount == 0);
137 errorCount = 0;
138 warningCount = 0;
139 return ret;
140 }
141