/* msgequal.c - Remove all msgstrs from a .po file which are identical to the msgid. (C) 2008 Canonical Ltd. Author: Martin Pitt This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include #include void xerror (int severity, po_message_t message, const char *filename, size_t lineno, size_t column, int multiline_p, const char *message_text) { fprintf (stderr, "%s:%zu: %s\n", filename, lineno, message_text); if (severity == PO_SEVERITY_FATAL_ERROR) { fputs ("FATAL error, aborting\n", stderr); exit (2); } } void xerror2 (int severity, po_message_t message1, const char *filename1, size_t lineno1, size_t column1, int multiline_p1, const char *message_text1, po_message_t message2, const char *filename2, size_t lineno2, size_t column2, int multiline_p2, const char *message_text2) { } int main (int argc, char** argv) { po_file_t po_in, po_out; struct po_xerror_handler eh; po_message_iterator_t msg_iter, out_iter; po_message_t msg; eh.xerror = xerror; eh.xerror2 = xerror2; if (argc != 3) { fputs ("Usage: msgequal \n", stderr); return 1; } /* slurp in file */ po_in = po_file_read (argv[1], &eh); if (!po_in) { perror("Opening input .po file"); return 1; } /* loop over translations and only copy those where msgid != msgstr */ po_out = po_file_create(); out_iter = po_message_iterator (po_out, NULL); msg_iter = po_message_iterator (po_in, NULL); while ((msg = po_next_message (msg_iter)) != NULL) if (strcmp (po_message_msgid (msg), po_message_msgstr (msg))) po_message_insert (out_iter, msg); /* write output file */ if (!po_file_write (po_out, argv[2], &eh)) { perror ("Writing output .po file"); return 1; } return 0; }