xref: /openbsd-src/gnu/usr.bin/binutils/intl/linux-msg.sed (revision d2201f2f89f0be1a0be6f7568000ed297414a06d)
1f7cc78ecSespie# po2msg.sed - Convert Uniforum style .po file to Linux style .msg file
2*d2201f2fSdrahn# Copyright 1995, 2002 Free Software Foundation, Inc.
3f7cc78ecSespie# Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
4f7cc78ecSespie#
5f7cc78ecSespie# This program is free software; you can redistribute it and/or modify
6f7cc78ecSespie# it under the terms of the GNU General Public License as published by
7f7cc78ecSespie# the Free Software Foundation; either version 2, or (at your option)
8f7cc78ecSespie# any later version.
9f7cc78ecSespie#
10f7cc78ecSespie# This program is distributed in the hope that it will be useful,
11f7cc78ecSespie# but WITHOUT ANY WARRANTY; without even the implied warranty of
12f7cc78ecSespie# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13f7cc78ecSespie# GNU General Public License for more details.
14f7cc78ecSespie#
15f7cc78ecSespie# You should have received a copy of the GNU General Public License
16f7cc78ecSespie# along with this program; if not, write to the Free Software
17f7cc78ecSespie# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18f7cc78ecSespie#
19f7cc78ecSespie#
20f7cc78ecSespie# The first directive in the .msg should be the definition of the
21f7cc78ecSespie# message set number.  We use always set number 1.
22f7cc78ecSespie#
23f7cc78ecSespie1 {
24f7cc78ecSespie  i\
25f7cc78ecSespie$set 1 # Automatically created by po2msg.sed
26f7cc78ecSespie  h
27f7cc78ecSespie  s/.*/0/
28f7cc78ecSespie  x
29f7cc78ecSespie}
30f7cc78ecSespie#
31f7cc78ecSespie# Mitch's old catalog format does not allow comments.
32f7cc78ecSespie#
33f7cc78ecSespie# We copy the original message as a comment into the .msg file.
34f7cc78ecSespie#
35f7cc78ecSespie/^msgid/ {
36f7cc78ecSespie  s/msgid[ 	]*"//
37f7cc78ecSespie#
38f7cc78ecSespie# This does not work now with the new format.
39f7cc78ecSespie# /"$/! {
40f7cc78ecSespie#   s/\\$//
41f7cc78ecSespie#   s/$/ ... (more lines following)"/
42f7cc78ecSespie# }
43f7cc78ecSespie  x
44f7cc78ecSespie# The following nice solution is by
45f7cc78ecSespie# Bruno <Haible@ma2s2.mathematik.uni-karlsruhe.de>
46f7cc78ecSespie  td
47f7cc78ecSespie# Increment a decimal number in pattern space.
48f7cc78ecSespie# First hide trailing `9' digits.
49f7cc78ecSespie  :d
50f7cc78ecSespie  s/9\(_*\)$/_\1/
51f7cc78ecSespie  td
52f7cc78ecSespie# Assure at least one digit is available.
53f7cc78ecSespie  s/^\(_*\)$/0\1/
54f7cc78ecSespie# Increment the last digit.
55f7cc78ecSespie  s/8\(_*\)$/9\1/
56f7cc78ecSespie  s/7\(_*\)$/8\1/
57f7cc78ecSespie  s/6\(_*\)$/7\1/
58f7cc78ecSespie  s/5\(_*\)$/6\1/
59f7cc78ecSespie  s/4\(_*\)$/5\1/
60f7cc78ecSespie  s/3\(_*\)$/4\1/
61f7cc78ecSespie  s/2\(_*\)$/3\1/
62f7cc78ecSespie  s/1\(_*\)$/2\1/
63f7cc78ecSespie  s/0\(_*\)$/1\1/
64f7cc78ecSespie# Convert the hidden `9' digits to `0's.
65f7cc78ecSespie  s/_/0/g
66f7cc78ecSespie  x
67f7cc78ecSespie  G
68f7cc78ecSespie  s/\(.*\)"\n\([0-9]*\)/$ #\2 Original Message:(\1)/p
69f7cc78ecSespie}
70f7cc78ecSespie#
71*d2201f2fSdrahn# The .msg file contains, other than the .po file, only the translations
72f7cc78ecSespie# but each given a unique ID.  Starting from 1 and incrementing by 1 for
73f7cc78ecSespie# each message we assign them to the messages.
74f7cc78ecSespie# It is important that the .po file used to generate the cat-id-tbl.c file
75f7cc78ecSespie# (with po-to-tbl) is the same as the one used here.  (At least the order
76f7cc78ecSespie# of declarations must not be changed.)
77f7cc78ecSespie#
78f7cc78ecSespie/^msgstr/ {
79f7cc78ecSespie  s/msgstr[ 	]*"\(.*\)"/# \1/
80f7cc78ecSespie# Clear substitution flag.
81f7cc78ecSespie  tb
82f7cc78ecSespie# Append the next line.
83f7cc78ecSespie  :b
84f7cc78ecSespie  N
85f7cc78ecSespie# Look whether second part is continuation line.
86f7cc78ecSespie  s/\(.*\n\)"\(.*\)"/\1\2/
87f7cc78ecSespie# Yes, then branch.
88f7cc78ecSespie  ta
89f7cc78ecSespie  P
90f7cc78ecSespie  D
91f7cc78ecSespie# Note that D includes a jump to the start!!
92f7cc78ecSespie# We found a continuation line.  But before printing insert '\'.
93f7cc78ecSespie  :a
94f7cc78ecSespie  s/\(.*\)\(\n.*\)/\1\\\2/
95f7cc78ecSespie  P
96f7cc78ecSespie# We cannot use D here.
97f7cc78ecSespie  s/.*\n\(.*\)/\1/
98f7cc78ecSespie  tb
99f7cc78ecSespie}
100f7cc78ecSespied
101