view util/mtcp.d @ 88:01f4f5f1acc9

Changes to init and to allow compiling with gdc. Tweaked init code to allow using circular iterators (disabled until my patch makes it into tango). Changes to allow compiling with gdc. Building is successful and unittests complete, but in my experience a SIGSEGV occurs within SDL.
author Diggory Hardy <diggory.hardy@gmail.com>
date Mon, 29 Sep 2008 12:09:44 +0100
parents 108d123238c0
children
line wrap: on
line source

/* LICENSE BLOCK
Part of mde: a Modular D game-oriented Engine
Copyright © 2007-2008 Diggory Hardy

This program is free software: you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation, either
version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>. */

/**************************************************************************************************
 * A small program for reading and writing mergetag files.
 *
 * Note that it's limited to copying data types which DefaultData can handle due to the nature of
 * mergetag's extendability.
 *************************************************************************************************/
module ut.mtcp;

import mde.mergetag.Reader;
import mde.mergetag.Writer;
import mde.mergetag.exception;

import tango.io.Stdout;
import tango.io.FilePath;

// Logger, used by mergetag:
import tango.util.log.Config;

int main (char[][] args)
{
    char[] inFile, outFile;
    bool badOpts = false;
    bool helpOnly = false;
    
    foreach (arg; args[1..$]) {
        if (arg == "-h" || arg == "--help")
            helpOnly = true;
        else {
            if (inFile is null)
                inFile = arg;
            else if (outFile is null)
                outFile = arg;
            else {
                badOpts = true;
                helpOnly = true;
            }
        }
    }
    if (outFile is null)
        helpOnly = badOpts = true;
    if (helpOnly) {
        if (badOpts)
            Stdout ("Error: bad options!").newline;
        Stdout ("Usage:").newline.opCall(args[0])(" [options] input_file output_file").newline;
        Stdout ("Options:").newline.opCall("-h\t--help\tPrint help message").newline;
        if (badOpts)
            return 1;
        else return 0;
    }
    
    IReader reader;
    try {
        reader = makeReader (FilePath(inFile), null, true);
        reader.read;
    } catch (MTException mte) {
        Stdout ("While reading "~inFile~":").newline;
        Stdout ("Mergetag exception:").newline.opCall(mte.msg).newline;
        return 2;
    } catch (Exception e) {
        Stdout ("While reading "~inFile~":").newline;
        Stdout ("Unhandled exception:").newline.opCall(e.msg).newline;
        return 2;
    }
    
    try {
        IWriter writer = makeWriter (outFile, reader.dataset, WriterMethod.FromExtension);
        writer.write;
    } catch (MTException mte) {
        Stdout ("While writing "~outFile~":").newline;
        Stdout ("Mergetag exception:").newline.opCall(mte.msg).newline;
        return 3;
    } catch (Exception e) {
        Stdout ("While writing "~outFile~":").newline;
        Stdout ("Unhandled exception:").newline.opCall(e.msg).newline;
        return 3;
    }
    
    Stdout ("Copy successful: "~inFile~" -> "~outFile).newline;
    return 0;
}