source: trunk/bin/Parameter.cc @ 1293

Last change on this file since 1293 was 1293, checked in by Peter Johansson, 11 years ago

rewrite svndigest-copy-cache in C++. closes #463

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.1 KB
Line 
1// $Id: Parameter.cc 1293 2010-11-14 05:34:10Z peter $
2
3/*
4  Copyright (C) 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
5  Copyright (C) 2009, 2010 Peter Johansson
6
7  This file is part of svndigest, http://dev.thep.lu.se/svndigest
8
9  svndigest is free software; you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 3 of the License, or
12  (at your option) any later version.
13
14  svndigest is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with svndigest. If not, see <http://www.gnu.org/licenses/>.
21*/
22
23#include <config.h> // this header file is created by configure
24
25#include "Parameter.h"
26
27#include "lib/utility.h"
28
29#include "yat/ColumnStream.h"
30#include "yat/Exception.h"
31#include "yat/OptionArg.h"
32#include "yat/OptionHelp.h"
33#include "yat/OptionSwitch.h"
34
35#include <cassert>
36#include <cerrno>
37#include <cstddef>
38#include <cstring>
39#include <fstream>
40#include <iostream>
41#include <sstream>
42#include <stdexcept>
43#include <string>
44#include <sys/stat.h>
45
46namespace theplu {
47namespace svndigest {
48
49  Parameter::Parameter(void)
50    : config_file_(cmd_, "config-file", 
51                   "configuration file [<ROOT>/.svndigest/config]"),
52      generate_config_(cmd_, "g,generate-config", 
53                       "write configuration to standard output"),
54      ignore_cache_(cmd_, "ignore-cache", 
55                    std::string("ignore cache files and analyze ") +
56                    std::string("everything from repository"))
57  {
58  }
59
60
61  Parameter::~Parameter(void)
62  {
63  }
64
65
66  void Parameter::analyse1(void)
67  {
68    std::string save_wd = pwd();
69
70    // check root but not if -g option given
71    if (!generate_config()) {
72      analyse_root(root_.value());
73    }
74
75    // check config file
76    struct stat nodestat;
77    // true also if there is a broken symlink named...
78    bool config_exists = !lstat(config_file_.value().c_str(), &nodestat);
79    // the latter case in order to catch broken symlink
80    if (config_file_.present() || config_exists)
81      // throws if file does not exists
82      check_existence(config_file_.value());
83    if (config_exists) {
84      // throws if file is not readable
85      check_readable(config_file_.value());
86      stat(config_file_.value().c_str(), &nodestat);
87      if (S_ISDIR(nodestat.st_mode)) {
88        std::stringstream ss;
89        ss << cmd_.program_name() << ": '" << config_file_.value() 
90           << "' is a directory";
91        throw yat::utility::cmd_error(ss.str());
92      }
93    }
94    analyse2();
95  }
96
97
98  std::string Parameter::config_file(void) const
99  {
100    return config_file_.value();
101  }
102
103
104  bool Parameter::generate_config(void) const
105  {
106    return generate_config_.present();
107  }
108
109
110  bool Parameter::ignore_cache(void) const
111  {
112    return ignore_cache_.present();
113  }
114
115
116  void Parameter::init1(void)
117  {
118    config_file_.print_arg("=FILE");
119    init2();
120  }
121
122
123  void Parameter::set_default1(void)
124  {
125    if (!config_file_.present())
126      config_file_.value(concatenate_path(root_.value(),".svndigest/config"));
127
128    set_default2();
129  }
130
131
132}} // of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.