1 /* Common code for file-based database parsers in nss_files module.
2 Copyright (C) 1996 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If
17 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
18 Cambridge, MA 02139, USA. */
26 #define CONCAT(a,b) CONCAT1(a,b)
27 #define CONCAT1(a,b) a##b
30 #define STRUCTURE ENTNAME
36 struct CONCAT(ENTNAME
,_data
) entdata
;
40 #define LINE_PARSER(BODY) \
42 parse_line (char *line, struct STRUCTURE *result, \
43 struct parser_data *data, int datalen) \
45 struct CONCAT(ENTNAME,_data) *const entdata __attribute__ ((unused)) \
48 TRAILING_LIST_PARSER; \
53 /* Comments can come mid-line; trim the line at the first # seen. */
54 #define MIDLINE_COMMENTS \
56 char *p = strchr (line, '#'); \
61 #define STRING_FIELD(variable, terminator_p, swallow) \
64 while (!terminator_p (*line)) \
65 if (*++line == '\0') \
70 while (swallow && terminator_p (*line)); \
73 #define INT_FIELD(variable, terminator_p, swallow, base, convert) \
76 variable = convert (strtol (line, &endp, base)); \
79 else if (terminator_p (*endp)) \
82 while (swallow && terminator_p (*endp)); \
83 else if (*endp != '\0') \
88 #define ISCOLON(c) ((c) == ':')
91 #ifndef TRAILING_LIST_MEMBER
92 #define TRAILING_LIST_PARSER /* Nothing to do. */
95 #define TRAILING_LIST_PARSER \
97 char **list = parse_list (line, data, datalen); \
99 result->TRAILING_LIST_MEMBER = list; \
104 static inline char **
105 parse_list (char *line
, struct parser_data
*data
, int datalen
)
107 char *eol
, **list
, **p
;
109 /* Find the end of the line buffer. */
110 eol
= strchr (line
, '\0');
111 /* Adjust the pointer so it is aligned for storing pointers. */
112 eol
+= (eol
- (char *) 0) % __alignof__ (char *);
113 /* We will start the storage here for the vector of pointers. */
114 list
= (char **) eol
;
121 if ((char *) &p
[1] - (char *) data
> datalen
)
123 /* We cannot fit another pointer in the buffer. */
133 if (TRAILING_LIST_SEPARATOR_P (*line
))
139 while (TRAILING_LIST_SEPARATOR_P (*line
));
141 else if (*line
== '\0' || *line
== '\n')
143 /* End of the line. */
159 #define LOOKUP_NAME(nameelt, aliaselt) \
162 if (! strcmp (name, result->nameelt)) \
164 for (ap = result->aliaselt; *ap; ++ap) \
165 if (! strcmp (name, *ap)) \