]> git.lyx.org Git - lyx.git/blobdiff - src/client/client.cpp
Win installer: translate 2 installer sections
[lyx.git] / src / client / client.cpp
index c781bc6d7f828388cfb5cf3269d0f265b16a31ca..9c7856014b36f0d994415cf84e041acf818e278e 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <config.h>
 
+#include "support/ConsoleApplication.h"
 #include "support/debug.h"
 #include "support/FileName.h"
 #include "support/FileNameList.h"
@@ -54,6 +55,7 @@
 #include <cerrno>
 #include <cstdio>
 #include <cstdlib>
+#include <exception>
 #include <string>
 #include <vector>
 #include <map>
@@ -424,7 +426,17 @@ bool CmdLineParser::parse(int argc, char * argv[])
 
 namespace cmdline {
 
-    docstring mainTmp(from_ascii("/tmp"));
+docstring mainTmp(from_ascii("/tmp"));
+
+
+class StopException : public exception
+{
+public:
+       StopException(int status) : status_(status) {}
+       int status() const { return status_; }
+private:
+       int status_;
+};
 
 
 void usage()
@@ -444,8 +456,8 @@ void usage()
          "lyxclient will connect only to a lyx with the specified pid. Options -c and -g\n"
          "cannot be set simultaneoulsly. If no -c or -g options are given, lyxclient\n"
          "will read commands from standard input and disconnect when command read is BYE:\n"
-      "\n"
-      "System directory is: " << to_utf8(cmdline::mainTmp)
+         "\n"
+         "System directory is: " << to_utf8(cmdline::mainTmp)
           << endl;
 }
 
@@ -453,7 +465,7 @@ void usage()
 int h(vector<docstring> const &)
 {
        usage();
-       exit(0);
+       throw StopException(EXIT_SUCCESS);
 }
 
 
@@ -548,15 +560,38 @@ int p(vector<docstring> const & arg)
 
 
 } // namespace cmdline
-} // namespace lyx
 
-
-int main(int argc, char * argv[])
+/// The main application class
+class LyXClientApp : public ConsoleApplication
 {
-       using namespace lyx;
-       lyxerr.setStream(cerr);
+public:
+       LyXClientApp(int & argc, char * argv[])
+               : ConsoleApplication("client" PROGRAM_SUFFIX, argc, argv),
+                 argc_(argc), argv_(argv)
+       {
+       }
+       void doExec()
+       {
+               try {
+                       int const exit_status = run();
+                       exit(exit_status);
+               }
+               catch (cmdline::StopException & e) {
+                       exit(e.status());
+               }
+       }
+private:
+       int run();
+       int & argc_;
+       char ** argv_;
+};
 
 
+int LyXClientApp::run()
+{
+       // qt changes this, and our numeric conversions require the C locale
+       setlocale(LC_NUMERIC, "C");
+
        // Set defaults
        char const * const lyxsocket = getenv("LYXSOCKET");
        if (lyxsocket)
@@ -576,11 +611,11 @@ int main(int argc, char * argv[])
        args.helper["-p"] = cmdline::p;
 
        // Command line failure conditions:
-       if ((!args.parse(argc, argv))
+       if ((!args.parse(argc_, argv_))
           || (args.isset["-c"] && args.isset["-g"])
           || (args.isset["-a"] && args.isset["-p"])) {
                cmdline::usage();
-               return 1;
+               return EXIT_FAILURE;
        }
 
        scoped_ptr<LyXDataSocket> server;
@@ -677,6 +712,17 @@ int main(int argc, char * argv[])
        return EXIT_SUCCESS;
 }
 
+} // namespace lyx
+
+
+int main(int argc, char * argv[])
+{
+       lyx::lyxerr.setStream(cerr);
+
+       lyx::LyXClientApp app(argc, argv);
+       return app.exec();
+}
+
 
 namespace boost {