From: Bruno Haible Date: Sun, 16 Aug 2009 18:55:05 +0000 (+0200) Subject: Reduce dependency on project-id heuristic. X-Git-Tag: v0.18~121 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=245358efa614dda16ee393ee24d723f3dc7c447c;p=thirdparty%2Fgettext.git Reduce dependency on project-id heuristic. --- diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index debde4dae..b234ec27d 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,10 @@ +2009-08-16 Bruno Haible + + Reduce dependency on project-id heuristic. + * msginit.c (project_id): Add header argument. Return first part of + Project-Id-Version field if present. + (fill_header): Update. + 2009-08-13 Bruno Haible * msgexec.c: Include msgl-charset.h. diff --git a/gettext-tools/src/msginit.c b/gettext-tools/src/msginit.c index a6e5c544a..5908925fc 100644 --- a/gettext-tools/src/msginit.c +++ b/gettext-tools/src/msginit.c @@ -810,8 +810,9 @@ englishname_of_language () /* Construct the value for the PACKAGE name. */ static const char * -project_id () +project_id (const char *header) { + const char *old_field; const char *gettextlibdir; char *prog; char *argv[3]; @@ -823,6 +824,33 @@ project_id () size_t linelen; int exitstatus; + /* Return the first part of the Project-Id-Version field if present, assuming + it was already filled in by xgettext. */ + old_field = get_field (header, "Project-Id-Version"); + if (old_field != NULL && strcmp (old_field, "PACKAGE VERSION") != 0) + { + /* Remove the last word from old_field. */ + const char *last_space; + + last_space = strrchr (old_field, ' '); + if (last_space != NULL) + { + while (last_space > old_field && last_space[-1] == ' ') + last_space--; + if (last_space > old_field) + { + size_t package_len = last_space - old_field; + char *package = XNMALLOC (package_len + 1, char); + memcpy (package, old_field, package_len); + package[package_len] = '\0'; + + return package; + } + } + /* It contains no version, just a package name. */ + return old_field; + } + gettextlibdir = getenv ("GETTEXTLIBDIR"); if (gettextlibdir == NULL || gettextlibdir[0] == '\0') gettextlibdir = relocate (LIBDIR "/gettext"); @@ -1649,7 +1677,7 @@ fill_header (msgdomain_list_ty *mdlp) const char *id; time_t now; - id = project_id (); + id = project_id (header); subst[0][0] = "SOME DESCRIPTIVE TITLE"; subst[0][1] = xasprintf (get_title (), id, id); subst[1][0] = "PACKAGE";