gwenhywfar  4.99.8beta
gwen_parser_todb.c
Go to the documentation of this file.
1 /***************************************************************************
2  begin : Fri Jul 25 2014
3  copyright : (C) 2014 by Martin Preuss
4  email : martin@libchipcard.de
5 
6  ***************************************************************************
7  * *
8  * This library is free software; you can redistribute it and/or *
9  * modify it under the terms of the GNU Lesser General Public *
10  * License as published by the Free Software Foundation; either *
11  * version 2.1 of the License, or (at your option) any later version. *
12  * *
13  * This library is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16  * Lesser General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU Lesser General Public *
19  * License along with this library; if not, write to the Free Software *
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21  * MA 02111-1307 USA *
22  * *
23  ***************************************************************************/
24 
25 
26 
27 
28 
29 int GWEN_Parser__toDbElementAndChildren(GWEN_PARSER_ELEMENT *eData, GWEN_DB_NODE *dbParent, int depth) {
30  int rv;
31  GWEN_PARSER_ELEMENT *eChild;
32  const char *s;
33  const char *groupName;
34 
35  groupName=GWEN_ParserElement_GetDbName(eData);
36  if (groupName) {
37  s=GWEN_ParserElement_GetData(eData);
38  if (s && *s)
39  GWEN_DB_SetCharValue(dbParent, GWEN_DB_FLAGS_DEFAULT, groupName, s);
40  }
41 
42  /* check children */
43  eChild=GWEN_ParserElement_Tree_GetFirstChild(eData);
44  if (eChild) {
45  GWEN_DB_NODE *dbThis=NULL;
46 
47  if (groupName && *groupName)
48  dbThis=GWEN_DB_GetGroup(dbParent, GWEN_DB_FLAGS_DEFAULT, groupName);
49  while(eChild) {
50  rv=GWEN_Parser__toDbElementAndChildren(eChild, dbThis?dbThis:dbParent, depth+1);
51  if (rv<0) {
52  DBG_INFO(GWEN_LOGDOMAIN, "here (%d) [%d]", rv, depth);
53  return rv;
54  }
55 
56  GWEN_ParserElement_Tree_GetNext(eChild);
57  }
58  }
59 
60  return 0;
61 }
62 
63 
64 
65 int GWEN_Parser_ToDbTree(GWEN_PARSER_ELEMENT_TREE *tData, GWEN_DB_NODE *db) {
66  GWEN_PARSER_ELEMENT *e;
67 
68  e=GWEN_ParserElement_Tree_GetFirst(tData);
69  while(e) {
70  int rv;
71 
73  if (rv<0) {
74  DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
75  return rv;
76  }
77  e=GWEN_ParserElement_Tree_GetNext(e);
78  }
79 
80  return 0;
81 }
82 
83 
84 
85 
86 
87 
struct GWEN_DB_NODE GWEN_DB_NODE
Definition: db.h:228
#define NULL
Definition: binreloc.c:290
int GWEN_Parser_ToDbTree(GWEN_PARSER_ELEMENT_TREE *tData, GWEN_DB_NODE *db)
#define GWEN_LOGDOMAIN
Definition: logger.h:35
int GWEN_Parser__toDbElementAndChildren(GWEN_PARSER_ELEMENT *eData, GWEN_DB_NODE *dbParent, int depth)
GWEN_DB_NODE * GWEN_DB_GetGroup(GWEN_DB_NODE *n, uint32_t flags, const char *path)
Definition: db.c:1260
int GWEN_DB_SetCharValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, const char *val)
Definition: db.c:922
#define DBG_INFO(dbg_logger, format, args...)
Definition: debug.h:164
#define GWEN_DB_FLAGS_DEFAULT
Definition: db.h:168