From 81b0e79a7b2af79835886ad61f8df030567a4e36 Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Thu, 20 Jan 2011 13:17:34 +0000 Subject: [PATCH] * 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 --- src/bin/message.cpp | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/bin/message.cpp b/src/bin/message.cpp index f96b322daa..09cead58a1 100644 --- a/src/bin/message.cpp +++ b/src/bin/message.cpp @@ -7,14 +7,15 @@ #include #include +#include #include int main(int argc, char *argv[]) { - if (argc != 2) { - printf("usage: %s \n", argv[0]); + if (argc < 2 || argc > 3) { + printf("usage: %s [index]\n", argv[0]); return 1; } @@ -24,13 +25,25 @@ main(int argc, char *argv[]) return 2; } - BMessage message; - status_t result = message.Unflatten(&input); - if (result != B_OK) { - printf("failed to unflatten message: %s\n", strerror(result)); + off_t fileSize; + status_t result; + if ((result = input.GetSize(&fileSize)) != B_OK) { + printf("cannot determine size of file \"%s\"\n", argv[1]); return 3; } - message.PrintToStream(); + 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(); + } + return 0; }