#include "msgl-ascii.h"
#include "msgl-ofn.h"
#include "xg-check.h"
+#include "vc-mtime.h"
#include "po-time.h"
+#include "msgl-header.h"
#include "write-catalog.h"
#include "write-po.h"
#include "write-properties.h"
/* If nonzero add comments used by itstool. */
static bool add_itstool_comments = false;
+/* Accumulating the version-controlled modification times of file names. */
+static bool has_some_mtimes = false;
+static struct timespec max_of_mtimes;
+static bool some_mtimes_failed = false;
+
/* Long options. */
static const struct option long_options[] =
{
{ "package-version", required_argument, NULL, CHAR_MAX + 13 },
{ "properties-output", no_argument, NULL, CHAR_MAX + 6 },
{ "qt", no_argument, NULL, CHAR_MAX + 9 },
+ { "reference", required_argument, NULL, CHAR_MAX + 22 },
{ "sentence-end", required_argument, NULL, CHAR_MAX + 18 },
{ "sort-by-file", no_argument, NULL, 'F' },
{ "sort-output", no_argument, NULL, 's' },
/* Forward declaration of local functions. */
_GL_NORETURN_FUNC static void usage (int status);
static void read_exclusion_file (char *file_name);
+static void consider_vc_mtime (const char *file_name);
static void extract_from_file (const char *file_name, extractor_ty extractor,
msgdomain_list_ty *mdlp);
static void extract_from_xml_file (const char *file_name,
x_javascript_tag (optarg);
break;
+ case CHAR_MAX + 22: /* --reference */
+ consider_vc_mtime (optarg);
+ break;
+
default:
usage (EXIT_FAILURE);
/* NOTREACHED */
/* Determine list of files we have to process. */
if (files_from != NULL)
- file_list = read_names_from_file (files_from);
+ {
+ if (strcmp (files_from, "-") != 0)
+ consider_vc_mtime (files_from);
+ file_list = read_names_from_file (files_from);
+ }
else
file_list = string_list_alloc ();
/* Append names from command line. */
printf (_("\
--msgid-bugs-address=EMAIL@ADDRESS set report address for msgid bugs\n"));
printf (_("\
+ --reference=FILE Declares that the output depends on the contents\n\
+ of the given FILE. This has an influence on the\n\
+ 'POT-Creation-Date' field in the output.\n"));
+ printf (_("\
-m[STRING], --msgstr-prefix[=STRING] use STRING or \"\" as prefix for msgstr\n\
values\n"));
printf (_("\
}
+static void
+consider_vc_mtime (const char *file_name)
+{
+ struct timespec mtime;
+ if (vc_mtime (&mtime, file_name) >= 0)
+ {
+ if (has_some_mtimes)
+ {
+ /* Compute the maximum of max_of_mtimes and mtime. */
+ if (max_of_mtimes.tv_sec < mtime.tv_sec
+ || (max_of_mtimes.tv_sec == mtime.tv_sec
+ && max_of_mtimes.tv_nsec < mtime.tv_nsec))
+ max_of_mtimes = mtime;
+ }
+ else
+ max_of_mtimes = mtime;
+ }
+ else
+ some_mtimes_failed = true;
+ has_some_mtimes = true;
+}
+
+
static void
exclude_directive_domain (abstract_catalog_reader_ty *catr,
char *name, lex_pos_ty *name_pos)
{
char *real_filename;
FILE *fp = open_catalog_file (filename, &real_filename, true);
- abstract_catalog_reader_ty *catr;
- catr = catalog_reader_alloc (&exclude_methods, textmode_xerror_handler);
+ consider_vc_mtime (real_filename);
+
+ abstract_catalog_reader_ty *catr =
+ catalog_reader_alloc (&exclude_methods, textmode_xerror_handler);
catalog_reader_parse (catr, fp, real_filename, filename, true, &input_format_po);
catalog_reader_free (catr);
if (extractor.extract_from_stream)
{
FILE *fp = xgettext_open (file_name, &logical_file_name, &real_file_name);
+ if (fp != stdin)
+ consider_vc_mtime (real_file_name);
/* Set the default for the source file encoding. May be overridden by
the extractor function. */
const char *found_in_dir;
xgettext_find_file (file_name, &logical_file_name,
&found_in_dir, &real_file_name);
+ consider_vc_mtime (real_file_name);
extractor.extract_from_file (found_in_dir, real_file_name,
logical_file_name,
char *logical_file_name;
char *real_file_name;
FILE *fp = xgettext_open (file_name, &logical_file_name, &real_file_name);
+ if (fp != stdin)
+ consider_vc_mtime (real_file_name);
/* The default encoding for XML is UTF-8. It can be overridden by
an XML declaration in the XML file itself, not through the
if (fp != stdin)
fclose (fp);
+ consider_vc_mtime (real_file_name);
free (logical_file_name);
free (real_file_name);
}
construct_header ()
{
char *project_id_version;
- time_t now;
- char *timestring;
message_ty *mp;
char *msgstr;
char *comment;
specify an --msgid-bugs-address command line option.\n\
")));
- time (&now);
- timestring = po_strftime (&now);
-
msgstr = xasprintf ("\
Project-Id-Version: %s\n\
Report-Msgid-Bugs-To: %s\n\
-POT-Creation-Date: %s\n\
+POT-Creation-Date: \n\
PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n\
Last-Translator: FULL NAME <EMAIL@ADDRESS>\n\
Language-Team: LANGUAGE <LL@li.org>\n\
Content-Type: text/plain; charset=CHARSET\n\
Content-Transfer-Encoding: 8bit\n",
project_id_version,
- msgid_bugs_address != NULL ? msgid_bugs_address : "",
- timestring);
+ msgid_bugs_address != NULL ? msgid_bugs_address : "");
assume (msgstr != NULL);
- free (timestring);
free (project_id_version);
mp = message_alloc (NULL, "", NULL, msgstr, strlen (msgstr) + 1, &pos);
static void
finalize_header (msgdomain_list_ty *mdlp)
{
+ /* Set the POT-Creation-Date field. */
+ {
+ time_t stamp;
+ if (has_some_mtimes && !some_mtimes_failed)
+ /* Use the maximum of the encountered mtimes. */
+ stamp = max_of_mtimes.tv_sec;
+ else
+ /* Use the current time. */
+ time (&stamp);
+ char *timestring = po_strftime (&stamp);
+ msgdomain_list_set_header_field (mdlp, "POT-Creation-Date:", timestring);
+ free (timestring);
+ }
+
/* If the generated PO file has plural forms, add a Plural-Forms template
to the constructed header. */
{