Switch tab-indented files to 4-space indent

This commit is contained in:
Wolfgang Thaller
2019-08-18 13:21:00 +02:00
parent 9cb90cb3b0
commit e5185d23c3
133 changed files with 7879 additions and 7866 deletions
+18 -18
View File
@@ -6,45 +6,45 @@
void byte(std::ostream& out, int byte)
{
out.put((unsigned char)byte);
out.put((unsigned char)byte);
}
void word(std::ostream& out, int word)
{
byte(out,(word >> 8) & 0xFF);
byte(out,word & 0xFF);
byte(out,(word >> 8) & 0xFF);
byte(out,word & 0xFF);
}
void ostype(std::ostream& out, ResType type)
{
longword(out, type);
longword(out, type);
}
void longword(std::ostream& out, int longword)
{
byte(out,(longword >> 24) & 0xFF);
byte(out,(longword >> 16) & 0xFF);
byte(out,(longword >> 8) & 0xFF);
byte(out,longword & 0xFF);
byte(out,(longword >> 24) & 0xFF);
byte(out,(longword >> 16) & 0xFF);
byte(out,(longword >> 8) & 0xFF);
byte(out,longword & 0xFF);
}
int byte(std::istream& in)
{
return in.get() & 0xFF;
return in.get() & 0xFF;
}
int word(std::istream& in)
{
int a = byte(in);
int b = byte(in);
return (a << 8) | b;
int a = byte(in);
int b = byte(in);
return (a << 8) | b;
}
ResType ostype(std::istream& in)
{
return longword(in);
return longword(in);
}
int longword(std::istream& in)
{
int a = byte(in);
int b = byte(in);
int c = byte(in);
int d = byte(in);
return (a << 24) | (b << 16) | (c << 8) | d;
int a = byte(in);
int b = byte(in);
int c = byte(in);
int d = byte(in);
return (a << 24) | (b << 16) | (c << 8) | d;
}
+7 -7
View File
@@ -18,16 +18,16 @@
find_package(Boost COMPONENTS filesystem system REQUIRED)
add_library(ResourceFiles
ResourceFork.h ResourceFork.cc
BinaryIO.h BinaryIO.cc
ResType.h ResType.cc
ResourceFile.h ResourceFile.cc
)
ResourceFork.h ResourceFork.cc
BinaryIO.h BinaryIO.cc
ResType.h ResType.cc
ResourceFile.h ResourceFile.cc
)
target_link_libraries(ResourceFiles ${Boost_LIBRARIES} ${CMAKE_INSTALL_PREFIX}/lib/libhfs.a)
target_include_directories(ResourceFiles PUBLIC .
PRIVATE ${CMAKE_INSTALL_PREFIX}/include
${Boost_INCLUDE_DIR})
PRIVATE ${CMAKE_INSTALL_PREFIX}/include
${Boost_INCLUDE_DIR})
find_package(Boost COMPONENTS program_options REQUIRED)
+110 -110
View File
@@ -11,134 +11,134 @@ static po::options_description desc;
map<string,ResourceFile::Format> formats {
#ifdef __APPLE__
{"real", ResourceFile::Format::real},
{"real", ResourceFile::Format::real},
#endif
{"macbin", ResourceFile::Format::macbin},
{"basilisk", ResourceFile::Format::basilisk},
{"applesingle", ResourceFile::Format::applesingle},
{"underscore_appledouble", ResourceFile::Format::underscore_appledouble}
{"macbin", ResourceFile::Format::macbin},
{"basilisk", ResourceFile::Format::basilisk},
{"applesingle", ResourceFile::Format::applesingle},
{"underscore_appledouble", ResourceFile::Format::underscore_appledouble}
};
map<ResourceFile::Format,string> reverseFormats;
static void usage()
{
std::cerr << "Usage: " << "ResInfo [options] input-file\n";
std::cerr << desc << std::endl;
std::cerr << "Available Resource Fork formats are:\n";
for(auto p : formats)
std::cerr << " " << p.first << std::endl;
std::cerr << "Usage: " << "ResInfo [options] input-file\n";
std::cerr << desc << std::endl;
std::cerr << "Available Resource Fork formats are:\n";
for(auto p : formats)
std::cerr << " " << p.first << std::endl;
}
int main(int argc, char *argv[])
{
desc.add_options()
("help,h", "show this help message")
("type,t", "print file type")
("creator,c", "print creator code")
("all,a", "print all info")
("format,f", "print format")
("count,n", "print number of resources")
("size,s", "show data fork size")
("filename,l", "echo input file name")
("set-format,F", po::value<string>(), "resource fork format)")
;
po::options_description hidden, alldesc;
hidden.add_options()
("input", po::value<std::vector<string>>(), "input file" )
;
alldesc.add(desc).add(hidden);
desc.add_options()
("help,h", "show this help message")
("type,t", "print file type")
("creator,c", "print creator code")
("all,a", "print all info")
("format,f", "print format")
("count,n", "print number of resources")
("size,s", "show data fork size")
("filename,l", "echo input file name")
("set-format,F", po::value<string>(), "resource fork format)")
;
po::options_description hidden, alldesc;
hidden.add_options()
("input", po::value<std::vector<string>>(), "input file" )
;
alldesc.add(desc).add(hidden);
po::variables_map options;
try
{
auto parsed = po::command_line_parser(argc, argv)
.options(alldesc)
.positional(po::positional_options_description().add("input", -1))
.style(po::command_line_style::default_style)
.run();
po::variables_map options;
try
{
auto parsed = po::command_line_parser(argc, argv)
.options(alldesc)
.positional(po::positional_options_description().add("input", -1))
.style(po::command_line_style::default_style)
.run();
po::store(parsed, options);
}
catch(po::error& e)
{
std::cerr << "ERROR: " << e.what() << std::endl << std::endl;
usage();
return 1;
}
po::store(parsed, options);
}
catch(po::error& e)
{
std::cerr << "ERROR: " << e.what() << std::endl << std::endl;
usage();
return 1;
}
po::notify(options);
po::notify(options);
if(options.count("help") || !options.count("input"))
{
usage();
return 0;
}
for(auto p : formats)
reverseFormats[p.second] = p.first;
if(options.count("help") || !options.count("input"))
{
usage();
return 0;
}
for(auto p : formats)
reverseFormats[p.second] = p.first;
bool showFilename = options.count("filename");
bool showType = options.count("type") != 0;
bool showCreator = options.count("creator") != 0;
bool showFormat = options.count("format") != 0;
bool showCount = options.count("count") != 0;
bool showSize = options.count("size") != 0;
bool showFilename = options.count("filename");
bool showType = options.count("type") != 0;
bool showCreator = options.count("creator") != 0;
bool showFormat = options.count("format") != 0;
bool showCount = options.count("count") != 0;
bool showSize = options.count("size") != 0;
ResourceFile::Format format = ResourceFile::Format::autodetect;
if(options.count("all"))
showType = showCreator = showFormat = showCount = showSize = true;
if(options.count("set-format"))
{
string s = options["set-format"].as<string>();
if(formats.find(s) != formats.end())
format = formats[s];
else
{
std::cerr << "Unknown format " << s << std::endl << std::endl;
usage();
exit(1);
}
}
if(options.count("input"))
for(std::string fn : options["input"].as<std::vector<std::string>>())
{
ResourceFile rsrcFile(fn, format);
if(!rsrcFile.read())
{
std::cerr << "Can't read file.\n";
return 1;
}
std::ostringstream out;
if(showType)
out << " " << rsrcFile.type;
if(showCreator)
out << " " << rsrcFile.creator;
if(showFormat)
out << " " << reverseFormats[rsrcFile.format];
if(showCount)
out << " " << rsrcFile.resources.resources.size();
if(showSize)
out << " " << rsrcFile.data.size();
ResourceFile::Format format = ResourceFile::Format::autodetect;
if(options.count("all"))
showType = showCreator = showFormat = showCount = showSize = true;
if(options.count("set-format"))
{
string s = options["set-format"].as<string>();
if(formats.find(s) != formats.end())
format = formats[s];
else
{
std::cerr << "Unknown format " << s << std::endl << std::endl;
usage();
exit(1);
}
}
if(options.count("input"))
for(std::string fn : options["input"].as<std::vector<std::string>>())
{
ResourceFile rsrcFile(fn, format);
if(!rsrcFile.read())
{
std::cerr << "Can't read file.\n";
return 1;
}
std::ostringstream out;
if(showType)
out << " " << rsrcFile.type;
if(showCreator)
out << " " << rsrcFile.creator;
if(showFormat)
out << " " << reverseFormats[rsrcFile.format];
if(showCount)
out << " " << rsrcFile.resources.resources.size();
if(showSize)
out << " " << rsrcFile.data.size();
string str = out.str();
if(str.size())
{
if(showFilename)
std::cout << fn << ": ";
std::cout << out.str().substr(1) << std::endl;
}
else
{
if(showFilename)
std::cout << fn << std::endl;
}
}
string str = out.str();
if(str.size())
{
if(showFilename)
std::cout << fn << ": ";
std::cout << out.str().substr(1) << std::endl;
}
else
{
if(showFilename)
std::cout << fn << std::endl;
}
}
return 0;
}
+31 -31
View File
@@ -4,55 +4,55 @@
ResType::ResType(const std::string &str)
{
auto p = str.begin();
auto e = str.end();
auto p = str.begin();
auto e = str.end();
assert(str.size() == 4);
assert(str.size() == 4);
x = 0;
while(p != e)
{
x <<= 8;
x |= (*p) & 0xFF;
++p;
}
x = 0;
while(p != e)
{
x <<= 8;
x |= (*p) & 0xFF;
++p;
}
}
ResType::ResType(const char *s)
{
auto p = s;
auto e = s + 4;
auto p = s;
auto e = s + 4;
assert(s[0] && s[1] && s[2] && s[3] && !s[4]);
assert(s[0] && s[1] && s[2] && s[3] && !s[4]);
x = 0;
while(p != e)
{
x <<= 8;
x |= (*p) & 0xFF;
++p;
}
x = 0;
while(p != e)
{
x <<= 8;
x |= (*p) & 0xFF;
++p;
}
}
ResType::operator std::string()
{
char c1 = static_cast<char>(x >> 24);
char c2 = static_cast<char>(x >> 16);
char c3 = static_cast<char>(x >> 8);
char c4 = static_cast<char>(x);
char c1 = static_cast<char>(x >> 24);
char c2 = static_cast<char>(x >> 16);
char c3 = static_cast<char>(x >> 8);
char c4 = static_cast<char>(x);
return std::string{ c1, c2, c3, c4 };
return std::string{ c1, c2, c3, c4 };
}
std::ostream &operator<<(std::ostream &out, ResType t)
{
char c1 = static_cast<char>((int)t >> 24);
char c2 = static_cast<char>((int)t >> 16);
char c3 = static_cast<char>((int)t >> 8);
char c4 = static_cast<char>((int)t);
char c1 = static_cast<char>((int)t >> 24);
char c2 = static_cast<char>((int)t >> 16);
char c3 = static_cast<char>((int)t >> 8);
char c4 = static_cast<char>((int)t);
out << "'" << c1 << c2 << c3 << c4 << "'";
return out;
out << "'" << c1 << c2 << c3 << c4 << "'";
return out;
}
+14 -14
View File
@@ -6,30 +6,30 @@
class ResType
{
int x;
int x;
public:
ResType() : x(0) {}
ResType(int x) : x(x) {}
ResType(const std::string& s);
ResType(const char* s);
ResType() : x(0) {}
ResType(int x) : x(x) {}
ResType(const std::string& s);
ResType(const char* s);
operator int() const { return x; }
bool operator<(ResType y) const { return x < y.x; }
operator int() const { return x; }
bool operator<(ResType y) const { return x < y.x; }
operator std::string();
operator std::string();
};
std::ostream& operator<<(std::ostream& out, ResType t);
struct ResRef : public std::pair<ResType, short>
{
ResRef() : std::pair<ResType, short>(ResType(), 0) {}
ResRef(ResType t, int id) : std::pair<ResType, short>(t,id) {}
ResRef() : std::pair<ResType, short>(ResType(), 0) {}
ResRef(ResType t, int id) : std::pair<ResType, short>(t,id) {}
ResType& type() { return first; }
ResType type() const { return first; }
short& id() { return second; }
short id() const { return second; }
ResType& type() { return first; }
ResType type() const { return first; }
short& id() { return second; }
short id() const { return second; }
};
#endif // RESTYPE_H
File diff suppressed because it is too large Load Diff
+29 -29
View File
@@ -11,44 +11,44 @@
class ResourceFile
{
public:
enum class Format
{
autodetect,
enum class Format
{
autodetect,
#ifdef __APPLE__
real,
real,
#endif
macbin,
diskimage,
basilisk,
applesingle,
underscore_appledouble,
percent_appledouble
};
macbin,
diskimage,
basilisk,
applesingle,
underscore_appledouble,
percent_appledouble
};
ResourceFile();
ResourceFile(std::string path, Format f = Format::autodetect);
~ResourceFile();
ResourceFile();
ResourceFile(std::string path, Format f = Format::autodetect);
~ResourceFile();
bool assign(std::string path, Format f = Format::autodetect);
bool assign(std::string path, Format f = Format::autodetect);
bool read(std::istream& in, Format f);
bool write(std::ostream& in, Format f);
bool read(std::istream& in, Format f);
bool write(std::ostream& in, Format f);
bool read();
bool write();
bool read();
bool write();
static bool hasPlainDataFork(Format f);
bool hasPlainDataFork();
static bool hasPlainDataFork(Format f);
bool hasPlainDataFork();
static bool isSingleFork(Format f);
static bool isSingleFork(Format f);
std::string pathstring;
std::string filename;
Format format;
ResType type;
ResType creator;
Resources resources;
std::string data;
std::string pathstring;
std::string filename;
Format format;
ResType type;
ResType creator;
Resources resources;
std::string data;
};
#endif // RESOURCEFILE_H
+133 -133
View File
@@ -7,156 +7,156 @@
void Resources::addResources(const Resources& res)
{
for(auto& rr : res.resources)
addResource(rr.second);
for(auto& rr : res.resources)
addResource(rr.second);
}
void Resources::writeFork(std::ostream& out) const
{
std::streampos start = out.tellp();
longword(out,0x100);
longword(out,0);
longword(out,0);
longword(out,0);
for(int i = 0; i < 0x100 - 16; i++)
byte(out, 0);
std::streampos start = out.tellp();
longword(out,0x100);
longword(out,0);
longword(out,0);
longword(out,0);
for(int i = 0; i < 0x100 - 16; i++)
byte(out, 0);
std::map< ResType, std::map<int, int> > resourceInfos;
std::streampos datastart = out.tellp();
for(auto& rr : resources)
{
const Resource& r = rr.second;
const std::string& data = r.getData();
unsigned offset = out.tellp() - datastart;
offset = (r.getAttr() << 24) | (offset & 0xFFFFFF);
resourceInfos[ r.getType() ][ r.getID() ] = (int)offset;
longword(out, data.size());
out << data;
}
std::streampos dataend = out.tellp();
std::map< ResType, std::map<int, int> > resourceInfos;
std::streampos datastart = out.tellp();
for(auto& rr : resources)
{
const Resource& r = rr.second;
const std::string& data = r.getData();
unsigned offset = out.tellp() - datastart;
offset = (r.getAttr() << 24) | (offset & 0xFFFFFF);
resourceInfos[ r.getType() ][ r.getID() ] = (int)offset;
longword(out, data.size());
out << data;
}
std::streampos dataend = out.tellp();
// while(out.tellp() % 0x100)
// out.put(0);
std::streampos resmap = out.tellp();
for(int i = 0; i < 16+4+2+2; i++)
byte(out, 0);
word(out,16+4+2+2+2+2); // offset to resource type list
std::streampos resnameOffset = out.tellp();
word(out,0);
std::streampos typelist = out.tellp();
word(out,resourceInfos.size() - 1);
for(std::map< ResType, std::map<int, int> >::iterator p = resourceInfos.begin();
p != resourceInfos.end(); ++p)
{
if(p->second.size())
{
ostype(out,p->first);
word(out,p->second.size()-1);
word(out,0); // replaced later
}
}
int typeIndex = 0;
int nameOffset = 0;
for(std::map< ResType, std::map<int, int> >::iterator p = resourceInfos.begin();
p != resourceInfos.end(); ++p)
{
if(p->second.size())
{
std::streampos pos = out.tellp();
out.seekp((int)typelist + 2 + 8 * typeIndex + 6);
word(out, pos - typelist);
out.seekp(pos);
typeIndex++;
std::streampos resmap = out.tellp();
for(int i = 0; i < 16+4+2+2; i++)
byte(out, 0);
word(out,16+4+2+2+2+2); // offset to resource type list
std::streampos resnameOffset = out.tellp();
word(out,0);
std::streampos typelist = out.tellp();
word(out,resourceInfos.size() - 1);
for(std::map< ResType, std::map<int, int> >::iterator p = resourceInfos.begin();
p != resourceInfos.end(); ++p)
{
if(p->second.size())
{
ostype(out,p->first);
word(out,p->second.size()-1);
word(out,0); // replaced later
}
}
int typeIndex = 0;
int nameOffset = 0;
for(std::map< ResType, std::map<int, int> >::iterator p = resourceInfos.begin();
p != resourceInfos.end(); ++p)
{
if(p->second.size())
{
std::streampos pos = out.tellp();
out.seekp((int)typelist + 2 + 8 * typeIndex + 6);
word(out, pos - typelist);
out.seekp(pos);
typeIndex++;
for(std::map<int,int>::iterator q = p->second.begin(); q != p->second.end(); ++q)
{
std::string name = resources.find(ResRef(p->first, q->first))->second.getName();
word(out,q->first);
if(name.size() == 0)
word(out,-1);
else
{
word(out, nameOffset);
nameOffset += (name.size() > 255 ? 255 : name.size()) + 1;
}
longword(out,q->second);
longword(out,0);
}
}
}
std::streampos resnames = out.tellp();
out.seekp(resnameOffset);
word(out, resnames - resmap);
out.seekp(resnames);
for(std::map<int,int>::iterator q = p->second.begin(); q != p->second.end(); ++q)
{
std::string name = resources.find(ResRef(p->first, q->first))->second.getName();
word(out,q->first);
if(name.size() == 0)
word(out,-1);
else
{
word(out, nameOffset);
nameOffset += (name.size() > 255 ? 255 : name.size()) + 1;
}
longword(out,q->second);
longword(out,0);
}
}
}
std::streampos resnames = out.tellp();
out.seekp(resnameOffset);
word(out, resnames - resmap);
out.seekp(resnames);
for(std::map< ResType, std::map<int, int> >::iterator p = resourceInfos.begin();
p != resourceInfos.end(); ++p)
{
for(std::map<int,int>::iterator q = p->second.begin(); q != p->second.end(); ++q)
{
std::string name = resources.find(ResRef(p->first, q->first))->second.getName();
if(name.size() > 0)
{
int sz = name.size() > 255 ? 255 : name.size();
byte(out, sz);
for(int i = 0; i < sz; i++)
byte(out, name[i]);
}
}
}
for(std::map< ResType, std::map<int, int> >::iterator p = resourceInfos.begin();
p != resourceInfos.end(); ++p)
{
for(std::map<int,int>::iterator q = p->second.begin(); q != p->second.end(); ++q)
{
std::string name = resources.find(ResRef(p->first, q->first))->second.getName();
if(name.size() > 0)
{
int sz = name.size() > 255 ? 255 : name.size();
byte(out, sz);
for(int i = 0; i < sz; i++)
byte(out, name[i]);
}
}
}
std::streampos end = out.tellp();
out.seekp(start + std::streampos(4));
longword(out, resmap - start);
longword(out, dataend - start - std::streampos(0x100));
longword(out, end - resmap);
out.seekp(end);
std::streampos end = out.tellp();
out.seekp(start + std::streampos(4));
longword(out, resmap - start);
longword(out, dataend - start - std::streampos(0x100));
longword(out, end - resmap);
out.seekp(end);
}
Resources::Resources(std::istream &in)
{
std::streampos start = in.tellg();
int resdataOffset = longword(in);
int resmapOffset = longword(in);
std::streampos start = in.tellg();
int resdataOffset = longword(in);
int resmapOffset = longword(in);
in.seekg(start + std::streampos(resmapOffset + 16 + 4 + 2 + 2));
int typeListOffset = word(in);
int nameListOffset = word(in);
int nTypes = (word(in) + 1) & 0xFFFF;
in.seekg(start + std::streampos(resmapOffset + 16 + 4 + 2 + 2));
int typeListOffset = word(in);
int nameListOffset = word(in);
int nTypes = (word(in) + 1) & 0xFFFF;
for(int i = 0; i < nTypes; i++)
{
in.seekg(start + std::streampos(resmapOffset + typeListOffset + 2 + i * 8));
std::string type = ostype(in);
int nRes = (word(in) + 1) & 0xFFFF;
int refListOffset = word(in);
for(int i = 0; i < nTypes; i++)
{
in.seekg(start + std::streampos(resmapOffset + typeListOffset + 2 + i * 8));
std::string type = ostype(in);
int nRes = (word(in) + 1) & 0xFFFF;
int refListOffset = word(in);
for(int j = 0; j < nRes; j++)
{
in.seekg(start + std::streampos(resmapOffset + typeListOffset + refListOffset + j * 12));
int id = (short) word(in);
int nameOffset = word(in);
int attr = byte(in);
int off1 = byte(in);
int off2 = byte(in);
int off3 = byte(in);
int offset = (off1 << 16) | (off2 << 8) | off3;
std::string name;
if(nameOffset != 0xFFFF)
{
in.seekg(start + std::streampos(resmapOffset + nameListOffset + nameOffset));
int nameLen = byte(in);
char buf[256];
in.read(buf, nameLen);
name = std::string(buf, nameLen);
}
for(int j = 0; j < nRes; j++)
{
in.seekg(start + std::streampos(resmapOffset + typeListOffset + refListOffset + j * 12));
int id = (short) word(in);
int nameOffset = word(in);
int attr = byte(in);
int off1 = byte(in);
int off2 = byte(in);
int off3 = byte(in);
int offset = (off1 << 16) | (off2 << 8) | off3;
std::string name;
if(nameOffset != 0xFFFF)
{
in.seekg(start + std::streampos(resmapOffset + nameListOffset + nameOffset));
int nameLen = byte(in);
char buf[256];
in.read(buf, nameLen);
name = std::string(buf, nameLen);
}
in.seekg(start + std::streampos(resdataOffset + offset));
int size = longword(in);
std::vector<char> tmp(size);
in.read(tmp.data(), size);
std::string data(tmp.data(), size);
in.seekg(start + std::streampos(resdataOffset + offset));
int size = longword(in);
std::vector<char> tmp(size);
in.read(tmp.data(), size);
std::string data(tmp.data(), size);
addResource(Resource(type, id, data, name, attr));
}
}
addResource(Resource(type, id, data, name, attr));
}
}
}
+23 -23
View File
@@ -7,43 +7,43 @@
class Resource
{
ResType type;
short id;
std::string name;
std::string data;
int attr;
ResType type;
short id;
std::string name;
std::string data;
int attr;
public:
Resource() {}
Resource(ResType type, int id, std::string data, std::string name = "", int attr = 0)
: type(type), id(id), name(name), data(data), attr(attr) {}
Resource() {}
Resource(ResType type, int id, std::string data, std::string name = "", int attr = 0)
: type(type), id(id), name(name), data(data), attr(attr) {}
const std::string& getData() const { return data; }
inline ResType getType() const { return type; }
inline int getID() const { return id; }
inline ResRef getTypeAndID() const { return ResRef(type, id); }
std::string getName() const { return name; }
int getAttr() const { return attr; }
const std::string& getData() const { return data; }
inline ResType getType() const { return type; }
inline int getID() const { return id; }
inline ResRef getTypeAndID() const { return ResRef(type, id); }
std::string getName() const { return name; }
int getAttr() const { return attr; }
};
class Fork
{
public:
virtual void writeFork(std::ostream& out) const { }
virtual ~Fork() {}
virtual void writeFork(std::ostream& out) const { }
virtual ~Fork() {}
};
class Resources : public Fork
{
public:
std::map<ResRef, Resource> resources;
std::map<ResRef, Resource> resources;
Resources() {}
Resources(std::istream& in);
void writeFork(std::ostream& out) const;
void addResource(Resource res) { resources[res.getTypeAndID()] = res; }
void addResources(const Resources& res);
Resources() {}
Resources(std::istream& in);
void writeFork(std::ostream& out) const;
void addResource(Resource res) { resources[res.getTypeAndID()] = res; }
void addResources(const Resources& res);
unsigned countResources() const { return resources.size(); }
unsigned countResources() const { return resources.size(); }
};
#endif // RESOURCEFORK_H