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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
diff -ur dvipdfmx-20110311.orig/src/dpxfile.c dvipdfmx-20110311/src/dpxfile.c
--- dvipdfmx-20110311.orig/src/dpxfile.c 2011-03-11 04:10:51.000000000 +0100
+++ dvipdfmx-20110311/src/dpxfile.c 2011-06-06 09:50:11.000000000 +0200
@@ -154,10 +154,14 @@
{
char **cmdv, **qv;
char *p, *pp;
- char buf[512];
- int i, ret;
+ char buf[1024];
+ int i, ret = -1;
- if (!cmd || !*cmd)
+ if (!cmd)
+ return -1;
+ while (*cmd == ' ' || *cmd == '\t')
+ cmd++;
+ if (*cmd == '\0')
return -1;
i = 0;
p = cmd;
@@ -166,19 +170,16 @@
i++;
p++;
}
- cmdv = (char **) xmalloc (sizeof (char *) * (i+2));
+ cmdv = xcalloc (i + 2, sizeof (char *));
p = cmd;
qv = cmdv;
- while (*p == ' ' || *p == '\t')
- p++;
while (*p) {
pp = buf;
if (*p == '"') {
p++;
while (*p != '"') {
if (*p == '\0') {
- free (cmdv);
- return -1;
+ goto done;
}
*pp++ = *p++;
}
@@ -187,40 +188,41 @@
p++;
while (*p != '\'') {
if (*p == '\0') {
- free (cmdv);
- return -1;
+ goto done;
}
*pp++ = *p++;
}
p++;
} else {
- while (*p != ' ' && *p != '\t' && *p)
-#ifdef WIN32
+ while (*p != ' ' && *p != '\t' && *p) {
if (*p == '\'') {
- *pp++ = '\"';
+ p++;
+ while (*p != '\'') {
+ if (*p == '\0') {
+ goto done;
+ }
+ *pp++ = *p++;
+ }
p++;
} else {
*pp++ = *p++;
}
-#else
- *pp++ = *p++;
-#endif
+ }
}
*pp = '\0';
- if ((pp = strchr (buf, ' ')) || (pp = strchr (buf, '\t'))) {
#ifdef WIN32
+ if (strchr (buf, ' ') || strchr (buf, '\t'))
*qv = concat3 ("\"", buf, "\"");
-#else
- *qv = concat3 ("'", buf, "'");
+ else
#endif
- } else {
- *qv = concat (buf, "");
- }
+ *qv = xstrdup (buf);
+/*
+ fprintf(stderr,"\n%s", *qv);
+*/
while (*p == ' ' || *p == '\t')
p++;
qv++;
}
- *qv = NULL;
#ifdef WIN32
ret = spawnvp (_P_WAIT, *cmdv, (const char* const*) cmdv);
#else
@@ -229,7 +231,7 @@
ret = -1;
else if (i == 0) {
if (execvp (*cmdv, cmdv))
- ret = -1;
+ _exit (-1);
} else {
if (wait (&ret) == i) {
ret = (WIFEXITED (ret) ? WEXITSTATUS (ret) : -1);
@@ -238,14 +240,13 @@
}
}
#endif
+done:
qv = cmdv;
- if (qv) {
- while (*qv) {
- free (*qv);
- qv++;
- }
- free (cmdv);
+ while (*qv) {
+ free (*qv);
+ qv++;
}
+ free (cmdv);
return ret;
}
|