this repo has no description
at fixPythonPipStalling 144 lines 4.2 kB view raw
1#include <iostream> 2#include <map> 3#include <string> 4#include "ResourceFile.h" 5#include "boost/program_options.hpp" 6namespace po = boost::program_options; 7using std::map; 8using std::string; 9 10static po::options_description desc; 11 12map<string,ResourceFile::Format> formats { 13#ifdef __APPLE__ 14 {"real", ResourceFile::Format::real}, 15#endif 16 {"macbin", ResourceFile::Format::macbin}, 17 {"basilisk", ResourceFile::Format::basilisk}, 18 {"applesingle", ResourceFile::Format::applesingle}, 19 {"underscore_appledouble", ResourceFile::Format::underscore_appledouble} 20}; 21map<ResourceFile::Format,string> reverseFormats; 22 23static void usage() 24{ 25 std::cerr << "Usage: " << "ResInfo [options] input-file\n"; 26 std::cerr << desc << std::endl; 27 std::cerr << "Available Resource Fork formats are:\n"; 28 for(auto p : formats) 29 std::cerr << " " << p.first << std::endl; 30} 31 32 33int main(int argc, char *argv[]) 34{ 35 desc.add_options() 36 ("help,h", "show this help message") 37 ("type,t", "print file type") 38 ("creator,c", "print creator code") 39 ("all,a", "print all info") 40 ("format,f", "print format") 41 ("count,n", "print number of resources") 42 ("size,s", "show data fork size") 43 ("filename,l", "echo input file name") 44 ("set-format,F", po::value<string>(), "resource fork format)") 45 ; 46 po::options_description hidden, alldesc; 47 hidden.add_options() 48 ("input", po::value<std::vector<string>>(), "input file" ) 49 ; 50 alldesc.add(desc).add(hidden); 51 52 po::variables_map options; 53 try 54 { 55 auto parsed = po::command_line_parser(argc, argv) 56 .options(alldesc) 57 .positional(po::positional_options_description().add("input", -1)) 58 .style(po::command_line_style::default_style) 59 .run(); 60 61 po::store(parsed, options); 62 } 63 catch(po::error& e) 64 { 65 std::cerr << "ERROR: " << e.what() << std::endl << std::endl; 66 usage(); 67 return 1; 68 } 69 70 po::notify(options); 71 72 if(options.count("help") || !options.count("input")) 73 { 74 usage(); 75 return 0; 76 } 77 78 for(auto p : formats) 79 reverseFormats[p.second] = p.first; 80 81 bool showFilename = options.count("filename"); 82 bool showType = options.count("type") != 0; 83 bool showCreator = options.count("creator") != 0; 84 bool showFormat = options.count("format") != 0; 85 bool showCount = options.count("count") != 0; 86 bool showSize = options.count("size") != 0; 87 88 ResourceFile::Format format = ResourceFile::Format::autodetect; 89 90 if(options.count("all")) 91 showType = showCreator = showFormat = showCount = showSize = true; 92 93 if(options.count("set-format")) 94 { 95 string s = options["set-format"].as<string>(); 96 if(formats.find(s) != formats.end()) 97 format = formats[s]; 98 else 99 { 100 std::cerr << "Unknown format " << s << std::endl << std::endl; 101 usage(); 102 exit(1); 103 } 104 } 105 106 if(options.count("input")) 107 for(std::string fn : options["input"].as<std::vector<std::string>>()) 108 { 109 ResourceFile rsrcFile; 110 111 if(!rsrcFile.read(fn, format)) 112 { 113 std::cerr << "Can't read file.\n"; 114 return 1; 115 } 116 117 std::ostringstream out; 118 if(showType) 119 out << " " << rsrcFile.type; 120 if(showCreator) 121 out << " " << rsrcFile.creator; 122 if(showFormat) 123 out << " " << reverseFormats[rsrcFile.getFormat()]; 124 if(showCount) 125 out << " " << rsrcFile.resources.resources.size(); 126 if(showSize) 127 out << " " << rsrcFile.data.size(); 128 129 string str = out.str(); 130 if(str.size()) 131 { 132 if(showFilename) 133 std::cout << fn << ": "; 134 std::cout << out.str().substr(1) << std::endl; 135 } 136 else 137 { 138 if(showFilename) 139 std::cout << fn << std::endl; 140 } 141 } 142 143 return 0; 144}