| 1 | // Generate an HTML table showing path decomposition -----------------------// |
|---|
| 2 | |
|---|
| 3 | // Copyright Beman Dawes 2005. Distributed under the Boost |
|---|
| 4 | // Software License, Version 1.0. (See accompanying file |
|---|
| 5 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 6 | |
|---|
| 7 | // See http://www.boost.org/libs/filesystem for documentation. |
|---|
| 8 | |
|---|
| 9 | // For purposes of generating the table, support both POSIX and Windows paths |
|---|
| 10 | #define BOOST_FILESYSTEM_NAMESPACE posix |
|---|
| 11 | #define BOOST_POSIX_PATH |
|---|
| 12 | #include "boost/filesystem/path.hpp" |
|---|
| 13 | |
|---|
| 14 | #undef BOOST_FILESYSTEM_PATH_HPP |
|---|
| 15 | #undef BOOST_FILESYSTEM_NAMESPACE |
|---|
| 16 | #define BOOST_FILESYSTEM_NAMESPACE windows |
|---|
| 17 | #define BOOST_WINDOWS_PATH |
|---|
| 18 | #include "boost/filesystem/path.hpp" |
|---|
| 19 | |
|---|
| 20 | namespace pos = boost::posix; |
|---|
| 21 | namespace win = boost::windows; |
|---|
| 22 | |
|---|
| 23 | #include <iostream> |
|---|
| 24 | #include <fstream> |
|---|
| 25 | |
|---|
| 26 | using std::string; |
|---|
| 27 | using std::cout; |
|---|
| 28 | |
|---|
| 29 | namespace |
|---|
| 30 | { |
|---|
| 31 | std::ifstream infile; |
|---|
| 32 | std::ofstream outfile; |
|---|
| 33 | |
|---|
| 34 | const string empty_string; |
|---|
| 35 | |
|---|
| 36 | struct column_abc |
|---|
| 37 | { |
|---|
| 38 | virtual string heading() const = 0; |
|---|
| 39 | virtual string cell_value( const pos::path & p ) const = 0; |
|---|
| 40 | virtual string cell_value( const win::path & p ) const = 0; |
|---|
| 41 | }; |
|---|
| 42 | |
|---|
| 43 | struct c0 : public column_abc |
|---|
| 44 | { |
|---|
| 45 | string heading() const { return string("<code>string()</code>"); } |
|---|
| 46 | string cell_value( const pos::path & p ) const |
|---|
| 47 | { |
|---|
| 48 | return p.string(); |
|---|
| 49 | } |
|---|
| 50 | string cell_value( const win::path & p ) const |
|---|
| 51 | { |
|---|
| 52 | return p.string(); |
|---|
| 53 | } |
|---|
| 54 | } o0; |
|---|
| 55 | |
|---|
| 56 | struct c1 : public column_abc |
|---|
| 57 | { |
|---|
| 58 | string heading() const { return string("<code>file_<br>string()"); } |
|---|
| 59 | string cell_value( const pos::path & p ) const { return p.file_string(); } |
|---|
| 60 | string cell_value( const win::path & p ) const { return p.file_string(); } |
|---|
| 61 | } o1; |
|---|
| 62 | |
|---|
| 63 | struct c2 : public column_abc |
|---|
| 64 | { |
|---|
| 65 | string heading() const { return string("Elements found<br>by iteration"); } |
|---|
| 66 | string cell_value( const pos::path & p ) const |
|---|
| 67 | { |
|---|
| 68 | string s; |
|---|
| 69 | for( pos::path::iterator i(p.begin()); i != p.end(); ++i ) |
|---|
| 70 | { |
|---|
| 71 | if ( i != p.begin() ) s += ','; |
|---|
| 72 | s += '\"'; |
|---|
| 73 | s += *i; |
|---|
| 74 | s += '\"'; |
|---|
| 75 | } |
|---|
| 76 | if ( s.empty() ) s += "\"\""; |
|---|
| 77 | return s; |
|---|
| 78 | } |
|---|
| 79 | string cell_value( const win::path & p ) const |
|---|
| 80 | { |
|---|
| 81 | string s; |
|---|
| 82 | for( win::path::iterator i(p.begin()); i != p.end(); ++i ) |
|---|
| 83 | { |
|---|
| 84 | if ( i != p.begin() ) s += ','; |
|---|
| 85 | s += '\"'; |
|---|
| 86 | s += *i; |
|---|
| 87 | s += '\"'; |
|---|
| 88 | } |
|---|
| 89 | if ( s.empty() ) s += "\"\""; |
|---|
| 90 | return s; |
|---|
| 91 | } |
|---|
| 92 | } o2; |
|---|
| 93 | |
|---|
| 94 | struct c3 : public column_abc |
|---|
| 95 | { |
|---|
| 96 | string heading() const { return string("<code>root_<br>path()<br>.string()</code>"); } |
|---|
| 97 | string cell_value( const pos::path & p ) const { return p.root_path().string(); } |
|---|
| 98 | string cell_value( const win::path & p ) const { return p.root_path().string(); } |
|---|
| 99 | } o3; |
|---|
| 100 | |
|---|
| 101 | struct c4 : public column_abc |
|---|
| 102 | { |
|---|
| 103 | string heading() const { return string("<code>root_<br>name()</code>"); } |
|---|
| 104 | string cell_value( const pos::path & p ) const { return p.root_name(); } |
|---|
| 105 | string cell_value( const win::path & p ) const { return p.root_name(); } |
|---|
| 106 | } o4; |
|---|
| 107 | |
|---|
| 108 | struct c5 : public column_abc |
|---|
| 109 | { |
|---|
| 110 | string heading() const { return string("<code>root_<br>directory()</code>"); } |
|---|
| 111 | string cell_value( const pos::path & p ) const { return p.root_directory(); } |
|---|
| 112 | string cell_value( const win::path & p ) const { return p.root_directory(); } |
|---|
| 113 | } o5; |
|---|
| 114 | |
|---|
| 115 | struct c6 : public column_abc |
|---|
| 116 | { |
|---|
| 117 | string heading() const { return string("<code>relative_<br>path()<br>.string()</code>"); } |
|---|
| 118 | string cell_value( const pos::path & p ) const { return p.relative_path().string(); } |
|---|
| 119 | string cell_value( const win::path & p ) const { return p.relative_path().string(); } |
|---|
| 120 | } o6; |
|---|
| 121 | |
|---|
| 122 | struct c7 : public column_abc |
|---|
| 123 | { |
|---|
| 124 | string heading() const { return string("<code>branch_<br>path()<br>.string()</code>"); } |
|---|
| 125 | string cell_value( const pos::path & p ) const { return p.branch_path().string(); } |
|---|
| 126 | string cell_value( const win::path & p ) const { return p.branch_path().string(); } |
|---|
| 127 | } o7; |
|---|
| 128 | |
|---|
| 129 | struct c8 : public column_abc |
|---|
| 130 | { |
|---|
| 131 | string heading() const { return string("<code>leaf()</code>"); } |
|---|
| 132 | string cell_value( const pos::path & p ) const { return p.leaf(); } |
|---|
| 133 | string cell_value( const win::path & p ) const { return p.leaf(); } |
|---|
| 134 | } o8; |
|---|
| 135 | |
|---|
| 136 | const column_abc * column[] = { &o2, &o0, &o1, &o3, &o4, &o5, &o6, &o7, &o8 }; |
|---|
| 137 | |
|---|
| 138 | // do_cell ---------------------------------------------------------------// |
|---|
| 139 | |
|---|
| 140 | void do_cell( const string & test_case, int i ) |
|---|
| 141 | { |
|---|
| 142 | |
|---|
| 143 | string posix_result( column[i]->cell_value( pos::path(test_case) ) ); |
|---|
| 144 | string windows_result( column[i]->cell_value( win::path(test_case) ) ); |
|---|
| 145 | |
|---|
| 146 | outfile << |
|---|
| 147 | (posix_result != windows_result |
|---|
| 148 | ? "<td bgcolor=\"#CCFF99\"><code>" |
|---|
| 149 | : "<td><code>"); |
|---|
| 150 | |
|---|
| 151 | if ( posix_result.empty() || posix_result[0] != '\"' ) |
|---|
| 152 | outfile << '\"' << posix_result << '\"'; |
|---|
| 153 | else |
|---|
| 154 | outfile << posix_result; |
|---|
| 155 | |
|---|
| 156 | if ( posix_result != windows_result ) |
|---|
| 157 | { |
|---|
| 158 | outfile << "<br>"; |
|---|
| 159 | if ( windows_result.empty() || windows_result[0] != '\"' ) |
|---|
| 160 | outfile << '\"' << windows_result << '\"'; |
|---|
| 161 | else |
|---|
| 162 | outfile << windows_result; |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | outfile << "</code></td>\n"; |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | // do_row ------------------------------------------------------------------// |
|---|
| 169 | |
|---|
| 170 | void do_row( const string & test_case ) |
|---|
| 171 | { |
|---|
| 172 | outfile << "<tr>\n<td><code>\"" << test_case << "\"</code></td>\n"; |
|---|
| 173 | |
|---|
| 174 | for ( int i = 0; i < sizeof(column)/sizeof(column_abc&); ++i ) |
|---|
| 175 | { |
|---|
| 176 | do_cell( test_case, i ); |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | outfile << "</tr>\n"; |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | // do_table ----------------------------------------------------------------// |
|---|
| 183 | |
|---|
| 184 | void do_table() |
|---|
| 185 | { |
|---|
| 186 | outfile << |
|---|
| 187 | "<h1>Path Decomposition Table for <i>POSIX</i> and <i>Windows</i></h1>\n" |
|---|
| 188 | "<p>Shaded entries indicate cases where <i>POSIX</i> and <i>Windows</i>\n" |
|---|
| 189 | "implementations yield different results. The top value is the\n" |
|---|
| 190 | "<i>POSIX</i> result and the bottom value is the <i>Windows</i> result.\n" |
|---|
| 191 | "<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\">\n" |
|---|
| 192 | "<p>\n" |
|---|
| 193 | ; |
|---|
| 194 | |
|---|
| 195 | // generate the column headings |
|---|
| 196 | |
|---|
| 197 | outfile << "<tr><td><b>Constructor<br>argument</b></td>\n"; |
|---|
| 198 | |
|---|
| 199 | for ( int i = 0; i < sizeof(column)/sizeof(column_abc&); ++i ) |
|---|
| 200 | { |
|---|
| 201 | outfile << "<td><b>" << column[i]->heading() << "</b></td>\n"; |
|---|
| 202 | } |
|---|
| 203 | |
|---|
| 204 | outfile << "</tr>\n"; |
|---|
| 205 | |
|---|
| 206 | // generate a row for each input line |
|---|
| 207 | |
|---|
| 208 | string test_case; |
|---|
| 209 | while ( std::getline( infile, test_case ) ) |
|---|
| 210 | { |
|---|
| 211 | do_row( test_case ); |
|---|
| 212 | } |
|---|
| 213 | |
|---|
| 214 | outfile << "</table>\n"; |
|---|
| 215 | } |
|---|
| 216 | |
|---|
| 217 | } // unnamed namespace |
|---|
| 218 | |
|---|
| 219 | // main --------------------------------------------------------------------// |
|---|
| 220 | |
|---|
| 221 | #define BOOST_NO_CPP_MAIN_SUCCESS_MESSAGE |
|---|
| 222 | #include <boost/test/included/prg_exec_monitor.hpp> |
|---|
| 223 | |
|---|
| 224 | int cpp_main( int argc, char * argv[] ) // note name! |
|---|
| 225 | { |
|---|
| 226 | if ( argc != 3 ) |
|---|
| 227 | { |
|---|
| 228 | std::cerr << |
|---|
| 229 | "Usage: path_table input-file output-file\n" |
|---|
| 230 | " input-file contains the paths to appear in the table.\n" |
|---|
| 231 | " output-file will contain the generated HTML.\n" |
|---|
| 232 | ; |
|---|
| 233 | return 1; |
|---|
| 234 | } |
|---|
| 235 | |
|---|
| 236 | infile.open( argv[1] ); |
|---|
| 237 | if ( !infile ) |
|---|
| 238 | { |
|---|
| 239 | std::cerr << "Could not open input file: " << argv[1] << std::endl; |
|---|
| 240 | return 1; |
|---|
| 241 | } |
|---|
| 242 | |
|---|
| 243 | outfile.open( argv[2] ); |
|---|
| 244 | if ( !outfile ) |
|---|
| 245 | { |
|---|
| 246 | std::cerr << "Could not open output file: " << argv[2] << std::endl; |
|---|
| 247 | return 1; |
|---|
| 248 | } |
|---|
| 249 | |
|---|
| 250 | outfile << "<html>\n" |
|---|
| 251 | "<head>\n" |
|---|
| 252 | "<title>Path Decomposition Table</title>\n" |
|---|
| 253 | "</head>\n" |
|---|
| 254 | "<body bgcolor=\"#ffffff\" text=\"#000000\">\n" |
|---|
| 255 | ; |
|---|
| 256 | |
|---|
| 257 | do_table(); |
|---|
| 258 | |
|---|
| 259 | outfile << "</body>\n" |
|---|
| 260 | "</html>\n" |
|---|
| 261 | ; |
|---|
| 262 | |
|---|
| 263 | return 0; |
|---|
| 264 | } |
|---|