]> git.lyx.org Git - lyx.git/blob - development/Win32/patches/dvipost-1.1.patch
Scons: continue refining scons installer
[lyx.git] / development / Win32 / patches / dvipost-1.1.patch
1 diff -riwbBu -Xex dvipost-1.1/dvi.c dvipost-1.1-modified/dvi.c\r
2 --- dvipost-1.1/dvi.c   Wed Mar 22 14:59:58 2006\r
3 +++ dvipost-1.1-modified/dvi.c  Wed May 31 11:27:44 2006\r
4 @@ -502,8 +502,12 @@\r
5                 for (i = 0; i < pos_changed.dim; i++)\r
6                 {\r
7                         POS *p = pos_changed.tab + i;\r
8 +                       if (!p->type)\r
9 +                               dout_special(out, osstart);     \r
10                         cmd_goto(out, p->end, cbcol);\r
11                         dout_putrule(out, p->end - p->beg, cbrule);\r
12 +                       if (!p->type)\r
13 +                               dout_special(out, osend);\r
14                 }\r
15  \r
16                 dout_special(out, cbend);\r
17 @@ -625,10 +629,9 @@\r
18         mv_right(w);\r
19         text_cnt++;\r
20  \r
21 -       if      (!cbmode[page_stat])    return;\r
22 -\r
23 +       if      (!cbmode[page_stat] && !osmode[page_stat])      return;\r
24         pos_add(&pos_changed, dvi_stat.v - text_height - cbexp,\r
25 -               dvi_stat.v + text_depth + cbexp);\r
26 +               dvi_stat.v + text_depth + cbexp, cbmode[page_stat]);\r
27  \r
28         if      (cbframe)\r
29         {\r
30 diff -riwbBu -Xex dvipost-1.1/dvipost.c dvipost-1.1-modified/dvipost.c\r
31 --- dvipost-1.1/dvipost.c       Mon Nov  4 08:44:46 2002\r
32 +++ dvipost-1.1-modified/dvipost.c      Mon Sep 18 13:11:58 2006\r
33 @@ -1,6 +1,7 @@\r
34  /*     dvi file post processing\r
35  \r
36  $Copyright (C) 2002 Erich Fruehstueck\r
37 +Modified version by LyX Team\r
38  \r
39  Dvipost is free software; you can redistribute it and/or\r
40  modify it under the terms of the GNU General Public\r
41 @@ -18,13 +19,20 @@\r
42  59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.\r
43  */\r
44  \r
45 -\r
46  #include "dvipost.h"\r
47  #include "dvi.h"\r
48 +#if !defined(_MSC_VER)\r
49  #include <unistd.h>\r
50  #include <dirent.h>\r
51 +#else\r
52 +#include "dirent.h"\r
53 +#endif\r
54  #include <sys/stat.h>\r
55  \r
56 +#ifdef _WIN32\r
57 +#include <windows.h>\r
58 +#endif\r
59 +\r
60  int dvipost (const char *iname, const char *oname)\r
61  {\r
62         FILE *input, *tmp, *output;\r
63 @@ -33,7 +41,19 @@\r
64  \r
65  /*     open temporary file\r
66  */\r
67 +#ifndef _WIN32\r
68         tmp = tmpfile();\r
69 +#else\r
70 +       /* create temporary file in Windows temp directory */\r
71 +\r
72 +       char tmppath[MAX_PATH-14];\r
73 +       char tmpname[MAX_PATH];\r
74 +\r
75 +       GetTempPath(MAX_PATH-14, tmppath);\r
76 +       GetTempFileName(tmppath, "dvp", 0, tmpname);\r
77 +\r
78 +       tmp = fopen(tmpname, "r+b");\r
79 +#endif\r
80  \r
81         if      (!tmp)\r
82         {\r
83 @@ -57,8 +77,10 @@\r
84         }\r
85         else\r
86         {\r
87 +#ifndef _WIN32\r
88                 iname = "<stdin>";\r
89                 input = stdin;\r
90 +#endif\r
91         }\r
92  \r
93  /*     check magic and process input\r
94 @@ -94,6 +116,8 @@\r
95  \r
96  /*     copy file to output\r
97  */\r
98 +\r
99 +#ifndef _WIN32\r
100         rewind(tmp);\r
101  \r
102         if      (oname && strcmp(oname, "-") != 0)\r
103 @@ -113,23 +137,20 @@\r
104                 oname = "<stdout>";\r
105                 output = stdout;\r
106         }\r
107 +#endif\r
108  \r
109         message(NOTE, "$!: Copy data to %s\n", oname);\r
110  \r
111 -       while ((c = getc(tmp)) != EOF)\r
112 -               putc(c, output);\r
113 -\r
114 +#ifndef _WIN32\r
115 +       while ((c = getc(tmp)) != EOF) putc(c, output);\r
116         fclose(tmp);\r
117 +#else\r
118 +       /* Copy file directly */\r
119 +       fclose(tmp);\r
120 +       CopyFile(tmpname, oname, FALSE);\r
121 +       DeleteFile(tmpname);\r
122 +#endif\r
123  \r
124 -       if      (ferror(output))\r
125 -       {\r
126 -               fprintf(stderr, "%s: ", pname);\r
127 -               perror(oname);\r
128 -               stat = EXIT_FAILURE;\r
129 -       }\r
130 -       else    stat = EXIT_SUCCESS;\r
131 -\r
132 -       fclose(output);\r
133         return stat;\r
134  }\r
135 diff -riwbBu -Xex dvipost-1.1/dvipost.h dvipost-1.1-modified/dvipost.h\r
136 --- dvipost-1.1/dvipost.h       Mon Nov  4 08:44:46 2002\r
137 +++ dvipost-1.1-modified/dvipost.h      Sun Sep 17 22:03:51 2006\r
138 @@ -1,6 +1,7 @@\r
139  /*     postfilter\r
140  \r
141  $Copyright (C) 2002 Erich Fruehstueck\r
142 +Modified version by LyX Team\r
143  \r
144  Dvipost is free software; you can redistribute it and/or\r
145  modify it under the terms of the GNU General Public\r
146 @@ -44,6 +45,7 @@\r
147  typedef struct {\r
148         int beg;\r
149         int end;\r
150 +       int type;\r
151  } POS;\r
152  \r
153  typedef struct {\r
154 @@ -53,7 +55,7 @@\r
155  } PosTab;\r
156  \r
157  void pos_init (PosTab *pos);\r
158 -void pos_add (PosTab *pos, int beg, int end);\r
159 +void pos_add (PosTab *pos, int beg, int end, int type);\r
160  \r
161  extern int process_dvi (const char *id, FILE *in, FILE *out);\r
162  extern int dvipost (const char *iname, const char *oname);\r
163 diff -riwbBu -Xex dvipost-1.1/main.c dvipost-1.1-modified/main.c\r
164 --- dvipost-1.1/main.c  Wed Nov 27 15:19:14 2002\r
165 +++ dvipost-1.1-modified/main.c Sun Sep 17 21:56:42 2006\r
166 @@ -24,15 +24,19 @@\r
167  #define        TEX_ACCEPT_OPTIONS      1\r
168  #endif\r
169  \r
170 -static char *version = "dvipost version 1.0\n\\r
171 +static char *version = "dvipost version 1.1 with modifications by LyX Team (sep 2006)\n\\r
172  Dvipost is copyright (C) 2002 Erich Fruehstueck.\n";\r
173  \r
174  #include "dvipost.h"\r
175  #include "dvi.h"\r
176 +#if !defined(_MSC_VER)\r
177  #include <unistd.h>\r
178 +#endif\r
179  #include <string.h>\r
180  #include <sys/types.h>\r
181 +#ifndef _WIN32\r
182  #include <sys/wait.h>\r
183 +#endif\r
184  \r
185  char **tex_argv = NULL;\r
186  int tex_argc = 0;\r
187 @@ -233,17 +237,26 @@\r
188         return stat;\r
189  }\r
190  \r
191 -static char *get_dvi_name (const char *arg)\r
192 +static char *get_dvi_name (char *arg)\r
193  {\r
194         char *p, *dvi;\r
195         \r
196 +#ifdef _WIN32  \r
197 +       int i;\r
198 +\r
199 +       for (i=0; i < strlen(arg); ++i) {\r
200 +               if (arg[i] == '\\')\r
201 +                       arg[i] = '/';\r
202 +       }\r
203 +#endif\r
204 +       \r
205         p = strrchr(arg, '/');\r
206  \r
207         if      (p && p[1])\r
208                 arg = p + 1;\r
209  \r
210 -       dvi = strcpy(xalloc(strlen(arg) + 4), arg);\r
211 -       p = strchr(dvi, '.');\r
212 +       dvi = strcpy(xalloc(strlen(arg) + 5), arg);\r
213 +       p = strrchr(dvi, '.');\r
214  \r
215         if      (p && strcmp(p, ".tex") == 0)\r
216                 *p = 0;\r
217 @@ -267,14 +280,32 @@\r
218         char *dviname;\r
219         int flag;\r
220         int i, n;\r
221 +#ifdef _WIN32\r
222 +       char *cmd;\r
223 +       char *qch;\r
224 +       char *p;\r
225 +#else\r
226         int status;\r
227         pid_t pid;\r
228 +#endif\r
229         time_t stamp;\r
230  \r
231         tex_argv = xalloc((1 + argc) * sizeof(char*));\r
232         tex_argv[0] = argv[0];\r
233         tex_argc = 1;\r
234  \r
235 +#ifdef _WIN32\r
236 +       for (i=0; i < strlen(argv[0]); ++i) {\r
237 +               if (argv[0][i] == '\\')\r
238 +                       argv[0][i] = '/';\r
239 +       }\r
240 +       \r
241 +       p = strrchr(argv[0], '.');\r
242 +\r
243 +       if      (p && strcmp(p, ".exe") == 0)\r
244 +               *p = 0;\r
245 +#endif\r
246 +\r
247         pname = strrchr(argv[0], '/');\r
248  \r
249         if      (pname == NULL) pname = argv[0];\r
250 @@ -356,6 +387,34 @@\r
251         fflush(stdout);\r
252  \r
253         time(&stamp);\r
254 +#ifdef _WIN32\r
255 +       for (i=0, n=0; i < tex_argc; ++i) {\r
256 +           n += strlen(tex_argv[i]);\r
257 +           qch = tex_argv[i];\r
258 +           while ((qch = strchr(qch, '"'))) {\r
259 +               ++qch;\r
260 +               ++n;\r
261 +           }\r
262 +       }\r
263 +\r
264 +       cmd = xalloc(1 + n + 3*(tex_argc-1));\r
265 +       strcpy(cmd, tex_argv[0]);\r
266 +\r
267 +       for (i=1, n=strlen(cmd); i < tex_argc; ++i)\r
268 +       {\r
269 +           cmd[n++] = ' ';\r
270 +           cmd[n++] = '"';\r
271 +           for (qch=tex_argv[i]; *qch; ++qch) {\r
272 +               if (*qch == '"')\r
273 +                   cmd[n++] = '\\';\r
274 +               cmd[n++] = *qch;\r
275 +           }\r
276 +           cmd[n++] = '"';\r
277 +       }\r
278 +       cmd[n] = '\0';\r
279 +       system(cmd);\r
280 +       xfree(cmd);\r
281 +#else\r
282         pid = fork();\r
283  \r
284         if      (pid == -1)\r
285 @@ -368,6 +427,7 @@\r
286                 execvp(tex_argv[0], tex_argv);\r
287  \r
288         waitpid(pid, &status, 0);\r
289 +#endif\r
290  \r
291         if      (dviname)\r
292                 return dvipost(dviname, dviname);\r
293 diff -riwbBu -Xex dvipost-1.1/pos.c dvipost-1.1-modified/pos.c\r
294 --- dvipost-1.1/pos.c   Tue Oct 29 12:54:02 2002\r
295 +++ dvipost-1.1-modified/pos.c  Sun Sep 17 22:03:41 2006\r
296 @@ -1,6 +1,7 @@\r
297  /*     position table\r
298  \r
299  $Copyright (C) 2002 Erich Fruehstueck\r
300 +Modified version by LyX Team\r
301  \r
302  Dvipost is free software; you can redistribute it and/or\r
303  modify it under the terms of the GNU General Public\r
304 @@ -39,7 +40,7 @@\r
305         pos->dim = 0;\r
306  }\r
307  \r
308 -void pos_add (PosTab *pos, int beg, int end)\r
309 +void pos_add (PosTab *pos, int beg, int end, int type)\r
310  {\r
311         if      (beg > end)\r
312         {\r
313 @@ -56,7 +57,7 @@\r
314                 {\r
315                         if      (last->end < end)       last->end = end;\r
316                         if      (last->beg > beg)       last->beg = beg;\r
317 -\r
318 +                       if      (last->type < type)     last->type = type;\r
319                         return;\r
320                 }\r
321         }\r
322 @@ -64,5 +65,6 @@\r
323         pos_expand(pos);\r
324         pos->tab[pos->dim].beg = beg;\r
325         pos->tab[pos->dim].end = end;\r
326 +       pos->tab[pos->dim].type = type;\r
327         pos->dim++;\r
328  }\r
329 diff -riwbBu -Xex dvipost-1.1/tfm.c dvipost-1.1-modified/tfm.c\r
330 --- dvipost-1.1/tfm.c   Sun Nov  3 09:52:04 2002\r
331 +++ dvipost-1.1-modified/tfm.c  Sun Sep 17 22:03:44 2006\r
332 @@ -1,6 +1,7 @@\r
333  /*     tfm data\r
334  \r
335  $Copyright (C) 2002 Erich Fruehstueck\r
336 +Modified version by LyX Team\r
337  \r
338  Dvipost is free software; you can redistribute it and/or\r
339  modify it under the terms of the GNU General Public\r
340 @@ -22,6 +23,11 @@\r
341  #include "dvi.h"\r
342  #include <ctype.h>\r
343  \r
344 +#if defined(_MSC_VER)\r
345 +#define popen _popen\r
346 +#define pclose _pclose\r
347 +#endif\r
348 +\r
349  static char tfm_buf[1024];\r
350  static int tfm_err = 0;\r
351  static int tfm_pos = 0;\r
352 @@ -112,6 +118,8 @@\r
353         {\r
354                 if      (tfm_buf[n] == '\n')\r
355                 {\r
356 +                       if (n && tfm_buf[n-1] == '\r')\r
357 +                           n--;\r
358                         tfm_buf[n] = 0;\r
359                         break;\r
360                 }\r