00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef VCSN_TOOLS_DUMPER_HXX
00018 # define VCSN_TOOLS_DUMPER_HXX
00019
00020 # include <vaucanson/tools/usual_io.hh>
00021 # ifdef VCSN_USE_XML
00022 # include <vaucanson/tools/xml_dump.hh>
00023 # endif
00024 # include <vaucanson/tools/dot_dump.hh>
00025 # include <vaucanson/tools/fsm_dump.hh>
00026 # include <vaucanson/tools/simple_dump.hh>
00027 # include <cstring>
00028 # include <cstdlib>
00029 # include <cerrno>
00030 # include <string>
00031
00032 namespace vcsn
00033 {
00034 namespace tools
00035 {
00036 int
00037 string_to_int (const std::string& s)
00038 {
00039
00040 errno = 0;
00041 const char *ccp = s.c_str ();
00042 char *cp;
00043 long res = std::strtol (ccp, &cp, 10);
00044 if (*cp || INT_MAX < res || errno)
00045 {
00046 std::cerr << "integer out of bounds: " << s;
00047 if (errno)
00048 std::cerr << " (" << std::strerror (errno) << ")";
00049 std::cerr << std::endl;
00050 exit (1);
00051 }
00052 return res;
00053 }
00054
00055 dumper::dumper (int argc, char **argv, int pos)
00056 : fmt_ (fmt_error), argc_ (argc), argv_ (argv)
00057 {
00058 if (pos < argc_)
00059 fmt_ = dump_format (argv_[pos]);
00060
00061 if (fmt_ == fmt_error
00062 #ifndef VCSN_USE_XML
00063 || fmt_ == fmt_xml
00064 #endif
00065 )
00066 {
00067 std::cerr << "Invalid input: " << pos << " " << argv_[pos] << std::endl;
00068 usage (1);
00069 }
00070 }
00071
00072 void
00073 dumper::usage (int estatus)
00074 {
00075 std::cerr << "Usage: " << argv_[0] << " ... <fmt>" << std::endl
00076 << "where fmt is one of:" << std::endl
00077 << " dot : graphviz format" << std::endl
00078 << " fsm : FSM toolbox format" << std::endl
00079 << " simple : internal Vaucanson format" << std::endl
00080 #ifdef VCSN_USE_XML
00081 << " xml : Vaucanson XML I/O format" << std::endl
00082 #endif
00083 ;
00084 exit (estatus);
00085 }
00086
00087 enum dumper::dump_format
00088 dumper::dump_format (std::string fmt)
00089 {
00090 if (fmt == "dot")
00091 return fmt_dot;
00092 else if (fmt == "simple")
00093 return fmt_simple;
00094 else if (fmt == "xml")
00095 return fmt_xml;
00096 else if (fmt == "fsm")
00097 return fmt_fsm;
00098 else
00099 return fmt_error;
00100 }
00101
00102
00103 const char*
00104 dumper::get_fmt() const
00105 {
00106 switch(fmt_)
00107 {
00108 case fmt_dot: return "dot";
00109 case fmt_xml: return "xml";
00110 case fmt_simple: return "simple";
00111 case fmt_fsm: return "fsm";
00112 case fmt_error: abort ();
00113 }
00114 return "unknown";
00115 }
00116
00117 void
00118 dumper::operator() (std::ostream& o,
00119 const automaton_t& automaton,
00120 const std::string& name)
00121 {
00122 switch(fmt_)
00123 {
00124 case fmt_dot:
00125 vcsn::tools::dot_dump (o, automaton, name);
00126 break;
00127 #ifdef VCSN_USE_XML
00128 case fmt_xml:
00129 vcsn::tools::xml_dump (o, automaton, name);
00130 break;
00131 #endif
00132 case fmt_simple:
00133 vcsn::tools::simple_dump (o, automaton,
00134 vcsn::io::usual_converter_poly<rat_exp_t>());
00135 break;
00136 case fmt_fsm:
00137 vcsn::tools::fsm_dump (o, automaton);
00138 break;
00139 case fmt_error:
00140 abort ();
00141 break;
00142 }
00143 }
00144
00145 }
00146 }
00147
00148 #endif // !VCSN_TOOLS_DUMPER_HXX