Ignore:
Timestamp:
Jun 13, 2010, 7:28:19 PM (11 years ago)
Author:
Peter Johansson
Message:

merge trunk to src-highlight

Location:
branches/src-highlight
Files:
7 deleted
77 edited
8 copied

Legend:

Unmodified
Added
Removed
  • branches/src-highlight

  • branches/src-highlight/lib/AddStats.cc

    r803 r1100  
    22
    33/*
    4   Copyright (C) 2008, 2009 Peter Johansson
     4  Copyright (C) 2005 Peter Johansson
     5  Copyright (C) 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
     6  Copyright (C) 2009, 2010 Peter Johansson
    57
    68  This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    7577
    7678
     79  unsigned int AddStats::max_element(const std::vector<unsigned int>& v) const
     80  {
     81    assert(v.size());
     82    return v.back();
     83  }
     84
     85
    7786}} // end of namespace svndigest and namespace theplu
  • branches/src-highlight/lib/AddStats.h

    r693 r1100  
    55
    66/*
    7   Copyright (C) 2008 Peter Johansson
     7  Copyright (C) 2005 Peter Johansson
     8  Copyright (C) 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
     9  Copyright (C) 2010 Peter Johansson
    810
    911  This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    4345  private:
    4446    void do_parse(const std::string&, svn_revnum_t);
     47    unsigned int max_element(const std::vector<unsigned int>&) const;
    4548
    4649  };
  • branches/src-highlight/lib/Alias.cc

    r768 r1100  
    22
    33/*
    4   Copyright (C) 2007, 2008 Peter Johansson
     4  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
    55
    66  This file is part of svndigest, http://dev.thep.lu.se/svndigest
  • branches/src-highlight/lib/Alias.h

    r768 r1100  
    55
    66/*
    7   Copyright (C) 2007, 2008 Peter Johansson
     7  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
    88
    99  This file is part of svndigest, http://dev.thep.lu.se/svndigest
  • branches/src-highlight/lib/BlameStats.cc

    r818 r1100  
    33/*
    44  Copyright (C) 2005 Peter Johansson
    5   Copyright (C) 2006, 2007 Jari Häkkinen, Peter Johansson
    6   Copyright (C) 2009 Peter Johansson
     5  Copyright (C) 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
     6  Copyright (C) 2009, 2010 Peter Johansson
    77
    88  This file is part of svndigest, http://dev.thep.lu.se/svndigest
  • branches/src-highlight/lib/BlameStats.h

    r693 r1100  
    66/*
    77  Copyright (C) 2005 Peter Johansson
    8   Copyright (C) 2006 Jari Häkkinen, Peter Johansson
    9   Copyright (C) 2007 Peter Johansson
     8  Copyright (C) 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
     9  Copyright (C) 2010 Peter Johansson
    1010
    1111  This file is part of svndigest, http://dev.thep.lu.se/svndigest
  • branches/src-highlight/lib/ClassicStats.cc

    r803 r1100  
    33/*
    44  Copyright (C) 2005 Peter Johansson
    5   Copyright (C) 2006, 2007 Jari Häkkinen, Peter Johansson
     5  Copyright (C) 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
     6  Copyright (C) 2009, 2010 Peter Johansson
    67
    78  This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    7374
    7475
     76  unsigned int
     77  ClassicStats::max_element(const std::vector<unsigned int>& v) const
     78  {
     79    assert(v.size());
     80    return v.back();
     81  }
     82
    7583}} // end of namespace svndigest and namespace theplu
  • branches/src-highlight/lib/ClassicStats.h

    r693 r1100  
    66/*
    77  Copyright (C) 2005 Peter Johansson
    8   Copyright (C) 2006 Jari Häkkinen, Peter Johansson
    9   Copyright (C) 2007 Peter Johansson
     8  Copyright (C) 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
     9  Copyright (C) 2010 Peter Johansson
    1010
    1111  This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    4545  private:
    4646    void do_parse(const std::string&, svn_revnum_t);
     47    unsigned int max_element(const std::vector<unsigned int>&) const;
    4748
    4849  };
  • branches/src-highlight/lib/Commitment.cc

    r768 r1100  
    22
    33/*
    4   Copyright (C) 2007, 2008 Peter Johansson
     4  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
    55
    66  This file is part of svndigest, http://dev.thep.lu.se/svndigest
  • branches/src-highlight/lib/Commitment.h

    r768 r1100  
    55
    66/*
    7   Copyright (C) 2007, 2008 Peter Johansson
     7  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
     8  Copyright (C) 2009 Peter Johansson
    89
    910  This file is part of svndigest, http://dev.thep.lu.se/svndigest
  • branches/src-highlight/lib/Configuration.cc

    r818 r1100  
    22
    33/*
    4   Copyright (C) 2007, 2008 Peter Johansson
    5   Copyright (C) 2008 Jari Häkkinen
     4  Copyright (C) 2007, 2008, 2009, 2010 Jari Häkkinen, Peter Johansson
    65
    76  This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    2120*/
    2221
     22#include <config.h>
     23
    2324#include "Configuration.h"
    2425
     26#include "Colors.h"
    2527#include "Functor.h"
    2628
     
    6163
    6264
     65  const std::map<std::string, std::string>&
     66  Configuration::author_colors(void) const
     67  {
     68    return author_color_;
     69  }
     70
    6371  std::string Configuration::author_str_color(const std::string& author) const
    6472  {
     
    7886    for (String2Codons::const_iterator i(string2codons_.begin());
    7987         i!=string2codons_.end(); ++i) {
    80       if (svndigest::equal(file_name.begin(), file_name.end(),
    81                            i->first.begin(), i->first.end()) ) {
     88      if (fnmatch(i->first.c_str(), file_name.c_str()))
    8289        return &i->second;
    83       }
    8490    }
    8591    return NULL;
     
    97103  {
    98104    for (size_t i=0; i<dictionary_.size(); ++i)
    99       if (svndigest::equal(lhs.begin(), lhs.end(),
    100                            dictionary_[i].first.begin(),
    101                            dictionary_[i].first.end()))
     105      if (fnmatch(lhs.c_str(), dictionary_[i].first.c_str()))
    102106        return &dictionary_[i];
    103107    return NULL;
     
    119123
    120124
     125  const std::string& Configuration::image_anchor_format(void) const
     126  {
     127    return image_anchor_format_;
     128  }
     129
     130
     131  const std::string& Configuration::image_format(void) const
     132  {
     133    return image_format_;
     134  }
     135
     136
    121137  void Configuration::load(void)
    122138  {
     
    129145  {
    130146    assert(is.good());
    131     set_default();
    132147
    133148    bool parsing_found=false;
     
    188203      }
    189204      else if (section == "author-color") {
     205        unsigned char r,g,b;
     206        try {
     207          str2rgb(rhs, r,g,b);
     208        }
     209        catch (std::runtime_error& e) {
     210          throw Config_error(line, e.what());
     211        }
    190212        author_color_[lhs] = rhs;
    191213      }     
     
    203225          for (String2Codons::const_iterator i(string2codons_.begin());
    204226               i!=string2codons_.end(); ++i) {
    205             if (svndigest::equal(lhs.begin(), lhs.end(),
    206                                  i->first.begin(), i->first.end()) ) {
     227            if (fnmatch(lhs.c_str(), i->first.c_str())) {
    207228              mess << "`" << i->first << "'";
    208229              break;
     
    269290        }
    270291      }
     292      else if (section == "image") {
     293        if (lhs == "format") {
     294          try {
     295            image_format(rhs);
     296          }
     297          catch (std::runtime_error e) {
     298            throw Config_error(line,
     299                               "unknown format: " + rhs + "\n" + e.what());
     300          }
     301        }
     302        else if (lhs == "image_format") {
     303          try {
     304            image_anchor_format(rhs);
     305          }
     306          catch (std::runtime_error e) {
     307            throw Config_error(line,
     308                               "unknown format: " + rhs + "\n" + e.what());
     309          }
     310        }
     311      }
    271312    }
    272313    validate_dictionary();
     314  }
     315
     316
     317  void Configuration::image_anchor_format(const std::string& format)
     318  {
     319    if (format!="none" && format!="pdf" && format!="png" && format!="svg") {
     320      std::ostringstream oss;
     321      oss << "Valid arguments are:\n"
     322          << "  - `none'\n"
     323          << "  - `pdf'\n"
     324          << "  - `png'\n"
     325          << "  - `svg'";
     326      throw std::runtime_error(oss.str());
     327    }
     328    image_anchor_format_ = format;
     329  }
     330
     331
     332  void Configuration::image_format(const std::string& format)
     333  {
     334    if (format!="none" && format!="png" && format!="svg") {
     335      std::ostringstream oss;
     336      oss << "Valid arguments are:\n"
     337          << "  - `none'\n"
     338          << "  - `png'\n"
     339          << "  - `svg'";
     340      throw std::runtime_error(oss.str());
     341    }
     342    image_format_ = format;
    273343  }
    274344
     
    294364                           const std::pair<std::string, std::string>& dic) const
    295365  {
    296     assert(svndigest::equal(str.begin(), str.end(),
    297                             dic.first.begin(), dic.first.end()));
    298366    std::string res;
    299367    std::vector<std::string> vec;
    300     regexp(str.begin(), str.end(), dic.first.begin(), dic.first.end(), vec);
     368    if (!regexp(dic.first, str, vec)) {
     369      std::stringstream mess;
     370      mess << "invalid config file: "
     371           << "expression " << dic.first << " is invalid";
     372      throw std::runtime_error(mess.str());       
     373    }
    301374    for (std::string::const_iterator i(dic.second.begin());
    302375         i!=dic.second.end(); ++i) {
     
    307380        if (n>vec.size() || n==0){
    308381          std::stringstream mess;
    309           mess << "svndigest: invalid config file: "
     382          mess << "invalid config file: "
    310383               << "expression " << dic.second << " is invalid";
    311384          if (n)
    312385            mess << "because " << n << " is a too large.";
    313           throw std::runtime_error("");       
     386          throw std::runtime_error(mess.str());       
    314387        }
    315388        res += vec[n-1];
     
    366439    add_codon("*.ac", "dnl", "\n");
    367440    add_codon("*.am", "#", "\n");
    368     add_codon("*.m4", "#", "\n");
    369     add_codon("*.m4", "dnl", "\n");
     441    add_codon("*.as", "#", "\n");
     442    add_codon("*.as", "dnl", "\n");
     443    add_codon("*.bat", "\nREM", "\n");
     444    add_codon("*.bat", "\nrem", "\n");
    370445    add_codon("*.c", "//", "\n");
    371446    add_codon("*.c", "/*", "*/");
     
    374449    add_codon("*.cpp", "//", "\n");
    375450    add_codon("*.cpp", "/*", "*/");
     451    add_codon("*.css", "<!--", "-->");
    376452    add_codon("*.cxx", "//", "\n");
    377453    add_codon("*.cxx", "/*", "*/");
     
    382458    add_codon("*.hpp", "//", "\n");
    383459    add_codon("*.hpp", "/*", "*/");
     460    add_codon("*.html", "<%--", "--%>");
    384461    add_codon("*.java", "//", "\n");
    385462    add_codon("*.java", "/*", "*/");
     463    add_codon("*.jsp", "<!--", "-->");
     464    add_codon("*.m", "%", "\n");
     465    add_codon("*.m4", "#", "\n");
     466    add_codon("*.m4", "dnl", "\n");
    386467    add_codon("*.pl", "#", "\n");
    387468    add_codon("*.pm", "#", "\n");
     469    add_codon("*.R", "#", "\n");
     470    add_codon("*.rss", "<!--", "-->");
     471    add_codon("*.sgml", "<!--", "-->");
    388472    add_codon("*.sh", "#", "\n");
     473    add_codon("*.shtml", "<!--", "-->");
     474    add_codon("*.tex", "%", "\n");
     475    add_codon("*.xhtml", "<!--", "-->");
     476    add_codon("*.xml", "<!--", "-->");
     477    add_codon("*.xsd", "<!--", "-->");
     478    add_codon("*.xsl", "<!--", "-->");
    389479    add_codon("*config", "#", "\n");
    390480    add_codon("bootstrap", "#", "\n");
    391481    add_codon("Makefile", "#", "\n");
    392     add_codon("*.tex", "%", "\n");
    393     add_codon("*.m", "%", "\n");
    394     add_codon("*.jsp", "<!--", "-->");
    395     add_codon("*.html", "<%--", "--%>");
    396     add_codon("*.xml", "<!--", "-->");
    397     add_codon("*.xsl", "<!--", "-->");
    398     add_codon("*.xsd", "<!--", "-->");
    399     add_codon("*.xhtml", "<!--", "-->");
    400     add_codon("*.shtml", "<!--", "-->");
    401     add_codon("*.xml", "<!--", "-->");
    402     add_codon("*.css", "<!--", "-->");
    403     add_codon("*.rss", "<!--", "-->");
    404     add_codon("*.sgml", "<!--", "-->");
    405     add_codon("*.bat", "\nREM", "\n");
    406     add_codon("*.bat", "\nrem", "\n");
    407482
    408483    dictionary_ = VectorPair(1, std::make_pair("*.in", "$1"));
     484    image_format_ = "png";
     485    image_anchor_format_ = "png";
    409486  }
    410487
     
    463540
    464541    for (vector::const_iterator i(vec.begin()); i!=vec.end(); ++i) {
    465       os << i->first << " = " << i->second.name() << " \n";
     542      os << i->first << " = " << i->second.name() << "\n";
    466543    }
    467544
    468545    os << "\n"
    469        << "### Section for author color in blame output\n"
     546       << "### Section for images\n"
     547       << "[image]\n"
     548       << "format = " << conf.image_format() << "\n";
     549    os << "anchor_format = " << conf.image_anchor_format() << "\n";
     550
     551
     552    os << "\n"
     553       << "### Section for author color in plots and blame output.\n"
    470554       << "[author-color]\n"
    471555       << "# jdoe = 000000\n";
     
    473557    for (str_map::const_iterator i(conf.author_color_.begin());
    474558         i!=conf.author_color_.end(); ++i) {
    475       os << i->first << " = " << i->second << " \n";
     559      os << i->first << " = " << i->second << "\n";
    476560    }
    477561
  • branches/src-highlight/lib/Configuration.h

    r815 r1100  
    55
    66/*
    7   Copyright (C) 2007, 2008 Peter Johansson
     7  Copyright (C) 2007, 2008, 2009 Jari Häkkinen, Peter Johansson
     8  Copyright (C) 2010 Peter Johansson
    89
    910  This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    4546
    4647    /**
    47        \return hexadecimal color code (e.g. 5aee4a) that is used in
    48        blame output. If no color is configured for \a author, an empty
    49        string is returned.
     48       \return Hexadecimal color code (e.g. 5aee4a) that is used in
     49       blame output and as line colors in plots. If no color is
     50       configured for \a author, an empty string is returned.
    5051     */
    5152    std::string author_str_color(const std::string& author) const;
     53
     54    /**
     55       The map to lookup the author-color mapping set in the
     56       configuration file. The color code is a six digit hexadecimal
     57       number rrggbb.
     58
     59       \return The author-color map
     60    */
     61    const std::map<std::string, std::string>& author_colors(void) const;
    5262
    5363    /**
     
    6171    ///
    6272    const std::map<std::string, Alias>& copyright_alias(void) const;
     73
     74    /**
     75       \return pdf, png, none, or svg
     76     */
     77    const std::string& image_anchor_format(void) const;
     78
     79    /**
     80       \brief set image_anchor_format
     81     */
     82    void image_anchor_format(const std::string&);
     83
     84    /**
     85       \return png, none, svg, or svgz
     86     */
     87    const std::string& image_format(void) const;
     88
     89    /**
     90       \brief set image_format
     91     */
     92    void image_format(const std::string&);
    6393
    6494    ///
     
    111141       Translate string \a str using dictionary \a dict
    112142
    113        \note \a str must be equal to d.first (see function equal),
     143       \note \a str must be equal to d.first (see regexp(5)),
    114144       or behavior is unspecified.
    115145
     
    134164
    135165    VectorPair dictionary_;
    136 
     166    std::string image_anchor_format_;
     167    std::string image_format_;
    137168    std::string trac_root_;
    138169  };
  • branches/src-highlight/lib/Date.cc

    r768 r1100  
    22
    33/*
    4   Copyright (C) 2007 Peter Johansson
    5   Copyright (C) 2008 Jari Häkkinen, Peter Johansson
     4  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
    65  Copyright (C) 2009 Peter Johansson
    76
  • branches/src-highlight/lib/Date.h

    r768 r1100  
    55
    66/*
    7   Copyright (C) 2007, 2008 Peter Johansson
     7  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
    88
    99  This file is part of svndigest, http://dev.thep.lu.se/svndigest
  • branches/src-highlight/lib/Directory.cc

    r834 r1100  
    22
    33/*
    4   Copyright (C) 2005, 2006, 2007 Jari Häkkinen, Peter Johansson
    5   Copyright (C) 2009 Peter Johansson
     4  Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Jari Häkkinen, Peter Johansson
    65
    76  This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    2423
    2524#include "Alias.h"
     25#include "Configuration.h"
    2626#include "File.h"
    2727#include "html_utility.h"
     
    3939#include <list>
    4040#include <map>
     41#include <sstream>
    4142
    4243#include <cerrno> // Needed to check error state below.
     
    148149  void Directory::print_core(const bool verbose) const
    149150  {
    150     mkdir("blame_output/" + local_path_);
     151    mkdir("blame_output/" + local_path());
    151152    // print daughter nodes
    152153    for (NodeConstIterator i=daughters_.begin(); i!=daughters_.end(); ++i)
     
    162163
    163164    const Stats& stats = stats_[stats_type];
    164     std::string outdir = stats_type+"/"+user+"/"+line_type+"/"+local_path_;
    165     if (local_path_=="")
    166       outdir = stats_type+"/"+user+"/"+line_type;
    167 
     165    std::string imagedir = stats_type+"/"+"images/"+line_type;
     166    std::string outdir   = stats_type+"/"+user+"/" +line_type;
     167    if (local_path()!="") {
     168      imagedir += "/"+local_path();
     169      outdir   += "/"+local_path();
     170    }
    168171    mkdir(outdir);
    169     std::string imagedir = stats_type+"/"+"images/"+line_type+"/"+local_path_;
    170172    if (user=="all")
    171173      mkdir(imagedir);
     
    180182                   local_path()+"/index.html", stats_type);
    181183    path_anchor(os);
    182     os << "<p class=\"plot\">\n<img src='";
     184
     185    std::stringstream ss;
    183186    for (size_t i=0; i<level_; ++i)
    184       os << "../";
    185     os << "../../../";
     187      ss << "../";
     188    ss << "../../../";
    186189    if (user=="all")
    187       os << stats.plot(imagedir+"/index.png", line_type);
     190      ss << stats.plot(imagedir+"/index", line_type);
    188191    else
    189       os << imagedir << "/index.png";
    190     os << "' alt='[plot]' /></p>\n";
     192      ss << imagedir << "/index";
     193    os << "<p class=\"plot\">\n";
     194    os << image(ss.str());
     195    os << "</p>\n";
     196
    191197    os << "<h3>File Summary";
    192198    if (user!="all")
  • branches/src-highlight/lib/Directory.h

    r834 r1100  
    55
    66/*
    7   Copyright (C) 2005, 2006, 2007 Jari Häkkinen, Peter Johansson
     7  Copyright (C) 2005, 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
    88  Copyright (C) 2009 Peter Johansson
    99
  • branches/src-highlight/lib/File.cc

    r834 r1100  
    22
    33/*
    4   Copyright (C) 2005, 2006, 2007 Jari Häkkinen, Peter Johansson
    5   Copyright (C) 2009 Peter Johansson
     4  Copyright (C) 2005, 2006, 2007, 2008, 2009 Jari Häkkinen, Peter Johansson
     5  Copyright (C) 2010 Peter Johansson
    66
    77  This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    2424
    2525#include "Alias.h"
     26#include "Colors.h"
    2627#include "Configuration.h"
    2728#include "Date.h"
    28 #include "GnuplotFE.h"
     29#include "Graph.h"
    2930#include "html_utility.h"
    3031#include "HtmlStream.h"
     
    4243#include <stdexcept>
    4344#include <string>
     45#include <sstream>
    4446#include <sys/stat.h>
    4547
     
    8284        ++rev_iter;
    8385      }
     86      // do not go beyond BASE rev of file
     87      last_rev_this_year = std::min(last_rev_this_year, last_changed_rev());
     88      last_rev_last_year = std::min(last_rev_last_year, last_changed_rev());
    8489      // loop over authors
    8590      for (std::set<std::string>::const_iterator a_iter=stats.authors().begin();
     
    103108            Alias a(*a_iter,alias.size());
    104109            year_authors[rev_iter->first].insert(a);
    105             std::cerr << "svndigest: warning: no copyright alias found for `"
     110            std::cerr << "svncopyright: warning: no copyright alias found for `"
    106111                      << *a_iter << "'\n";
    107112            // insert alias to avoid multiple warnings.
     
    258263    int first=0;
    259264    bool using_dates=true;
    260     if (GnuplotFE::instance()->dates().empty()){
     265    if (!Graph::date_xticks()) {
    261266      using_dates=false;
    262267      last = stats_["classic"].revision();
    263268    }
    264269    else {
    265       last = Date(GnuplotFE::instance()->dates().back()).seconds();
     270      last = Date(Graph::xticks().back()).seconds();
    266271      // earliest date corresponds either to revision 0 or revision 1
    267       first = std::min(Date(GnuplotFE::instance()->dates()[0]).seconds(),
    268                        Date(GnuplotFE::instance()->dates()[1]).seconds());
     272      first = std::min(Date(Graph::xticks()[0]).seconds(),
     273                       Date(Graph::xticks()[1]).seconds());
    269274    }
    270275    // color is calculated linearly on time, c = kt + m
     
    287292      hs << Date(blame.date())("%d %b %y");
    288293      os << "</font></td>\n<td class=\"author\">";
    289       std::string author_color =
    290         Configuration::instance().author_str_color(blame.author());
    291       if (!author_color.empty())
    292         os << "<font color=\"#" << author_color << "\">";
     294      const std::string& author_color =
     295        Colors::instance().color_str(blame.author());
     296      assert(!author_color.empty());
     297      os << "<font color=\"#" << author_color << "\">";
    293298      hs << blame.author();
    294299      os << "</td>\n<td class=\"";
     
    330335    if (!detect_copyright(old_block, start_line, end_line, prefix)){
    331336      if (Configuration::instance().missing_copyright_warning())
    332         std::cerr << "svndigest: warning: no copyright statement found in `"
     337        std::cerr << "svncopyright: warning: no copyright statement found in `"
    333338                  << path_ << "'\n";
    334339      return;
     
    363368      lpath = "index";
    364369    std::string outpath = stats_type+"/"+user+"/"+line_type+"/"+lpath;
    365     std::string imagefile = stats_type+"/"+"images/"+line_type+"/"+
    366       lpath+".png";
     370    std::string imagefile = stats_type+"/"+"images/"+line_type+"/"+lpath;
    367371    std::string html_name(outpath + ".html");
    368372    std::ofstream os(html_name.c_str());
     
    370374                 stats_type);
    371375    path_anchor(os);
    372     os << "<p class=\"plot\">\n<img src='";
     376
     377    std::stringstream ss;
    373378    for (size_t i=0; i<level_; ++i)
    374       os << "../";
    375     os << "../../../";
     379      ss << "../";
     380    ss << "../../../";
    376381    if (user=="all")
    377       os << stats_[stats_type].plot(imagefile,line_type);
     382      ss << stats_[stats_type].plot(imagefile,line_type);
    378383    else
    379       os << imagefile;
    380     os << "' alt='[plot]' />\n</p>";
     384      ss << imagefile;
     385    os << "<p class=\"plot\">\n";
     386    os << image(ss.str());
     387    os << "</p>\n";
    381388
    382389    print_author_summary(os, stats_[stats_type], line_type, log);
     
    443450    catch (std::runtime_error e) {
    444451      // catch exception, cleanup, and rethrow
    445       std::cerr << "svndigest: File::print_copyright: Exception caught, "
     452      std::cerr << "svncopyright: File::print_copyright: Exception caught, "
    446453                << "removing temporary file " << tmpname << std::endl;
    447454      if (unlink(tmpname))
  • branches/src-highlight/lib/File.h

    r834 r1100  
    55
    66/*
    7   Copyright (C) 2005, 2006, 2007 Jari Häkkinen, Peter Johansson
     7  Copyright (C) 2005, 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
    88  Copyright (C) 2009 Peter Johansson
    99
  • branches/src-highlight/lib/Functor.cc

    r693 r1100  
    22
    33/*
    4   Copyright (C) 2006, 2007 Jari Häkkinen, Peter Johansson
     4  Copyright (C) 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
    55
    66  This file is part of svndigest, http://dev.thep.lu.se/svndigest
  • branches/src-highlight/lib/Functor.h

    r727 r1100  
    55
    66/*
    7   Copyright (C) 2005, 2006, 2007 Jari Häkkinen, Peter Johansson
    8   Copyright (C) 2008 Jari Häkkinen
     7  Copyright (C) 2005 Peter Johansson
     8  Copyright (C) 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
    99
    1010  This file is part of svndigest, http://dev.thep.lu.se/svndigest
  • branches/src-highlight/lib/HtmlBuf.cc

    r693 r1100  
    22
    33/*
    4   Copyright (C) 2007 Jari Häkkinen, Peter Johansson
    5   Copyright (C) 2008 Peter Johansson
     4  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
     5  Copyright (C) 2009 Peter Johansson
    66
    77  This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    3333    : std::streambuf(), buf_(buf)
    3434  {
    35     map_['"']=std::string("\"");
     35    map_['"']=std::string("&quot;");
    3636    map_['\'']=std::string("\'");
    3737    map_['\n']=std::string("<br />");
     
    4242    // This should be configurable, but for now indentation is two spaces.
    4343    map_['\t']=std::string("&nbsp;&nbsp;");
    44     map_['å']=std::string("&aring;");
    45     map_['ä']=std::string("&auml;");
    46     map_['ö']=std::string("&ouml;");
    47     map_['Å']=std::string("&Aring;");
    48     map_['Ä']=std::string("&Auml;");
    49     map_['Ö']=std::string("&Ouml;");
    50     map_['é']=std::string("&eacute;");
    51     map_['É']=std::string("&Eacute;");
    52     map_['á']=std::string("&aacute;");
    53     map_['Á']=std::string("&Aacute;");
    5444  }
    5545
  • branches/src-highlight/lib/HtmlBuf.h

    r693 r1100  
    55
    66/*
    7   Copyright (C) 2007, 2008 Peter Johansson
     7  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
    88
    99  This file is part of svndigest, http://dev.thep.lu.se/svndigest
  • branches/src-highlight/lib/HtmlStream.cc

    r768 r1100  
    22
    33/*
    4   Copyright (C) 2007 Jari Häkkinen, Peter Johansson
    5   Copyright (C) 2008 Peter Johansson
     4  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
    65
    76  This file is part of svndigest, http://dev.thep.lu.se/svndigest
  • branches/src-highlight/lib/HtmlStream.h

    r768 r1100  
    55
    66/*
    7   Copyright (C) 2007, 2008 Peter Johansson
     7  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
    88
    99  This file is part of svndigest, http://dev.thep.lu.se/svndigest
  • branches/src-highlight/lib/LineTypeParser.cc

    r693 r1100  
    22
    33/*
    4   Copyright (C) 2006, 2007 Jari Häkkinen, Peter Johansson
     4  Copyright (C) 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
     5  Copyright (C) 2009 Peter Johansson
    56
    67  This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    4041    : mode_(0), post_copyright_(false), copyright_found_(false)
    4142  {
    42     codon_ = Configuration::instance().codon(path);
     43    codon_ = Configuration::instance().codon(file_name(path));
    4344  }
    4445
  • branches/src-highlight/lib/LineTypeParser.h

    r802 r1100  
    55
    66/*
    7   Copyright (C) 2006 Jari Häkkinen, Peter Johansson
    8   Copyright (C) 2007, 2009 Peter Johansson
     7  Copyright (C) 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
     8  Copyright (C) 2009 Peter Johansson
    99
    1010  This file is part of svndigest, http://dev.thep.lu.se/svndigest
  • branches/src-highlight/lib/Makefile.am

    r838 r1100  
    44
    55# Copyright (C) 2005 Jari Häkkinen
    6 # Copyright (C) 2006 Jari Häkkinen, Peter Johansson
    7 # Copyright (C) 2007, 2008 Peter Johansson
    8 # Copyright (C) 2008 Jari Häkkinen, Peter Johansson
    9 # Copyright (C) 2009 Peter Johansson
     6# Copyright (C) 2006, 2007, 2008, 2009 Jari Häkkinen, Peter Johansson
     7# Copyright (C) 2010 Peter Johansson
    108#
    119# This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    2927SUBDIRS = yat .
    3028
    31 AM_CPPFLAGS = $(SVNDIGEST_CPPFLAGS)
    32 AM_CXXFLAGS = $(SVNDIGEST_CXXFLAGS)
     29AM_CPPFLAGS = $(DEFAULT_CPPFLAGS) $(APR_CPPFLAGS) $(SVN_CPPFLAGS) \
     30  $(PLPLOT_CPPFLAGS)
     31AM_CXXFLAGS = $(DEFAULT_CXXFLAGS)
    3332
    3433noinst_LIBRARIES = libsvndigest.a
    3534
    3635noinst_HEADERS = AddStats.h Alias.h BlameStats.h ClassicStats.h \
    37   Commitment.h Configuration.h copyright_year.h css.h\
     36  Colors.h Commitment.h Configuration.h css.h \
    3837  Date.h Directory.h File.h first_page.h Functor.h \
    39   Gnuplot.h GnuplotFE.h \
     38  Graph.h \
    4039  HtmlBuf.h HtmlStream.h html_utility.h LineTypeParser.h \
    41   Node.h
     40  main_utility.h Node.h \
    4241  OptionVersion.h rmdirhier.h \
    4342  Stats.h StatsCollection.h subversion_info.h SVN.h SVNblame.h  \
     
    4544
    4645libsvndigest_a_SOURCES = AddStats.cc Alias.cc BlameStats.cc \
    47   ClassicStats.cc \
    48   Commitment.cc Configuration.cc copyright_year.cc \
     46  ClassicStats.cc Colors.cc \
     47  Commitment.cc Configuration.cc \
    4948  css.cc Date.cc Directory.cc File.cc first_page.cc\
    50   Functor.cc Gnuplot.cc GnuplotFE.cc  HtmlBuf.cc HtmlStream.cc \
    51   html_utility.cc LineTypeParser.cc Node.cc \
     49  Functor.cc Graph.cc HtmlBuf.cc HtmlStream.cc \
     50  html_utility.cc LineTypeParser.cc main_utility.cc Node.cc \
    5251  OptionVersion.cc \
    5352  rmdirhier.cc Stats.cc StatsCollection.cc subversion_info.cc SVN.cc \
     
    7271  $(srcdir)/subversion_info.cc.in >> $@ ;
    7372
    74 # update copyright year automatically (if we build from svn wc)
    75 $(srcdir)/copyright_year.cc: copyright_year.cc.tmp
    76   @$(MOVE_IF_CHANGE) copyright_year.cc.tmp $@
    77 
    78 copyright_year.cc.tmp: FORCE
    79   @if (echo $(SVN_REVISION) | $(GREP) M); then \
    80     $(SED) -e 's/"20[0-9][0-9]"/'\"`date -u "+%Y"`\"'/g' \
    81       $(srcdir)/copyright_year.cc > $@ ; \
    82   else \
    83     cp $(srcdir)/copyright_year.cc $@; \
    84   fi
    85 
    8673else
    8774# this is needed in 'svn export' build
  • branches/src-highlight/lib/Node.cc

    r834 r1100  
    22
    33/*
    4   Copyright (C) 2005, 2006, 2007 Jari Häkkinen, Peter Johansson
    5   Copyright (C) 2008 Jari Häkkinen
     4  Copyright (C) 2005, 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
    65  Copyright (C) 2009 Peter Johansson
    76
  • branches/src-highlight/lib/Node.h

    r834 r1100  
    55
    66/*
    7   Copyright (C) 2005, 2006, 2007 Jari Häkkinen, Peter Johansson
     7  Copyright (C) 2005, 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
    88  Copyright (C) 2009 Peter Johansson
     9  Copyright (C) 2010 Jari Häkkinen
    910
    1011  This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    208209
    209210    unsigned int level_;
    210     std::string local_path_; // path from root
    211211    std::string output_dir_;
    212212    std::string path_; // absolute path
     
    235235    bool binary_;
    236236    bool link_;
     237    std::string local_path_; // path from root
    237238    mutable SVNlog* log_;
    238239    bool svndigest_ignore_;
  • branches/src-highlight/lib/OptionVersion.cc

    r795 r1100  
    22
    33/*
    4   Copyright (C) 2008, 2009 Peter Johansson
     4  Copyright (C) 2008, 2009, 2010 Peter Johansson
    55
    66  This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    2222#include <config.h>
    2323
    24 #include "copyright_year.h"
    2524#include "OptionVersion.h"
    2625#include "subversion_info.h"
     
    3433#include <apr_version.h>
    3534
     35#include <cstdlib>
     36#include <iostream>
    3637#include <sstream>
    3738#include <string>
     
    5253    yat::utility::ColumnStream cs(std::cout, 1);
    5354    cs.width(0)=79;
    54     cs << PACKAGE_NAME << " " << PACKAGE_VERSION;
     55    cs << prog_name_ << " " << PACKAGE_VERSION;
    5556    bool no_verbose = verbose_ && verbose_->present() && !verbose_->value();
    5657    if (!no_verbose) {
     
    6162         << ")";
    6263    }
    63     cs << "\n\nCopyright (C) " << svn_year()
     64    cs << "\n\nCopyright (C) " << RELEASE_YEAR
    6465       << " Jari H\u00E4kkinen and Peter Johansson.\n"
    6566       << "This is free software. You may redistribute copies of it under "
     
    7879      cs << apr_version_string();
    7980      cs << "\n";
     81      cs << extra_;
    8082    }
    81     exit(0);
     83    exit(EXIT_SUCCESS);
     84  }
     85
     86
     87  void OptionVersion::extra(const std::string& str)
     88  {
     89    extra_ = str;
     90  }
     91
     92
     93  void OptionVersion::program_name(const std::string& str)
     94  {
     95    prog_name_ = str;
    8296  }
    8397
  • branches/src-highlight/lib/OptionVersion.h

    r795 r1100  
    55
    66/*
    7   Copyright (C) 2008 Peter Johansson
     7  Copyright (C) 2008, 2009, 2010 Peter Johansson
    88
    9   This file is part of svndigest, http://trac.thep.lu.se/svndigest
     9  This file is part of svndigest, http://dev.thep.lu.se/svndigest
    1010
    1111  svndigest is free software; you can redistribute it and/or modify it
     
    5757                  OptionSwitch* const verbose=NULL);
    5858
     59    /**
     60       add extra string appended to output
     61     */
     62    void extra(const std::string&);
     63
     64    /**
     65       set program name
     66     */
     67    void program_name(const std::string&);
     68
     69    /**
     70       \brief set version string
     71    */
     72    void version(const std::string&);
     73
    5974  private:
    6075    OptionSwitch* const verbose_;
    61 
     76    std::string extra_;
     77    std::string prog_name_;
    6278
    6379    /**
  • branches/src-highlight/lib/SVN.cc

    r693 r1100  
    33/*
    44  Copyright (C) 2006 Jari Häkkinen
    5   Copyright (C) 2007 Jari Häkkinen, Peter Johansson
    6   Copyright (C) 2008 Peter Johansson
     5  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
    76
    87  This file is part of svndigest, http://dev.thep.lu.se/svndigest
  • branches/src-highlight/lib/SVN.h

    r800 r1100  
    66/*
    77  Copyright (C) 2006 Jari Häkkinen
    8   Copyright (C) 2007 Jari Häkkinen, Peter Johansson
    9   Copyright (C) 2008 Peter Johansson
     8  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
     9  Copyright (C) 2009 Peter Johansson
    1010
    1111  This file is part of svndigest, http://dev.thep.lu.se/svndigest
  • branches/src-highlight/lib/SVNblame.cc

    r768 r1100  
    33/*
    44  Copyright (C) 2006 Jari Häkkinen
    5   Copyright (C) 2007 Jari Häkkinen, Peter Johansson
    6   Copyright (C) 2008 Peter Johansson
     5  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
    76
    87  This file is part of svndigest, http://dev.thep.lu.se/svndigest
  • branches/src-highlight/lib/SVNblame.h

    r768 r1100  
    66/*
    77  Copyright (C) 2006 Jari Häkkinen
    8   Copyright (C) 2007 Jari Häkkinen, Peter Johansson
    9   Copyright (C) 2008 Peter Johansson
     8  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
    109
    1110  This file is part of svndigest, http://dev.thep.lu.se/svndigest
  • branches/src-highlight/lib/SVNinfo.cc

    r768 r1100  
    33/*
    44  Copyright (C) 2006 Jari Häkkinen
    5   Copyright (C) 2007 Jari Häkkinen, Peter Johansson
    6   Copyright (C) 2008 Peter Johansson
     5  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
    76
    87  This file is part of svndigest, http://dev.thep.lu.se/svndigest
  • branches/src-highlight/lib/SVNinfo.h

    r768 r1100  
    66/*
    77  Copyright (C) 2006 Jari Häkkinen
    8   Copyright (C) 2007 Jari Häkkinen, Peter Johansson
    9   Copyright (C) 2008 Peter Johansson
     8  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
    109
    1110  This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    109108    /// @see Subversion API documentation
    110109    ///
    111     // The return type should be svn_log_message_receiver_t but I
    112     // cannot get it to compile (see comment for log_message_receiver
    113     // in SVNlog.h)
    114110    static svn_error_t * info_receiver(void *baton, const char *path,
    115111                                       const svn_info_t *info, apr_pool_t *pool);
  • branches/src-highlight/lib/SVNlog.cc

    r768 r1100  
    33/*
    44  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
     5  Copyright (C) 2009 Peter Johansson
    56
    67  This file is part of svndigest, http://dev.thep.lu.se/svndigest
  • branches/src-highlight/lib/SVNlog.h

    r768 r1100  
    55
    66/*
    7   Copyright (C) 2007 Jari Häkkinen, Peter Johansson
    8   Copyright (C) 2008 Peter Johansson
     7  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
     8  Copyright (C) 2009 Peter Johansson
    99
    1010  This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    126126       \see Subversion API documentation
    127127    */
    128     // The return type should be svn_log_message_receiver_t but I
    129     // cannot get it to compile. The svn API has a typedef like
    130     // typedef svn_error_t*(* svn_log_message_receiver_t)(void *baton,
    131     // apr_hash_t *changed_paths, svn_revnum_t revision, const char
    132     // *author, const char *date,const char *message, apr_pool_t
    133     // *pool) for svn_log_message_receiver_t.
    134128    static svn_error_t*
    135129    log_message_receiver(void *baton, apr_hash_t *changed_paths,
  • branches/src-highlight/lib/SVNproperty.cc

    r768 r1100  
    33/*
    44  Copyright (C) 2006 Jari Häkkinen
    5   Copyright (C) 2007, 2008 Peter Johansson
     5  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
    66
    77  This file is part of svndigest, http://dev.thep.lu.se/svndigest
  • branches/src-highlight/lib/SVNproperty.h

    r768 r1100  
    66/*
    77  Copyright (C) 2006 Jari Häkkinen
    8   Copyright (C) 2007, 2008 Peter Johansson
     8  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
    99
    1010  This file is part of svndigest, http://dev.thep.lu.se/svndigest
  • branches/src-highlight/lib/Stats.cc

    r803 r1100  
    33/*
    44  Copyright (C) 2005 Peter Johansson
    5   Copyright (C) 2006, 2007 Jari Häkkinen, Peter Johansson
    6   Copyright (C) 2008, 2009 Peter Johansson
     5  Copyright (C) 2006, 2007, 2008, 2009 Jari Häkkinen, Peter Johansson
     6  Copyright (C) 2010 Peter Johansson
    77
    88  This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    2424#include "Stats.h"
    2525
     26#include "Colors.h"
     27#include "Configuration.h"
    2628#include "Functor.h"
    27 #include "GnuplotFE.h"
     29#include "Graph.h"
    2830#include "SVNblame.h"
    2931#include "SVNinfo.h"
     
    278280    std::string str;
    279281    getline(is, str);
    280     if (str!=cache_check_str())
     282    if (str!=cache_check_str()) {
     283      if (str == prev_cache_check_str())
     284        std::cout << "cache file is obsolete; "
     285                  << "retrieving statistics from repository.\n";
    281286      return 0;
     287    }
    282288    svn_revnum_t rev;
    283289    is >> rev;
     
    331337
    332338
     339  unsigned int Stats::max_element(const std::vector<unsigned int>& vec) const
     340  {
     341    return *std::max_element(vec.begin(), vec.end());
     342  }
     343
     344
    333345  void Stats::parse(const std::string& path, svn_revnum_t rev)
    334346  {
     
    349361  }
    350362
     363
    351364  std::string Stats::plot(const std::string& filename,
    352365                          const std::string& linetype) const
    353366  {
     367    const std::string& format = Configuration::instance().image_format();
     368    if (format=="none")
     369      return filename;
     370    plot(filename, linetype, format);
     371    const std::string& anchor_format =
     372      Configuration::instance().image_anchor_format();
     373
     374    if (format!=anchor_format)
     375      plot(filename, linetype, anchor_format);
     376    return filename;
     377  }
     378
     379
     380  void Stats::plot(const std::string& filename,
     381                   const std::string& linetype,
     382                   const std::string& format) const
     383  {
    354384    assert(total_stats().size());
    355     plot_init(filename);
    356     GnuplotFE* gp=GnuplotFE::instance();
     385    Graph gp(filename+"."+format, format);
    357386    const Author2Vector* stat=NULL;
    358387    if (linetype=="total")
     
    368397    assert(stat->find("all")!=stat->end());
    369398    std::vector<unsigned int> total=get_vector(*stat, "all");   
    370     double yrange_max=1.03*total.back()+1;
    371     gp->yrange(yrange_max);
     399    double yrange_max=1.03 * max_element(total) +1.0;
     400    gp.ymax(yrange_max);
    372401
    373402    typedef std::vector<std::pair<std::string, std::vector<unsigned int> > > vec_type;
     
    376405    for (std::set<std::string>::const_iterator i=authors_.begin();
    377406         i != authors_.end(); ++i) {
    378       if (lines(*i)) {
    379         assert(stat->find(*i)!=stat->end());
    380         author_cont.push_back(std::make_pair(*i,get_vector(*stat,*i)));
     407      assert(stat->find(*i)!=stat->end());
     408      const std::vector<unsigned int>& vec = get_vector(*stat,*i);
     409      if (max_element(vec)) {
     410        author_cont.push_back(std::make_pair(*i,vec));
    381411      }
    382412    }
     
    387417    std::sort(author_cont.begin(), author_cont.end(), compare);
    388418
    389     size_t plotno=author_cont.size();
    390     std::stringstream ss;
    391419    vec_type::iterator end(author_cont.end());
    392     for (vec_type::iterator i(author_cont.begin()); i!=end; ++i) {
    393       ss.str("");
    394       ss << "set key height " << 2*plotno;
    395       gp->command(ss.str());
    396       ss.str("");
    397       ss << get_back(*stat, i->first) << " " << i->first;
    398       gp->yrange(yrange_max);
    399       gp->linetitle(ss.str());
    400       ss.str("");
    401       ss << "steps " << --plotno+2;
    402       gp->linestyle(ss.str());
    403       gp->plot(i->second);
    404     }
    405     ss.str("");
    406     ss << get_back(*stat, "all") << " total";
    407     gp->command("set key height 0");
    408     gp->linetitle(ss.str());
    409     gp->linestyle("steps 1");
    410     gp->plot(total);
    411 
    412     gp->command("unset multiplot");
    413     gp->yrange();
    414 
    415     return filename;
    416   }
    417 
    418 
    419   void Stats::plot_init(const std::string& filename) const
    420   {
    421     GnuplotFE* gp=GnuplotFE::instance();
    422     gp->command("set term png");
    423     gp->command("set output '"+filename+"'");
    424     gp->command("set xtics nomirror");
    425     gp->command("set ytics nomirror");
    426     gp->command("set key default");
    427     gp->command("set key left Left reverse");
    428     gp->command("set multiplot");
     420    vec_type::iterator i(author_cont.begin());
     421    const vec_type::size_type maxauthors=8;
     422    int authskip=author_cont.size()-maxauthors;
     423    if (authskip>1) {
     424      // only use others if there is more than 1 author to be skipped,
     425      // there is no reason to add only 1 author to others.
     426      vec_type::iterator j(i);
     427      i+=authskip;
     428      std::vector<unsigned int> init(revision()+1);
     429      std::vector<unsigned int> others =
     430        std::accumulate(j, i, init, PairValuePlus<std::string,unsigned int>());
     431      unsigned char r, g, b;
     432      std::string label("others");
     433      Colors::instance().get_color(label, r,g,b);
     434      gp.current_color(r,g,b);
     435      gp.plot(others, label, others.back());
     436    }
     437    for ( ; i!=end; ++i) {
     438      unsigned char r, g, b;
     439      Colors::instance().get_color(i->first,r,g,b);
     440      gp.current_color(r,g,b);
     441      gp.plot(i->second, i->first, get_back(*stat, i->first));
     442    }
     443    gp.current_color(255,0,0);
     444    gp.plot(total, "total", get_back(*stat, "all"));
    429445  }
    430446
     
    432448  void Stats::plot_summary(const std::string& filename) const
    433449  {
    434     plot_init(filename);
    435     GnuplotFE* gp=GnuplotFE::instance();
     450    const std::string& format = Configuration::instance().image_format();
     451    if (format=="none")
     452      return;
     453    plot_summary(filename, format);
     454    const std::string& anchor_format =
     455      Configuration::instance().image_anchor_format();
     456
     457    if (format!=anchor_format)
     458      plot_summary(filename, anchor_format);
     459  }
     460
     461
     462  void Stats::plot_summary(const std::string& filename,
     463                           const std::string& format) const
     464  {
     465    Graph gp(filename+"."+format, format);
    436466    std::vector<unsigned int> total = get_vector(total_stats(), "all");
    437467    double yrange_max=1.03*total.back()+1;
    438     gp->yrange(yrange_max);
    439     std::stringstream ss;
     468    gp.ymax(yrange_max);
    440469   
    441     ss.str("");
    442470    std::vector<unsigned int> x(get_vector(code_stats(), "all"));
    443     ss << x.back() << " code";
    444     gp->command("set key height 2");
    445     gp->linetitle(ss.str());
    446     gp->linestyle("steps 2");
    447     gp->plot(x);
    448 
    449     ss.str("");
     471    gp.current_color(255,255,0);
     472    gp.plot(x, "code", x.back());
     473
    450474    x = get_vector(comment_or_copy_stats(), "all");
    451     ss << x.back() << " comment";
    452     gp->command("set key height 4");
    453     gp->linetitle(ss.str());
    454     gp->linestyle("steps 3");
    455     gp->plot(x);
    456 
    457     ss.str("");
     475    gp.current_color(0,0,255);
     476    gp.plot(x, "comment", x.back());
     477
    458478    x = get_vector(other_stats(), "all");
    459     ss << x.back() << " other";
    460     gp->command("set key height 6");
    461     gp->linetitle(ss.str());
    462     gp->linestyle("steps 4");
    463     gp->plot(x);
    464 
    465     ss.str("");
    466     ss << total.back() << " total";
    467     gp->command("set key height 0");
    468     gp->linetitle(ss.str());
    469     gp->linestyle("steps 1");
    470     gp->plot(total);
    471 
    472     gp->command("unset multiplot");
    473     gp->yrange();
     479    gp.current_color(0,255,0);
     480    gp.plot(x, "other", x.back());
     481
     482    gp.current_color(255,0,0);
     483    gp.plot(total, "total", total.back());
    474484  }
    475485
  • branches/src-highlight/lib/Stats.h

    r768 r1100  
    66/*
    77  Copyright (C) 2005 Peter Johansson
    8   Copyright (C) 2006 Jari Häkkinen, Peter Johansson
    9   Copyright (C) 2007, 2008 Peter Johansson
     8  Copyright (C) 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
     9  Copyright (C) 2010 Peter Johansson
    1010
    1111  This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    192192                 Author2Vector& map);
    193193
    194     ///
    195     /// Init statistics graph.
    196     ///
    197     void plot_init(const std::string& output) const;
    198 
    199194    std::set<std::string> authors_;
    200195
     
    221216    virtual void do_parse(const std::string&, svn_revnum_t first_rev)=0;
    222217   
     218    /**
     219       called from plot(2)
     220     */
     221    void plot(const std::string& basename, const std::string& linetype,
     222              const std::string& format) const;
     223
     224    /**
     225       called from plot_summary(1)
     226     */
     227    void plot_summary(const std::string& basename,
     228                      const std::string& format) const;
     229
    223230    // Change this string if cache format is changed in such a way
    224231    // that all old cache files are obsolete.
    225232    inline std::string cache_check_str(void) const
     233    {return "CACHE FILE VERSION 7";}
     234
     235    inline std::string prev_cache_check_str(void) const
    226236    {return "CACHE FILE VERSION 6";}
    227237
     
    231241    unsigned int get_back(const Author2Vector&, std::string user) const;
    232242    void load(std::istream& is, Author2Vector& m);
     243    /**
     244       Finds the largets element by iterating through the entire
     245       vector. Inherited classes should implement their own version
     246       when it is possible to get the largest element in faster than
     247       in linear time.
     248
     249       \return the largest largest element in \a v.
     250    */
     251    virtual unsigned int max_element(const std::vector<unsigned int>& v) const;
     252
    233253    void print(std::ostream& os, const Author2Vector& m) const;
    234254
  • branches/src-highlight/lib/StatsCollection.cc

    r803 r1100  
    33/*
    44  Copyright (C) 2007 Peter Johansson
     5  Copyright (C) 2008 Jari Häkkinen, Peter Johansson
     6  Copyright (C) 2009, 2010 Peter Johansson
    57
    68  This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    4951  StatsCollection::~StatsCollection(void)
    5052  {
    51     for (map::const_iterator i(stats_.begin()); i!=stats_.end(); ++i) {
     53    for (map::iterator i(stats_.begin()); i!=stats_.end(); ++i) {
    5254      assert(i->second);
    5355      delete i->second;
     56      i->second = NULL;
    5457    }
    55 
    5658  }
    5759
  • branches/src-highlight/lib/StatsCollection.h

    r801 r1100  
    55
    66/*
    7   Copyright (C) 2005 Peter Johansson
    8   Copyright (C) 2006 Jari Häkkinen, Peter Johansson
    97  Copyright (C) 2007 Peter Johansson
     8  Copyright (C) 2008 Jari Häkkinen, Peter Johansson
     9  Copyright (C) 2010 Peter Johansson
    1010
    1111  This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    8787
    8888  private:
     89    // copy not allowed
     90    StatsCollection(const StatsCollection&);
     91    StatsCollection& operator=(const StatsCollection&);
     92
    8993    const std::string path_;
    9094    typedef std::map<std::string, Stats*> map;
  • branches/src-highlight/lib/Trac.cc

    r768 r1100  
    22
    33/*
    4   Copyright (C) 2007 Jari Häkkinen, Peter Johansson
    5   Copyright (C) 2008, 2009 Peter Johansson
     4  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
     5  Copyright (C) 2009 Peter Johansson
    66
    77  This file is part of svndigest, http://dev.thep.lu.se/svndigest
  • branches/src-highlight/lib/Trac.h

    r768 r1100  
    55
    66/*
    7   Copyright (C) 2007, 2008, 2009 Peter Johansson
     7  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
     8  Copyright (C) 2009 Peter Johansson
    89
    910  This file is part of svndigest, http://dev.thep.lu.se/svndigest
  • branches/src-highlight/lib/css.cc

    r832 r1100  
    33/*
    44  Copyright (C) 2006 Peter Johansson
    5   Copyright (C) 2007 Jari Häkkinen, Peter Johansson
    6   Copyright (C) 2009 Peter Johansson
     5  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
     6  Copyright (C) 2009, 2010 Peter Johansson
    77
    88  This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    3737
    3838      << "Copyright (C) 2006 Peter Johansson\n"
    39       << "Copyright (C) 2007 Jari Häkkinen, Peter Johansson\n"
     39      << "Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson\n"
    4040      << "Copyright (C) 2009 Peter Johansson\n"
    4141      << "\nThis file is part of svndigest, "
     
    146146    s << " padding: 0 1em .1em 0;\n";
    147147    s << "}\n\n";
    148 
     148    s << "div.main img { border: 0; }\n";
    149149
    150150    s << "p.plot { text-align: center; }\n";
  • branches/src-highlight/lib/css.h

    r768 r1100  
    55
    66/*
    7   Copyright (C) 2006, 2007, 2008 Peter Johansson
     7  Copyright (C) 2006 Peter Johansson
     8  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
    89
    910  This file is part of svndigest, http://dev.thep.lu.se/svndigest
  • branches/src-highlight/lib/first_page.cc

    r759 r1100  
    33/*
    44  Copyright (C) 2006 Peter Johansson
    5   Copyright (C) 2007 Jari Häkkinen, Peter Johansson
    6   Copyright (C) 2009 Peter Johansson
     5  Copyright (C) 2007, 2008, 2009 Jari Häkkinen, Peter Johansson
     6  Copyright (C) 2010 Peter Johansson
    77
    88  This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    9393       << "</th></tr></thead>\n"
    9494       << "<tbody>\n"
    95        << "<tr><td>URL:</td><td>"
    96        << url << "</td></tr>\n"
     95       << "<tr><td>URL:</td><td>";
     96    if (url.size()>=4 && url.substr(0,4)=="http")
     97      os << anchor(url, url);
     98    else
     99      os << url;
     100    os << "</td></tr>\n"
    97101       << "<tr><td>First Revision Date:</td><td>"
    98102       << begin(timefmt) << "</td></tr>\n"
     
    149153         << 100*stats.comments(i->author())/(stats.comments()?stats.comments():1)
    150154         << "%)</td><td>";
    151       hs << Date(i->date())(timefmt);
     155      std::string date = Date(i->date())(timefmt);
     156      const Configuration& conf = Configuration::instance();
     157      if (conf.trac_root().empty())
     158        hs << date;
     159      else {
     160        std::stringstream url;
     161        url << conf.trac_root() << "changeset/" << i->revision();
     162        os << anchor(url.str(), date);
     163      }
    152164      os << "</td>" <<"</tr>";
    153165    }
     
    226238  void print_summary_plot(std::ostream& os, const Stats& stats)
    227239  {
    228     std::string name("summary_plot.png");
     240    std::string name("summary_plot");
    229241    stats.plot_summary(name);
    230242    os << "<div class=\"main\">\n";
    231     os << "<img src='" << name << "' alt='[plot]'/>";
     243    os << image(name);
    232244    os << "</div>";
     245
     246
    233247  }
    234248
  • branches/src-highlight/lib/first_page.h

    r768 r1100  
    55
    66/*
    7   Copyright (C) 2006, 2007, 2008 Peter Johansson
     7  Copyright (C) 2006 Peter Johansson
     8  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
    89
    910  This file is part of svndigest, http://dev.thep.lu.se/svndigest
  • branches/src-highlight/lib/html_utility.cc

    r751 r1100  
    33/*
    44  Copyright (C) 2006 Peter Johansson
    5   Copyright (C) 2007 Jari Häkkinen, Peter Johansson
    6   Copyright (C) 2009 Peter Johansson
     5  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
     6  Copyright (C) 2009, 2010 Peter Johansson
    77
    88  This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    3131#include "subversion_info.h"
    3232
     33#include <cassert>
    3334#include <sstream>
    3435#include <string>
     
    6162
    6263 
     64  std::string image(const std::string& name)
     65  {
     66    std::ostringstream os;
     67    const std::string& format = Configuration::instance().image_format();
     68    const std::string& anchor_format =
     69      Configuration::instance().image_anchor_format();
     70    if (format=="svg") {
     71      os << "<object data='" << name << ".svg' type='image/svg+xml'"
     72         << " width='600'>\n"
     73         << "<embed src='" << name << ".svg' type='image/svg+xml'"
     74         << " width='600' />\n"
     75         << "</object>\n";
     76      if (anchor_format != "svg")
     77        std::cerr << "svndigest: anchor_format: " << anchor_format
     78                  << " not supported with format " << format << "\n";
     79    }
     80    else if (format=="png") {
     81      if (anchor_format=="none")
     82        os << "<img src='" << name << ".png' alt='[plot]'/>";
     83      else
     84        os << "<a href=\"" << name << "." << anchor_format << "\">"
     85           << "<img src='" << name << ".png' alt='[plot]'/>"
     86           << "</a>";
     87    }
     88    else if (format=="none")
     89      os << "<!-- no images -->";
     90    else {
     91      assert(false);
     92      throw std::runtime_error("unknown image format: " + format);
     93    }
     94    return os.str();
     95  }
     96
     97
    6398  void print_footer(std::ostream& os)
    6499  {
     
    67102    os << "<p class=\"footer\">\nGenerated on ";
    68103    hs << date("%a %b %e %H:%M:%S %Y") << " (UTC) by ";
    69     os << anchor("http://dev.thep.lu.se/svndigest/",
    70                  PACKAGE_STRING, 0, "");
     104    os << anchor(PACKAGE_URL, PACKAGE_STRING, 0, "");
    71105    if (DEV_BUILD)
    72106      os << " (dev build " << svn_revision() << ")";
     
    179213       << "<head>\n"
    180214       << "<title> " << title << " - svndigest</title>\n"
     215       << "<meta http-equiv=\"Content-type\" content=\"text/html; "
     216       << "charset=UTF-8\" />\n"
    181217       << "<link rel=\"stylesheet\" "
    182218       << "href=\"";
  • branches/src-highlight/lib/html_utility.h

    r768 r1100  
    77  Copyright (C) 2006 Peter Johansson
    88  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
    9   Copyright (C) 2008 Peter Johansson
     9  Copyright (C) 2009, 2010 Peter Johansson
    1010
    1111  This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    4747                     const std::string& title="",
    4848                     const std::string& color="");
     49
     50  /**
     51   */
     52  std::string image(const std::string& name);
    4953
    5054  ///
  • branches/src-highlight/lib/rmdirhier.cc

    r823 r1100  
    33/*
    44  Copyright (C) 2006 Jari Häkkinen
    5   Copyright (C) 2007, 2008 Peter Johansson
     5  Copyright (C) 2007, 2008, 2009 Jari Häkkinen, Peter Johansson
     6  Copyright (C) 2010 Peter Johansson
    67
    78  This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    7879      return;
    7980    }
    80     if (chdir(dir.c_str()))
     81    if (::chdir(dir.c_str()))
    8182      throw BadDirectory(concatenate_path(pwd(),dir));
    8283
  • branches/src-highlight/lib/rmdirhier.h

    r768 r1100  
    66/*
    77  Copyright (C) 2006 Jari Häkkinen
    8   Copyright (C) 2007, 2008 Peter Johansson
     8  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
    99
    1010  This file is part of svndigest, http://dev.thep.lu.se/svndigest
  • branches/src-highlight/lib/subversion_info.cc.in

    r726 r1100  
    22
    33/*
    4   Copyright (C) 2008 Peter Johansson
     4  Copyright (C) 2008 Jari Häkkinen, Peter Johansson
    55
    66  This file is part of svndigest, http://dev.thep.lu.se/svndigest
  • branches/src-highlight/lib/subversion_info.h

    r726 r1100  
    55
    66/*
    7   Copyright (C) 2007, 2008 Peter Johansson
     7  Copyright (C) 2007 Peter Johansson
     8  Copyright (C) 2008 Jari Häkkinen, Peter Johansson
    89
    910  This file is part of svndigest, http://dev.thep.lu.se/svndigest
  • branches/src-highlight/lib/utility.cc

    r797 r1100  
    22
    33/*
    4   Copyright (C) 2006, 2007, 2009 Jari Häkkinen, Peter Johansson
    5   Copyright (C) 2008, 2009 Peter Johansson
     4  Copyright (C) 2006, 2007, 2008, 2009 Jari Häkkinen, Peter Johansson
     5  Copyright (C) 2010 Peter Johansson
    66
    77  This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    2525#include "subversion_info.h"
    2626#include "config.h"
     27
     28#include "yat/Exception.h"
    2729
    2830#include <cassert>
     
    3133#include <cstdlib>
    3234#include <cstring>
     35#include <fnmatch.h>
    3336#include <fstream>
    3437#include <sstream>
     
    6770
    6871
     72  void chdir(const std::string& dir)
     73  {
     74    if (::chdir(dir.c_str()) )
     75      throw yat::utility::errno_error("chdir: " + dir + ":");
     76  }
     77
     78
    6979  std::string concatenate_path(std::string dir, std::string base)
    7080  {
     
    107117
    108118
    109   bool equal(std::string::const_iterator first1,
    110              std::string::const_iterator end1,
    111              std::string::const_iterator first2,
    112              std::string::const_iterator end2)
    113   {
    114     if (first1==end1 && first2==end2)
    115       return true;
    116     if (first1!=end1 && first2!=end2 &&
    117         (*first1==*first2 || *first1=='*' || *first2=='*' ||
    118          *first1=='?' || *first2=='?') &&
    119         equal(first1+1, end1, first2+1, end2) )
    120       return true;
    121     if ( (first1!=end1 && first2!=end2 && (*first1=='*'|| *first2=='*') ) &&
    122          (equal(first1+1, end1, first2, end2) ||
    123           equal(first1, end1, first2+1, end2))
    124          )
    125       return true;
    126     return false;
    127   }
    128 
    129 
    130119  std::string file_name(const std::string& full_path)
    131120  {
     
    167156
    168157
     158  bool fnmatch(const std::string& pattern, const std::string& str)
     159  {
     160    int res = ::fnmatch(pattern.c_str(), str.c_str(), 0);
     161    if (res==0)
     162      return true;
     163    if (res!=FNM_NOMATCH) {
     164      std::stringstream ss;
     165      ss << "fnmatch with args: " << pattern << ", " << str;
     166      throw std::runtime_error(ss.str());
     167    }                     
     168    return false;
     169  }
     170
     171
    169172  std::string ltrim(std::string str)
    170173  {
     
    220223
    221224
    222   bool regexp(std::string::const_iterator first1,
    223               std::string::const_iterator last1,
    224               std::string::const_iterator first2,
    225               std::string::const_iterator last2,
     225  bool regexp(const std::string& pattern, const std::string& str,
    226226              std::vector<std::string>& vec)
    227227  {
    228     if (vec.empty())
    229       vec.push_back("");
    230 
    231     // first two cases when ranges are empty
    232     if (first1==last1 && first2==last2){
    233       vec.pop_back();
    234       return true;
    235     }
     228    bool regexp__(std::string::const_iterator first1,
     229                  std::string::const_iterator last1,
     230                  std::string::const_iterator first2,
     231                  std::string::const_iterator last2,
     232                  std::vector<std::string>::iterator item);
     233   
     234    // find number of special chars
     235    size_t count=0;
     236    for (std::string::const_iterator i=pattern.begin(); i!=pattern.end(); ++i)
     237      if (*i=='*' || *i=='?' || *i=='[')
     238        ++count;
     239    vec.resize(count);
     240    return regexp__(pattern.begin(), pattern.end(), str.begin(), str.end(),
     241                    vec.begin());
     242  }
     243
     244  bool regexp__(std::string::const_iterator first1,
     245                std::string::const_iterator last1,
     246                std::string::const_iterator first2,
     247                std::string::const_iterator last2,
     248                std::vector<std::string>::iterator item)
     249  {
     250    if (first1==last1) {
     251      return first2==last2;
     252    }
     253    if (*first1 == '*') {
     254      if (first2<last2) {
     255        item->push_back(*first2);
     256        if (regexp__(first1, last1, first2+1, last2, item))
     257          return true;
     258        item->resize(item->size()-1);
     259      }
     260      return regexp__(first1+1, last1, first2, last2, item+1);
     261    }
     262    if (*first1 == '?') {
     263      if (first2==last2)
     264        return false;
     265      *item = *first2;
     266      return regexp__(first1+1, last1, first2+1, last2, item+1);
     267    }
     268    if (*first1 == '[') {
     269      if (first2==last2)
     270        return false;
     271      bool found = false;
     272      while (*first1 != ']') {
     273        if (*first1 == *first2) {
     274          found = true;
     275          *item = *first2;
     276        }
     277        ++first1;
     278        assert(first1!=last1);
     279      }
     280      return regexp__(first1+1, last1, first2+1, last2, item+1);
     281      /*
     282      while (*first2 != ']') {
     283        if (*first2==*first1) {
     284          found = true;
     285          vec.back() = *first1;
     286          vec.push_back("");
     287        }
     288        ++first2;
     289        assert(first2!=last2);
     290      }
     291      if (!found)
     292        return false;
     293      return regexp(first1+1, last1, first2+1, last2, vec);
     294      */
     295    }
     296
     297    if (first2==last2)
     298      return false;
     299    if (*first1 != *first2)
     300      return false;
     301    return regexp__(first1+1, last1, first2+1, last2, item);
     302
     303    /*
     304
     305
     306
     307    if (first1==last1)
     308      return false;
     309    if (*first1 != *first2)
     310      return false;
     311    return regexp(first1+1, last1, first2+1, last2, vec);
     312   
     313    /// hm
    236314    if (first1==last1 || first2==last2)
    237315      return false;
     
    271349      return false;
    272350    return regexp(++first1, last1, ++first2, last2, vec);
     351    */
    273352  }
    274353
  • branches/src-highlight/lib/utility.h

    r796 r1100  
    77  Copyright (C) 2005 Peter Johansson
    88  Copyright (C) 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
    9   Copyright (C) 2009 Peter Johansson
     9  Copyright (C) 2009, 2010 Peter Johansson
    1010
    1111  This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    5757
    5858  /**
     59     wrapper around GNU C Library function chdir
     60
     61     \throw if underlying chdir call does not return 0
     62   */
     63  void chdir(const std::string& dir);
     64
     65  /**
    5966     \return dir+base if dir ends with '/', else dir+'/'+base
    6067   */
     
    7885  std::string directory_name(std::string path);
    7986
    80   /**
    81      Function to compare strings. Strings may contain '*'.
    82 
    83      \return true if \a a and \a b are identical.
    84    */
    85   bool equal(std::string::const_iterator first1,
    86              std::string::const_iterator end1,
    87              std::string::const_iterator first2,
    88              std::string::const_iterator end2);
    89 
    9087  ///
    9188  /// @return everything after last '/'
    9289  ///
    9390  std::string file_name(const std::string&);
     91
     92  /**
     93     \return true if \a str matches \a pattern
     94
     95     \see fnmatch(3)
     96   */
     97  bool fnmatch(const std::string& pattern, const std::string& str);
    9498
    9599  ///
     
    161165
    162166  /**
    163      \return true if first range match second range
    164 
    165      Second range may contain wildcards (such as '*' and '?'), in
    166      which case vector \a vec is filled with the corresponding strings
    167      in first range. The algorithm is greedy, i.e., wildcard * is will
     167     \return true if \a str matches \a pattern
     168
     169     \a pattern may contain wildcards '*', '?' and \a vec will contain
     170     the matching string in \a str. If it's not a match, \a vec is
     171     undefined. The algorithm is greedy, i.e., wildcards '*' will
    168172     consume as many charcters as possible.
    169173
    170174     \note \a vec is supposed to be empty
    171175   */
    172   bool regexp(std::string::const_iterator first1,
    173               std::string::const_iterator end1,
    174               std::string::const_iterator first2,
    175               std::string::const_iterator end2,
     176  bool regexp(const std::string& pattern, const std::string& str,
    176177              std::vector<std::string>& vec);
    177178
  • branches/src-highlight/lib/yat/ColumnStream.cc

    r795 r1100  
    1 // $Id: ColumnStream.cc 1797 2009-02-12 18:07:10Z peter $
     1// $Id: ColumnStream.cc 2119 2009-12-12 23:11:43Z peter $
    22
    33/*
  • branches/src-highlight/lib/yat/ColumnStream.h

    r795 r1100  
    22#define _theplu_yat__utility_column_stream_
    33
    4 // $Id: ColumnStream.h 1887 2009-03-31 17:38:16Z peter $
     4// $Id: ColumnStream.h 2119 2009-12-12 23:11:43Z peter $
    55
    66/*
     
    2424*/
    2525#include <fstream>
    26 #include <iostream>
     26#include <iosfwd>
    2727#include <sstream>
    2828#include <vector>
  • branches/src-highlight/lib/yat/CommandLine.cc

    r824 r1100  
    1 // $Id: CommandLine.cc 2046 2009-09-02 21:42:32Z peter $
     1// $Id: CommandLine.cc 2265 2010-06-05 23:12:10Z peter $
    22
    33/*
     
    55  Copyright (C) 2008 Jari Häkkinen, Peter Johansson
    66  Copyright (C) 2009 Peter Johansson
     7  Copyright (C) 2010 Jari Häkkinen, Peter Johansson
    78
    89  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    3132
    3233#include <algorithm>
     34#include <cassert>
    3335#include <functional>
    3436#include <fstream>
     
    6062        ss << "yat::utility::Commandline: two options with long_name: "
    6163           << option.long_name();
    62         throw std::runtime_error(ss.str());
     64        throw runtime_error(ss.str());
    6365      }
    6466      long_options_[option.long_name()] = &option;
     
    6971        ss << "yat::utility::Commandline: two options with short_name: "
    7072           << option.short_name();
    71         throw std::runtime_error(ss.str());
     73        throw runtime_error(ss.str());
    7274      }
    7375      short_options_[option.short_name()] = &option;
     
    196198
    197199
     200  void CommandLine::sort(void)
     201  {
     202    sort(OptionCompare());
     203  }
     204
     205
    198206  std::vector<std::string> CommandLine::split(std::string str, char del) const
    199207  {
     
    236244
    237245
     246  bool CommandLine::OptionCompare::operator()(const Option* lhs,
     247                                              const Option* rhs) const
     248  {
     249    assert(lhs);
     250    assert(rhs);
     251    std::string lhs_str = lhs->long_name();
     252    if (lhs_str.empty())
     253      lhs_str = lhs->short_name();
     254    std::string rhs_str = rhs->long_name();
     255    if (rhs_str.empty())
     256      rhs_str = rhs->short_name();
     257    return lhs_str < rhs_str;
     258  }
     259
     260
    238261}}} // of namespace utility, yat, and theplu
  • branches/src-highlight/lib/yat/CommandLine.h

    r824 r1100  
    22#define _theplu_yat_utility_commandline_
    33
    4 //$Id: CommandLine.h 2054 2009-09-06 18:25:06Z peter $
     4//$Id: CommandLine.h 2265 2010-06-05 23:12:10Z peter $
    55
    66/*
    7   Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
    8   Copyright (C) 2009 Peter Johansson
     7  Copyright (C) 2007, 2008, 2009, 2010 Jari Häkkinen, Peter Johansson
    98
    109  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    2423*/
    2524
     25#include <algorithm>
    2626#include <cctype>
    2727#include <map>
     
    158158
    159159    /**
     160       \brief Sort Options how they will appear in (help) output.
     161
     162       This function will sort the Options in alphabetical order. If
     163       the Option has a long_name, it is used for the sorting;
     164       otherwise, the short_name is used.
     165
     166       \since New in yat 0.7
     167     */
     168    void sort(void);
     169
     170    /**
     171       Like sort(void) but using \a compare to sort Options.
     172
     173       The functor Compare must be a <a
     174       href="http://www.sgi.com/tech/stl/BinaryFunction.html">Binary
     175       Function</a> with both argument types \c const \c Option* and
     176       return type \c bool.
     177
     178       \since New in yat 0.7
     179     */
     180    template<class Compare>
     181    void sort(Compare compare);
     182
     183    /**
    160184       \return something like "Try `<program_name()> --help` for
    161185       more information."
     
    165189  private:
    166190    friend std::ostream& operator<<(std::ostream& os, const CommandLine& cl);
    167     void add_private(std::string, Option&);
    168191    bool is_long_option(std::string str) const;
    169192    bool is_short_option(std::string str) const;
     
    178201    bool parsed_;
    179202    std::string program_name_;
     203
     204    struct OptionCompare
     205    {
     206      bool operator()(const Option*, const Option*) const;
     207    };
     208
    180209  };
    181210
     
    200229  std::ostream& operator<<(std::ostream&, const CommandLine&);
    201230
     231  template<class Compare>
     232  void CommandLine::sort(Compare compare)
     233  {
     234    std::sort(options_.begin(), options_.end(), compare);
     235  }
     236
    202237}}} // end of namespace utility, yat, and theplu
    203238
  • branches/src-highlight/lib/yat/Exception.h

    r795 r1100  
    22#define _theplu_yat_utility_exception_
    33
    4 // $Id: Exception.h 1797 2009-02-12 18:07:10Z peter $
     4// $Id: Exception.h 2210 2010-03-05 22:59:01Z peter $
    55
    66/*
    77  Copyright (C) 2005, 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
     8  Copyright (C) 2010 Peter Johansson
    89
    910  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    3031namespace utility {
    3132
     33 
     34
     35  /**
     36     \brief Class used for all runtime error detected within yat library.
     37   */
     38  class runtime_error : public std::runtime_error
     39  {
     40  public:
     41    /**
     42       \brief Constructor
     43
     44       \param message message to be displayed using function what().
     45     */
     46    runtime_error(std::string message);
     47  };
     48
     49
    3250  /**
    3351     \brief Class used for error reported from Commandline or Option.
     
    4159       \param message message to be displayed using function what().
    4260     */
    43     inline cmd_error(std::string message)
    44       : std::runtime_error(message) {}
     61    cmd_error(std::string message);
     62  };
     63
     64
     65  /**
     66     \brief Class that contains information reported bia global
     67     variable errno.
     68   */
     69  class errno_error : public std::runtime_error
     70  {
     71  public:
     72    /**
     73       The error message, return from what(), is set to
     74       \a message + strerror(errno)
     75     */
     76    errno_error(std::string message);
     77  };
     78
     79  /**
     80     \brief Class for errors reported from underlying GSL calls.
     81
     82     GSL_error is used in the same way as C++ standard library
     83     exceptions.
     84  */
     85  class GSL_error : public std::runtime_error
     86  {
     87  public:
     88    /**
     89       \brief Constructor to create an exception with a message.
     90    */
     91    GSL_error(std::string message);
     92
     93    /**
     94       \brief Constructor to create an exception with a message
     95       containg the GSL error description.
     96    */
     97    GSL_error(std::string message, int gsl_status);
    4598  };
    4699
     
    58111       \brief Constructor to create an exception with a message.
    59112    */
    60     inline IO_error(std::string message) throw()
    61       : std::runtime_error("IO_error: " + message) {}
     113    IO_error(std::string message);
    62114  };
    63115
  • branches/src-highlight/lib/yat/Makefile.am

    r795 r1100  
    33## $Id$
    44
    5 # Copyright (C) 2009 Peter Johansson
     5# Copyright (C) 2009, 2010 Peter Johansson
    66#
    77# This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    2222MOVE_IF_CHANGE = $(SHELL) $(abs_top_srcdir)/build_support/move-if-change
    2323
    24 AM_CPPFLAGS = $(SVNDIGEST_CPPFLAGS)
    25 AM_CXXFLAGS = $(SVNDIGEST_CXXFLAGS)
     24AM_CPPFLAGS = $(DEFAULT_CPPFLAGS)
     25AM_CXXFLAGS = $(DEFAULT_CXXFLAGS)
    2626
    2727noinst_LIBRARIES = libyat.a
     
    4242libyat_a_SOURCES += ColumnStream.cc
    4343libyat_a_SOURCES += CommandLine.cc
     44libyat_a_SOURCES += Exception.cc
    4445libyat_a_SOURCES += Option.cc
    4546libyat_a_SOURCES += OptionHelp.cc
     
    5758  test -d Fetchdir || $(SVN) co $(yat_url) Fetchdir
    5859  (cd Fetchdir && $(SVN) revert -Rq . && $(SVN) update)
    59   cp $(srcdir)/Exception.h.diff Fetchdir
    60   (cd Fetchdir && patch -i Exception.h.diff || exit 1)
     60  cp $(srcdir)/Exception.cc.patch Fetchdir
     61  (cd Fetchdir && patch -i Exception.cc.patch || exit 1)
    6162  @for f in $(FETCH_FILES); do \
    6263    $(MOVE_IF_CHANGE) -v Fetchdir/$$f $(srcdir)/$$f; \
  • branches/src-highlight/lib/yat/Option.cc

    r795 r1100  
    1 // $Id: Option.cc 1797 2009-02-12 18:07:10Z peter $
     1// $Id: Option.cc 2210 2010-03-05 22:59:01Z peter $
    22
    33/*
     
    2323#include "Option.h"
    2424#include "CommandLine.h"
     25#include "Exception.h"
    2526
    2627#include <iostream>
    2728#include <sstream>
    28 #include <stdexcept>
    2929#include <string>
    3030
     
    3838  {
    3939    if (flag.empty())
    40       throw std::runtime_error("yat: Option: given flag is empty");
     40      throw runtime_error("yat: Option: given flag is empty");
    4141    if (flag.size()==1 || (flag.size()==2 && flag[1]==','))
    4242      short_name_ = flag[0];
     
    8989  {
    9090    if (!cmd().parsed()) {
    91       std::string s("Option::present called before Commandline was parsed");
     91      std::string s("theplu::yat::utility::Option::present");
     92      s += " called before Commandline was parsed";
    9293      throw std::logic_error(s);
    9394    }
  • branches/src-highlight/lib/yat/Option.h

    r824 r1100  
    22#define _theplu_yat_utility_option_
    33
    4 // $Id: Option.h 2046 2009-09-02 21:42:32Z peter $
     4// $Id: Option.h 2119 2009-12-12 23:11:43Z peter $
    55
    66/*
  • branches/src-highlight/lib/yat/OptionArg.h

    r824 r1100  
    22#define _theplu_yat_utility_option_arg_
    33
    4 // $Id: OptionArg.h 2046 2009-09-02 21:42:32Z peter $
     4// $Id: OptionArg.h 2210 2010-03-05 22:59:01Z peter $
    55
    66/*
     
    134134    }
    135135
    136     void assign(std::string& lhs, std::string rhs )
     136    void assign(std::string& lhs, const std::string& rhs )
    137137    {
    138138      lhs = rhs;
     
    140140   
    141141    template<class T1>
    142     void assign(T1& lhs, std::string rhs )
     142    void assign(T1& lhs, const std::string& rhs )
    143143    {
    144144      try {
    145145        lhs = convert<T1>(rhs);
    146146      }
    147       catch (std::runtime_error& e) {
     147      catch (runtime_error& e) {
    148148        std::stringstream sstr(rhs);
    149149        sstr << ": invalid argument";
  • branches/src-highlight/lib/yat/OptionHelp.cc

    r824 r1100  
    1 // $Id: OptionHelp.cc 2055 2009-09-08 18:23:43Z peter $
     1// $Id: OptionHelp.cc 2246 2010-04-22 00:53:23Z peter $
    22
    33/*
    44  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
     5  Copyright (C) 2009 Peter Johansson
    56
    67  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    4950    std::cout << cmd() << "\n";
    5051    std::cout << post_cmd_;
    51     exit(0);
     52    exit(EXIT_SUCCESS);
    5253  }
    5354
  • branches/src-highlight/lib/yat/OptionHelp.h

    r795 r1100  
    22#define _theplu_yat_utility_option_help_
    33
    4 // $Id: OptionHelp.h 1797 2009-02-12 18:07:10Z peter $
     4// $Id: OptionHelp.h 2119 2009-12-12 23:11:43Z peter $
    55
    66/*
  • branches/src-highlight/lib/yat/OptionSwitch.cc

    r795 r1100  
    1 // $Id: OptionSwitch.cc 1797 2009-02-12 18:07:10Z peter $
     1// $Id: OptionSwitch.cc 2119 2009-12-12 23:11:43Z peter $
    22
    33/*
  • branches/src-highlight/lib/yat/OptionSwitch.h

    r795 r1100  
    22#define _theplu_yat_utility_option_switch_
    33
    4 // $Id: OptionSwitch.h 1797 2009-02-12 18:07:10Z peter $
     4// $Id: OptionSwitch.h 2119 2009-12-12 23:11:43Z peter $
    55
    66/*
  • branches/src-highlight/lib/yat/README

    r826 r1100  
    88fetch'. Be careful doing this and particularly in sensitive branches
    99such as a stable-branch. All files are left pristine except
    10 `Exception.h' that is modified to avoid a dependency to GSL.
     10`Exception.cc' that is modified to avoid a dependency to GSL.
    1111
    1212How to add a new file from yat? Add the file to 'noinst_HEADERS' or
     
    1919
    2020
    21 Copyright (C) 2009 Peter Johansson
     21Copyright (C) 2009, 2010 Peter Johansson
    2222
    2323This file is part of svndigest, http://dev.thep.lu.se/svndigest
  • branches/src-highlight/lib/yat/config_public.h.in

    r798 r1100  
    22#define _theplu_yat_utility_config_public_
    33
    4 // $Id: config_public.h.in 1797 2009-02-12 18:07:10Z peter $
     4// $Id: config_public.h.in 2140 2009-12-31 22:43:29Z peter $
    55
    66/*
    77  Copyright (C) 2008 Jari Häkkinen, Peter Johansson
     8  Copyright (C) 2009 Peter Johansson
    89
    9   This file is part of the yat library, http://trac.thep.lu.se/yat
     10  This file is part of the yat library, http://dev.thep.lu.se/yat
    1011
    1112  The yat library is free software; you can redistribute it and/or
  • branches/src-highlight/lib/yat/deprecate.h

    r824 r1100  
    22#define _theplu_yat_utility_deprecate_
    33
    4 // $Id: deprecate.h 2062 2009-09-14 20:19:17Z peter $
     4// $Id: deprecate.h 2124 2009-12-19 22:43:03Z peter $
    55
    66/*
    77  Copyright (C) 2008, 2009 Peter Johansson
    88
    9   This file is part of the yat library, http://trac.thep.lu.se/yat
     9  This file is part of the yat library, http://dev.thep.lu.se/yat
    1010
    1111  The yat library is free software; you can redistribute it and/or
  • branches/src-highlight/lib/yat/utility.h

    r824 r1100  
    22#define _theplu_yat_utility_utility_
    33
    4 // $Id: utility.h 2055 2009-09-08 18:23:43Z peter $
     4// $Id: utility.h 2248 2010-04-22 00:57:13Z peter $
    55
    66/*
     
    8888
    8989  /**
    90      @return true if string \a s fulfills regular expression \verbatim
    91      ^\w* \endverbatim \a other \verbatim \w*$ \endverbatim (case
    92      insensitive)
     90     This function takes the first word (separated by whitespace) in
     91     \a s, replaces all upper case with lower case, and compares it
     92     with \a other.
     93
     94     \return true if processed \a s is equal to \a other. It returns
     95     false otherwise or if \a s contains more than one word.
    9396  */
    9497  bool is_equal(std::string s, std::string other);
     
    146149
    147150     \note Requirement on T: utility::convert<T> must be supported
     151     (from yat 0.7 T=string is also supported)
    148152
    149153     \since New in yat 0.6
     
    170174     
    171175     \note Requirement on T: utility::convert<T> must be supported
     176     (from yat 0.7 T=string is also supported)
    172177
    173178     \since New in yat 0.6
     
    176181  void load(std::istream& is, std::vector<T>& vec, char sep='\0');
    177182 
     183// private namespace
     184namespace detail {
     185  /**
     186     Functor used in load function
     187   */
     188  template<typename T>
     189  struct VectorPusher
     190  {
     191    /**
     192       convert element to T and push on vec's back
     193
     194       \internal
     195     */
     196    void operator()(const std::string& element, std::vector<T>& vec)
     197    {
     198      if (!element.size())
     199        vec.push_back(std::numeric_limits<T>::quiet_NaN());
     200      else {
     201        vec.push_back(theplu::yat::utility::convert<T>(element));
     202      }
     203    }
     204  };
     205
     206  /**
     207     specialization for string
     208
     209     \internal
     210   */
     211  template<>
     212  struct VectorPusher<std::string>
     213  {
     214    /**
     215       push element on vec's back
     216     */
     217    void operator()(const std::string& element, std::vector<std::string>& vec)
     218    {
     219      vec.push_back(element);
     220    }
     221  };
     222
     223} // end of namespace detail
     224
     225
    178226  // template implementations
    179227
     
    209257        return -std::numeric_limits<T>::infinity();
    210258      else
    211         throw std::runtime_error(std::string("yat::utility::convert(\"")+s+
    212                                  std::string("\"): type is unsigned") );
     259        throw runtime_error(std::string("yat::utility::convert(\"")+s+
     260                            std::string("\"): type is unsigned") );
    213261    }
    214262    std::stringstream ss(s);
     
    222270    ss >> b;
    223271    if (!b.empty() || !ok)
    224       throw std::runtime_error(std::string("yat::utility::convert(\"")+s+
    225                                std::string("\")"));
     272      throw runtime_error(std::string("yat::utility::convert(\"")+s+
     273                          std::string("\")"));
    226274    return a;
    227275  }
     
    284332  void load(std::istream& is, std::vector<T>& vec, char sep='\0')
    285333  {
     334    detail::VectorPusher<T> pusher;
    286335    std::string element;
    287336    bool ok=true;
    288     while(ok) {
     337    while(true) {
    289338      if(sep=='\0')
    290339        ok=(is>>element);
     
    294343        break;
    295344     
    296       if (!element.size())
    297         vec.push_back(std::numeric_limits<T>::quiet_NaN());
    298       else {
    299         vec.push_back(convert<T>(element));
    300       }
     345      pusher(element, vec);
    301346    }
    302347  }           
Note: See TracChangeset for help on using the changeset viewer.