This file is indexed.

/usr/bin/leo is in libwww-dict-leo-org-perl 1.36-1.

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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
#!/usr/bin/perl

eval 'exec /usr/bin/perl  -S $0 ${1+"$@"}'
    if 0; # not running under some shell
#
# This little handy script grabs the german/english translation for a
# given term from http://dict.leo.org. Thanks the LEO folks for their
# good job!
#
# Usage is quite simple, the script requires just one parameter,
# the term to be translated. It will then return the results in
# an unformatted form.
#
# $Id: leo,v 1.33 2008/04/22 22:23:39 scip Exp $
#
# Copyleft (l) 2000-2013 by Thomas Linden <tom@daemon.de>. leo may be
# used and distributed under the terms of the GNU General Public License.
# All other brand and product names are trademarks, registered trademarks
# or service marks of their respective holders.

use lib qw(blib/lib);
#use Org;

use utf8;

use strict;
use Getopt::Long;
use DB_File;
use POSIX qw(isatty);
use WWW::Dict::Leo::Org;
use Data::Dumper;



#
# internal settings
#
my $highlight = 1;
my $default_c = "\033[0m";    # reset default terminal color
my $bold_c    = "\033[0;34m"; # blue color
my $copy_c    = "\033[0;35m"; # copyright message color (green)

my $version   = "1.36";
my $config    = $ENV{HOME} . "/.leo";
my $cache     = $ENV{HOME} . "/.leo-CACHE.db";

my $debugging = 0;

#defaults for config
my %conf      = (
		 use_cache => "no",
		 use_color => "yes",
		 use_latin => "yes"
		 );

my %validopts = qw(use_cache 0 use_color 0 user_agent 0 use_latin 0);
my %line      = %validopts;
my %CACHE     = ();
my $site      = "";
my $proxy_user = "";
my $proxy_pass = "";

sub debug;

my($o_s, $o_m, $o_c, $o_l, $o_v, $o_h, $o_n, $o_f, $o_d, $o_u, $o_p);

isatty(1) && eval q{ use open OUT => ':locale'};

#
# commandline options
#
Getopt::Long::Configure( qw(no_ignore_case));
if (! GetOptions (
		  "spelltolerance|s=s" => \$o_s,
		  "morphology|m=s"     => \$o_m,
		  "chartolerance|c=s"  => \$o_c,
		  "language|l=s"       => \$o_l,
		  "force|f"            => \$o_f,
		  "version|v"          => \$o_v,
		  "help|h"             => \$o_h,
		  "debug|d"            => \$o_d,
		  "noescapechars|n"    => \$o_n,
		  "user|u=s"           => \$o_u,
		  "passwd|p=s"         => \$o_p
                 )    ) {
  &usage;
}

if ($o_h) {
  &usage;
}
if ($o_v) {
  print STDERR "leo version $version\n";
  exit;
}


#
# search term
#
my $string = shift;
if (!$string) {
  $string = <STDIN>;
  chomp $string;
}

if (eval { require I18N::Langinfo; require Encode; 1 }) {
  my $codeset = I18N::Langinfo::langinfo(I18N::Langinfo::CODESET());
  if ($codeset) {
    for ($string) {
      $_ = Encode::decode($codeset, $_);
    }
  }
}

#
# open the config, if any
#
if (-e $config) {
  open C, "<$config" or die "Could not open config $config: $!\n";
  local $_;
  while (<C>) {
    chomp;
    next if(/^\s*#/); # ignore comments
    next if(/^\s*$/); # ignore empty lines
    s/^\s*//;         # remove leading whitespace
    s/\s*$//;         # remove trailing whitespace
    s/\s*#.*$//;      # remove trailing comment
    my($opt, $val) = split /\s*=\s*/;
    $conf{$opt} = $val;
    $line{$opt} = $.;
  }
  close C;
}


#
# validate the config
#
foreach my $opt (keys %conf) {
  if (!exists $validopts{$opt}) {
    print "<$opt>\n";
    print STDERR "Error in config $config line: " . $line{$opt} . ". Unsupported option \"$opt\"!\n";
    exit;
  }
}

#
# feed config values into program
#
if ($conf{use_color} eq "no") {
  $highlight = 0;
}
elsif ($conf{use_color} eq "yes") {
  $highlight = 1;
}

#
# open the cache, if wanted
#
if ($conf{use_cache} eq "yes") {
  dbmopen(%CACHE, $cache, 0600) or $conf{use_cache} = "no";
}

my %PARAM;

if ($o_l) {
  $PARAM{"-Language"} = $o_l;
}
if(exists $ENV{http_proxy}) {
  $PARAM{"-Proxy"} = $ENV{http_proxy};
}
if ($o_u) {
  $PARAM{"-ProxyUser"} = $o_u;
}
if ($o_p) {
  $PARAM{"-ProxyPass"} = $o_p;
}

if($o_n) {
  $highlight = 0;
}
else {
  # highlighting turned on, check if possible
  if (! isatty(1)) {
    $highlight = 0;
  }
}
if ($o_d) {
  # enable
  $PARAM{"-Debug"} = 1;
}

if($o_s) {
  $PARAM{"-SpellTolerance"} = $o_s;
}
if($o_m) {
  $PARAM{"-Morphology"} = $o_m;
}
if($o_c) {
  $PARAM{"-CharTolerance"} = $o_c;
}

if (exists $ENV{http_proxy} and $o_u) {
    # authenticate
    if (! $o_p) {
      # ask for it
      my $proxy_pass;
      local $| = 1;
      print "password: ";
      eval {
	local($|) = 1;
	local(*TTY);
	open(TTY,"/dev/tty") or die "No /dev/tty!";
	system ("stty -echo </dev/tty") and die "stty failed!";
	chomp($proxy_pass = <TTY>);
	print STDERR "\r\n";
	system ("stty echo </dev/tty") and die "stty failed!";
	close(TTY);
      };
      if ($@) {
	$proxy_pass = <>;
      }
      chomp $proxy_pass;
      $PARAM{"-ProxyPass"} = $proxy_pass;
    }
}

my (@match, $lines, $maxsize);
my $cache_key = join ("", sort keys %PARAM) . $string;
if ($o_f && $conf{use_cache} eq "yes") {
  delete $CACHE{$cache_key};
}

if(exists $CACHE{$cache_key} && $conf{use_cache} eq "yes") {
  # deliver from cache
  my $code = $CACHE{$cache_key};
  my ($VAR1, $VAR2, $VAR3);
  eval $code;
  @match = @{$VAR1};
  $lines = $VAR2;
  $maxsize = $VAR3;
}
else {
  my $leo = new WWW::Dict::Leo::Org(%PARAM) or
     die "Could not initialize WWW::Dict::Leo::Org: $!\n";
  @match   = $leo->translate($string);
  $lines   = $leo->lines();
  $maxsize = $leo->maxsize();

  if($conf{use_cache} eq "yes") {
    $CACHE{$cache_key} = Dumper(\@match, $lines, $maxsize);
  }
}

if ($conf{use_cache} eq "yes") {
  dbmclose(%CACHE);
}

if(! @match) {
  print STDERR "Search for \"$string\" returned no results.\n";
  exit 1;
}

$maxsize += 5;
print "Found $lines matches for '$string' on dict.leo.org:\n";

#
# print it out in a formated manner, keep the order of dict.leo.org
#
foreach my $section (@match) {
  utf8::decode($section->{title}) if ($conf{use_latin});

  if ($highlight) {
    print "\n${bold_c}$section->{title}${default_c}\n";
  }
  else {
    print "\n$section->{title}\n";
  }

  foreach my $entry (@{$section->{data}}) {
    $entry->{left} =~ s/^(.*)$/$1 . " " x ($maxsize - length($1))/e;
    if ($conf{use_latin}) {
      utf8::decode($entry->{left});
      utf8::decode($entry->{right});
    }
    if ($highlight) {
      $entry->{left}  =~ s/(\Q$string\E)/$bold_c . $1 . $default_c/ei;
      $entry->{right} =~ s/(\Q$string\E)/$bold_c . $1 . $default_c/ei;
    }
    print " $entry->{left}$entry->{right}\n";
  }
}


print "$copy_c" if $highlight;
print "\n     Fetched by leo $version via http://dict.leo.org/";
print "\n     Copyright (C) LEO  Dictionary Team 1995-2013";
print "\n     [leo] GPL Copyleft   Thomas Linden 2000-2013\n\n";
print "$default_c" if $highlight;



sub parserror {
  my $msg = shift;
  print STDERR "Parse error $msg\n";
  print STDERR "Could not recognize site html of target site\n";
  print STDERR "dict.leo.org. This might be a bug or the site\n";
  print STDERR "might have changed. Please repeat the last step\n";
  print STDERR "with debugging enabled (-d) and send the output\n";
  print STDERR "to the author. Thanks.\n";
  exit 1;
}

sub usage {
  my $msg = shift;
  my $me        = $0;
  $me           =~ s(^.*/)();

  print "$msg\n" if($msg);

  print qq(Usage:   $me [-slmcfuphdv] [<term>]
Translate a term from german to english or vice versa.

  -s, --spelltolerance=on|off                   allow spelling errors
  -m, --morphology=none|forcedAll               provide morphology information
  -c, --chartolerance=fuzzy|exact               allow umlaut alternatives
  -l, --language=en|fr|de2(en|fr)|(en|fr)2de    translation direction
  -n, --noescapechars                           dont use escapes for highlighting
  -f, --force                                   don't use the query cache
  -u, --user=username                           user for proxy authentication
  -p, --passwd=password                         cleartext passphrase for proxy authentication
  -h, --help                                    display this help and exit
  -d, --debug                                   enable debugging output
  -v, --version                                 output version information and exit

<term> is the string you are asking to be translated. It will
be requested from STDIN if not specified on the commandline.

Report bugs to <tom\@daemon.de>.
);

  exit 1;
}



1;



=head1 NAME

leo - commandline interface to http://dict.leo.org/.

=head1 SYNOPSIS

 leo [-slmcfuphdv] [<term>]

=head1 DESCRIPTION

B<leo> is a commandline interface to the german/english/french
dictionary on http://dict.leo.org/. It supports almost
all features which the website supports, plus more.

Results will be printed to the terminal. By default the
searched key word will be highlighted (which can be
turned off, see below).

To get faster results, B<leo> is able to cache queries
if you repeatedly use the same query.

B<leo> acts as a standard webbrowser as your mozilla or
what so ever does, it connects to the website, exectues
the query, parses the HTML result and finally prints
it somewhat nicely formatted to the terminal.

As of this writing B<leo> acts as:

 Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9

=head1 OPTIONS

=over

=item I<-s --spelltolerance>

Allow spelling errors.

Possible values: B<standard>, B<on> or B<off>.

Default setting: B<standard>.

=item I<-m --morphology>

Provide morphology information.

Possible values: B<standard>, B<none> or B<forcedAll>.

Default setting: B<standard>.

=item I<-c --chartolerance>

Allow umlaut alternatives.

Possible values: B<fuzzy>, B<exact> or B<relaxed>.

Default: B<relaxed>.

=item I<-l --language>

Translation direction.

Possible values: B<en>, B<fr>, B<de2en>, B<en2de>, B<de2fr> or B<fr2de>.

B<en> and B<fr> do select the translation direction automatically.

Default: B<en>.

=item I<-n --noescapechars>

Don't use escapes for highlighting.

Default: do highlighting.

Controllable via config file too. See below.

No highlighting will be used if STDOUT is not connected
to a terminal.

=item I<-f --force>

Don't use the query cache.

Default: use the cache.

This option has no effect if B<use_cache> is turned
off in the config file.

=item I<-u --user>

Specify the http proxy user to use if your proxy requires
authentication. Read the 'PROXY' section for more details.

=item I<-p --passwd>

Specify the cleartext password to use with http proxy
authentication.

This is not recommended and just implemented for completeness.

=item I<-h --help>

Display this help and exit.

=item I<-v --version>

Display version information and exit.

=item I<-d --debug>

Enable debugging output (a lot of it, beware!), which will be printed
to STDERR. If you find a bug you must supply the debugging output
along with your bugreport.

=back

B<term> is the key word which you want to translate.
If the term contains white spaces quote it using double
quotes.

If the B<term> parameter is not specified, B<leo> will read
it from STDIN.

=head1 CONFIG

B<leo> reads a config file B<.leo> in your home directory
if it exists. The following variables are supported:

=over

=item I<use_latin>

Turns on conversion of UTF8 characters to their latin*
encoding.

Default setting (if not given): B<yes>.

=item I<use_cache>

Controls the use of the cache (see later).

Possible values: B<yes> or B<no>.

Default setting(if not given): B<yes>.

If the commandline option B<-f> or B<--force> has been
set then the cache will not be used for the query and
if for this query exists an entry in the cache it will
be removed from it.

=item I<use_color>

Controls the use of escape sequences in the terminal
output to highlight the key-waord in the result.

Possible values: B<yes> or B<no>.

Default setting(if not given): B<yes>.

You can set this option via commandline too: B<-n>
or B<--noescapechars>.

The config option has higher precedence.

=item I<user_agent>

You may modify the user agent as B<leo> identifies itself
on the target site. The default is:

 User-Agent: Mozilla/5.0 (compatible; Konqueror/3.3.1; X11)

=back

=head1 CACHING

B<leo> supports caching of queries for faster results
if you repeatedly use the same query. A query consists
of the given B<term> (the key word or string) plus the
translation option settings.

If you, for example, execute once the following query:

 % leo langnase

and somewhere later:

 % leo -c exact

then B<leo> will treat the latter query as a different
one than the previous one, because I<dict.leo.org>
behaves different when different translation options
are given.


=head1 PROXY

B<leo> can be used with a HTTP proxy service. For this to
work, you only have to set the environment variable
B<http_proxy>. It has the following format:

 PROTO://[USER:PASSWD@]SERVER[:PORT]

The only supported protocol is B<http>. If your proxy works without
authentication, you can omit the B<user:passwd> part. If no
port is specified, B<80> will be used.

Here is an example (for bash):

 export http_proxy=http://172.16.120.120:3128

and an example with authentication credentials:

 export http_proxy=http://max:34dwe2@172.16.120.120:3128

As security is always important, I have to warn you, that
other users on the same machine can read your environment
using the 'ps -e ..' command, so this is not recommended.

The most secure way for proxy authentication is just to
specify the server+port with B<http_proxy> but no credentials,
and instead use the B<-u> commandline parameter to specify
a user (do not use B<-p> to specify the password, this will
also be readyble in process listing). In this case, B<leo>
will ask you interactively for the password. It will try its
best to hide it from being displayed when you type it (as
most such routines in other tools do it as well), it this
fails (e.g. because you do not have the 'stty' tool installed),
the password will be read from STDIN.

=head1 FILES

 ~/.leo             the config file for leo. Not required.
 ~/.leo-CACHE.db*   the cache file.


=head1 AUTHOR

Thomas Linden <tom@daemon.de>.


=head1 BUGS

B<leo> depends on http://dict.leo.org/. It may break B<leo>
if they change something on the site. Therefore be so kind and
inform me if you encounter some weird behavior of B<leo>.
In most cases it is not a bug of B<leo> itself, it is a
website change on http://dict.leo.org/.

In such a case repeat the failed query and use the commandline
flag B<-d> (which enables debugging) and send the full output
to me, thanks.


=head1 COPYRIGHT

B<leo> copyleft 2000-2013 Thomas Linden. All rights reserved.

http://dict.leo.org/ copyright (c) 1995-2013 LEO Dictionary Team.


The search results returned by B<leo> are based on the work
of the people at LEO.org. Thanks for the great work.

Some time ago they told me that they are disagreed with B<leo>,
or in other words: from their point of view B<leo> seems to
break copyright law in some or another way.

I thought a long time about this, but I must deny this. B<leo>
acts as a simple web client, just like mozilla, IE or even
lynx are doing. They are providing the service to the public
so I use my favorite web browser to make use of it. In fact
my favorite browser to view dict.leo.org is B<leo>. There is
nothing wrong with that. IMHO.

If you disagree or are asked by the LEO team to stop using B<leo>
you may decide this for yourself. I in my case wrote kinda
browser, what is not prohibited. At least not today.

=head1 VERSION

This is the manpage for B<leo> version B<1.36>.

=cut