unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
blob eec65411b4ca887dd74623c252e73d22cc4ad3d5 1890 bytes (raw)
name: test/hex-xcode.c 	 # note: path name is non-authoritative(*)

  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
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
 
/* No, nothing to to with IDE from Apple Inc.
   testbed for ../util/hex-escape.c.

   usage:
   hex-xcode [--direction=(encode|decode)] [--omit-newline] < file
   hex-xcode [--direction=(encode|decode)] [--omit-newline] arg1 arg2 arg3 ...

 */

#include "notmuch-client.h"
#include "hex-escape.h"
#include <assert.h>


enum direction {
    ENCODE,
    DECODE
};

static int
xcode (void *ctx, enum direction dir, char *in, char **buf_p, size_t *size_p)
{
    hex_status_t status;

    if (dir == ENCODE)
	status = hex_encode (ctx, in, buf_p, size_p);
    else
	status = hex_decode (ctx, in, buf_p, size_p);

    if (status == HEX_SUCCESS)
	fputs (*buf_p, stdout);

    return status;
}


int
main (int argc, char **argv)
{


    enum direction dir = DECODE;
    int omit_newline = FALSE;

    notmuch_opt_desc_t options[] = {
	{ NOTMUCH_OPT_KEYWORD, &dir, "direction", 'd',
	  (notmuch_keyword_t []){ { "encode", ENCODE },
				  { "decode", DECODE },
				  { 0, 0 } } },
	{ NOTMUCH_OPT_BOOLEAN, &omit_newline, "omit-newline", 'n', 0 },
	{ 0, 0, 0, 0, 0 }
    };

    int opt_index = parse_arguments (argc, argv, options, 1);

    if (opt_index < 0)
	exit (1);

    void *ctx = talloc_new (NULL);

    char *line = NULL;
    size_t line_size;
    ssize_t line_len;

    char *buffer = NULL;
    size_t buf_size = 0;

    notmuch_bool_t read_stdin = TRUE;

    for (; opt_index < argc; opt_index++) {

	if (xcode (ctx, dir, argv[opt_index],
		   &buffer, &buf_size) != HEX_SUCCESS)
	    return 1;

	if (!omit_newline)
	    putchar ('\n');

	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 (!omit_newline)
	    putchar ('\n');

    }

    if (line)
	free (line);

    talloc_free (ctx);

    return 0;
}

debug log:

solving eec6541 ...
found eec6541 in https://yhetil.org/notmuch/1344888831-4301-3-git-send-email-bremner@debian.org/ ||
	https://yhetil.org/notmuch/a984626045b59100ec7f2d9f9b14a9a48252d8d0.1333231401.git.jani@nikula.org/ ||
	https://yhetil.org/notmuch/e40d095e6a5208d8e720d1f681bd172e28f3f112.1334404979.git.jani@nikula.org/ ||
	https://yhetil.org/notmuch/1326591624-15493-3-git-send-email-david@tethera.net/ ||
	https://yhetil.org/notmuch/1353265498-3839-3-git-send-email-david@tethera.net/ ||
	https://yhetil.org/notmuch/1353792017-31459-3-git-send-email-david@tethera.net/ ||
	https://yhetil.org/notmuch/1345382314-5330-3-git-send-email-david@tethera.net/

applying [1/1] https://yhetil.org/notmuch/1344888831-4301-3-git-send-email-bremner@debian.org/
diff --git a/test/hex-xcode.c b/test/hex-xcode.c
new file mode 100644
index 0000000..eec6541

Checking patch test/hex-xcode.c...
Applied patch test/hex-xcode.c cleanly.

skipping https://yhetil.org/notmuch/a984626045b59100ec7f2d9f9b14a9a48252d8d0.1333231401.git.jani@nikula.org/ for eec6541
skipping https://yhetil.org/notmuch/e40d095e6a5208d8e720d1f681bd172e28f3f112.1334404979.git.jani@nikula.org/ for eec6541
skipping https://yhetil.org/notmuch/1326591624-15493-3-git-send-email-david@tethera.net/ for eec6541
skipping https://yhetil.org/notmuch/1353265498-3839-3-git-send-email-david@tethera.net/ for eec6541
skipping https://yhetil.org/notmuch/1353792017-31459-3-git-send-email-david@tethera.net/ for eec6541
skipping https://yhetil.org/notmuch/1345382314-5330-3-git-send-email-david@tethera.net/ for eec6541
index at:
100644 eec65411b4ca887dd74623c252e73d22cc4ad3d5	test/hex-xcode.c

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).