Quick & dirty utility for making DTD entities
authorphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 5 Oct 2009 20:42:53 +0000 (20:42 +0000)
committerphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 5 Oct 2009 20:42:53 +0000 (20:42 +0000)
Usage:
        make_entities.pl <prefix> <filename> > filename.new 2> entities.dtd

        mv filename.new filename
        sort entities.dtd | uniq >> lang.dtd

git-svn-id: svn://svn.open-ils.org/ILS/trunk@14264 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/xul/staff_client/external/make_entities.pl [new file with mode: 0755]

diff --git a/Open-ILS/xul/staff_client/external/make_entities.pl b/Open-ILS/xul/staff_client/external/make_entities.pl
new file mode 100755 (executable)
index 0000000..e785808
--- /dev/null
@@ -0,0 +1,27 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+my $entity_prefix = $ARGV[0];
+my $filename = $ARGV[1];
+
+if (! $entity_prefix && ! $filename) {
+    print STDOUT "Usage:\n\tmake_entities.pl <prefix> <filename> > filename.new 2> entities.dtd\n\n\tmv filename.new filename\n\tsort entities.dtd | uniq >> lang.dtd\n\n";
+    exit 0;
+}
+
+my %entity_hash = ();
+
+open FILE, $filename;
+while (my $line = <FILE>) {
+
+    while ($line =~ /(label|value)="(.+?)"/g) {
+        my $value = $2; if ( $value =~ /^&.+;$/ ) { next; } # Already an entity
+        my $entity = $value; $entity =~ s/\W/_/g; $entity = $entity_prefix . $entity;
+        $line =~ s/$value/&$entity;/g;
+        print STDERR qq^<!ENTITY $entity "$value">\n^;
+    }
+    print STDOUT $line;
+
+}
+close FILE;