def LDIF.parse_file( file, sort=false )
File.open( file ) do |f|
entries = []
entry = false
header = true
version = false
while line = f.gets
if line =~ /^dn:/
header = false
if entry && ! version
if block_given?
yield parse_entry( entry )
else
entries << parse_entry( entry )
end
end
if version
entry << line
version = false
else
entry = [ line ]
end
next
end
if header && line.downcase =~ /^version/
entry = [ line ]
version = true
next
end
entry << line
end
if block_given?
yield parse_entry( entry )
nil
else
entries << parse_entry( entry )
entries.sort! { |x,y| x.dn.length <=> y.dn.length } if sort
entries
end
end
end