From a564b5d03e5d2ba5b2feea24dcebde9696d6727e Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Mon, 8 Aug 2016 16:52:10 -0300 Subject: [PATCH] eeshow/cro.c (new_cc): separate context creation from option parsing --- eeshow/cro.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/eeshow/cro.c b/eeshow/cro.c index a6be06c..4cbc064 100644 --- a/eeshow/cro.c +++ b/eeshow/cro.c @@ -255,10 +255,9 @@ static const struct gfx_ops real_cro_ops = { }; -static struct cro_ctx *init_common(int argc, char *const *argv) +static struct cro_ctx *new_cc(void) { struct cro_ctx *cc; - char c; cc = alloc_type(struct cro_ctx); cc->xo = cc->yo = 0; @@ -270,6 +269,22 @@ static struct cro_ctx *init_common(int argc, char *const *argv) cc->color_override = COLOR_NONE; cc->output_name = NULL; + + /* + * record_init does not perform allocations or such, so it's safe to + * call it here even if we don't use this facility. + */ + record_init(&cc->record, &real_cro_ops, cc); + + return cc; +} + + +static struct cro_ctx *init_common(int argc, char *const *argv) +{ + struct cro_ctx *cc = new_cc(); + char c; + while ((c = getopt(argc, argv, "o:s:")) != EOF) switch (c) { case 'o': @@ -282,8 +297,6 @@ static struct cro_ctx *init_common(int argc, char *const *argv) usage(*argv); } - record_init(&cc->record, &real_cro_ops, cc); - return cc; }