2 #include "sha1-array.h"
4 static void print_sha1(const unsigned char sha1
[20], void *data
)
6 puts(sha1_to_hex(sha1
));
9 int main(int argc
, char **argv
)
11 struct sha1_array array
= SHA1_ARRAY_INIT
;
12 struct strbuf line
= STRBUF_INIT
;
14 while (strbuf_getline(&line
, stdin
) != EOF
) {
16 unsigned char sha1
[20];
18 if (skip_prefix(line
.buf
, "append ", &arg
)) {
19 if (get_sha1_hex(arg
, sha1
))
20 die("not a hexadecimal SHA1: %s", arg
);
21 sha1_array_append(&array
, sha1
);
22 } else if (skip_prefix(line
.buf
, "lookup ", &arg
)) {
23 if (get_sha1_hex(arg
, sha1
))
24 die("not a hexadecimal SHA1: %s", arg
);
25 printf("%d\n", sha1_array_lookup(&array
, sha1
));
26 } else if (!strcmp(line
.buf
, "clear"))
27 sha1_array_clear(&array
);
28 else if (!strcmp(line
.buf
, "for_each_unique"))
29 sha1_array_for_each_unique(&array
, print_sha1
, NULL
);
31 die("unknown command: %s", line
.buf
);