home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1999 May / pcp151c.iso / misc / src / install / simplemot < prev    next >
Encoding:
Text File  |  1998-10-12  |  1.1 KB  |  58 lines

  1. #!/usr/bin/perl
  2.  
  3. $inone = 0;
  4. $intran = 0;
  5. $total = 0;
  6. while (<>) {
  7.     if (!$inone && /^msgid/) {
  8.     chop;
  9.     $str = substr($_, 7, length($_) - 8);
  10.     $inone = 1;
  11.     } elsif ($inone && /^"/) {
  12.     chop;
  13.     $str .= substr($_, 1, length($_) - 2);
  14.     } elsif ($inone) {
  15.     $inone = 0;
  16.  
  17.     $str =~ s/\\n/\n/g;
  18.  
  19.     # the string is complete -- calculate a hash
  20.     $sum = 0;
  21.     $xor = 0;
  22.     for ($i = 0; $i < length($str); $i++) {
  23.         $char = ord(substr($str, $i, 1));
  24.         $sum += $char;
  25.         $xor ^= $char;
  26.     }
  27.  
  28.     $total = ($sum << 16) | (($xor & 0xFF) << 8) | (length($str) & 0xFF);
  29.     }
  30.  
  31.     if (!$intran && /^msgstr/) {
  32.     chop;
  33.     $tran = substr($_, 8, length($_) - 9);
  34.     $intran = 1;
  35.     } elsif ($intran && /^"/) {
  36.     chop;
  37.     $tran .= substr($_, 1, length($_) - 2);
  38.     } elsif ($intran) {
  39.     $intran = 0;
  40.  
  41.     $tran =~ s/\\n/\n/g;
  42.     $tran =~ s/\\t/\t/g;
  43.     $tran =~ s/\\"/"/g;
  44.  
  45.     if (!$total && $str) {
  46.         print STDERR "Missing string for $tran";
  47.         exit 1
  48.     } elsif ($str && $tran) {
  49.         print pack("Nn", $total, length($tran));
  50.         print $tran;
  51.  
  52.         #if ($tran < 60) {
  53.         #printf STDERR ("0x%x %s\n", $total, $tran);
  54.         #}
  55.     }
  56.     }
  57. }
  58.