X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Foutput%2Fodt.c;h=99f5e60d6ec7cb8fdb45265f424b16a37f18d133;hb=16c70c9f2e041d4ff21f57c29be37e60be40c089;hp=ab38cd0411c91d779a860f86c7380896d6e425de;hpb=f51ecb48027e6b1eb46840ae25888a25b429f012;p=pspp-builds.git diff --git a/src/output/odt.c b/src/output/odt.c index ab38cd04..99f5e60d 100644 --- a/src/output/odt.c +++ b/src/output/odt.c @@ -21,7 +21,9 @@ #include #include #include +#ifdef HAVE_PWD_H #include +#endif #include #include #include @@ -32,6 +34,7 @@ #include "libpspp/str.h" #include "libpspp/version.h" #include "output/driver-provider.h" +#include "output/message-item.h" #include "output/options.h" #include "output/tab.h" #include "output/table-item.h" @@ -64,6 +67,9 @@ struct odt_driver /* Number of tables so far. */ int table_num; + + /* Name of current command. */ + char *command_name; }; static const struct output_driver_class odt_driver_class; @@ -87,7 +93,7 @@ create_mimetype (const char *dirname) if (fp == NULL) { - error (0, errno, _("failed to create output file %s"), + error (0, errno, _("error opening output file \"%s\""), ds_cstr (&filename)); ds_destroy (&filename); return false; @@ -251,30 +257,36 @@ write_meta_data (struct odt_driver *odt) { char buf[30]; - struct passwd *pw = getpwuid (getuid ()); time_t t = time (NULL); struct tm *tm = localtime (&t); strftime (buf, 30, "%Y-%m-%dT%H:%M:%S", tm); - xmlTextWriterStartElement (w, _xml ("meta:initial-creator")); - xmlTextWriterWriteString (w, _xml (strtok (pw->pw_gecos, ","))); - xmlTextWriterEndElement (w); - xmlTextWriterStartElement (w, _xml ("meta:creation-date")); xmlTextWriterWriteString (w, _xml (buf)); xmlTextWriterEndElement (w); - xmlTextWriterStartElement (w, _xml ("dc:creator")); - xmlTextWriterWriteString (w, _xml (strtok (pw->pw_gecos, ","))); - - xmlTextWriterEndElement (w); - xmlTextWriterStartElement (w, _xml ("dc:date")); xmlTextWriterWriteString (w, _xml (buf)); xmlTextWriterEndElement (w); } +#ifdef HAVE_PWD_H + { + struct passwd *pw = getpwuid (getuid ()); + if (pw != NULL) + { + xmlTextWriterStartElement (w, _xml ("meta:initial-creator")); + xmlTextWriterWriteString (w, _xml (strtok (pw->pw_gecos, ","))); + xmlTextWriterEndElement (w); + + xmlTextWriterStartElement (w, _xml ("dc:creator")); + xmlTextWriterWriteString (w, _xml (strtok (pw->pw_gecos, ","))); + xmlTextWriterEndElement (w); + } + } +#endif + xmlTextWriterEndElement (w); xmlTextWriterEndElement (w); xmlTextWriterEndDocument (w); @@ -403,6 +415,7 @@ odt_destroy (struct output_driver *driver) else fprintf (stderr, "Not removing directory %s\n", odt->dirname); + free (odt->command_name); free (odt->dirname); free (odt); } @@ -503,23 +516,37 @@ odt_submit_table (struct odt_driver *odt, struct table_item *item) xmlTextWriterEndElement (odt->content_wtr); /* table */ } +static void +odt_output_text (struct odt_driver *odt, const char *text) +{ + xmlTextWriterStartElement (odt->content_wtr, _xml("text:p")); + xmlTextWriterWriteString (odt->content_wtr, _xml(text)); + xmlTextWriterEndElement (odt->content_wtr); +} + /* Submit a table to the ODT driver */ static void odt_submit (struct output_driver *driver, const struct output_item *output_item) { struct odt_driver *odt = odt_driver_cast (driver); + + output_driver_track_current_command (output_item, &odt->command_name); + if (is_table_item (output_item)) odt_submit_table (odt, to_table_item (output_item)); else if (is_text_item (output_item)) { - const struct text_item *text_item = to_text_item (output_item); - const char *text = text_item_get_text (text_item); - /* XXX apply different styles based on text_item's type. */ - xmlTextWriterStartElement (odt->content_wtr, _xml("text:p")); - xmlTextWriterWriteString (odt->content_wtr, _xml(text)); - xmlTextWriterEndElement (odt->content_wtr); + odt_output_text (odt, text_item_get_text (to_text_item (output_item))); + } + else if (is_message_item (output_item)) + { + const struct message_item *message_item = to_message_item (output_item); + const struct msg *msg = message_item_get_msg (message_item); + char *s = msg_to_string (msg, odt->command_name); + odt_output_text (odt, s); + free (s); } }