From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dave Wysochanski Date: Tue, 17 Apr 2007 13:24:43 -0400 Subject: [PATCH 2/2] add lib/config support functions Message-ID: <1176830683.4070.21.camel@linux-cxyg> List-Id: To: lvm-devel@redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Add support functions for analysis of config sections, and hence, on-disk LVM2 metadata. Should not change functional behavior. Index: LVM2/lib/config/config.c =================================================================== --- LVM2.orig/lib/config/config.c 2007-04-17 13:11:08.000000000 -0400 +++ LVM2/lib/config/config.c 2007-04-17 13:16:25.000000000 -0400 @@ -26,6 +26,9 @@ #include #include +#define TOK_SECTION_B_CHAR '{' +#define TOK_SECTION_E_CHAR '}' + enum { TOK_INT, TOK_FLOAT, @@ -474,7 +477,7 @@ static struct config_node *_file(struct static struct config_node *_section(struct parser *p) { - /* IDENTIFIER '{' VALUE* '}' */ + /* IDENTIFIER TOK_SECTION_B_CHAR VALUE* TOK_SECTION_E_CHAR */ struct config_node *root, *n, *l = NULL; if (!(root = _create_node(p))) { stack; @@ -623,12 +626,12 @@ static void _get_token(struct parser *p, p->t = TOK_INT; /* fudge so the fall through for floats works */ switch (*p->te) { - case '{': + case TOK_SECTION_B_CHAR: p->t = TOK_SECTION_B; p->te++; break; - case '}': + case TOK_SECTION_E_CHAR: p->t = TOK_SECTION_E; p->te++; break; @@ -708,8 +711,9 @@ static void _get_token(struct parser *p, default: p->t = TOK_IDENTIFIER; while ((p->te != p->fe) && (*p->te) && !isspace(*p->te) && - (*p->te != '#') && (*p->te != '=') && (*p->te != '{') && - (*p->te != '}')) + (*p->te != '#') && (*p->te != '=') && + (*p->te != TOK_SECTION_B_CHAR) && + (*p->te != TOK_SECTION_E_CHAR)) p->te++; break; } @@ -1146,3 +1150,61 @@ int merge_config_tree(struct cmd_context return 1; } + +/* + * Convert a token type to the char it represents. + */ +static char _token_type_to_char(int type) +{ + switch (type) { + case TOK_SECTION_B: + return TOK_SECTION_B_CHAR; + case TOK_SECTION_E: + return TOK_SECTION_E_CHAR; + default: + return 0; + } +} + +/* + * Returns: + * # of 'type' tokens in 'str'. + */ +static unsigned _count_tokens (char *str, unsigned len, int type) +{ + unsigned i; + unsigned count=0; + char c; + + c = _token_type_to_char(type); + + for (i=0; i