summaryrefslogtreecommitdiffstats
path: root/misc/quiz-extract-automata.pl
diff options
context:
space:
mode:
Diffstat (limited to 'misc/quiz-extract-automata.pl')
-rwxr-xr-xmisc/quiz-extract-automata.pl53
1 files changed, 53 insertions, 0 deletions
diff --git a/misc/quiz-extract-automata.pl b/misc/quiz-extract-automata.pl
new file mode 100755
index 0000000..8327ce3
--- /dev/null
+++ b/misc/quiz-extract-automata.pl
@@ -0,0 +1,53 @@
+#! /usr/local/bin/perl -w
+
+use strict;
+use warnings;
+
+my $inputfile = $ARGV[0];
+die "please pass input file as argument" unless defined($inputfile);
+my $outputdir = "/tmp/automata";
+
+my $f;
+
+open $f, "<", $inputfile or die "can't open $inputfile: $!";
+my %automata;
+my $thisname;
+while (<$f>) {
+ $thisname = undef if defined($thisname) && /^\\end\{center\}/;
+ $automata{$thisname} .= $_ if defined($thisname);
+ $thisname = $1 if /^\\begin\{center\}\s*\%+\s*NAME:\s*(\S+)/;
+}
+close $f;
+
+my $prologue = <<'__EOF__';
+\documentclass[crop,tikz]{standalone}
+%
+%
+%
+\usepackage{tikz}
+\usetikzlibrary{arrows,automata,positioning}
+%
+\tikzstyle{automaton}=[>=stealth',initial text={},thick,every loop/.style={min distance=7mm,looseness=5}]
+\tikzstyle{state}=[]
+\tikzstyle{final}=[accepting by arrow]
+%
+%
+%
+__EOF__
+
+mkdir $outputdir;
+
+foreach my $name (keys(%automata)) {
+ chdir $outputdir;
+ print "Processing $name\n";
+ open $f, ">", "${outputdir}/${name}.tex";
+ print $f $prologue;
+ print $f "\\begin{document}\n\n";
+ print $f $automata{$name};
+ print $f "\n\\end{document}\n";
+ close $f;
+ system "pdflatex", "${name}.tex";
+ system "pdf2svg", "${name}.pdf", "${name}.raw.svg";
+ system "scour", "-i", "${name}.raw.svg", "-o", "${name}.svg";
+ system "rsvg-convert", "${name}.svg", "-d", "300", "-p", "300", "-b", "white", "-o", "${name}.png";
+}