VPR-7.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
read_settings.c
Go to the documentation of this file.
1 #include <string.h>
2 #include <assert.h>
3 #include "read_xml_util.h"
4 #include "read_settings.h"
5 
6 static int process_settings(ezxml_t Cur, char ** outv)
7 {
8  int count = 0;
9 
10  if (!Cur)
11  return(0);
12 
13  while (Cur->attr[count])
14  {
15  if (outv)
16  {
17  if (! (count % 2))
18  {
19  outv[count] = (char *)my_malloc(strlen(Cur->attr[count]) + 3);
20  strcpy(&outv[count][2], Cur->attr[count]);
21  outv[count][0] = outv[count][1] = '-';
22  }
23  else
24  outv[count] = Cur->attr[count];
25  }
26  count++;
27  }
28 
29  Cur = Cur->child;
30 
31  while (Cur)
32  {
33  if (outv)
34  {
35  outv[count] = (char *)my_malloc(strlen(Cur->name) + 3);
36  strcpy(&outv[count][2], Cur->name);
37  outv[count][0] = outv[count][1] = '-';
38  }
39  count++;
40 
41  if (strlen(Cur->txt))
42  {
43  if (outv) outv[count] = Cur->txt;
44  count++;
45  }
46 
47  Cur = Cur->ordered;
48  }
49 
50  return count;
51 }
52 
53 int read_settings_file(char * file_name, char *** outv)
54 {
55  ezxml_t Cur;
56  int count;
57 
58  Cur = ezxml_parse_file(file_name);
59  assert(*outv == NULL);
60  assert(! strcmp("settings",Cur->name));
61  Cur = FindElement(Cur, "arguments", FALSE);
62 
63  count = process_settings(Cur, *outv);
64 
65  /* prepend the settings file name */
66  count++;
67 
68  *outv = (char **)my_malloc(count * sizeof(char *));
69 
70  (*outv)[0] = my_strdup(file_name);
71 
72  if (count)
73  {
74  process_settings(Cur, &((*outv)[1]));
75  }
76 
77  return(count);
78 }
Definition: ezxml.h:44
char * txt
Definition: ezxml.h:47
Definition: util.h:12
static void * my_malloc(int ibytes)
Definition: graphics.c:499
ezxml_t FindElement(INP ezxml_t Parent, INP const char *Name, INP boolean Required)
Definition: read_xml_util.c:11
static int process_settings(ezxml_t Cur, char **outv)
Definition: read_settings.c:6
ezxml_t ordered
Definition: ezxml.h:51
char * name
Definition: ezxml.h:45
ezxml_t ezxml_parse_file(const char *file)
Definition: ezxml.c:846
char ** attr
Definition: ezxml.h:46
int read_settings_file(char *file_name, char ***outv)
Definition: read_settings.c:53
char * my_strdup(const char *str)
Definition: util.c:101
ezxml_t child
Definition: ezxml.h:52