From e02deb23bf382d706e4085467fc0eb2b5b7364c0 Mon Sep 17 00:00:00 2001 From: Amin Bandali Date: Sat, 9 Oct 2021 22:08:37 -0400 Subject: [PATCH] txt2html: use Getopt::Long for saner command line arg handling --- GNUmakefile | 2 +- txt2html | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index 2330e5d..f5b4014 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -9,7 +9,7 @@ gen = perl txt2html < $< > $@ -gen_fa = perl txt2html 'fa' < $< > $@ +gen_fa = perl txt2html --lang='fa' < $< > $@ port := $(if $(port),$(port),8000) TXT := $(filter-out bandali-pubkey.txt bandali.txt,$(wildcard *.txt)) diff --git a/txt2html b/txt2html index 128995c..f2a23d9 100644 --- a/txt2html +++ b/txt2html @@ -23,6 +23,11 @@ use strict; use warnings 'all'; +use Getopt::Long; + +my $opt_lang = 'en'; +GetOptions ('lang=s' => \$opt_lang) + or die("bad command line arguments\n"); my $link_re = qr{([\('!])?\b((?:ftps?|https?|nntps?|imaps?|s?news|gopher):// @@ -91,7 +96,7 @@ sub linkify { my $txt = do { local $/; }; my $title = html_esc($txt =~ /\A([^\n]+)/); $title =~ s/^\s+|\s+$//g; -if ($ARGV[0] and $ARGV[0] eq 'fa') { +if ($opt_lang eq 'fa') { $title .= ' — بندعلی' if $title !~ /بندعلی/; } else { $title .= ' — bandali' if $title !~ /bandali/; @@ -100,16 +105,14 @@ if ($ARGV[0] and $ARGV[0] eq 'fa') { $txt = linkify(html_esc($txt)); print('', - ($ARGV[0] and $ARGV[0] eq 'fa') - ? '' - : '', - '', - '', + '', "$title", - ($ARGV[0] and $ARGV[0] eq 'fa') + $opt_lang eq 'fa' ? "\n\n" -- 2.20.1