Skip to content

Commit 4943b73

Browse files
author
Peter Szabo
committed
adapted win32port/pdfsizeopt_winstub.c to the new pdfsizeopt_win32exec directory layout
1 parent 317ef8e commit 4943b73

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

win32port/pdfsizeopt_winstub.c

+29-13
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
//
2-
// pdfsizeopt_winstub.c: Start Python on Win32.
3-
// by pts@fazekas.hu at Wed Jun 27 14:07:04 CEST 2012
4-
//
5-
// Compile with: i586-mingw32msvc-gcc -mconsole -s -W -Wall -o pdfsizeopt.exe pdfsizeopt_winstub.c
1+
/*
2+
* pdfsizeopt_winstub.c: Start Python on Win32.
3+
* by pts@fazekas.hu at Wed Jun 27 14:07:04 CEST 2012
4+
*
5+
* Compile with: i586-mingw32msvc-gcc -mconsole -s -W -Wall -o ../pdfsizeopt.exe pdfsizeopt_winstub.c
6+
*/
67

78
#include <errno.h>
89
#include <limits.h> // PATH_MAX is 259.
@@ -33,6 +34,11 @@ static char is_in_dir(const char *file, const char *p, const char *q) {
3334
return 0 == stat(pathname, &st) && S_ISREG(st.st_mode);
3435
}
3536

37+
static char is_file(const char *pathname) {
38+
struct stat st;
39+
return 0 == stat(pathname, &st) && S_ISREG(st.st_mode);
40+
}
41+
3642
static void find_on_path(const char *prog, char *dir_out) {
3743
const char *path = getenv("PATH"), *p, *q;
3844
if (path != NULL || *path != '\0') {
@@ -58,12 +64,14 @@ static void find_on_path(const char *prog, char *dir_out) {
5864
*dir_out = '\0';
5965
}
6066

61-
static const char python_exe[] = "pdfsizeopt_python.exe";
62-
static const char pdfsizeopt_py[] = "pdfsizeopt.py";
67+
/* FILE_SEP inlined here. */
68+
static const char python_exe[] = "pdfsizeopt_win32exec\\pdfsizeopt_python.exe";
69+
static const char pdfsizeopt_py0[] = "pdfsizeopt";
70+
static const char pdfsizeopt_py1[] = "pdfsizeopt.single";
6371

6472
int main(int argc, char **argv) {
6573
char python_bin[PATH_MAX + 1], argv0_bin[PATH_MAX + 1], *p, *q;
66-
char prog_py[PATH_MAX + 1];
74+
char prog_py[PATH_MAX + 2];
6775
const char *moreargv[ARGV_MAX + 1];
6876
int i;
6977
(void)argc;
@@ -110,19 +118,27 @@ int main(int argc, char **argv) {
110118
strcpy(python_bin + i + 1, python_exe);
111119

112120
i = strlen(prog_py);
113-
if (i + strlen(pdfsizeopt_py) > PATH_MAX) {
114-
i = PATH_MAX - strlen(pdfsizeopt_py);
121+
if (i + strlen(pdfsizeopt_py0) > PATH_MAX) {
122+
i = PATH_MAX - strlen(pdfsizeopt_py0);
123+
}
124+
if (i + strlen(pdfsizeopt_py1) > PATH_MAX) {
125+
i = PATH_MAX - strlen(pdfsizeopt_py0);
126+
}
127+
prog_py[i++] = FILE_SEP;
128+
strcpy(prog_py + i, pdfsizeopt_py0);
129+
if (!is_file(prog_py)) {
130+
strcpy(prog_py + i, pdfsizeopt_py1);
131+
if (!is_file(prog_py)) {
132+
fprintf(stderr, "error: Python script missing: %s\n", prog_py);
133+
}
115134
}
116-
prog_py[i] = FILE_SEP;
117-
strcpy(prog_py + i + 1, pdfsizeopt_py);
118135

119136
moreargv[0] = "python26";
120137
moreargv[1] = prog_py;
121138
for (i = 1; argv[i] != NULL; ++i) {
122139
moreargv[i + 1] = argv[i];
123140
}
124141
moreargv[i + 1] = NULL;
125-
126142

127143
// execv(...) and P_OVERLAY don't work well in wine-1.2.2 and Windows XP,
128144
// because they make this process return before the started process finishes.

0 commit comments

Comments
 (0)