Blame catgets/xopen-msg.awk

Packit 6c4009
# xopen-msg.awk - Convert Uniforum style .po file to X/Open style .msg file
Packit 6c4009
# Copyright (C) 2012-2018 Free Software Foundation, Inc.
Packit 6c4009
#
Packit 6c4009
# This program is free software; you can redistribute it and/or modify
Packit 6c4009
# it under the terms of the GNU General Public License as published by
Packit 6c4009
# the Free Software Foundation; either version 2, or (at your option)
Packit 6c4009
# any later version.
Packit 6c4009
#
Packit 6c4009
# This program is distributed in the hope that it will be useful,
Packit 6c4009
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 6c4009
# GNU General Public License for more details.
Packit 6c4009
#
Packit 6c4009
# You should have received a copy of the GNU General Public License
Packit 6c4009
# along with this program; if not, see <http://www.gnu.org/licenses/>.
Packit 6c4009
#
Packit 6c4009
#
Packit 6c4009
# The first directive in the .msg should be the definition of the
Packit 6c4009
# message set number.  We use always set number 1.
Packit 6c4009
#
Packit 6c4009
BEGIN {
Packit 6c4009
    print "$set 1 # Automatically created by xopen-msg.awk"
Packit 6c4009
    num = 0
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#
Packit 6c4009
# The .msg file contains, other then the .po file, only the translations
Packit 6c4009
# but each given a unique ID.  Starting from 1 and incrementing by 1 for
Packit 6c4009
# each message we assign them to the messages.
Packit 6c4009
# It is important that the .po file used to generate the ../intl/msg.h file
Packit 6c4009
# (with po2test.awk) is the same as the one used here.  (At least the order
Packit 6c4009
# of declarations must not be changed.)
Packit 6c4009
#
Packit 6c4009
function output_message() {
Packit 6c4009
    # Ignore messages containing <PRI.*> which would have to be replaced
Packit 6c4009
    # by the correct format depending on the word size
Packit 6c4009
    if (msg && msg !~ /<PRI.*>/) {
Packit 6c4009
	if (msgtype == "msgid") {
Packit 6c4009
	    # We copy the original message as a comment into the .msg file.
Packit 6c4009
	    gsub(/\n/, "\n$ ", msg)
Packit 6c4009
	    printf "$ Original Message: %s\n", msg
Packit 6c4009
	} else {
Packit 6c4009
	    gsub(/\n/, "\\\n", msg)
Packit 6c4009
	    printf "%d %s\n", ++num, msg
Packit 6c4009
	}
Packit 6c4009
    }
Packit 6c4009
    msg = 0
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
$1 ~ "msg(id|str)" {
Packit 6c4009
    # Output collected message
Packit 6c4009
    output_message()
Packit 6c4009
    # Collect next message
Packit 6c4009
    msgtype = $1
Packit 6c4009
    sub(/^msg(id|str)[ \t]*"/, "", $0)
Packit 6c4009
    sub(/"$/, "", $0)
Packit 6c4009
    msg = $0
Packit 6c4009
    next
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/^"POT-Creation-Date: [0-9-]+ [0-9:+-]+\\n"/ {
Packit 6c4009
    # Ignore POT-Creation-Date to match what is done in intl/Makefile.
Packit 6c4009
    next
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/^".*"/ {
Packit 6c4009
    # Append to current message
Packit 6c4009
    sub(/^"/, "", $0)
Packit 6c4009
    sub(/"$/, "", $0)
Packit 6c4009
    msg = msg "\n" $0
Packit 6c4009
    next
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
END {
Packit 6c4009
    # Output last collected message
Packit 6c4009
    output_message()
Packit 6c4009
}