/* G-Cows - scripting language for creation of web sites Copyright (C) 2002, 2003, 2004, 2005, 2006 Andrea Sozzi This file is part of G-Cows. G-Cows is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. G-Cows is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "error.H" #include "file_utils.H" #include using namespace std; Msg *Msg::instance = 0; void Msg::set_parsed_file (string file) { unsigned int slash; string dir, opt_dir, dir_fragment; if ( ( (slash = file.rfind ('/') ) != string::npos)) { parse_log_infos.file = file.substr (slash+1); parse_log_infos.dir = opt_file_name (parse_log_infos.dir + file.substr (0, slash+1)); } else parse_log_infos.file = file; parse_log_infos.line = 1; } void Msg::restore_saved_buffer () { Log_infos_iter iter = parse_log_infos_stack.end (); parse_log_infos = *(--iter); parse_log_infos_stack.erase (iter); } void Msg::advance_line (const char *token) { int start = -1; string token_string (token); while ((start=token_string.find ("\n", start + 1) ) != (int)string::npos ) parse_log_infos.line++; } void Msg::out (string long_msg, string short_msg, const char *type, int lines_back) { Log_infos_iter iter; int inclusions = parse_log_infos_stack.size (); if ( inclusions == 1 ) { iter = parse_log_infos_stack.begin (); cerr << "In file included from " << (*iter).dir << (*iter).file << ":" << (*iter).line << ":\n"; } else if ( inclusions > 1 ) { int showing_inclusion = 1; for (iter = parse_log_infos_stack.begin (); iter != parse_log_infos_stack.end (); iter++, showing_inclusion++) { if (showing_inclusion == 1) cerr << "In file included "; else cerr << " "; cerr << "from " << (*iter).dir << (*iter).file << ":" << (*iter).line; if (showing_inclusion == inclusions) cerr << ":\n"; else cerr << ",\n"; } } Log_infos infos = (log_mode == parsing_log_mode) ? parse_log_infos : exec_log_infos; cerr << infos.dir; if (infos.file != "") cerr << infos.file << ":"; else if (program_name != "") cerr << program_name << ": "; if (infos.line) cerr << infos.line - lines_back << ": "; if ( (type) && (strcmp (type, "error")) ) cerr << type << ": "; if ( (brief_flag) && (short_msg != "") ) cerr << short_msg << endl; else cerr << long_msg << endl; }