gwenhywfar  5.3.0
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 {
31  int rv;
32  GWEN_PARSER_ELEMENT *eChild;
33  const char *s;
34  const char *groupName;
35 
36  groupName=GWEN_ParserElement_GetDbName(eData);
37  if (groupName) {
38  s=GWEN_ParserElement_GetData(eData);
39  if (s && *s)
40  GWEN_DB_SetCharValue(dbParent, GWEN_DB_FLAGS_DEFAULT, groupName, s);
41  }
42 
43  /* check children */
44  eChild=GWEN_ParserElement_Tree_GetFirstChild(eData);
45  if (eChild) {
46  GWEN_DB_NODE *dbThis=NULL;
47 
48  if (groupName && *groupName)
49  dbThis=GWEN_DB_GetGroup(dbParent, GWEN_DB_FLAGS_DEFAULT, groupName);
50  while (eChild) {
51  rv=GWEN_Parser__toDbElementAndChildren(eChild, dbThis?dbThis:dbParent, depth+1);
52  if (rv<0) {
53  DBG_INFO(GWEN_LOGDOMAIN, "here (%d) [%d]", rv, depth);
54  return rv;
55  }
56 
57  GWEN_ParserElement_Tree_GetNext(eChild);
58  }
59  }
60 
61  return 0;
62 }
63 
64 
65 
66 int GWEN_Parser_ToDbTree(GWEN_PARSER_ELEMENT_TREE *tData, GWEN_DB_NODE *db)
67 {
68  GWEN_PARSER_ELEMENT *e;
69 
70  e=GWEN_ParserElement_Tree_GetFirst(tData);
71  while (e) {
72  int rv;
73 
75  if (rv<0) {
76  DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
77  return rv;
78  }
79  e=GWEN_ParserElement_Tree_GetNext(e);
80  }
81 
82  return 0;
83 }
84 
85 
86 
87 
88 
89 
struct GWEN_DB_NODE GWEN_DB_NODE
Definition: db.h:228
#define NULL
Definition: binreloc.c:300
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:1379
int GWEN_DB_SetCharValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, const char *val)
Definition: db.c:995
#define DBG_INFO(dbg_logger, format, args...)
Definition: debug.h:178
#define GWEN_DB_FLAGS_DEFAULT
Definition: db.h:168