FOSSology  4.4.0
Open Source License Compliance by Open Source Software
fossconfigTest.c
Go to the documentation of this file.
1 /*
2  SPDX-FileCopyrightText: © 2011 Hewlett-Packard Development Company, L.P.
3 
4  SPDX-License-Identifier: GPL-2.0-only
5 */
14 #include <libfossology.h>
15 #include <stdio.h>
16 #include <errno.h>
17 #include <glib.h>
18 
28 int main(int argc, char** argv)
29 {
30  GError* error = NULL;
31  char** groups;
32  char** keys;
33  gchar* temp;
34  int i, ngrps;
35  int j, nkeys;
36  int k, nlist;
37  fo_conf* config;
38  fo_conf* tmp;
39 
40  if(argc < 2)
41  {
42  fprintf(stderr, "Usage: %s ini1 ini2 ... iniN\n", argv[0]);
43  return 255;
44  }
45 
46  config = fo_config_load(argv[1], &error);
47 
48  if(error)
49  {
50  fprintf(stderr, "ERROR: %s\n", error->message);
51  return 254;
52  }
53 
54  for(i = 2; i < argc; i++)
55  {
56  tmp = fo_config_load(argv[i], &error);
57 
58  if(error)
59  {
60  fprintf(stderr, "ERROR: %s\n", error->message);
61  return 254;
62  }
63 
64  fo_config_join(config, tmp, &error);
65 
66  if(error)
67  {
68  fprintf(stderr, "ERROR: %s\n", error->message);
69  return 253;
70  }
71 
72  fo_config_free(tmp);
73  }
74 
75  groups = fo_config_group_set(config, &ngrps);
76  for(i = 0; i < ngrps; i++)
77  {
78  printf("[%s]\n", groups[i]);
79 
80  keys = fo_config_key_set(config, groups[i], &nkeys);
81  for(j = 0; j < nkeys; j++)
82  {
83  if(fo_config_is_list(config, groups[i], keys[j], &error))
84  {
85  nlist = fo_config_list_length(config, groups[i], keys[j], &error);
86  printf(" %s:\n", keys[j]);
87  for(k = 0; k < nlist; k++)
88  {
89  printf(" [%d] = %s\n", k,
90  (temp = fo_config_get_list(config, groups[i], keys[j], k, &error)));
91  g_free(temp);
92  }
93  }
94  else
95  {
96  printf(" %s = %s\n", keys[j],
97  fo_config_get(config, groups[i], keys[j], &error));
98  }
99  }
100  }
101 
102  fo_config_free(config);
103  return 0;
104 }
int main(int argc, char **argv)
Main function for the test.
char * fo_config_get_list(fo_conf *conf, char *group, char *key, int idx, GError **error)
Definition: fossconfig.c:382
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:475
void fo_config_free(fo_conf *conf)
Frees the memory associated with the internal configuration data structures.
Definition: fossconfig.c:506
char ** fo_config_group_set(fo_conf *conf, int *length)
Gets the set of group names.
Definition: fossconfig.c:572
fo_conf * fo_config_load(char *rawname, GError **error)
Load the configuration information from the provided file.
Definition: fossconfig.c:275
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,...
Definition: fossconfig.c:336
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:439
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:531
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:614
The main FOSSology C library.