]> git.lyx.org Git - lyx.git/blob - development/cygwin/lyxwin.c
Customization: correct some color names.
[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 <cygwin/version.h>
26 #include <sys/cygwin.h>
27 #include <windows.h>
28
29 void convert_to_posix_path(char const * from, char *to)
30 {
31 #if CYGWIN_VERSION_DLL_MAJOR >= 1007
32     cygwin_conv_path(CCP_WIN_A_TO_POSIX | CCP_RELATIVE, from, to, PATH_MAX);
33 #else
34     cygwin_conv_to_posix_path(from, to);
35 #endif
36 }
37
38 int main (int argc, char **argv, char **environ)
39 {
40         FILE *fp;
41         char *s;
42         char posixpath[PATH_MAX];
43         char cmd[4096] = PACKAGE " ";
44         char const *nargs[5] = {
45                 "/bin/bash", "--login",
46                 "-c", cmd,
47                 NULL
48         };
49         int i = 1;
50
51         while (i < argc) {
52                 int done = 0;
53                 int lyxfile = (s = strrchr(argv[i], '.'))
54                                 && strcasecmp(s, ".lyx") == 0;
55                 /* Add initial quote */
56                 strcat(cmd, "\"");
57                 convert_to_posix_path(argv[i], posixpath) ;
58                 /* Hack to account for shares */
59                 if (lyxfile && argv[i][0] == '\\' && argv[i][1] != '\\')
60                         strcat(cmd, "/");
61                 /* add the argument */
62                 strcat(cmd, posixpath);
63                 /* add closing quote */
64                 strcat(cmd, "\" ");
65                 if (!done && lyxfile && (s = strrchr(posixpath,'/'))) {
66                         *s = '\0';
67                         if (setenv("CDPATH", posixpath, 1) == 0)
68                                 done = 1;
69                 }
70                 ++i;
71         }
72
73         strcat(cmd, "</dev/null 1>/dev/null 2>&1");
74
75         /* fprintf(stderr , "Command is: |%s|\n", cmd); */
76         /* ensure bash reads our global env changes */
77         putenv("BASH_ENV=" LYX_ABS_INSTALLED_DATADIR "/lyxprofile") ;
78         /* exec sub command */
79         spawnv(_P_NOWAIT, "/bin/bash", nargs);
80         /* exit with no error */
81         return(0) ;
82 }