-
Notifications
You must be signed in to change notification settings - Fork 4
/
insert-figures
executable file
·76 lines (73 loc) · 2.19 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/perl
sub insert {
local($file, $wrapped, $codewrapped, $codetype) = @_;
my $file;
my $basefile;
my $lastline;
$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);
$basefile = shift @sorted;
$file = "yang/" . $basefile;
print STDERR "Setting file=$file\n";
}
open(FILE, "<" . $file) || die "Can not open $file: $!\n";
print "<figure><artwork><![CDATA[\n" if $wrapped && !$codetype;
print "<sourcecode type=\"$codetype\"><![CDATA[\n" if $wrapped && $codetype;
if($file =~ /\.yang$/) {
$codewrapped=1;
print "<CODE BEGINS> file \"$basefile\"\n";
} else {
print "<CODE BEGINS>\n" if $codewrapped;
}
while(<FILE>) {
print;
$lastline = $_;
}
close(FILE);
$lastline=~ s/^\s+|\s+$//g;
print "\n" if length($lastline)>0;
print "<CODE ENDS>\n" if $codewrapped;
print "]]></artwork></figure>\n" if $wrapped && !$codetype;
print "]]></sourcecode>\n" if $wrapped && $codetype;
}
while(<>) {
if(/INSERT_TEXT_FROM_FILE (.*) END/) {
insert($1, 0, 0);
}
elsif(/INSERT_FIG_FROM_FILE (.*) END/) {
insert($1, 1, 0);
}
elsif(/INSERT_CBORDIAG_FROM_FILE (.*) END/) {
insert($1, 1, 0, "cbor-diag");
}
elsif(/INSERT_X509_FROM_FILE (.*) END/) {
insert($1, 1, 0, "x509");
}
elsif(/INSERT_HEX_FROM_FILE (.*) END/) {
insert($1, 1, 0, "pseudocode");
}
elsif(/INSERT_PEM_FROM_FILE (.*) END/) {
insert($1, 1, 0, "x509");
}
elsif(/INSERT_CODE_FROM_FILE (.*) END/) {
insert($1, 1, 1, "pseudocode");
}
elsif(/INSERT_SH_FROM_FILE (.*) END/) {
insert($1, 1, 1, "bash");
}
elsif(/INSERT_C_FROM_FILE (.*) END/) {
insert($1, 1, 1, "c");
} else {
print;
}
}