From: Ben Pfaff Date: Sat, 6 Nov 2010 04:11:24 +0000 (-0700) Subject: csv: Add ability to suppress table captions. X-Git-Tag: v0.7.7~141 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5deb8ead72bb5b6058594894bec297768692d780;p=pspp-builds.git csv: Add ability to suppress table captions. Requested by Björn Manke . --- diff --git a/doc/invoking.texi b/doc/invoking.texi index 2080a3e2..82d8a5ed 100644 --- a/doc/invoking.texi +++ b/doc/invoking.texi @@ -379,8 +379,11 @@ Specify the output format. This is only necessary if the file name given on @option{-o} does not end in @file{.csv}. @item -O separator=@var{field-separator} -Sets the character used to separate fields. The default is a comma +Sets the character used to separate fields. Default: a comma (@samp{,}). + +@item -O captions=@var{boolean} +Whether table captions should be printed. Default: @code{on}. @end table The CSV format used is an extension to that specified in RFC 4180: @@ -390,8 +393,9 @@ The CSV format used is an extension to that specified in RFC 4180: Each table row is output on a separate line, and each column is output as a field. The contents of a cell that spans multiple rows or columns is output only for the top-left row and column; the rest are -output as empty fields. When a table has a caption, it is output just -above the table as a single field prefixed by @samp{Table:}. +output as empty fields. When a table has a caption and captions are +enabled, the caption is output just above the table as a single field +prefixed by @samp{Table:}. @item Text Text in output is printed as a field on a line by itself. The TITLE diff --git a/src/output/csv.c b/src/output/csv.c index 3fbf53d9..d168fd95 100644 --- a/src/output/csv.c +++ b/src/output/csv.c @@ -45,6 +45,8 @@ struct csv_driver char *separator; /* Field separator (usually comma or tab). */ char *quote_set; /* Characters that force quoting. */ + bool captions; /* Print table captions? */ + char *file_name; /* Output file name. */ char *command_name; /* Current command. */ FILE *file; /* Output file. */ @@ -80,6 +82,7 @@ csv_create (const char *file_name, enum settings_output_devices device_type, csv->separator = parse_string (opt (d, o, "separator", ",")); csv->quote_set = xasprintf ("\"\n\r\t%s", csv->separator); + csv->captions = parse_boolean (opt (d, o, "captions", "true")); csv->file_name = xstrdup (file_name); csv->file = fn_open (csv->file_name, "w"); csv->n_items = 0; @@ -181,7 +184,7 @@ csv_submit (struct output_driver *driver, csv_put_separator (csv); - if (caption != NULL) + if (csv->captions && caption != NULL) { csv_output_field_format (csv, "Table: %s", caption); putc ('\n', csv->file);