/* No, nothing to to with IDE from Apple Inc. testbed for ../util/hex-escape.c. usage: hex-xcode (e|d) < foo e is for encode d is for decode */ #include "notmuch-client.h" #include "hex-escape.h" #include static int xcode (void *ctx, char dir, char *in, char **buf_p, size_t *size_p) { hex_status_t status; if (dir == 'e') status = hex_encode (ctx, in, buf_p, size_p); else status = hex_decode (ctx, in, buf_p, size_p); if (status == HEX_SUCCESS) puts (*buf_p); return status; } int main (int argc, char **argv) { assert (argc > 1 && argv[1]); char dir = argv[1][0]; void *ctx = talloc_new (NULL); char *line = NULL; size_t line_size; ssize_t line_len; char *buffer = NULL; size_t buf_size = 0; int arg_index = 2; notmuch_bool_t read_stdin = TRUE; for (arg_index = 2; arg_index < argc; arg_index++) { if (xcode (ctx, dir, argv[arg_index], &buffer, &buf_size) != HEX_SUCCESS) return 1; read_stdin = FALSE; } if (!read_stdin) return 0; while ((line_len = getline (&line, &line_size, stdin)) != -1) { chomp_newline (line); if (xcode (ctx, dir, line, &buffer, &buf_size) != HEX_SUCCESS) return 1; } if (line) free (line); talloc_free (ctx); return 0; }