Fixed some RPMlint errors - group name, duplicate files, etc.
[profile/ivi/ico-uxf-homescreen.git] / ico-app-framework / ico_uxf_conf_common.c
1 /*
2  * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
3  *
4  * This program is licensed under the terms and conditions of the
5  * Apache License, version 2.0.  The full text of the Apache License is at
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
8  */
9 /**
10  * @brief   user experiance library(common function in read configuration)
11  *
12  * @date    Feb-28-2013
13  */
14
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <sys/types.h>
18 #include <sys/stat.h>
19 #include <unistd.h>
20 #include <string.h>
21 #include <sys/time.h>
22 #include <sys/file.h>
23 #include <errno.h>
24
25 #include "ico_apf_log.h"
26 #include "ico_apf_apimacro.h"
27 #include "ico_uxf_conf_common.h"
28
29 /* Number of hash table                         */
30 #define ICO_UXF_MISC_HASHSIZE   64          /* Must be 2's factorial            */
31
32 /*--------------------------------------------------------------------------*/
33 /**
34  * @brief   ico_uxf_misc_hashByName: create hash value by name string
35  *          there is no distinction of an english capital letter/small
36  *
37  * @param[in]   name        character string changed into a hash value(NULL termination)
38  *
39  * @return  create hash value
40  */
41 /*--------------------------------------------------------------------------*/
42 int
43 ico_uxf_misc_hashByName(const char *name)
44 {
45     int     hash = 0;
46     int     i;
47
48     for (i = 0; name[i]; i++)  {
49         hash = (hash << 1) | (name[i] & 0x1f);
50     }
51     return hash & (ICO_UXF_MISC_HASHSIZE-1);
52 }
53
54 /*--------------------------------------------------------------------------*/
55 /**
56  * @brief   ico_uxf_conf_getUint: convert value string to value
57  *
58  * @param[in]   str         string
59  * @return      converted value
60  */
61 /*--------------------------------------------------------------------------*/
62 int
63 ico_uxf_conf_getUint(const char* str)
64 {
65     int key = -1;
66     if (str != NULL)    {
67         if ((strcasecmp(str, "true") == 0) ||
68             (strcasecmp(str, "yes") == 0))   {
69             key = 1;
70         }
71         else if ((strcasecmp(str, "false") == 0) ||
72                  (strcasecmp(str, "no") == 0))   {
73             key = 0;
74         }
75         else    {
76             char    *errpt = (char *)0;
77             key = strtol(str, &errpt, 0);
78             if ((errpt) && (*errpt != 0))  {
79                 key = -1;
80             }
81         }
82     }
83     return key;
84 }
85
86 /*--------------------------------------------------------------------------*/
87 /**
88  * @brief   ico_uxf_conf_countNumericalKey: count numerical keys in configuration file
89  *
90  * @param[in]   keyfile         configuration file
91  * @param[in]   group           configuration groupe(ex.[display])
92  * @return      configuration list
93  */
94 /*--------------------------------------------------------------------------*/
95 GList *
96 ico_uxf_conf_countNumericalKey(GKeyFile *keyfile, const char* group)
97 {
98     GList*  list = NULL;
99     char    **result;
100     gsize   length;
101     int     i;
102
103     result = g_key_file_get_keys(keyfile, group, &length,NULL);
104
105     for (i = 0; i < (int)length; i++) {
106         int id = ico_uxf_conf_getUint(result[i]);
107         if (id >= 0) {
108             list=g_list_append(list,g_strdup(result[i]));
109         }
110     }
111     g_strfreev(result);
112     return list;
113 }
114
115 /*--------------------------------------------------------------------------*/
116 /**
117  * @brief   ico_uxf_conf_appendStr: connect strings
118  *
119  * @param[in]   str1            string 1
120  * @param[in]   str2            string 2
121  * @return      static connected string (str1+str2)
122  */
123 /*--------------------------------------------------------------------------*/
124 const char *
125 ico_uxf_conf_appendStr(const char* str1, const char* str2)
126 {
127     static char buf[256];
128     sprintf(buf, "%s%s", str1, str2);
129     return buf;
130 }
131
132 /*--------------------------------------------------------------------------*/
133 /**
134  * @brief   ico_uxf_conf_checkGerror: output configuration error message
135  *
136  * @param[in]   error           error information
137  * @return      none
138  */
139 /*--------------------------------------------------------------------------*/
140 void
141 ico_uxf_conf_checkGerror(GError** error)
142 {
143     if (*error != NULL) {
144         uifw_warn("%s",(*error)->message);
145     }
146     g_clear_error(error);
147 }
148