Index: boost/graph/read_dimacs.hpp =================================================================== --- boost/graph/read_dimacs.hpp (revision 64760) +++ boost/graph/read_dimacs.hpp (working copy) @@ -30,20 +30,21 @@ namespace detail { -template +template int read_dimacs_max_flow_internal(Graph& g, CapacityMap capacity, ReverseEdgeMap reverse_edge, typename graph_traits::vertex_descriptor& src, typename graph_traits::vertex_descriptor& sink, std::istream& in, - bool require_source_and_sink) + bool require_source_and_sink, + const char (&PROBLEM_TYPE)[PROBLEM_TYPE_LEN]) { // const int MAXLINE = 100; /* max line length in the input file */ const int ARC_FIELDS = 3; /* no of fields in arc line */ const int NODE_FIELDS = 2; /* no of fields in node line */ const int P_FIELDS = 3; /* no of fields in problem line */ - const char* PROBLEM_TYPE = "max"; /* name of problem type*/ + //const char* PROBLEM_TYPE = "max"; /* name of problem type*/ typedef typename graph_traits::vertices_size_type vertices_size_type; typedef typename graph_traits::vertex_descriptor vertex_descriptor; @@ -61,7 +62,7 @@ no_alines=0; /* no of arc-lines */ std::string in_line; /* for reading input line */ - char pr_type[4]; /* for reading type of the problem */ + char pr_type[PROBLEM_TYPE_LEN + 1]; /* for reading type of the problem */ char nd; /* source (s) or sink (t) */ int k, /* temporary */ @@ -140,15 +141,17 @@ no_plines = 1; + char scanf_format[30]; + std::snprintf(scanf_format, 30, "%%*c %%%ds %%ld %%ld", PROBLEM_TYPE_LEN); if ( /* reading problem line: type of problem, no of nodes, no of arcs */ - std::sscanf ( in_line.c_str(), "%*c %3s %ld %ld", pr_type, &n, &m ) + std::sscanf ( in_line.c_str(), scanf_format, pr_type, &n, &m ) != P_FIELDS ) /*wrong number of parameters in the problem line*/ { err_no = EN2; goto error; } - if ( std::strcmp ( pr_type, PROBLEM_TYPE ) ) + if ( std::strncmp ( pr_type, PROBLEM_TYPE, PROBLEM_TYPE_LEN ) ) /*wrong problem type*/ { err_no = EN3; goto error; } @@ -295,7 +298,8 @@ typename graph_traits::vertex_descriptor& src, typename graph_traits::vertex_descriptor& sink, std::istream& in = std::cin) { - return detail::read_dimacs_max_flow_internal(g, capacity, reverse_edge, src, sink, in, true); + const char PROBLEM_TYPE[3] = {'m', 'a', 'x'}; + return detail::read_dimacs_max_flow_internal(g, capacity, reverse_edge, src, sink, in, true, PROBLEM_TYPE); } template @@ -304,7 +308,8 @@ ReverseEdgeMap reverse_edge, std::istream& in = std::cin) { typename graph_traits::vertex_descriptor dummy_src, dummy_sink; // Not filled in - return detail::read_dimacs_max_flow_internal(g, capacity, reverse_edge, dummy_src, dummy_sink, in, false); + const char PROBLEM_TYPE[3] = {'c', 'u', 't'}; + return detail::read_dimacs_max_flow_internal(g, capacity, reverse_edge, dummy_src, dummy_sink, in, false, PROBLEM_TYPE); } } // namespace boost