View Javadoc
1   package eu.simuline.m2latex.core;
2   
3   import java.util.HashMap;
4   import java.util.Map;
5   
6   enum Converter {
7   
8       PdfLatex {
9   	String getCommand() {
10  	    return "pdflatex";
11  	}
12  
13  	/**
14  	 * The version pattern at a first sight consists of three parts: 
15  	 * <ul>
16  	 * <li>the tex version which is an approximation of pi 
17  	 * and which will be frozen as Donald Knuth will die at $\pi$ 
18  	 * (meant maybe in double precision)</li>
19  	 * <li>the etex version which is a two integer version. 
20  	 * It has to be clarified, whether there is a new release to be expected. </li>
21  	 * <li>the pdftex version. </li>
22  	 * </ul>
23  	 * It is quite sure from the examples found, 
24  	 * that the latter does not start from the beginning 
25  	 * when the former is increased. 
26  	 * This means that the first of the two version numbers are informative only
27  	 * and must thus be included in the environment. 
28  	 * @see #getVersionEnvironment()
29  	 */
30  	String getVersionPattern() {
31  	    // 3.1415926-2.3-1.40.12
32  	    // 3.14159265-2.6-1.40.21
33  	   return X_X_X;
34  	}
35  	
36  	/**
37  	 * For an explanation why part of the version string is in the environment, 
38  	 * see {@link #getVersionPattern()}. 
39  	 */
40  	String getVersionEnvironment() {
41  	    return "^pdfTeX 3\\.[0-9]*-[0-9]+\\.[0-9]+-%s \\(TeX Live";
42  	}
43      },
44      LuaLatex {
45  	String getCommand() {
46  	    return "lualatex";
47  	}
48  	String getVersionPattern() {
49  	    return X_X_X;
50  	}
51  	String getVersionEnvironment() {
52  	    return "^This is LuaHBTeX, Version %s \\(TeX Live";
53  	}
54      },
55      XeLatex {
56  	String getCommand() {
57  	    return "xelatex";
58  	}
59  
60  	/**
61  	 * The version pattern at a first sight consists of three parts: 
62  	 * <ul>
63  	 * <li>the tex version which is an approximation of pi 
64  	 * and which will be frozen as Donald Knuth will die at $\pi$ 
65  	 * (meant maybe in double precision)</li>
66  	 * <li>the etex version which is a two integer version. 
67  	 * It has to be clarified, whether there is a new release to be expected. </li>
68  	 * <li>the xetex version. </li>
69  	 * </ul>
70  	 * It is quite sure from the examples found, 
71  	 * that the latter does not start from the beginning 
72  	 * when the former is increased. 
73  	 * This means that the first of the two version numbers are informative only
74  	 * and must thus be included in the environment. 
75  	 * @see #getVersionEnvironment()
76  	 */
77  	String getVersionPattern() {
78  	    return "((0\\.[0-9]*))";
79  	}
80  
81  	/**
82  	 * For an explanation why part of the version string is in the environment, 
83  	 * see {@link #getVersionPattern()}. 
84  	 */
85  	String getVersionEnvironment() {
86  	    return "^XeTeX 3\\.[0-9]*-[0-9]+\\.[0-9]+-%s \\(TeX Live";
87  	}
88      },
89      Latex2rtf {
90  	String getCommand() {
91  	    return "latex2rtf";
92  	}
93  	String getVersionPattern() {
94  	    return "(([0-9]+)\\.([0-9]+)\\.([0-9]+) r([0-9]+))";
95  	}
96  	String getVersionEnvironment() {
97  	    return "^latex2rtf %s \\(released";
98  	}
99      },
100     Odt2doc {
101 	String getCommand() {
102 	    return "odt2doc";
103 	}
104 	String getVersionOption() {
105 	    return "--version";
106 	}
107 	// TBC: not clear whether this is the significant version 
108 	String getVersionPattern() {
109 	    return X_X_X;
110 	}
111 	String getVersionEnvironment() {
112 	    return "^unoconv %s\n";
113 	}
114     },
115     Pdf2txt {
116 	String getCommand() {
117 	    return "pdftotext";
118 	}
119 	String getVersionPattern() {
120 	    return X_X_X;
121 	}
122 	String getVersionEnvironment() {
123 	    return "^pdftotext version %s\n";
124 	}
125     },
126     Dvips {
127 	String getCommand() {
128 	    return "dvips";
129 	}
130 	String getVersionPattern() {
131 	    return "(([0-9\\.]{4})\\.([0-9]))";
132 	}
133 	String getVersionEnvironment() {
134 	    return "^This is dvips\\(k\\) %s " + 
135 		    "Copyright [0-9]+ Radical Eye Software \\(www\\.radicaleye\\.com\\)\n";
136 	}
137     },
138     Dvipdfm {
139 	String getCommand() {
140 	    return "dvipdfm";
141 	}
142 	String getVersionOption() {
143 	    return "--version";
144 	}
145 	String getVersionPattern() {
146 	    return YYYYMMDD;
147 	}
148 	String getVersionEnvironment() {
149 	    return "^This is xdvipdfmx Version %s " + 
150 	"by the DVIPDFMx project team,\n";
151 	}
152    },
153     Dvipdfmx {
154 	String getCommand() {
155 	    return "dvipdfmx";
156 	}
157 	String getVersionOption() {
158 	    return "--version";
159 	}
160 	String getVersionPattern() {
161 	    return YYYYMMDD;
162 	}
163 	String getVersionEnvironment() {
164 	    return "^This is dvipdfmx Version %s " + 
165 	"by the DVIPDFMx project team,\n";
166 	}
167     },
168     XDvipdfmx {
169 	String getCommand() {
170 	    return "xdvipdfmx";
171 	}
172 	String getVersionOption() {
173 	    return "--version";
174 	}
175 	String getVersionPattern() {
176 	    return YYYYMMDD;
177 	}
178 	String getVersionEnvironment() {
179 	    return "^This is xdvipdfmx Version %s " + 
180 	"by the DVIPDFMx project team,\n";
181 	}
182     },
183     Dvipdft {
184 	String getCommand() {
185 	    return "dvipdft";
186 	}
187 	String getVersionOption() {
188 	    return "--version";
189 	}
190 	String getVersionPattern() {
191 	    return "(([0-9]{4})([0-9]{2})([0-9]{2})\\.([0-9]{4}))";
192 	}
193 	String getVersionEnvironment() {
194 	    return "^dvipdft version %s by Thomas Esser and others\n";
195 	}
196     },
197     GS {
198 	String getCommand() {
199 	    return "gs";
200 	}
201 	String getVersionPattern() {
202 	    return "(([0-9]+)\\.([0-9]+)(?:\\.([0-9]+))?)";
203 	}
204 	String getVersionEnvironment() {
205 	    return "^GPL Ghostscript %s \\([0-9]{4}-[0-9]{2}-[0-9]{2}\\)\n";
206 	}
207     },
208     Chktex {
209 	String getCommand() {
210 	    return "chktex";
211 	}
212 	String getVersionOption() {
213 	    return "-W";
214 	}
215 	String getVersionPattern() {
216 	    return X_X_X;
217 	}
218 	String getVersionEnvironment() {
219 	    return "^ChkTeX v%s - " + 
220 		    "Copyright [0-9]{4}-[0-9]{2} Jens T. Berger Thielemann.\n";
221 	}
222     },
223     Bibtex {
224 	String getCommand() {
225 	    return "bibtex";
226 	}
227 	String getVersionPattern() {
228 	    return "((0\\.[0-9]*)([a-z]))";
229 	}
230 	String getVersionEnvironment() {
231 	    return "^BibTeX %s \\(TeX Live ";
232 	}
233     },
234     Bibtexu {
235 	String getCommand() {
236 	    return "bibtexu";
237 	}
238 
239 	/**
240 	 * Returns the pattern for the version string. 
241 	 * Note that <code>bibtexu -v</code> yields three versions, 
242 	 * the version of bibtex (something like 0.99d) 
243 	 * which is something like the specification version, 
244 	 * the ICU version and the release version (and date). 
245 	 * What is returned is the latter version.  
246 	 * 
247 	 * @return
248 	 *    the pattern for the version string. 
249 	 */
250 	String getVersionPattern() {
251 	    return X_X;
252 	}
253 	String getVersionEnvironment() {
254 	    return "^[^\n]*\n[^\n]*\n" +
255 	"Release version: %s \\([0-9]{2} [a-z]{3} [0-9]{4}\\)\n";
256 	}
257     },
258     Bibtex8 {
259 	String getCommand() {
260 	    return "bibtex8";
261 	}
262 
263 	/**
264 	 * Returns the pattern for the version string. 
265 	 * Note that <code>bibtex8 -v</code> yields three versions, 
266 	 * the version of bibtex (something like 0.99d) 
267 	 * which is something like the specification version, 
268 	 * the ICU version and the release version (and date). 
269 	 * What is returned is the latter version.  
270 	 * 
271 	 * @return
272 	 *    the pattern for the version string. 
273 	 */
274 	String getVersionPattern() {
275 	    return X_X;
276 	}
277 	String getVersionEnvironment() {
278 	    return "^[^\n]*\n[^\n]*\n" +
279 			"Release version: %s \\([0-9]{2} [a-z]{3} [0-9]{4}\\)\n";
280 	}
281     },
282 //    Makeindex {
283 //	String getCommand() {
284 //	    return "makeindex";
285 //	}
286 //	String getVersionOption() {
287 //	    return "-q";
288 //	}
289 //	String getVersionPattern() {
290 //	    return "^(.*)\n";
291 //	}
292 //    },
293     // TBC: maybe this replaces makeindex 
294   Upmendex {
295 	String getCommand() {
296 	    return "upmendex";
297 	}
298 	String getVersionOption() {
299 	    return "-h";
300 	}
301 	String getVersionPattern() {
302 	    return X_X;
303 	}
304 	String getVersionEnvironment() {
305 	    return "^upmendex - index processor, version %s " + 
306 	"\\(TeX Live [0-9]{4}\\).\n";
307 	}
308   },
309     Splitindex {
310 	String getCommand() {
311 	    return "splitindex";
312 	}
313 	String getVersionOption() {
314 	    return "--version";
315 	}
316 	String getVersionPattern() {
317 	    return X_X;
318 	}
319 	String getVersionEnvironment() {
320 	    return "^splitindex.pl %s\n";
321 	}
322     },
323     // TBC: which of the versions is the relevant one? 
324     Xindy {
325 	String getCommand() {
326 	    return "xindy";
327 	}
328 	String getVersionOption() {
329 	    return "-V";
330 	}
331 	// TBC: not clear whether this is the significant version 
332 	String getVersionPattern() {
333 	    return X_X_X;
334 	}
335 	String getVersionEnvironment() {
336 	    return "^xindy release: %s\n";
337 	}
338     },
339     Makeglossaries {
340 	String getCommand() {
341 	    return "makeglossaries";
342 	}
343 	String getVersionOption() {
344 	    return "--help";
345 	}
346 	String getVersionPattern() {
347 	    return X_X;
348 	}
349 	String getVersionEnvironment() {
350 	    return "^Makeglossaries Version %s " +
351 	"\\([0-9]{4}-[0-9]{2}-[0-9]{2}\\)\n";
352 	}
353     },
354     Mpost {
355 	String getCommand() {
356 	    return "mpost";
357 	}
358 	String getVersionPattern() {
359 	    return X_X;
360 	}
361 	String getVersionEnvironment() {
362 	    return "^MetaPost %s \\(TeX Live ";
363 	}
364     },
365     Ebb {
366 	String getCommand() {
367 	    return "ebb";
368 	}
369 	String getVersionOption() {
370 	    return "--version";
371 	}
372 	// 2nd line 
373 	String getVersionPattern() {
374 	    return YYYYMMDD;
375 	}
376 	String getVersionEnvironment() {
377 	    return "^[^\n]*\nThis is ebb Version %s\n";
378 	}
379     },
380     Gnuplot {
381 	String getCommand() {
382 	    return "gnuplot";
383 	}
384 	String getVersionOption() {
385 	    return "-V";
386 	}
387 	// TBC: we allow here patchlevel 0 only. Is this appropriate? 
388 	String getVersionPattern() {
389 	    return X_X;
390 	}
391 	String getVersionEnvironment() {
392 	    return "^gnuplot %s patchlevel 0\n";
393 	}
394     },
395     Inkscape {
396 	String getCommand() {
397 	    return "inkscape";
398 	}
399 	String getVersionOption() {
400 	    return "-V";
401 	}
402 	String getVersionPattern() {
403 	    return X_X_X;
404 	}
405 	// TBD: sometimes the pango line '    Pango version: 1.46.2' comes first. 
406 	String getVersionEnvironment() {
407 	    return "^Inkscape %s \\([0-9a-f]+, [0-9]{4}-[0-9]{2}-[0-9]{2}\\)\n";
408 	}
409     },
410     Fig2Dev {
411 	String getCommand() {
412 	    return "fig2dev";
413 	}
414 	String getVersionOption() {
415 	    return "-V";
416 	}
417 	String getVersionPattern() {
418 	    return "(([0-9]+)\\.([0-9]+)\\.([0-9]+)([a-z]))";
419 	}
420 	String getVersionEnvironment() {
421 	    return "^fig2dev Version %s\n";
422 	}
423 
424     };
425     
426     private final static String X_X_X = "(([0-9]+)\\.([0-9]+)\\.([0-9]+))";
427     private final static String X_X   = "(([0-9]+)\\.([0-9]+))";
428     private final static String YYYYMMDD = "(([0-9]{4})([0-9]{2})([0-9]{2}))";
429     
430     // TBC: needed? 
431     final static Map<String, Converter> cmd2conv;
432     static {
433 	cmd2conv = new HashMap<String, Converter>();
434 	for (Converter conv : Converter.values()) {
435 	    cmd2conv.put(conv.getCommand(), conv);
436 	}
437     }
438 
439     /**
440      * Returns the command which which to invoke this converter. 
441      * 
442      * @return
443      *    the command of this converter. 
444      */
445     abstract String getCommand();
446 
447     /**
448      * Returns the option which just displays information 
449      * given by {@link #getVersionEnvironment()} and among that version information 
450      * as descried by {@link #getVersionPattern()}. 
451      * 
452      * @return
453      *    the option to display (a string containing) version information. 
454      *    As a default, this is <code>-v</code> which is the most common such option.
455      */
456     String getVersionOption() {
457 	return "-v";
458     }
459 
460     /**
461      * Returns the pattern of the version for this converter as a regular expression. 
462      * All is enclosed by brackets indicating a capturing group. 
463      * Non capturing groups may occur without restriction 
464      * but capturing groups except the outermost one must come sequential. 
465      * This patters is part of the converters output 
466      * as indicated by {@link #getVersionEnvironment()}. 
467      * 
468      * @return
469      *    the pattern of the version for this converter. 
470      */
471     abstract String getVersionPattern();
472 
473     /**
474      * Returns the pattern of the output of this converter 
475      * if invoked with command {@link #getCommand()} and option {@link #getVersionOption()}. 
476      * Here, the literal <code>%s</code> indicates the location 
477      * of the proper version pattern given by {@link #getVersionPattern()}.
478      * If this is included a regular expression emerges. 
479      * 
480      * @return
481      *    the pattern of the output of this converter containing its version. 
482      */
483     abstract String getVersionEnvironment();
484     
485 }