root/util/mtcp.d

Revision 67:108d123238c0, 3.2 kB (checked in by Diggory Hardy <diggory.hardy@gmail.com>, 6 months ago)

Changes to work with tango r3700 (post 0.99.6).

Changes to logging.
Replaced many uses of PathView? with FilePath?.

Line 
1 /* LICENSE BLOCK
2 Part of mde: a Modular D game-oriented Engine
3 Copyright © 2007-2008 Diggory Hardy
4
5 This program is free software: you can redistribute it and/or modify it under the terms
6 of the GNU General Public License as published by the Free Software Foundation, either
7 version 2 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 See the GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
15
16 /**************************************************************************************************
17  * A small program for reading and writing mergetag files.
18  *
19  * Note that it's limited to copying data types which DefaultData can handle due to the nature of
20  * mergetag's extendability.
21  *************************************************************************************************/
22 module ut.mtcp;
23
24 import mde.mergetag.Reader;
25 import mde.mergetag.Writer;
26 import mde.mergetag.exception;
27
28 import tango.io.Stdout;
29 import tango.io.FilePath;
30
31 // Logger, used by mergetag:
32 import tango.util.log.Config;
33
34 int main (char[][] args)
35 {
36     char[] inFile, outFile;
37     bool badOpts = false;
38     bool helpOnly = false;
39    
40     foreach (arg; args[1..$]) {
41         if (arg == "-h" || arg == "--help")
42             helpOnly = true;
43         else {
44             if (inFile is null)
45                 inFile = arg;
46             else if (outFile is null)
47                 outFile = arg;
48             else {
49                 badOpts = true;
50                 helpOnly = true;
51             }
52         }
53     }
54     if (outFile is null)
55         helpOnly = badOpts = true;
56     if (helpOnly) {
57         if (badOpts)
58             Stdout ("Error: bad options!").newline;
59         Stdout ("Usage:").newline.opCall(args[0])(" [options] input_file output_file").newline;
60         Stdout ("Options:").newline.opCall("-h\t--help\tPrint help message").newline;
61         if (badOpts)
62             return 1;
63         else return 0;
64     }
65    
66     IReader reader;
67     try {
68         reader = makeReader (FilePath(inFile), null, true);
69         reader.read;
70     } catch (MTException mte) {
71         Stdout ("While reading "~inFile~":").newline;
72         Stdout ("Mergetag exception:").newline.opCall(mte.msg).newline;
73         return 2;
74     } catch (Exception e) {
75         Stdout ("While reading "~inFile~":").newline;
76         Stdout ("Unhandled exception:").newline.opCall(e.msg).newline;
77         return 2;
78     }
79    
80     try {
81         IWriter writer = makeWriter (outFile, reader.dataset, WriterMethod.FromExtension);
82         writer.write;
83     } catch (MTException mte) {
84         Stdout ("While writing "~outFile~":").newline;
85         Stdout ("Mergetag exception:").newline.opCall(mte.msg).newline;
86         return 3;
87     } catch (Exception e) {
88         Stdout ("While writing "~outFile~":").newline;
89         Stdout ("Unhandled exception:").newline.opCall(e.msg).newline;
90         return 3;
91     }
92    
93     Stdout ("Copy successful: "~inFile~" -> "~outFile).newline;
94     return 0;
95 }
Note: See TracBrowser for help on using the browser.