From: Ben Pfaff Date: Sat, 20 Jun 2009 05:57:16 +0000 (-0700) Subject: output: Make outp_parse_options slightly more general-purpose. X-Git-Tag: v0.7.3~34 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=18121006e5416f858633900820c4518dd30479c4;p=pspp-builds.git output: Make outp_parse_options slightly more general-purpose. This function can be a little more flexible in the interface it offers its callers by letting them provide general auxiliary data instead of having to provide a struct outp_driver *. --- diff --git a/src/output/ascii.c b/src/output/ascii.c index c6a808e8..5a33a661 100644 --- a/src/output/ascii.c +++ b/src/output/ascii.c @@ -133,7 +133,7 @@ struct ascii_driver_ext static void ascii_flush (struct outp_driver *); static int get_default_box_char (size_t idx); static bool update_page_size (struct outp_driver *, bool issue_error); -static bool handle_option (struct outp_driver *this, const char *key, +static bool handle_option (void *this, const char *key, const struct string *val); static bool @@ -176,7 +176,7 @@ ascii_open_driver (const char *name, int types, struct substring options) x->line_cap = 0; x->chart_cnt = 0; - if (!outp_parse_options (options, handle_option, this)) + if (!outp_parse_options (this->name, options, handle_option, this)) goto error; if (!update_page_size (this, true)) @@ -317,9 +317,10 @@ static const struct outp_option option_tab[] = }; static bool -handle_option (struct outp_driver *this, const char *key, +handle_option (void *this_, const char *key, const struct string *val) { + struct outp_driver *this = this_; struct ascii_driver_ext *x = this->ext; int subcat; const char *value; diff --git a/src/output/cairo.c b/src/output/cairo.c index 53c454c2..8da63817 100644 --- a/src/output/cairo.c +++ b/src/output/cairo.c @@ -124,7 +124,7 @@ struct xr_driver_ext struct xr_font fonts[OUTP_FONT_CNT]; }; -static bool handle_option (struct outp_driver *this, const char *key, +static bool handle_option (void *this, const char *key, const struct string *val); static void draw_headers (struct outp_driver *this); @@ -173,7 +173,7 @@ xr_open_driver (const char *name, int types, struct substring options) font->layout = NULL; } - outp_parse_options (options, handle_option, this); + outp_parse_options (name, options, handle_option, this); width_pt = x->paper_width / 1000.0; length_pt = x->paper_length / 1000.0; @@ -318,9 +318,10 @@ static const struct outp_option option_tab[] = }; static bool -handle_option (struct outp_driver *this, const char *key, +handle_option (void *this_, const char *key, const struct string *val) { + struct outp_driver *this = this_; struct xr_driver_ext *x = this->ext; int subcat; char *value = ds_cstr (val); diff --git a/src/output/html.c b/src/output/html.c index 08931f52..bfe0850d 100644 --- a/src/output/html.c +++ b/src/output/html.c @@ -47,7 +47,7 @@ static void escape_string (FILE *file, const char *text, size_t length, const char *space); -static bool handle_option (struct outp_driver *this, +static bool handle_option (void *this, const char *key, const struct string *val); static void print_title_tag (FILE *file, const char *name, const char *content); @@ -65,7 +65,7 @@ html_open_driver (const char *name, int types, struct substring options) x->file = NULL; x->chart_cnt = 0; - outp_parse_options (options, handle_option, this); + outp_parse_options (name, options, handle_option, this); x->file = fn_open (x->file_name, "w"); if (x->file == NULL) @@ -161,9 +161,9 @@ static const struct outp_option option_tab[] = }; static bool -handle_option (struct outp_driver *this, - const char *key, const struct string *val) +handle_option (void *this_, const char *key, const struct string *val) { + struct outp_driver *this = this_; struct html_driver_ext *x = this->ext; int subcat; diff --git a/src/output/output.c b/src/output/output.c index 6082d249..c0747a97 100644 --- a/src/output/output.c +++ b/src/output/output.c @@ -594,10 +594,9 @@ get_option_token (struct substring *s, const char *driver_name, } bool -outp_parse_options (struct substring options, - bool (*callback) (struct outp_driver *, const char *key, - const struct string *value), - struct outp_driver *driver) +outp_parse_options (const char *driver_name, struct substring options, + bool (*callback) (void *aux, const char *key, + const struct string *value), void *aux) { struct string key = DS_EMPTY_INITIALIZER; struct string value = DS_EMPTY_INITIALIZER; @@ -610,7 +609,7 @@ outp_parse_options (struct substring options, if (ss_is_empty (left)) break; - if (!get_option_token (&left, driver->name, &key)) + if (!get_option_token (&left, driver_name, &key)) break; ss_ltrim (&left, ss_cstr (CC_SPACES)); @@ -618,15 +617,15 @@ outp_parse_options (struct substring options, { error (0, 0, _("syntax error expecting `=' " "parsing options for driver \"%s\""), - driver->name); + driver_name); break; } ss_ltrim (&left, ss_cstr (CC_SPACES)); - if (!get_option_token (&left, driver->name, &value)) + if (!get_option_token (&left, driver_name, &value)) break; - ok = callback (driver, ds_cstr (&key), &value); + ok = callback (aux, ds_cstr (&key), &value); } while (ok); diff --git a/src/output/output.h b/src/output/output.h index 47680fee..bfab57ec 100644 --- a/src/output/output.h +++ b/src/output/output.h @@ -151,10 +151,10 @@ void outp_list_classes (void); void outp_enable_device (bool enable, int device); struct outp_driver *outp_drivers (struct outp_driver *); -bool outp_parse_options (struct substring options, - bool (*) (struct outp_driver *, const char *key, - const struct string *value), - struct outp_driver *); +bool outp_parse_options (const char *driver_name, struct substring options, + bool (*callback) (void *aux, const char *key, + const struct string *value), + void *aux); int outp_match_keyword (const char *, const struct outp_option *, int *); int outp_evaluate_dimension (const char *); diff --git a/src/output/postscript.c b/src/output/postscript.c index 4f486cca..1fdc8d69 100644 --- a/src/output/postscript.c +++ b/src/output/postscript.c @@ -110,7 +110,7 @@ struct ps_driver_ext /* Transform logical y-ordinate Y into a page ordinate. */ #define YT(Y) (this->length - (Y)) -static bool handle_option (struct outp_driver *this, const char *key, +static bool handle_option (void *this, const char *key, const struct string *val); static void draw_headers (struct outp_driver *this); @@ -152,7 +152,7 @@ ps_open_driver (const char *name, int types, struct substring options) for (i = 0; i < OUTP_FONT_CNT; i++) x->fonts[i] = NULL; - outp_parse_options (options, handle_option, this); + outp_parse_options (this->name, options, handle_option, this); x->file = fn_open (x->file_name, "w"); if (x->file == NULL) @@ -299,9 +299,10 @@ static const struct outp_option option_tab[] = }; static bool -handle_option (struct outp_driver *this, const char *key, +handle_option (void *this_, const char *key, const struct string *val) { + struct outp_driver *this = this_; struct ps_driver_ext *x = this->ext; int subcat; char *value = ds_cstr (val);