File: commentmerge

package info (click to toggle)
kde-i18n 4%3A2.2.2-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 341,220 kB
  • ctags: 327
  • sloc: sh: 10,878; perl: 2,910; cpp: 1,319; makefile: 1,016; python: 258
file content (134 lines) | stat: -rwxr-xr-x 2,229 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#! /opt/local/bin/perl --					# -*-Perl-*-
eval "exec /opt/local/bin/perl -S $0 $*"
    if $running_under_some_shell;

# Combine a new .po file and an old translated .po file to a new translation.
# Copyright (C) 1995 Free Software Foundation, Inc.
# Ulrich Drepper <drepper@gnu.ai.mit.edu>, May 1995.
#
# I have almost rewritten this file to only care about comments, not about
# entries.

# We take exactly two arguments.
#
if ($#ARGV != 1)
{
    die "Try `tupdate --help' for more information.\n";
}

unless (open(OLD, "$ARGV[1]"))
{
    die "Cannot open old translated .po file '$ARGV[1]'\n";
}

$last_comment = "";

while (<OLD>)
{
  $last_comment = "";

  if (/^#/) {
      while ( $_ !~ m/^\s*msgid\s*\"/) {
	$last_comment .= $_;
	$_ = <OLD>;
      }
    }

  if (/^\s*msgid/) {
    $_ =~ s/^\s*msgid\s*\"//;
    $_ =~ s/\"\n$//;

    $msgid = $_;
	
    $_ = <OLD>;
    
    while (/^\s*\"/)
      {
	$_ =~ s/^\s*\"//;
	$_ =~ s/\"\n$//;

	$msgid .= $_;
	$_ = <OLD>;
      }
  } else {
    $msgid = "";
  }
  
  $comment{$msgid} = $last_comment if ($last_comment && $msgid);
}

close (OLD);

unless (open (NEW, "$ARGV[0]"))
{
    die "Cannot open new .po file '$ARGV[0]'\n";
}

my $first = 1;

while (<NEW>)
{
  $last_comment = "";

  while (/^#\~/ || /^\s*$/) {
	 print STDOUT "$_";
	 $_ = <NEW>;
	 last if (! $_);
       }

  if (/^#/) {

      while ( $_ !~ m/^\s*msgid\s*\"/) {
	if ($_ =~ /^#,\s*fuzzy/ || $_ =~ /^#\s*,\s*.*-format/ || $first == 1) {
	    $last_comment .= $_;
	  }

	$_ = <NEW>;
	last if (! $_);
	last if (/^#\~/);
      }
    }
  if (/^\s*msgid/) {
    $_ =~ s/^\s*msgid\s*\"//;
    $_ =~ s/\"\n$//;
    $msgid = $_;
    
    $_ = <NEW>;
    
    while (/^\s*\"/)
      {
	$_ =~ s/^\s*\"//;
	$_ =~ s/\"\n$//;
	$msgid .= $_;
	$_ = <NEW>;
      }

    if ($last_comment =~ /.*-format/ && $comment{$msgid} =~ /.*-format/) {
       $comment{$msgid} =~ s/# *, .*-format//;
       $comment{$msgid} =~ s/\n\n/\n/;
    }
      
    if ($first == 0) {
      print STDOUT $comment{$msgid};
    }
    
    print STDOUT $last_comment;

    print STDOUT "msgid \"$msgid\"\n";
    
  } else {
    print STDOUT $last_comment;
    $msgid = "";
  }
      
  $first = 0;


      print STDOUT $_;
      
}

  


exit 0;