summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/stex/bin/convert-paths
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/source/latex/stex/bin/convert-paths')
-rwxr-xr-xMaster/texmf-dist/source/latex/stex/bin/convert-paths56
1 files changed, 56 insertions, 0 deletions
diff --git a/Master/texmf-dist/source/latex/stex/bin/convert-paths b/Master/texmf-dist/source/latex/stex/bin/convert-paths
new file mode 100755
index 00000000000..55ee72a2370
--- /dev/null
+++ b/Master/texmf-dist/source/latex/stex/bin/convert-paths
@@ -0,0 +1,56 @@
+#!/usr/bin/perl -w
+#
+# A script that converts paths in sTeX files from the old \Foosnipppath{bar}
+# to \snippets{foo/bar}, according to the definition of those path macros in
+# paths.sty.
+#
+# Syntax: convert-paths path/to/paths.sty FILES
+#
+# © 2008 Christoph Lange, KWARC, Jacobs University
+
+use File::Copy;
+
+my %map;
+
+my $SNIPPATHRE = '\\\\[[:alnum:]]+(?i:snip|pic)path';
+
+if (open(P, shift(@ARGV))) {
+ print STDERR "Mapping:\n";
+ while (<P>) {
+ if (/^\\def($SNIPPATHRE)#1\{(\\KWARCslides\{[^#]+)#1\}/o) {
+ printf STDERR "\t%s -> %s\n", $1, $2;
+ $map{$1} = $2;
+ }
+ }
+ close(P);
+}
+else {
+ die "Could not open paths.sty";
+}
+
+print STDERR "Processing files:\n";
+while ($#ARGV >= 0) {
+ my $filename = shift(@ARGV);
+ print STDERR "\t$filename\n";
+ copy($filename, "$filename~") || print STDERR "\t\tWARN: could not create backup\n";
+ if (open(T, $filename)) {
+ # slurp the file into a string
+ local $/;
+ $data = <T>;
+ $data =~ s/($SNIPPATHRE)\{([^}]+)\}/
+ $map{$1} ? "$map{$1}$2\}"
+ : ((print STDERR "\t\tWARN: could not replace $1\n"), "$1\{$2}")
+ /oxge;
+ close T;
+ if (open(T, ">$filename")) {
+ print T $data;
+ close T;
+ }
+ else {
+ print STDERR "\t\tWARN: could not save replacement\n";
+ }
+ }
+ else {
+ print STDERR "\t\tWARN: could not open file\n";
+ }
+}