diff --git a/faqs.pl b/faqs.pl

index 0c93c8ae1ba5c421cc1852929dd7358ebdc08672..28d7b8c027bf1ed6d37465b588880054821e52f6 100755

--- a/faqs.pl

+++ b/faqs.pl

@@ -9,15 +9,15 @@ use URI::Escape;

use lib 'lib/';

use gmnifaq;

-config();

-

# enable UTF-8 mode for everything

use utf8;

binmode STDOUT, ':utf8';

binmode STDERR, ':utf8';

+config();

+

if (!defined($ENV{'SERVER_PROTOCOL'}) || $ENV{'SERVER_PROTOCOL'} ne 'GEMINI') {

- write_response('CGI_ERROR', 'CGI execution error', undef);

+ write_response('CGI_ERROR', 'CGI execution error', undef);

}

my @body = ();

@@ -52,8 +52,8 @@ {

my @return;

my $dbh = DBI->connect($CONF{'dsn'}, '', '', { RaiseError => 1 }) or die $DBI::errstr;

- my @rows = $dbh->selectall_array(sql());

- $dbh->disconnect();

+ my @rows = $dbh->selectall_array(sql());

+ $dbh->disconnect();

if ( !scalar @rows ) {

push @return, 'No faqs found!';

diff --git a/index.pl b/index.pl

index 9b27f07e619d9075b8f8947788a7f825b4d6b097..209120f4625388a52c083e3937b40c5d78a4a5e4 100755

--- a/index.pl

+++ b/index.pl

@@ -8,15 +8,15 @@ use DBI;

use lib 'lib/';

use gmnifaq;

-config();

-

# enable UTF-8 mode for everything

use utf8;

binmode STDOUT, ':utf8';

binmode STDERR, ':utf8';

+config();

+

if (!defined($ENV{'SERVER_PROTOCOL'}) || $ENV{'SERVER_PROTOCOL'} ne 'GEMINI') {

- write_response('CGI_ERROR', 'CGI execution error', undef);

+ write_response('CGI_ERROR', 'CGI execution error', undef);

}

my @body = ();

@@ -37,9 +37,9 @@ sub header

{

my $dbh = DBI->connect($CONF{'dsn'}, '', '', { RaiseError => 1 }) or die $DBI::errstr;

- my $tagcount = $dbh->selectrow_array("SELECT count(id) from tags");

- my $faqcount = $dbh->selectrow_array("SELECT count(id) from questions");

- $dbh->disconnect();

+ my $tagcount = $dbh->selectrow_array("SELECT count(id) from tags");

+ my $faqcount = $dbh->selectrow_array("SELECT count(id) from questions");

+ $dbh->disconnect();

return ('# '. $CONF{'name'}, '', $CONF{'intro'}, '', sprintf('We are currently serving %d FAQs categorized with %d tags!', $faqcount, $tagcount), '');

}

diff --git a/lib/gmnifaq.pm b/lib/gmnifaq.pm

index c1b807efc5a3e795583af0d50540e6428f57bb8c..7311d29c7fe0a86f4e2ffcdc61d49739b69ded05 100755

--- a/lib/gmnifaq.pm

+++ b/lib/gmnifaq.pm

@@ -56,16 +56,16 @@ }

sub write_response

{

- my ($returncode, $meta, @content) = @_;

-

+ my ($returncode, $meta, @content) = @_;

+

if (!defined($RC{$returncode})) { die "Unknown response code!"; }

- printf("%d %s\r\n", $RC{$returncode}, ($meta eq '') ? $returncode : $meta);

- foreach (@content) {

- print("$_\r\n");

- }

+ printf("%d %s\r\n", $RC{$returncode}, ($meta eq '') ? $returncode : $meta);

+ foreach (@content) {

+ print("$_\r\n");

+ }

- exit;

+ exit;

}

1;

diff --git a/search.pl b/search.pl

index b31921d6980b1388f053d2b91a792df1eb22e834..b39cd56f182859dae2e5d8965e062560f1f00822 100755

--- a/search.pl

+++ b/search.pl

@@ -17,7 +17,7 @@ binmode STDOUT, ':utf8';

binmode STDERR, ':utf8';

if (!defined($ENV{'SERVER_PROTOCOL'}) || $ENV{'SERVER_PROTOCOL'} ne 'GEMINI') {

- write_response('CGI_ERROR', 'CGI execution error', undef);

+ write_response('CGI_ERROR', 'CGI execution error', undef);

}

my $query = lc(uri_unescape($ENV{'QUERY_STRING'}));

@@ -41,8 +41,8 @@ my ($term) = @_;

my @result = ();

my $dbh = DBI->connect($CONF{'dsn'}, '', '', { RaiseError => 1 }) or die $DBI::errstr;

- my @matchingtags = $dbh->selectall_array("SELECT id, name, count(t_id) FROM tags LEFT JOIN tags_questions ON tags_questions.t_id = tags.id WHERE name LIKE '%$term%' GROUP BY t_id");

- my @matchingfaqs = $dbh->selectall_array("SELECT * FROM questions WHERE question LIKE '%$term%' OR answer LIKE '%$term%'");

+ my @matchingtags = $dbh->selectall_array("SELECT id, name, count(t_id) FROM tags LEFT JOIN tags_questions ON tags_questions.t_id = tags.id WHERE name LIKE '%$term%' GROUP BY t_id");

+ my @matchingfaqs = $dbh->selectall_array("SELECT * FROM questions WHERE question LIKE '%$term%' OR answer LIKE '%$term%'");

$dbh->disconnect();

if ( scalar(@matchingtags)) {

diff --git a/tags.pl b/tags.pl

index 805b3235d2e0ca22d56c67162c35178a842f98c0..8417146bc235d3c4f4783b9a624507d04e08ebaa 100755

--- a/tags.pl

+++ b/tags.pl

@@ -5,6 +5,7 @@ # https://git.sr.ht/~rwa/gmni-perl-cgi-demo

use strict;

use DBI;

+use URI::Escape;

use lib 'lib/';

use gmnifaq;

@@ -16,7 +17,7 @@ binmode STDOUT, ':utf8';

binmode STDERR, ':utf8';

if (!defined($ENV{'SERVER_PROTOCOL'}) || $ENV{'SERVER_PROTOCOL'} ne 'GEMINI') {

- write_response('CGI_ERROR', 'CGI execution error', undef);

+ write_response('CGI_ERROR', 'CGI execution error', undef);

}

my @body = ();

@@ -33,8 +34,8 @@ {

my $dbh = DBI->connect($CONF{'dsn'}, '', '', { RaiseError => 1 }) or die $DBI::errstr;

my @result;

- my @rows = $dbh->selectall_array('SELECT id, name, count(t_id) FROM tags LEFT JOIN tags_questions ON tags_questions.t_id = tags.id GROUP BY t_id');

- $dbh->disconnect();

+ my @rows = $dbh->selectall_array('SELECT id, name, count(t_id) FROM tags LEFT JOIN tags_questions ON tags_questions.t_id = tags.id GROUP BY t_id');

+ $dbh->disconnect();

if ( !scalar @rows ) {

push @result, 'No tags found!';