File: lyxeditor.c

package info (click to toggle)
lyx 2.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 138,444 kB
  • sloc: cpp: 244,268; ansic: 106,398; xml: 72,791; python: 39,384; sh: 7,666; makefile: 6,584; pascal: 2,143; perl: 2,101; objc: 1,084; tcl: 163; sed: 16
file content (64 lines) | stat: -rw-r--r-- 1,646 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
 * \file lyxeditor.c
 * This file is part of LyX, the document processor.
 * Licence details can be found in the file COPYING.
 *
 * \author Enrico Forestieri
 *
 * Full author contact details are available in file CREDITS.
 *
 * This is a wrapper program for the lyxeditor.sh script or lyxclient program,
 * meant to be used with yap or sumatrapdf for inverse search.
 */

#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <cygwin/version.h>
#include <sys/cygwin.h>
#include <windows.h>

void convert_to_full_posix_path(char const * from, char *to)
{
#if CYGWIN_VERSION_DLL_MAJOR >= 1007
    cygwin_conv_path(CCP_WIN_A_TO_POSIX, from, to, PATH_MAX);
#else
    cygwin_conv_to_full_posix_path(from, to);
#endif
}

int main(int ac, char **av)
{
	char * buf;
	int bufsize;
	char posixpath[PATH_MAX];

	if (ac < 3 || ac > 4) {
		MessageBox(0, "Usage: lyxeditor [-g] <file.tex> <lineno>",
				"ERROR: Wrong number of arguments", 0);
		return 1;
	}

	if (ac == 3) {
		char const * fmt = "lyxeditor.sh" PROGRAM_SUFFIX " '%s' %s";
		convert_to_full_posix_path(av[1], posixpath);
		bufsize = snprintf(0, 0, fmt, posixpath, av[2]) + 1;
		if ((buf = malloc(bufsize)))
			snprintf(buf, bufsize, fmt, posixpath, av[2]);
	} else {
		char const * fmt = "lyxclient" PROGRAM_SUFFIX " %s '%s' %s";
		convert_to_full_posix_path(av[2], posixpath);
		bufsize = snprintf(0, 0, fmt, av[1], posixpath, av[3]) + 1;
		if ((buf = malloc(bufsize)))
			snprintf(buf, bufsize, fmt, av[1], posixpath, av[3]);
	}

	if (!buf) {
		MessageBox(0, "Too long arguments", "lyxeditor", 0);
		return 1;
	}
	system(buf);
	free(buf);
	return 0;
}