Make UEFI boot-platform build again
[haiku.git] / src / bin / locale / dumpcatalog.cpp
blob5a93b25f6d01f437e1850919aa8bf2d88e254444
1 /*
2 ** Copyright 2003, Oliver Tappe, zooey@hirschkaefer.de. All rights reserved.
3 ** Distributed under the terms of the MIT License.
4 */
6 #include <cstdio>
7 #include <cstdlib>
9 #include <File.h>
10 #include <String.h>
12 #include <DefaultCatalog.h>
13 #include <EditableCatalog.h>
16 using BPrivate::CatKey;
17 using BPrivate::DefaultCatalog;
18 using BPrivate::EditableCatalog;
21 void
22 usage()
24 fprintf(stderr, "usage: dumpcatalog <catalogFiles>\n");
25 exit(-1);
29 int
30 main(int argc, char **argv)
32 const char *inputFile = NULL;
33 status_t res;
34 if (!argv[1] || !strcmp(argv[1], "--help")) {
35 usage();
36 } else {
37 inputFile = argv[1];
39 if (!inputFile || !strlen(inputFile))
40 usage();
42 EditableCatalog inputCatalog("Default", "dummy", "dummy");
43 if ((res = inputCatalog.InitCheck()) != B_OK) {
44 fprintf(stderr, "couldn't construct catalog %s - error: %s\n",
45 inputFile, strerror(res));
46 exit(-1);
48 if ((res = inputCatalog.ReadFromFile(inputFile)) != B_OK) {
49 fprintf(stderr, "couldn't load input-catalog %s - error: %s\n",
50 inputFile, strerror(res));
51 exit(-1);
53 DefaultCatalog* inputCatImpl
54 = dynamic_cast<DefaultCatalog*>(inputCatalog.CatalogData());
55 if (!inputCatImpl) {
56 fprintf(stderr, "couldn't access impl of input-catalog %s\n",
57 inputFile);
58 exit(-1);
60 // now walk over all entries in input-catalog and dump them to
61 // stdout
62 DefaultCatalog::CatWalker walker(inputCatImpl);
63 BString str, ctx, cmt;
64 while (!walker.AtEnd()) {
65 const CatKey &key(walker.GetKey());
66 key.GetStringParts(&str, &ctx, &cmt);
67 printf("Hash:\t\t%" B_PRIu32 "\nKey:\t\t<%s:%s:%s>\nTranslation:\t%s\n"
68 "-----\n", key.fHashVal, str.String(), ctx.String(), cmt.String(),
69 walker.GetValue());
70 walker.Next();
72 int32 count = inputCatalog.CountItems();
73 if (count) {
74 fprintf(stderr, "%" B_PRId32 " entr%s dumped\n", count,
75 (count==1 ? "y": "ies"));
76 } else
77 fprintf(stderr, "no entries found\n");
78 return res;