Changeset 227


Ignore:
Timestamp:
Mar 12, 2007, 1:32:53 AM (15 years ago)
Author:
Peter Johansson
Message:

Automatic copyright statement fixes #36

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/bin/svndigest.cc

    r226 r227  
    150150  if (option->copyright()){
    151151    try {
     152      if (option->verbose())
     153        std::cout << "Updating copyright statements" << std::endl;
    152154      tree.print_copyright(commit_dates, authors, option->copyright_alias());
    153155    }
  • trunk/lib/File.cc

    r226 r227  
    163163    assert(dates.size()==authors.size());
    164164    using namespace std;
    165     cout << "Copyright: " << local_path() << std::endl;
    166165    SVN* svn=SVN::instance();
    167166    vector<size_t> rev=svn->revisions(path());
     
    184183    }
    185184   
     185    // Code copied from Gnuplot -r70
     186    char tmpname[]="/tmp/svndigestXXXXXX";
     187    int fd=mkstemp(tmpname);  // mkstemp return a file descriptor
     188    if (fd == -1)
     189      throw std::runtime_error(std::string("Failed to get unique filename: ") +
     190                               tmpname);
     191    // Jari would like to do something like 'std::ofstream tmp(fd);'
     192    // but has to settle for (which is stupid since the file is
     193    // already open for writing.
     194    std::ofstream tmp(tmpname);
     195     
     196
     197
     198
     199    ifstream is(path().c_str());
     200    string line;
     201    bool found_copyright = false;
     202    bool after_copyright = false;
    186203    string prefix;
    187 
    188     for (Container::const_iterator i=copyright.begin(); i!=copyright.end();) {
    189       cout << prefix << "Copyright (C) "
    190            << 1900+i->first;
    191       Container::const_iterator j = i;
    192       while (++j!=copyright.end() && i->second == j->second){
    193         cout << ", " << 1900+j->first;
     204    while(getline(is, line)){
     205      if (after_copyright)
     206        tmp << line << "\n";
     207      else if (found_copyright){
     208        // check if line is end of copyright statement, i.e. contains
     209        // no alphanumerical character
     210        after_copyright = true;
     211        for (size_t i=0; i<line.size()&&after_copyright; ++i)
     212          if (isalnum(line[i]))
     213            after_copyright = false;
     214        if (after_copyright)
     215          tmp << line << "\n";
     216         
    194217      }
    195      
    196       // printing authors
    197       for (set<string>::iterator a=i->second.begin(); a!=i->second.end(); ++a) {
    198         if (a!=i->second.begin())
    199           cout << ",";
    200         cout << " " << *a;
     218      else {
     219        // check whether copyright starts on this line
     220        string::iterator i = search(line.begin(), line.end(), "Copyright (C)");
     221       
     222        if (i==line.end())
     223          tmp << line << "\n";
     224        else {
     225          prefix = line.substr(0, distance(line.begin(), i));
     226          found_copyright = true;
     227          if (!found_copyright)
     228            tmp << line << "\n";
     229          else {
     230            // Printing copyright statement
     231            for (Container::const_iterator i=copyright.begin();
     232                 i!=copyright.end();) {
     233              tmp << prefix << "Copyright (C) "
     234                   << 1900+i->first;
     235              Container::const_iterator j = i;
     236              while (++j!=copyright.end() && i->second == j->second){
     237                tmp << ", " << 1900+j->first;
     238              }
     239              // printing authors
     240              for (set<string>::iterator a=i->second.begin();
     241                   a!=i->second.end(); ++a){
     242                if (a!=i->second.begin())
     243                  tmp << ",";
     244                tmp << " " << *a;
     245              }
     246              tmp << "\n";
     247              i = j;
     248            }
     249          }
     250        }
    201251      }
    202       cout << "\n";
    203       i = j;
    204     }
    205 
     252    }
     253    is.close();
     254    tmp.close();
     255    close(fd);
     256    // finally move printed temporary file to original file
     257    rename(tmpname, path().c_str());
    206258  }
    207259}} // end of namespace svndigest and namespace theplu
  • trunk/lib/utility.h

    r226 r227  
    105105  std::string pwd(void);
    106106
    107   inline std::string::iterator search(std::string::iterator& first,
    108                                       std::string::iterator& last,
    109                                       const std::string& str)
     107  ///
     108  /// Search finds a subsecuence in [first, last) being identical to @ str
     109  ///
     110  /// @return iterator pointing to first character in found subsequence
     111  ///
     112  /// @see std::search
     113  ///
     114  inline std::string::iterator search(std::string::iterator first,
     115                                      std::string::iterator last,
     116                                      std::string str)
    110117  { return std::search(first, last, str.begin(), str.end()); }
    111118
Note: See TracChangeset for help on using the changeset viewer.