1ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta/******************************************************************************
2ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
35b790feeeb211c42bf78ca3ae9c26aa30e516765Jakub Pawlowski *  Copyright 2014 The Android Open Source Project
49ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson *  Copyright 2002 - 2004 Open Interface North America, Inc. All rights
59ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson *                        reserved.
6ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
7ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *  Licensed under the Apache License, Version 2.0 (the "License");
8ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *  you may not use this file except in compliance with the License.
9ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *  You may obtain a copy of the License at:
10ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
11ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *  http://www.apache.org/licenses/LICENSE-2.0
12ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
13ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *  Unless required by applicable law or agreed to in writing, software
14ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *  distributed under the License is distributed on an "AS IS" BASIS,
15ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *  See the License for the specific language governing permissions and
17ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *  limitations under the License.
18ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
19ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta ******************************************************************************/
20ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta#ifndef _OI_UTILS_H
21ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta#define _OI_UTILS_H
22ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta/**
23ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * @file
24ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
25ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * This file provides the interface for utility functions.
26ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * Among the utilities are strlen (string length), strcmp (string compare), and
27ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * other string manipulation functions. These are provided for those plaforms
28ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * where this functionality is not available in stdlib.
29ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta */
30ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta
31ee96a3c60fca590d38025925c072d264e06493c4Myles Watson/*******************************************************************************
32ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta  $Revision: #1 $
33ee96a3c60fca590d38025925c072d264e06493c4Myles Watson ******************************************************************************/
34ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta
35ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta#include <stdarg.h>
36911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson#include "oi_bt_spec.h"
37ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta#include "oi_common.h"
38ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta#include "oi_string.h"
39ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta
40ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta/** \addtogroup Misc Miscellaneous APIs */
41ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta/**@{*/
42ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta
43ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta#ifdef __cplusplus
44ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Guptaextern "C" {
45ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta#endif
46ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta
47ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta/**
48ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * Opaque type for a callback function handle. See OI_ScheduleCallbackFunction()
49ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta */
50a239d20e95238c37d02121abb49b14d433c5afc2Jakub Pawlowskitypedef uint32_t OI_CALLBACK_HANDLE;
51ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta
52ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta/**
53ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * Function prototype for a timed procedure callback.
54ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
559ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * @param arg   Value that was passed into the OI_ScheduleCallback() function
56ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
57ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta */
58911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsontypedef void (*OI_SCHEDULED_CALLBACK)(void* arg);
59ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta
60ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta/**
619ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * Registers a function to be called when a timeout expires. This API uses
629ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * BLUEmagic's internal function dispatch mechanism, so applications that make
639ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * extensive use of this facility may need to increase the value of
649ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * DispatchTableSize in the configuration block for the dispatcher (see
65ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * oi_bt_stack_config.h).
66ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
679ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * @param callbackFunction    The function that will be called when the timeout
689ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson *                            expires
69ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
709ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * @param arg                 Value that will be returned as the parameter to
719ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson *                            the callback function.
72ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
739ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * @param timeout             A timeout expressed in OI_INTERVALs (tenths of
749ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson *                            seconds). This can be zero in which case the
759ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson *                            callback function will be called as soon as
76ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *                            possible.
77ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
78ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * @param handle              NULL or a pointer receive the callback handle.
79ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
809ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * @return                    OI_OK if the function was registered, or an error
819ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson *                            status.
82ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta */
83ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant GuptaOI_STATUS OI_ScheduleCallbackFunction(OI_SCHEDULED_CALLBACK callbackFunction,
84911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson                                      void* arg, OI_INTERVAL timeout,
85911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson                                      OI_CALLBACK_HANDLE* handle);
86ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta
87ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta/**
889ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * Cancels a function registered with OI_ScheduleCallbackFunction() before its
899ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * timer expires.
90ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
91ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * @param handle              handle returned by  OI_ScheduleCallbackFunction().
92ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
939ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * @return                    OI_OK if the function was cancelled, or an error
949ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson *                            status.
95ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta */
96ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant GuptaOI_STATUS OI_CancelCallbackFunction(OI_CALLBACK_HANDLE handle);
97ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta
98ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta/**
999ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * Registers a function to be called when a timeout expires. This version does
1009ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * not return a handle so can only be canceled by calling OI_CancelCallback().
101ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
1029ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * @param callbackFunction    The function that will be called when the timeout
1039ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson *                            expires
104ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
1059ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * @param arg                 Value that will be returned as the parameter to
1069ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson *                            the callback function.
107ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
1089ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * @param timeout             A timeout expressed in OI_INTERVALs (tenths of
1099ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson *                            seconds). This can be zero in which case the
1109ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson *                            callback function will be called as soon as
111ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *                            possible.
112ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
1139ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * @return                    OI_OK if the function was reqistered, or an error
1149ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson *                            status.
115ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta */
116911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson#define OI_ScheduleCallback(f, a, t) OI_ScheduleCallbackFunction(f, a, t, NULL);
117ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta
118ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta/**
1199ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * Cancels a function registered with OI_ScheduleCallback() before its timer
1209ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * expires. This function will cancel the first entry matches the indicated
1219ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * callback function pointer.
122ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
123ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * @param callbackFunction    The function that was originally registered
124ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
1259ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * @return                    OI_OK if the function was cancelled, or an error
1269ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson *                            status.
127ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta */
128ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant GuptaOI_STATUS OI_CancelCallback(OI_SCHEDULED_CALLBACK callbackFunction);
129ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta
130ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta/**
131ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * Printf function for platforms which have no stdio or printf available.
132ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * OI_Printf supports the basic formatting types, with the exception of
133ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * floating point types. Additionally, OI_Printf supports several formats
134ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * specific to BLUEmagic 3.0 software:
135ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
136ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * \%!   prints the string for an #OI_STATUS value.
137ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *       @code OI_Printf("There was an error %!", status); @endcode
138ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
139ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * \%@   prints a hex dump of a buffer.
140ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *       Requires a pointer to the buffer and a signed integer length
141ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *       (0 for default length). If the buffer is large, only an excerpt will
142ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *       be printed.
1439ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson *       @code OI_Printf("Contents of buffer %@", buffer, sizeof(buffer));
1449ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson *       @endcode
145ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
146ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * \%^   decodes and prints a data element as formatted XML.
147ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *       Requires a pointer to an #OI_DATAELEM.
1489ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson *       @code OI_Printf("Service attribute list is:\n%^", &attributes);
1499ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson *       @endcode
150ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
151ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * \%/   prints the base file name of a path, that is, the final substring
152ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *       following a '/' or '\\' character. Requires a pointer to a null
153ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *       terminated string.
154ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *       @code OI_Printf("File %/", "c:\\dir1\\dir2\\file.txt"); @endcode
155ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
156ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * \%~   prints a string, escaping characters as needed to display it in
157ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *       ASCII. Requires a pointer to an #OI_PSTR and an #OI_UNICODE_ENCODING
158ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *       parameter.
159ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *       @code OI_Printf("Identifier %~", &id, OI_UNICODE_UTF16_BE); @endcode
160ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
161ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * \%[   inserts an ANSI color escape sequence. Requires a single character
162ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *       identifying the color to select. Colors are red (r/R), green (g/G),
163ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *       blue (b/B), yellow (y/Y), cyan (c/C), magenta (m/M), white (W),
164ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *       light-gray (l/L), dark-gray (d/D), and black (0). The lower case is
165ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *       dim, the upper case is bright (except in the case of light-gray and
166ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *       dark-gray, where bright and dim are identical). Any other value will
167ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *       select the default color.
168ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *       @code OI_Printf("%[red text %[black %[normal\n", 'r', '0', 0); @endcode
169ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
170ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * \%a   same as \%s, except '\\r' and '\\n' are output as "<cr>" and "<lf>".
171ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *       \%?a is valid, but \%la is not.
172ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
173ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * \%b   prints an integer in base 2.
174ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *       @code OI_Printf("Bits are %b", I); @endcode
175ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
176ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * \%lb  prints a long integer in base 2.
177ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
178ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * \%?b  prints the least significant N bits of an integer (or long integer)
179ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *       in base 2. Requires the integer and a length N.
180ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *       @code OI_Printf("Bottom 4 bits are: %?b", I, 4); @endcode
181ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
182ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * \%B   prints an integer as boolean text, "TRUE" or "FALSE".
183ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *       @code OI_Printf("The value 0 is %B, the value 1 is %B", 0, 1); @endcode
184ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
185ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * \%?s  prints a substring up to a specified maximum length.
186ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *       Requires a pointer to a string and a length parameter.
187ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *       @code OI_Printf("String prefix is %?s", str, 3); @endcode
188ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
189ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * \%ls  same as \%S.
190ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
191ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * \%S   prints a UTF16 string as UTF8 (plain ASCII, plus 8-bit char sequences
192ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *       where needed). Requires a pointer to #OI_CHAR16. \%?S is valid. The
193ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *       length parameter is in OI_CHAR16 characters.
194ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
195ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * \%T   prints time, formatted as "secs.msecs".
196ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *       Requires pointer to #OI_TIME struct, NULL pointer prints current time.
197ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *       @code OI_Printf("The time now is %T", NULL); @endcode
198ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
199ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *  @param format   The format string
200ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
201ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta */
202911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonvoid OI_Printf(const OI_CHAR* format, ...);
203ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta
204ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta/**
205ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * Var-args version OI_Printf
206ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
207ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * @param format   Same as for OI_Printf.
208ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
209ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * @param argp     Var-args list.
210ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta */
211911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonvoid OI_VPrintf(const OI_CHAR* format, va_list argp);
212ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta
213ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta/**
2149ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * Writes a formatted string to a buffer. This function supports the same format
2159ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * specifiers as OI_Printf().
216ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
217ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * @param buffer   Destination buffer for the formatted string.
218ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
219ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * @param bufLen   The length of the destination buffer.
220ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
221ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * @param format   The format string
222ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
223ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * @return   Number of characters written or -1 in the case of an error.
224ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta */
225911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonint32_t OI_SNPrintf(OI_CHAR* buffer, uint16_t bufLen, const OI_CHAR* format,
226911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson                    ...);
227ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta
228ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta/**
229ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * Var-args version OI_SNPrintf
230ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
231ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * @param buffer   Destination buffer for the formatted string.
232ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
233ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * @param bufLen   The length of the destination buffer.
234ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
235ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * @param format   The format string
236ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
237ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * @param argp     Var-args list.
238ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
239ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * @return   Number of characters written or -1 in the case of an error.
240ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta */
241911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonint32_t OI_VSNPrintf(OI_CHAR* buffer, uint16_t bufLen, const OI_CHAR* format,
242911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson                     va_list argp);
243ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta
244ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta/**
245ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * Convert a string to an integer.
246ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
247ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * @param str  the string to parse
248ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
2499ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * @return the integer value of the string or 0 if the string could not be
2509ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson *         parsed
251ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta */
252911d1ae03efec2d54c3b1b605589d790d1745488Myles WatsonOI_INT OI_atoi(const OI_CHAR* str);
253ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta
254ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta/**
255ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * Parse a signed integer in a string.
256ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
2579ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * Skips leading whitespace (space and tabs only) and parses a decimal or hex
2589ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * string. Hex string must be prefixed by "0x". Returns pointer to first
2599ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * character following the integer. Returns the pointer passed in if the string
2609ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * does not describe an integer.
261ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
262ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * @param str    String to parse.
263ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
264ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * @param val    Pointer to receive the parsed integer value.
265ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
2669ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * @return       A pointer to the first character following the integer or the
2679ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson *               pointer passed in.
268ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta */
269911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonconst OI_CHAR* OI_ScanInt(const OI_CHAR* str, int32_t* val);
270ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta
271ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta/**
272ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * Parse an unsigned integer in a string.
273ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
2749ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * Skips leading whitespace (space and tabs only) and parses a decimal or hex
2759ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * string. Hex string must be prefixed by "0x". Returns pointer to first
2769ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * character following the integer. Returns the pointer passed in if the
2779ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * string does not describe an integer.
278ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
279ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * @param str    String to parse.
280ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
281ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * @param val    Pointer to receive the parsed unsigned integer value.
282ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
2839ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * @return       A pointer to the first character following the unsigned
2849ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson *               integer or the pointer passed in.
285ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta */
286911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonconst OI_CHAR* OI_ScanUInt(const OI_CHAR* str, uint32_t* val);
287ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta
288ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta/**
289ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * Parse a whitespace delimited substring out of a string.
290ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
291ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * @param str     Input string to parse.
292ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * @param outStr  Buffer to return the substring
293ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * @param len     Length of outStr
294ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
295ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
2969ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * @return       A pointer to the first character following the substring or
2979ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson *               the pointer passed in.
298ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta */
299911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonconst OI_CHAR* OI_ScanStr(const OI_CHAR* str, OI_CHAR* outStr, uint16_t len);
300ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta
301ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta/**
3029ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * Parse a string for one of a set of alternative value. Skips leading
3039ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * whitespace (space and tabs only) and parses text matching one of the
3049ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * alternative strings. Returns pointer to first character following the
3059ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * matched text.
306ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
307ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * @param str    String to parse.
308ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
309ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * @param alts   Alternative matching strings separated by '|'
310ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
3119ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * @param index  Pointer to receive the index of the matching alternative,
3129ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson *               return value is -1 if there is no match.
313ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
3149ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson * @return       A pointer to the first character following the matched value or
3159ca07091a1f07ea201cee0504dab6a1d7073d429Myles Watson *               the pointer passed in if there was no matching text.
316ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta */
317911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonconst OI_CHAR* OI_ScanAlt(const OI_CHAR* str, const OI_CHAR* alts,
318911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson                          OI_INT* index);
319ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta
320ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta/** Get a character from a digit integer value (0 - 9). */
321ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta#define OI_DigitToChar(d) ((d) + '0')
322ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta
323ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta/**
324ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * Determine Maximum and Minimum between two arguments.
325ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
326ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * @param a  1st value
327ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * @param b  2nd value
328ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta *
329ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta * @return the max or min value between a & b
330ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta */
331911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson#define OI_MAX(a, b) (((a) < (b)) ? (b) : (a))
332911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson#define OI_MIN(a, b) (((a) > (b)) ? (b) : (a))
333ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta
334ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta#ifdef __cplusplus
335ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta}
336ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta#endif
337ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta
338ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta/**@}*/
339ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta
340ce24765fe7620c34e8d88ed4f826c8a6917582b2Hemant Gupta#endif /* _OI_UTILS_H */
341