]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ipc/ipcdev.git/blob - qnx/src/ipc3x_dev/ti/syslink/utils/common/Cfg.c
Merge branch '3.30' into ipc-next
[ipc/ipcdev.git] / qnx / src / ipc3x_dev / ti / syslink / utils / common / Cfg.c
1 /*
2  *  @file   Cfg.c
3  *
4  *  @brief      Configuration Helper Utilities
5  *
6  *
7  *  ============================================================================
8  *
9  *  Copyright (c) 2008-2015, Texas Instruments Incorporated
10  *
11  *  Redistribution and use in source and binary forms, with or without
12  *  modification, are permitted provided that the following conditions
13  *  are met:
14  *
15  *  *  Redistributions of source code must retain the above copyright
16  *     notice, this list of conditions and the following disclaimer.
17  *
18  *  *  Redistributions in binary form must reproduce the above copyright
19  *     notice, this list of conditions and the following disclaimer in the
20  *     documentation and/or other materials provided with the distribution.
21  *
22  *  *  Neither the name of Texas Instruments Incorporated nor the names of
23  *     its contributors may be used to endorse or promote products derived
24  *     from this software without specific prior written permission.
25  *
26  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
28  *  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
30  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31  *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32  *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
33  *  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
34  *  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
35  *  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
36  *  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37  *  Contact information for paper mail:
38  *  Texas Instruments
39  *  Post Office Box 655303
40  *  Dallas, Texas 75265
41  *  Contact information:
42  *  http://www-k.ext.ti.com/sc/technical-support/product-information-centers.htm?
43  *  DCMP=TIHomeTracking&HQS=Other+OT+home_d_contact
44  *  ============================================================================
45  *
46  */
49 /* Standard headers */
50 #include <ti/syslink/Std.h>
52 /* OSAL & Utils headers */
53 #include <ti/syslink/utils/String.h>
55 /* -------------------------- Generic includes ------------------------------ */
56 #include <string.h>
58 /* this module's header file */
59 #include "../Cfg.h"
62 /* =============================================================================
63  * Struct & Enums
64  * =============================================================================
65  */
68 /* =============================================================================
69  * Globals
70  * =============================================================================
71  */
74 /* =============================================================================
75  * APIs
76  * =============================================================================
77  */
79 /* Find given property string in given params string. If found, copy
80  * property value into output buffer and return true. Otherwise, return
81  * false.
82  */
83 Bool Cfg_prop(String prop, String params, Char *buf)
84 {
85     Int     len;
86     String  delim;
88     if ((prop == NULL) || (params == NULL)) {
89         return(FALSE);
90     }
92     len = strlen(prop);
94     /* loop until params string has been scanned */
95     while (*params != '\0') {
97         /* search for prop starting at current pointer */
98         if (strncmp(prop, params, len) == 0) {
100             /* found prop, advance to value */
101             params += len;
102             if ((delim = strchr(params, ';')) == NULL) {
103                 return(FALSE);
104             }
106             /* copy value into output buffer */
107             while (params != delim) {
108                 *buf++ = *params++;
109             }
111             /* add string terminator */
112             *buf = '\0';
114             return(TRUE);
115         }
117         /* advance to next prop in params */
118         else {
119             if ((params = strchr(params, ';')) == NULL) {
120                 return(FALSE);
121             }
122             params++;
123         }
124     }
126     return(FALSE);
130 /* Search for prop in params and parse value. If found, assign value
131  * to var.
132  */
133 Int Cfg_propBool(String prop, String params, Bool *var)
135     Char    buf[8];
136     Int     status = 0;
138     if (Cfg_prop(prop, params, buf)) {
139         if (strncmp("TRUE", buf, 4) == 0) {
140             *var = TRUE;
141         }
142         else if (strncmp("FALSE", buf, 5) == 0) {
143             *var = FALSE;
144         }
145         else {
146             status = -1;  /* bad value */
147         }
148     }
149     else {
150         return(1);  /* not found, no errors */
151     }
153     return(status);
157 /* =============================================================================
158  * Internal functions
159  * =============================================================================
160  */