head     1.1;
branch   1.1.1;
access   ;
symbols  gfxboot25:1.1.1.1 morphix:1.1.1;
locks    ; strict;
comment  @# @;


1.1
date     2005.10.17.17.11.57;  author tcheun;  state Exp;
branches 1.1.1.1;
next     ;

1.1.1.1
date     2005.10.17.17.11.57;  author tcheun;  state Exp;
branches ;
next     ;


desc
@@



1.1
log
@Initial revision
@
text
@#! /usr/bin/perl

# convert *.po files to *.txt files suitable for linuxrc
# usage: po2h file.po >file.h
# Note: en.po ist treated specially!

sub read_texts;
sub join_msg;

for $lang (@@ARGV) {
  $lang = 'en' if $lang eq 'linuxrc.pot';
  $lang =~ s/\.po$//;
  read_texts $lang;
}


sub read_texts
{
  local $_;

  my ($lang, @@f, $txt, $context, $t, $p, $ids, $file);

  $lang = shift;

  $file = "$lang.po";
  $file = 'linuxrc.pot' if $lang eq 'en';

  if($lang eq 'en') {
    $ids = 1;
  }

  open F, $file;
  @@f = (<F>);
  close F;

  $_ = $lang;
  s/.*\///;
  print "/*\n * This file is generated automatically. Editing it is pointless.\n */\n\n";
  print "static text_t txt_${_}_atm [] =\n{\n";

  for (@@f) {
    if(/^\s*#\.\s*(TXT_\S+)/) {
      if($txt) {
        @@msgstr = @@msgid if $ids || join_msg(\@@msgstr) eq "";
        printf "{ %-25s", "$txt,";
        $p = pop @@msgstr;
        for $t (@@msgstr) {
          printf "%s\n%-27s", $t, "";
        }
        printf "%-56s},\n", $p;
      }

      $txt = $1;

      push @@txts, $txt;

      undef @@msgid;
      undef @@msgstr;
      undef $context;
      next;
    }

    next if /^\s*#.*|^\s*$/;
    
    if(/^\s*msgid\s*(\".*\")\s*$/) {
      push @@msgid, $1 unless $1 eq '""';
      $context = 1;
      next;
    }

    if(/^\s*msgstr\s*(\".*\")\s*$/) {
      push @@msgstr, $1 unless $1 eq '""';
      $context = 2;
      next;
    }

    if(/^\s*(\".*\")\s*$/) {
      if($context == 1) {
        push @@msgid, $1;
      }
      elsif($context == 2) {
        push @@msgstr, $1;
      }
      else {
        die "format oops in ${lang}.po: $_"
      }
    }
  }

  if($txt) {
    printf "{ %-25s", "$txt,";
    @@msgstr = @@msgid if $ids || join_msg(\@@msgstr) eq "";
    $p = pop @@msgstr;
    for $t (@@msgstr) {
      printf "%s\n%-27s", $t, "";
    }
    printf "%-56s}\n", $p;
  }

  print "};\n";

  if($ids) {
    open W, ">text_textids.h";
    print W "/*\n * This file is generated automatically. Editing it is pointless.\n */\n\n";
    print W "enum textid_t {\n";
    $p = pop @@txts;
    for (@@txts) { print W "  $_,\n" }
    print W "  $p\n};\n";
    close W;
  }
  else {
    open F, "text_textids.h";
    for (<F>) {
      if(/\s+(TXT_.+?)(\s|,)/) {
        $txt_ref{$1} = undef;
      }
    }
    close F;
    for (@@txts) {
      $txt_list{$_}++;
      $txt_multi{$_} = 1 if $txt_list{$_} > 1;
    }
    for (@@txts) {
      $txt_unknown{$_} = 1 unless exists $txt_ref{$_};
    }
    for (keys %txt_ref) {
      $txt_miss{$_} = 1 unless exists $txt_list{$_};
    }

    if(defined(%txt_miss) || defined(%txt_unknown) || defined(%txt_multi)) {
      print STDERR "$lang:\n";
      for (sort keys %txt_miss) {
        print STDERR "  missing: $_\n"
      }
      for (sort keys %txt_unknown) {
        print STDERR "  unknown: $_\n"
      }
      for (sort keys %txt_multi) {
        print STDERR "  multi: $_\n"
      }
    }
  }

}


sub join_msg
{
  local $_;
  my ($s, $msg, $m);

  $msg = shift;

  for $s (@@{$msg}) {
    $_ = $s;
    s/^\"(.*)\"$/$1/;
    $m .= $_;
  }

  return $m;
}
@


1.1.1.1
log
@morhhix
@
text
@@
