+ if ((argc - optind) < 1) {
+ usage();
+ } else if (!strcmp("add", argv[optind])) {
+ if (binary) {
+ result = read_openpgp_stream(stdin_getchar, NULL,
+ &packets);
+ if (verbose) {
+ fprintf(stderr,
+ "read_openpgp_stream: %d\n", result);
+ }
+ } else {
+ dearmor_openpgp_stream(stdin_getchar, NULL, &packets);
+ }
+ if (packets != NULL) {
+ result = parse_keys(packets, &keys);
+ free_packet_list(packets);
+ packets = NULL;
+ if (verbose) {
+ fprintf(stderr, "Finished reading %d keys.\n",
+ result);
+ }
+
+ initdb();
+ fprintf(stderr, "Got %d new keys.\n",
+ update_keys(&keys, verbose));
+ if (keys != NULL && update) {
+ flatten_publickey(keys,
+ &packets,
+ &list_end);
+ armor_openpgp_stream(stdout_putchar,
+ NULL,
+ packets);
+ free_packet_list(packets);
+ packets = NULL;
+ }
+ cleanupdb();
+ } else {
+ rc = 1;
+ fprintf(stderr, "No keys read.\n");
+ }
+
+ if (keys != NULL) {
+ free_publickey(keys);
+ keys = NULL;
+ } else {
+ rc = 1;
+ fprintf(stderr, "No changes.\n");
+ }
+ } else if ((argc - optind) == 2) {
+ search = argv[optind+1];
+ if (search != NULL) {
+ keyid = strtoul(search, &end, 16);
+ if (*search != 0 &&
+ end != NULL &&
+ *end == 0) {
+ ishex = true;
+ }
+ }