#! /usr/bin/perl # $Id: dict2docbook,v 1.1 2000/06/21 07:57:48 villate Exp $ # # dict2docbook - program to create an sgml version of the orca glossary, # conforming to the DocBook DTD. # Copyright (C) Jaime Villate , 2000 # # 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. # # Jaime Villate, Faculdade de Engenharia, Rua dos Bragas, 4050-123 Porto # Portugal # # The ORCA project =head1 NAME dict2docbook - Creates a SGML (DocBook) version of glosario.dict =head1 SYNOPSIS S =head1 DESCRIPTION This programs reads the glosario.dict text file and creates a SGML version of it, conforming to the DocBook DTD. =head1 AUTHOR Jaime Villate Evillate@fe.up.ptE. =cut use strict vars; use vars qw($info $short $url $author $version $first $letter); sub usage { print "Usage: dict2docbook \n"; exit; } my $keyw = ''; my $text = ''; my $word = ''; my $item = 0; usage() if ($#ARGV != 0); my $filehandle = $ARGV[0]; usage() if ($filehandle =~ /^\-/); (my $sgmlname = $filehandle) =~ s/\.dict/\.sgml/; open(DICT, "< $filehandle"); open(SGML,"> $sgmlname"); while () { if (/^([^0\#\s])/) { chop; $word = $_; $first = uc($1); if ($item == 0) { preamble(); $item = 1; $letter = $first; print SGML "\n$letter\n"; } else { print SGML "\n$keyw\n"; print SGML "\n\n$text\n\n"; print SGML "\n"; if ($first ne $letter) { $letter = $first; print SGML "\n\n"; print SGML "\n$letter\n"; } } $keyw = $word; $text = ''; } else { $text .= $_ if (/\S/); } if ($item == 0) { $author = $1, next if (/^\s*Autor:(.*)$/); $version = $1, next if (/^\s*(Versión.*)$/); } } close DICT; if($keyw =~ /^[^0\#]/) { print SGML "\n$keyw\n"; print SGML "\n\n$text\n\n"; print SGML "\n"; } print SGML "\n\n\nBibliografía"; print SGML "\n\n\n \n"; open (BIB, ') { if (/\S/) { $text = fmturl($_); if ($item == 0) { $item = 1; print SGML " \n\n\n \n"; } print SGML " $text"; } else { $item = 0; } } close BIB; print SGML " \n\n\n\n"; print SGML "\nColaboradores\n\n"; open (COL, ') { if (/\S/) { $text = fmturl($_); print SGML " \n $text\n \n"; } } close COL; print SGML "\n\n\n"; close SGML; exit; sub preamble { $author = fmturl($author); print SGML <<"EndPreamble"; $version ORCA - Glosario de Informática Inglés- Español Jaime Villate 2000 Jaime E. Villate. Este documento es libre. Puede copiarlo, distribuirlo y/o modificarlo bajo los términos de la Licencia GNU Para Documentación Libre, versión 1.1 o cualquier versión posterior publicada por la Free Software Foundation. Prefacio EndPreamble open (PRE, ') { if (/\S/) { $text = fmturl($_); print SGML $text; } else { print SGML "\n\n"; } } print SGML "\n"; close PRE; print SGML "\n"; } sub fmturl { (my $line) = @_; $line =~ s/[\<\(]?([\w\.]+\@[\w\.]+)[\>\)]?/$1<\/ulink>/g; $line =~ s/[\<\(]?(h?[tf]tp:\/\/[\w\/\.\~\%]+)[\>\)]?/$1<\/ulink>/g; return $line; }