File: path_table.cpp

package info (click to toggle)
boost1.35 1.35.0-5
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 203,856 kB
  • ctags: 337,867
  • sloc: cpp: 938,683; xml: 56,847; ansic: 41,589; python: 18,999; sh: 11,566; makefile: 664; perl: 494; yacc: 456; asm: 353; csh: 6
file content (264 lines) | stat: -rw-r--r-- 7,512 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
//  Generate an HTML table showing path decomposition  -----------------------//

//  Copyright Beman Dawes 2005.  Distributed under the Boost
//  Software License, Version 1.0. (See accompanying file
//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

//  See http://www.boost.org/libs/filesystem for documentation.

//  For purposes of generating the table, support both POSIX and Windows paths
#define BOOST_FILESYSTEM_NAMESPACE posix
#define BOOST_POSIX_PATH
#include "boost/filesystem/path.hpp"

#undef BOOST_FILESYSTEM_PATH_HPP
#undef BOOST_FILESYSTEM_NAMESPACE
#define BOOST_FILESYSTEM_NAMESPACE windows
#define BOOST_WINDOWS_PATH
#include "boost/filesystem/path.hpp"

namespace pos = boost::posix;
namespace win = boost::windows;

#include <iostream>
#include <fstream>

using std::string;
using std::cout;

namespace
{
  std::ifstream infile;
  std::ofstream outfile;

  const string empty_string;

  struct column_abc
  {
    virtual string heading() const = 0;
    virtual string cell_value( const pos::path & p ) const = 0;
    virtual string cell_value( const win::path & p ) const = 0;
  };

  struct c0 : public column_abc
  {
    string heading() const { return string("<code>string()</code>"); }
    string cell_value( const pos::path & p ) const
    { 
      return p.string();
    }
    string cell_value( const win::path & p ) const
    {
      return p.string();
    }
  } o0;

    struct c1 : public column_abc
  {
    string heading() const { return string("<code>file_<br>string()"); }
    string cell_value( const pos::path & p ) const { return p.file_string(); }
    string cell_value( const win::path & p ) const { return p.file_string(); }
  } o1;

  struct c2 : public column_abc
  {
    string heading() const { return string("Elements found<br>by iteration"); }
    string cell_value( const pos::path & p ) const
    {
      string s;
      for( pos::path::iterator i(p.begin()); i != p.end(); ++i )
      {
        if ( i != p.begin() ) s += ',';
        s += '\"';
        s += *i;
        s += '\"';
      }
      if ( s.empty() ) s += "\"\"";
      return s;
    }
    string cell_value( const win::path & p ) const
    {
      string s;
      for( win::path::iterator i(p.begin()); i != p.end(); ++i )
      {
        if ( i != p.begin() ) s += ',';
        s += '\"';
        s += *i;
        s += '\"';
      }
      if ( s.empty() ) s += "\"\"";
      return s;
    }
  } o2;

  struct c3 : public column_abc
  {
    string heading() const { return string("<code>root_<br>path()<br>.string()</code>"); }
    string cell_value( const pos::path & p ) const { return p.root_path().string(); }
    string cell_value( const win::path & p ) const { return p.root_path().string(); }
  } o3;

  struct c4 : public column_abc
  {
    string heading() const { return string("<code>root_<br>name()</code>"); }
    string cell_value( const pos::path & p ) const { return p.root_name(); }
    string cell_value( const win::path & p ) const { return p.root_name(); }
  } o4;

  struct c5 : public column_abc
  {
    string heading() const { return string("<code>root_<br>directory()</code>"); }
    string cell_value( const pos::path & p ) const { return p.root_directory(); }
    string cell_value( const win::path & p ) const { return p.root_directory(); }
  } o5;

  struct c6 : public column_abc
  {
    string heading() const { return string("<code>relative_<br>path()<br>.string()</code>"); }
    string cell_value( const pos::path & p ) const { return p.relative_path().string(); }
    string cell_value( const win::path & p ) const { return p.relative_path().string(); }
  } o6;

  struct c7 : public column_abc
  {
    string heading() const { return string("<code>branch_<br>path()<br>.string()</code>"); }
    string cell_value( const pos::path & p ) const { return p.branch_path().string(); }
    string cell_value( const win::path & p ) const { return p.branch_path().string(); }
  } o7;

  struct c8 : public column_abc
  {
    string heading() const { return string("<code>leaf()</code>"); }
    string cell_value( const pos::path & p ) const { return p.leaf(); }
    string cell_value( const win::path & p ) const { return p.leaf(); }
  } o8;

  const column_abc * column[] = { &o2, &o0, &o1, &o3, &o4, &o5, &o6, &o7, &o8 };

  //  do_cell  ---------------------------------------------------------------//

  void do_cell( const string & test_case, int i )
  {

    string posix_result( column[i]->cell_value( pos::path(test_case) ) );
    string windows_result( column[i]->cell_value( win::path(test_case) ) );

    outfile <<
      (posix_result != windows_result
        ? "<td bgcolor=\"#CCFF99\"><code>"
        : "<td><code>");

    if ( posix_result.empty() || posix_result[0] != '\"' )
      outfile << '\"' << posix_result << '\"';
    else
      outfile << posix_result;

    if ( posix_result != windows_result )
    {
      outfile << "<br>";
      if ( windows_result.empty() || windows_result[0] != '\"' )
        outfile << '\"' << windows_result << '\"';
      else
        outfile << windows_result;
    }

    outfile << "</code></td>\n";
  }

//  do_row  ------------------------------------------------------------------//

  void do_row( const string & test_case )
  {
    outfile << "<tr>\n<td><code>\"" << test_case << "\"</code></td>\n";

    for ( int i = 0; i < sizeof(column)/sizeof(column_abc&); ++i )
    {
      do_cell( test_case, i );
    }

    outfile << "</tr>\n";
  }

//  do_table  ----------------------------------------------------------------//

  void do_table()
  {
    outfile <<
      "<h1>Path Decomposition Table for <i>POSIX</i> and <i>Windows</i></h1>\n"
      "<p>Shaded entries indicate cases where <i>POSIX</i> and <i>Windows</i>\n"
      "implementations yield different results. The top value is the\n"
      "<i>POSIX</i> result and the bottom value is the <i>Windows</i> result.\n" 
      "<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\">\n"
      "<p>\n"
      ;

    // generate the column headings

    outfile << "<tr><td><b>Constructor<br>argument</b></td>\n";

    for ( int i = 0; i < sizeof(column)/sizeof(column_abc&); ++i )
    {
      outfile << "<td><b>" << column[i]->heading() << "</b></td>\n";
    }

    outfile << "</tr>\n";

    // generate a row for each input line

    string test_case;
    while ( std::getline( infile, test_case ) )
    {
      do_row( test_case );
    }

    outfile << "</table>\n";
  }

} // unnamed namespace

//  main  --------------------------------------------------------------------//

#define BOOST_NO_CPP_MAIN_SUCCESS_MESSAGE
#include <boost/test/included/prg_exec_monitor.hpp>

int cpp_main( int argc, char * argv[] ) // note name!
{
  if ( argc != 3 )
  {
    std::cerr <<
      "Usage: path_table input-file output-file\n"
      "  input-file contains the paths to appear in the table.\n"
      "  output-file will contain the generated HTML.\n"
      ;
    return 1;
  }

  infile.open( argv[1] );
  if ( !infile )
  {
    std::cerr << "Could not open input file: " << argv[1] << std::endl;
    return 1;
  }

  outfile.open( argv[2] );
  if ( !outfile )
  {
    std::cerr << "Could not open output file: " << argv[2] << std::endl;
    return 1;
  }

  outfile << "<html>\n"
          "<head>\n"
          "<title>Path Decomposition Table</title>\n"
          "</head>\n"
          "<body bgcolor=\"#ffffff\" text=\"#000000\">\n"
          ;

  do_table();

  outfile << "</body>\n"
          "</html>\n"
          ;

  return 0;
}