X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fclient%2Fclient.cpp;h=19e38fae5174b8df8d088c594915968473aecf22;hb=26910d5ec49395d1372dd5b9259f1bf6ed23de0a;hp=8d47e347aa21df77f6ee60d7ff0236428b1823c8;hpb=316764c6115f1f853ceb19d7fa17361f861ef20d;p=lyx.git diff --git a/src/client/client.cpp b/src/client/client.cpp index 8d47e347aa..19e38fae51 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -16,6 +16,7 @@ #include "support/FileName.h" #include "support/FileNameList.h" #include "support/lstrings.h" +#include "support/Messages.h" #include "support/unicode.h" #include @@ -47,6 +48,9 @@ // fcntl() #include +// strerror() +#include + #include #include #include @@ -62,6 +66,30 @@ using ::boost::scoped_ptr; namespace lyx { +// Dummy LyXRC support +struct LyXRC { + string icon_set; +} lyxrc; + +// Keep the linker happy on Windows +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) @@ -94,7 +122,7 @@ FileNameList lyxSockets(string const & dir, string const & pid) for (; it != end; ++it) { if (!it->isDirectory()) continue; - string const tmpdir = it->absFilename(); + string const tmpdir = it->absFileName(); if (!contains(tmpdir, "lyx_tmpdir" + pid)) continue; @@ -137,7 +165,7 @@ int connect(FileName const & name) if (::connect(fd, reinterpret_cast(&addr), sizeof(addr)) == -1) { - cerr << "lyxclient: Could not connect to socket " << name.absFilename() + cerr << "lyxclient: Could not connect to socket " << name.absFileName() << ": " << strerror(errno) << endl; ::close(fd); return -1; @@ -281,7 +309,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; @@ -396,6 +424,9 @@ bool CmdLineParser::parse(int argc, char * argv[]) namespace cmdline { + docstring mainTmp(from_ascii("/tmp")); + + void usage() { cerr << @@ -409,10 +440,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; } @@ -429,7 +462,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; @@ -444,7 +477,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; @@ -474,7 +507,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; @@ -485,12 +518,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; @@ -505,7 +537,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; @@ -524,10 +556,16 @@ int main(int argc, char * argv[]) using namespace lyx; lyxerr.setStream(cerr); + + // 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; @@ -566,14 +604,14 @@ int main(int argc, char * argv[]) if (server->connected()) break; lyxerr << "lyxclient: " << "Could not connect to " - << addr->absFilename() << endl; + << addr->absFileName() << endl; } if (addr == end) { lyxerr << "lyxclient: No suitable server found." << endl; return EXIT_FAILURE; } - cerr << "lyxclient: " << "Connected to " << addr->absFilename() << endl; + cerr << "lyxclient: " << "Connected to " << addr->absFileName() << endl; } int const serverfd = server->fd(); @@ -621,6 +659,8 @@ int main(int argc, char * argv[]) if (iowatch.isset(0)) { string command; getline(cin, command); + if (command.empty()) + continue; if (command == "BYE:") { server->writeln("BYE:"); saidbye = true;