tools/exploder.cpp

Go to the documentation of this file.
00001 /* $Id: exploder.cpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2004 - 2012 by Philippe Plantier <ayin@anathas.org>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 #include "../game_config.hpp"
00017 #include "exploder_composer.hpp"
00018 
00019 #include <iostream>
00020 
00021 namespace {
00022 
00023     void print_usage(std::string name)
00024     {
00025         std::cerr << "usage: " << name << " [source] [destination]\n";
00026     }
00027 }
00028 
00029 int main(int argc, char* argv[])
00030 {
00031     std::string src;
00032     std::string dest;
00033     composer comp;
00034 
00035     //parse arguments that shouldn't require a display device
00036     int arg;
00037     for(arg = 1; arg != argc; ++arg) {
00038         const std::string val(argv[arg]);
00039         if(val.empty()) {
00040             continue;
00041         }
00042 
00043         if(val == "--help" || val == "-h") {
00044             print_usage(argv[0]);
00045             return 0;
00046         } else if(val == "--interactive" || val == "-i") {
00047             comp.set_interactive(true);
00048         } else if(val == "--verbose" || val == "-v") {
00049             comp.set_verbose(true);
00050         } else if(val == "--directory" || val == "-d" ) {
00051             game_config::path = argv[++arg];
00052         } else {
00053             if(src.empty()) {
00054                 src = val;
00055             } else if(dest.empty()) {
00056                 dest = val;
00057             } else {
00058                 print_usage(argv[0]);
00059                 return 1;
00060             }
00061         }
00062     }
00063 
00064     if(src.empty() || dest.empty()) {
00065         print_usage(argv[0]);
00066         return 1;
00067     }
00068 
00069     try {
00070         surface image = comp.compose(src, dest);
00071         save_image(image, dest);
00072     } catch(exploder_failure& err) {
00073         std::cerr << "Failed: " << err.message << "\n";
00074         return 1;
00075     }
00076 
00077     return 0;
00078 }
00079 
00080 
00081 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Thu May 24 2012 01:02:54 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs