On Tue, 28 Oct 2003, Alfredo Braunstein wrote:
> JoĆ£o, it would be asking too much to repost an updated version of all your > pending patches? > > I'll apply non-controversial ones and ask for advice on the rest. * putenv.diff: allocate space for the exported string and store the pointers in a static map<>. Pointers are deleted when a variable is overwritten, so the function doesn't leak memory. * export-socket.diff: export variables EDITOR and LYXSOCKET when the socket is created. Since there is no need of passing the socket address through $$a, it is removed from format.C. Xdvi must then be called with no arguments, and kdvi works if the editor is defined as 'lyxclient -g %f %l'. * export-lyxclient.diff: makes lyxclient work with LYXSOCKET environment variable. * lyxclient.man: manual page for lyxclient. I again ask some native english speaker to revise it, please. * socket-qt.diff: bring lyxsocket to qt. * socket_callback.{C,h}: class analogous to io_callback for sockets. They must be placed under src/frontends/qt2. TODO: * make lib/configure detect if there is a --src or --src-specials option available for latex or if there is a srcltx.sty package and then set the variable \srcspecials latexoption "--src-specials" or \srcspecials package "srcltx.sty" (or whatever is best) * Make latex generate source specials only when previewing, not when exporting DVI. Alfredo, I have been looking at the "flavours" code. Do you think that a good solution would be defining a latex + src specials flavour? * forward search. Regards, Joćo.
Index: src/support/ChangeLog =================================================================== RCS file: /cvs/lyx/lyx-devel/src/support/ChangeLog,v retrieving revision 1.228 diff -u -r1.228 ChangeLog --- src/support/ChangeLog 2003/11/03 17:47:28 1.228 +++ src/support/ChangeLog 2003/11/05 06:08:40 @@ -1,3 +1,10 @@ +2003-11-05 Joćo Luis M. Assirati <[EMAIL PROTECTED]> + + * putenv.C: allocate the string before putting it into the + environment. + + * lyxlib.h: adjust. + 2003-11-03 Lars Gullik Bjųnnes <[EMAIL PROTECTED]> * tempname.C (tempName): use scoped_array for exception safety Index: src/support/putenv.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/support/putenv.C,v retrieving revision 1.8 diff -u -r1.8 putenv.C --- src/support/putenv.C 2003/08/23 00:16:57 1.8 +++ src/support/putenv.C 2003/11/05 06:08:40 @@ -4,6 +4,7 @@ * Licence details can be found in the file COPYING. * * \author Lars Gullik Bjųnnes + * \author Joćo Luis M. Assirati * * Full author contact details are available in file CREDITS. */ @@ -13,8 +14,24 @@ #include "lyxlib.h" #include <cstdlib> +#include <string> +#include <map> -int lyx::support::putenv(char const * str) +using std::string; +using std::map; + +bool lyx::support::putenv(string const & varname, string const & value) { - return ::putenv(const_cast<char*>(str)); + static map<string, char *> varmap; + + string str = varname + '=' + value; + char * newptr = new char[str.size() + 1]; + newptr[str.copy(newptr, string::npos)] = '\0'; + bool status = (::putenv(newptr) == 0); + + char * oldptr = varmap[varname]; + if(oldptr) delete oldptr; + varmap[varname] = newptr; + + return status; } Index: src/support/lyxlib.h =================================================================== RCS file: /cvs/lyx/lyx-devel/src/support/lyxlib.h,v retrieving revision 1.34 diff -u -r1.34 lyxlib.h --- src/support/lyxlib.h 2003/10/06 15:43:18 1.34 +++ src/support/lyxlib.h 2003/11/05 06:08:40 @@ -40,8 +40,8 @@ void abort(); /// create the given directory with the given mode int mkdir(std::string const & pathname, unsigned long int mode); -/// put a C std::string into the environment -int putenv(char const * str); +/// put variable=value as a C std::string into the environment +bool putenv(std::string const & varname, std::string const & value); /// unlink the given file int unlink(std::string const & file); /// remove the given directory
Index: development/lyxsocket/lyxclient.C =================================================================== RCS file: /cvs/lyx/lyx-devel/development/lyxsocket/lyxclient.C,v retrieving revision 1.1 diff -u -r1.1 lyxclient.C --- development/lyxsocket/lyxclient.C 2003/10/13 12:25:08 1.1 +++ development/lyxsocket/lyxclient.C 2003/11/05 06:12:32 @@ -13,7 +13,6 @@ #include <map> #include <iostream> - // getpid(), getppid() #include <sys/types.h> #include <unistd.h> @@ -35,6 +34,8 @@ // fcntl() #include <fcntl.h> +// getenv() +#include <cstdlib> using std::string; using std::vector; @@ -75,8 +76,7 @@ // Parts stolen from lyx::support::DirList() -// Returns pathnames begining with dir and ending with -// pathname separator (/ in unix) +// Returns the absolute pathnames of all lyx local sockets vector<string> lyxSockets(string const & dir, string const & pid) { vector<string> dirlist; @@ -94,6 +94,7 @@ string lyxsocket = dir + '/' + fil + "/lyxsocket"; struct stat status; // not checking if it is a socket -- just if it exists + // and has reading permissions if (!::stat(lyxsocket.c_str(), &status)) { dirlist.push_back(lyxsocket); } @@ -124,7 +125,7 @@ addr.sun_path[len] = '\0'; if((fd = ::socket(PF_UNIX, SOCK_STREAM, 0))== -1) { - cerr << "lyxclient: Could not create socket: " + cerr << "lyxclient: Could not create socket descriptor: " << strerror(errno) << endl; return -1; } @@ -415,7 +416,8 @@ return 2; } -char * serverAddress; +// 0 if LYXSOCKET is not set in the environment +char * serverAddress = getenv("LYXSOCKET"); int a(vector<char *> const & arg) { if(arg.size() < 1) { @@ -423,6 +425,7 @@ << endl; return -1; } + // -a supercedes LYXSOCKET environment variable serverAddress = arg[0]; return 1; } @@ -457,25 +460,25 @@ int main(int argc, char * argv[]) { - CmdLineParser parser; - parser.helper["-h"] = cmdline::h; - parser.helper["-c"] = cmdline::c; - parser.helper["-g"] = cmdline::g; - parser.helper["-n"] = cmdline::n; - parser.helper["-a"] = cmdline::a; - parser.helper["-t"] = cmdline::t; - parser.helper["-p"] = cmdline::p; + CmdLineParser args; + args.helper["-h"] = cmdline::h; + args.helper["-c"] = cmdline::c; + args.helper["-g"] = cmdline::g; + args.helper["-n"] = cmdline::n; + args.helper["-a"] = cmdline::a; + args.helper["-t"] = cmdline::t; + args.helper["-p"] = cmdline::p; // Command line failure conditions: - if((!parser.parse(argc, argv)) - || (parser.isset["-c"] && parser.isset["-g"]) - || (parser.isset["-a"] && parser.isset["-p"])) { + if((!args.parse(argc, argv)) + || (args.isset["-c"] && args.isset["-g"]) + || (args.isset["-a"] && args.isset["-p"])) { cmdline::usage(); return 1; } LyXDataSocket * server; - if(parser.isset["-a"]) { + if(cmdline::serverAddress) { server = new LyXDataSocket(cmdline::serverAddress); if(!server->connected()) { cerr << "lyxclient: " << "Could not connect to " @@ -526,7 +529,7 @@ return 1; } - if(parser.isset["-g"] || parser.isset["-c"]) { + if(args.isset["-g"] || args.isset["-c"]) { server->writeln(cmdline::singleCommand); iowatch.wait(2.0); if(iowatch.isset(serverfd) && server->readln(answer)) {
Index: src/ChangeLog =================================================================== RCS file: /cvs/lyx/lyx-devel/src/ChangeLog,v retrieving revision 1.1682 diff -u -r1.1682 ChangeLog --- src/ChangeLog 2003/11/04 12:36:52 1.1682 +++ src/ChangeLog 2003/11/05 06:10:55 @@ -1,3 +1,9 @@ +2003-11-05 Joćo Luis M. Assirati <[EMAIL PROTECTED]> + + * lyxsocket.C: export variables XEDITOR and LYXSOCKET + + * format.C: remove unneeded $$a + 2003-11-04 André Pönitz <[EMAIL PROTECTED]> * cursor.[Ch]: restructure Index: src/lyxsocket.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/lyxsocket.C,v retrieving revision 1.3 diff -u -r1.3 lyxsocket.C --- src/lyxsocket.C 2003/11/03 17:47:22 1.3 +++ src/lyxsocket.C 2003/11/05 06:10:55 @@ -45,6 +45,13 @@ lyxerr << "lyx: Disabling LyX socket." << endl; return; } + + // These env vars are used by DVI inverse search + // Needed by xdvi + lyx::support::putenv("XEDITOR", "lyxclient -g %f %l"); + // Needed by lyxclient + lyx::support::putenv("LYXSOCKET", address_); + lyx_gui::set_serversocket_callback(this); lyxerr[Debug::LYXSERVER] << "lyx: New server socket " << fd_ << ' ' << address_ << endl; Index: src/format.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/format.C,v retrieving revision 1.20 diff -u -r1.20 format.C --- src/format.C 2003/10/14 11:35:50 1.20 +++ src/format.C 2003/11/05 06:10:55 @@ -16,7 +16,6 @@ #include "lyxrc.h" #include "debug.h" #include "gettext.h" -#include "lyxsocket.h" #include "frontends/Alert.h" //to be removed? @@ -37,13 +36,10 @@ using std::string; -extern LyXServerSocket * lyxsocket; - namespace { string const token_from("$$i"); string const token_path("$$p"); -string const token_socket("$$a"); } //namespace anon @@ -199,7 +195,6 @@ command = subst(command, token_from, QuoteName(OnlyFilename(filename))); command = subst(command, token_path, QuoteName(OnlyPath(filename))); - command = subst(command, token_socket, QuoteName(lyxsocket->address())); lyxerr[Debug::FILES] << "Executing command: " << command << std::endl; buffer.message(_("Executing command: ") + command);
Index: src/frontends/qt2/ChangeLog =================================================================== RCS file: /cvs/lyx/lyx-devel/src/frontends/qt2/ChangeLog,v retrieving revision 1.605 diff -u -r1.605 ChangeLog --- src/frontends/qt2/ChangeLog 2003/11/04 12:01:10 1.605 +++ src/frontends/qt2/ChangeLog 2003/11/05 06:14:06 @@ -1,3 +1,10 @@ +2003-11-05 Joćo Luis M. Assirati <[EMAIL PROTECTED]> + + * {set,remove}_{server,data}socket_callback(): Working functions + + * socket_callback.[Ch]: new files with a class to connect sockets + + * Makefile.dialogs: add the above 2003-11-04 Alfredo Braunstein <[EMAIL PROTECTED]> Index: src/frontends/qt2/Makefile.dialogs =================================================================== RCS file: /cvs/lyx/lyx-devel/src/frontends/qt2/Makefile.dialogs,v retrieving revision 1.45 diff -u -r1.45 Makefile.dialogs --- src/frontends/qt2/Makefile.dialogs 2003/10/23 11:58:00 1.45 +++ src/frontends/qt2/Makefile.dialogs 2003/11/05 06:14:06 @@ -125,4 +125,5 @@ QURLDialog.C QURLDialog.h \ QVCLogDialog.C QVCLogDialog.h \ QWrapDialog.C QWrapDialog.h \ - QLToolbar.C QLToolbar.h + QLToolbar.C QLToolbar.h \ + socket_callback.C socket_callback.h
// -*- C++ -*- /** * \file io_callback.h * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * * \author unknown * \author John Levon * \author Joćo Luis M. Assirati * * Full author contact details are available in file CREDITS. */ #ifndef SOCKET_CALLBACK_H #define SOCKET_CALLBACK_H #include <qobject.h> #include <qsocketnotifier.h> #include <boost/scoped_ptr.hpp> class LyXServerSocket; class LyXDataSocket; /** * socket_callback - a simple wrapper for asynchronous socket notification * * This is used by the lyxsocket to notice the socket is ready to be * connected/read. * * FIXME: this code apparently will not work on Windows. */ class socket_callback : public QObject { Q_OBJECT public: /// connect a connection notification from the LyXServerSocket socket_callback(LyXServerSocket * server); socket_callback(LyXDataSocket * data); public slots: void server_received(); void data_received(); private: /// our notifier boost::scoped_ptr<QSocketNotifier> sn_; LyXServerSocket * server_; LyXDataSocket * data_; }; #endif // SOCKET_CALLBACK_H
/** * \file io_callback.C * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * * \author unknown * \author John Levon * \author Joćo Luis M. Assirati * * Full author contact details are available in file CREDITS. */ #include <config.h> #include "lyxsocket.h" #include "socket_callback.h" socket_callback::socket_callback(LyXServerSocket * server) : server_(server) { sn_.reset(new QSocketNotifier(server->fd(), QSocketNotifier::Read, this)); connect(sn_.get(), SIGNAL(activated(int)), this, SLOT(server_received())); } socket_callback::socket_callback(LyXDataSocket * data) : data_(data) { sn_.reset(new QSocketNotifier(data->fd(), QSocketNotifier::Read, this)); connect(sn_.get(), SIGNAL(activated(int)), this, SLOT(data_received())); } void socket_callback::server_received() { server_->serverCallback(); } void socket_callback::data_received() { data_->server()->dataCallback(data_); }