Asger Ottar Alstrup wrote:
> Angus Leeming wrote:
>> In all seriousness, if you are interested in working on LyX under Visual
>> Studio, then why not take this on?
>
> Fair enough. Is the CVS source ready for Visual Studio now? I.e. are all
> windows patches merged?
No. Attached is the remaining 'kludge' patch that is needed to get LyX to
compile with gcc under MinGW/MinSYS. I made this on 10 Jan, so it's
possibly a little out of date, but you shouldn't have any problems
applying it.
NOTE. I'm testing only LyX 1.3.x. I'm applying changes to both 1.3.x and to
1.4.x but LyX 1.4.x will certainly not compile just yet. You'll need an
equivalent to the 1.3.x 'kludge' patch.
Nonetheless, as you can see from the patch, I've got to the stage where
really only the child process stuff needs sorting out. I have some ideas
and some code, so I'd just apply the patch for now.
In addition, Ruurd has a patch for a brainless MSVC compiler (v6?) that he
needs on top of the primary patch. See
http://www.home.zonnet.nl/rareitsma/lyx/msvc.diff
My current road map:
* Kayvan's cygwin_path_fix thingie. In hand.
* Define and use LyXRC::path_prefix and get rid of the
hard-coded MacOSX PATH nastiness in lyx_main.C.
Rationale: LyX uses sh to run a number of scripts at the
moment. Off the top of my head:
lib/configure
lib/scripts/convertDefault.sh
It also generates a shell script (src/graphics/GraphicsConverter.C)
to control the conversion of a graphics file to a format
loadable by the GUI frontend.
All these should be re-written in python but for now
Windows will need to use LyXRC::path_prefix if it is to find
a sh.exe. I don't suppose such a thing is in your normal PATH.
* Augment the 1.3.x version of LibScriptSearch to recognize $$s,
just like the 1.4.x version does. (Just backport the 1.4.x code,
actually.)
That means that converters will be defined as
sh $$s/convertDefault.sh
python $$s/lyxpreview2ppm.py
We've been getting reports from the Windows users that things
like convertDefault.sh and lyx2lyx aren't starting and that's
entirely because of the way they're invoked.
* Exit if the Package::temp_dir() does not exist and the user
has LyXRC::use_tempdir == true (use_tempdir is used only on
1.3.x).
Once I've addressed these issues, I'll return to the 'kludge' patch.
--
Angus
Index: src/ispell.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ispell.C,v
retrieving revision 1.5.2.5
diff -u -p -r1.5.2.5 ispell.C
--- src/ispell.C 7 Dec 2004 10:48:23 -0000 1.5.2.5
+++ src/ispell.C 11 Jan 2005 09:03:03 -0000
@@ -21,12 +21,20 @@
#include "support/forkedcall.h"
#include "support/lstrings.h"
+#ifdef _WIN32
+# include "support/os_win32.h"
+#endif
+
// HP-UX 11.x doesn't have this header
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif
#include <sys/time.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
#ifndef CXX_GLOBAL_CSTD
using std::strcpy;
using std::strlen;
@@ -309,11 +317,15 @@ bool ISpell::select(bool & err_read)
tv.tv_sec = 2;
tv.tv_usec = 0;
+#ifdef HAVE_SELECT
retval = ::select(SELECT_TYPE_ARG1 (max(pipeout[0], pipeerr[0]) + 1),
SELECT_TYPE_ARG234 (&infds),
0,
0,
SELECT_TYPE_ARG5 (&tv));
+#else
+ retval = -1;
+#endif
// error
if (retval <= 0)
Index: src/lyx_cb.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyx_cb.C,v
retrieving revision 1.190.2.3
diff -u -p -r1.190.2.3 lyx_cb.C
--- src/lyx_cb.C 10 Jan 2005 19:17:24 -0000 1.190.2.3
+++ src/lyx_cb.C 11 Jan 2005 09:03:04 -0000
@@ -37,6 +37,10 @@
#include "support/systemcall.h"
#include "support/lstrings.h"
+#ifdef _WIN32
+# include "support/os_win32.h" // fork()
+#endif
+
#include "BoostFormat.h"
#include <fstream>
Index: src/lyx_main.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyx_main.C,v
retrieving revision 1.134.2.9
diff -u -p -r1.134.2.9 lyx_main.C
--- src/lyx_main.C 10 Jan 2005 19:17:25 -0000 1.134.2.9
+++ src/lyx_main.C 11 Jan 2005 09:03:05 -0000
@@ -36,6 +36,10 @@
#include "support/package.h"
#include "support/path.h"
+#ifdef _WIN32
+# include "support/os_win32.h" // SIGHUP
+#endif
+
#include "BoostFormat.h"
#include <boost/function.hpp>
Index: src/lyxserver.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxserver.C,v
retrieving revision 1.48.2.2
diff -u -p -r1.48.2.2 lyxserver.C
--- src/lyxserver.C 10 Jan 2005 19:17:27 -0000 1.48.2.2
+++ src/lyxserver.C 11 Jan 2005 09:03:05 -0000
@@ -49,6 +49,10 @@
#include "support/lyxlib.h"
#include "frontends/lyx_gui.h"
+#ifdef _WIN32
+# include "support/os_win32.h" // F_SETFL, O_NONBLOCK, fcntl
+#endif
+
#ifdef __EMX__
#include <cstdlib>
#include <io.h>
Index: src/support/forkedcall.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/forkedcall.C,v
retrieving revision 1.11.2.2
diff -u -p -r1.11.2.2 forkedcall.C
--- src/support/forkedcall.C 7 Dec 2004 10:50:09 -0000 1.11.2.2
+++ src/support/forkedcall.C 11 Jan 2005 09:03:08 -0000
@@ -30,6 +30,9 @@
#include "lyxlib.h"
#include "filetools.h"
#include "os.h"
+#ifdef _WIN32
+#include "os_win32.h"
+#endif
#include "debug.h"
#include "frontends/Timeout.h"
@@ -37,7 +40,9 @@
#include <cerrno>
#include <sys/types.h>
-#include <sys/wait.h>
+#ifdef HAVE_SYS_WAIT_H
+# include <sys/wait.h>
+#endif
#include <csignal>
#include <cstdlib>
#include <unistd.h>
@@ -155,7 +160,7 @@ bool ForkedProcess::running() const
waitpid(pid(), &waitstatus, WNOHANG);
// Racy of course, but it will do.
- if (::kill(pid(), 0) && errno == ESRCH)
+ if (lyx::kill(pid(), 0) && errno == ESRCH)
return false;
return true;
}
@@ -269,7 +274,7 @@ int Forkedcall::generateChild()
}
argv[index] = 0;
-#ifndef __EMX__
+#if !defined(__EMX__) && !defined(_WIN32)
pid_t const cpid = ::fork();
if (cpid == 0) {
// Child
@@ -280,9 +285,12 @@ int Forkedcall::generateChild()
<< strerror(errno) << endl;
_exit(1);
}
-#else
+#elif __EMX__
pid_t const cpid = spawnvp(P_SESSION|P_DEFAULT|P_MINIMIZE|P_BACKGROUND,
argv[0], argv);
+#else //_WIN32
+ pid_t cpid = spawnvp(_P_NOWAIT,
+ argv[0], argv);
#endif
if (cpid < 0) {
Index: src/support/forkedcontr.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/forkedcontr.C,v
retrieving revision 1.6.2.3
diff -u -p -r1.6.2.3 forkedcontr.C
--- src/support/forkedcontr.C 7 Dec 2004 10:50:09 -0000 1.6.2.3
+++ src/support/forkedcontr.C 11 Jan 2005 09:03:09 -0000
@@ -19,6 +19,10 @@
#include "lyxfunctional.h"
#include "debug.h"
+#ifdef _WIN32
+#include "os_win32.h"
+#endif
+
#include "frontends/Timeout.h"
#include <boost/bind.hpp>
@@ -26,7 +30,10 @@
#include <cerrno>
#include <cstdlib>
#include <unistd.h>
-#include <sys/wait.h>
+
+#ifdef HAVE_SYS_WAIT_H
+# include <sys/wait.h>
+#endif
using std::vector;
using std::endl;
Index: src/support/kill.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/kill.C,v
retrieving revision 1.7
diff -u -p -r1.7 kill.C
--- src/support/kill.C 10 Jun 2002 17:31:57 -0000 1.7
+++ src/support/kill.C 11 Jan 2005 09:03:09 -0000
@@ -5,7 +5,40 @@
#include <sys/types.h>
#include <csignal>
+#ifdef _WIN32
+#include "debug.h"
+#include "os.h"
+
+#include <windows.h>
+#include <errno.h>
+
+using std::endl;
+#endif //_WIN32
+
int lyx::kill(int pid, int sig)
{
+#ifdef _WIN32
+ if (pid == (int)GetCurrentProcessId())
+ return -(raise(sig));
+ else{
+ HANDLE hProcess;
+ if (!(hProcess =
+ OpenProcess(PROCESS_ALL_ACCESS, TRUE, pid))) {
+ lyxerr << "kill OpenProcess failed!" << endl;
+ return -1;
+ }
+ else {
+ if (!TerminateProcess(hProcess, sig)){
+ lyxerr << "kill process failed!" << endl;
+ CloseHandle(hProcess);
+ return -1;
+ }
+ CloseHandle(hProcess);
+ }
+ }
+ return 0;
+
+#else
return ::kill(pid, sig);
+#endif
}
Index: src/support/os_win32.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/os_win32.C,v
retrieving revision 1.8.2.8
diff -u -p -r1.8.2.8 os_win32.C
--- src/support/os_win32.C 10 Jan 2005 19:17:31 -0000 1.8.2.8
+++ src/support/os_win32.C 11 Jan 2005 09:03:09 -0000
@@ -29,9 +29,32 @@ string const os::nulldev_ = "nul";
os::shell_type os::shell_ = os::CMD_EXE;
#endif
-
-void os::init(int, char *[])
-{}
+void os::init(int /* argc */, char * argv[])
+{
+#ifdef _WIN32
+ // Close the console when run (probably)
+ // not run from command prompt
+ char WindowTitle[1024];
+ HWND hwndFound;
+ GetConsoleTitle(WindowTitle,1024);
+ if ((strcmp(WindowTitle, argv[0]) == 0) ||
+ (strcmp(WindowTitle,"LyX") == 0)) {
+ // format a "unique" newWindowTitle
+ wsprintf(WindowTitle,"%d/%d",
+ GetTickCount(),
+ GetCurrentProcessId());
+ // change current window title
+ SetConsoleTitle(WindowTitle);
+ // ensure window title has been updated
+ Sleep(40);
+ // look for newWindowTitle
+ hwndFound=FindWindow(NULL, WindowTitle);
+ // If found, hide it
+ if ( hwndFound != NULL)
+ ShowWindow( hwndFound, SW_HIDE);
+ }
+#endif
+}
string os::current_root()
Index: src/support/os_win32.h
===================================================================
RCS file: src/support/os_win32.h
diff -N src/support/os_win32.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/support/os_win32.h 11 Jan 2005 09:03:09 -0000
@@ -0,0 +1,76 @@
+// os_win32.h copyright "Ruurd A. Reitsma" <[EMAIL PROTECTED]>
+
+#ifndef _OS_WIN32_H_
+#define _OS_WIN32_H_
+
+//Avoid zillions of windows includes
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+//fcntl.h
+#define FD_CLOEXEC 1 /* posix */
+#define F_DUPFD 0 /* Duplicate fildes */
+#define F_GETFD 1 /* Get fildes flags (close on exec) */
+#define F_SETFD 2 /* Set fildes flags (close on exec) */
+#define F_GETFL 3 /* Get file flags */
+#define F_SETFL 4 /* Set file flags */
+#define O_NONBLOCK 0x4000
+inline int fcntl (int, int, ...) {return -1;}
+
+//signal.h
+#define SIGHUP 1
+#define SIGKILL 9
+
+//sys/time.h
+//struct timeval {
+// long tv_sec;
+// long tv_usec;
+//};
+
+//unistd.h
+inline int fork () {return -1;}
+#define pipe(a) _pipe(a,0,0)
+
+
+//sys/wait.h
+#define waitpid(a,b,c) cwait(b,a,c)
+#define WNOHANG 1
+#define WUNTRACED 2
+#define WIFEXITED(a) 0
+#define WEXITSTATUS(a) 0
+#define WIFSIGNALED(a) 0
+#define WTERMSIG(a) 0
+#define WIFSTOPPED(a) 0
+#define WSTOPSIG(a) 0
+
+//sys/types.h
+#define fd_set int
+
+//sys/select.h
+//#define select(a,b,c,d,e) -1
+#define FD_ZERO(a)
+#define FD_SET(a,b)
+#define FD_ISSET(fd, set) 0
+
+#ifndef __MINGW32__ //already defined in mingw headers
+
+#define _S_IFBLK 0x3000
+#define S_IFIFO _S_IFIFO
+#define S_IFBLK _S_IFBLK
+#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
+#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
+#define popen(a,b) _popen(a,b)
+#define pclose(a) _pclose(a)
+
+#endif //!__MINGW32
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //_OS_WIN32_H_