Mercurial > code
changeset 154:c7ad101ed4a1
Cleanup useless for pack.[ch]
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sun, 15 Jul 2012 20:59:10 +0200 |
parents | a6a7cd08be72 |
children | 3fde269076a7 |
files | pack.c pack.h |
diffstat | 2 files changed, 18 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/pack.c Sun Jul 15 20:40:54 2012 +0200 +++ b/pack.c Sun Jul 15 20:59:10 2012 +0200 @@ -48,8 +48,7 @@ * -------------------------------------------------------- */ static size_t pack_getsize(char); -static ConvertFn pack_getconvert_by_tok(char); -static ConvertFn pack_getconvert_by_size(size_t); +static ConvertFn get_convert(size_t); static void pack_convert16(uint16_t *); static void pack_convert32(uint32_t *); static void pack_convert64(uint64_t *); @@ -101,28 +100,11 @@ } /* - * Return the conversion function. - */ - -static ConvertFn -pack_getconvert_by_tok(char tok) -{ - struct integer *s; - unsigned int i; - - for (s = sizes, i = 0; i < LENGTH(sizes); ++s, ++i) - if (s->tok == tok) - return s->convert; - - return NULL; -} - -/* * Same but by size. */ static ConvertFn -pack_getconvert_by_size(size_t size) +get_convert(size_t size) { struct integer *s; unsigned int i; @@ -186,7 +168,7 @@ int i; if (ptype != PACK_HOST_BYTEORDER) - conv = pack_getconvert_by_size(val->size); + conv = get_convert(val->size); for (i = 0; i < val->nelem; ++i) { it = 0; @@ -217,7 +199,7 @@ uint64_t it = 0; if (ptype != PACK_HOST_BYTEORDER) - conv = pack_getconvert_by_size(val->size); + conv = get_convert(val->size); for (i = 0; i < val->nelem; ++i) { it = 0; @@ -237,7 +219,7 @@ */ static void -pack_get_arg(struct value *val, va_list ap, int ptype) +pack_get_arg(struct value *val, va_list ap) { if (val->nelem == 1) { switch (val->tok) { @@ -260,7 +242,7 @@ */ static void -pack_get_properties(struct value *val, char **p, va_list ap, int ptype) +pack_get_properties(struct value *val, char **p, va_list ap) { memset(val, 0, sizeof (struct value)); @@ -303,20 +285,20 @@ */ size_t -pack_fmtlen(int ptype, const char *fmt, ...) +pack_fmtlen(const char *fmt, ...) { va_list ap; size_t count; va_start(ap, fmt); - count = pack_vfmtlen(ptype, fmt, ap); + count = pack_vfmtlen(fmt, ap); va_end(ap); return count; } size_t -pack_vfmtlen(int ptype, const char *fmt, va_list ap) +pack_vfmtlen(const char *fmt, va_list ap) { const char *p; struct value v; @@ -324,7 +306,7 @@ p = fmt; while (*p != '\0') { - pack_get_properties(&v, (char **)&p, ap, ptype); + pack_get_properties(&v, (char **)&p, ap); count += (v.size * v.nelem); } @@ -360,8 +342,8 @@ p = fmt; while (*p != '\0') { - pack_get_properties(&v, (char **)&p, ap, ptype); - pack_get_arg(&v, ap, ptype); + pack_get_properties(&v, (char **)&p, ap); + pack_get_arg(&v, ap); if ((b = realloc(b, offset + (v.nelem * v.size))) == NULL) { *buf = NULL; @@ -440,8 +422,8 @@ p = fmt; while (*p != '\0') { - pack_get_properties(&v, (char **)&p, ap, ptype); - pack_get_arg(&v, ap, ptype); + pack_get_properties(&v, (char **)&p, ap); + pack_get_arg(&v, ap); pack_convert_write(&v, ptype, (WriteFn)pack_writefunc_fp, fp, NULL); } @@ -472,7 +454,7 @@ p = fmt; while (*p != '\0' && offset <= len) { - pack_get_properties(&v, (char **)&p, ap, ptype); + pack_get_properties(&v, (char **)&p, ap); if ((ptr = va_arg(ap, uint8_t *)) == NULL || v.nelem == 0) continue; @@ -542,7 +524,7 @@ p = fmt; while (*p != '\0') { - pack_get_properties(&v, (char **)&p, ap, ptype); + pack_get_properties(&v, (char **)&p, ap); if ((ptr = va_arg(ap, uint8_t *)) == NULL || v.nelem == 0) continue;
--- a/pack.h Sun Jul 15 20:40:54 2012 +0200 +++ b/pack.h Sun Jul 15 20:59:10 2012 +0200 @@ -57,8 +57,8 @@ ((uint32_t) pack_swap32((uint32_t) (((x) << 32) >> 32))) << 32) \ | (uint32_t) pack_swap32((uint32_t) ((x) >> 32))) -size_t pack_fmtlen(int, const char *, ...); -size_t pack_vfmtlen(int, const char *, va_list); +size_t pack_fmtlen(const char *, ...); +size_t pack_vfmtlen(const char *, va_list); int pack_swrite(int, uint8_t **, size_t *, const char *, ...); int pack_vswrite(int, uint8_t **, size_t *, const char *, va_list);