1 /* 2 ** Copyright 2003, Oliver Tappe, zooey@hirschkaefer.de. All rights reserved. 3 ** Distributed under the terms of the OpenBeOS License. 4 */ 5 6 #include <cstdio> 7 #include <cstdlib> 8 9 #include <File.h> 10 #include <String.h> 11 12 #include <DefaultCatalog.h> 13 #include <EditableCatalog.h> 14 15 16 using BPrivate::CatKey; 17 using BPrivate::DefaultCatalog; 18 using BPrivate::EditableCatalog; 19 20 21 void 22 usage() 23 { 24 fprintf(stderr, "usage: dumpcatalog <catalogFiles>\n"); 25 exit(-1); 26 } 27 28 29 int 30 main(int argc, char **argv) 31 { 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]; 38 } 39 if (!inputFile || !strlen(inputFile)) 40 usage(); 41 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); 47 } 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); 52 } 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); 59 } 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%lu\nKey:\t\t<%s:%s:%s>\nTranslation:\t%s\n-----\n", 68 key.fHashVal, str.String(), ctx.String(), cmt.String(), 69 walker.GetValue()); 70 walker.Next(); 71 } 72 int32 count = inputCatalog.CountItems(); 73 if (count) 74 fprintf(stderr, "%ld entr%s dumped\n", count, (count==1 ? "y": "ies")); 75 else 76 fprintf(stderr, "no entries found\n"); 77 return res; 78 } 79