8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libldap5 / sources / ldap / common / friendly.c
blob79d602160db6995ea8715f890b45f7a96bddb6c1
1 /*
2 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
4 */
5 #pragma ident "%Z%%M% %I% %E% SMI"
7 /*
8 * The contents of this file are subject to the Netscape Public
9 * License Version 1.1 (the "License"); you may not use this file
10 * except in compliance with the License. You may obtain a copy of
11 * the License at http://www.mozilla.org/NPL/
13 * Software distributed under the License is distributed on an "AS
14 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
15 * implied. See the License for the specific language governing
16 * rights and limitations under the License.
18 * The Original Code is Mozilla Communicator client code, released
19 * March 31, 1998.
21 * The Initial Developer of the Original Code is Netscape
22 * Communications Corporation. Portions created by Netscape are
23 * Copyright (C) 1998-1999 Netscape Communications Corporation. All
24 * Rights Reserved.
26 * Contributor(s):
29 * Copyright (c) 1990 Regents of the University of Michigan.
30 * All rights reserved.
33 * friendly.c
36 #if 0
37 #ifndef lint
38 static char copyright[] = "@(#) Copyright (c) 1993 Regents of the University of Michigan.\nAll rights reserved.\n";
39 #endif
40 #endif
42 #include "ldap-int.h"
44 char *
45 LDAP_CALL
46 ldap_friendly_name( char *filename, char *name, FriendlyMap *map )
48 int i, entries;
49 FILE *fp;
50 char *s;
51 char buf[BUFSIZ];
53 if ( map == NULL ) {
54 return( name );
56 if ( NULL == name)
58 return (name);
61 if ( *map == NULL ) {
62 if ( (fp = fopen( filename, "rF" )) == NULL )
63 return( name );
65 entries = 0;
66 while ( fgets( buf, sizeof(buf), fp ) != NULL ) {
67 if ( buf[0] != '#' )
68 entries++;
70 rewind( fp );
72 if ( (*map = (FriendlyMap)NSLDAPI_MALLOC( (entries + 1) *
73 sizeof(struct friendly) )) == NULL ) {
74 fclose( fp );
75 return( name );
78 i = 0;
79 while ( fgets( buf, sizeof(buf), fp ) != NULL && i < entries ) {
80 if ( buf[0] == '#' )
81 continue;
83 if ( (s = strchr( buf, '\n' )) != NULL )
84 *s = '\0';
86 if ( (s = strchr( buf, '\t' )) == NULL )
87 continue;
88 *s++ = '\0';
90 if ( *s == '"' ) {
91 int esc = 0, found = 0;
93 for ( ++s; *s && !found; s++ ) {
94 switch ( *s ) {
95 case '\\':
96 esc = 1;
97 break;
98 case '"':
99 if ( !esc )
100 found = 1;
101 /* FALL */
102 default:
103 esc = 0;
104 break;
109 (*map)[i].f_unfriendly = nsldapi_strdup( buf );
110 (*map)[i].f_friendly = nsldapi_strdup( s );
111 i++;
114 fclose( fp );
115 (*map)[i].f_unfriendly = NULL;
118 for ( i = 0; (*map)[i].f_unfriendly != NULL; i++ ) {
119 if ( strcasecmp( name, (*map)[i].f_unfriendly ) == 0 )
120 return( (*map)[i].f_friendly );
122 return( name );
126 void
127 LDAP_CALL
128 ldap_free_friendlymap( FriendlyMap *map )
130 struct friendly* pF;
132 if ( map == NULL || *map == NULL ) {
133 return;
136 for ( pF = *map; pF->f_unfriendly; pF++ ) {
137 NSLDAPI_FREE( pF->f_unfriendly );
138 NSLDAPI_FREE( pF->f_friendly );
140 NSLDAPI_FREE( *map );
141 *map = NULL;