Author: zooey Date: 2011-01-20 14:17:34 +0100 (Thu, 20 Jan 2011) New Revision: 40254 Changeset: http://dev.haiku-os.org/changeset/40254 Modified: haiku/trunk/src/bin/message.cpp Log: * adjusted 'message' to be able to deal with more than a single message Modified: haiku/trunk/src/bin/message.cpp =================================================================== --- haiku/trunk/src/bin/message.cpp 2011-01-20 12:12:58 UTC (rev 40253) +++ haiku/trunk/src/bin/message.cpp 2011-01-20 13:17:34 UTC (rev 40254) @@ -7,14 +7,15 @@ #include <Message.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> int main(int argc, char *argv[]) { - if (argc != 2) { - printf("usage: %s <flattened message file>\n", argv[0]); + if (argc < 2 || argc > 3) { + printf("usage: %s <flattened message file> [index]\n", argv[0]); return 1; } @@ -24,13 +25,25 @@ 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; }