This file is indexed.

/usr/sbin/foomatic-extract-text is in foomatic-db-engine 4.0.12-2+b1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/usr/bin/perl -w   # -*- perl -*-

use Foomatic::Defaults;
use Foomatic::DB;
use strict;

sub write_po{
    my ($out, $messages) = @_;
    foreach (sort(keys %$messages)) {
	if ($_ eq '') {
	    next;
	}
	my $translation = $messages->{$_};
	print $out "msgid \"$_\"\nmsgstr \"$translation\"\n\n";
    }
}

sub write_message_files {
    my ($messages) = @_;

    foreach (keys %$messages) {
	print "LANGUAGE: $_\n";
	open my $out, ">:encoding(utf-8)", "$_.po" or die;
	write_po($out, $messages->{$_});
    }
}

sub extract_ppd_old{
    my $file = $_[0];
    my %messages;


    if ($file =~ /ppd\.gz$/) {
	open(FILE, "zcat $file |") or die "Can't open file: $file";
    } else {
	open(FILE, $file);
    } 

    while (<FILE>){
	if ( /\*(\w+) (\w+)\/([^:]+): \"([^\"]*)\"/ ) {
	    print $_, "'$1' '$2' '$3' '$4'\n\n"
	}
	#print
    }
    close FILE;
}


sub extract_from_db{
    my $messages = $_[0];

    my $db = Foomatic::DB->new();

    my @files = $db->_get_xml_filelist("source/opt");
    foreach my $file (@files){
	if ( $file =~ /[Mm]odel|^18$|^57$/ ) { 
	    next; 
	}
	my $xml = $db->_get_object_xml("source/opt/$file");
	while ($xml =~ /\<[^\<\/]*longname\>.*?\<en\>(.*?)\<\/en\>/sg) {
	    my $message = Foomatic::DB::unhtmlify($1); # xml unquoting
	    $messages->{$message} = '';
	}
    }
}

sub extract_ppd{
    my ($db, $messages) = @_;
    my $args = $db->{"dat"}{"args_byname"};

    for my $option (keys %$args){
	$messages->{$args->{$option}{"comment"}} = "";
	#foreach (keys %{$args->{$option}}) {
	#    print $_, "\n";
	#}
	if ($args->{$option}{"type"} eq "bool"){
	    $messages->{$args->{$option}{"comment_true"}} = '';
	    $messages->{$args->{$option}{"comment_false"}} = '';
	} elsif ($args->{$option}{"type"} eq "enum") {
	    for my $val (@{$args->{$option}{"vals"}}){
		$messages->{$val->{"comment"}} = '';
	    }
	}
    }
    return;
    # old code:
    $a = $db->{"dat"}{"args_byname"}{"MediaType"}{"vals"}[0];
    print "$a\n\n";
    if (0){
    	foreach my $val (@$a){
    	    print "$val\n";
    	}
    	return;
    }
    foreach my $name (keys %$a) {
	print "$name:\n";
	print $a->{$name}, "\n\n";
	if ($name != "compiled-at"){
	    foreach (keys %{$db->{"dat"}{$name}}) {
		print $_, "\n";
	    }
	    print "\n";
	}
    }
}

sub get_translated_messages{
    my ($ppd_en, $ppd_lang, $translation) = @_;

    my $args_en = $ppd_en->{"dat"}{"args_byname"};
    my $args_lang = $ppd_lang->{"dat"}{"args_byname"};

    for my $option (keys %$args_en){
	$translation->{$args_en->{$option}{"comment"}} = 
	    $args_lang->{$option}{"comment"};

	if ($args_en->{$option}{"type"} eq "bool"){
	    $translation->{$args_en->{$option}{"comment_true"}} = 
		$args_lang->{$option}{"comment_true"}; 
	    $translation->{$args_en->{$option}{"comment_false"}} =  
		$args_lang->{$option}{"comment_false"};
	} elsif ($args_en->{$option}{"type"} eq "enum") {
	    for my $val (@{$args_en->{$option}{"vals"}}){
		my $value = $val->{"value"};
		for my $val_lang (@{$args_lang->{$option}{"vals"}}){
		    if ($val_lang->{"value"} eq $value) {
			$translation->{$val->{"comment"}} = 
			    $val_lang->{"comment"};
		    };
		}
	    }
	}
    }
}

sub extract_ppds{
    my ($path, $messages) = @_;
    my $ppds = { };
    my %language_names = ('English' => 'en',
			  'French' => 'fr',
			  'German' => 'de',
			  'Italian' => 'it',
			  'Japanese' => 'jp',
			  'Portugse' => 'pt',
			  'Portuguese' => 'pt',
			  'Spanish' => 'es');

    # read ppds
    open(PPDS, "find $path -name \*.ppd\*|");
    while (<PPDS>){
	print substr($_, 0, -1), "\n";
	my $db = Foomatic::DB->new();
	$db->getdatfromppd(substr($_, 0, -1));
	my $makemodel = $db->{'dat'}{'makemodel'};
	$ppds->{$makemodel} = [] unless exists $ppds->{$makemodel};
	push @{$ppds->{$makemodel}}, $db;
    }
    foreach my $makemodel (keys %$ppds) {
	my $en_ppd;
	foreach my $ppd (@{$ppds->{$makemodel}}) {
	    if ($ppd->{'dat'}{'language'} eq 'English') {
		$en_ppd = $ppd;
		last;
	    }
	}
	foreach my $ppd (@{$ppds->{$makemodel}}) {
	    my $lang = $ppd->{'dat'}{'language'};
	    if (exists $language_names{$lang}) {
		$lang = $language_names{$lang};
	    }
	    $messages->{$lang} = {} unless exists $messages->{$lang};
	    if ($lang ne 'en') {
		get_translated_messages($en_ppd, $ppd, $messages->{$lang});
	    } else {
		extract_ppd($ppd, $messages->{$lang});
	    }
	}
    }
}

sub main{
    my $messages = { };
    $messages->{'en'} = { }; 
    extract_from_db($messages->{'en'});
    extract_ppds("$libdir/db/source/PPD/", $messages);
    write_message_files($messages);
}

main();