]> git.lyx.org Git - lyx.git/blobdiff - src/client/client.cpp
Revert commenting the file format warnings
[lyx.git] / src / client / client.cpp
index a4883405a6d227cab16ffd3aad2e98ebebb33b9e..9b494c1eb201bd1e9ce63df1ea9eb763e71e765b 100644 (file)
@@ -47,6 +47,9 @@
 // fcntl()
 #include <fcntl.h>
 
+// strerror()
+#include <string.h>
+
 #include <cerrno>
 #include <cstdio>
 #include <cstdlib>
@@ -62,6 +65,15 @@ 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)
+{}
+
 namespace support {
 
 string itoa(unsigned int i)
@@ -94,7 +106,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 +149,7 @@ int connect(FileName const & name)
        if (::connect(fd,
                      reinterpret_cast<struct sockaddr *>(&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;
@@ -396,23 +408,28 @@ bool CmdLineParser::parse(int argc, char * argv[])
 
 namespace cmdline {
 
+    docstring mainTmp(from_ascii("/tmp"));
+
+
 void usage()
 {
        cerr <<
                "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"
          "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;
 }
 
@@ -485,7 +502,6 @@ int a(vector<docstring> const & arg)
 }
 
 
-docstring mainTmp(from_ascii("/tmp"));
 
 
 int t(vector<docstring> const & arg)
@@ -524,10 +540,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 +588,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 +643,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;