tools: add new builtin macros to assemblies

This commit is contained in:
Ralph Lange
2015-10-10 19:12:11 +02:00
parent 8596dc41f2
commit f8b0b2f5f0
2 changed files with 15 additions and 1 deletions
+6
View File
@@ -11,6 +11,7 @@ use strict;
use warnings;
use Getopt::Std;
use Sys::Hostname;
use File::Basename;
use Data::Dumper;
@@ -26,18 +27,22 @@ my $ipattern;
my $datetime = localtime();
my $user = $ENV{LOGNAME} || $ENV{USER} || $ENV{USERNAME};
my $host = hostname;
my %replacements = (
_DATETIME_ => $datetime,
_USER_ => $user,
_HOST_ => $host,
);
if ($opt_o) {
open $out, '>', $opt_o or
die "Can't create $opt_o: $!\n";
print STDERR "opened file $opt_o for output\n" if $opt_d;
$replacements{_OUTPUTFILE_} = $opt_o;
} else {
open $out, '>&', STDOUT;
print STDERR "using STDOUT for output\n" if $opt_d;
$replacements{_OUTPUTFILE_} = 'STDERR';
}
if ($opt_m) {
@@ -113,6 +118,7 @@ foreach my $r (sort {$a<=>$b} keys %snippets) {
my $f = $s->[0];
print STDERR " snippet $n from file $f\n" if $opt_d;
open $in, '<', $f or die "Can't open $f: $!\n";
$replacements{_SNIPPETFILE_} = $f;
print $dep " \\\n $f" if $opt_M;
while (<$in>) {
chomp;
+9 -1
View File
@@ -1,10 +1,12 @@
#!/usr/bin/env perl
use File::Path;
use Sys::Hostname;
use Test::More tests => 26;
use Test::More tests => 29;
my $user = $ENV{LOGNAME} || $ENV{USER} || $ENV{USERNAME};
my $host = hostname;
mkdir "a$$";
mkdir "b$$";
@@ -76,7 +78,13 @@ is assemble("a$$/10_a", "b$$/2_a", "a$$/15_a", "b$$/09_a"), '2 09 10 15', "rank
# Builtin macros
mksnip('a', '30_a', '_USER_');
mksnip('a', '30_b', '_OUTPUTFILE_');
mksnip('a', '30_c', '_SNIPPETFILE_');
mksnip('a', '30_d', '_HOST_');
is assemble("a$$/30_a"), "$user", "builtin macro _USER_";
is assemble("a$$/30_b"), "out$$", "builtin macro _OUTPUTFILE_";
is assemble("a$$/30_c"), "a$$/30_c", "builtin macro _SNIPPETFILE_";
is assemble("a$$/30_d"), "$host", "builtin macro _HOST_";
# User macros
mksnip('b', '35_a', 'Line _M1_');