summaryrefslogtreecommitdiff
path: root/2004/i/nono/src/config/config.cc
diff options
context:
space:
mode:
Diffstat (limited to '2004/i/nono/src/config/config.cc')
-rw-r--r--2004/i/nono/src/config/config.cc33
1 files changed, 22 insertions, 11 deletions
diff --git a/2004/i/nono/src/config/config.cc b/2004/i/nono/src/config/config.cc
index 9a88494..ea726c6 100644
--- a/2004/i/nono/src/config/config.cc
+++ b/2004/i/nono/src/config/config.cc
@@ -24,9 +24,20 @@
// }}}
#include "config.h"
#include "config_lex.h"
-#include "erreur/erreur.h"
#include <cstring>
+#include <cstdio>
+
+const char *
+ConfigError::what () const throw ()
+{
+ static char descr[1024];
+ if (!m_id)
+ sprintf (descr, "%s: %s", m_file, m_descr);
+ else
+ sprintf (descr, "%s: %s: %s", m_file, m_id, m_descr);
+ return descr;
+}
// Constructeur, prend l'identificateur de configuration en paramètre (nom de
// fichier).
@@ -54,7 +65,7 @@ Config::getNum (void)
{
if (m_type == -1) m_type = config_yylex ();
if (m_type != NUM)
- throw ErreurConfig (m_filename.c_str (), "Nombre attendu.\n");
+ throw ConfigError (m_filename.c_str (), "Nombre attendu.\n");
m_type = -1;
return config_yylval.num;
}
@@ -64,7 +75,7 @@ Config::getId (void)
{
if (m_type == -1) m_type = config_yylex ();
if (m_type != ID)
- throw ErreurConfig (m_filename.c_str (), "Identificateur attendu.\n");
+ throw ConfigError (m_filename.c_str (), "Identificateur attendu.\n");
m_type = -1;
return config_yylval.id;
}
@@ -74,7 +85,7 @@ Config::getId (std::string &s)
{
if (m_type == -1) m_type = config_yylex ();
if (m_type != ID)
- throw ErreurConfig (m_filename.c_str (), "Identificateur attendu.\n");
+ throw ConfigError (m_filename.c_str (), "Identificateur attendu.\n");
m_type = -1;
s = config_yylval.id;
}
@@ -84,7 +95,7 @@ Config::getBool (void)
{
if (m_type == -1) m_type = config_yylex ();
if (m_type != BOOL)
- throw ErreurConfig (m_filename.c_str (), "Booléen attendu.\n");
+ throw ConfigError (m_filename.c_str (), "Booléen attendu.\n");
m_type = -1;
return config_yylval.boolean;
}
@@ -104,7 +115,7 @@ Config::getFloat (void)
return (double) config_yylval.num;
}
else
- throw ErreurConfig (m_filename.c_str (), "Flotant attendu.\n");
+ throw ConfigError (m_filename.c_str (), "Flotant attendu.\n");
}
void
@@ -112,7 +123,7 @@ Config::getString (std::string &s)
{
if (m_type == -1) m_type = config_yylex ();
if (m_type != STRING)
- throw ErreurConfig (m_filename.c_str (),
+ throw ConfigError (m_filename.c_str (),
"Chaîne de caractères attendue.\n");
m_type = -1;
s = config_yylval.str;
@@ -123,7 +134,7 @@ Config::getEof (void)
{
if (m_type == -1) m_type = config_yylex ();
if (m_type)
- throw ErreurConfig (m_filename.c_str (),
+ throw ConfigError (m_filename.c_str (),
"Fin de fichier attendue.\n");
}
@@ -141,7 +152,7 @@ Config::isId (const char *s)
{
if (m_type == -1) m_type = config_yylex ();
if (m_type != ID)
- throw ErreurConfig (m_filename.c_str (), "Identificateur attendu.\n");
+ throw ConfigError (m_filename.c_str (), "Identificateur attendu.\n");
return strcmp (config_yylval.id, s) == 0;
}
@@ -149,14 +160,14 @@ Config::isId (const char *s)
void
Config::noId (void)
{
- throw ErreurConfig (m_filename.c_str (), config_yylval.id,
+ throw ConfigError (m_filename.c_str (), config_yylval.id,
"Identificateur inconnu.\n");
}
void
Config::throwError (const char *msg)
{
- throw ErreurConfig (m_filename.c_str (), msg);
+ throw ConfigError (m_filename.c_str (), msg);
}
// Appellé par le lexer pour changer de fichier.