4 static const char show_index_usage[] =
7 int main(int argc, char **argv)
12 static unsigned int top_index[256];
17 usage(show_index_usage);
18 if (fread(top_index, 2 * 4, 1, stdin) != 1)
19 die("unable to read header");
20 if (top_index[0] == htonl(PACK_IDX_SIGNATURE)) {
21 version = ntohl(top_index[1]);
22 if (version < 2 || version > 2)
23 die("unknown index version");
24 if (fread(top_index, 256 * 4, 1, stdin) != 1)
25 die("unable to read index");
28 if (fread(&top_index[2], 254 * 4, 1, stdin) != 1)
29 die("unable to read index");
32 for (i = 0; i < 256; i++) {
33 unsigned n = ntohl(top_index[i]);
35 die("corrupt index file");
39 for (i = 0; i < nr; i++) {
40 unsigned int offset, entry[6];
42 if (fread(entry, 4 + 20, 1, stdin) != 1)
43 die("unable to read entry %u/%u", i, nr);
44 offset = ntohl(entry[0]);
45 printf("%u %s\n", offset, sha1_to_hex((void *)(entry+1)));
48 unsigned off64_nr = 0;
50 unsigned char sha1[20];
54 ALLOC_ARRAY(entries, nr);
55 for (i = 0; i < nr; i++)
56 if (fread(entries[i].sha1, 20, 1, stdin) != 1)
57 die("unable to read sha1 %u/%u", i, nr);
58 for (i = 0; i < nr; i++)
59 if (fread(&entries[i].crc, 4, 1, stdin) != 1)
60 die("unable to read crc %u/%u", i, nr);
61 for (i = 0; i < nr; i++)
62 if (fread(&entries[i].off, 4, 1, stdin) != 1)
63 die("unable to read 32b offset %u/%u", i, nr);
64 for (i = 0; i < nr; i++) {
66 uint32_t off = ntohl(entries[i].off);
67 if (!(off & 0x80000000)) {
71 if ((off & 0x7fffffff) != off64_nr)
72 die("inconsistent 64b offset index");
73 if (fread(off64, 8, 1, stdin) != 1)
74 die("unable to read 64b offset %u", off64_nr);
75 offset = (((uint64_t)ntohl(off64[0])) << 32) |
79 printf("%" PRIuMAX " %s (%08"PRIx32")\n",
81 sha1_to_hex(entries[i].sha1),
82 ntohl(entries[i].crc));