head	1.1;
access;
symbols
	tcllib-1-13:1.1
	tcllib-1-12:1.1
	tklib-0-5:1.1
	tcllib-1-11-1:1.1
	tcllib-1-11:1.1
	tcllib-1-10:1.1
	tcllib-1-9:1.1;
locks; strict;
comment	@# @;


1.1
date	2006.09.19.22.48.06;	author mic42;	state Exp;
branches;
next	;


desc
@@


1.1
log
@New example: ldifdump

Takes a list of ldif files and dumps the contents to stdout, sorted by
dn an demonstrates how to use the basic ldapx::ldif feature for reading an
ldif file (e.g. Mozilla Thunderbird addressbook export).
@
text
@#!/usr/bin/env tclsh
########################################################################
#
# Load and print an ldif file
#
########################################################################

package require ldapx

if {![llength $argv]} {
    puts stderr "Usage: [info script] file ?file ... file?"
    exit 1
}
set entries [list]

proc loadLDIF {fd} {
    global entries
    
    ldapx::ldif ld
    ld channel $fd
    
    set e [ldapx::entry %AUTO%]
    while {[ld read $e]} {
       lappend entries $e
       set e [ldapx::entry %AUTO%]
    }
    $e destroy
    
}

proc displayLDIF {} {
    global entries
    set sort [list]
    foreach e $entries {
        lappend sort [list [$e dn] $e]
    }
    set sort [lsort -index 0 $sort]
    foreach key $sort {
        set e [lindex $key 1]
        puts "[$e print] \n"
    }
    
}

foreach file $argv {
    set fd [open $file]
    loadLDIF $fd
    close $fd
}
displayLDIF
exit
@
