Added copyright lines for files I've edited this year.
[synfig.git] / synfig-core / trunk / src / tool / main.cpp
index 794e0d1..b4155f4 100644 (file)
@@ -1,20 +1,22 @@
-/* === S I N F G =========================================================== */
-/*!    \file main.cpp
-**     \brief SINFG Tool
+/* === S Y N F I G ========================================================= */
+/*!    \file tool/main.cpp
+**     \brief SYNFIG Tool
 **
-**     $Id: main.cpp,v 1.9 2005/01/23 04:41:10 darco Exp $
+**     $Id$
 **
 **     \legal
-**     Copyright (c) 2002 Robert B. Quattlebaum Jr.
+**     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
+**     Copyright (c) 2007, 2008 Chris Moore
 **
-**     This software and associated documentation
-**     are CONFIDENTIAL and PROPRIETARY property of
-**     the above-mentioned copyright holder.
+**     This package 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.
 **
-**     You may not copy, print, publish, or in any
-**     other way distribute this software without
-**     a prior written agreement with
-**     the copyright holder.
+**     This package 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.
 **     \endlegal
 */
 /* ========================================================================= */
 #include <list>
 #include <ETL/clock>
 #include <algorithm>
-
-#include <sinfg/loadcanvas.h>
-#include <sinfg/savecanvas.h>
-#include <sinfg/target_scanline.h>
-#include <sinfg/module.h>
-#include <sinfg/importer.h>
-#include <sinfg/layer.h>
-#include <sinfg/canvas.h>
-#include <sinfg/target.h>
-#include <sinfg/time.h>
-#include <sinfg/string.h>
-#include <sinfg/paramdesc.h>
-#include <sinfg/main.h>
-#include <sinfg/guid.h>
+#include <cstring>
+
+#include <synfig/loadcanvas.h>
+#include <synfig/savecanvas.h>
+#include <synfig/target_scanline.h>
+#include <synfig/module.h>
+#include <synfig/importer.h>
+#include <synfig/layer.h>
+#include <synfig/canvas.h>
+#include <synfig/target.h>
+#include <synfig/time.h>
+#include <synfig/string.h>
+#include <synfig/paramdesc.h>
+#include <synfig/main.h>
+#include <synfig/guid.h>
 #endif
 
 using namespace std;
 using namespace etl;
-using namespace sinfg;
+using namespace synfig;
 
 /* === M A C R O S ========================================================= */
 
+#ifdef ENABLE_NLS
+#undef _
+#define _(x) gettext(x)
+#else
+#undef _
+#define _(x) (x)
+#endif
+
 enum exit_code
 {
-       SINFGTOOL_OK                            =0,
-       SINFGTOOL_FILENOTFOUND          =1,
-       SINFGTOOL_BORRED                        =2,
-       SINFGTOOL_HELP                          =3,
-       SINFGTOOL_UNKNOWNARGUMENT       =4,     
-       SINFGTOOL_UNKNOWNERROR          =5,     
-       SINFGTOOL_INVALIDTARGET         =6,     
-       SINFGTOOL_RENDERFAILURE         =7,     
-       SINFGTOOL_BLANK                         =8,
-       SINFGTOOL_BADVERSION            =9
+       SYNFIGTOOL_OK                           = 0,
+       SYNFIGTOOL_FILENOTFOUND         = 1,
+       SYNFIGTOOL_BORED                        = 2,
+       SYNFIGTOOL_HELP                         = 3,
+       SYNFIGTOOL_UNKNOWNARGUMENT      = 4,
+       SYNFIGTOOL_UNKNOWNERROR         = 5,
+       SYNFIGTOOL_INVALIDTARGET        = 6,
+       SYNFIGTOOL_RENDERFAILURE        = 7,
+       SYNFIGTOOL_BLANK                        = 8,
+       SYNFIGTOOL_BADVERSION           = 9,
+       SYNFIGTOOL_MISSINGARGUMENT      =10
 };
 
 #ifndef VERSION
 #define VERSION "unknown"
-#define PACKAGE "sinfg-tool"
+#define PACKAGE "synfig-tool"
 #endif
 
 #ifdef DEFAULT_QUALITY
@@ -90,14 +102,14 @@ bool print_benchmarks=false;
 
 /* === M E T H O D S ======================================================= */
 
-class Progress : public sinfg::ProgressCallback
+class Progress : public synfig::ProgressCallback
 {
        const char *program;
-       
+
 public:
-       
+
        Progress(const char *name):program(name) { }
-       
+
        virtual bool
        task(const String &task)
        {
@@ -120,25 +132,25 @@ public:
        }
 
        virtual bool
-       amount_complete(int current, int total)
+       amount_complete(int /*current*/, int /*total*/)
        {
                return true;
        }
 };
 
-class RenderProgress : public sinfg::ProgressCallback
+class RenderProgress : public synfig::ProgressCallback
 {
        string taskname;
-       
+
        etl::clock clk;
        int clk_scanline; // The scanline at which the clock was reset
        etl::clock clk2;
 
-       float last_time;        
+       float last_time;
 public:
-       
-       RenderProgress():clk_scanline(0) { }
-       
+
+       RenderProgress():clk_scanline(0), last_time(0) { }
+
        virtual bool
        task(const String &thetask)
        {
@@ -176,7 +188,7 @@ public:
                        if(clk2()<0.2)
                                return true;
                        clk2.reset();
-                               
+
                        if(scanline)
                                seconds=(int)time+1;
                        else
@@ -185,7 +197,7 @@ public:
                                clk.reset();
                                clk_scanline=scanline;
                        }
-                       
+
                        if(seconds<0)
                        {
                                clk.reset();
@@ -200,7 +212,7 @@ public:
                                days++,hours-=24;
                        while(days>=7)
                                weeks++,days-=7;
-                       
+
                        cerr<<taskname<<": "<<_("Line")<<" "<<scanline<<_(" of ")<<h<<" -- ";
                        //cerr<<time/(h-clk_scanline)<<" ";
                        /*
@@ -211,9 +223,9 @@ public:
                        {
                                //cerr<<"reset"<<endl;
                                clk.reset();
-                               clk_scanline=scanline;                          
+                               clk_scanline=scanline;
                        }
-                       
+
                        if(weeks)
                                cerr<<weeks<<"w ";
                        if(days)
@@ -224,7 +236,7 @@ public:
                                cerr<<minutes<<"m ";
                        if(seconds)
                                cerr<<seconds<<"s ";
-                       
+
                        cerr<<"           \r";
                }
                else
@@ -237,13 +249,13 @@ struct Job
 {
        String filename;
        String outfilename;
-       
+
        RendDesc desc;
 
        Canvas::Handle root;
        Canvas::Handle canvas;
        Target::Handle target;
-       
+
        int quality;
        bool sifout;
 };
@@ -256,7 +268,7 @@ void guid_test()
        cout<<"GUID Test"<<endl;
        for(int i=20;i;i--)
        {
-               cout<<sinfg::GUID().get_string()<<' '<<sinfg::GUID().get_string()<<endl;
+               cout<<synfig::GUID().get_string()<<' '<<synfig::GUID().get_string()<<endl;
        }
 }
 
@@ -293,12 +305,14 @@ void display_help(int amount)
                                cerr<<strprintf(" %s %s %s",flag, arg, spaces+strlen(arg)+strlen(flag)+1)+description<<endl;
                        else
                                cerr<<strprintf(" %s %s",flag,spaces+strlen(flag))+description<<endl;
-               
                }
        };
-       cerr<<_("syntax: ")<<progname<<" [DEFAULT OPTIONS] ([SIF FILE] [SPECIFIC OPTIONS])..."<<endl;
-       cerr<<endl;
-       if(amount>=1)
+
+       cerr << endl << _("syntax: ") << progname << " [DEFAULT OPTIONS] ([SIF FILE] [SPECIFIC OPTIONS])..." << endl << endl;
+
+       if(amount == 0)
+               Argument("--help",NULL,_("Print out usage and syntax info"));
+       else
        {
                Argument("-t","<output type>",_("Specify output target (Default:unknown)"));
                Argument("-w","<pixel width>",_("Set the image width (Use zero for file default)"));
@@ -312,16 +326,13 @@ void display_help(int amount)
                Argument("-c","<canvas id>",_("Render the canvas with the given id instead of the root."));
                Argument("-o","<output file>",_("Specify output filename"));
                Argument("-T","<# of threads>",_("Enable multithreaded renderer using specified # of threads"));
-
                Argument("-b",NULL,_("Print Benchmarks"));
-
                Argument("--fps","<framerate>",_("Set the frame rate"));
                Argument("--time","<time>",_("Render a single frame at <seconds>"));
                Argument("--begin-time","<time>",_("Set the starting time"));
                Argument("--end-time","<time>",_("Set the ending time"));
                Argument("--dpi","<res>",_("Set the dots-per-inch"));
                Argument("--append","<filename>",_("Append layers in <filename> to composition"));
-
                Argument("--layer-info","<layer>",_("Print out layer's description, parameter info, etc."));
                Argument("--layers",NULL,_("Print out the list of available layers"));
                Argument("--targets",NULL,_("Print out the list of available targets"));
@@ -337,39 +348,35 @@ void display_help(int amount)
                Argument("--signal-test",NULL,_("Test signal implementation"));
 #endif
        }
-       else
 
-       Argument("--help",NULL,_("Print out usage and syntax info"));
        cerr<<endl;
 }
 
 int process_global_flags(arg_list_t &arg_list)
 {
        arg_list_t::iterator iter, next;
-       
+
        for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
        {
                if(*iter == "--")
-                       return SINFGTOOL_OK;
+                       return SYNFIGTOOL_OK;
 
                if(*iter == "--signal-test")
                {
                        signal_test();
-                       return SINFGTOOL_HELP;
+                       return SYNFIGTOOL_HELP;
                }
-               
+
                if(*iter == "--guid-test")
                {
                        guid_test();
-                       return SINFGTOOL_HELP;
+                       return SYNFIGTOOL_HELP;
                }
 
-               
                if(*iter == "--help")
                {
                        display_help(1);
-
-                       return SINFGTOOL_HELP;
+                       return SYNFIGTOOL_HELP;
                }
 
                if(*iter == "--info")
@@ -386,28 +393,28 @@ int process_global_flags(arg_list_t &arg_list)
                        cout<<" with Borland Turbo C++ "<<(__TCPLUSPLUS__>>8)<<'.'<<((__TCPLUSPLUS__&255)>>4)<<'.'<<(__TCPLUSPLUS__&15);
 #endif
 
-                       cout<<endl<<SINFG_COPYRIGHT<<endl;
+                       cout<<endl<<SYNFIG_COPYRIGHT<<endl;
                        cout<<endl;
-                       return SINFGTOOL_HELP;
+                       return SYNFIGTOOL_HELP;
                }
 
                if(*iter == "--layers")
                {
                        Progress p(PACKAGE);
-                       sinfg::Main sinfg_main(dirname(progname),&p);
-                       sinfg::Layer::Book::iterator iter=sinfg::Layer::book().begin();
-                       for(;iter!=sinfg::Layer::book().end();iter++)
+                       synfig::Main synfig_main(dirname(progname),&p);
+                       synfig::Layer::Book::iterator iter=synfig::Layer::book().begin();
+                       for(;iter!=synfig::Layer::book().end();iter++)
                                cout<<iter->first<<endl;
 
-                       return SINFGTOOL_HELP;
+                       return SYNFIGTOOL_HELP;
                }
 
                if(*iter == "--layer-info")
                {
                        Progress p(PACKAGE);
-                       sinfg::Main sinfg_main(dirname(progname),&p);
+                       synfig::Main synfig_main(dirname(progname),&p);
                        iter=next++;
-                       Layer::Handle layer=sinfg::Layer::create(*iter);
+                       Layer::Handle layer=synfig::Layer::create(*iter);
                        cout<<"Layer Name: "<<layer->get_name()<<endl;
                        cout<<"Localized Layer Name: "<<layer->get_local_name()<<endl;
                        cout<<"Version: "<<layer->get_version()<<endl;
@@ -424,155 +431,132 @@ int process_global_flags(arg_list_t &arg_list)
                                        cout<<"\tHint: "<<vocab.front().get_hint()<<endl;
                        }
 
-                       return SINFGTOOL_HELP;
+                       return SYNFIGTOOL_HELP;
                }
 
                if(*iter == "--modules")
                {
                        Progress p(PACKAGE);
-                       sinfg::Main sinfg_main(dirname(progname),&p);
-                       sinfg::Module::Book::iterator iter=sinfg::Module::book().begin();
-                       for(;iter!=sinfg::Module::book().end();iter++)
+                       synfig::Main synfig_main(dirname(progname),&p);
+                       synfig::Module::Book::iterator iter=synfig::Module::book().begin();
+                       for(;iter!=synfig::Module::book().end();iter++)
                                cout<<iter->first<<endl;
-                       return SINFGTOOL_HELP;
+                       return SYNFIGTOOL_HELP;
                }
 
                if(*iter == "--targets")
                {
                        Progress p(PACKAGE);
-                       sinfg::Main sinfg_main(dirname(progname),&p);
-                       sinfg::Target::Book::iterator iter=sinfg::Target::book().begin();
-                       for(;iter!=sinfg::Target::book().end();iter++)
+                       synfig::Main synfig_main(dirname(progname),&p);
+                       synfig::Target::Book::iterator iter=synfig::Target::book().begin();
+                       for(;iter!=synfig::Target::book().end();iter++)
                                cout<<iter->first<<endl;
-                               
-                       return SINFGTOOL_HELP;
+                       return SYNFIGTOOL_HELP;
                }
 
                if(*iter == "--valuenodes")
                {
                        Progress p(PACKAGE);
-                       sinfg::Main sinfg_main(dirname(progname),&p);
-                       sinfg::LinkableValueNode::Book::iterator iter=sinfg::LinkableValueNode::book().begin();
-                       for(;iter!=sinfg::LinkableValueNode::book().end();iter++)
+                       synfig::Main synfig_main(dirname(progname),&p);
+                       synfig::LinkableValueNode::Book::iterator iter=synfig::LinkableValueNode::book().begin();
+                       for(;iter!=synfig::LinkableValueNode::book().end();iter++)
                                cout<<iter->first<<endl;
-                               
-                       return SINFGTOOL_HELP;
+                       return SYNFIGTOOL_HELP;
                }
 
                if(*iter == "--importers")
                {
                        Progress p(PACKAGE);
-                       sinfg::Main sinfg_main(dirname(progname),&p);
-                       sinfg::Importer::Book::iterator iter=sinfg::Importer::book().begin();
-                       for(;iter!=sinfg::Importer::book().end();iter++)
+                       synfig::Main synfig_main(dirname(progname),&p);
+                       synfig::Importer::Book::iterator iter=synfig::Importer::book().begin();
+                       for(;iter!=synfig::Importer::book().end();iter++)
                                cout<<iter->first<<endl;
-                               
-                       return SINFGTOOL_HELP;
+                       return SYNFIGTOOL_HELP;
                }
 
                if(*iter == "--version")
                {
                        cerr<<PACKAGE<<" "<<VERSION<<endl;
-               
                        arg_list.erase(iter);
-                       
-                       return SINFGTOOL_HELP;
+                       return SYNFIGTOOL_HELP;
                }
 
                if(*iter == "--license")
                {
                        cerr<<PACKAGE<<" "<<VERSION<<endl;
-                       cout<<SINFG_COPYRIGHT<<endl<<endl;
+                       cout<<SYNFIG_COPYRIGHT<<endl<<endl;
                        cerr<<"\
-**     This software and associated documentation\n\
-**     are CONFIDENTIAL and PROPRIETARY property of\n\
-**     the above-mentioned copyright holder.\n\
+**     This package is free software; you can redistribute it and/or\n\
+**     modify it under the terms of the GNU General Public License as\n\
+**     published by the Free Software Foundation; either version 2 of\n\
+**     the License, or (at your option) any later version.\n\
 **\n\
-**     You may not use, copy, print, publish, or in\n\
-**     any other way distribute or exploit this software\n\
-**     without a prior written agreement with the\n\
-**     copyright holder. " << endl << endl;    
+**     " << endl << endl;
                        arg_list.erase(iter);
-                       
-                       return SINFGTOOL_HELP;
+                       return SYNFIGTOOL_HELP;
                }
 
                if(*iter == "-v")
                {
                        verbosity++;
-                       
                        arg_list.erase(iter);
-                       
                        continue;
                }
 
                if(*iter == "-q")
                {
                        be_quiet=true;
-
                        arg_list.erase(iter);
-
                        continue;
                }
                if(*iter == "-b")
                {
                        print_benchmarks=true;
-
                        arg_list.erase(iter);
-
                        continue;
                }
        }
-       
-       return SINFGTOOL_OK;
+
+       return SYNFIGTOOL_OK;
+}
+
+/* true if the given flag takes an extra parameter */
+bool flag_requires_value(String flag) {
+       return (flag=="-a"      || flag=="-c"   || flag=="-g"   || flag=="-h"   || flag=="-o" ||
+                       flag=="-Q"      || flag=="-s"   || flag=="-t"   || flag=="-T"   || flag=="-w" ||
+                       flag=="--append"        || flag=="--begin-time"         || flag=="--dpi"                || flag=="--dpi-x"      ||
+                       flag=="--dpi-y"         || flag=="--end-frame"          || flag=="--end-time"   || flag=="--fps"        ||
+                       flag=="--frame"         || flag=="--start-frame"        || flag=="--start-time" || flag=="--time"       );
 }
 
 int extract_arg_cluster(arg_list_t &arg_list,arg_list_t &cluster)
 {
        arg_list_t::iterator iter, next;
-       
+
        for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
        {
                if(*iter->begin() != '-')
                {
                        //cerr<<*iter->begin()<<"-----------"<<endl;
-                       return SINFGTOOL_OK;
+                       return SYNFIGTOOL_OK;
                }
 
-               if(
-                       *iter=="-t" ||
-                       *iter=="-w" ||
-                       *iter=="-h" ||
-                       *iter=="-a" ||
-                       *iter=="-g" ||
-                       *iter=="-o" ||
-                       *iter=="-s" ||
-                       *iter=="-Q" ||
-                       *iter=="-c" ||
-                       *iter=="--fps" ||
-                       *iter=="--start-time" ||
-                       *iter=="--begin-time" ||
-                       *iter=="--end-time" ||
-                       *iter=="--start-frame" ||
-                       *iter=="--end-frame" ||
-                       *iter=="--time" ||
-                       *iter=="--frame" ||
-                       *iter=="--dpi" ||
-                       *iter=="--dpi-x" ||
-                       *iter=="--dpi-y" ||
-                       *iter=="--append" ||
-                       *iter=="-T" )
+               if (flag_requires_value(*iter))
                {
                        cluster.push_back(*iter);
                        arg_list.erase(iter);
                        iter=next++;
+                       if (iter==arg_list.end()) {
+                               error("The `%s' flag requires a value.  Use --help for a list of options.", cluster.back().c_str());
+                               return SYNFIGTOOL_MISSINGARGUMENT;
+                       }
                }
-                       
+
                cluster.push_back(*iter);
                arg_list.erase(iter);
        }
-       
-       return SINFGTOOL_OK;
+
+       return SYNFIGTOOL_OK;
 }
 
 int extract_RendDesc(arg_list_t &arg_list,RendDesc &desc)
@@ -589,14 +573,14 @@ int extract_RendDesc(arg_list_t &arg_list,RendDesc &desc)
                        w=atoi(iter->c_str());
                        arg_list.erase(iter);
                }
-               if(*iter=="-h")
+               else if(*iter=="-h")
                {
                        arg_list.erase(iter);
                        iter=next++;
                        h=atoi(iter->c_str());
                        arg_list.erase(iter);
                }
-               if(*iter=="-a")
+               else if(*iter=="-a")
                {
             int a;
                        arg_list.erase(iter);
@@ -606,7 +590,7 @@ int extract_RendDesc(arg_list_t &arg_list,RendDesc &desc)
                        VERBOSE_OUT(1)<<strprintf(_("Antialiasing set to %d, (%d samples per pixel)"),a,a*a)<<endl;
                        arg_list.erase(iter);
                }
-               if(*iter=="-s")
+               else if(*iter=="-s")
                {
                        arg_list.erase(iter);
                        iter=next++;
@@ -614,7 +598,7 @@ int extract_RendDesc(arg_list_t &arg_list,RendDesc &desc)
                        VERBOSE_OUT(1)<<strprintf(_("Span set to %d units"),span)<<endl;
                        arg_list.erase(iter);
                }
-               if(*iter=="--fps")
+               else if(*iter=="--fps")
                {
                        arg_list.erase(iter);
                        iter=next++;
@@ -623,7 +607,7 @@ int extract_RendDesc(arg_list_t &arg_list,RendDesc &desc)
                        arg_list.erase(iter);
                        VERBOSE_OUT(1)<<strprintf(_("Frame rate set to %d frames per second"),fps)<<endl;
                }
-               if(*iter=="--dpi")
+               else if(*iter=="--dpi")
                {
                        arg_list.erase(iter);
                        iter=next++;
@@ -633,7 +617,7 @@ int extract_RendDesc(arg_list_t &arg_list,RendDesc &desc)
                        arg_list.erase(iter);
                        VERBOSE_OUT(1)<<strprintf(_("Physical resolution set to %f dpi"),dpi)<<endl;
                }
-               if(*iter=="--dpi-x")
+               else if(*iter=="--dpi-x")
                {
                        arg_list.erase(iter);
                        iter=next++;
@@ -643,7 +627,7 @@ int extract_RendDesc(arg_list_t &arg_list,RendDesc &desc)
                        arg_list.erase(iter);
                        VERBOSE_OUT(1)<<strprintf(_("Physical X resolution set to %f dpi"),dpi)<<endl;
                }
-               if(*iter=="--dpi-y")
+               else if(*iter=="--dpi-y")
                {
                        arg_list.erase(iter);
                        iter=next++;
@@ -653,21 +637,21 @@ int extract_RendDesc(arg_list_t &arg_list,RendDesc &desc)
                        arg_list.erase(iter);
                        VERBOSE_OUT(1)<<strprintf(_("Physical Y resolution set to %f dpi"),dpi)<<endl;
                }
-               if(*iter=="--start-time" || *iter=="--begin-time")
+               else if(*iter=="--start-time" || *iter=="--begin-time")
                {
                        arg_list.erase(iter);
                        iter=next++;
                        desc.set_time_start(Time(*iter,desc.get_frame_rate()));
                        arg_list.erase(iter);
                }
-               if(*iter=="--end-time")
+               else if(*iter=="--end-time")
                {
                        arg_list.erase(iter);
                        iter=next++;
                        desc.set_time_end(Time(*iter,desc.get_frame_rate()));
                        arg_list.erase(iter);
                }
-               if(*iter=="--time")
+               else if(*iter=="--time")
                {
                        arg_list.erase(iter);
                        iter=next++;
@@ -675,14 +659,16 @@ int extract_RendDesc(arg_list_t &arg_list,RendDesc &desc)
                        VERBOSE_OUT(1)<<_("Rendering frame at ")<<desc.get_time_start().get_string(desc.get_frame_rate())<<endl;
                        arg_list.erase(iter);
                }
-               if(*iter=="-g")
+               else if(*iter=="-g")
                {
-                       sinfg::warning("Gamma argument is currently ignored");
-                       //arg_list.erase(iter);
-                       //iter=next++;
+                       synfig::warning("Gamma argument is currently ignored");
+                       arg_list.erase(iter);
+                       iter=next++;
                        //desc.set_gamma(Gamma(atof(iter->c_str())));
-                       //arg_list.erase(iter);
+                       arg_list.erase(iter);
                }
+               else if (flag_requires_value(*iter))
+                       iter=next++;
        }
        if(w&&h)
        {
@@ -704,7 +690,7 @@ int extract_RendDesc(arg_list_t &arg_list,RendDesc &desc)
        }
        if(span)
                desc.set_span(span);
-       return SINFGTOOL_OK;
+       return SYNFIGTOOL_OK;
 }
 
 int extract_quality(arg_list_t &arg_list,int &quality)
@@ -720,9 +706,11 @@ int extract_quality(arg_list_t &arg_list,int &quality)
                        VERBOSE_OUT(1)<<strprintf(_("Quality set to %d"),quality)<<endl;
                        arg_list.erase(iter);
                }
+               else if (flag_requires_value(*iter))
+                       iter=next++;
        }
-       
-       return SINFGTOOL_OK;
+
+       return SYNFIGTOOL_OK;
 }
 
 int extract_threads(arg_list_t &arg_list,int &threads)
@@ -738,16 +726,18 @@ int extract_threads(arg_list_t &arg_list,int &threads)
                        VERBOSE_OUT(1)<<strprintf(_("Threads set to %d"),threads)<<endl;
                        arg_list.erase(iter);
                }
+               else if (flag_requires_value(*iter))
+                       iter=next++;
        }
-       
-       return SINFGTOOL_OK;
+
+       return SYNFIGTOOL_OK;
 }
 
 int extract_target(arg_list_t &arg_list,string &type)
 {
        arg_list_t::iterator iter, next;
        type.clear();
-       
+
        for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
        {
                if(*iter=="-t")
@@ -757,16 +747,18 @@ int extract_target(arg_list_t &arg_list,string &type)
                        type=*iter;
                        arg_list.erase(iter);
                }
+               else if (flag_requires_value(*iter))
+                       iter=next++;
        }
 
-       return SINFGTOOL_OK;
+       return SYNFIGTOOL_OK;
 }
 
 int extract_append(arg_list_t &arg_list,string &filename)
 {
        arg_list_t::iterator iter, next;
        filename.clear();
-       
+
        for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
        {
                if(*iter=="--append")
@@ -776,17 +768,19 @@ int extract_append(arg_list_t &arg_list,string &filename)
                        filename=*iter;
                        arg_list.erase(iter);
                }
+               else if (flag_requires_value(*iter))
+                       iter=next++;
        }
 
-       return SINFGTOOL_OK;
+       return SYNFIGTOOL_OK;
 }
 
 int extract_outfile(arg_list_t &arg_list,string &outfile)
 {
        arg_list_t::iterator iter, next;
-       int ret=SINFGTOOL_FILENOTFOUND;
+       int ret=SYNFIGTOOL_FILENOTFOUND;
        outfile.clear();
-       
+
        for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
        {
                if(*iter=="-o")
@@ -795,8 +789,10 @@ int extract_outfile(arg_list_t &arg_list,string &outfile)
                        iter=next++;
                        outfile=*iter;
                        arg_list.erase(iter);
-                       ret=SINFGTOOL_OK;
+                       ret=SYNFIGTOOL_OK;
                }
+               else if (flag_requires_value(*iter))
+                       iter=next++;
        }
 
        return ret;
@@ -806,7 +802,7 @@ int extract_canvasid(arg_list_t &arg_list,string &canvasid)
 {
        arg_list_t::iterator iter, next;
        //canvasid.clear();
-       
+
        for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
        {
                if(*iter=="-c")
@@ -816,9 +812,11 @@ int extract_canvasid(arg_list_t &arg_list,string &canvasid)
                        canvasid=*iter;
                        arg_list.erase(iter);
                }
+               else if (flag_requires_value(*iter))
+                       iter=next++;
        }
 
-       return SINFGTOOL_OK;
+       return SYNFIGTOOL_OK;
 }
 
 /* === M E T H O D S ======================================================= */
@@ -830,52 +828,61 @@ int main(int argc, char *argv[])
        int i;
        arg_list_t arg_list;
        job_list_t job_list;
-       
+
+       setlocale(LC_ALL, "");
+
+#ifdef ENABLE_NLS
+       bindtextdomain("synfig", LOCALEDIR);
+       textdomain("synfig");
+#endif
+
        progname=argv[0];
        Progress p(argv[0]);
-       
-       if(!SINFG_CHECK_VERSION())
+
+       if(!SYNFIG_CHECK_VERSION())
        {
-               cerr<<_("FATAL: Sinfg Version Mismatch")<<endl;
-               return SINFGTOOL_BADVERSION;
+               cerr<<_("FATAL: Synfig Version Mismatch")<<endl;
+               return SYNFIGTOOL_BADVERSION;
        }
        if(argc==1)
        {
                display_help(0);
-               return SINFGTOOL_BLANK;
+               return SYNFIGTOOL_BLANK;
        }
 
        for(i=1;i<argc;i++)
                arg_list.push_back(argv[i]);
-       
+
        if((i=process_global_flags(arg_list)))
                return i;
 
        VERBOSE_OUT(1)<<_("verbosity set to ")<<verbosity<<endl;
-       sinfg::Main sinfg_main(dirname(progname),&p);
-       
+       synfig::Main synfig_main(dirname(progname),&p);
+
        {
                arg_list_t defaults, imageargs;
-               
+               int ret;
+
                // Grab the defaults before the first file
-               extract_arg_cluster(arg_list,defaults);
-               
+               if ((ret = extract_arg_cluster(arg_list,defaults)) != SYNFIGTOOL_OK)
+                 return ret;
+
                while(arg_list.size())
                {
                        string target_name;
                        job_list.push_front(Job());
                        int threads=0;
-                       
+
                        imageargs=defaults;
                        job_list.front().filename=arg_list.front();
                        arg_list.pop_front();
 
-                       extract_arg_cluster(arg_list,imageargs);                        
-                       
+                       if ((ret = extract_arg_cluster(arg_list,imageargs)) != SYNFIGTOOL_OK)
+                         return ret;
+
                        // Open the composition
-                       {
-                               job_list.front().root=open_canvas(job_list.front().filename);
-                       }
+                       job_list.front().root=open_canvas(job_list.front().filename);
+
                        if(!job_list.front().root)
                        {
                                cerr<<_("Unable to open ")<<job_list.front().filename<<"."<<endl;
@@ -885,7 +892,7 @@ int main(int argc, char *argv[])
                        }
 
                        job_list.front().root->set_time(0);
-                       
+
                        string canvasid;
                        extract_canvasid(imageargs,canvasid);
                        if(!canvasid.empty())
@@ -900,7 +907,7 @@ int main(int argc, char *argv[])
                                        cerr<<_("Throwing out job...")<<endl;
                                        job_list.pop_front();
                                        continue;
-                                       
+
                                }
                                catch(Exception::BadLinkName)
                                {
@@ -908,12 +915,12 @@ int main(int argc, char *argv[])
                                        cerr<<_("Throwing out job...")<<endl;
                                        job_list.pop_front();
                                        continue;
-                                       
+
                                }
                        }
                        else
                                job_list.front().canvas=job_list.front().root;
-                       
+
                        extract_RendDesc(imageargs,job_list.front().canvas->rend_desc());
                        extract_target(imageargs,target_name);
                        extract_threads(imageargs,threads);
@@ -941,25 +948,37 @@ int main(int argc, char *argv[])
                                        }
                                        VERBOSE_OUT(2)<<_("Appended contents of ")<<composite_file<<endl;
                                }
-                       }while(false);
-                       
+                       } while(false);
+
                        VERBOSE_OUT(4)<<_("Attempting to determine target/outfile...")<<endl;
-                       
+
                        // If the target type is not yet defined,
                        // try to figure it out from the outfile.
                        if(target_name.empty() && !job_list.front().outfilename.empty())
-                       try
                        {
                                VERBOSE_OUT(3)<<_("Target name undefined, attempting to figure it out")<<endl;
-                               string ext=string(find(job_list.front().outfilename.begin(),job_list.front().outfilename.end(),'.')+1,job_list.front().outfilename.end());
+                               string ext = filename_extension(job_list.front().outfilename);
+                               if (ext.length()) ext = ext.substr(1);
                                if(Target::ext_book().count(ext))
+                               {
                                        target_name=Target::ext_book()[ext];
+                                       info("target name not specified - using %s", target_name.c_str());
+                               }
                                else
-                                       target_name=ext;
-                       }
-                       catch(std::length_error)
-                       {
-                               sinfg::warning("Length error caught when attempting to figure out target name");
+                               {
+                                       string lower_ext(ext);
+
+                                       for(unsigned int i=0;i<ext.length();i++)
+                                               lower_ext[i] = tolower(ext[i]);
+
+                                       if(Target::ext_book().count(lower_ext))
+                                       {
+                                               target_name=Target::ext_book()[lower_ext];
+                                               info("target name not specified - using %s", target_name.c_str());
+                                       }
+                                       else
+                                               target_name=ext;
+                               }
                        }
 
                        // If the target type is STILL not yet defined, then
@@ -975,9 +994,7 @@ int main(int argc, char *argv[])
                        // given input filename. (ie: change the extension)
                        if(job_list.front().outfilename.empty())
                        {
-                               job_list.front().outfilename=job_list.front().filename;
-                               job_list.front().outfilename.erase(find(job_list.front().outfilename.begin(),job_list.front().outfilename.end(),'.'),job_list.front().outfilename.end());
-                               job_list.front().outfilename+='.';
+                               job_list.front().outfilename = filename_sans_extension(job_list.front().filename) + '.';
                                if(Target::book().count(target_name))
                                        job_list.front().outfilename+=Target::book()[target_name].second;
                                else
@@ -986,10 +1003,10 @@ int main(int argc, char *argv[])
 
                        VERBOSE_OUT(4)<<"target_name="<<target_name<<endl;
                        VERBOSE_OUT(4)<<"outfile_name="<<job_list.front().outfilename<<endl;
-                       
+
                        VERBOSE_OUT(4)<<_("Creating the target...")<<endl;
-                       job_list.front().target=sinfg::Target::create(target_name,job_list.front().outfilename);
-                       
+                       job_list.front().target=synfig::Target::create(target_name,job_list.front().outfilename);
+
                        if(target_name=="sif")
                        {
                                job_list.front().sifout=true;
@@ -1011,16 +1028,16 @@ int main(int argc, char *argv[])
                        {
                                VERBOSE_OUT(4)<<_("Setting the canvas on the target...")<<endl;
                                job_list.front().target->set_canvas(job_list.front().canvas);
-                               VERBOSE_OUT(4)<<_("Setting the quality of the target...")<<endl;                                
+                               VERBOSE_OUT(4)<<_("Setting the quality of the target...")<<endl;
                                job_list.front().target->set_quality(job_list.front().quality);
                        }
-                       
+
                        // Set the threads for the target
                        if(job_list.front().target && Target_Scanline::Handle::cast_dynamic(job_list.front().target))
                        {
                                Target_Scanline::Handle::cast_dynamic(job_list.front().target)->set_threads(threads);
                        }
-                       
+
                        if(imageargs.size())
                        {
                                cerr<<_("Unidentified arguments for ")<<job_list.front().filename<<": ";
@@ -1031,26 +1048,24 @@ int main(int argc, char *argv[])
                                job_list.pop_front();
                                continue;
                        }
-                       //string bleh;
-                       //getline(cin,bleh);
                }
        }
-       
+
        if(arg_list.size())
        {
                cerr<<_("Unidentified arguments:");
                for(;arg_list.size();arg_list.pop_front())
                        cerr<<' '<<arg_list.front();
                cerr<<endl;
-               return SINFGTOOL_UNKNOWNARGUMENT;
+               return SYNFIGTOOL_UNKNOWNARGUMENT;
        }
-       
+
        if(!job_list.size())
        {
                cerr<<_("Nothing to do!")<<endl;
-               return SINFGTOOL_BORRED;
+               return SYNFIGTOOL_BORED;
        }
-       
+
        for(;job_list.size();job_list.pop_front())
        {
                VERBOSE_OUT(3)<<job_list.front().filename<<" -- "<<endl<<'\t'<<
@@ -1067,7 +1082,7 @@ int main(int argc, char *argv[])
                        job_list.front().desc.get_br()[0],job_list.front().desc.get_br()[1],
                        job_list.front().desc.get_focus()[0],job_list.front().desc.get_focus()[1]
                        )<<endl;
-               
+
                RenderProgress p;
                p.task(job_list.front().filename+" ==> "+job_list.front().outfilename);
                if(!job_list.front().sifout)
@@ -1079,7 +1094,7 @@ int main(int argc, char *argv[])
                        if(!job_list.front().target->render(&p))
                        {
                                cerr<<"Render Failure."<<endl;
-                               return SINFGTOOL_RENDERFAILURE;
+                               return SYNFIGTOOL_RENDERFAILURE;
                        }
                        if(print_benchmarks)
                        {
@@ -1091,14 +1106,14 @@ int main(int argc, char *argv[])
                        if(!save_canvas(job_list.front().outfilename,job_list.front().canvas))
                        {
                                cerr<<"Render Failure."<<endl;
-                               return SINFGTOOL_RENDERFAILURE;
+                               return SYNFIGTOOL_RENDERFAILURE;
                        }
                }
        }
-       
+
        job_list.clear();
-       
+
        VERBOSE_OUT(1)<<_("Done.")<<endl;
-       
-       return SINFGTOOL_OK;
+
+       return SYNFIGTOOL_OK;
 }