Changeset 234 for trunk/lib/File.cc


Ignore:
Timestamp:
Apr 9, 2007, 2:08:26 PM (16 years ago)
Author:
Peter Johansson
Message:

fixes #87 and #95 and #103 and #104 and #80 and #108, and refs #69

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/File.cc

    r232 r234  
    2626#include "html_utility.h"
    2727#include "Stats.h"
    28 #include "SVN.h"
     28#include "SVNlog.h"
    2929
    3030#include <cassert>
     
    6666    std::string html_name(outpath + ".html");
    6767    std::ofstream os(html_name.c_str());
    68     print_header(os, name(), level_+2, line_type, local_path()+".html");
     68    print_header(os, name(), level_+2, user, line_type, local_path()+".html");
    6969    path_anchor(os);
    7070    os << "<p align=center>\n<img src='"
     
    7272       << "' alt='[plot]' border=0>\n</p>";
    7373
    74     os << "<table class=\"listings\">\n";
    75     os << "<thead>";
    76     os << "<tr>\n";
    77     os << "<th>Author</th>\n";
    78     os << "<th>Lines</th>\n";
    79     os << "<th>Code</th>\n";
    80     os << "<th>Comments</th>\n";
    81     os << "</tr>\n</thead>\n";
    82     os << "<tbody>";
    83 
    84     bool dark=false;
    85     os << "<tr class=\"light\">\n";
    86     os << "<td class=\"directory\" colspan=\"5\">";
    87     anchor(os, "index.html", "../");
    88     os << "</td>\n</tr>\n";
    89     dark=!dark;
    90    
    91     // print authors
    92     for (std::set<std::string>::const_iterator i=stats_.authors().begin();
    93          i!=stats_.authors().end(); ++i){
    94       if (dark)
    95         os << "<tr class=\"dark\"><td>" << *i
    96            << "</td><td>" << stats_.lines(*i)
    97            << "</td><td>" << stats_.code(*i)
    98            << "</td><td>" << stats_.comments(*i)
    99            << "</td></tr>\n";
    100       else
    101         os << "<tr class=\"light\"><td>" << *i
    102            << "</td><td>" << stats_.lines(*i)
    103            << "</td><td>" << stats_.code(*i)
    104            << "</td><td>" << stats_.comments(*i)
    105            << "</td></tr>\n";
    106       dark=!dark;
    107     }
    108     if (dark)
    109       os << "<tr class=\"dark\">\n";
    110     else
    111       os << "<tr class=\"light\">\n";
    112     os << "<td>Total</td>\n";
    113     os << "<td>" << stats_.lines() << "</td>\n";
    114     os << "<td>" << stats_.code() << "</td>\n";
    115     os << "<td>" << stats_.comments() << "</td>\n";
    116     os << "</tr>\n";
    117     os << "</table>\n";
     74    print_author_summary(os);
    11875    os << "</p>\n";
    11976
     
    154111
    155112
    156   void File::print_copyright
    157   (const std::vector<std::string>& dates,
    158    const std::vector<std::string>& authors,
    159    std::map<std::string, std::string>& alias) const
    160   {
     113  void File::print_copyright (std::map<std::string,std::string>& alias) const{
    161114    if (ignore())
    162115      return;
    163     assert(dates.size()==authors.size());
    164116    using namespace std;
    165     SVN* svn=SVN::instance();
    166     vector<size_t> rev=svn->revisions(path());
     117
     118    SVNlog log(path());
    167119
    168120    typedef map<int, set<string> > Container;
    169121    Container copyright;
    170     for (vector<size_t>::iterator i=rev.begin(); i!=rev.end(); ++i) {
    171       assert(*i<dates.size());
    172       time_t sec = str2time(dates[*i]);
     122
     123   
     124    assert(log.author().size()==log.date().size());
     125    vector<string>::const_iterator author=log.author().begin();
     126    for (vector<string>::const_iterator date=log.date().begin();
     127         date!=log.date().end(); ++date, ++author) {
     128      time_t sec = str2time(*date);
    173129      tm* timeinfo = gmtime(&sec);
    174130
    175131      // find username in map of aliases
    176       map<string, string>::iterator name = alias.lower_bound(authors[*i]);
     132      map<string, string>::iterator name = alias.lower_bound(*author);
    177133      // if alias exist insert alias
    178       if (name != alias.end() && name->first==authors[*i])
     134      if (name != alias.end() && name->first==*author)
    179135        copyright[timeinfo->tm_year].insert(name->second);
    180136      else {
    181137        // else insert user name
    182         copyright[timeinfo->tm_year].insert(authors[*i]);
    183         std::cerr << "Warning: no alias found for `" << authors[*i] << "`\n";
     138        copyright[timeinfo->tm_year].insert(*author);
     139        std::cerr << "Warning: no alias found for `" << *author << "`\n";
    184140        // insert alias to avoid multiple warnings.
    185         alias.insert(name, std::make_pair(authors[*i], authors[*i]));
     141        alias.insert(name, std::make_pair(*author, *author));
    186142      }
    187143    }
    188    
     144
     145
    189146    // Code copied from Gnuplot -r70
    190147    char tmpname[]="/tmp/svndigestXXXXXX";
     
    197154    // already open for writing.
    198155    std::ofstream tmp(tmpname);
    199      
    200 
    201 
    202156
    203157    ifstream is(path().c_str());
     158    assert(is.good());
    204159    string line;
    205160    bool found_copyright = false;
     
    223178        // check whether copyright starts on this line
    224179        string::iterator i = search(line.begin(), line.end(), "Copyright (C)");
    225        
    226         if (i==line.end())
     180        if (i==line.end()) {
    227181          tmp << line << "\n";
     182        }     
    228183        else {
    229184          prefix = line.substr(0, distance(line.begin(), i));
    230185          found_copyright = true;
    231           if (!found_copyright)
    232             tmp << line << "\n";
    233           else {
    234             // Printing copyright statement
    235             for (Container::const_iterator i=copyright.begin();
    236                  i!=copyright.end();) {
    237               tmp << prefix << "Copyright (C) "
    238                    << 1900+i->first;
    239               Container::const_iterator j = i;
    240               while (++j!=copyright.end() && i->second == j->second){
    241                 tmp << ", " << 1900+j->first;
    242               }
    243               // printing authors
    244               for (set<string>::iterator a=i->second.begin();
    245                    a!=i->second.end(); ++a){
    246                 if (a!=i->second.begin())
    247                   tmp << ",";
    248                 tmp << " " << *a;
    249               }
    250               tmp << "\n";
    251               i = j;
     186          // Printing copyright statement
     187          for (Container::const_iterator i=copyright.begin();
     188               i!=copyright.end();) {
     189            tmp << prefix << "Copyright (C) "
     190                << 1900+i->first;
     191            Container::const_iterator j = i;
     192            assert(i!=copyright.end());
     193            while (++j!=copyright.end() && i->second == j->second){
     194              tmp << ", " << 1900+(j->first);
    252195            }
     196            // printing authors
     197            for (set<string>::iterator a=i->second.begin();
     198                 a!=i->second.end(); ++a){
     199              if (a!=i->second.begin())
     200                tmp << ",";
     201              tmp << " " << *a;
     202            }
     203            tmp << "\n";
     204            i = j;
    253205          }
    254206        }
Note: See TracChangeset for help on using the changeset viewer.