FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
fossconfigTest.c
Go to the documentation of this file.
1 /* **************************************************************
2 Copyright (C) 2011 Hewlett-Packard Development Company, L.P.
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 version 2 as published by the Free Software Foundation.
7 
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 
13 You should have received a copy of the GNU General Public License along
14 with this program; if not, write to the Free Software Foundation, Inc.,
15 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 
17 ************************************************************** */
26 #include <libfossology.h>
27 #include <stdio.h>
28 #include <errno.h>
29 #include <glib.h>
30 
40 int main(int argc, char** argv)
41 {
42  GError* error = NULL;
43  char** groups;
44  char** keys;
45  gchar* temp;
46  int i, ngrps;
47  int j, nkeys;
48  int k, nlist;
49  fo_conf* config;
50  fo_conf* tmp;
51 
52  if(argc < 2)
53  {
54  fprintf(stderr, "Usage: %s ini1 ini2 ... iniN\n", argv[0]);
55  return 255;
56  }
57 
58  config = fo_config_load(argv[1], &error);
59 
60  if(error)
61  {
62  fprintf(stderr, "ERROR: %s\n", error->message);
63  return 254;
64  }
65 
66  for(i = 2; i < argc; i++)
67  {
68  tmp = fo_config_load(argv[i], &error);
69 
70  if(error)
71  {
72  fprintf(stderr, "ERROR: %s\n", error->message);
73  return 254;
74  }
75 
76  fo_config_join(config, tmp, &error);
77 
78  if(error)
79  {
80  fprintf(stderr, "ERROR: %s\n", error->message);
81  return 253;
82  }
83 
84  fo_config_free(tmp);
85  }
86 
87  groups = fo_config_group_set(config, &ngrps);
88  for(i = 0; i < ngrps; i++)
89  {
90  printf("[%s]\n", groups[i]);
91 
92  keys = fo_config_key_set(config, groups[i], &nkeys);
93  for(j = 0; j < nkeys; j++)
94  {
95  if(fo_config_is_list(config, groups[i], keys[j], &error))
96  {
97  nlist = fo_config_list_length(config, groups[i], keys[j], &error);
98  printf(" %s:\n", keys[j]);
99  for(k = 0; k < nlist; k++)
100  {
101  printf(" [%d] = %s\n", k,
102  (temp = fo_config_get_list(config, groups[i], keys[j], k, &error)));
103  g_free(temp);
104  }
105  }
106  else
107  {
108  printf(" %s = %s\n", keys[j],
109  fo_config_get(config, groups[i], keys[j], &error));
110  }
111  }
112  }
113 
114  fo_config_free(config);
115  return 0;
116 }
void fo_config_join(fo_conf *dst, fo_conf *src, GError **error)
Takes all groups and key from a fo_conf and adds them to another.
Definition: fossconfig.c:536
int fo_config_is_list(fo_conf *conf, char *group, char *key, GError **error)
Checks if a particular value is a list or just a normal value.
Definition: fossconfig.c:444
int main(int argc, char **argv)
Main function for the test.
char * fo_config_get(fo_conf *conf, const char *group, const char *key, GError **error)
Gets an element based on its group name and key name. If the group or key is not found, the error object is set and NULL is returned.
Definition: fossconfig.c:341
char ** fo_config_group_set(fo_conf *conf, int *length)
Gets the set of group names.
Definition: fossconfig.c:577
char * fo_config_get_list(fo_conf *conf, char *group, char *key, int idx, GError **error)
Definition: fossconfig.c:387
int fo_config_list_length(fo_conf *conf, char *group, char *key, GError **error)
Gets the length of the list associated with a particular list key.
Definition: fossconfig.c:480
The main FOSSology C library.
void fo_config_free(fo_conf *conf)
Frees the memory associated with the internal configuration data structures.
Definition: fossconfig.c:511
char ** fo_config_key_set(fo_conf *conf, char *group, int *length)
Gets the set of key names for a particular group.
Definition: fossconfig.c:619
fo_conf * fo_config_load(char *rawname, GError **error)
Load the configuration information from the provided file.
Definition: fossconfig.c:280