]> git.lyx.org Git - lyx.git/blob - development/Win32/win32_kludge.diff
Add Windows-specific code to userinfo.C.
[lyx.git] / development / Win32 / win32_kludge.diff
1 Index: src/DepTable.C
2 ===================================================================
3 RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/DepTable.C,v
4 retrieving revision 1.41
5 diff -u -a -u -r1.41 DepTable.C
6 --- src/DepTable.C      13 Oct 2003 01:01:33 -0000      1.41
7 +++ src/DepTable.C      18 Apr 2005 17:37:02 -0000
8 @@ -26,7 +26,9 @@
9  #include <fstream>
10  
11  #ifndef CXX_GLOBAL_CSTD
12 +# ifndef _WIN32
13  using std::time;
14 +# endif
15  #endif
16  
17  using lyx::support::ltrim;
18 Index: src/buffer.C
19 ===================================================================
20 RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.C,v
21 retrieving revision 1.615
22 diff -u -a -u -r1.615 buffer.C
23 --- src/buffer.C        18 Apr 2005 17:43:08 -0000      1.615
24 +++ src/buffer.C        18 Apr 2005 17:37:02 -0000
25 @@ -78,7 +78,11 @@
26  #include <boost/bind.hpp>
27  #include <boost/filesystem/operations.hpp>
28  
29 -#include <utime.h>
30 +#ifdef _WIN32
31 +# include <windows.h>
32 +#else
33 +# include <utime.h>
34 +#endif
35  
36  #include <iomanip>
37  #include <stack>
38 Index: src/cursor.C
39 ===================================================================
40 RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor.C,v
41 retrieving revision 1.123
42 diff -u -a -u -r1.123 cursor.C
43 --- src/cursor.C        25 Feb 2005 11:55:31 -0000      1.123
44 +++ src/cursor.C        18 Apr 2005 17:37:02 -0000
45 @@ -58,7 +58,9 @@
46  using std::vector;
47  using std::endl;
48  #ifndef CXX_GLOBAL_CSTD
49 +# ifndef _WIN32
50  using std::isalpha;
51 +# endif
52  #endif
53  using std::min;
54  using std::swap;
55 Index: src/ispell.C
56 ===================================================================
57 RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ispell.C,v
58 retrieving revision 1.25
59 diff -u -a -u -r1.25 ispell.C
60 --- src/ispell.C        20 Jan 2005 16:17:36 -0000      1.25
61 +++ src/ispell.C        18 Apr 2005 17:37:02 -0000
62 @@ -24,11 +24,17 @@
63  
64  #include "support/forkedcall.h"
65  
66 +#ifdef _WIN32
67 +# include "support/os_win32.h"
68 +#endif
69 +
70  // HP-UX 11.x doesn't have this header
71  #ifdef HAVE_SYS_SELECT_H
72  #include <sys/select.h>
73  #endif
74 -#include <sys/time.h>
75 +#ifndef _WIN32
76 +# include <sys/time.h>
77 +#endif
78  
79  using boost::shared_ptr;
80  
81 @@ -88,6 +94,7 @@
82         }
83  
84         // child process
85 +#ifndef _WIN32
86         dup2(pipein[0], STDIN_FILENO);
87         dup2(pipeout[1], STDOUT_FILENO);
88         dup2(pipeerr[1], STDERR_FILENO);
89 @@ -180,6 +187,7 @@
90  
91         lyxerr << "LyX: Failed to start ispell!" << endl;
92         _exit(0);
93 +#endif
94  }
95  
96  
97 @@ -191,6 +199,7 @@
98  {
99         lyxerr[Debug::GUI] << "Created ispell" << endl;
100  
101 +#ifndef _WIN32
102         // static due to the setvbuf. Ugly.
103         static char o_buf[BUFSIZ];
104  
105 @@ -275,6 +284,7 @@
106         close(pipeerr[1]);
107         child_->kill();
108         child_.reset(0);
109 +#endif
110  }
111  
112  
113 @@ -295,18 +305,23 @@
114                 fclose(out);
115         }
116  
117 +#ifndef _WIN32
118         close(pipein[0]);
119         close(pipein[1]);
120         close(pipeout[0]);
121         close(pipeout[1]);
122         close(pipeerr[0]);
123         close(pipeerr[1]);
124 +#endif
125         delete [] str;
126  }
127  
128  
129  bool ISpell::select(bool & err_read)
130  {
131 +#ifdef _WIN32
132 +       return false;
133 +#else
134         fd_set infds;
135         struct timeval tv;
136         int retval = 0;
137 @@ -316,11 +331,15 @@
138         tv.tv_sec = 2;
139         tv.tv_usec = 0;
140  
141 +#ifdef HAVE_SELECT
142         retval = ::select(SELECT_TYPE_ARG1 (max(pipeout[0], pipeerr[0]) + 1),
143                         SELECT_TYPE_ARG234 (&infds),
144                         0,
145                         0,
146                         SELECT_TYPE_ARG5 (&tv));
147 +#else
148 +       retval = -1;
149 +#endif
150  
151         // error
152         if (retval <= 0)
153 @@ -335,6 +354,7 @@
154         fgets(buf, BUFSIZ, in);
155         err_read = false;
156         return false;
157 +#endif
158  }
159  
160  
161 Index: src/lyx_cb.C
162 ===================================================================
163 RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyx_cb.C,v
164 retrieving revision 1.247
165 diff -u -a -u -r1.247 lyx_cb.C
166 --- src/lyx_cb.C        31 Jan 2005 10:42:18 -0000      1.247
167 +++ src/lyx_cb.C        18 Apr 2005 17:37:02 -0000
168 @@ -44,6 +44,10 @@
169  #include "support/path.h"
170  #include "support/systemcall.h"
171  
172 +#ifdef _WIN32
173 +# include "support/os_win32.h" // fork()
174 +#endif
175 +
176  #include <boost/shared_ptr.hpp>
177  #include <boost/filesystem/operations.hpp>
178  
179 Index: src/lyxserver.C
180 ===================================================================
181 RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxserver.C,v
182 retrieving revision 1.60
183 diff -u -a -u -r1.60 lyxserver.C
184 --- src/lyxserver.C     15 Feb 2005 11:04:40 -0000      1.60
185 +++ src/lyxserver.C     18 Apr 2005 17:37:02 -0000
186 @@ -54,6 +54,10 @@
187  #include <sys/stat.h>
188  #include <fcntl.h>
189  
190 +#ifdef _WIN32
191 +# include "support/os_win32.h" // F_SETFL, O_NONBLOCK, fcntl
192 +#endif
193 +
194  #ifdef __EMX__
195  #include <cstdlib>
196  #include <io.h>
197 @@ -180,6 +184,8 @@
198         // Imported handles can be used both with OS/2 APIs and emx
199         // library functions.
200         int const fd = _imphandle(os2fd);
201 +#elif defined(_WIN32)
202 +       int fd = -1;
203  #else
204         if (::access(filename.c_str(), F_OK) == 0) {
205                 lyxerr << "LyXComm: Pipe " << filename << " already exists.\n"
206 @@ -235,10 +241,12 @@
207         }
208  #endif
209  
210 +#ifndef _WIN32
211         if (::close(fd) < 0) {
212                 lyxerr << "LyXComm: Could not close pipe " << filename
213                        << '\n' << strerror(errno) << endl;
214         }
215 +#endif
216  
217  // OS/2 pipes are deleted automatically
218  #ifndef __EMX__
219 @@ -274,7 +282,13 @@
220         errno = 0;
221         int status;
222         // the single = is intended here.
223 -       while ((status = ::read(infd, charbuf, charbuf_size - 1))) {
224 +       while ((status = 
225 +#ifndef _WIN32
226 +               ::read(infd, charbuf, charbuf_size - 1)
227 +#else
228 +               -1
229 +#endif
230 +               )) {
231  
232                 if (status > 0) {
233                         charbuf[status] = '\0'; // turn it into a c string
234 @@ -331,6 +345,9 @@
235  
236         if (pipename.empty()) return;
237  
238 +#ifdef _WIN32
239 +       return;
240 +#else
241         if (!ready) {
242                 lyxerr << "LyXComm: Pipes are closed. Could not send "
243                        << msg << endl;
244 @@ -341,6 +358,7 @@
245                 closeConnection();
246                 openConnection();
247         }
248 +#endif
249  #ifdef __EMX__
250         APIRET rc;
251         int errnum;
252 Index: src/lyxsocket.C
253 ===================================================================
254 RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxsocket.C,v
255 retrieving revision 1.7
256 diff -u -a -u -r1.7 lyxsocket.C
257 --- src/lyxsocket.C     15 Feb 2005 13:45:40 -0000      1.7
258 +++ src/lyxsocket.C     18 Apr 2005 17:37:02 -0000
259 @@ -69,7 +69,9 @@
260  LyXServerSocket::~LyXServerSocket()
261  {
262         lyx_gui::unregister_socket_callback(fd_);
263 +#ifndef _WIN32
264         ::close(fd_);
265 +#endif
266         lyx::support::unlink(address_);
267         lyxerr[Debug::LYXSERVER] << "lyx: Server socket quitting" << endl;
268  }
269 @@ -156,7 +158,11 @@
270  {
271         string const linen(line + '\n');
272         int const size = linen.size();
273 +#ifndef _WIN32
274         int const written = ::write(fd_, linen.c_str(), size);
275 +#else
276 +       int const written = -1;
277 +#endif
278         if (written < size) { // Allways mean end of connection.
279                 if ((written == -1) && (errno == EPIPE)) {
280                         // The program will also receive a SIGPIPE
281 @@ -195,7 +201,9 @@
282  
283  LyXDataSocket::~LyXDataSocket()
284  {
285 +#ifndef _WIN32
286         ::close(fd_);
287 +#endif
288  
289         lyx_gui::unregister_socket_callback(fd_);
290         lyxerr[Debug::LYXSERVER] << "lyx: Data socket " << fd_ << " quitting."
291 @@ -217,7 +225,13 @@
292         int count;
293  
294         // read and store characters in buffer
295 -       while ((count = ::read(fd_, charbuf, charbuf_size - 1)) > 0) {
296 +       while ((count = 
297 +#ifndef _WIN32
298 +               ::read(fd_, charbuf, charbuf_size - 1)
299 +#else
300 +               0
301 +#endif
302 +               ) > 0) {
303                 buffer_.append(charbuf, charbuf + count);
304         }
305  
306 @@ -251,7 +265,11 @@
307  {
308         string const linen(line + '\n');
309         int const size = linen.size();
310 +#ifndef _WIN32
311         int const written = ::write(fd_, linen.c_str(), size);
312 +#else
313 +       int const written = -1;
314 +#endif
315         if (written < size) { // Allways mean end of connection.
316                 if ((written == -1) && (errno == EPIPE)) {
317                         // The program will also receive a SIGPIPE
318 Index: src/client/client.C
319 ===================================================================
320 RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/client/client.C,v
321 retrieving revision 1.7
322 diff -u -a -u -r1.7 client.C
323 --- src/client/client.C 20 Jan 2005 15:38:13 -0000      1.7
324 +++ src/client/client.C 18 Apr 2005 17:37:02 -0000
325 @@ -25,12 +25,14 @@
326  # include <unistd.h>
327  #endif
328  
329 +#ifndef _WIN32
330  // select()
331 -#include <sys/select.h>
332 +# include <sys/select.h>
333  
334  // socket(), connect()
335 -#include <sys/socket.h>
336 -#include <sys/un.h>
337 +# include <sys/socket.h>
338 +# include <sys/un.h>
339 +#endif
340  
341  // fcntl()
342  #include <fcntl.h>
343 Index: src/frontends/LyXView.C
344 ===================================================================
345 RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/LyXView.C,v
346 retrieving revision 1.51
347 diff -u -a -u -r1.51 LyXView.C
348 --- src/frontends/LyXView.C     13 Apr 2005 09:43:57 -0000      1.51
349 +++ src/frontends/LyXView.C     18 Apr 2005 17:37:02 -0000
350 @@ -39,7 +39,9 @@
351  
352  #include <boost/bind.hpp>
353  
354 -#include <sys/time.h>
355 +#ifndef _WIN32
356 +# include <sys/time.h>
357 +#endif
358  #ifdef HAVE_UNISTD_H
359  # include <unistd.h>
360  #endif
361 Index: src/frontends/qt2/QLyXKeySym.C
362 ===================================================================
363 RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QLyXKeySym.C,v
364 retrieving revision 1.32
365 diff -u -a -u -r1.32 QLyXKeySym.C
366 --- src/frontends/qt2/QLyXKeySym.C      7 Jul 2004 09:32:19 -0000       1.32
367 +++ src/frontends/qt2/QLyXKeySym.C      18 Apr 2005 17:37:02 -0000
368 @@ -74,7 +74,7 @@
369  void initEncodings()
370  {
371         // when no document open
372 -       encoding_map[""] = QTextCodec::codecForLocale();
373 +       encoding_map[std::string()] = QTextCodec::codecForLocale();
374  
375         encoding_map["iso8859-1"] = QTextCodec::codecForName("ISO 8859-1");
376         encoding_map["iso8859-2"] = QTextCodec::codecForName("ISO 8859-2");
377 Index: src/support/filetools.C
378 ===================================================================
379 RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/filetools.C,v
380 retrieving revision 1.207
381 diff -u -a -u -r1.207 filetools.C
382 --- src/support/filetools.C     18 Apr 2005 17:43:11 -0000      1.207
383 +++ src/support/filetools.C     19 Apr 2005 10:11:54 -0000
384 @@ -1052,6 +1051,11 @@
385  
386  cmd_ret const RunCommand(string const & cmd)
387  {
388 +#ifdef _WIN32
389 +       // TODO: Implement this, or merge it into forkedcall.
390 +       // Used for lyx2lyx in buffer.C, echo in math_extern and kpse in this file
391 +       return make_pair(-1, string());
392 +#else
393         // FIXME: replace all calls to RunCommand with ForkedCall
394         // (if the output is not needed) or the code in ispell.C
395         // (if the output is needed).
396 @@ -1092,6 +1096,7 @@
397         sigprocmask(SIG_SETMASK, &oldMask, 0);
398  
399         return make_pair(pret, ret);
400 +#endif
401  }
402  
403  
404 Index: src/support/globbing.C
405 ===================================================================
406 RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/globbing.C,v
407 retrieving revision 1.11
408 diff -u -a -u -r1.11 globbing.C
409 --- src/support/globbing.C      26 Nov 2004 14:37:40 -0000      1.11
410 +++ src/support/globbing.C      19 Apr 2005 08:09:32 -0000
411 @@ -10,6 +10,8 @@
412  
413  #include <config.h>
414  
415 +#if !defined (_WIN32)
416 +
417  #include "support/globbing.h"
418  #include "support/path.h"
419  
420 @@ -42,3 +44,5 @@
421  
422  } // namespace support
423  } // namespace lyx
424 +
425 +#endif
426 Index: src/support/os_win32.C
427 ===================================================================
428 RCS file: /cvs/lyx/lyx-devel/src/support/os_win32.C,v
429 retrieving revision 1.27
430 diff -u -r1.27 os_win32.C
431 --- src/support/os_win32.C      2005/01/21 22:08:59     1.27
432 +++ src/support/os_win32.C      2005/02/17 18:19:25
433 @@ -89,12 +89,14 @@
434         // Close the console when run (probably)
435         // not run from command prompt
436         char WindowTitle[1024];
437 -       HWND hwndFound;
438 -       GetConsoleTitle(WindowTitle,1024);
439 +       if (GetConsoleTitle(WindowTitle, sizeof(WindowTitle)) == 0) {
440 +               // Could not get the title, so we just leave things as they are
441 +               return;
442 +       }
443         if ((strcmp(WindowTitle, argv[0]) == 0) ||
444 -               (strcmp(WindowTitle,"LyX") == 0)) {
445 +               (strcmp(WindowTitle, "LyX") == 0)) {
446                 // format a "unique" newWindowTitle
447 -               wsprintf(WindowTitle,"%d/%d",
448 +               wsprintf(WindowTitle, "%d/%d",
449                         GetTickCount(),
450                         GetCurrentProcessId());
451                 // change current window title
452 @@ -102,10 +104,11 @@
453                 // ensure window title has been updated
454                 Sleep(40);
455                 // look for newWindowTitle
456 -               hwndFound=FindWindow(NULL, WindowTitle);
457 +               HWND hwndFound = FindWindow(NULL, WindowTitle);
458                 // If found, hide it
459 -               if ( hwndFound != NULL)
460 +               if ( hwndFound != NULL) {
461                         ShowWindow( hwndFound, SW_HIDE);
462 +               }
463         }
464  }
465  
466 Index: src/support/socktools.C
467 ===================================================================
468 RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/socktools.C,v
469 retrieving revision 1.6
470 diff -u -a -u -r1.6 socktools.C
471 --- src/support/socktools.C     20 Jan 2005 15:38:14 -0000      1.6
472 +++ src/support/socktools.C     19 Apr 2005 08:09:40 -0000
473 @@ -15,8 +15,10 @@
474  
475  #include "debug.h"
476  
477 +#ifndef _WIN32
478  #include <sys/socket.h>
479  #include <sys/un.h>
480 +#endif
481  #include <fcntl.h>
482  #ifdef HAVE_UNISTD_H
483  # include <unistd.h>
484 @@ -48,6 +50,7 @@
485  // special file 'name' will be created in the filesystem.
486  int listen(string const & name, int queue)
487  {
488 +#ifndef _WIN32
489         int fd; // File descriptor for the socket
490         sockaddr_un addr; // Structure that hold the socket address
491  
492 @@ -105,14 +108,17 @@
493                 lyx::support::unlink(name);
494                 return -1;
495         }
496 -
497         return fd;
498 +#else
499 +       return -1;
500 +#endif
501  }
502  
503  // Returns a file descriptor for a new connection from the socket
504  // descriptor 'sd' (or -1 in case of error)
505  int accept(int sd)
506  {
507 +#ifndef _WIN32
508         int fd;
509  
510         // Returns the new file descriptor or -1 in case of error
511 @@ -132,6 +138,9 @@
512                 return -1;
513         }
514         return fd;
515 +#else
516 +       return -1;
517 +#endif
518  }
519  
520  } // namespace socktools
521 Index: src/support/tempname.C
522 ===================================================================
523 RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/tempname.C,v
524 retrieving revision 1.25
525 diff -u -a -u -r1.25 tempname.C
526 --- src/support/tempname.C      20 Jan 2005 15:38:14 -0000      1.25
527 +++ src/support/tempname.C      19 Apr 2005 08:09:40 -0000
528 @@ -30,6 +30,10 @@
529  # include <sys/stat.h>
530  #endif
531  
532 +#ifdef _WIN32
533 +# include <io.h>
534 +#endif
535 +
536  using boost::scoped_array;
537  
538  using std::string;
539 @@ -42,6 +46,9 @@
540  {
541  #if defined(HAVE_MKSTEMP)
542         return ::mkstemp(templ);
543 +#elif defined(_WIN32)
544 +       ::_mktemp(templ);
545 +       return (int) ::fopen(templ, "w");
546  #elif defined(HAVE_MKTEMP)
547         // This probably just barely works...
548         ::mktemp(templ);
549 @@ -58,7 +65,9 @@
550  {
551         string const tmpdir(dir.empty() ? package().temp_dir() : dir);
552         string tmpfl(AddName(tmpdir, mask));
553 +#ifndef _WIN32
554         tmpfl += convert<string>(getpid());
555 +#endif
556         tmpfl += "XXXXXX";
557  
558         // The supposedly safe mkstemp version
559 @@ -69,7 +78,11 @@
560         int const tmpf = make_tempfile(tmpl.get());
561         if (tmpf != -1) {
562                 string const t(tmpl.get());
563 +#ifdef _WIN32
564 +               ::fclose((FILE *) tmpf);
565 +#else
566                 ::close(tmpf);
567 +#endif
568                 lyxerr[Debug::FILES] << "Temporary file `" << t
569                                      << "' created." << endl;
570                 return t;