X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Foutput%2Fcsv.c;h=e6b769b383039c740abdb9c5321c86b5d889724a;hb=12b9efe4bcd6ef6e5a87df9108e4ba49182730b4;hp=b1ad6b0c172b48687f6122721eb5cf291073b836;hpb=6132656980af2e8527e3e83c8418846ef4c478c7;p=pspp diff --git a/src/output/csv.c b/src/output/csv.c index b1ad6b0c17..e6b769b383 100644 --- a/src/output/csv.c +++ b/src/output/csv.c @@ -65,44 +65,46 @@ csv_driver_cast (struct output_driver *driver) return UP_CAST (driver, struct csv_driver, driver); } -static struct driver_option * -opt (struct output_driver *d, struct string_map *options, const char *key, - const char *default_value) +static struct driver_option +opt (struct driver_options *options, const char *key, const char *default_value) { - return driver_option_get (d, options, key, default_value); + return driver_option_get (options, key, default_value); } static struct output_driver * csv_create (struct file_handle *fh, enum settings_output_devices device_type, - struct string_map *o) + struct driver_options *o) { - struct output_driver *d; - struct csv_driver *csv; - char *quote; - - csv = xzalloc (sizeof *csv); - d = &csv->driver; - output_driver_init (&csv->driver, &csv_driver_class, fh_get_file_name (fh), device_type); - - csv->separator = parse_string (opt (d, o, "separator", ",")); - quote = parse_string (opt (d, o, "quote", "\"")); - csv->quote = quote[0]; - free (quote); - csv->quote_set = xasprintf ("\n\r\t%s%c", csv->separator, csv->quote); - csv->titles = parse_boolean (opt (d, o, "titles", "true")); - csv->captions = parse_boolean (opt (d, o, "captions", "true")); - csv->handle = fh; - csv->file = fn_open (fh, "w"); - csv->n_items = 0; - - if (csv->file == NULL) + FILE *file = fn_open (fh, "w"); + if (!file) { msg_error (errno, _("error opening output file `%s'"), fh_get_file_name (fh)); - output_driver_destroy (d); return NULL; } - return d; + char *quote_s = parse_string (opt (o, "quote", "\"")); + int quote = quote_s[0]; + free (quote_s); + + char *separator = parse_string (opt (o, "separator", ",")); + + struct csv_driver *csv = xmalloc (sizeof *csv); + *csv = (struct csv_driver) { + .driver = { + .class = &csv_driver_class, + .name = xstrdup (fh_get_file_name (fh)), + .device_type = device_type, + }, + .separator = separator, + .quote = quote, + .quote_set = xasprintf ("\n\r\t%s%c", separator, quote), + .titles = parse_boolean (opt (o, "titles", "true")), + .captions = parse_boolean (opt (o, "captions", "true")), + .handle = fh, + .file = file, + }; + + return &csv->driver; } static void