#!/usr/bin/perl
use strict;

my @files = @ARGV;

my $strpat = '\\"((?:[^"]|\\\\\\")*)\\"';

foreach my $file ( @files ) {
  # read the file in
  open(SRC,$file) || die "Could not open the file '$file' !\n";
  local $_;
  my $cnt = 1;
  chomp(my @lines = <SRC>);
  close(SRC);

  my @strlines = grep { $_->[1] =~ /${strpat}/o } map { [$cnt++,$_,($_=~/^(.*)(\/\/.*)?$/o)[0]] } @lines;
  # filter the include lines

  my @coll = grep { $_->[7] =~ /${strpat}/ }
             grep { my ($a) = $_->[7]=~m/${strpat}/; $a!~/\.xpm$/ }                  # Obvious pixmap names
             grep { my $a=$_->[6]; $a=~s/(setA|a)ttribute\s*\(\s*${strpat}//g; $_->[7]=$a }   # Meta-object access
             grep { my $a=$_->[5]; $a=~s/\"\"//g; $_->[6]=$a }   # Empty strings
             grep { my $a=$_->[4]; $a=~s/kd(Warning|Debug)\(\)\s*\<\<[^;]*;//g; $_->[5]=$a }   # Debugging msgs
             grep { my $a=$_->[3]; $a=~s/loadIcon\s*\(\s*${strpat}//g; $_->[4]=$a }  # Load icon statements
             grep { my $a=$_->[2]; $a=~s/i18n\s*\(\s*${strpat}\s*\)//g; $_->[3]=$a } # remove translated strings
             grep { $_->[2] !~ /^\s*\#(include|error)\b/ }       # remove includes
             @strlines;

  # Printout the result
  my @out = map { "${file}:$_->[0]: $_->[1]" }  @coll;
  print join("\n",@out),"\n" if @out;
}

