Imported Upstream version 0.19.7
[platform/upstream/gettext.git] / gettext-tools / src / msgattrib.c
index 7732315..1f945b6 100644 (file)
@@ -1,5 +1,6 @@
 /* Manipulates attributes of messages in translation catalogs.
-   Copyright (C) 2001-2007, 2009-2010, 2012 Free Software Foundation, Inc.
+   Copyright (C) 2001-2007, 2009-2010, 2012, 2015 Free Software
+   Foundation, Inc.
    Written by Bruno Haible <haible@clisp.cons.org>, 2001.
 
    This program is free software: you can redistribute it and/or modify
@@ -73,17 +74,19 @@ enum
   SET_OBSOLETE          = 1 << 2,
   RESET_OBSOLETE        = 1 << 3,
   REMOVE_PREV           = 1 << 4,
-  ADD_PREV              = 1 << 5
+  ADD_PREV              = 1 << 5,
+  REMOVE_TRANSLATION    = 1 << 6
 };
 static int to_change;
 
 /* Long options.  */
 static const struct option long_options[] =
 {
-  { "add-location", no_argument, &line_comment, 1 },
+  { "add-location", optional_argument, NULL, 'n' },
   { "clear-fuzzy", no_argument, NULL, CHAR_MAX + 8 },
   { "clear-obsolete", no_argument, NULL, CHAR_MAX + 10 },
   { "clear-previous", no_argument, NULL, CHAR_MAX + 18 },
+  { "empty", no_argument, NULL, CHAR_MAX + 23 },
   { "color", optional_argument, NULL, CHAR_MAX + 19 },
   { "directory", required_argument, NULL, 'D' },
   { "escape", no_argument, NULL, 'E' },
@@ -94,7 +97,7 @@ static const struct option long_options[] =
   { "indent", no_argument, NULL, 'i' },
   { "no-escape", no_argument, NULL, 'e' },
   { "no-fuzzy", no_argument, NULL, CHAR_MAX + 3 },
-  { "no-location", no_argument, &line_comment, 0 },
+  { "no-location", no_argument, NULL, CHAR_MAX + 22 },
   { "no-obsolete", no_argument, NULL, CHAR_MAX + 5 },
   { "no-wrap", no_argument, NULL, CHAR_MAX + 13 },
   { "obsolete", no_argument, NULL, CHAR_MAX + 12 },
@@ -207,7 +210,8 @@ main (int argc, char **argv)
         break;
 
       case 'n':
-        line_comment = 1;
+        if (handle_filepos_comment_option (optarg))
+          usage (EXIT_FAILURE);
         break;
 
       case 'o':
@@ -331,6 +335,14 @@ main (int argc, char **argv)
         to_change |= ADD_PREV;
         break;
 
+      case CHAR_MAX + 22: /* --no-location */
+        message_print_style_filepos (filepos_comment_none);
+        break;
+
+      case CHAR_MAX + 23: /* --empty */
+        to_change |= REMOVE_TRANSLATION;
+        break;
+
       default:
         usage (EXIT_FAILURE);
         /* NOTREACHED */
@@ -367,10 +379,6 @@ There is NO WARRANTY, to the extent permitted by law.\n\
     }
 
   /* Verify selected options.  */
-  if (!line_comment && sort_by_filepos)
-    error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"),
-           "--no-location", "--sort-by-file");
-
   if (sort_by_msgid && sort_by_filepos)
     error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"),
            "--sort-output", "--sort-by-file");
@@ -471,6 +479,8 @@ Attribute manipulation:\n"));
       printf (_("\
       --clear-previous        remove the \"previous msgid\" from all messages\n"));
       printf (_("\
+      --empty                 when removing 'fuzzy', also set msgstr empty\n"));
+      printf (_("\
       --only-file=FILE.po     manipulate only entries listed in FILE.po\n"));
       printf (_("\
       --ignore-file=FILE.po   manipulate only entries not listed in FILE.po\n"));
@@ -614,7 +624,25 @@ process_message_list (message_list_ty *mlp,
                 }
 
               if (to_change & RESET_FUZZY)
-                mp->is_fuzzy = false;
+                {
+                  if ((to_change & REMOVE_TRANSLATION)
+                      && mp->is_fuzzy && !mp->obsolete)
+                    {
+                      unsigned long int nplurals = 0;
+                      char *msgstr;
+                      size_t pos;
+
+                      for (pos = 0; pos < mp->msgstr_len; ++pos)
+                        if (!mp->msgstr[pos])
+                          ++nplurals;
+                      free ((char *) mp->msgstr);
+                      msgstr = XNMALLOC (nplurals, char);
+                      memset (msgstr, '\0', nplurals);
+                      mp->msgstr = msgstr;
+                      mp->msgstr_len = nplurals;
+                    }
+                  mp->is_fuzzy = false;
+                }
               /* Always keep the header entry non-obsolete.  */
               if ((to_change & SET_OBSOLETE) && !is_header (mp))
                 mp->obsolete = true;