2 * (c) Copyright 1992 by Panagiotis Tsirigotis
3 * (c) Sections Copyright 1998-2001 by Rob Braun
4 * All rights reserved. The file named COPYRIGHT specifies the terms
5 * and conditions for redistribution.
23 * next_line returns the next line of the file or NULL if the end of file
25 * Comment lines and empty lines are skipped.
27 char *next_line( int fd )
32 char *line = Srdline( fd ) ;
39 for ( p = line ;; p++ )
40 if ( *p == NUL || *p == COMMENT_BEGIN )
41 break ; /* skip this line */
42 else if ( isspace( *p ) )
43 continue ; /* skip white space */
53 * name [SPACE] OP [SPACE] value [SPACE] value ...
55 * Recognize the attribute name and operator and place them in *attrp, *opp
57 * Currently, we allow any non-space character to be used in the
60 * Return value: a pointer to the character after OP.
62 static char *get_attr_op( char *line, char **attrp, enum assign_op *opp )
67 const char *func = "get_attr_op" ;
70 * First get the attribute name
72 for ( p = line ; isspace( *p ) ; p++ ) ; /* skip spaces */
75 parsemsg( LOG_ERR, func, "Empty line" ) ;
80 for ( ; ! isspace( *p ) && (*p != '='); p++ ) ; /* skip attribute name */
83 parsemsg( LOG_ERR, func, "Nothing after attribute: %s", attr ) ;
87 *p = NUL ; /* now attribute name is NUL terminated */
88 parsemsg( LOG_ERR, func, "Attribute %s needs a space before operator", attr);
91 *p++ = NUL ; /* now attribute name is NUL terminated */
93 while ( isspace( *p ) ) p++ ; /* skip spaces */
98 parsemsg( LOG_ERR, func, "Nothing after attribute: %s", attr ) ;
107 op = ( *p++ == '+' ) ? PLUS_EQ : MINUS_EQ ;
111 /* FALL THROUGH if there is no '=' after the '+' or '-' */
114 parsemsg( LOG_ERR, func, "Bad operator for attribute: %s", attr ) ;
119 return( ++p ) ; /* skip the '=' */
124 * Parse a line of the form:
125 * name OP value value value ...
126 * where each value is a string and OP can be '=', '+=', '-='
128 * NOTE: We do not allocate space for the name and values. Instead we keep
129 * pointers to the line.
131 status_e parse_line( char *line,
137 char *values_string ;
140 const char *func = "parse_line" ;
142 if ( ( values_string = get_attr_op( line, &attribute, opp ) ) == NULL )
146 * Now grab the values
148 strp = str_parse( values_string, " \t", STR_RETURN_ERROR, (int *)0 ) ;
151 parsemsg( LOG_CRIT, func, ES_NOMEM ) ;
155 while ( (value = str_component( strp )) )
157 if ( pset_add( values, value ) == NULL )
159 parsemsg( LOG_CRIT, func, ES_NOMEM ) ;
160 str_endparse( strp ) ;
165 str_endparse( strp ) ;
171 void skip_entry( int fd )
175 char *line = next_line( fd ) ;
177 if ( line == NULL ) /* reached EOF ? */
179 parsemsg( LOG_WARNING, "skip_entry",
180 "missing %c in last service entry", ENTRY_END ) ;
184 if ( line_has_only_1_char( line, ENTRY_END ) )
192 * Returns TRUE if the given line contains a single instance of the
193 * specified character and no other non-space characters
195 int line_has_only_1_char( const char *line, char ch )
198 char target_char = ch ;
200 for ( p = line ; *p ; p++ )
201 if ( *p == target_char )
203 else if ( ! isspace( *p ) )
205 return( target_char != ch ) ;