xref: /netbsd-src/external/bsd/openldap/dist/libraries/liblber/idtest.c (revision c2f76ff004a2cb67efe5b12d97bd3ef7fe89e18d)
1 /*	$NetBSD: idtest.c,v 1.1.1.3 2010/12/12 15:21:28 adam Exp $	*/
2 
3 /* idtest.c - ber decoding test program using isode libraries */
4 /* OpenLDAP: pkg/ldap/libraries/liblber/idtest.c,v 1.18.2.5 2010/04/13 20:22:54 kurt Exp */
5 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
6  *
7  * Copyright 1998-2010 The OpenLDAP Foundation.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted only as authorized by the OpenLDAP
12  * Public License.
13  *
14  * A copy of this license is available in the file LICENSE in the
15  * top-level directory of the distribution or, alternatively, at
16  * <http://www.OpenLDAP.org/license.html>.
17  */
18 /* Portions Copyright (c) 1990 Regents of the University of Michigan.
19  * All rights reserved.
20  *
21  * Redistribution and use in source and binary forms are permitted
22  * provided that this notice is preserved and that due credit is given
23  * to the University of Michigan at Ann Arbor. The name of the University
24  * may not be used to endorse or promote products derived from this
25  * software without specific prior written permission. This software
26  * is provided ``as is'' without express or implied warranty.
27  */
28 /* ACKNOWLEDGEMENTS:
29  * This work was originally developed by the University of Michigan
30  * (as part of U-MICH LDAP).
31  */
32 
33 #include "portable.h"
34 
35 #include <stdio.h>
36 
37 #include <ac/stdlib.h>
38 
39 #ifdef HAVE_PSAP_H
40 #include <psap.h>
41 #include <quipu/attr.h>
42 #endif
43 
44 int
45 main( int argc, char **argv )
46 {
47 #ifdef HAVE_PSAP_H
48 	PE	pe;
49 	PS	psin, psout, pserr;
50 
51 	/* read the pe from standard in */
52 	if ( (psin = ps_alloc( std_open )) == NULLPS ) {
53 		perror( "ps_alloc" );
54 		exit( EXIT_FAILURE );
55 	}
56 	if ( std_setup( psin, stdin ) == NOTOK ) {
57 		perror( "std_setup" );
58 		exit( EXIT_FAILURE );
59 	}
60 	/* write the pe to standard out */
61 	if ( (psout = ps_alloc( std_open )) == NULLPS ) {
62 		perror( "ps_alloc" );
63 		exit( EXIT_FAILURE );
64 	}
65 	if ( std_setup( psout, stdout ) == NOTOK ) {
66 		perror( "std_setup" );
67 		exit( EXIT_FAILURE );
68 	}
69 	/* pretty print it to standard error */
70 	if ( (pserr = ps_alloc( std_open )) == NULLPS ) {
71 		perror( "ps_alloc" );
72 		exit( EXIT_FAILURE );
73 	}
74 	if ( std_setup( pserr, stderr ) == NOTOK ) {
75 		perror( "std_setup" );
76 		exit( EXIT_FAILURE );
77 	}
78 
79 	while ( (pe = ps2pe( psin )) != NULLPE ) {
80 		pe2pl( pserr, pe );
81 		pe2ps( psout, pe );
82 	}
83 
84 	exit( EXIT_SUCCESS );
85 #else
86 	fprintf(stderr, "requires ISODE X.500 distribution.\n");
87 	return( EXIT_FAILURE );
88 #endif
89 }
90