{-------------------------------------------------------------}
{              Cartavox - produz lista de cartas
{-------------------------------------------------------------}

unit carList;

interface

uses winProcs, winDos, winTypes,
     dvcrt, strings, dvWin,
     carVars, carMsg;

procedure montaListaDeCartas (extensao: string);

implementation

{--------------------------------------------------------}
{              monta lista de cartas
{--------------------------------------------------------}

procedure montaListaDeCartas (extensao: string);
var
    DirInfo: TSearchRec;
    i, j: integer;
    temp: pregCarta;
    ext: array [0..10] of char;

begin
    numRegs := 0;
    mensagem ('CTORDLIS', 1);  {'Ordenando a lista de cartas pela data...'}

    strPcopy (ext, '*.'+extensao);
    FindFirst (ext, FaArchive, DirInfo);
    while (DosError = 0) and (numRegs < maxCartas) do
            begin
                numRegs := numregs + 1;
                new (regLido [numRegs]);
                with regLido [numRegs]^ do
                    begin
                        nomArqCarta := strPas (dirInfo.name);
                        while (nomArqCarta <> '') and
                              (nomArqCarta [length (nomArqCarta)] = ' ') do
                                   delete (nomArqCarta, length (nomArqCarta), 1);
                        dataHora := dirInfo.Time;
                        FindNext (DirInfo);
                    end;
            end;

    for i := 1 to numRegs-1 do
        for j := i+1 to numRegs do
            begin
                if regLido[i]^.dataHora > regLido[j]^.dataHora then
                    begin
                        temp := reglido[i];
                        reglido[i] := reglido[j];
                        reglido[j] := temp;
                    end;
            end;

    if numRegs <> 0 then
        mensagem ('CTOKORD', 1);  {'Ok, cartas ordenadas.'}
end;

end.