-
Notifications
You must be signed in to change notification settings - Fork 1
/
insert-figures
executable file
·48 lines (45 loc) · 1.43 KB
/
insert-figures
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/perl
use File::Basename;
while(<>) {
if(/INSERT_TEXT_FROM_FILE (.*) END/) {
my $codewrapper=0;
my $base;
my $basename;
$file = $1;
print STDERR "File: $file\n";
if( $file =~ /(.*)\@DATE/ ) {
$base = $1;
print STDERR "Searching for base=$base\n";
# look for the newest file with @DATE, assumed to be in CWD.
opendir(DIR, "yang");
@files=readdir(DIR);
closedir(DIR);
#print STDERR join(',', @files);
my @sorted = reverse sort grep(/^$base@/,@files);
#print STDERR join(',', @sorted);
$file = "yang/" . shift @sorted;
$basename = basename($file);
print STDERR "Setting file=$file (basename=${basename})\n";
}
open(FILE, "<" . $file) || die "Can not open $file: $!\n";
print "<artwork><![CDATA[\n";
if($file =~ /\.yang$/) {
$codewrapper=1;
print "<CODE BEGINS> file \"$basename\"\n"
}
elsif($file =~ /\.sh$/) {
$basename = basename($file);
$sourcewrapper=1;
print "<sourcecode> file \"$basename\"\n"
}
while(<FILE>) {
print;
}
close(FILE);
print "<CODE ENDS>\n" if $codewrapper;
print "</sourcecode>\n" if $sourcewrapper;
print "]]></artwork>\n";
} else {
print;
}
}