| 1 | #!/usr/bin/perl |
| 2 | # findshapes.pl. |
| 3 | |
| 4 | use strictscip-perl cpan Acme-EyeDrops 1.62 strict/; |
| 5 | use Getopt::Stdscip-perl cpan Acme-EyeDrops 1.62 Getopt/Std/ (); |
| 6 | use Acme::EyeDropsscip-perl cpan Acme-EyeDrops 1.62 Acme/EyeDrops/ qw(get_eye_shapes |
| 7 | find_eye_shapes |
| 8 | get_eye_string |
| 9 | get_eye_properties |
| 10 | get_eye_keywords); |
| 11 | |
| 12 | sub usagescip-perl cpan Acme-EyeDrops 1.62 main/usage(). |
| 13 | { |
| 14 | print STDERR <<'EOM'; |
| 15 | usage: findshapes [-kvH] [keywords] |
| 16 | Options: |
| 17 | -k List shapes by keyword |
| 18 | -H List keyword histogram |
| 19 | -v Verbose (display shape in addition to shape properties) |
| 20 | Notes: |
| 21 | You cannot specify keywords with -k and -H options. |
| 22 | The -v option does not apply to -k and -H options. |
| 23 | Examples: |
| 24 | findshapes face person perlhacker |
| 25 | Find all shapes containing keywords face AND person AND perlhacker. |
| 26 | findshapes face 'person OR perlhacker' |
| 27 | Find all shapes containing keywords face AND (person OR perlhacker). |
| 28 | findshapes -v face 'person OR perlhacker' |
| 29 | Find all shapes containing keywords face AND (person OR perlhacker). |
| 30 | This time also display the shape contents. |
| 31 | findshapes |
| 32 | List all available shapes and their properties. |
| 33 | findshapes -v |
| 34 | List all available shapes, their properties and contents. |
| 35 | findshapes -k |
| 36 | List all shapes by keyword. |
| 37 | findshapes -H |
| 38 | List keyword histogram. |
| 39 | EOM |
| 40 | exitscip-perl cpan Acme-EyeDrops 1.62 main/exit(). 1; |
| 41 | } |
| 42 | |
| 43 | my %option = (); |
| 44 | Getopt::Std::getoptsscip-perl cpan Acme-EyeDrops 1.62 Getopt/Std/getopts().("hkHv", \%option) or usagescip-perl cpan Acme-EyeDrops 1.62 main/usage().(); |
| 45 | usagescip-perl cpan Acme-EyeDrops 1.62 main/usage().() if $option{h}; |
| 46 | |
| 47 | if ($option{k} || $option{H}) { |
| 48 | usagescip-perl cpan Acme-EyeDrops 1.62 main/usage().() if @ARGVscip-perl cpan Acme-EyeDrops 1.62 main/`@ARGV`.; |
| 49 | my $h = get_eye_keywordsscip-perl cpan Acme-EyeDrops 1.62 Acme/EyeDrops/get_eye_keywords().(); |
| 50 | if ($option{k}) { |
| 51 | for my $k (sortscip-perl cpan Acme-EyeDrops 1.62 main/sort(). keysscip-perl cpan Acme-EyeDrops 1.62 main/keys(). %{$h}) { printscip-perl cpan Acme-EyeDrops 1.62 main/print(). "$k: @{$h->{$k}}\n" } |
| 52 | } |
| 53 | if ($option{H}) { |
| 54 | for my $k (sortscip-perl cpan Acme-EyeDrops 1.62 main/sort(). keysscip-perl cpan Acme-EyeDrops 1.62 main/keys(). %{$h}) { printscip-perl cpan Acme-EyeDrops 1.62 main/print(). "$k: ", scalarscip-perl cpan Acme-EyeDrops 1.62 main/scalar().(@{$h->{$k}}), "\n" } |
| 55 | } |
| 56 | exitscip-perl cpan Acme-EyeDrops 1.62 main/exit().(0); |
| 57 | } |
| 58 | |
| 59 | my @shapes; |
| 60 | if (@ARGVscip-perl cpan Acme-EyeDrops 1.62 main/`@ARGV`.) { |
| 61 | @shapes = find_eye_shapesscip-perl cpan Acme-EyeDrops 1.62 Acme/EyeDrops/find_eye_shapes().(@ARGVscip-perl cpan Acme-EyeDrops 1.62 main/`@ARGV`.); |
| 62 | } else { |
| 63 | @shapes = get_eye_shapesscip-perl cpan Acme-EyeDrops 1.62 Acme/EyeDrops/get_eye_shapes().(); |
| 64 | } |
| 65 | |
| 66 | for my $s (@shapes) { |
| 67 | printscip-perl cpan Acme-EyeDrops 1.62 main/print(). "--$s--\n"; |
| 68 | my $p = get_eye_propertiesscip-perl cpan Acme-EyeDrops 1.62 Acme/EyeDrops/get_eye_properties().($s) or next; |
| 69 | for my $k (sortscip-perl cpan Acme-EyeDrops 1.62 main/sort(). keysscip-perl cpan Acme-EyeDrops 1.62 main/keys(). %{$p}) { |
| 70 | printfscip-perl cpan Acme-EyeDrops 1.62 main/printf(). " %-13.13s: %s\n", $k, $p->{$k}; |
| 71 | } |
| 72 | if ($option{v}) { |
| 73 | printscip-perl cpan Acme-EyeDrops 1.62 main/print(). get_eye_stringscip-perl cpan Acme-EyeDrops 1.62 Acme/EyeDrops/get_eye_string().($s); |
| 74 | } |
| 75 | } |