This file is indexed.

/usr/bin/odffilesearch is in libopenoffice-oodoc-perl 2.125-3.

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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
#!/usr/bin/perl

eval 'exec /usr/bin/perl  -S $0 ${1+"$@"}'
    if 0; # not running under some shell
#-----------------------------------------------------------------------------
#	$Id: odffilesearch 0.007 2008-05-04$
#-----------------------------------------------------------------------------

=head1	NAME

	odffilesearch - File selection by keywords

=head1	SYNOPSIS

	odffilesearch -R "D:\Documents\*.odt" openoffice desktop XML
	
	produces the list of the ODF Text documents present in the given
	directory and its subdirectories, and containing the words
	"openoffice", "desktop" AND "XML"
	
	odffilesearch -command "rm -f %f" "*.ods *.odt" lost dismiss cancel

	executes the "rm -f filename" (i.e. deletes the file in a Unix system)
	for each ODT or ODS file present in the current directory
	and containing the words "lost", "dismiss" AND "cancel"

=head1	USAGE

	odffilesearch [-options] <file filter> <keyword list>

=head1	DESCRIPTION

	This utility allows the user to retrieve a list of files matching
	a given set of keywords or regular expressions. A file is selected
	when it contains, in its text and/or in its metadata (title, subject,
	keywords or description), all the given search strings.

	The selected files are echoed to the standard output (one file per
	line), so this utility can be used as a filter piping its results
	to another program. Alternatively, a given shell command can be
	launched by the script each time a file matches, allowing on-the-fly
	processing of the selected documents.

	The files filter may content one or more space-separated paths.
	Each path may content jokers. So it's possible to explore several
	directories and/or several filename patterns. 

	All the arguments after the file filter are processed as search
	criteria.

=head1	OPTIONS

	-R -recursive
		include the subdirectories of each given search directory
	-verbose -trace -debug
		echo some processing comments
	-warnings
		activate the warning messages of the OpenOffice::OODoc API
	-log <file>
		like -verbose, but then messages are sent to the given file
		and don't pollute the standard output
	-result <file>
	-output <file>
		send the list of matching files to the given file and not
		to the standard output
	-criteria <file>
		get search criteria from a file (one per line); the loaded
		search keywords may be combined with additional criteria
		passed with the command line, if any.
	-command <command> -exec <command>
		execute a shell command for each matching file ; if the
		command string contains "%f", this substring is replaced
		with the name of the selected file ; if this option is
		provided, the selection list is not echoed to the standard
		output ; if -verbose is on, the value returned by the
		command is echoed
	-encoding <encoding>
		selects the user's character set ; this option is mandatory
		if one or more search criteria contain characters not
		belonging to the default character set

=cut

#=============================================================================

use	OpenOffice::OODoc	2.101;
use	Getopt::Long;

our	$VERSION		= 0.007;

#=============================================================================


my	$recursive	= undef;
my	$verbose	= undef;
my	$warnings	= undef;
my	$command	= undef;
my	$result		= undef;
my	$log		= undef;
my	$list		= undef;
my	$character_set	= undef;
my	$RESULT		= *STDOUT;
my	$LOG		= *STDOUT;

GetOptions
	(
	'R|recursive'			=> \$recursive,
	'verbose|trace|debug'		=> \$verbose,
	'warnings'			=> \$warnings,
	'log=s'				=> \$log,
	'result|output=s'		=> \$result,
	'command|exec=s'		=> \$command,
	'criteria=s'			=> \$list,
	'encoding=s'			=> \$character_set
	);

#=============================================================================

my	@keywords	= ();
my	$count		= 0;

#=============================================================================

sub	horodate
	{
	my @d = localtime();
	return sprintf
		(
		"[%02d/%02d/%04d %02d:%02d:%02d] ",
		$d[3], $d[4] + 1, $d[5] + 1900, $d[2], $d[1], $d[0]
		);
	}

sub	message
	{
	my $text = shift;
	return unless ($verbose);
	print $LOG horodate() . "$text\n";
	print $LOG "\t$_\n" for @_;
	}

#-----------------------------------------------------------------------------

sub	matching_file
	{
	my $file	= shift;
	my @words	= @_;
	my $n		= scalar @words;
	my $text	= "";

	my $oof	= ooFile($file);
	unless ($oof)
		{
		message	"$file doesn't look like an ODF file";
		return undef;
		}
	my $meta	= odfMeta(container => $oof) or message
				"$file doesn't contain metadata";
	if ($meta)
		{
		my $title = $meta->title;
		if ($title)
			{
			message "Title: \"$title\"";
			$text .= $title;
			}
		else
			{
			message "Title: <UNTITLED>";
			}
		$text .= ($meta->keywords || "");
		$text .= ($meta->subject || "");
		$text .= ($meta->description || "");

		$meta->dispose;
		}
	my $content	= odfText(container => $oof) or message
				"$file doesn't have a regular content";
	if ($content)
		{
		$text .= ($content->getTextContent || "");

		$content->dispose;
		}

	return undef unless $text;
	while (@words)
		{
		my $word = shift @words or next;
		return undef unless $text =~ /$word/i;
		}
	return 1;
	}

#-----------------------------------------------------------------------------

sub	file_selection
	{
	my @list = @_;
	my $number = scalar @list;

	message "$number file(s) in the search list";
	FILE: foreach my $file (@list)
		{
		unless (-r $file)
			{
			message "$file : unreadable";
			next FILE;
			}
		if (-l $file)
			{
			message "$file : symbolic link, ignored";
			next FILE;
			}
		if ((-d $file) && $recursive)
			{
			message "Searching in $file";
			file_selection(glob("$file/*"));
			next FILE;
			}
		unless (-s $file)
			{
			message "$file : empty";
			next FILE;
			}
		unless (-f $file)
			{
			message "$file is not a regular file";
			next FILE;
			}
		message "Processing $file";
		if (matching_file($file, @keywords))
			{
			message "OK! $file matches all the criteria";
			if ($command)	
				{
				my $cmd = $command;
				$cmd =~ s/\%f/$file/g;
				message "Executing command: $cmd";
				my $r = system $cmd;
				message "Command result is $r";
				}
			else	
				{
				print $RESULT "$file\n";
				}
			$count++;
			}
		else
			{
			message "file $file doesn't match";
			}
		}
	}

#=============================================================================
# main program

if ($result)
	{
	open RESULT, ">", $result
		or die "output file $result is unwritable\n";
	$RESULT = *RESULT;
	}

if ($log)
	{
	open OUTPUT, ">>", $log
		or die "log file $log is unwritable\n";
	$LOG = *OUTPUT;
	$verbose = 1;
	}

if ($list)
	{
	message "Loading a keyword list from $list";
	my $m;
	open LIST, "<", $list or warn "file $list is unreadable\n";
	while ($m = <LIST>)
		{
		chomp $m;
		push @keywords, $m;
		}
	close LIST;
	}

localEncoding($character_set)	if $character_set;

die "Usage: odffilesearch [-options] <filefilter> [keywords]\n"
		unless $ARGV[0];

message "Starting the search...";

my $filter = shift @ARGV;
push @keywords, @ARGV;
die "Empty keword list.\n" unless @keywords;
message "Keyword list:", @keywords;
unless ($warnings)
	{
	$SIG{'__WARN__'} = sub {};
	}
file_selection(glob($filter));

message "Finished - $count file(s) selected";
exit;

#=============================================================================