Created
November 26, 2009 02:12
-
-
Save gsomoza/243183 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{$R+} | |
{$mode TP} { Modo de compatibilidad con Turbo Pascal 7 } | |
{$PACKRECORDS 1} | |
program fileAccess; | |
const | |
BUENOS_AIRES = 'BSAS.DAT'; | |
ARCHIVO_INFO = 'INFO.TMP'; | |
ASC_A = 65; | |
ASC_R = 82; | |
type | |
str3 = string[3]; | |
str4 = string[4]; | |
str5 = string[5]; | |
str10 = string[10]; | |
RegFecha = record | |
dd, | |
mm:byte; | |
aaaa:word | |
end; | |
RegZona = record | |
NroPat : str4; | |
NroRegCon : longint; | |
rFecInf : RegFecha; | |
CodDestPol: word; | |
CodInfr: word; | |
NroIdPol : str5 | |
end; | |
ArchivoZona = file of RegZona; | |
{Tengo 2 cosas: | |
RegAux para un archivo y un array de tamaño estático. | |
tLista para guardar listas dinámicas | |
} | |
tLista = ^tNodo; | |
RegAux = record | |
cantInf:byte; | |
pPrimero:tLista; | |
pUltimo:tLista | |
end; | |
ArchivoAux = file of RegAux; | |
VectorAux = array[5000..10999] of RegAux; | |
tInfo = longint; | |
tNodo = record | |
info:tInfo; | |
sgte:tLista | |
end; | |
procedure AbrirArchivos(var ArchBsAs:ArchivoZona; | |
var ArchInfo:ArchivoAux); | |
begin | |
{assign(output, 'listarBsAs.txt'); | |
rewrite(output);} | |
assign(ArchBsAs, BUENOS_AIRES); | |
assign(ArchInfo, ARCHIVO_INFO); | |
fileMode:=0; | |
reset(ArchBsAs); | |
rewrite(ArchInfo) | |
end; | |
procedure CerrarArchivos(var ArchBsAs:ArchivoZona; | |
var ArchInfo:ArchivoAux); | |
begin | |
Close(ArchBsAs); | |
Close(ArchInfo); | |
end; | |
function patenteADireccion(patente:string):longint; | |
var | |
hiVal, | |
lowVal, | |
ret, | |
errCode:integer; | |
tmp:string; | |
begin | |
tmp := Copy(patente, Length(patente) - 2, 3); | |
Val(tmp, lowVal, errCode); | |
if Ord(patente[1]) >= ASC_R then | |
hiVal := Ord(patente[1]) - ASC_R + 5 | |
else | |
hiVal := Ord(patente[1]) - ASC_A; | |
hiVal := hiVal * 1000; | |
ret := hiVal + lowVal; | |
patenteADireccion := ret | |
end; | |
procedure CrearCascaronInfo(var ArchInfo:ArchivoAux); | |
var | |
rAux:RegAux; | |
i:integer; | |
begin | |
rAux.cantInf := 0; | |
rAux.pPrimero := nil; | |
rAux.pUltimo := nil; | |
for i := 0 to 4999 do | |
write(ArchInfo, rAux) | |
end; | |
procedure GuardarEnDisco(var ArchInfo:ArchivoAux; | |
rBsAs:RegZona); | |
var | |
rAux:RegAux; | |
begin | |
seek(ArchInfo, patenteADireccion(rBsAs.NroPat)); | |
read(ArchInfo, rAux); | |
rAux.cantInf := rAux.cantInf + 1; | |
end; | |
procedure CrearListas(var ArchBsAs:ArchivoZona; | |
var ArchInfo:ArchivoAux); | |
var | |
rBsAs:RegZona; | |
begin | |
writeln('** Comenzando a procesar patentes'); | |
while not eof(ArchBsAs) do begin | |
read(ArchBsAs, rBsAs); | |
writeln('Procesando patente: ', rBsAs.NroPat); | |
if patenteADireccion(rBsAs.NroPat) < 5000 then | |
GuardarEnDisco(ArchInfo, rBsAs) | |
else | |
{Meterlo en Memoria} | |
end; | |
writeln('** Patentes procesadas'); | |
end; | |
{ MAIN } | |
var | |
ArchBsAs:ArchivoZona; | |
ArchInfo:ArchivoAux; | |
begin | |
AbrirArchivos(ArchBsAs, ArchInfo); | |
CrearCascaronInfo(ArchInfo); | |
CrearListas(ArchBsAs, ArchInfo); | |
CerrarArchivos(ArchBsAs, ArchInfo) | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment