-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathga_merge
executable file
·79 lines (71 loc) · 1.71 KB
/
ga_merge
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
77
78
79
#!/usr/bin/env perl
use strict;
use warnings;
use File::Path qw(mkpath);
my $GA_DOC_DIR = "./";
my $GA_API_DOC = "ga_api_tmp.tex";
my $GA_API_DIR = "./tmp/";
if ($#ARGV == 0) {
$GA_API_DIR = "$ARGV[0]/";
}
mkpath $GA_API_DIR;
opendir(APIDIR,"$GA_API_DIR");
my @files = readdir(APIDIR);
closedir(APIDIR);
my @files2 = ();
foreach my $file (@files) {
# Skip any non-.tex file.
if ($file =~ m/\.tex/) {
# strip of .tex from filenames
my $shorter = substr $file,0,-4;
push (@files2, $shorter);
}
else {
print "skipping file: $file\n";
}
}
my $api_text = "";
my $begin = 0;
my $frag = "";
foreach my $file (sort @files2) {
# add .tex back on
$file = "$file.tex";
open(INFILE, "$GA_API_DIR/$file");
while (<INFILE>) {
my $line = $_;
if ($begin == 0) {
if ($line =~ /begin\{document\}/) {
$begin = 1;
$frag = "";
}
} else {
if ($line =~ /end\{document\}/) {
$begin = 0;
} else {
$frag .= $line;
if ($line =~/\S/) {
$api_text .= $frag;
$frag = "";
}
}
}
}
close(INFILE);
}
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\/preamble\}\n";
#$API_DECS .= "\\include\{otype\}\n\n";
open(OUTFILE, ">$GA_DOC_DIR/$GA_API_DOC");
my $api_doc = "";
$api_doc = $API_DECS;
$api_doc .= "\\begin\{document\}\n\n";
$api_doc .= $api_text;
$api_doc .= "\\end\{document\}\n";
print OUTFILE "$api_doc";
close(OUTFILE);