Obtiene informacion de un archivo

pascal:
// $Id: htdump.pp,v 1.4 2005/02/14 17:13:18 peter Exp $

{
  This program takes an W3 IDL XML file with interface definitions and
  dumps a interface definition.
}


{$MODE objfpc}
{$H+}

program htdump;

uses sysutils, DOM, xmlread;

Var DoImplementation : Boolean;

procedure DumpNode(node: TDOMNode; spc: String);forward;

procedure DumpMethodNode(node: TDOMElement; spc: String);

var N,NN : TDOMNode;
    rettype : DOMString;
    firstparam : boolean;
    i : longint;

begin

   N:=Node.FindNode('returns');
   If N<>Nil then
      rettype:=TDomElement(N).GetAttribute('type');
   If Not DoImplementation then
     Write (spc);
   If RetType='void' then
     Write ('Procedure ')
   else
     Write ('Function ');
   If DoImplementation then
     Write(TDomElement(Node.ParentNode).GetAttribute('name'),'.');
   Write (Node.GetAttribute('name'));
   N:=Node.FindNode('params');
   If N<>Nil then
     begin
     FirstParam:=True;
     for I:=1 to N.ChildNodes.Count-1 do
       begin
       NN:=N.ChildNodes.Item[i];
       If NN.NodeName<>'param' then
         begin
         If Firstparam then
           begin
           Write('(');
           FirstParam:=False
           end
         else
           Write(';');
         writeln (spc,NN.NodeName,' : ',TDOMElement(NN).GetAttribute('type'));
         end;
       end;
     If Not FirstParam then
     Write (')');
     end;
   If RetType <>'void' then
     Write (' : ',Rettype);
   Writeln(';');
   If DoImplementation then
     begin
     Writeln;
     Writeln('Begin');
     Writeln('End;');
     Writeln;
     Writeln;
     end;
end;

procedure DumpAttributeNode(Doprivate: Boolean;node: TDOMElement; spc: String);

Var PropName : DOMString;

begin
  PropName:=Node.GetAttribute('name');
  If DOPrivate then
    Write (spc,'F')
  else
    Write (spc,'Property ');
  Write (PropName,' : ',Node.getAttribute('type'));
  If Not DoPrivate then
    begin
    Write (' Read F',PropName);
    If not(Node.getAttribute('readonly')='yes') then
      Write (' Write F',PropName)
    end;
  Writeln(';');
end;

Procedure DumpInterfaceNode (node : TDomElement; spc : String);

Var N : TDOMNode;
    C : TDOMNodeList;
    I : longint;

begin
  If not DoImplementation then
    begin
    Write(spc,Node.GetAttribute('name'),' = Class');
    N:=Node.Attributes.GetNamedItem('inherits');
    If N<>Nil then
      Write('(',N.NodeValue,')');
    Writeln;
    // Dump Property fields
    Writeln (Spc+'  Private');
    N:=Node.FirstChild;
    While N<>Nil do
      begin
      If N.NodeName='attribute' then
          DumpAttributeNode(True,TDOMElement(N), spc + '    ');
      N:=N.NextSibling;
      end;
    Writeln (Spc,'  Public');
    end;
  N:=Node.FirstChild;
  While N<>Nil do
    begin
    If N.NodeName='method' then
       DumpMethodNode(TDomElement(N), spc + '    ');
    N:=N.NextSibling;
    end;
  If Not DoImplementation then
    begin
    N:=Node.FirstChild;
    While N<>Nil do
      begin
      If N.NodeName='attribute' then
         DumpAttributeNode(False,TDomElement(N), spc + '    ');
      N:=N.NextSibling;
      end;
    writeln (spc,'End;')
    end;
end;

procedure DumpNode(node: TDOMNode; spc: String);

var
  i: Integer;
  attr: TDOMNode;
begin
  If Node.NodeName='interface' then
    DumpInterfaceNode(TDOMElement(Node),Spc)
  else if Node.NodeName='method' then
    DumpMethodNode(TDOMELEMENt(Node),Spc)
  else if Node.NodeName='attribute' then
    DumpAttributeNode(True,TDomelement(node),spc)
  else
    if node.FirstChild <> nil then
      DumpNode(node.FirstChild, spc + '  ');
  if node.NextSibling <> nil then
    DumpNode(node.NextSibling, spc);
end;

var
  i : longint;
  xml: TXMLDocument;

begin
  if (ParamCount <1) or (paramcount>2) then begin
    WriteLn('htdump -m <xml>');
    exit;
  end;
  I:=1;
  If paramstr(1)='-m' then
    begin
    I:=2;
    DoImplementation:=True;
    end;
  ReadXMLFile(xml, ParamStr(i));
  WriteLn ('// Created From file ',paramstr(I));
  DumpNode(xml, '');
end.


{
  $Log: htdump.pp,v $
  Revision 1.4  2005/02/14 17:13:18  peter
    * truncate log

}

 
¿Ya le viste algún error? Dejanos tu correción ;-)

Antes de comentar: Gran parte de los ejercicios propuestos no tienen librerías debido a que Wordpress elimina los tags HTML. Si sabes/tienes/conoces las librerías que hacen falta, déjalo en los comentarios.

Otro punto antes de comentar, Si vas a sugerir un segmento de código en algún lenguaje debes hacerlo así:

De esta manera el código sale coloreado.

Otro punto importante para muchos que sienten que se les ignora: Todos los comentarios los reviso y en su debido momento los apruebo, pero ojo con el último párrafo.

Para poner los símbolos de las librerías sin que desaparezcan, debes escribir los símbolos de mayor > y menor qué < con su entidad HTML correspondiente, así como el símbolo de &

Mis Algoritmos se reserva el derecho de alterar, publicar o no los comentarios así como cambiar estas reglas de uso.

Si estas de acuerdo, adelante puedes comentar :)

P.D. No le hago tareas a nadie, mejor hagan la mía :P