Changeset 979
- Timestamp:
- Oct 21, 2007, 9:46:14 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/commandline_test.cc
r975 r979 34 34 bool test_switch(std::ostream& error); 35 35 bool test_arg(std::ostream& error); 36 bool test_file(std::ostream& error); 36 37 bool test_failures(std::ostream& error); 37 38 … … 56 57 ok &= test_switch(*error); 57 58 ok &= test_arg(*error); 59 ok &= test_file(*error); 58 60 ok &= test_failures(*error); 59 61 } … … 342 344 343 345 344 345 346 347 346 bool test_file(std::ostream& error) 347 { 348 bool ok=true; 349 CommandLine cmd; 350 OptionFile inclones(cmd, "clones", "file containing clones"); 351 OptionFile indata(cmd, "data", "data to merge"); 352 OptionSwitch help(cmd, "h,help", "display this help and exit"); 353 354 error << "Testing OptionFile... "; 355 { 356 int ac = 2; 357 char* av[] = { "test_prog", "-h" }; 358 cmd.parse(ac,av); 359 error << "ok\n"; 360 } 361 return ok; 362 } 363 364 365 366 367 -
trunk/yat/utility/CommandLine.cc
r975 r979 159 159 while (std::getline(ss, str, del)){ 160 160 vec.push_back(str); 161 std::cout << "split: push_back() " << vec.back() << std::endl;162 161 } 163 162 return vec; -
trunk/yat/utility/OptionFile.cc
r975 r979 34 34 OptionFile::OptionFile(CommandLine& cmd, std::string flag, 35 35 std::string desc, bool exist, std::string bits) 36 : OptionArg< char*>(cmd, flag, desc), exist_(exist), bits_(bits)36 : OptionArg<std::string>(cmd, flag, desc), exist_(exist), bits_(bits) 37 37 { 38 38 } … … 41 41 void OptionFile::do_validate() const 42 42 { 43 FileUtil fu(value()); 43 if (!present()) 44 return; 45 FileUtil fu(value().c_str()); 44 46 if (exist_ && !fu.exists()){ 45 47 std::stringstream ss; … … 47 49 throw std::runtime_error(ss.str()); 48 50 } 49 // Peter, this loop is stupid but I wanna differentiate the error message 50 for (size_t i=0; i<bits_.length(); ++i) 51 switch (bits_[i]) { 52 case 'r': 53 if (fu.permissions("r")){ 51 if (fu.permissions(bits_)) { 52 // Peter, this loop is stupid but I wanna differentiate the error message 53 for (std::string::const_iterator iter; iter!=bits_.end(); ++iter){ 54 if (*iter=='r' && fu.permissions("r")){ 54 55 std::stringstream ss; 55 56 ss << "cannot stat `" << value() << "': No such file or directory"; 56 57 throw std::runtime_error(ss.str()); 57 58 } 58 break; 59 case 'w': 60 if (fu.permissions("w")){ 59 else if (*iter=='w' && fu.permissions("w")){ 61 60 std::stringstream ss; 62 61 ss << "cannot create file `" << value() … … 64 63 throw std::runtime_error(ss.str()); 65 64 } 66 break;67 case 'x':68 if (fu.permissions("w")){69 std::stringstream ss;70 ss << value() << ": Permission denied";71 throw std::runtime_error(ss.str());72 }73 break;74 65 } 66 std::stringstream ss; 67 ss << value() << ": Permission denied"; 68 throw std::runtime_error(ss.str()); 69 } 75 70 } 76 71 -
trunk/yat/utility/OptionFile.h
r975 r979 37 37 \brief Class for file related options 38 38 */ 39 class OptionFile : public OptionArg< char*>39 class OptionFile : public OptionArg<std::string> 40 40 { 41 41 public: … … 44 44 45 45 \param cmd Commandline Option is associated with 46 \param name string such as "file" for --file, "f" for - hor46 \param name string such as "file" for --file, "f" for -f or 47 47 "f,file" for having both short and long option name 48 48 \param desc string used in help display 49 49 \param exist if true File must exist 50 \param bits used to check permission on file, @see51 FileUtil ::permission50 \param bits used to check permission on file, see 51 FileUtil 52 52 */ 53 53 OptionFile(CommandLine& cmd, std::string name,
Note: See TracChangeset
for help on using the changeset viewer.