]> 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 5a5fbae2a716c1b494c6dcd114aa99f02615d928..e65e7ae731c9fc61468e8f99b35a225f43b32f5b 100644 (file)
 
 #include <config.h>
 
-#include "debug.h"
+#include "support/debug.h"
 #include "support/FileName.h"
 #include "support/unicode.h"
 #include "support/lstrings.h"
 
 #include <boost/filesystem/operations.hpp>
-#include <boost/lexical_cast.hpp>
 #include <boost/scoped_ptr.hpp>
 
 // getpid(), getppid()
 #include <map>
 #include <iostream>
 
+using namespace std;
+using namespace lyx::support;
 
-namespace lyx {
-
-using support::FileName;
-using support::prefixIs;
-
-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;
+using ::boost::scoped_ptr;
+namespace fs = ::boost::filesystem;
 
+namespace lyx {
 
 namespace support {
 
 string itoa(unsigned int i)
 {
-       return boost::lexical_cast<string>(i);
+       char buf[20];
+       sprintf(buf, "%d", i);
+       return buf;
 }
 
 
@@ -161,7 +153,12 @@ int connect(FileName const & name)
 
 
 
-// Class IOWatch ------------------------------------------------------------
+/////////////////////////////////////////////////////////////////////
+//
+// IOWatch
+//
+/////////////////////////////////////////////////////////////////////
+
 class IOWatch {
 public:
        IOWatch();
@@ -213,13 +210,19 @@ bool IOWatch::wait()
 }
 
 
-bool IOWatch::isset(int fd) {
+bool IOWatch::isset(int fd)
+{
        return FD_ISSET(fd, &act);
 }
-// ~Class IOWatch ------------------------------------------------------------
 
 
-// Class LyXDataSocket -------------------------------------------------------
+
+/////////////////////////////////////////////////////////////////////
+//
+// LyXDataSocket
+//
+/////////////////////////////////////////////////////////////////////
+
 // Modified LyXDataSocket class for use with the client
 class LyXDataSocket {
 public:
@@ -245,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;
@@ -327,15 +330,19 @@ void LyXDataSocket::writeln(string const & line)
                connected_ = false;
        }
 }
-// ~Class LyXDataSocket -------------------------------------------------------
 
 
-// Class CmdLineParser -------------------------------------------------------
+/////////////////////////////////////////////////////////////////////
+//
+// CmdLineParser
+//
+/////////////////////////////////////////////////////////////////////
+
 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;
 };
@@ -387,21 +394,22 @@ namespace cmdline {
 
 void usage()
 {
-       cerr << "Usage: lyxclient [options]" << endl
-            << "Options are:" << endl
-            << "  -a address    set address of the lyx socket" << endl
-            << "  -t directory  set system temporary directory" << endl
-            << "  -p pid        select a running lyx by pid" << endl
-            << "  -c command    send a single command and quit" << endl
-            << "  -g file row   send a command to go to file and row" << endl
-            << "  -n name       set client name" << endl
-            << "  -h name       display this help end exit" << endl
-            << "If -a is not used, lyxclient will use the arguments of -t and -p to look for" << endl
-            << "a running lyx. If -t is not set, 'directory' defaults to /tmp. If -p is set," << endl
-            << "lyxclient will connect only to a lyx with the specified pid. Options -c and -g" << endl
-            << "cannot be set simultaneoulsly. If no -c or -g options are given, lyxclient" << endl
-            << "will read commands from standard input and disconnect when command read is BYE:"
-            << endl;
+       cerr <<
+               "Usage: lyxclient [options]\n"
+         "Options are:\n"
+         "  -a address    set address of the lyx socket\n"
+         "  -t directory  set system temporary directory\n"
+         "  -p pid        select a running lyx by pidi\n"
+         "  -c command    send a single command and quit\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"
+         "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"
+         "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:"
+          << endl;
 }
 
 
@@ -412,7 +420,8 @@ int h(vector<docstring> const &)
 }
 
 
-docstring clientName(from_ascii(support::itoa(::getppid()) + ">" + support::itoa(::getpid())));
+docstring clientName =
+       from_ascii(itoa(::getppid()) + ">" + itoa(::getpid()));
 
 int n(vector<docstring> const & arg)
 {
@@ -503,14 +512,13 @@ int p(vector<docstring> const & arg)
 
 
 } // namespace cmdline
-
 } // namespace lyx
 
 
 int main(int argc, char * argv[])
 {
        using namespace lyx;
-       lyxerr.rdbuf(cerr.rdbuf());
+       lyxerr.setStream(cerr);
 
        char const * const lyxsocket = getenv("LYXSOCKET");
        if (lyxsocket)
@@ -545,7 +553,7 @@ 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> 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) {
@@ -635,4 +643,3 @@ void assertion_failed(char const* a, char const* b, char const* c, long d)
 }
 
 } // namespace boost
-