1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
| | /* 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 <assert.h>
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;
}
|