comparison src/getidblock.c @ 202:2f38c4ce606f

remove readpstlog, switch to plain ascii debug log files
author Carl Byington <carl@five-ten-sg.com>
date Mon, 18 May 2009 15:55:05 -0700
parents 0a4f7ecd7452
children 4573b536177f
comparison
equal deleted inserted replaced
201:3850a3b11745 202:2f38c4ce606f
11 printf("usage: getidblock [options] filename id\n"); 11 printf("usage: getidblock [options] filename id\n");
12 printf("\tfilename - name of the file to access\n"); 12 printf("\tfilename - name of the file to access\n");
13 printf("\tid - ID of the block to fetch (0 to fetch all) - can begin with 0x for hex\n"); 13 printf("\tid - ID of the block to fetch (0 to fetch all) - can begin with 0x for hex\n");
14 printf("\toptions\n"); 14 printf("\toptions\n");
15 printf("\t\t-p\tProcess the block before finishing.\n"); 15 printf("\t\t-p\tProcess the block before finishing.\n");
16 printf("\t\t-b\tDump the blocks in binary to stdout.\n");
16 printf("\t\t\tView the debug log for information\n"); 17 printf("\t\t\tView the debug log for information\n");
17 } 18 }
18 19
19 20
20 void dumper(uint64_t i_id); 21 void dumper(uint64_t i_id);
22 { 23 {
23 char *buf = NULL; 24 char *buf = NULL;
24 size_t readSize; 25 size_t readSize;
25 pst_desc_tree *ptr; 26 pst_desc_tree *ptr;
26 27
27 DEBUG_MAIN(("\n\n\nLooking at block index1 id %#"PRIx64"\n", i_id)); 28 DEBUG_INFO(("\n\n\nLooking at block index1 id %#"PRIx64"\n", i_id));
28 29
29 if ((readSize = pst_ff_getIDblock_dec(&pstfile, i_id, &buf)) <= 0 || buf == 0) { 30 if ((readSize = pst_ff_getIDblock_dec(&pstfile, i_id, &buf)) <= 0 || buf == 0) {
30 DIE(("Error loading block\n")); 31 DIE(("Error loading block\n"));
31 } 32 }
32 33
33 DEBUG_MAIN(("Printing block id %#"PRIx64", size %#"PRIx64"\n", i_id, (uint64_t)readSize)); 34 DEBUG_INFO(("Printing block id %#"PRIx64", size %#"PRIx64"\n", i_id, (uint64_t)readSize));
34 if (binary) { 35 if (binary) {
35 if (fwrite(buf, 1, readSize, stdout) != 0) { 36 if (fwrite(buf, 1, readSize, stdout) != 0) {
36 DIE(("Error occured during writing of buf to stdout\n")); 37 DIE(("Error occured during writing of buf to stdout\n"));
37 } 38 }
38 } else { 39 } else {
40 pst_debug_hexdumper(stdout, buf, readSize, 0x10, 0); 41 pst_debug_hexdumper(stdout, buf, readSize, 0x10, 0);
41 } 42 }
42 if (buf) free(buf); 43 if (buf) free(buf);
43 44
44 if (process) { 45 if (process) {
45 DEBUG_MAIN(("Parsing block id %#"PRIx64"\n", i_id)); 46 DEBUG_INFO(("Parsing block id %#"PRIx64"\n", i_id));
46 ptr = pstfile.d_head; 47 ptr = pstfile.d_head;
47 while (ptr) { 48 while (ptr) {
48 if (ptr->assoc_tree && ptr->assoc_tree->i_id == i_id) 49 if (ptr->assoc_tree && ptr->assoc_tree->i_id == i_id)
49 break; 50 break;
50 if (ptr->desc && ptr->desc->i_id == i_id) 51 if (ptr->desc && ptr->desc->i_id == i_id)
64 65
65 void dump_desc(pst_desc_tree *ptr); 66 void dump_desc(pst_desc_tree *ptr);
66 void dump_desc(pst_desc_tree *ptr) 67 void dump_desc(pst_desc_tree *ptr)
67 { 68 {
68 while (ptr) { 69 while (ptr) {
69 DEBUG_MAIN(("\n\n\nLooking at block desc id %#"PRIx64"\n", ptr->d_id)); 70 DEBUG_INFO(("\n\n\nLooking at block desc id %#"PRIx64"\n", ptr->d_id));
70 if (ptr->desc && ptr->desc->i_id) dumper(ptr->desc->i_id); 71 if (ptr->desc && ptr->desc->i_id) dumper(ptr->desc->i_id);
71 if (ptr->assoc_tree && ptr->assoc_tree->i_id) dumper(ptr->assoc_tree->i_id); 72 if (ptr->assoc_tree && ptr->assoc_tree->i_id) dumper(ptr->assoc_tree->i_id);
72 if (ptr->child) dump_desc(ptr->child); 73 if (ptr->child) dump_desc(ptr->child);
73 ptr = ptr->next; 74 ptr = ptr->next;
74 } 75 }
80 // pass the id number to display on the command line 81 // pass the id number to display on the command line
81 char *fname, *sid; 82 char *fname, *sid;
82 uint64_t i_id; 83 uint64_t i_id;
83 int c; 84 int c;
84 85
85 DEBUG_INIT("getidblock.log"); 86 DEBUG_INIT("getidblock.log", NULL);
86 DEBUG_REGISTER_CLOSE();
87 DEBUG_ENT("main"); 87 DEBUG_ENT("main");
88 88
89 while ((c = getopt(argc, argv, "bdp")) != -1) { 89 while ((c = getopt(argc, argv, "bp")) != -1) {
90 switch (c) { 90 switch (c) {
91 case 'b': 91 case 'b':
92 // enable binary output 92 // enable binary output
93 binary = 1; 93 binary = 1;
94 break; 94 break;
109 } 109 }
110 fname = argv[optind]; 110 fname = argv[optind];
111 sid = argv[optind + 1]; 111 sid = argv[optind + 1];
112 i_id = (uint64_t)strtoll(sid, NULL, 0); 112 i_id = (uint64_t)strtoll(sid, NULL, 0);
113 113
114 DEBUG_MAIN(("Opening file\n")); 114 DEBUG_INFO(("Opening file\n"));
115 memset(&pstfile, 0, sizeof(pstfile)); 115 memset(&pstfile, 0, sizeof(pstfile));
116 if (pst_open(&pstfile, fname)) { 116 if (pst_open(&pstfile, fname)) {
117 DIE(("Error opening file\n")); 117 DIE(("Error opening file\n"));
118 } 118 }
119 119
120 DEBUG_MAIN(("Loading Index\n")); 120 DEBUG_INFO(("Loading Index\n"));
121 if (pst_load_index(&pstfile) != 0) { 121 if (pst_load_index(&pstfile) != 0) {
122 DIE(("Error loading file index\n")); 122 DIE(("Error loading file index\n"));
123 } 123 }
124 124
125 if (i_id) { 125 if (i_id) {