X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fclient%2Fclient.cpp;h=538f75d48e66d3606c853471ec50ddccc96ec69e;hb=dba4f28b6269c0ebd7a4e70a82ca10cf6c4a6ff8;hp=bf96e3e9b5c9b52e665b6191e5016fd3ba6a4eaa;hpb=377ae30bd8dd025e6e676691b9142c086aad87e9;p=lyx.git diff --git a/src/client/client.cpp b/src/client/client.cpp index bf96e3e9b5..538f75d48e 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -3,8 +3,8 @@ * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * - * \author João Luis M. Assirati - * \author Lars Gullik Bjønnes + * \author João Luis M. Assirati + * \author Lars Gullik Bjønnes * * Full author contact details are available in file CREDITS. */ @@ -14,10 +14,10 @@ #include "support/debug.h" #include "support/FileName.h" -#include "support/unicode.h" +#include "support/FileNameList.h" #include "support/lstrings.h" +#include "support/unicode.h" -#include #include // getpid(), getppid() @@ -47,29 +47,32 @@ // fcntl() #include +// strerror() +#include + #include +#include #include #include #include #include #include - -namespace lyx { - -using support::FileName; -using support::prefixIs; +using namespace std; +using namespace lyx::support; using ::boost::scoped_ptr; -namespace fs = ::boost::filesystem; -using std::string; -using std::vector; -using std::cout; -using std::cerr; -using std::cin; -using std::endl; +namespace lyx { +// Dummy LyXRC support +struct LyXRC { + string icon_set; +} lyxrc; + +// Keep the linker happy on Windows +void lyx_exit(int) +{} namespace support { @@ -84,21 +87,32 @@ string itoa(unsigned int i) /// Returns the absolute pathnames of all lyx local sockets in /// file system encoding. /// Parts stolen from lyx::support::DirList(). -vector lyxSockets(string const & dir, string const & pid) +FileNameList lyxSockets(string const & dir, string const & pid) { - FileName dirpath(dir); + FileNameList dirlist; + + FileName dirpath(dir + "/"); + + if (!dirpath.exists() || !dirpath.isDirectory()) { + lyxerr << dir << " does not exist or is not a directory." + << endl; + return dirlist; + } - vector dirlist = dirpath.dirList(); - vector::iterator it = dirlist.begin(); - vector::iterator const end = dirlist.end(); + FileNameList dirs = dirpath.dirList(""); + FileNameList::const_iterator it = dirs.begin(); + FileNameList::const_iterator end = dirs.end(); for (; it != end; ++it) { - if (prefixIs(it->baseName(), "lyx_tmpdir" + pid)) { - FileName lyxsocket(it->abs() + "lyxsocket"; - if (fs::exists(lyxsocket)) { - dirlist.push_back(lyxsocket); - } - } + if (!it->isDirectory()) + continue; + string const tmpdir = it->absFileName(); + if (!contains(tmpdir, "lyx_tmpdir" + pid)) + continue; + + FileName lyxsocket(tmpdir + "/lyxsocket"); + if (lyxsocket.exists()) + dirlist.push_back(lyxsocket); } return dirlist; @@ -135,7 +149,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; @@ -250,7 +264,7 @@ private: LyXDataSocket::LyXDataSocket(FileName const & address) { - if ((fd_ = support::socktools::connect(address)) == -1) { + if ((fd_ = socktools::connect(address)) == -1) { connected_ = false; } else { connected_ = true; @@ -343,8 +357,8 @@ void LyXDataSocket::writeln(string const & line) class CmdLineParser { public: typedef int (*optfunc)(vector const & args); - std::map helper; - std::map isset; + map helper; + map isset; bool parse(int, char * []); vector nonopt; }; @@ -400,9 +414,9 @@ void usage() "Usage: lyxclient [options]\n" "Options are:\n" " -a address set address of the lyx socket\n" - " -t directory set system temporary directory\n" + " -t directory set system temporary directory (for detecting sockets)\n" " -p pid select a running lyx by pidi\n" - " -c command send a single command and quit\n" + " -c command send a single command and quit (LYXCMD prefix needed)\n" " -g file row send a command to go to file and row\n" " -n name set client name\n" " -h name display this help end exit\n" @@ -423,7 +437,7 @@ int h(vector const &) docstring clientName = - from_ascii(support::itoa(::getppid()) + ">" + support::itoa(::getpid())); + from_ascii(itoa(::getppid()) + ">" + itoa(::getpid())); int n(vector const & arg) { @@ -555,9 +569,9 @@ int main(int argc, char * argv[]) } else { // We have to look for an address. // serverPid can be empty. - vector addrs = support::lyxSockets(to_filesystem8bit(cmdline::mainTmp), cmdline::serverPid); - vector::const_iterator addr = addrs.begin(); - vector::const_iterator end = addrs.end(); + FileNameList addrs = lyxSockets(to_filesystem8bit(cmdline::mainTmp), cmdline::serverPid); + FileNameList::const_iterator addr = addrs.begin(); + FileNameList::const_iterator end = addrs.end(); for (; addr != end; ++addr) { // Caution: addr->string() is in filesystem encoding server.reset(new LyXDataSocket(*addr)); @@ -571,7 +585,7 @@ int main(int argc, char * argv[]) << endl; return EXIT_FAILURE; } - cerr << "lyxclient: " << "Connected to " << addr->string() << endl; + cerr << "lyxclient: " << "Connected to " << addr->absFileName() << endl; } int const serverfd = server->fd(); @@ -618,7 +632,9 @@ int main(int argc, char * argv[]) iowatch.wait(); if (iowatch.isset(0)) { string command; - cin >> command; + getline(cin, command); + if (command.empty()) + continue; if (command == "BYE:") { server->writeln("BYE:"); saidbye = true;