source: trunk/lib/File.cc @ 176

Last change on this file since 176 was 176, checked in by Peter Johansson, 16 years ago

fixes #12 binary files are now printed with note without anchor. Binary files and directories all counted as zero lines.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.0 KB
Line 
1// $Id: File.cc 176 2006-09-02 04:17:28Z peter $
2
3/*
4  Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson
5
6  This file is part of svndigest, http://lev.thep.lu.se/trac/svndigest
7
8  svndigest is free software; you can redistribute it and/or modify it
9  under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  svndigest is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#include "File.h"
25#include "Stats.h"
26
27#include <fstream>
28#include <iostream>
29#include <string>
30
31namespace theplu{
32namespace svndigest{
33
34  bool File::binary(void) const
35  {
36    return binary_;
37  }
38
39
40  std::string File::href(void) const
41  { 
42    return name()+".html"; 
43  }
44
45
46  const Stats& File::parse(const bool verbose)
47  {
48    if (verbose)
49      std::cout << "Parsing " << path_ << std::endl; 
50    stats_.reset();
51    binary_ = stats_.parse(path_);
52    return stats_;
53  }
54
55  void File::print(const bool verbose) const 
56  {
57    // no output page for binary files
58    if (binary_)
59      return;
60    std::string output(output_name() + ".html");
61    if (verbose)
62      std::cout << "Printing output for " << path_ << std::endl;
63    std::ofstream os(output.c_str());
64    print_header(os);
65    os << "<p align=center>\n<img src='" 
66       << file_name(stats_.plot(output_name()+".png",output_name()))
67       << "' alt='[plot]' border=0>\n</p>";
68
69    os << "<table class=\"listings\">\n";
70    os << "<thead>";
71    os << "<tr>\n";
72    os << "<th>Author</th>\n";
73    os << "<th>Lines</th>\n";
74    os << "<th>Code</th>\n";
75    os << "<th>Comments</th>\n";
76    os << "</tr>\n</thead>\n";
77    os << "<tbody>";
78
79    bool dark=false;
80    os << "<tr class=\"light\">\n";
81    os << "<td colspan=\"5\"><a href=\"index.html\">../</a></td>\n";
82    os << "</tr>\n";
83    dark=!dark;
84   
85
86    // print authors
87    for (std::set<std::string>::const_iterator i=stats_.authors().begin();
88         i!=stats_.authors().end(); ++i){
89      if (dark)
90        os << "<tr class=\"dark\"><td>" << *i
91           << "</td><td>" << stats_.lines(*i)
92           << "</td><td>" << stats_.code(*i)
93           << "</td><td>" << stats_.comments(*i)
94           << "</td></tr>\n";
95      else
96        os << "<tr class=\"light\"><td>" << *i
97           << "</td><td>" << stats_.lines(*i)
98           << "</td><td>" << stats_.code(*i)
99           << "</td><td>" << stats_.comments(*i)
100           << "</td></tr>\n";
101      dark=!dark;
102    }
103    if (dark)
104      os << "<tr class=\"dark\">\n";
105    else
106      os << "<tr class=\"light\">\n";
107    os << "<td>Total</td>\n";
108    os << "<td>" << stats_.lines() << "</td>\n";
109    os << "<td>" << stats_.code() << "</td>\n";
110    os << "<td>" << stats_.comments() << "</td>\n";
111    os << "</tr>\n";
112    os << "</table>\n";
113    os << "</p>\n";
114
115    print_footer(os);
116    os.close(); 
117  }
118
119}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.