From: David Gibson Date: Wed, 3 Oct 2012 13:02:39 +0000 (+1000) Subject: rfc822: Add an example program X-Git-Url: http://git.ozlabs.org/?p=ccan;a=commitdiff_plain;h=affb2280db6983da455a73a2dd078f1d3f0e7268 rfc822: Add an example program Add a simple full-blown example program for the rfc822 module. 'headernames' simply dumps the header field name for every header field in each message file given on the command line to stdout. Signed-off-by: David Gibson --- diff --git a/ccan/rfc822/examples/.gitignore b/ccan/rfc822/examples/.gitignore new file mode 100644 index 00000000..18c657d7 --- /dev/null +++ b/ccan/rfc822/examples/.gitignore @@ -0,0 +1 @@ +headernames diff --git a/ccan/rfc822/examples/Makefile b/ccan/rfc822/examples/Makefile new file mode 100644 index 00000000..bb20fc03 --- /dev/null +++ b/ccan/rfc822/examples/Makefile @@ -0,0 +1,10 @@ +CFLAGS= -I../../.. ../../rfc822.o \ + ../../talloc/talloc.o ../../grab_file/grab_file.o \ + ../../list/list.o ../../noerr/noerr.o + +EXAMPLES = headernames + +all: $(EXAMPLES) + +clean: + rm -f $(EXAMPLES) diff --git a/ccan/rfc822/examples/headernames.c b/ccan/rfc822/examples/headernames.c new file mode 100644 index 00000000..161ceab3 --- /dev/null +++ b/ccan/rfc822/examples/headernames.c @@ -0,0 +1,42 @@ +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +static void process_file(const char *name) +{ + void *ctx = talloc_new(NULL); + size_t size; + void *buf; + struct rfc822_msg *msg; + struct rfc822_header *hdr; + + buf = grab_file(ctx, name, &size); + + msg = rfc822_start(ctx, buf, size); + + rfc822_for_each_header(msg, hdr) { + struct bytestring hname = rfc822_header_raw_name(msg, hdr); + + printf("%.*s\n", hname.len, hname.ptr); + } + + talloc_free(ctx); +} + +int main(int argc, char *argv[]) +{ + int i; + + for (i = 0; i < (argc - 1); i++) + process_file(argv[i + 1]); + + exit(0); +}