summaryrefslogtreecommitdiff
path: root/2004/i/nono/src/config
diff options
context:
space:
mode:
authorschodet2004-05-13 23:10:37 +0000
committerschodet2004-05-13 23:10:37 +0000
commit6006fee7b9eddd71dee20b6b39b233f7e4088db9 (patch)
tree40b170282e451d9da73eac179baf8ab4fc5054e5 /2004/i/nono/src/config
parent18570afbe14ef0bcc12ddb6c39fc6047190e052e (diff)
Virure de Erreur
Diffstat (limited to '2004/i/nono/src/config')
-rw-r--r--2004/i/nono/src/config/config.cc33
-rw-r--r--2004/i/nono/src/config/config.h15
2 files changed, 37 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.
diff --git a/2004/i/nono/src/config/config.h b/2004/i/nono/src/config/config.h
index f6f22df..4187223 100644
--- a/2004/i/nono/src/config/config.h
+++ b/2004/i/nono/src/config/config.h
@@ -26,6 +26,21 @@
// }}}
#include <string>
+#include <stdexcept>
+
+class ConfigError : public std::runtime_error
+{
+ const char *m_file;
+ const char *m_id;
+ const char *m_descr;
+ public:
+ ConfigError (const char *file, const char *id,
+ const char *descr)
+ { m_file = file; m_id = id; m_descr = descr; }
+ ConfigError (const char *file, const char *descr)
+ { m_file = file; m_id = 0; m_descr = descr; }
+ virtual const char *what () const throw ();
+};
class Config
{