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