Changeset 646 for branches/replacing_gnuplot/bin
- Timestamp:
- Jun 4, 2008, 12:05:22 AM (15 years ago)
- Location:
- branches/replacing_gnuplot/bin
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/replacing_gnuplot/bin/Makefile.am
r585 r646 30 30 noinst_HEADERS = Parameter.h 31 31 32 LDADD = $(STATICFLAG) @top_builddir@/lib/libsvndigest.la 32 LDADD = @top_builddir@/lib/libsvndigest.la $(SVNDIGEST_LIBS) 33 AM_LDFLAGS = $(STATICFLAG) $(SVNDIGEST_LDFLAGS) 33 34 34 AM_CPPFLAGS = -I@top_srcdir@/lib 35 AM_CPPFLAGS = -I@top_srcdir@/lib $(SVNDIGEST_CPPFLAGS) 36 AM_CXXFLAGS = $(SVNDIGEST_CXXFLAGS) 37 35 38 36 39 # install versioned binary (excluding patch version) -
branches/replacing_gnuplot/bin/Parameter.cc
r581 r646 42 42 43 43 Parameter::Parameter( int argc, char *argv[]) 44 { 45 defaults(); 44 : config_file_(""), copyright_(false), force_(false), 45 generate_config_(false), ignore_cache_(false), report_(true), 46 revisions_(false), root_("."), root_node_("."), targetdir_("."), 47 verbose_(false) 48 { 46 49 for (int i=1; i<argc; ++i) { 47 bool ok=false;48 50 std::stringstream ss(argv[i]); 49 51 std::string myargv(""); … … 54 56 if (myargv=="--config-file"){ 55 57 if (value.size()) { 56 config_file_= value; 57 ok=true; 58 config_file_.value()= value; 58 59 } 59 60 else if (++i<argc){ 60 config_file_= std::string(argv[i]); 61 ok=true; 61 config_file_.value()= std::string(argv[i]); 62 } 63 else { 64 missing_argument(myargv); 62 65 } 63 66 } 64 67 else if (myargv=="--copyright"){ 65 copyright_=true; 66 ok=true; 68 copyright_.value()=true; 67 69 } 68 70 else if (myargv=="-f" || myargv=="--force"){ 69 force_=true; 70 ok=true; 71 force_.value()=true; 71 72 } 72 73 else if (myargv=="-g" || myargv=="--generate-config"){ 73 generate_config_=true; 74 ok=true; 74 generate_config_.value()=true; 75 75 } 76 76 else if (myargv=="-h" || myargv=="--help"){ … … 79 79 } 80 80 else if (myargv=="--ignore-cache"){ 81 ignore_cache_=true; 82 ok=true; 81 ignore_cache_.value()=true; 83 82 } 84 83 else if (myargv=="-r" || myargv=="--root"){ 85 84 if (value.size()) { 86 root_= value; 87 ok=true; 85 root_.value()= value; 88 86 } 89 87 else if (++i<argc){ 90 root_= std::string(argv[i]); 91 ok=true; 88 root_.value()= std::string(argv[i]); 89 } 90 else { 91 missing_argument(myargv); 92 92 } 93 93 } 94 94 else if (myargv=="--report") { 95 report_=true; 96 ok=true; 95 report_.value()=true; 97 96 } 98 97 else if (myargv=="--no-report") { 99 report_=false; 100 ok=true; 98 report_.value()=false; 101 99 } 102 100 else if (myargv=="--revisions") { 103 revisions_=true; 104 ok=true; 101 revisions_.value()=true; 105 102 } 106 103 else if (myargv=="-t" || myargv=="--target"){ 107 104 if (value.size()) { 108 targetdir_= value; 109 ok=true; 105 targetdir_.value()= value; 110 106 } 111 107 else if (++i<argc){ 112 targetdir_= std::string(argv[i]); 113 ok=true; 108 targetdir_.value()= std::string(argv[i]); 109 } 110 else { 111 missing_argument(myargv); 114 112 } 115 113 } 116 114 else if (myargv=="-v" || myargv=="--verbose"){ 117 verbose_=true; 118 ok=true; 115 verbose_.value()=true; 119 116 } 120 117 else if (myargv=="--version"){ 121 version _=true;122 ok=true;118 version(); 119 exit(0); 123 120 } 124 121 else if (myargv=="-vf" || myargv=="-fv"){ 125 verbose_=true; 126 force_=true; 127 ok=true; 128 } 129 130 if (!ok) 122 verbose_.value()=true; 123 force_.value()=true; 124 } 125 else { 131 126 throw std::runtime_error("svndigest: invalid option: " + myargv + 132 127 "\nTry `svndigest --help' for usage."); 128 } 129 } 130 131 analyse(); 132 } 133 134 135 void Parameter::analyse(void) 136 { 137 using namespace std; 138 139 string workdir(pwd()); // remember current working directory (cwd). 140 141 if (!node_exist(root_.value())) 142 throw runtime_error(string("svndigest: cannot stat `" + root_.value() + 143 "': no such file or directory")); 144 145 if (access_rights(root_.value(), "r")) 146 throw runtime_error(string("svndigest: cannot open `" + root_.value() + 147 "' for reading: Permission denied")); 148 149 // Check whether root is directory or file 150 struct stat nodestat; 151 stat(root_.value().c_str(), &nodestat); 152 if (S_ISDIR(nodestat.st_mode)) { 153 chdir(root_.value().c_str()); 154 root_node_.value() = root_.value() = pwd(); 133 155 } 134 135 if (version_){ 136 version(verbose_); 137 exit(0); 138 } 139 analyse(); 140 } 141 142 143 void Parameter::analyse(void) 144 { 145 using namespace std; 146 147 string workdir(pwd()); // remember current working directory (cwd). 148 149 bool root_ok = node_exist(root_) && !access_rights(root_, "r"); 150 151 if (root_ok) { 152 // Check that root_ is a directory 153 struct stat nodestat; 154 stat(root_.c_str(), &nodestat); 155 if (!S_ISDIR(nodestat.st_mode)) 156 throw runtime_error(string("svndigest: accessing `") + root_ + 157 "': Not a directory."); 156 else { 157 std::string fname = file_name(root_.value()); 158 root_.value() = directory_name(root_.value()); 159 chdir(root_.value().c_str()); 160 root_.value() = pwd(); 161 root_node_.value() = root_.value() + "/" + fname; 158 162 } 159 160 // Checking that root_ exists and retrieve the absolute path to root_161 if (!root_ok || chdir(root_.c_str()))162 throw runtime_error(string("svndigest: Root directory (") + root_ +163 ") access failed.");164 root_ = pwd();165 166 167 163 168 164 // need to get back to cwd if relative paths are used. … … 172 168 // Checking that targetdir_ exists and retrieve the absolute path 173 169 // to targetdir_ 174 if (chdir(targetdir_.c_str())) 175 throw runtime_error(string("svndigest: Target directory (") + targetdir_ + 176 ") access failed."); 177 targetdir_ = pwd(); 178 // Checking write permissions for targetdir_ 179 if (access_rights(targetdir_,"w")) 180 throw runtime_error(string("svndigest: No write permission on target ") + 181 "directory (" + targetdir_ +")."); 170 if (report()) { 171 if (chdir(targetdir_.value().c_str())) 172 throw runtime_error(string("svndigest: Target directory (") + 173 targetdir_.value() + ") access failed."); 174 targetdir_.value() = pwd(); 175 // Checking write permissions for targetdir_ 176 if (access_rights(targetdir_.value(),"w")) 177 throw runtime_error(string("svndigest: No write permission on target ") + 178 "directory (" + targetdir_.value() +")."); 179 } 182 180 183 181 // return back to cwd … … 191 189 { 192 190 // not default 193 if (!config_file_. empty())194 return config_file_ ;191 if (!config_file_.value().empty()) 192 return config_file_.value(); 195 193 196 194 // default behaviour … … 199 197 200 198 201 void Parameter::defaults(void) 202 { 203 config_file_ = ""; 204 copyright_=false; 205 force_=false; 206 generate_config_=false; 207 ignore_cache_=false; 208 report_=true; 209 revisions_=false; 210 root_="."; 211 targetdir_="."; 212 verbose_=false; 213 version_=false; 214 } 215 216 217 void Parameter::help(void) 218 { 219 defaults(); 220 199 void Parameter::help(void) const 200 { 221 201 ColumnStream cs(std::cout, 1); 222 202 cs.width(0)=79; 223 203 cs.margin(0)=0; 224 204 ColumnStream cs2(std::cout, 2); 225 cs2.width(0)=24; 205 // Widest line should fit exactly 206 cs2.width(0)=21; 226 207 cs2.width(1)=52; 227 208 cs2.margin(0)=2; 209 // Gnits standard suggest three characters gap between option and description 210 cs2.margin(1)=3; 228 211 229 212 std::cout << "Usage: svndigest [OPTION]...\n" … … 235 218 << "short options too.\n"; 236 219 237 cs2 << " --copyright\tupdate copyright statement\n" 238 << " --config-file=ARG\tconfiguration file " 220 cs2 << " --config-file=ARG\tconfiguration file " 239 221 << "[<ROOT>/.svndigest/config]\n" 222 << " --copyright\tupdate copyright statement\n" 240 223 << "-f, --force\tif sub-directory named <ROOT> exists in " 241 224 << "target directory, remove sub-directory before writing results\n" … … 243 226 << "to standard output and exit\n" 244 227 << "-h, --help\tdisplay this help and exit\n" 245 << " --ignore-cache\t Ignore cache files and analyze "228 << " --ignore-cache\tignore cache files and analyze " 246 229 << "everything from repository\n" 247 << " --no-report\t Create no HTML report\n"248 << " --revisions\t Use revision numbers as time scale "230 << " --no-report\tcreate no HTML report\n" 231 << " --revisions\tuse revision numbers as time scale " 249 232 << "instead of dates [dates]\n" 250 233 << "-r, --root=ROOT\tsvn controlled directory to perform " 251 << "statistics calculation on [" << root_ << "]\n" 252 << "-t, --target=TARGET\toutput directory [" << targetdir_ << "]\n" 234 << "statistics calculation on [" << root_.default_value() << "]\n" 235 << "-t, --target=TARGET\toutput directory [" 236 << targetdir_.default_value() << "]\n" 253 237 << "-v, --verbose\texplain what is being done\n" 254 238 << " --version\tprint version information and exit\n"; … … 259 243 260 244 245 void Parameter::missing_argument(std::string opt) const 246 { 247 if (opt.size()>0 && opt[0]=='-') 248 opt = opt.substr(1); 249 if (opt.size()>0 && opt[0]=='-') 250 opt = opt.substr(1); 251 std::stringstream ss; 252 ss << "svndigest: option requires an argument -- " << opt << "\n" 253 << "Try `svndigest --help' for usage."; 254 throw std::runtime_error(ss.str()); 255 } 256 261 257 void Parameter::version(bool verbose) const 262 258 { 263 259 ColumnStream cs(std::cout, 1); 264 260 cs.width(0)=79; 265 cs << PACKAGE_STRING; 266 cs << " ("; 267 if (DEV_BUILD) 268 cs << "r" << svn_revision() << " "; 269 cs << "compiled " << __DATE__ ", " << __TIME__ << ")\n"; 270 261 cs << PACKAGE_STRING << version_string() << "\n"; 271 262 cs << "\nCopyright (C) " << svn_year() 272 263 << " Jari H\u00E4kkinen and Peter Johansson.\n" -
branches/replacing_gnuplot/bin/Parameter.h
r540 r646 26 26 */ 27 27 28 #include "Option.h" 29 28 30 #include <map> 29 31 #include <string> … … 37 39 Parameter( int argc, char *argv[]); 38 40 std::string config_file(void) const; 39 inline bool copyright(void) const { return copyright_ ; }41 inline bool copyright(void) const { return copyright_.value(); } 40 42 /// @todo 41 inline bool force(void) const { return force_; } 42 inline bool generate_config(void) const { return generate_config_; } 43 inline bool ignore_cache(void) const { return ignore_cache_; } 44 inline bool report(void) const { return report_; } 45 inline bool revisions(void) const { return revisions_; } 43 inline bool force(void) const { return force_.value(); } 44 inline bool generate_config(void) const { return generate_config_.value(); } 45 // Until we fix caching (#313) ignore caching 46 //inline bool ignore_cache(void) const { return ignore_cache_.value(); } 47 inline bool ignore_cache(void) const { return true; } 48 inline bool report(void) const { return report_.value(); } 49 inline bool revisions(void) const { return revisions_.value(); } 46 50 /// @return absolute path to root directory 47 inline const std::string& root(void) const { return root_; } 51 inline const std::string& root(void) const { return root_.value(); } 52 /// @return absolute path to root node 53 inline const std::string& root_node(void) const {return root_node_.value();} 48 54 /// @return absolute path to target directory 49 inline const std::string& targetdir(void) const { return targetdir_; } 50 inline bool verbose(void) const { return verbose_; } 55 inline const std::string& targetdir(void) const 56 { return targetdir_.value(); } 57 inline bool verbose(void) const { return verbose_.value(); } 51 58 52 59 private: 53 60 void analyse(void); 54 void defaults(void);55 void help(void);61 void help(void) const; 62 void missing_argument(std::string opt) const; 56 63 void version(bool=false) const; 57 64 58 std::stringconfig_file_;59 boolcopyright_;60 boolforce_;61 boolgenerate_config_;62 boolignore_cache_;63 boolreport_;64 boolrevisions_;65 std::stringroot_;66 std::string targetdir_;67 bool verbose_;68 bool version_;65 Option<std::string> config_file_; 66 Option<bool> copyright_; 67 Option<bool> force_; 68 Option<bool> generate_config_; 69 Option<bool> ignore_cache_; 70 Option<bool> report_; 71 Option<bool> revisions_; 72 Option<std::string> root_; 73 Option<std::string> root_node_; 74 Option<std::string> targetdir_; 75 Option<bool> verbose_; 69 76 }; 70 77 -
branches/replacing_gnuplot/bin/svndigest.cc
r579 r646 160 160 if (option->verbose()) 161 161 std::cout << "Generating output" << std::endl; 162 if (!option->revisions()) 163 GnuplotFE::instance()->set_dates(SVNlog(repo).date()); 162 if (!option->revisions()) { 163 SVNlog log(repo); 164 std::vector<std::string> dates; 165 dates.reserve(log.commits().size()); 166 for (size_t i=0; i<log.commits().size(); ++i) { 167 assert(static_cast<svn_revnum_t>(i)==log.commits()[i].revision()); 168 dates.push_back(log.commits()[i].date()); 169 } 170 GnuplotFE::instance()->set_dates(dates); 171 } 164 172 chdir(option->targetdir().c_str()); 165 173 mkdir(tree->name());
Note: See TracChangeset
for help on using the changeset viewer.