* Fixed warning.
* Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32309 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+50
-25
@@ -3,6 +3,7 @@
|
|||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -14,8 +15,10 @@
|
|||||||
#include <StorageDefs.h>
|
#include <StorageDefs.h>
|
||||||
#include <TypeConstants.h>
|
#include <TypeConstants.h>
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
static const char *kCommandName = "xres";
|
static const char *kCommandName = "xres";
|
||||||
static const char *kDefaultResourceName = NULL;
|
static const char *kDefaultResourceName = NULL;
|
||||||
static const char *kDefaultOutputFile = "xres.output.rsrc";
|
static const char *kDefaultOutputFile = "xres.output.rsrc";
|
||||||
@@ -80,6 +83,7 @@ const char *kUsage =
|
|||||||
" <id> - A positive or negative integer.\n"
|
" <id> - A positive or negative integer.\n"
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
// resource_type
|
// resource_type
|
||||||
static const char *
|
static const char *
|
||||||
resource_type(type_code type)
|
resource_type(type_code type)
|
||||||
@@ -95,6 +99,7 @@ resource_type(type_code type)
|
|||||||
return typeString;
|
return typeString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ResourceID
|
// ResourceID
|
||||||
struct ResourceID {
|
struct ResourceID {
|
||||||
type_code type;
|
type_code type;
|
||||||
@@ -103,9 +108,10 @@ struct ResourceID {
|
|||||||
|
|
||||||
ResourceID(type_code type = B_ANY_TYPE, int32 id = 0,
|
ResourceID(type_code type = B_ANY_TYPE, int32 id = 0,
|
||||||
bool wildcardID = true)
|
bool wildcardID = true)
|
||||||
: type(type),
|
:
|
||||||
id(id),
|
type(type),
|
||||||
wildcardID(wildcardID)
|
id(id),
|
||||||
|
wildcardID(wildcardID)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,6 +135,7 @@ struct ResourceID {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// ResourceDataSource
|
// ResourceDataSource
|
||||||
struct ResourceDataSource {
|
struct ResourceDataSource {
|
||||||
ResourceDataSource()
|
ResourceDataSource()
|
||||||
@@ -146,6 +153,7 @@ struct ResourceDataSource {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// MemoryResourceDataSource
|
// MemoryResourceDataSource
|
||||||
struct MemoryResourceDataSource : ResourceDataSource {
|
struct MemoryResourceDataSource : ResourceDataSource {
|
||||||
MemoryResourceDataSource(const void *data, size_t size, bool clone)
|
MemoryResourceDataSource(const void *data, size_t size, bool clone)
|
||||||
@@ -191,12 +199,14 @@ private:
|
|||||||
bool fOwner;
|
bool fOwner;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// FileResourceDataSource
|
// FileResourceDataSource
|
||||||
struct FileResourceDataSource : ResourceDataSource {
|
struct FileResourceDataSource : ResourceDataSource {
|
||||||
FileResourceDataSource(const char *path)
|
FileResourceDataSource(const char *path)
|
||||||
: fPath(path),
|
:
|
||||||
fData(NULL),
|
fPath(path),
|
||||||
fSize(0)
|
fData(NULL),
|
||||||
|
fSize(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,6 +276,7 @@ private:
|
|||||||
size_t fSize;
|
size_t fSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// State
|
// State
|
||||||
struct State {
|
struct State {
|
||||||
State()
|
State()
|
||||||
@@ -305,6 +316,7 @@ struct State {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// ListState
|
// ListState
|
||||||
struct ListState : State {
|
struct ListState : State {
|
||||||
ListState()
|
ListState()
|
||||||
@@ -351,22 +363,22 @@ struct ListState : State {
|
|||||||
const char *name;
|
const char *name;
|
||||||
size_t size;
|
size_t size;
|
||||||
for (int32 i = 0;
|
for (int32 i = 0;
|
||||||
resources.GetResourceInfo(i, &type, &id, &name, &size);
|
resources.GetResourceInfo(i, &type, &id, &name, &size); i++) {
|
||||||
i++) {
|
printf("'%s' %11ld %11lu %s\n", resource_type(type), id, size,
|
||||||
|
|
||||||
printf("'%s' %11ld %11u %s\n", resource_type(type), id, size,
|
|
||||||
(name && strlen(name) > 0 ? name : "(no name)"));
|
(name && strlen(name) > 0 ? name : "(no name)"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// WriteFileState
|
// WriteFileState
|
||||||
struct WriteFileState : State {
|
struct WriteFileState : State {
|
||||||
WriteFileState()
|
WriteFileState()
|
||||||
: fOutputFilePath(kDefaultOutputFile),
|
:
|
||||||
fResources(NULL),
|
fOutputFilePath(kDefaultOutputFile),
|
||||||
fInclusionPattern(NULL),
|
fResources(NULL),
|
||||||
fExclusionPattern(NULL)
|
fInclusionPattern(NULL),
|
||||||
|
fExclusionPattern(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -525,6 +537,7 @@ private:
|
|||||||
ResourceID *fExclusionPattern;
|
ResourceID *fExclusionPattern;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Command
|
// Command
|
||||||
struct Command {
|
struct Command {
|
||||||
Command()
|
Command()
|
||||||
@@ -538,11 +551,13 @@ struct Command {
|
|||||||
virtual void Do(State *state) = 0;
|
virtual void Do(State *state) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// SetOutputCommand
|
// SetOutputCommand
|
||||||
struct SetOutputCommand : Command {
|
struct SetOutputCommand : Command {
|
||||||
SetOutputCommand(const char *path)
|
SetOutputCommand(const char *path)
|
||||||
: Command(),
|
:
|
||||||
fPath(path)
|
Command(),
|
||||||
|
fPath(path)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -555,11 +570,13 @@ private:
|
|||||||
string fPath;
|
string fPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// ProcessInputCommand
|
// ProcessInputCommand
|
||||||
struct ProcessInputCommand : Command {
|
struct ProcessInputCommand : Command {
|
||||||
ProcessInputCommand(const char *path)
|
ProcessInputCommand(const char *path)
|
||||||
: Command(),
|
:
|
||||||
fPath(path)
|
Command(),
|
||||||
|
fPath(path)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -572,12 +589,14 @@ private:
|
|||||||
string fPath;
|
string fPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// SetResourcePatternCommand
|
// SetResourcePatternCommand
|
||||||
struct SetResourcePatternCommand : Command {
|
struct SetResourcePatternCommand : Command {
|
||||||
SetResourcePatternCommand(const ResourceID &pattern, bool inclusion)
|
SetResourcePatternCommand(const ResourceID &pattern, bool inclusion)
|
||||||
: Command(),
|
:
|
||||||
fPattern(pattern),
|
Command(),
|
||||||
fInclusion(inclusion)
|
fPattern(pattern),
|
||||||
|
fInclusion(inclusion)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -594,14 +613,16 @@ private:
|
|||||||
bool fInclusion;
|
bool fInclusion;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// AddResourceCommand
|
// AddResourceCommand
|
||||||
struct AddResourceCommand : Command {
|
struct AddResourceCommand : Command {
|
||||||
AddResourceCommand(const ResourceID &id, const char *name,
|
AddResourceCommand(const ResourceID &id, const char *name,
|
||||||
ResourceDataSource *dataSource)
|
ResourceDataSource *dataSource)
|
||||||
: Command(),
|
:
|
||||||
fID(id),
|
Command(),
|
||||||
fHasName(name),
|
fID(id),
|
||||||
fDataSource(dataSource)
|
fHasName(name),
|
||||||
|
fDataSource(dataSource)
|
||||||
{
|
{
|
||||||
if (fHasName)
|
if (fHasName)
|
||||||
fName = name;
|
fName = name;
|
||||||
@@ -648,6 +669,7 @@ print_usage(bool error)
|
|||||||
commandName);
|
commandName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// print_usage_and_exit
|
// print_usage_and_exit
|
||||||
static void
|
static void
|
||||||
print_usage_and_exit(bool error)
|
print_usage_and_exit(bool error)
|
||||||
@@ -656,6 +678,7 @@ print_usage_and_exit(bool error)
|
|||||||
exit(error ? 1 : 0);
|
exit(error ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// next_arg
|
// next_arg
|
||||||
static const char *
|
static const char *
|
||||||
next_arg(int &argi, bool optional = false)
|
next_arg(int &argi, bool optional = false)
|
||||||
@@ -669,6 +692,7 @@ next_arg(int &argi, bool optional = false)
|
|||||||
return kArgv[argi++];
|
return kArgv[argi++];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// parse_resource_id
|
// parse_resource_id
|
||||||
static void
|
static void
|
||||||
parse_resource_id(const char *toParse, ResourceID &resourceID,
|
parse_resource_id(const char *toParse, ResourceID &resourceID,
|
||||||
@@ -733,6 +757,7 @@ parse_resource_id(const char *toParse, ResourceID &resourceID,
|
|||||||
*name = toParse + 1;
|
*name = toParse + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// main
|
// main
|
||||||
int
|
int
|
||||||
main(int argc, const char *const *argv)
|
main(int argc, const char *const *argv)
|
||||||
|
|||||||
Reference in New Issue
Block a user