Hello,
This patch implement this by using exception instead of direct call.
Objection?
Abdel.
Index: lyx_main.C
===================================================================
--- lyx_main.C (revision 16823)
+++ lyx_main.C (working copy)
@@ -53,6 +53,7 @@
#include "support/filetools.h"
#include "support/lyxlib.h"
#include "support/convert.h"
+#include "support/Message.h"
#include "support/os.h"
#include "support/package.h"
#include "support/path.h"
@@ -395,9 +396,17 @@
// we need to parse for "-dbg" and "-help"
easyParse(argc, argv);
- support::init_package(to_utf8(from_local8bit(argv[0])),
+ try { support::init_package(to_utf8(from_local8bit(argv[0])),
cl_system_support, cl_user_support,
support::top_build_dir_is_one_level_up);
+ } catch (support::Message message) {
+ if (message.type_ == support::ErrorMessage) {
+ Alert::error(message.title_, message.details_);
+ exit(1);
+ } else if (message.type_ == support::WarningMessage) {
+ Alert::warning(message.title_, message.details_);
+ }
+ }
if (!use_gui) {
// FIXME: create a ConsoleApplication
Index: support/Message.h
===================================================================
--- support/Message.h (revision 0)
+++ support/Message.h (revision 0)
@@ -0,0 +1,41 @@
+// -*- C++ -*-
+/**
+ * \file Message.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ *
+ * A store of the paths to the various different directoies used
+ * by LyX. These paths differ markedly from one OS to another,
+ * following the local Windows, MacOS X or Posix conventions.
+ */
+#ifndef LYX_MESSAGE_H
+#define LYX_MESSAGE_H
+
+#include "support/docstring.h"
+
+namespace lyx {
+namespace support {
+
+
+enum MessageType {
+ ErrorMessage,
+ WarningMessage
+};
+
+struct Message {
+ Message(MessageType type, docstring const & title, docstring const &
details):
+ type_(type), title_(title), details_(details) {}
+
+ MessageType type_;
+ docstring title_;
+ docstring details_;
+};
+
+} // namespace support
+} // namespace lyx
+
+#endif // LYX_MESSAGE_H
Property changes on: support\Message.h
___________________________________________________________________
Name: svn:eol-style
+ native
Index: support/package.C.in
===================================================================
--- support/package.C.in (revision 16828)
+++ support/package.C.in (working copy)
@@ -22,6 +22,7 @@
#include "support/environment.h"
#include "support/filetools.h"
#include "support/lstrings.h"
+#include "support/Message.h"
#include "support/os.h"
#if defined (USE_WINDOWS_PACKAGING)
@@ -369,15 +370,6 @@
}
-void bail_out()
-{
-#ifndef CXX_GLOBAL_CSTD
- using std::exit;
-#endif
- exit(1);
-}
-
-
// Extracts the absolute path from the foo of "-sysdir foo" or "-userdir foo"
string const abs_path_from_command_line(string const & command_line)
{
@@ -440,11 +432,10 @@
string const abs_binary = get_binary_path(exe);
if (abs_binary.empty()) {
// FIXME UNICODE
- lyxerr << lyx::to_utf8(bformat(_("Unable to determine the path
to the "
- "LyX binary from the command
line %1$s"),
- lyx::from_utf8(exe)))
- << std::endl;
- bail_out();
+ throw Message(ErrorMessage,
+ _("LyX binary not found"),
+ bformat(_("Unable to determine the path to the LyX
binary from the command line %1$s"),
+ lyx::from_utf8(exe)));
}
return abs_binary;
}
@@ -562,17 +553,16 @@
}
// FIXME UNICODE
- lyxerr << lyx::to_utf8(bformat(_("Unable to determine the system
directory "
+ throw Message(ErrorMessage, _("No system directory"),
+ bformat(_("Unable to determine the system directory "
"having searched\n"
"\t%1$s\n"
"Use the '-sysdir' command line
parameter or "
"set the environment variable
LYX_DIR_15x to "
"the LyX system directory containing
the file "
"`chkconfig.ltx'."),
- lyx::from_utf8(searched_dirs_str)))
- << std::endl;
+ lyx::from_utf8(searched_dirs_str)));
- bail_out();
// Keep the compiler happy.
return string();
}
@@ -648,11 +638,10 @@
FileName const abs_path = fileSearch(dir, file);
if (abs_path.empty()) {
// FIXME UNICODE
- lyxerr << lyx::to_utf8(bformat(_("Invalid %1$s switch.\n"
- "Directory %2$s does not
contain %3$s."),
- lyx::from_utf8(command_line_switch),
lyx::from_utf8(dir),
- lyx::from_utf8(file)))
- << std::endl;
+ throw Message(WarningMessage, _("File not found"), bformat(
+ _("Invalid %1$s switch.\nDirectory %2$s does not
contain %3$s."),
+ lyx::from_utf8(command_line_switch),
lyx::from_utf8(dir),
+ lyx::from_utf8(file)));
}
return !abs_path.empty();
@@ -676,10 +665,11 @@
FileName const abs_path = fileSearch(dir, file);
if (abs_path.empty()) {
// FIXME UNICODE
- lyxerr << lyx::to_utf8(bformat(_("Invalid %1$s environment
variable.\n"
- "Directory %2$s does not
contain %3$s."),
- lyx::from_utf8(env_var), lyx::from_utf8(dir),
lyx::from_utf8(file)))
- << std::endl;
+ throw Message(WarningMessage, _("File not found"), bformat(
+ _("Invalid %1$s environment variable.\n"
+ "Directory %2$s does not contain %3$s."),
+ lyx::from_utf8(env_var), lyx::from_utf8(dir),
+ lyx::from_utf8(file)));
}
return !abs_path.empty();
@@ -703,8 +693,8 @@
docstring const fmt =
_("Invalid %1$s environment variable.\n%2$s is not a
directory.");
- lyxerr << lyx::to_utf8(bformat(fmt, lyx::from_utf8(env_var),
lyx::from_utf8(dir)))
- << std::endl;
+ throw Message(WarningMessage, _("Directory not found"), bformat(
+ fmt, lyx::from_utf8(env_var), lyx::from_utf8(dir)));
}
return success;
Index: tex2lyx/tex2lyx.C
===================================================================
--- tex2lyx/tex2lyx.C (revision 16811)
+++ tex2lyx/tex2lyx.C (working copy)
@@ -23,6 +23,7 @@
#include "support/fs_extras.h"
#include "support/lstrings.h"
#include "support/lyxlib.h"
+#include "support/Message.h"
#include "support/os.h"
#include "support/package.h"
#include "support/unicode.h"
@@ -518,9 +519,16 @@
}
lyx::support::os::init(argc, argv);
- support::init_package(to_utf8(from_local8bit(argv[0])),
+
+ try { support::init_package(to_utf8(from_local8bit(argv[0])),
cl_system_support, cl_user_support,
support::top_build_dir_is_two_levels_up);
+ } catch (support::Message message) {
+ cerr << message.title_ << ':\n'
+ << message.details_ << endl;
+ if (message.type_ == support::ErrorMessage)
+ exit(1);
+ }
// Now every known option is parsed. Look for input and output
// file name (the latter is optional).