1 | // $Id: File.cc 213 2006-09-15 15:05:45Z 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 "html_utility.h" |
---|
26 | #include "Stats.h" |
---|
27 | |
---|
28 | #include <cassert> |
---|
29 | #include <fstream> |
---|
30 | #include <iostream> |
---|
31 | #include <string> |
---|
32 | |
---|
33 | namespace theplu{ |
---|
34 | namespace svndigest{ |
---|
35 | |
---|
36 | |
---|
37 | std::string File::href(void) const |
---|
38 | { |
---|
39 | return name()+".html"; |
---|
40 | } |
---|
41 | |
---|
42 | |
---|
43 | const std::string File::node_type(void) const |
---|
44 | { |
---|
45 | return std::string("file"); |
---|
46 | } |
---|
47 | |
---|
48 | |
---|
49 | const Stats& File::parse(const bool verbose) |
---|
50 | { |
---|
51 | if (verbose) |
---|
52 | std::cout << "Parsing " << path_ << std::endl; |
---|
53 | stats_.reset(); |
---|
54 | stats_.parse(path_); |
---|
55 | return stats_; |
---|
56 | } |
---|
57 | |
---|
58 | |
---|
59 | void File::print(const std::string& user, const std::string& line_type) const |
---|
60 | { |
---|
61 | std::string outpath = user+"/"+line_type+"/"+local_path(); |
---|
62 | std::string html_name(outpath + ".html"); |
---|
63 | std::ofstream os(html_name.c_str()); |
---|
64 | print_header(os, name(), level_+2, line_type, local_path()+".html"); |
---|
65 | path_anchor(os); |
---|
66 | os << "<p align=center>\n<img src='" |
---|
67 | << file_name(stats_.plot(outpath+".png",local_path(),line_type)) |
---|
68 | << "' alt='[plot]' border=0>\n</p>"; |
---|
69 | |
---|
70 | os << "<table class=\"listings\">\n"; |
---|
71 | os << "<thead>"; |
---|
72 | os << "<tr>\n"; |
---|
73 | os << "<th>Author</th>\n"; |
---|
74 | os << "<th>Lines</th>\n"; |
---|
75 | os << "<th>Code</th>\n"; |
---|
76 | os << "<th>Comments</th>\n"; |
---|
77 | os << "</tr>\n</thead>\n"; |
---|
78 | os << "<tbody>"; |
---|
79 | |
---|
80 | bool dark=false; |
---|
81 | os << "<tr class=\"light\">\n"; |
---|
82 | os << "<td class=\"directory\" colspan=\"5\">"; |
---|
83 | anchor(os, "index.html", "../"); |
---|
84 | os << "</td>\n</tr>\n"; |
---|
85 | dark=!dark; |
---|
86 | |
---|
87 | // print authors |
---|
88 | for (std::set<std::string>::const_iterator i=stats_.authors().begin(); |
---|
89 | i!=stats_.authors().end(); ++i){ |
---|
90 | if (dark) |
---|
91 | os << "<tr class=\"dark\"><td>" << *i |
---|
92 | << "</td><td>" << stats_.lines(*i) |
---|
93 | << "</td><td>" << stats_.code(*i) |
---|
94 | << "</td><td>" << stats_.comments(*i) |
---|
95 | << "</td></tr>\n"; |
---|
96 | else |
---|
97 | os << "<tr class=\"light\"><td>" << *i |
---|
98 | << "</td><td>" << stats_.lines(*i) |
---|
99 | << "</td><td>" << stats_.code(*i) |
---|
100 | << "</td><td>" << stats_.comments(*i) |
---|
101 | << "</td></tr>\n"; |
---|
102 | dark=!dark; |
---|
103 | } |
---|
104 | if (dark) |
---|
105 | os << "<tr class=\"dark\">\n"; |
---|
106 | else |
---|
107 | os << "<tr class=\"light\">\n"; |
---|
108 | os << "<td>Total</td>\n"; |
---|
109 | os << "<td>" << stats_.lines() << "</td>\n"; |
---|
110 | os << "<td>" << stats_.code() << "</td>\n"; |
---|
111 | os << "<td>" << stats_.comments() << "</td>\n"; |
---|
112 | os << "</tr>\n"; |
---|
113 | os << "</table>\n"; |
---|
114 | os << "</p>\n"; |
---|
115 | |
---|
116 | print_footer(os); |
---|
117 | os.close(); |
---|
118 | } |
---|
119 | |
---|
120 | |
---|
121 | void File::print(const bool verbose) const |
---|
122 | { |
---|
123 | // no output page for binary files |
---|
124 | if (ignore()) |
---|
125 | return; |
---|
126 | if (verbose) |
---|
127 | std::cout << "Printing output for " << path_ << std::endl; |
---|
128 | print("all", "total"); |
---|
129 | print("all", "code"); |
---|
130 | print("all", "comments"); |
---|
131 | print("all", "empty"); |
---|
132 | |
---|
133 | for (std::set<std::string>::const_iterator i = stats_.authors().begin(); |
---|
134 | i!=stats_.authors().end(); ++i) { |
---|
135 | print(*i, "total"); |
---|
136 | print(*i, "code"); |
---|
137 | print(*i, "comments"); |
---|
138 | print(*i, "empty"); |
---|
139 | } |
---|
140 | |
---|
141 | } |
---|
142 | |
---|
143 | |
---|
144 | void File::print_blame(std::ofstream& os, const std::string line_type) const |
---|
145 | { |
---|
146 | os << "<table class=\"blame\">\n"; |
---|
147 | |
---|
148 | os << "</table>\n"; |
---|
149 | } |
---|
150 | |
---|
151 | |
---|
152 | void File::print_copyright(const std::vector<std::string>& dates) const |
---|
153 | { |
---|
154 | if (ignore()) |
---|
155 | return; |
---|
156 | std::cout << "\nCOPYRIGHT " << local_path() << std::endl; |
---|
157 | // last rev and 4-chars string for each year |
---|
158 | std::vector<std::pair<size_t,std::string> > years; |
---|
159 | for (size_t i=1; i<dates.size(); ++i) // ignoring rev 0 |
---|
160 | if (years.empty() || years.back().second != dates[i].substr(0,4)){ |
---|
161 | years.push_back(std::pair<size_t,std::string>(i,dates[i].substr(0,4))); |
---|
162 | } |
---|
163 | else { |
---|
164 | years.back() = std::pair<size_t, std::string>(i, dates[i].substr(0,4)); |
---|
165 | } |
---|
166 | |
---|
167 | // copyrigt[i] is set of contributors for year 'i' |
---|
168 | std::vector<std::set<std::string> > copyright; |
---|
169 | copyright.resize(years.size()); |
---|
170 | for (std::set<std::string>::const_iterator au=stats_.authors().begin(); |
---|
171 | au!=stats_.authors().end(); ++au){ |
---|
172 | std::vector<u_int> lines = stats_.total(*au); |
---|
173 | assert(!lines.empty()); |
---|
174 | // insert author for 'year zero' |
---|
175 | if (lines[years[0].first]>0 ){ |
---|
176 | copyright[0].insert(*au); |
---|
177 | } |
---|
178 | // insert authors for remaining years |
---|
179 | for (size_t y=1; y<years.size(); ++y) |
---|
180 | if (lines[years[y].first]!=lines[years[y-1].first] ){ |
---|
181 | copyright[y].insert(*au); |
---|
182 | } |
---|
183 | |
---|
184 | } |
---|
185 | // looping over years |
---|
186 | for (size_t i = 0; i<copyright.size();++i){ |
---|
187 | if (copyright[i].empty()){ |
---|
188 | continue; |
---|
189 | } |
---|
190 | |
---|
191 | std::cout << "Copyright (C) " << years[i].second; |
---|
192 | for (size_t j=i+1; j<copyright.size(); ++j){ |
---|
193 | if (copyright[j].empty()) |
---|
194 | continue; |
---|
195 | else if (copyright[j]==copyright[i]){ |
---|
196 | std::cout << ", " << years[j].second; |
---|
197 | i=j; |
---|
198 | } |
---|
199 | else |
---|
200 | break; |
---|
201 | } |
---|
202 | std::cout << " "; |
---|
203 | |
---|
204 | for (std::set<std::string>::const_iterator iter=copyright[i].begin(); |
---|
205 | iter!=copyright[i].end(); ++iter){ |
---|
206 | if (iter!=copyright[i].begin()) |
---|
207 | std::cout << ", "; |
---|
208 | std::cout << *iter; |
---|
209 | |
---|
210 | } |
---|
211 | std::cout << std::endl; |
---|
212 | } |
---|
213 | } |
---|
214 | }} // end of namespace svndigest and namespace theplu |
---|