dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libldap5 / sources / ldap / common / friendly.c
blobe6e2b2b097d8adc52d019c226bed4d430ef6cf44
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 static char copyright[] = "@(#) Copyright (c) 1993 Regents of the University of Michigan.\nAll rights reserved.\n";
38 #endif
40 #include "ldap-int.h"
42 char *
43 LDAP_CALL
44 ldap_friendly_name( char *filename, char *name, FriendlyMap *map )
46 int i, entries;
47 FILE *fp;
48 char *s;
49 char buf[BUFSIZ];
51 if ( map == NULL ) {
52 return( name );
54 if ( NULL == name)
56 return (name);
59 if ( *map == NULL ) {
60 if ( (fp = fopen( filename, "rF" )) == NULL )
61 return( name );
63 entries = 0;
64 while ( fgets( buf, sizeof(buf), fp ) != NULL ) {
65 if ( buf[0] != '#' )
66 entries++;
68 rewind( fp );
70 if ( (*map = (FriendlyMap)NSLDAPI_MALLOC( (entries + 1) *
71 sizeof(struct friendly) )) == NULL ) {
72 fclose( fp );
73 return( name );
76 i = 0;
77 while ( fgets( buf, sizeof(buf), fp ) != NULL && i < entries ) {
78 if ( buf[0] == '#' )
79 continue;
81 if ( (s = strchr( buf, '\n' )) != NULL )
82 *s = '\0';
84 if ( (s = strchr( buf, '\t' )) == NULL )
85 continue;
86 *s++ = '\0';
88 if ( *s == '"' ) {
89 int esc = 0, found = 0;
91 for ( ++s; *s && !found; s++ ) {
92 switch ( *s ) {
93 case '\\':
94 esc = 1;
95 break;
96 case '"':
97 if ( !esc )
98 found = 1;
99 /* FALL */
100 default:
101 esc = 0;
102 break;
107 (*map)[i].f_unfriendly = nsldapi_strdup( buf );
108 (*map)[i].f_friendly = nsldapi_strdup( s );
109 i++;
112 fclose( fp );
113 (*map)[i].f_unfriendly = NULL;
116 for ( i = 0; (*map)[i].f_unfriendly != NULL; i++ ) {
117 if ( strcasecmp( name, (*map)[i].f_unfriendly ) == 0 )
118 return( (*map)[i].f_friendly );
120 return( name );
124 void
125 LDAP_CALL
126 ldap_free_friendlymap( FriendlyMap *map )
128 struct friendly* pF;
130 if ( map == NULL || *map == NULL ) {
131 return;
134 for ( pF = *map; pF->f_unfriendly; pF++ ) {
135 NSLDAPI_FREE( pF->f_unfriendly );
136 NSLDAPI_FREE( pF->f_friendly );
138 NSLDAPI_FREE( *map );
139 *map = NULL;