Changeset 446


Ignore:
Timestamp:
Aug 16, 2007, 5:57:18 PM (14 years ago)
Author:
Peter Johansson
Message:

fixes #243

Location:
trunk/lib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Configuration.cc

    r439 r446  
    4848  {
    4949    return copyright_alias_;
     50  }
     51
     52
     53  bool Configuration::equal_false(const std::string& str) const
     54  {
     55    return str=="false" || str=="False" || str=="FALSE" ||
     56      str=="no" || str=="No" || str=="NO";
     57  }
     58
     59
     60  bool Configuration::equal_true(const std::string& str) const
     61  {
     62    return str=="true" || str=="True" || str=="TRUE" ||
     63      str=="yes" || str=="Yes" || str=="YES";
    5064  }
    5165
     
    7387        getline(ss, tmp, '[');
    7488        getline(ss, section, ']');
    75       }
    76       else if (section == "copyright-alias"){
    77         getline(ss, tmp, '=');
    78         std::string key = trim(tmp);
    79         getline(ss, tmp);
    80         std::string name = trim(tmp);
     89        continue;
     90      }
     91      getline(ss, tmp, '=');
     92      std::string lhs = trim(tmp);
     93      getline(ss, tmp);
     94      std::string rhs = trim(tmp);
     95      if (rhs.empty()){
     96        std::stringstream mess;
     97        mess << "svndigest: invalid config file: "
     98             << "line: `" << line << "' is invalid.";
     99        throw std::runtime_error(mess.str());
     100
     101      if (section == "copyright-alias"){
    81102        std::map<std::string,Alias>::iterator iter =
    82           copyright_alias_.lower_bound(key);
    83         if (iter!=copyright_alias_.end() && iter->first==key){
     103          copyright_alias_.lower_bound(lhs);
     104        if (iter!=copyright_alias_.end() && iter->first==lhs){
    84105          std::stringstream mess;
    85106          mess << "svndigest: invalid config file: "
    86                << "in copright-alias section " << key + " defined twice.";
     107               << "in copright-alias section " << lhs << " defined twice.";
    87108          throw std::runtime_error(mess.str());
    88109        }
    89110       
    90111        // insert alias
    91         copyright_alias_.insert(iter,std::make_pair(key, Alias(name,copyright_alias_.size())));
     112        copyright_alias_.insert(iter,std::make_pair(lhs, Alias(rhs,copyright_alias_.size())));
    92113      }
    93114      else if (section == "trac"){
    94         getline(ss, tmp, '=');
    95         std::string key = trim(tmp);
    96         getline(ss, tmp);
    97         std::string value = trim(tmp);
    98         if (key=="trac-root")
    99           trac_root_=value;
     115        if (lhs=="trac-root")
     116          trac_root_=rhs;
    100117        else {
    101118          std::stringstream mess;
    102119          mess << "svndigest: invalid config file: "
    103                << "in trac section" << key + " is invalid option.";
     120               << "in trac section" << lhs + " is invalid option.";
    104121          throw std::runtime_error(mess.str());
    105122        }
     123      }
     124      else if (section == "copyright")
     125        if (lhs=="missing-copyright-warning")
     126          if (equal_false(rhs))
     127            missing_copyright_warning_ = false;
     128          else if (equal_true(rhs))
     129            missing_copyright_warning_ = true;
     130          else {
     131            std::stringstream mess;
     132            mess << "svndigest: invalid config file: "
     133                 << "line: `" << line << "' is invalid.";
     134            throw std::runtime_error(mess.str());
     135          }
    106136      }
    107137    }
     
    117147
    118148
     149  bool Configuration::missing_copyright_warning(void) const
     150  {
     151    return missing_copyright_warning_;
     152  }
     153
     154
    119155  void Configuration::set_default(void)
    120156  {
    121157    copyright_alias_.clear();
     158    missing_copyright_warning_=false;
    122159    trac_root_ = "";
    123160  }
     
    133170  {
    134171    os << "### This file configures various behaviors for svndigest\n"
    135        << "### The commented-out below are intended to demonstrate how to use\n" 
     172       << "### The commented-out below are intended to demonstrate how to use\n"
    136173       << "### this file.\n"
    137174       << "\n"
     175       << "### Section for setting behaviour of copyright update\n"
     176       << "[copyright]\n"
     177       << "# if true svndigest will warn if file has no copyright statement.\n"
     178       << "missing-copyright-warning = ";
     179   
     180    if (conf.missing_copyright_warning())
     181      os << "yes\n";
     182    else
     183      os << "no\n";
     184
     185    os << "\n"
    138186       << "### Section for setting aliases used in copyright update\n"
    139187       << "[copyright-alias]\n"
  • trunk/lib/Configuration.h

    r439 r446  
    4444    static Configuration& instance(void);
    4545
     46    ///
     47    /// @brief Aliases for Copyright
     48    ///
     49    const std::map<std::string, Alias>& copyright_alias(void) const;
     50
    4651    ///
    4752    /// @brief load deafult configuration
     
    5762
    5863    ///
    59     /// @brief Aliases for Copyright
     64    /// @return true if we should warn about missing copyright statement
    6065    ///
    61     const std::map<std::string, Alias>& copyright_alias(void) const;
     66    bool  missing_copyright_warning(void) const;
    6267
    6368    ///
     
    8186    void clear(void);
    8287
     88    bool equal_false(const std::string&) const;
     89    bool equal_true(const std::string&) const;
     90
    8391    void set_default(void);
    8492
     
    8795    std::map<std::string, Alias> copyright_alias_;
    8896
     97    bool missing_copyright_warning_;
    8998    std::string trac_root_;
    9099  };
  • trunk/lib/File.cc

    r445 r446  
    2525
    2626#include "Alias.h"
     27#include "Configuration.h"
    2728#include "Date.h"
    2829#include "GnuplotFE.h"
     
    8081        year_authors[timeinfo->tm_year].insert(a);
    8182        std::cerr << "svndigest: warning: no copyright alias found for `"
    82                   << *author << "`\n";
     83                  << *author << "'\n";
    8384        // insert alias to avoid multiple warnings.
    8485        alias.insert(name, std::make_pair(*author, a));
     
    267268    size_t end_line=0;
    268269    std::string prefix;
    269     if (!detect_copyright(old_block, start_line, end_line, prefix))
     270    if (!detect_copyright(old_block, start_line, end_line, prefix)){
     271      if (Configuration::instance().missing_copyright_warning())
     272        std::cerr << "svndigest: warning: no copyright statement found in `"
     273                  << path_ << "'\n";
    270274      return;
     275    }
    271276    std::map<int, std::set<Alias> > map=copyright_map(alias);
    272277    std::string new_block = copyright_block(map, prefix);
Note: See TracChangeset for help on using the changeset viewer.