Ignore:
Timestamp:
Nov 16, 2009, 11:27:19 PM (12 years ago)
Author:
Jari Häkkinen
Message:

Merged trunk changes -r782:844 to replacing_gnuplot branch.

Location:
branches/replacing_gnuplot/bin
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/replacing_gnuplot/bin/Makefile.am

    r784 r845  
    2929noinst_HEADERS = Parameter.h
    3030
    31 LDADD = $(top_builddir)/lib/libsvndigest.a $(SVNDIGEST_LIBS)
     31LDADD = $(top_builddir)/lib/libsvndigest.a \
     32  $(top_builddir)/lib/yat/libyat.a $(SVNDIGEST_LIBS)
    3233AM_LDFLAGS = $(SVNDIGEST_LDFLAGS)
    3334
  • branches/replacing_gnuplot/bin/Parameter.cc

    r784 r845  
    2222#include "Parameter.h"
    2323
    24 #include "ColumnStream.h"
    25 #include "OptionArg.h"
    26 #include "OptionHelp.h"
    27 #include "OptionSwitch.h"
    2824#include "OptionVersion.h"
    29 #include "utility.h"
     25#include "../lib/utility.h" // to avoid inclusion of yat file
     26
     27#include "yat/ColumnStream.h"
     28#include "yat/Exception.h"
     29#include "yat/OptionArg.h"
     30#include "yat/OptionHelp.h"
     31#include "yat/OptionSwitch.h"
     32
    3033#include <config.h> // this header file is created by configure
    3134
     
    4144#include <sys/stat.h>
    4245
     46// FIXME: remove this when we require autoconf 2.64
     47// autoconf 2.64 defines PACKAGE_URL in config.h (from AC_INIT)
     48#ifndef PACKAGE_URL
     49#define PACKAGE_URL "http://dev.thep.lu.se/svndigest"
     50#endif
     51
    4352namespace theplu {
    4453namespace svndigest {
    4554
    4655  Parameter::Parameter( int argc, char *argv[])
    47     : cmd_(
    48      "Mandatory arguments to long options are mandatory for short options too.")
     56    : cmd_( std::string("Mandatory arguments to long options ") +
     57            std::string("are mandatory for short options too.")),
     58      config_file_(cmd_, "config-file",
     59                   "configuration file [<ROOT>/.svndigest/config]"),
     60      copyright_(cmd_, "copyright", "update copyright statement"),
     61      force_(cmd_, "f,force",
     62             std::string("if sub-directory named <ROOT> exists in target dire")+
     63             std::string("ctory, remove sub-directory before writing results")),
     64      generate_config_(cmd_, "g,generate-config",
     65                       "write configuration to standard output"),
     66      help_(cmd_),
     67      ignore_cache_(cmd_, "ignore-cache",
     68                    std::string("ignore cache files and analyze ") +
     69                    std::string("everything from repository")),
     70      report_(cmd_, "report", "create no HTML report", true),
     71      revisions_(cmd_, "revisions",
     72                 "use revision number as time scale instead of dates [dates]"),
     73      root_(cmd_, "r,root",
     74            "svn controlled directory to perform statistics on [.]"),
     75      target_(cmd_, "t,target", "output directory [.]"),
     76      verbose_(cmd_, "v,verbose", "explain what is being done"),
     77      version_(cmd_, "version", "print version information and exit", &verbose_)
    4978  {
    5079    init();
     
    5281      cmd_.parse(argc, argv);
    5382    }
    54     catch (cmd_error& e) {
     83    catch (yat::utility::cmd_error& e) {
    5584      std::cerr << e.what() << std::endl;
    5685      exit (-1);
     
    5887
    5988    // set default values
    60     if (!root_->present())
    61       root_->value(".");
    62 
    63     if (!target_->present())
    64       target_->value(".");
    65 
    66     if (!config_file_->present())
    67       config_file_->value(concatenate_path(root_->value(),".svndigest/config"));
     89    if (!root_.present())
     90      root_.value(".");
     91
     92    if (!target_.present())
     93      target_.value(".");
     94
     95    if (!config_file_.present())
     96      config_file_.value(concatenate_path(root_.value(),".svndigest/config"));
    6897
    6998    // analyse arguments
     
    74103  Parameter::~Parameter(void)
    75104  {
    76     delete config_file_;
    77     delete copyright_;
    78     delete force_;
    79     delete generate_config_;
    80     delete help_;
    81     delete ignore_cache_;
    82     delete report_;
    83     delete revisions_;
    84     delete root_;
    85     delete target_;
    86     delete verbose_;
    87     delete version_;
    88105  }
    89106
     
    95112    // check root but not if -g option given
    96113    if (!generate_config()) {
    97       check_existence(root_->value());
    98       check_readable(root_->value());
    99       if (chdir(root_->value().c_str())) {
     114      check_existence(root_.value());
     115      check_readable(root_.value());
     116      if (chdir(root_.value().c_str())) {
    100117        std::stringstream ss;
    101         ss << "svndigest: cannot read `" << root_->value() << "': "
     118        ss << "svndigest: cannot read `" << root_.value() << "': "
    102119           << strerror(errno);
    103         throw cmd_error(ss.str());
     120        throw yat::utility::cmd_error(ss.str());
    104121      }
    105       root_->value(pwd());
     122      root_.value(pwd());
    106123      chdir(save_wd.c_str());
    107124
    108125      // check target (only if we write report)
    109126      if (report()) {
    110         check_existence(target_->value());
    111         check_readable(target_->value());
    112         std::string base_root = file_name(root_->value());
    113         std::string path = concatenate_path(target_->value(),base_root);
    114         if (access_rights(target_->value().c_str(), "w")) {
     127        check_existence(target_.value());
     128        check_readable(target_.value());
     129        std::string base_root = file_name(root_.value());
     130        std::string path = concatenate_path(target_.value(),base_root);
     131        if (access_rights(target_.value().c_str(), "w")) {
    115132          std::stringstream ss;
    116133          ss << "svndigest: cannot create directory `" << path
    117134             << "': " << strerror(errno);
    118           throw cmd_error(ss.str());
     135          throw yat::utility::cmd_error(ss.str());
    119136        }
    120137        if (node_exist(path) && !force()) {
     
    122139          ss << "svndigest: cannot create directory `" << path << "' "
    123140             << strerror(EEXIST);
    124           throw cmd_error(ss.str());
     141          throw yat::utility::cmd_error(ss.str());
    125142        }
    126         if (chdir(target_->value().c_str())) {
     143        if (chdir(target_.value().c_str())) {
    127144          std::stringstream ss;
    128           ss << "svndigest: cannot read `" << target_->value() << "': "
     145          ss << "svndigest: cannot read `" << target_.value() << "': "
    129146             << strerror(errno);
    130           throw cmd_error(ss.str());
     147          throw yat::utility::cmd_error(ss.str());
    131148        }
    132         target_->value(pwd());
     149        target_.value(pwd());
    133150        chdir(save_wd.c_str());
    134151      }
     
    138155    struct stat nodestat;
    139156    // true also if there is a broken symlink named...
    140     bool config_exists = !lstat(config_file_->value().c_str(), &nodestat);
     157    bool config_exists = !lstat(config_file_.value().c_str(), &nodestat);
    141158    // the latter case in order to catch broken symlink
    142     if (config_file_->present() || config_exists)
     159    if (config_file_.present() || config_exists)
    143160      // throws if file does not exists
    144       check_existence(config_file_->value());
     161      check_existence(config_file_.value());
    145162    if (config_exists) {
    146163      // throws if file is not readable
    147       check_readable(config_file_->value());
    148       stat(config_file_->value().c_str(), &nodestat);
     164      check_readable(config_file_.value());
     165      stat(config_file_.value().c_str(), &nodestat);
    149166      if (!S_ISREG(nodestat.st_mode)) {
    150167        std::stringstream ss;
    151         ss << "svndigest: `" << config_file_->value()
     168        ss << "svndigest: `" << config_file_.value()
    152169           << "' is not a regular file";
    153         throw cmd_error(ss.str());
     170        throw yat::utility::cmd_error(ss.str());
    154171      }
    155172    }
     
    163180    std::stringstream ss;
    164181    ss << "svndigest: cannot stat `" << path << "': " << strerror(errno);
    165     throw cmd_error(ss.str());
     182    throw yat::utility::cmd_error(ss.str());
    166183  }
    167184
     
    173190    std::stringstream ss;
    174191    ss << "svndigest: cannot open `" << path << "': " << strerror(errno);
    175     throw cmd_error(ss.str());
     192    throw yat::utility::cmd_error(ss.str());
    176193  }
    177194 
     
    179196  std::string Parameter::config_file(void) const
    180197  {
    181     return config_file_->value();
     198    return config_file_.value();
    182199  }
    183200
     
    185202  bool Parameter::copyright(void) const
    186203  {
    187     return copyright_->present();
     204    return copyright_.present();
    188205  }
    189206
     
    191208  bool Parameter::force(void) const
    192209  {
    193     return force_->present();
     210    return force_.present();
    194211  }
    195212
     
    197214  bool Parameter::generate_config(void) const
    198215  {
    199     return generate_config_->present();
     216    return generate_config_.present();
    200217  }
    201218
     
    203220  bool Parameter::ignore_cache(void) const
    204221  {
    205     return ignore_cache_->present();
     222    return ignore_cache_.present();
    206223  }
    207224
     
    211228    // don't use argv[0] because user may rename the binary
    212229    cmd_.program_name() = PACKAGE_NAME;
    213     config_file_=new OptionArg<std::string>(cmd_, "config-file",
    214                                 "configuration file [<ROOT>/.svndigest/config]");
    215     config_file_->print_arg("=FILE");
     230    config_file_.print_arg("=FILE");
     231    root_.print_arg("=ROOT");
     232    target_.print_arg("=TARGET");
    216233    std::stringstream ss;
    217     copyright_ = new OptionSwitch(cmd_, "copyright",
    218                                   "update copyright statement");
    219 
    220     ss << "if sub-directory named <ROOT> exists in target directory, remove "
    221        << "sub-directory before writing results";
    222     force_ = new OptionSwitch(cmd_, "f,force", ss.str());
    223     ss.str("");
    224 
    225     help_ = new OptionHelp(cmd_);
    226     generate_config_ =
    227       new OptionSwitch(cmd_, "g,generate-config",
    228                        "write configuration file to standard output");
    229 
    230     ss.str("");
    231     ss << "ignore cache files and analyze everything from repository";
    232     ignore_cache_ = new OptionSwitch(cmd_, "ignore-cache", ss.str());
    233          
    234     report_ = new OptionSwitch(cmd_, "report", "create no HTML report", true);
    235 
    236     ss.str("");
    237     ss << "use revision numbers as time scale instead of dates [dates]";
    238     revisions_ = new OptionSwitch(cmd_, "revisions", ss.str());
    239 
    240     root_=
    241       new OptionArg<std::string>(cmd_, "r,root",
    242                      "svn controlled directory to perform statistics on [.]");
    243     root_->print_arg("=ROOT");
    244     target_ = new OptionArg<std::string>(cmd_, "t,target",
    245                                          "output directory [.]");
    246     target_->print_arg("=TARGET");
    247    
    248     verbose_ = new OptionSwitch(cmd_, "v,verbose", "explain what is being done");
    249     version_ = new OptionVersion(cmd_, "version",
    250                                  "print version information and exit", verbose_);
    251 
    252     ss.str("");
    253     ss << "Report bugs to " << PACKAGE_BUGREPORT << ".\n";
    254     help_->post_arguments() = ss.str();
    255     help_->synopsis() =
     234    ss << "Report bugs to " << PACKAGE_BUGREPORT << ".\n"
     235       << PACKAGE << " home page: <" << PACKAGE_URL << ">.\n";
     236    help_.post_arguments() = ss.str();
     237    help_.synopsis() =
    256238      "Generate statistical report for a subversion repository\n";
    257239  }
     
    260242  bool Parameter::report(void) const
    261243  {
    262     return report_->value();
     244    return report_.value();
    263245  }
    264246
     
    266248  bool Parameter::revisions(void) const
    267249  {
    268     return revisions_->present();
     250    return revisions_.present();
    269251  }
    270252
     
    272254  std::string Parameter::root(void) const
    273255  {
    274     return root_->value();
     256    return root_.value();
    275257  }
    276258
     
    278260  std::string Parameter::targetdir(void) const
    279261  {
    280     return target_->value();
     262    return target_.value();
    281263  }
    282264
     
    284266  bool Parameter::verbose(void) const
    285267  {
    286     return verbose_->present();
     268    return verbose_.present();
    287269  }
    288270
  • branches/replacing_gnuplot/bin/Parameter.h

    r784 r845  
    2424*/
    2525
    26 #include "CommandLine.h"
    27 #include "OptionArg.h"
     26#include "OptionVersion.h"
     27
     28#include "yat/CommandLine.h"
     29#include "yat/OptionArg.h"
     30#include "yat/OptionHelp.h"
     31#include "yat/OptionSwitch.h"
     32
    2833
    2934#include <string>
    3035
    3136namespace theplu {
     37namespace yat {
     38namespace utility {
     39  class OptionHelp;
     40  class OptionSwitch;
     41}}
    3242namespace svndigest {
    3343
    34   class OptionHelp;
    35   class OptionSwitch;
    3644  class OptionVersion;
    3745
     
    6674    void init(void);
    6775
    68     CommandLine cmd_;
    69     OptionArg<std::string>* config_file_;
    70     OptionSwitch* copyright_;
    71     OptionSwitch* force_;
    72     OptionSwitch* generate_config_;
    73     OptionHelp* help_;
    74     OptionSwitch* ignore_cache_;
    75     OptionSwitch* report_;
    76     OptionSwitch* revisions_;
    77     OptionArg<std::string>* root_;
    78     OptionArg<std::string>* target_;
    79     OptionSwitch* verbose_;
    80     OptionVersion* version_;
     76    yat::utility::CommandLine cmd_;
     77    yat::utility::OptionArg<std::string> config_file_;
     78    yat::utility::OptionSwitch copyright_;
     79    yat::utility::OptionSwitch force_;
     80    yat::utility::OptionSwitch generate_config_;
     81    yat::utility::OptionHelp help_;
     82    yat::utility::OptionSwitch ignore_cache_;
     83    yat::utility::OptionSwitch report_;
     84    yat::utility::OptionSwitch revisions_;
     85    yat::utility::OptionArg<std::string> root_;
     86    yat::utility::OptionArg<std::string> target_;
     87    yat::utility::OptionSwitch verbose_;
     88    OptionVersion version_;
    8189
    8290  };
  • branches/replacing_gnuplot/bin/svndigest.cc

    r784 r845  
    2626#include "css.h"
    2727#include "Directory.h"
    28 #include "Exception.h"
    2928#include "first_page.h"
    3029#include "GnuplotFE.h"
     
    3635#include "SVNinfo.h"
    3736#include "SVNlog.h"
    38 #include "utility.h"
     37#include "../lib/utility.h"
     38
     39#include "yat/Exception.h"
    3940
    4041#include <cassert>
     
    5152int main( int argc, char* argv[])
    5253{
    53   using namespace theplu::svndigest;
     54  using namespace theplu;
     55  using namespace svndigest;
    5456
    5557  // Reading commandline options
     
    6062      std::cout << "Done parsing parameters" << std::endl;
    6163  }
    62   catch (cmd_error& e) {
     64  catch (yat::utility::cmd_error& e) {
    6365    std::cerr << e.what() << std::endl;
    6466    exit(-1);
     
    158160        std::cout << "Removing old target tree: " << target_path << "\n";
    159161      rmdirhier(target_path);
    160     }
     162      // exit if remove failed
     163      if (node_exist(target_path)) {
     164        std::cerr << "svndigest: remove failed\n";
     165        exit(-1);
     166      }
     167    }
     168
    161169
    162170    if (option->verbose())
Note: See TracChangeset for help on using the changeset viewer.