7 use String::ShellQuote qw( shell_quote );
8 use Any::URI::Escape qw( uri_escape );
10 my $path = $ENV{'PATH_INFO'};
11 my $query = $ENV{'QUERY_STRING'};
12 my $script_path = $ENV{'SCRIPT_NAME'};
15 my ($code, $meta) = @_;
16 print "$code $meta\r\n";
29 reply(20, 'text/gemini');
31 say "Search results for: $query";
34 open(my $h, "-|", ("apropos", "-w", $query));
38 my ($page, $section) = split /\./;
39 my $esc = uri_escape($page);
40 say "=> $script_path/$section/$esc $page($section)";
54 return shell_quote($a);
56 return shell_quote($a) . " " . shell_quote($b);
61 reply(20, 'text/plain');
63 say "OpenBSD 6.8 amd64";
64 say "% man ", join(' ', @_);
67 if (!defined($pid = fork())) {
70 exec("man -Tutf8 -- " . man_cmd(@_) .
71 " | col -b | sed '\$d'");
76 my $home = !$path || $path eq '/';
78 if ($home && $query) {
81 reply(20, 'text/gemini');
83 say "Welcome to the manual!";
85 say "This service allows you to lookup a manual page is several ways:";
86 say "* by name, appending /<name> to the current URL";
87 say "* by name and section, appending /<section>/<name> to the current URL";
88 say "* by searching it, appending ?<query> to the current URL";
90 say "=> $script_path/search Or just click here to search";
91 } elsif ($path =~ m[^/?search/?]) {
93 reply(10, 'manpage:');
96 } elsif ($path =~ m{^/([1-9]p?)/([-\w:]+)/?$}) {
98 } elsif ($path =~ m[^/([\w:]+)/?$]) {
101 reply(51, 'not found');