Index: tools/dim_to_lgf.cc
===================================================================
--- tools/dim_to_lgf.cc	(revision 2404)
+++ tools/dim_to_lgf.cc	(revision 2410)
@@ -19,5 +19,5 @@
 ///\ingroup demos
 ///\file
-///\brief DIMACS to LGF converter (demo).
+///\brief DIMACS to LGF converter.
 ///
 /// This program converts various DIMACS formats to the LEMON Graph Format
@@ -34,29 +34,8 @@
 #include <lemon/graph_writer.h>
 
+#include <lemon/arg_parser.h>
+
 using namespace std;
 using namespace lemon;
-
-const char* versionString =
-"dim_to_lgf - part of lemon library\n";
-
-const char* helpString =
-"DIMACS to LGF converter\n"
-"Usage: dim_to_lgf [OPTIONS]\n"
-"\n"
-"Examples:\n"
-"  dim_to_lgf --type shortestpath --input graph.dim --output graph.lgf\n"
-"\n"
-"Options:\n"
-"  -i FILE, --input FILE    use FILE as input instead of standard input\n"
-"  -o FILE, --output FILE   use FILE as output instead of standard output\n"
-"  -t TYPE, --type TYPE     set up the type of the graph\n"
-"                             Possible types:\n"
-"                               mincostflow\n"
-"                               maxflow (default)\n"
-"                               shortestpath\n"
-"                               capacitated\n"
-"                               plain\n"
-"  -v, --version            shows the version of the converter\n"
-"  -h, --help               shows the help of the converter\n";
 
 
@@ -74,64 +53,44 @@
   std::string typeName;
 
-  bool help = false;
-  bool version = false;
+  bool mincostflow;
+  bool maxflow;
+  bool shortestpath;
+  bool capacitated;
+  bool plain;
 
-  for (int arg = 1; arg < argc; ++arg) {
-    if (strcmp(argv[arg], "--type") == 0 || 
-	strcmp(argv[arg], "-t") == 0) {
-      if (!typeName.empty()) {
-	cerr << "Multiple type description" << endl;
-	return -1;
-      }
-      if (arg + 1 == argc) {
-	cerr << "Parameter without value" << endl;
-	return -1;
-      }
-      typeName = argv[++arg];
-    }
-    else if (strcmp(argv[arg], "--input") == 0 || 
-	     strcmp(argv[arg], "-i") == 0) {
-      if (!inputName.empty()) {
-	cerr << "Multiple input description" << endl;
-	return -1;
-      }
-      if (arg + 1 == argc) {
-	cerr << "Parameter without value" << endl;
-	return -1;
-      }
-      inputName = argv[++arg];
-    }
-    else if (strcmp(argv[arg], "--output") == 0 || 
-	     strcmp(argv[arg], "-o") == 0) {
-      if (!outputName.empty()) {
-	cerr << "Multiple input description" << endl;
-	return -1;
-      }
-      if (arg + 1 == argc) {
-	cerr << "Parameter without value" << endl;
-	return -1;
-      }
-      outputName = argv[++arg];
-    } else if (strcmp(argv[arg], "--help") == 0 ||
-	       strcmp(argv[arg], "-h") == 0) {
-      help = true;
-    } else if (strcmp(argv[arg], "--version") == 0 ||
-	       strcmp(argv[arg], "-v") == 0) {
-      version = true;
-    } else {
-      cerr << "Invalid option: " << argv[arg] << endl;
-      return -1;
-    }
-  }
+  bool version;
 
-  if (version) {
-    cout << versionString;
-  }
-  if (help) {
-    cout << helpString;
-  }
-  if (help || version) {
-    return 0;
-  }
+  ArgParser ap(argc, argv);
+  ap.refOption("-input", 
+               "use FILE as input instead of standard input", 
+               inputName).synonym("i", "-input")
+    .refOption("-output", 
+               "use FILE as output instead of standard output", 
+               outputName).synonym("o", "-output")
+    .refOption("-mincostflow", 
+               "set the type of the graph to \"mincostflow\" graph", 
+               mincostflow)
+    .optionGroup("type", "-mincostflow").synonym("mcf", "-mincostflow")
+    .refOption("-maxflow", 
+               "set the type of the graph to \"maxflow\" graph", 
+               maxflow)
+    .optionGroup("type", "-maxflow").synonym("mf", "-maxflow")
+    .refOption("-shortestpath", 
+               "set the type of the graph to \"shortestpath\" graph", 
+               shortestpath)
+    .optionGroup("type", "-shortestpath").synonym("sp", "-shortestpath")
+    .refOption("-capacitated", 
+               "set the type of the graph to \"capacitated\" graph", 
+               capacitated)
+    .optionGroup("type", "-capacitated").synonym("cap", "-capacitated")
+    .refOption("-plain", 
+               "set the type of the graph to \"plain\" graph", 
+               plain)
+    .optionGroup("type", "-plain").synonym("pl", "-plain")
+    .onlyOneGroup("type")
+    .mandatoryGroup("type")
+    .refOption("-version", "show version information", version)
+    .synonym("v", "-version")
+    .run();
 
   ifstream input;
@@ -155,9 +114,5 @@
   ostream& os = (outputName.empty() ? cout : output);
 
-  if (typeName.empty()) {
-    typeName = "maxflow";
-  }
-
-  if (typeName == "mincostflow") {
+  if (mincostflow) {
     Graph graph;
     Node s, t;
@@ -170,5 +125,5 @@
       writeEdgeMap("cost", cost).
       run();
-  } else if (typeName == "maxflow") {
+  } else if (maxflow) {
     Graph graph;
     Node s, t;
@@ -180,5 +135,5 @@
       writeNode("target", t).
       run();
-  } else if (typeName == "shortestpath") {
+  } else if (shortestpath) {
     Graph graph;
     Node s;
@@ -189,5 +144,5 @@
       writeNode("source", s).
       run();
-  } else if (typeName == "capacitated") {
+  } else if (capacitated) {
     Graph graph;
     DoubleMap capacity(graph);
@@ -196,5 +151,5 @@
       writeEdgeMap("capacity", capacity).
       run();
-  } else if (typeName == "plain") {
+  } else if (plain) {
     Graph graph;
     readDimacs(is, graph);
