1 /******************************************************************************
2 @file log_ini.c
4 @brief TIMAC 2.0 API Parse log file settings from an INI file
6 Group: WCS LPC
7 $Target Devices: Linux: AM335x, Embedded Devices: CC1310, CC1350, CC1352$
9 ******************************************************************************
10 $License: BSD3 2016 $
12 Copyright (c) 2015, Texas Instruments Incorporated
13 All rights reserved.
15 Redistribution and use in source and binary forms, with or without
16 modification, are permitted provided that the following conditions
17 are met:
19 * Redistributions of source code must retain the above copyright
20 notice, this list of conditions and the following disclaimer.
22 * Redistributions in binary form must reproduce the above copyright
23 notice, this list of conditions and the following disclaimer in the
24 documentation and/or other materials provided with the distribution.
26 * Neither the name of Texas Instruments Incorporated nor the names of
27 its contributors may be used to endorse or promote products derived
28 from this software without specific prior written permission.
30 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
31 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
32 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
33 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
34 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
35 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
36 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
37 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
38 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
39 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
40 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 ******************************************************************************
42 $Release Name: TI-15.4Stack Linux x64 SDK$
43 $Release Date: Sept 27, 2017 (2.04.00.13)$
44 *****************************************************************************/
46 #include "compiler.h"
47 #include "log.h"
48 #include "ini_file.h"
50 #include <string.h>
52 const struct ini_flag_name log_builtin_flag_names[] = {
53 { .name = "everything" , .value = LOG_EVERYTHING },
54 { .name = "warning" , .value = LOG_WARN },
55 { .name = "error" , .value = LOG_ERROR },
56 { .name = "fatal" , .value = LOG_FATAL },
57 { .name = "sys_dbg_mutex" , .value = LOG_DBG_MUTEX },
58 { .name = "sys_dbg_thread" , .value = LOG_DBG_THREAD },
59 { .name = "sys_dbg_fifo" , .value = LOG_DBG_FIFO },
60 { .name = "sys_dbg_uart" , .value = LOG_DBG_UART },
61 { .name = "sys_dbg_uart_raw" , .value = LOG_DBG_UART_RAW },
62 { .name = "sys_dbg_sleep" , .value = LOG_DBG_SLEEP },
63 { .name = "sys_dbg_socket" , .value = LOG_DBG_SOCKET },
64 { .name = "sys_dbg_socket_raw" , .value = LOG_DBG_SOCKET_RAW },
65 { .name = "sys_dbg_collector" , .value = LOG_DBG_COLLECTOR },
66 { .name = "sys_dbg_collector_raw" , .value = LOG_DBG_COLLECTOR_RAW },
67 /* terminate list */
68 { .name = NULL }
69 };
71 /*
72 * Parse LOG file ini settings from an ini file in a standard way.
73 *
74 * see log.h
75 */
76 int LOG_INI_settings(struct ini_parser *pINI, bool *handled)
77 {
78 const struct ini_flag_name * pF;
79 bool is_not;
80 int64_t v64;
82 if(pINI->item_name == NULL)
83 {
84 /* this is the section name, we don't care about it. */
85 return (0);
86 }
88 if(INI_itemMatches(pINI, "log", "filename"))
89 {
90 LOG_init(pINI->item_value);
91 *handled = true;
92 return (0);
93 }
95 if(INI_itemMatches(pINI, "log", "dup2stderr"))
96 {
97 log_cfg.dup_to_stderr = INI_valueAsBool(pINI);
98 *handled = true;
99 return (0);
100 }
102 if(!INI_itemMatches(pINI, "log", "flag"))
103 {
104 /* nothing else matches */
105 /* below is dealing with log flags. */
106 return (0);
107 }
109 /* beyondhere it is a flag... and only a flag */
110 *handled = true;
112 /* if quoted, dequote it */
113 INI_dequote(pINI);
115 v64 = 0;
116 is_not = false;
118 /* if it is a number value ... then use the number */
119 if(INI_isValueS64(pINI, &v64))
120 {
121 /* we use the number */
122 }
123 else
124 {
125 /* otherwise, it could be a named value */
126 int x;
127 for(x = 0 ; (pF = log_flag_names[x]) != NULL ; x++)
128 {
129 pF = INI_flagLookup(pF, pINI->item_value, &is_not);
130 if(pF != NULL)
131 {
132 break;
133 }
134 };
136 if(pF == NULL)
137 {
138 pF = INI_flagLookup(log_builtin_flag_names,
139 pINI->item_value,
140 &is_not);
141 }
143 if(pF == NULL)
144 {
145 INI_syntaxError(pINI, "unknown-flag: %s\n", pINI->item_value);
146 return (-1);
147 }
149 v64 = pF->value;
150 }
152 if(is_not)
153 {
154 log_cfg.log_flags &= (~(v64));
155 }
156 else
157 {
158 log_cfg.log_flags |= ((v64));
159 }
161 return (1);
162 }
164 /*
165 * ========================================
166 * Texas Instruments Micro Controller Style
167 * ========================================
168 * Local Variables:
169 * mode: c
170 * c-file-style: "bsd"
171 * tab-width: 4
172 * c-basic-offset: 4
173 * indent-tabs-mode: nil
174 * End:
175 * vim:set filetype=c tabstop=4 shiftwidth=4 expandtab=true
176 */