- Timestamp:
- Mar 11, 2007, 8:32:41 PM (17 years ago)
- Location:
- trunk/bin
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bin/Parameter.cc
r198 r226 3 3 /* 4 4 Copyright (C) 2006 Jari Häkkinen, Peter Johansson 5 Copyright (C) 2007 Peter Johansson 5 6 6 7 This file is part of svndigest, http://lev.thep.lu.se/trac/svndigest … … 26 27 #include <config.h> // this header file is created by configure 27 28 29 #include <fstream> 28 30 #include <iostream> 31 #include <sstream> 29 32 #include <stdexcept> 30 33 #include <string> … … 40 43 bool ok=false; 41 44 std::string myargv(argv[i]); 42 if (myargv=="-f" || myargv=="--force"){ 45 if (myargv=="-c" || myargv=="--config"){ 46 if (++i<argc){ 47 config_path_= std::string(argv[i]); 48 ok=true; 49 } 50 } 51 else if (myargv=="--copyright"){ 52 copyright_=true; 53 ok=true; 54 } 55 else if (myargv=="-f" || myargv=="--force"){ 43 56 force_=true; 44 ok=true;45 }46 if (myargv=="--copyright"){47 copyright_=true;48 57 ok=true; 49 58 } … … 86 95 "\nType 'svndigest --help' for usage."); 87 96 } 97 98 std::string home_path = getenv("HOME") + "/.svndigest"; 99 if (!node_exist(home_path)) 100 mkdir(home_path); 101 if (!node_exist(home_path+"/config")) 102 print_config(home_path+"/config"); 103 read_config(config_path_); 88 104 89 105 analyse(); … … 126 142 void Parameter::defaults(void) 127 143 { 144 config_path_ = getenv("HOME")+"/.svndigest/config"; 128 145 copyright_=false; 129 146 force_=false; … … 149 166 << "\n" 150 167 << "Valid options:\n" 168 << " -c [--config] arg : path to config file [" 169 << config_path_ << "]\n" 151 170 << " -f [--force] : remove target directory/file if it exists\n" 152 171 << " [no force]. NOTE recursive delete.\n" … … 165 184 166 185 186 void Parameter::print_config(std::string path) const 187 { 188 std::ofstream os(path.c_str()); 189 if (!os.good()){ 190 os.close(); 191 throw std::runtime_error("svndigest: error: cannot create file '" + 192 path + "': permission denied"); 193 } 194 os << "### This file configures various behaviors for svndigest\n" 195 << "### The commented-out below are intended to demonstrate how to use\n" 196 << "### this file.\n" 197 << "\n" 198 << "### Section for setting aliases used in copyright update\n" 199 << "#[copyright-alias]\n" 200 << "# jdoe = John Doe\n" 201 << std::endl; 202 os.close(); 203 } 204 205 206 void Parameter::read_config(std::string path) 207 { 208 if (!node_exist(path)) 209 throw std::runtime_error("svndigest: error: configuration file '" + 210 path + "' not found"); 211 std::ifstream is(path.c_str()); 212 if (!is.good()){ 213 is.close(); 214 throw std::runtime_error("svndigest: error: cannot open file '" + path + 215 "' for reading"); 216 } 217 std::string line; 218 std::string section; 219 std::string tmp; 220 while (getline(is, line)) { 221 line = ltrim(line); 222 if (line.empty() || line[0]=='#') 223 continue; 224 std::stringstream ss(line); 225 if (line[0] == '[') { 226 getline(ss, tmp, '['); 227 getline(ss, section, ']'); 228 } 229 else if (section == "copyright-alias"){ 230 getline(ss, tmp, '='); 231 std::string key = trim(tmp); 232 getline(ss, tmp); 233 std::string name = trim(tmp); 234 copyright_alias_[key] = name; 235 } 236 } 237 is.close(); 238 } 239 240 167 241 void Parameter::version(void) const 168 242 { 169 243 using namespace std; 170 244 cout << PACKAGE_STRING 171 << "\nCopyright (C) 2006 Jari Häkkinen and Peter Johansson.\n\n"245 << "\nCopyright (C) 2006-2007 Jari Häkkinen and Peter Johansson.\n\n" 172 246 << "This is free software; see the source for copying conditions.\n" 173 247 << "There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR\n" -
trunk/bin/Parameter.h
r225 r226 52 52 void defaults(void); 53 53 void help(void); 54 void print_config(std::string) const; 55 void read_config(std::string); 54 56 void version(void) const; 55 57 58 std::string config_path_; 56 59 bool copyright_; 57 60 std::map<std::string, std::string> copyright_alias_; -
trunk/bin/svndigest.cc
r225 r226 40 40 #include <unistd.h> 41 41 42 ///43 /// @brief Check whether \a path already exists or not.44 ///45 /// @return True if \a path exists, false otherwise.46 ///47 bool check_target(const std::string& path)48 {49 struct stat buf;50 return !stat(path.c_str(),&buf);51 }52 53 54 42 int main(const int argc,const char* argv[]) 55 43 { … … 83 71 std::cout << "Checking target directory" << std::endl; 84 72 std::string target_path=option->targetdir() + '/' + file_name(option->root()); 85 bool need_to_erase_target = check_target(target_path);73 bool need_to_erase_target = node_exist(target_path); 86 74 if (need_to_erase_target && !option->force()) 87 75 throw std::runtime_error(std::string("svndigest: directory (") + … … 162 150 if (option->copyright()){ 163 151 try { 164 tree.print_copyright(commit_dates, authors );152 tree.print_copyright(commit_dates, authors, option->copyright_alias()); 165 153 } 166 154 catch (const std::runtime_error& x) {
Note: See TracChangeset
for help on using the changeset viewer.