aboutsummaryrefslogtreecommitdiff
path: root/src/pack.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2013-10-12 17:29:05 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2013-10-12 17:29:05 +0300
commit66f3521c257d2777cbf9697716a9f2288254376c (patch)
treebe3b4993d1b4bb515f67227bd0647dac4dbc08ff /src/pack.c
parent60a356d55ed0aca4283ddc3134298936e45ad18b (diff)
downloadvmod-binlog-66f3521c257d2777cbf9697716a9f2288254376c.tar.gz
vmod-binlog-66f3521c257d2777cbf9697716a9f2288254376c.tar.bz2
Fix processing repeat counts in packinnext.
* src/binlog.c (vmod_start): call packinit. * src/pack.c (packinst) <cur>: New member. (packinnext): Correctly process repeat counts. (packout): Likewise. (packinit): New function. * src/pack.h (packinit): New proto.
Diffstat (limited to 'src/pack.c')
-rw-r--r--src/pack.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/pack.c b/src/pack.c
index 12dc19d..2e7e7a6 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -69,6 +69,7 @@ struct packinst {
struct packinst *next;
struct packspec *spec;
int rep;
+ int cur;
};
static char *
@@ -509,10 +510,12 @@ packinnext(struct packinst *pi, struct packenv *env)
return NULL;
if (pi->spec->flags & F_REP)
pi->spec->packer(env, pi->spec, pi->rep);
- else
- for (i = 0; i < pi->rep; i++)
- pi->spec->packer(env, pi->spec, 1);
- return pi->next;
+ else {
+ pi->spec->packer(env, pi->spec, 1);
+ if (++pi->cur < pi->rep)
+ return pi;
+ }
+ return packinit(pi->next);
}
void
@@ -524,8 +527,11 @@ packout(struct packinst *pi, struct packenv *env)
if (pi->spec->flags & F_REP)
pi->spec->unpacker(env, pi->spec, pi->rep);
else
- for (i = 0; i < pi->rep; i++)
+ for (i = 0; i < pi->rep; i++) {
+ if (i > 0)
+ fputc(' ', env->fp);
pi->spec->unpacker(env, pi->spec, 1);
+ }
if (pi->next)
fputc(' ', env->fp);
}
@@ -541,6 +547,14 @@ packsize(struct packinst *pi)
return env.buf_pos;
}
+struct packinst *
+packinit(struct packinst *inst)
+{
+ if (inst)
+ inst->cur = 0;
+ return inst;
+}
+
struct packenv *
packenv_create(size_t size)
{

Return to:

Send suggestions and report system problems to the System administrator.