ucloc.cc

Go to the documentation of this file.
00001 
00007 /*
00008 Copyright (C) 2000 The Exult Team
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00023 */
00024 
00025 #ifdef HAVE_CONFIG_H
00026 #  include <config.h>
00027 #endif
00028 
00029 #include <iostream>
00030 #include "ucloc.h"
00031 
00032 using std::strcmp;
00033 using std::strcpy;
00034 using std::strlen;
00035 using std::cout;
00036 using std::endl;
00037 
00038 
00039 std::vector<char *> Uc_location::source_names;
00040 char *Uc_location::cur_source = 0;
00041 int Uc_location::cur_line = 0;
00042 int Uc_location::num_errors = 0;
00043 
00044 /*
00045  *  Set current source and line #.
00046  */
00047 
00048 void Uc_location::set_cur
00049   (
00050   const char *s, 
00051   int l
00052   )
00053   {
00054   cur_line = l;
00055   cur_source = 0;     // See if already here.
00056   for (std::vector<char *>::const_iterator it = source_names.begin();
00057       it != source_names.end(); it++)
00058     if (strcmp(s, *it) == 0)
00059       {
00060       cur_source = *it;
00061       break;
00062       }
00063   if (!cur_source)    // 1st time.
00064     {
00065     int len = strlen(s);
00066     cur_source = new char[len + 1];
00067     strcpy(cur_source, s);
00068     source_names.push_back(cur_source);
00069     }
00070   }
00071 
00072 /*
00073  *  Print error for stored position.
00074  */
00075 
00076 void Uc_location::error
00077   (
00078   char *s
00079   )
00080   {
00081   cout << source << ':' << line + 1 << ": " << s << endl;
00082   num_errors++;
00083   }
00084 
00085 /*
00086  *  Print error for current parse location.
00087  */
00088 
00089 void Uc_location::yyerror
00090   (
00091   char *s
00092   )
00093   {
00094   cout << cur_source << ':' << cur_line + 1 << ": " << s << endl;
00095   num_errors++;
00096   }

Generated on Mon Jul 9 14:42:51 2007 for ExultEngine by  doxygen 1.5.1