1 #pragma ident "%Z%%M% %I% %E% SMI"
5 * The contents of this file are subject to the Netscape Public
6 * License Version 1.1 (the "License"); you may not use this file
7 * except in compliance with the License. You may obtain a copy of
8 * the License at http://www.mozilla.org/NPL/
10 * Software distributed under the License is distributed on an "AS
11 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 * implied. See the License for the specific language governing
13 * rights and limitations under the License.
15 * The Original Code is Mozilla Communicator client code, released
18 * The Initial Developer of the Original Code is Netscape
19 * Communications Corporation. Portions created by Netscape are
20 * Copyright (C) 1998-1999 Netscape Communications Corporation. All
26 * Copyright (c) 1993, 1994 Regents of the University of Michigan.
27 * All rights reserved.
29 * Redistribution and use in source and binary forms are permitted
30 * provided that this notice is preserved and that due credit is given
31 * to the University of Michigan at Ann Arbor. The name of the University
32 * may not be used to endorse or promote products derived from this
33 * software without specific prior written permission. This software
34 * is provided ``as is'' without express or implied warranty.
37 * dsparse.c: parsing routines used by display template and search
38 * preference file library routines for LDAP clients.
44 static int next_line( char **bufp
, long *blenp
, char **linep
);
45 static char *next_token( char ** sp
);
48 ldap_next_line_tokens( char **bufp
, long *blenp
, char ***toksp
)
50 char *p
, *line
, *token
, **toks
;
55 if (( rc
= next_line( bufp
, blenp
, &line
)) <= 0 ) {
59 if (( toks
= (char **)NSLDAPI_CALLOC( 1, sizeof( char * ))) == NULL
) {
66 while (( token
= next_token( &p
)) != NULL
) {
67 if (( toks
= (char **)NSLDAPI_REALLOC( toks
, ( tokcnt
+ 2 ) *
68 sizeof( char * ))) == NULL
) {
69 NSLDAPI_FREE( (char *)toks
);
73 toks
[ tokcnt
] = token
;
74 toks
[ ++tokcnt
] = NULL
;
77 if ( tokcnt
== 1 && strcasecmp( toks
[ 0 ], "END" ) == 0 ) {
79 ldap_free_strarray( toks
);
87 NSLDAPI_FREE( (char *)toks
);
98 next_line( char **bufp
, long *blenp
, char **linep
)
100 char *linestart
, *line
, *p
;
108 for ( linestart
= p
; plen
> 0; ++p
, --plen
) {
110 if ( plen
> 1 && *(p
+1) == '\n' ) {
118 if ( plen
> 1 && *(p
+1) == '\r' ) {
127 } while ( plen
> 0 && ( *linestart
== '#' || linestart
+ 1 == p
));
136 return( 0 ); /* end of file */
139 if (( line
= NSLDAPI_MALLOC( p
- linestart
)) == NULL
) {
141 return( -1 ); /* fatal error */
144 SAFEMEMCPY( line
, linestart
, p
- linestart
);
145 line
[ p
- linestart
- 1 ] = '\0';
147 return( strlen( line
));
152 next_token( char **sp
)
155 char *p
, *tokstart
, *t
;
157 if ( **sp
== '\0' ) {
163 while ( ldap_utf8isspace( p
)) { /* skip leading white space */
178 if ( *p
== '\0' || ( ldap_utf8isspace( p
) && !in_quote
)) {
182 *t
++ = '\0'; /* end of token */
187 in_quote
= !in_quote
;
196 if ( t
== tokstart
) {
200 return( nsldapi_strdup( tokstart
));
205 ldap_free_strarray( char **sap
)
210 for ( i
= 0; sap
[ i
] != NULL
; ++i
) {
211 NSLDAPI_FREE( sap
[ i
] );
213 NSLDAPI_FREE( (char *)sap
);