#include <config.h>
+#include "LyXRC.h"
+
+#include "support/ConsoleApplication.h"
#include "support/debug.h"
#include "support/FileName.h"
#include "support/FileNameList.h"
#include "support/lstrings.h"
#include "support/Messages.h"
#include "support/unicode.h"
-
-#include <boost/scoped_ptr.hpp>
+#include "support/unique_ptr.h"
// getpid(), getppid()
#ifdef HAVE_SYS_TYPES_H
#include <cerrno>
#include <cstdio>
#include <cstdlib>
+#include <exception>
#include <string>
#include <vector>
#include <map>
#include <iostream>
+
using namespace std;
using namespace lyx::support;
-using ::boost::scoped_ptr;
-
namespace lyx {
-// Dummy LyXRC support
-struct LyXRC {
- string icon_set;
-} lyxrc;
+// Required global variables
+bool verbose = false;
+LyXRC lyxrc;
// Keep the linker happy on Windows
void lyx_exit(int)
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()
"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;
}
int h(vector<docstring> const &)
{
usage();
- exit(0);
+ throw StopException(EXIT_SUCCESS);
}
<< endl;
return -1;
}
- singleCommand = "LYXCMD:server-goto-file-row "
- + arg[0] + ' '
- + arg[1];
+ singleCommand = "LYXCMD:command-sequence "
+ "server-goto-file-row "
+ + arg[0] + ' '
+ + arg[1] + "; " +
+ "lyx-activate";
return 2;
}
} // 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_;
+};
- // Set defaults
+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)
cmdline::serverAddress = from_local8bit(lyxsocket);
- // Default temporary
- cmdline::mainTmp = FileName::tempPath().absoluteFilePath();
+ // Default temporary
+ cmdline::mainTmp = FileName::tempPath().absoluteFilePath();
- // Command line builder
+ // Command line builder
CmdLineParser args;
args.helper["-h"] = cmdline::h;
args.helper["-c"] = cmdline::c;
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;
+ unique_ptr<LyXDataSocket> server;
if (!cmdline::serverAddress.empty()) {
server.reset(new LyXDataSocket(FileName(to_utf8(cmdline::serverAddress))));
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 {