]> git.lyx.org Git - lyx.git/blob - development/cygwin/lyxwin.c
Don't need this.
[lyx.git] / development / cygwin / lyxwin.c
1 /**
2  * \file lyxwin.c
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Claus Hentschel
7  * \author Enrico Forestieri
8  *
9  * Full author contact details are available in file CREDITS.
10  *
11  * This is the wrapper program for LyX/Cygwin. Using this wrapper no
12  * DOS window will be present when running LyX from the Windows GUI.
13  * The bad side of this: no error output can be seen ;-)
14  *
15  * It launches the real binary using the native Windows GUI.
16  */
17
18 #include "config.h"
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <unistd.h>
22 #include <process.h>
23 #include <string.h>
24 #include <limits.h>
25 #include <sys/cygwin.h>
26 #include <windows.h>
27
28 int main (int argc, char **argv, char **environ)
29 {
30         FILE *fp;
31         char *s;
32         char posixpath[PATH_MAX];
33         char cmd[4096] = PACKAGE " ";
34         char const *nargs[5] = {
35                 "/bin/bash", "--login",
36                 "-c", cmd,
37                 NULL
38         };
39         int i = 1;
40
41         while (i < argc) {
42                 int done = 0;
43                 int lyxfile = (s = strrchr(argv[i], '.'))
44                                 && strcasecmp(s, ".lyx") == 0;
45                 /* Add initial quote */
46                 strcat(cmd, "\"");
47                 cygwin_conv_to_posix_path(argv[i], posixpath) ;
48                 /* Hack to account for shares */
49                 if (lyxfile && argv[i][0] == '\\' && argv[i][1] != '\\')
50                         strcat(cmd, "/");
51                 /* add the argument */
52                 strcat(cmd, posixpath);
53                 /* add closing quote */
54                 strcat(cmd, "\" ");
55                 if (!done && lyxfile && (s = strrchr(posixpath,'/'))) {
56                         *s = '\0';
57                         if (setenv("CDPATH", posixpath, 1) == 0)
58                                 done = 1;
59                 }
60                 ++i;
61         }
62
63         strcat(cmd, "</dev/null 1>/dev/null 2>&1");
64
65         /* fprintf(stderr , "Command is: |%s|\n", cmd); */
66         /* ensure bash reads our global env changes */
67         putenv("BASH_ENV=/etc/lyxprofile") ;
68         /* exec sub command */
69         spawnv(_P_NOWAIT, "/bin/bash", nargs);
70         /* exit with no error */
71         return(0) ;
72 }