git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: Jakub Narebski <jnareb@gmail.com>
Cc: Thomas Rast <trast@student.ethz.ch>,
	git@vger.kernel.org, Jonathan Nieder <jrnieder@gmail.com>,
	Jeff King <peff@peff.net>
Subject: Re: [PATCH 2/24] Documentation: Add variable-substitution script
Date: Mon, 26 Jul 2010 21:49:36 +0000	[thread overview]
Message-ID: <AANLkTinM8w4MiwdNmiUzLDRvR-NqSxNn0I1avQDt9QtR@mail.gmail.com> (raw)
In-Reply-To: <m3wrsikkol.fsf@localhost.localdomain>

On Mon, Jul 26, 2010 at 21:17, Jakub Narebski <jnareb@gmail.com> wrote:

Well caught. Those were on me, here's the fixed up version (in my
branch, which Thomas can pull in to his):

#!/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);
substitute_variables($vars, $input, $output);
exit 0;

sub read_varlist {
	my ($file) = @_;

	open my $fh, "<", $file or die "Can't open $file: $!";
	my %vars;

	my ($v, $last_v);
	my $in_block = 0;
	while (<$fh>) {
		if (/^(\S+)::/) {
			$v = lc $1;
			$in_block = 0;
			push @{$vars{$v}}, $_;
		} elsif (/^$/ && !$in_block) {
			if (defined $last_v && !$#{$vars{$last_v}}) {
				$vars{$last_v} = $vars{$v};
			}
			$last_v = $v;
		} elsif (defined $v) {
			push @{$vars{$v}}, $_;
			$in_block = !$in_block if /^--$/;
		}
	}

	close $fh or die "Closing $file failed: $!";

	return \%vars
}

sub substitute_variables {
	my ($varlist, $in, $out) = @_;

	open my $infh, "<", $in or die "Can't open $in: $!";
	open my $outfh, ">", $out or die "Can't open $out: $!";

	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 $in failed: $!";
	close $outfh or die "Closing $out failed: $!";

	return;
}

  reply	other threads:[~2010-07-26 21:49 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-26 18:48 [RFC PATCH 0/24] Documentation: refactor config variable descriptions Thomas Rast
2010-07-26 18:48 ` [PATCH 2/24] Documentation: Add variable-substitution script Thomas Rast
2010-07-26 19:51   ` Jonathan Nieder
2010-07-26 20:27     ` Ævar Arnfjörð Bjarmason
2010-07-26 21:17   ` Jakub Narebski
2010-07-26 21:49     ` Ævar Arnfjörð Bjarmason [this message]
2010-07-26 18:48 ` [PATCH 3-24/24] Documentation: include configuration options in manpages Thomas Rast
2010-07-26 19:55   ` Jonathan Nieder
2010-07-26 19:05 ` [RFC PATCH 0/24] Documentation: refactor config variable descriptions Ævar Arnfjörð Bjarmason
     [not found] ` <75c9db91f5ab43ebb60cace0d20389462a2ab02c.1280169048.git.trast@student.ethz.ch>
2010-07-26 19:38   ` [PATCH 1/24] Documentation: Move variables from config.txt to separate file Jonathan Nieder
2010-07-26 20:18     ` Ævar Arnfjörð Bjarmason
2010-07-27  6:48       ` Sverre Rabbelier
2010-07-28 17:23       ` Junio C Hamano
2010-07-26 22:25 ` [RFC PATCH 0/24] Documentation: refactor config variable descriptions Ævar Arnfjörð Bjarmason

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AANLkTinM8w4MiwdNmiUzLDRvR-NqSxNn0I1avQDt9QtR@mail.gmail.com \
    --to=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=jnareb@gmail.com \
    --cc=jrnieder@gmail.com \
    --cc=peff@peff.net \
    --cc=trast@student.ethz.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).