diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2014-01-16 09:03:11 +0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-01-16 12:51:23 +0700 |
commit | 96a4fd1bb223d646bb3f3c8b9d4d0800ebe49e13 (patch) | |
tree | ccab6808c0f791790ad3662a836f451c90dad2c7 /membuffer.h | |
parent | 2e08f75618e6ff86e37de5e1ee0100a31cc8efb7 (diff) | |
download | subsurface-96a4fd1bb223d646bb3f3c8b9d4d0800ebe49e13.tar.gz |
Save XML files into a memory buffer rather than directly into a file
This introduces a "struct membuffer" abstraction that you can write
things into, and makes the XML saving code write to the memory buffer
rather than a file.
The UDDF export already really wanted this: it used to write to a file,
only to then read that file back into memory, delete the file, and then
*rewrite* the file after doing the magic xslt transform.
But the longer-term reason for this is that I want to try to write other
formats, and I want to try to share most helpers. And those other
formats will need this memory buffer model.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'membuffer.h')
-rw-r--r-- | membuffer.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/membuffer.h b/membuffer.h new file mode 100644 index 000000000..bef9e76bc --- /dev/null +++ b/membuffer.h @@ -0,0 +1,52 @@ +#ifndef MEMBUFFER_H +#define MEMBUFFER_H + +struct membuffer { + unsigned int size, used; + char *buffer; +}; + +#ifdef __GNUC__ +#define __printf(x,y) __attribute__ ((__format__ (__printf__, x, y))) +#else +#define __printf(x,y) +#endif + +extern void free_buffer(struct membuffer *); +extern void flush_buffer(struct membuffer *, FILE *); +extern void put_bytes(struct membuffer *, const char *, int); +extern void put_string(struct membuffer *, const char *); +extern __printf(2,0) void put_vformat(struct membuffer *, const char *, va_list); +extern __printf(2,3) void put_format(struct membuffer *, const char *fmt, ...); + +/* Output one of our "milli" values with type and pre/post data */ +extern void put_milli(struct membuffer *, const char *, int, const char *); + +/* + * Helper functions for showing particular types. If the type + * is empty, nothing is done, and the function returns false. + * Otherwise, it returns true. + * + * The two "const char *" at the end are pre/post data. + * + * The reason for the pre/post data is so that you can easily + * prepend and append a string without having to test whether the + * type is empty. So + * + * put_temperature(b, temp, "Temp=", " C\n"); + * + * writes nothing to the buffer if there is no temperature data, + * but otherwise would a string that looks something like + * + * "Temp=28.1 C\n" + * + * to the memory buffer (typically the post/pre will be some XML + * pattern and unit string or whatever). + */ +extern int put_temperature(struct membuffer *, temperature_t, const char *, const char *); +extern int put_depth(struct membuffer *, depth_t, const char *, const char *); +extern int put_duration(struct membuffer *, duration_t, const char *, const char *); +extern int put_pressure(struct membuffer *, pressure_t, const char *, const char *); +extern int put_salinity(struct membuffer *, int, const char *, const char *); + +#endif |