]> git.lyx.org Git - features.git/blobdiff - src/client/client.cpp
Let lyxclient read the whole line of input.
[features.git] / src / client / client.cpp
index 4b1962eb3bf30aea02f76a0a9c722ddce231e8b0..ede4e144255d03607d236856f788523c4ee890c5 100644 (file)
 
 #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 <boost/filesystem/operations.hpp>
 #include <boost/scoped_ptr.hpp>
 
 // getpid(), getppid()
 #include <iostream>
 
 using namespace std;
+using namespace lyx::support;
 
 using ::boost::scoped_ptr;
-namespace fs = ::boost::filesystem;
 
 namespace lyx {
 
-using support::FileName;
-using support::prefixIs;
-
 namespace support {
 
 string itoa(unsigned int i)
@@ -77,28 +74,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<fs::path> lyxSockets(string const & dir, string const & pid)
+FileNameList lyxSockets(string const & dir, string const & pid)
 {
-       vector<fs::path> dirlist;
+       FileNameList dirlist;
 
-       fs::path dirpath(dir);
+       FileName dirpath(dir + "/");
 
-       if (!fs::exists(dirpath) || !fs::is_directory(dirpath)) {
+       if (!dirpath.exists() || !dirpath.isDirectory()) {
                lyxerr << dir << " does not exist or is not a directory."
                       << endl;
                return dirlist;
        }
 
-       fs::directory_iterator beg((fs::path(dir)));
-       fs::directory_iterator end;
+       FileNameList dirs = dirpath.dirList("");
+       FileNameList::const_iterator it = dirs.begin();
+       FileNameList::const_iterator end = dirs.end();
 
-       for (; beg != end; ++beg) {
-               if (prefixIs(beg->leaf(), "lyx_tmpdir" + pid)) {
-                       fs::path lyxsocket = beg->path() / "lyxsocket";
-                       if (fs::exists(lyxsocket)) {
-                               dirlist.push_back(lyxsocket);
-                       }
-               }
+       for (; it != end; ++it) {
+               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;
@@ -250,7 +251,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 +344,8 @@ void LyXDataSocket::writeln(string const & line)
 class CmdLineParser {
 public:
        typedef int (*optfunc)(vector<docstring> const & args);
-       std::map<string, optfunc> helper;
-       std::map<string, bool> isset;
+       map<string, optfunc> helper;
+       map<string, bool> isset;
        bool parse(int, char * []);
        vector<char *> nonopt;
 };
@@ -423,7 +424,7 @@ int h(vector<docstring> const &)
 
 
 docstring clientName =
-       from_ascii(support::itoa(::getppid()) + ">" + support::itoa(::getpid()));
+       from_ascii(itoa(::getppid()) + ">" + itoa(::getpid()));
 
 int n(vector<docstring> const & arg)
 {
@@ -555,23 +556,23 @@ int main(int argc, char * argv[])
        } else {
                // We have to look for an address.
                // serverPid can be empty.
-               vector<fs::path> addrs = support::lyxSockets(to_filesystem8bit(cmdline::mainTmp), cmdline::serverPid);
-               vector<fs::path>::const_iterator addr = addrs.begin();
-               vector<fs::path>::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(FileName(to_utf8(from_filesystem8bit(addr->string())))));
+                       server.reset(new LyXDataSocket(*addr));
                        if (server->connected())
                                break;
                        lyxerr << "lyxclient: " << "Could not connect to "
-                            << addr->string() << endl;
+                            << addr->absFilename() << endl;
                }
                if (addr == end) {
                        lyxerr << "lyxclient: No suitable server found."
                               << 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 +619,7 @@ int main(int argc, char * argv[])
                iowatch.wait();
                if (iowatch.isset(0)) {
                        string command;
-                       cin >> command;
+                       getline(cin, command);
                        if (command == "BYE:") {
                                server->writeln("BYE:");
                                saidbye = true;