]> git.lyx.org Git - lyx.git/blobdiff - src/client/client.cpp
* new function to set border around selection
[lyx.git] / src / client / client.cpp
index bf96e3e9b5c9b52e665b6191e5016fd3ba6a4eaa..e65e7ae731c9fc61468e8f99b35a225f43b32f5b 100644 (file)
 #include <map>
 #include <iostream>
 
-
-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 {
 
 namespace support {
 
@@ -84,17 +75,24 @@ 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<FileName> lyxSockets(string const & dir, string const & pid)
+vector<fs::path> lyxSockets(string const & dir, string const & pid)
 {
-       FileName dirpath(dir);
+       vector<fs::path> dirlist;
+
+       fs::path dirpath(dir);
+
+       if (!fs::exists(dirpath) || !fs::is_directory(dirpath)) {
+               lyxerr << dir << " does not exist or is not a directory."
+                      << endl;
+               return dirlist;
+       }
 
-       vector<FileName> dirlist = dirpath.dirList();
-       vector<FileName>::iterator it = dirlist.begin();
-       vector<FileName>::iterator const end = dirlist.end();
+       fs::directory_iterator beg((fs::path(dir)));
+       fs::directory_iterator end;
 
-       for (; it != end; ++it) {
-               if (prefixIs(it->baseName(), "lyx_tmpdir" + pid)) {
-                       FileName lyxsocket(it->abs() + "lyxsocket";
+       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);
                        }
@@ -250,7 +248,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 +341,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 +421,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,16 +553,16 @@ int main(int argc, char * argv[])
        } else {
                // We have to look for an address.
                // serverPid can be empty.
-               vector<FileName> addrs = support::lyxSockets(to_filesystem8bit(cmdline::mainTmp), cmdline::serverPid);
-               vector<FileName>::const_iterator addr = addrs.begin();
-               vector<FileName>::const_iterator end = addrs.end();
+               vector<fs::path> addrs = lyxSockets(to_filesystem8bit(cmdline::mainTmp), cmdline::serverPid);
+               vector<fs::path>::const_iterator addr = addrs.begin();
+               vector<fs::path>::const_iterator end = addrs.end();
                for (; addr != end; ++addr) {
                        // Caution: addr->string() is in filesystem encoding
-                       server.reset(new LyXDataSocket(*addr));
+                       server.reset(new LyXDataSocket(FileName(to_utf8(from_filesystem8bit(addr->string())))));
                        if (server->connected())
                                break;
                        lyxerr << "lyxclient: " << "Could not connect to "
-                            << addr->absFileName() << endl;
+                            << addr->string() << endl;
                }
                if (addr == end) {
                        lyxerr << "lyxclient: No suitable server found."