/usr/bin/gift-dtd-to-keywords.pl is in gnuift-perl 0.1.14-12.1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | #!/usr/bin/perl -w # -*- mode: perl -*-
# GIFT, a flexible content based image retrieval system.
# Copyright (C) 1998, 1999, 2000, 2001, 2002, CUI University of Geneva
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# gift-dtd-to-tex.pl
#
# This program turns a simple sgml dtd (with does not contain external
# entities) into a class, which contains all keywords as string constants
#
# The use of this is to improve type safety when extendint MRML or changing
# things in the program
#
use Getopt::Long;
use XML::Parser;
require 5.002;
#use strict;
use Socket;
use FileHandle;
use English;
use IO::File;
use XML::Parser;
########################################
#
# slurps in some DTD and translates all te
# keywords of the DTD into constant strings of
# the language wanted
#
########################################
package CDTDToLanguage;
require Exporter;
@ISA= qw(Exporter);
@EXPORT= qw(new
slurpDTD
translateToLanguage
);
sub new {
my $class = shift;
my $self = {};
bless $self, $class;
$self->initialize();
return $self;
}
sub initialize(){
my$self=shift;
$self->{parser} = new XML::Parser(Handlers => {Element => \&handleElement,
Attlist => \&handleAttlist,
});
# Make the parser know who is this structure
$self->{parser}->{mCaller}=$self;
$self->{parser}->{mMagic}=42;
###############################
#ยง
# for quick changes what to look at when debugging/testing
#
#
$self->{vDEBUG}={
handleElement => 1,
handleAttlist => 1,
processDTD => 1,
};
print "Printing debugging info for the functions:\n";
{
my $i;
foreach $i (keys(%{$self->{vDEBUG}})){
if($self->{vDEBUG}->{$i}){
print "$i\n";
}
}
}
###############################
#
# Parameters for the query. Here some set/get/functions would be nice
#
}
##############################
#
# Expat parser handlers
#
sub handleElement( $$$ ){
my $self=shift;
die "BLACK MAGIC!" if ($self->{mMagic}!=42);
$self=$self->{mCaller};
my $lElementName=shift;
print "Element: $lElementName\n" if($self->{vDEBUG}->{handleElement});
$self->{used}->{$lElementName}=1;
}
sub handleAttlist( $$$$$$ ){
my $self=shift;
die "BLACK MAGIC!" if ($self->{mMagic}!=42);
$self=$self->{mCaller};
my($inElement)=shift;
my $lAttributeName=shift;
print "Attribute: $lAttributeName\n" if($self->{vDEBUG}->{handleAttlist});
$self->{used}->{$lAttributeName}=1;
}
sub processDTD( $$ ){
my$self=shift;
my $lDTDHandle=shift;
my $lEmptyText=shift;
print "\nNow I will try to read...\n" if($self->{vDEBUG}->{processDTD});
#we read, and then we parse
#for this reason, we can return the
#string read
{
my $lRead=join("",$lDTDHandle->getlines());
if($lRead){
if($self->{vDEBUG}->{processDTD}){
print "Parsing: $lRead";
open OF,">mrml-parsing-log";
print OF $lRead;
}
$self->{parser}->parse("$lRead $lEmptyText");
}
$lRead;
}
}
sub translateToJava( $;$ ){
my$self=shift;
my $lClassname=shift;
my $inPackage=shift || $lClassname;
my $lFH=new IO::File;
$lFH->open("> $lClassname.java") or die "could not generate $lClassname.java $!\n";
print $lFH "
//Automatically generated from the dtd by gift-dtd-to-keywords
package $inPackage;
import java.lang.String;
public class $lClassname \{ \n";
foreach $i (sort keys(%{$self->{used}})){
$_=$i;
tr[-][_];
tr[A-Z][a-z];
print $lFH " public final static String $_ = new String(\"$i\");\n "
}
print $lFH "\}; \n";
}
sub translateToH( $ ){
my$self=shift;
my $lClassname=shift;
my $lFH=new IO::File;
$lFH->open("> $lClassname.h") or die "could not generate $lClassname.h $!\n";
print $lFH "
#ifndef _MRML_CONST
#define _MRML_CONST
//Automatically generated from the dtd by gift-dtd-to-keywords
#include <string>
using namespace std;
class $lClassname \{ public: \n";
foreach $i (sort keys(%{$self->{used}})){
$_=$i;
tr[-][_];
tr[A-Z][a-z];
print $lFH " static const string $_;\n "
}
print $lFH "\}; \n#endif\n";
}
sub translateToCC( $ ){
my$self=shift;
my $lClassname=shift;
my $lIncludePrefix="libMRML/include/";
my $lFH=new IO::File;
$lFH->open("> $lClassname.cc") or die "could not generate $lClassname.cc $!\n";
print $lFH "
//Automatically generated from the dtd by gift-dtd-to-keywords
#include <string>
#include \"$lIncludePrefix$lClassname.h\"
";
foreach $i (sort keys(%{$self->{used}})){
$_=$i;
tr[-][_];
tr[A-Z][a-z];
print $lFH "const string ${lClassname}::$_(\"$i\");\n "
}
print $lFH "\n";
}
package main;
%lOptions=();
GetOptions(\%lOptions,
"cc",
"include",
"java"
);
my $inDTDFile=shift;
my $inTag=shift;
my $inClassname=shift;
my $inPackagename=shift;
if(!$inDTDFile){
print "
Usage: gift-dtd-to-keywords.pl infile doctype classname packagename
This program turns a simple sgml dtd (with does not contain external
entities) into LaTeX.
";
}
my $lDTDToLanguage=new CDTDToLanguage();
{
my $lFH=new IO::File;
$lFH->open("< $inDTDFile") or die "there is no $inDTDFile $!\n";
$lDTDToLanguage->processDTD($lFH,"<$inTag></$inTag>");
$lDTDToLanguage->translateToJava($inClassname,
$inPackagename);
$lDTDToLanguage->translateToH($inClassname);
$lDTDToLanguage->translateToCC($inClassname);
}
|