Synopsis - Cross-Reference

File: /Synopsis/Parsers/IDL/idlerr.cc
  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, write to the Free Software
 23//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 24//  02111-1307, USA.
 25//
 26// Description:
 27//   
 28//   IDL compiler error handling
 29
 30// $Id: idlerr.cc,v 1.8.2.1 2003/03/23 21:01:46 dgrisby Exp $
 31// $Log: idlerr.cc,v $
 32// Revision 1.8.2.1  2003/03/23 21:01:46  dgrisby
 33// Start of omniORB 4.1.x development branch.
 34//
 35// Revision 1.5.2.2  2000/10/27 16:31:08  dpg1
 36// Clean up of omniidl dependencies and types, from omni3_develop.
 37//
 38// Revision 1.5.2.1  2000/07/17 10:36:03  sll
 39// Merged from omni3_develop the diff between omni3_0_0_pre3 and omni3_0_0.
 40//
 41// Revision 1.6  2000/07/13 15:25:53  dpg1
 42// Merge from omni3_develop for 3.0 release.
 43//
 44// Revision 1.3.2.1  2000/03/06 15:03:48  dpg1
 45// Minor bug fixes to omniidl. New -nf and -k flags.
 46//
 47// Revision 1.3  1999/11/02 17:07:27  dpg1
 48// Changes to compile on Solaris.
 49//
 50// Revision 1.2  1999/10/29 15:43:44  dpg1
 51// Error counts now reset when Report...() is called.
 52//
 53// Revision 1.1  1999/10/27 14:05:58  dpg1
 54// *** empty log message ***
 55//
 56
 57#include <idlerr.h>
 58#include <idlutil.h>
 59#include <idlconfig.h>
 60
 61#include <stdio.h>
 62#include <stdlib.h>
 63#include <stdarg.h>
 64#include <string.h>
 65
 66int errorCount    = 0;
 67int warningCount  = 0;
 68
 69void
 70IdlError(const char* file, int line, const char* fmt ...)
 71{
 72  errorCount++;
 73
 74  if (!Config::quiet) {
 75    fprintf(stderr, "%s:%d: ", file, line);
 76    va_list args;
 77    va_start(args, fmt);
 78    vfprintf(stderr, fmt, args);
 79    va_end(args);
 80    fprintf(stderr, "\n");
 81  }
 82}
 83
 84void
 85IdlErrorCont(const char* file, int line, const char* fmt ...)
 86{
 87  if (!Config::quiet) {
 88    fprintf(stderr, "%s:%d:  ", file, line);
 89    va_list args;
 90    va_start(args, fmt);
 91    vfprintf(stderr, fmt, args);
 92    va_end(args);
 93    fprintf(stderr, "\n");
 94  }
 95}
 96
 97void
 98IdlSyntaxError(const char* file, int line, const char* mesg)
 99{
100  static char* lastFile = idl_strdup("");
101  static int   lastLine = 0;
102  static char* lastMesg = idl_strdup("");
103
104  if (line != lastLine || strcmp(file, lastFile) || strcmp(mesg, lastMesg)) {
105    lastLine = line;
106    if (strcmp(file, lastFile)) {
107      delete [] lastFile;
108      lastFile = idl_strdup(file);
109    }
110    if (strcmp(mesg, lastMesg)) {
111      delete [] lastMesg;
112      lastMesg = idl_strdup(mesg);
113    }
114    IdlError(file, line, mesg);
115  }
116}
117
118void IdlWarning(const char* file, int line, const char* fmt ...)
119{
120  warningCount++;
121
122  if (!Config::quiet) {
123    fprintf(stderr, "%s:%d: Warning: ", file, line);
124    va_list args;
125    va_start(args, fmt);
126    vfprintf(stderr, fmt, args);
127    va_end(args);
128    fprintf(stderr, "\n");
129  }
130}
131
132void IdlWarningCont(const char* file, int line, const char* fmt ...)
133{
134  if (!Config::quiet) {
135    fprintf(stderr, "%s:%d: Warning:  ", file, line);
136    va_list args;
137    va_start(args, fmt);
138    vfprintf(stderr, fmt, args);
139    va_end(args);
140    fprintf(stderr, "\n");
141  }
142}
143
144IDL_Boolean
145IdlReportErrors()
146{
147  if (!Config::quiet) {
148    if (errorCount > 0 || warningCount > 0)
149      fprintf(stderr, "omniidl: ");
150
151    if (errorCount > 0)
152      fprintf(stderr, "%d error%s", errorCount, errorCount == 1 ? "" : "s");
153
154    if (errorCount > 0 && warningCount > 0)
155      fprintf(stderr, " and ");
156
157    if (warningCount > 0)
158      fprintf(stderr, "%d warning%s", warningCount,
159	      warningCount == 1 ? "" : "s");
160
161    if (errorCount > 0 || warningCount > 0)
162      fprintf(stderr, ".\n");
163  }
164
165  IDL_Boolean ret = (errorCount == 0);
166  errorCount      = 0;
167  warningCount    = 0;
168  return ret;
169}