/usr/bin/gift-dtd-to-tex.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 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | #!/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 CDTDToTeX;
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,
Comment => \&handleComment,
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}={
handleComment => 0,
handleElement => 0,
handleAttlist => 0,
processDTD => 0,
};
print "Printing debugging info for the functions:\n";
{
my $i;
foreach $i (keys(%{$self->{vDEBUG}})){
if($self->{vDEBUG}->{$i}){
print "$i\n";
}
}
}
###############################
#
# this structure contains the attribute-lists for all
# elements
#
$self->{attribute_list}={};
}
##############################
#
# Expat parser handlers
#
sub handleComment( $$ ){
my $self=shift;
die "BLACK MAGIC!" if ($self->{mMagic}!=42);
$self=$self->{mCaller};
my $lComment=shift;
$lComment=~s/\+\+\++//g;
print "Comment: $lComment\n" if($self->{vDEBUG}->{handleComment});
$self->addComment($lComment);
}
sub handleElement( $$$ ){
my $self=shift;
die "BLACK MAGIC!" if ($self->{mMagic}!=42);
$self=$self->{mCaller};
my $inElementName=shift;
my $inElementModel=shift;
print "<!ELEMENT $inElementName,$inElementModel >\n" if($self->{vDEBUG}->{handleElement});
$self->addElement($inElementName,
$inElementModel);
}
sub handleAttlist( $$$$$$ ){
my $self=shift;
die "BLACK MAGIC!" if ($self->{mMagic}!=42);
$self=$self->{mCaller};
my $inElement=shift;
my $inAttributeName=shift;
my $inAttributeType=shift;
my $inDefault=shift;
my $inFixed=shift || "";
unless($inAttributeName=~m/^cui-/){
$self->addAttribute($inElement,[$inAttributeName,
$inAttributeType,
$inDefault
]);
print "Attribute: $inAttributeName $inAttributeType $inDefault $inFixed\n" if($self->{vDEBUG}->{handleAttlist});
}
}
sub processDTD( $$$$ ){
my$self=shift;
my $lDTDHandle=shift;
my $lEmptyText=shift;
my $lStartTeX=shift;
my $lEndTeX=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
$self->initialiseSequence($lStartTeX);
{
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;
}
$self->buildStringFromSequence();
$self->endSequence($lEndTeX);
return $self->{string_from_sequence};
}
sub addAttribute( $$ ){
my $self=shift;
my $inElement=shift;
my $inAttributeDescription=shift;
unless(ref($self->{attribute_list}->{$inElement})){
$self->{attribute_list}->{$inElement}=[];
push @{$self->{printer_sequence}},["attribute",$inElement];
}
push @{$self->{attribute_list}->{$inElement}}, $inAttributeDescription;
}
sub addText( $ ){
my $self=shift;
my $inText=shift;
push @{$self->{printer_sequence}},["text",$inText];
}
sub addComment( $ ){
my $self=shift;
my $inText=shift;
push @{$self->{printer_sequence}},["comment",[$inText]];
}
sub addElement( $ ){
my $self=shift;
my $inElementName=shift;
my $inModel=shift;
push @{$self->{printer_sequence}},["element",[$inElementName,$inModel]];
}
sub addToSequence( $ ){
my$self=shift;
my $inText=shift;
$self->{string_from_sequence}.=$inText;
}
sub initialiseSequence( $ ){
my$self=shift;
my$inStart=shift || "\n%TESTBEGIN\n";
$self->{string_from_sequence}=$inStart;
}
sub endSequence( $ ){
my$self=shift;
my$inEnd=shift || "\n%TESTEND\n";
$self->{string_from_sequence}.=$inEnd;
}
sub buildStringFromSequence( ){
my $self=shift;
my $i;
foreach $i (@{$self->{printer_sequence}}){
$self->printText($i->[1]) if( $i->[0] eq "text");
$self->printComment($i->[1]) if( $i->[0] eq "comment");
$self->printAttribute($i->[1]) if( $i->[0] eq "attribute");
$self->printElement($i->[1]) if( $i->[0] eq "element");
}
}
sub printElement( $ ){
my $self=shift;
my $inElement=shift;
unless($inElement->[0]=~m/^cui-/){
$lModel=$inElement->[1];
#remove cui-private tags
$lModel=~s/cui[\-a-zA-Z]*//g;
#clean up resulting untidiness
$lModel=~s/(\||,)(\s|\n)*([\)\|])/$3/g;
$self->addToSequence("\\begin{verbatim}\n<!ELEMENT $inElement->[0] $lModel \n>\\end{verbatim}\n\n");
}
}
sub printComment( $ ){
my $self=shift;
my $inComment=shift;
my $lCommentString=$inComment->[0];
$self->addToSequence("\\begin{verbatim}<!--\\end{verbatim}\n $lCommentString \n \\begin{verbatim}-->\\end{verbatim}\n\n\n\n") unless($lCommentString=~m/==HIDE/);
}
sub printAttribute( $ ){
my $self=shift;
my $inElement=shift;
$self->addToSequence("\\begin{verbatim}\n<!ATTLIST $inElement ");
my $i;
for $i (@{$self->{attribute_list}->{$inElement}}){
$self->addToSequence("\n ".(" " x length($inElement)).join(" ",@$i));
}
$self->addToSequence("\n>\\end{verbatim}\n\n");
}
sub printText( $ ){
my $self = shift;
my $inText = shift;
$self->addToSequence("$inText\n");
}
package main;
%lOptions=();
GetOptions(\%lOptions,
"fragment"
);
my $inDTDFile=shift;
my $inTag=(split(/(\.)|(\/)/,$inDTDFile))[-4];
if(!$inDTDFile){
print "
Usage: gift-dtd-to-tex.pl infile [--fragment]
This program turns a simple sgml dtd (with does not contain external
entities) into LaTeX.
Options:
--fragment create a fragment which can be included into other LaTeX files
";
}
my $lDTDToTeX=new CDTDToTeX();
{
my $lFH=new IO::File;
my $lOH=new IO::File;
$lFH->open("< $inDTDFile") or die "there is no $inDTDFile $!\n";
$lOH->open("> ${inDTDFile}.tex") or die "there is no ${inDTDFile}.tex $!\n";
unless(%lOptions->{fragment}){
print $lOH $lDTDToTeX->processDTD($lFH,"<$inTag></$inTag>",
'\documentclass{article}
\newcommand{\requesttitle}[1]{\textbf{Request: }{\texttt{#1}}\\\\}
\newcommand{\responsetitle}[1]{\textbf{Response: }{\texttt{#1}}\\\\}
\newcommand{\tagtitle}[1]{\textbf{Tag: }{\texttt{#1}}\\\\}
\newcommand{\MRML}{\textrm{MRML}}
\newcommand{\tag}[1]{\texttt{#1}}
\begin{document}
',
'\end{document}
'
);
}else{
print $lOH $lDTDToTeX->processDTD($lFH,"<$inTag></$inTag>");
}
}
|