source: trunk/lib/File.cc @ 151

Last change on this file since 151 was 149, checked in by Jari Häkkinen, 15 years ago

Changed svnstat to svndigest.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.9 KB
Line 
1// $Id: File.cc 149 2006-08-12 09:11:46Z jari $
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  std::string File::html_link(void) const
35  { 
36    return "<a href=\"" + name() + ".html\">" + name() + "</a>"; 
37  }
38
39
40  const Stats& File::parse(const bool verbose)
41  {
42    if (verbose)
43      std::cout << "Parsing " << path_ << std::endl; 
44    stats_.reset();
45    binary_ = stats_.parse(path_);
46    return stats_;
47  }
48
49  void File::print(const bool verbose) const 
50  {
51    std::string output(output_name() + ".html");
52    if (verbose)
53      std::cout << "Printing output for " << path_ << std::endl;
54    std::ofstream os(output.c_str());
55    print_header(os);
56    os << "<p align=center>\n<img src='" 
57       << file_name(stats_.plot(output_name()+".png",output_name()))
58       << "' alt='[plot]' border=0>\n</p>";
59
60    os << "<table class=\"listings\">\n";
61    os << "<thead>";
62    os << "<tr>\n";
63    os << "<th>Author</th>\n";
64    os << "<th>Lines</th>\n";
65    os << "<th>Code</th>\n";
66    os << "<th>Comments</th>\n";
67    os << "</tr>\n</thead>\n";
68    os << "<tbody>";
69
70    bool dark=false;
71    os << "<tr class=\"light\">\n";
72    os << "<td colspan=\"5\"><a href=\"index.html\">../</a></td>\n";
73    os << "</tr>\n";
74    dark=!dark;
75   
76
77    // print authors
78    for (std::set<std::string>::const_iterator i=stats_.authors().begin();
79         i!=stats_.authors().end(); ++i){
80      if (dark)
81        os << "<tr class=\"dark\"><td>" << *i
82           << "</td><td>" << stats_.lines(*i)
83           << "</td><td>" << stats_.code(*i)
84           << "</td><td>" << stats_.comments(*i)
85           << "</td></tr>\n";
86      else
87        os << "<tr class=\"light\"><td>" << *i
88           << "</td><td>" << stats_.lines(*i)
89           << "</td><td>" << stats_.code(*i)
90           << "</td><td>" << stats_.comments(*i)
91           << "</td></tr>\n";
92      dark=!dark;
93    }
94    if (dark)
95      os << "<tr class=\"dark\">\n";
96    else
97      os << "<tr class=\"light\">\n";
98    os << "<td>Total</td>\n";
99    os << "<td>" << stats_.lines() << "</td>\n";
100    os << "<td>" << stats_.code() << "</td>\n";
101    os << "<td>" << stats_.comments() << "</td>\n";
102    os << "</tr>\n";
103    os << "</table>\n";
104    os << "</p>\n";
105
106    print_footer(os);
107    os.close(); 
108  }
109
110}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.