X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Foutput%2Fodt.c;h=c0a386e653d502cc9207616534ac8bd76885f18e;hb=14be690de6bd259d26e710ad5363e106afde1e93;hp=721e7c87d9766dec20761e7100aba0ca6b24ea5b;hpb=97f9b8ad137e333af9b3c767556d28dfda93a461;p=pspp diff --git a/src/output/odt.c b/src/output/odt.c index 721e7c87d9..c0a386e653 100644 --- a/src/output/odt.c +++ b/src/output/odt.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 2009, 2010, 2011, 2012, 2014 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -31,6 +31,7 @@ #include "libpspp/assertion.h" #include "libpspp/cast.h" +#include "libpspp/message.h" #include "libpspp/str.h" #include "libpspp/temp-file.h" #include "libpspp/version.h" @@ -44,7 +45,6 @@ #include "output/text-item.h" #include "gl/xalloc.h" -#include "gl/error.h" #include "gettext.h" #define _(msgid) gettext (msgid) @@ -91,7 +91,7 @@ create_mimetype (struct zip_writer *zip) fp = create_temp_file (); if (fp == NULL) { - error (0, errno, _("error creating temporary file")); + msg_error (errno, _("error creating temporary file")); return false; } @@ -380,10 +380,36 @@ odt_destroy (struct output_driver *driver) zip_writer_close (odt->zip); } + free (odt->file_name); free (odt->command_name); free (odt); } +static void +write_xml_with_line_breaks (xmlTextWriterPtr writer, char *line) +{ + char *newline; + char *p; + + for (p = line; *p; p = newline + 1) + { + newline = strchr (p, '\n'); + + if (!newline) + { + xmlTextWriterWriteString (writer, _xml(p)); + return; + } + + if (newline > p && newline[-1] == '\r') + newline[-1] = '\0'; + else + *newline = '\0'; + xmlTextWriterWriteString (writer, _xml(p)); + xmlTextWriterWriteElement (writer, _xml("text:line-break"), _xml("")); + } +} + static void odt_submit_table (struct odt_driver *odt, struct table_item *item) { @@ -457,7 +483,14 @@ odt_submit_table (struct odt_driver *odt, struct table_item *item) else xmlTextWriterWriteAttribute (odt->content_wtr, _xml("text:style-name"), _xml("Table_20_Contents")); - xmlTextWriterWriteString (odt->content_wtr, _xml(cell.contents)); + if (strchr (cell.contents, '\n')) + { + char *line = xstrdup (cell.contents); + write_xml_with_line_breaks (odt->content_wtr, line); + free (line); + } + else + xmlTextWriterWriteString (odt->content_wtr, _xml(cell.contents)); xmlTextWriterEndElement (odt->content_wtr); /* text:p */ xmlTextWriterEndElement (odt->content_wtr); /* table:table-cell */ @@ -501,8 +534,10 @@ odt_submit (struct output_driver *driver, odt_submit_table (odt, to_table_item (output_item)); else if (is_text_item (output_item)) { - /* XXX apply different styles based on text_item's type. */ - odt_output_text (odt, text_item_get_text (to_text_item (output_item))); + struct text_item *text_item = to_text_item (output_item); + + if (text_item_get_type (text_item) != TEXT_ITEM_COMMAND_CLOSE) + odt_output_text (odt, text_item_get_text (text_item)); } else if (is_message_item (output_item)) { @@ -514,7 +549,8 @@ odt_submit (struct output_driver *driver, } } -struct output_driver_factory odt_driver_factory = { "odt", odt_create }; +struct output_driver_factory odt_driver_factory = + { "odt", "pspp.odf", odt_create }; static const struct output_driver_class odt_driver_class = {