* adjusted 'message' to be able to deal with more than a single message
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40254 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+19
-6
@@ -7,14 +7,15 @@
|
|||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (argc != 2) {
|
if (argc < 2 || argc > 3) {
|
||||||
printf("usage: %s <flattened message file>\n", argv[0]);
|
printf("usage: %s <flattened message file> [index]\n", argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,13 +25,25 @@ main(int argc, char *argv[])
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
BMessage message;
|
off_t fileSize;
|
||||||
status_t result = message.Unflatten(&input);
|
status_t result;
|
||||||
if (result != B_OK) {
|
if ((result = input.GetSize(&fileSize)) != B_OK) {
|
||||||
printf("failed to unflatten message: %s\n", strerror(result));
|
printf("cannot determine size of file \"%s\"\n", argv[1]);
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int index = argc > 2 ? atoi(argv[2]) : 0;
|
||||||
|
|
||||||
|
for (int i = 1; input.Position() < fileSize; ++i) {
|
||||||
|
BMessage message;
|
||||||
|
result = message.Unflatten(&input);
|
||||||
|
if (result != B_OK) {
|
||||||
|
printf("failed to unflatten message: %s\n", strerror(result));
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
if (index == 0 || i == index)
|
||||||
message.PrintToStream();
|
message.PrintToStream();
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user