summaryrefslogtreecommitdiffstats
path: root/misc
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2022-05-27 23:27:27 +0200
committerDavid A. Madore <david+git@madore.org>2022-05-27 23:27:27 +0200
commitdadb4ff38f53dd4b3b5e4b13e16f713d32018a89 (patch)
treebb587fd096360801611d5546ec02ffdd4a41cc6f /misc
parentb56f7e20a51fb6cec8238f943c19dc6837923d0e (diff)
downloadinf105-dadb4ff38f53dd4b3b5e4b13e16f713d32018a89.tar.gz
inf105-dadb4ff38f53dd4b3b5e4b13e16f713d32018a89.tar.bz2
inf105-dadb4ff38f53dd4b3b5e4b13e16f713d32018a89.zip
Write another short quiz.
Diffstat (limited to 'misc')
-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";
+}