git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/24] Documentation: Add variable-substitution script

From
Jakub Narebski <jnareb@gmail.com>
Date
Jul 26, 2010, 21:17 UTC
Message-ID
<m3wrsikkol.fsf@localhost.localdomain>
In-Reply-To
<049043aa444288fd9409a3706fe3190fd679cb7d.1280169048.git.trast@student.ethz.ch>
Thomas Rast <trast@student.ethz.ch> writes:
Show 33 quoted lines
> diff --git a/Documentation/subst-config.perl b/Documentation/subst-config.perl
> new file mode 100755
> index 0000000..a981670
> --- /dev/null
> +++ b/Documentation/subst-config.perl
> @@ -0,0 +1,74 @@
> +#!/usr/bin/perl
> +use 5.006002;
> +use strict;
> +use warnings;
> +use Getopt::Long;
> +
> +Getopt::Long::Configure qw/ pass_through /;
> +
> +my $rc = GetOptions(
> +    "varlist=s" => \my $varlist,
> +    "input=s"   => \my $input,
> +    "output=s"  => \my $output,
> +);
> +
> +if (!$rc or (!-r $varlist or !-r $input)) {
> +    print "$0 --varlist=<varlist> --input=<in> --output=<out>\n";
> +    exit 1;
> +}
> +
> +my $vars = read_varlist($varlist);                       # [1]
> +substitute_variables($vars, $input, $output);            # [2]
> +exit 0;
> +
> +sub read_varlist {
> +    my ($file) = @_;
> +
> +    open my $fh, "<", $varlist or die "cannot open $varlist: $!";
NITPICK

You are passing global variable $varlist to this function as parameter $file, see place marked [1]. Why don't you use there $file instead of $varlist? Alternatively, why don't you name parameter as $varlist?

Show 5 quoted lines
> +sub substitute_variables {
> +    my ($varlist, $in, $out) = @_;
> +
> +    open my $infh, "<", $input or die "Can't open $in for reading: $!";
> +    open my $outfh, ">", $output or die "Can't open $out for reading: $!";
Same here: $input or $in, $output or $out?
Show 17 quoted lines
> +
> +    while (<$infh>) {
> +        if (/^\@\@CONFIG\((\S+)\)\@\@$/) {
> +            my $v = lc $1;
> +            die "Key $v not documented" unless exists $varlist->{$v};
> +            print $outfh @{$varlist->{$v}};
> +            print $outfh "\n";
> +        } else {
> +            print $outfh $_;
> +        }
> +    }
> +
> +    close $infh or die "closing input failed: $!";
> +    close $outfh or die "closing output failed: $!";
> +
> +    return;
> +}

Also, could you consitently start error messages (in die "sth") with capital letter (upper-case), or with lower-case letter?

-- 
Jakub Narebski
Poland
ShadeHawk on #git
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 5 of 14 in “Documentation: refactor config variable descriptions”
  1. 0/24 Documentation: refactor config variable descriptionsThomas Rast, Jul 26, 2010
  2. 2/24 Documentation: Add variable-substitution scriptThomas Rast, Jul 26, 2010
  3. Jonathan NiederJul 26, 2010
  4. Ævar Arnfjörð BjarmasonJul 26, 2010
  5. Jakub NarebskiJul 26, 2010
  6. Ævar Arnfjörð BjarmasonJul 26, 2010
  7. 24/24 Documentation: include configuration options in manpagesThomas Rast, Jul 26, 2010
  8. Jonathan NiederJul 26, 2010
  9. Ævar Arnfjörð BjarmasonJul 26, 2010
  10. Ævar Arnfjörð BjarmasonJul 26, 2010
  11. Jonathan NiederJul 26, 2010
  12. Ævar Arnfjörð BjarmasonJul 26, 2010
  13. Sverre RabbelierJul 27, 2010
  14. Junio C HamanoJul 28, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.