X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fclient%2Fclient.cpp;h=9c7856014b36f0d994415cf84e041acf818e278e;hb=c162d029155d022c15d7618448a253ff5b3618c7;hp=538f75d48e66d3606c853471ec50ddccc96ec69e;hpb=a99340cd10b67cb9216787315da86bcfeda5c944;p=lyx.git diff --git a/src/client/client.cpp b/src/client/client.cpp index 538f75d48e..9c7856014b 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -12,10 +12,12 @@ #include +#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 @@ -53,6 +55,7 @@ #include #include #include +#include #include #include #include @@ -74,6 +77,21 @@ struct LyXRC { void lyx_exit(int) {} +// Dummy language support +Messages const & getGuiMessages() +{ + static Messages lyx_messages; + + return lyx_messages; +} + + +Messages const & getMessages(string const &) +{ + return getGuiMessages(); +} + + namespace support { string itoa(unsigned int i) @@ -293,7 +311,7 @@ bool LyXDataSocket::connected() const // Returns true if there was a complete line to input // A line is of the form : // A line not of this form will not be passed -// The line read is splitted and stored in 'key' and 'value' +// The line read is split and stored in 'key' and 'value' bool LyXDataSocket::readln(string & line) { int const charbuf_size = 100; @@ -408,6 +426,19 @@ bool CmdLineParser::parse(int argc, char * argv[]) namespace cmdline { +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() { cerr << @@ -421,10 +452,12 @@ void usage() " -n name set client name\n" " -h name display this help end exit\n" "If -a is not used, lyxclient will use the arguments of -t and -p to look for\n" - "a running lyx. If -t is not set, 'directory' defaults to /tmp. If -p is set,\n" + "a running lyx. If -t is not set, 'directory' defaults to the system directory. If -p is set,\n" "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:" + "will read commands from standard input and disconnect when command read is BYE:\n" + "\n" + "System directory is: " << to_utf8(cmdline::mainTmp) << endl; } @@ -432,7 +465,7 @@ void usage() int h(vector const &) { usage(); - exit(0); + throw StopException(EXIT_SUCCESS); } @@ -441,7 +474,7 @@ docstring clientName = int n(vector const & arg) { - if (arg.size() < 1) { + if (arg.empty()) { cerr << "lyxclient: The option -n requires 1 argument." << endl; return -1; @@ -456,7 +489,7 @@ docstring singleCommand; int c(vector const & arg) { - if (arg.size() < 1) { + if (arg.empty()) { cerr << "lyxclient: The option -c requires 1 argument." << endl; return -1; @@ -486,7 +519,7 @@ docstring serverAddress; int a(vector const & arg) { - if (arg.size() < 1) { + if (arg.empty()) { cerr << "lyxclient: The option -a requires 1 argument." << endl; return -1; @@ -497,12 +530,11 @@ int a(vector const & arg) } -docstring mainTmp(from_ascii("/tmp")); int t(vector const & arg) { - if (arg.size() < 1) { + if (arg.empty()) { cerr << "lyxclient: The option -t requires 1 argument." << endl; return -1; @@ -517,7 +549,7 @@ string serverPid; // Init to empty string int p(vector const & arg) { - if (arg.size() < 1) { + if (arg.empty()) { cerr << "lyxclient: The option -p requires 1 argument." << endl; return -1; @@ -528,18 +560,47 @@ int p(vector const & arg) } // namespace cmdline -} // namespace lyx +/// The main application class +class LyXClientApp : public ConsoleApplication +{ +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 main(int argc, char * argv[]) + +int LyXClientApp::run() { - using namespace lyx; - lyxerr.setStream(cerr); + // 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(); + + // Command line builder CmdLineParser args; args.helper["-h"] = cmdline::h; args.helper["-c"] = cmdline::c; @@ -550,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 server; @@ -651,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 {