From: John Darrington Date: Fri, 31 Jul 2009 17:57:03 +0000 (+0200) Subject: Added a meta.xml file. X-Git-Tag: sid-i386-build98~25 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a7a2de8a6346ede44d011a0554a60afa3699f5ee;p=pspp-builds.git Added a meta.xml file. Add the meta.xml file, to contain (at present) the author's name, version of pspp and time that the document was created. --- diff --git a/src/output/odt.c b/src/output/odt.c index 83f4b17f..f557278d 100644 --- a/src/output/odt.c +++ b/src/output/odt.c @@ -20,14 +20,14 @@ /* A driver for creating OpenDocument Format text files from PSPP's output */ #include -#include #include -#include -#include + #include #include #include +#include +#include #include #include @@ -35,11 +35,6 @@ #include -#include - -#include "error.h" -#include "intprops.h" -#include "minmax.h" #include "xalloc.h" #define _xml(X) (const xmlChar *)(X) @@ -99,6 +94,70 @@ create_writer (const struct odt_driver_ext *driver, const char *filename) return w; } + +static void +register_file (struct odt_driver_ext *x, const char *filename) +{ + assert (x->manifest_wtr); + xmlTextWriterStartElement (x->manifest_wtr, _xml("manifest:file-entry")); + xmlTextWriterWriteAttribute (x->manifest_wtr, _xml("manifest:media-type"), _xml("text/xml")); + xmlTextWriterWriteAttribute (x->manifest_wtr, _xml("manifest:full-path"), _xml (filename)); + xmlTextWriterEndElement (x->manifest_wtr); +} + +static void +write_meta_data (struct odt_driver_ext *x) +{ + xmlTextWriterPtr w = create_writer (x, "meta.xml"); + register_file (x, "meta.xml"); + + xmlTextWriterStartElement (w, _xml ("office:document-meta")); + xmlTextWriterWriteAttribute (w, _xml ("xmlns:office"), _xml ("urn:oasis:names:tc:opendocument:xmlns:office:1.0")); + xmlTextWriterWriteAttribute (w, _xml ("xmlns:dc"), _xml ("http://purl.org/dc/elements/1.1/")); + xmlTextWriterWriteAttribute (w, _xml ("xmlns:meta"), _xml ("urn:oasis:names:tc:opendocument:xmlns:meta:1.0")); + xmlTextWriterWriteAttribute (w, _xml ("xmlns:ooo"), _xml("http://openoffice.org/2004/office")); + xmlTextWriterWriteAttribute (w, _xml ("office:version"), _xml("1.1")); + + xmlTextWriterStartElement (w, _xml ("office:meta")); + { + xmlTextWriterStartElement (w, _xml ("meta:generator")); + xmlTextWriterWriteString (w, _xml (stat_version)); + xmlTextWriterEndElement (w); + } + + + { + 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); + } + + xmlTextWriterEndElement (w); + xmlTextWriterEndElement (w); + xmlTextWriterEndDocument (w); + xmlFreeTextWriter (w); +} + static bool odt_open_driver (const char *name, int types, struct substring option_string) { @@ -129,13 +188,10 @@ odt_open_driver (const char *name, int types, struct substring option_string) xmlTextWriterEndElement (x->manifest_wtr); - x->content_wtr = create_writer (x, "content.xml"); + write_meta_data (x); - /* Add a manifest entry for content.xml */ - xmlTextWriterStartElement (x->manifest_wtr, _xml("manifest:file-entry")); - xmlTextWriterWriteAttribute (x->manifest_wtr, _xml("manifest:media-type"), _xml("text/xml")); - xmlTextWriterWriteAttribute (x->manifest_wtr, _xml("manifest:full-path"), _xml("content.xml")); - xmlTextWriterEndElement (x->manifest_wtr); + x->content_wtr = create_writer (x, "content.xml"); + register_file (x, "content.xml"); /* Some necessary junk at the start */