]> git.lyx.org Git - lyx.git/blob - development/cygwin/lyxeditor.c
Cmake build: Amend 1b5f8f27
[lyx.git] / development / cygwin / lyxeditor.c
1 /**
2  * \file lyxeditor.c
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Enrico Forestieri
7  *
8  * Full author contact details are available in file CREDITS.
9  *
10  * This is a wrapper program for the lyxeditor.sh script or lyxclient program,
11  * meant to be used with yap or sumatrapdf for inverse search.
12  */
13
14 #include "config.h"
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <limits.h>
18 #include <cygwin/version.h>
19 #include <sys/cygwin.h>
20 #include <windows.h>
21
22 void convert_to_full_posix_path(char const * from, char *to)
23 {
24 #if CYGWIN_VERSION_DLL_MAJOR >= 1007
25     cygwin_conv_path(CCP_WIN_A_TO_POSIX, from, to, PATH_MAX);
26 #else
27     cygwin_conv_to_full_posix_path(from, to);
28 #endif
29 }
30
31 int main(int ac, char **av)
32 {
33         char * buf;
34         int bufsize;
35         char posixpath[PATH_MAX];
36
37         if (ac < 3 || ac > 4) {
38                 MessageBox(0, "Usage: lyxeditor [-g] <file.tex> <lineno>",
39                                 "ERROR: Wrong number of arguments", 0);
40                 return 1;
41         }
42
43         if (ac == 3) {
44                 char const * fmt = "lyxeditor.sh" PROGRAM_SUFFIX " '%s' %s";
45                 convert_to_full_posix_path(av[1], posixpath);
46                 bufsize = snprintf(0, 0, fmt, posixpath, av[2]) + 1;
47                 if ((buf = malloc(bufsize)))
48                         snprintf(buf, bufsize, fmt, posixpath, av[2]);
49         } else {
50                 char const * fmt = "lyxclient" PROGRAM_SUFFIX " %s '%s' %s";
51                 convert_to_full_posix_path(av[2], posixpath);
52                 bufsize = snprintf(0, 0, fmt, av[1], posixpath, av[3]) + 1;
53                 if ((buf = malloc(bufsize)))
54                         snprintf(buf, bufsize, fmt, av[1], posixpath, av[3]);
55         }
56
57         if (!buf) {
58                 MessageBox(0, "Too long arguments", "lyxeditor", 0);
59                 return 1;
60         }
61         system(buf);
62         free(buf);
63         return 0;
64 }