-
Notifications
You must be signed in to change notification settings - Fork 0
/
ga_split
executable file
·69 lines (64 loc) · 1.66 KB
/
ga_split
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
#!/usr/bin/env perl
use strict;
use warnings;
use File::Path qw(mkpath);
my $GA_DOC_DIR = "./";
my $GA_API_DOC = "ga_api.tex";
my $GA_API_DIR = "./tmp/";
if ($#ARGV >= 0) {
$GA_API_DIR = "$ARGV[0]/";
}
if ($#ARGV >= 1) {
$GA_API_DOC = "$ARGV[1]";
}
mkpath $GA_API_DIR;
my $API_DECS = "\\documentclass\[12pt\]\{article\}\n";
$API_DECS .= "\\usepackage\{fullpage\}\n";
$API_DECS .= "\\usepackage\{color\}\n";
$API_DECS .= "\\usepackage\{alltt\}\n";
$API_DECS .= "\\usepackage\{underscore\}\n";
$API_DECS .= "\\usepackage\{environ\}\n";
$API_DECS .= "\\usepackage\{graphicx\}\n";
$API_DECS .= "\\include\{preamble\}\n";
$API_DECS .= "\\include\{otype\}\n\n";
my %apis = ();
my $key = "";
my $entry = "";
my $begin = 0;
# Parse infile and divide API documentation into individual entries
open(INFILE, "$GA_DOC_DIR/$GA_API_DOC") or die "couldn't open infile";
while(<INFILE>) {
my $line = $_;
if ($line =~ /\\apih\{([^\}]*)\}/) {
$begin = 1;
if ($entry) {
$apis{$key} = $entry;
}
# make api name lowercase and spaces replaced with dashes
$key = $1;
unless($key) {
die "key was empty for line '$line'";
}
$key =~ s/ /\-/g;
$key = lc($key);
$entry = $line;
} elsif ($line =~ /\\end\{document\}/) {
if ($entry) {
$apis{$key} = $entry;
}
} elsif ($begin == 1) {
$entry .= $line;
}
}
close(INFILE);
foreach my $key (keys %apis)
{
my $api_doc = $API_DECS;
$api_doc .= "\\begin\{document\}\n\n";
$api_doc .= $apis{$key};
$api_doc .= "\\end\{document\}\n";
my $api_file = "$key.tex";
open(OUTFILE, ">$GA_API_DIR$api_file") or die "couldn't open outfile";
print OUTFILE "$api_doc";
close(OUTFILE);
}