head 1.5; access; symbols last-version-in-peti-style:1.4 callback-semantic-rewrite:1.3.0.2; locks; strict; comment @ * @; 1.5 date 2001.08.08.19.15.23; author rse; state dead; branches; next 1.4; 1.4 date 2001.08.01.15.25.47; author simons; state Exp; branches; next 1.3; 1.3 date 2001.07.18.17.49.51; author simons; state Exp; branches 1.3.2.1; next 1.2; 1.2 date 2001.07.08.15.22.00; author simons; state Exp; branches; next 1.1; 1.1 date 2001.07.08.14.10.32; author simons; state Exp; branches; next ; 1.3.2.1 date 2001.08.01.09.55.58; author simons; state Exp; branches; next 1.3.2.2; 1.3.2.2 date 2001.08.01.13.26.29; author simons; state Exp; branches; next ; desc @@ 1.5 log @First cut of the ruthless style adjustments to OSSP XDS: o adjust source tree to follow OSSP source tree style by heavily combining sources into smaller sets (needs more work when still missing parts are added later) o automatic re-indentation of sources with GNU indent (still needs manual review and adjustments; will follow) These two heavy steps were mostly done automatically with the help of two helper scripts written in Perl. So expect more manual adjustments to follow... @ text @/* XDS - OSSP Extensible Data Serialization Library Copyright (c) 2001 The OSSP Project (http://www.ossp.org/) Copyright (c) 2001 Cable & Wireless Deutschland (http://www.cw.com/de/) This file is part of OSSP XDS, an extensible data serialization library which can be found at http://www.ossp.com/pkg/xds/. Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include "internal.h" int xds_find_engine(const engine_map_t* engines, size_t last, const char* name, size_t* pos) { size_t first; /* Sanity checks. */ xds_check_parameter(engines != NULL || last == 0); xds_check_parameter(name != NULL); xds_check_parameter(pos != NULL); /* Use binary search to find "name" in "engines". */ for (first = 0; (last - first) > 0; ) { size_t half = first + ((last - first) / 2); int rc = strcmp(engines[half].name, name); if (rc < 0) { first = half + 1; } else if(rc == 0) { /* found it */ *pos = half; return XDS_TRUE; } else { last = half; } assert(first <= last); } *pos = first; return XDS_FALSE; } @ 1.4 log @Merged the whole contents of branch "callback-semantic-rewrite" into the main branch. The changes there include: - A change of the callback semantics; callbacks do now return XDS_ERR_(UNDER|OVER)FLOW in case the buffer size doesn't fit. Rather than passing the differing byte size through the return code, it is stored in the location used_buffer_size points to -- a new parameter provided to all callbacks. In order to implement this, the framework, all callbacks and most of the test suits had to be adapted. - internal.h now provides the macro xds_check_parameter(), which can be used to verify the contents of function parameters with assert() and if in one line. If assert()s are deactivated, the routine will still return XDS_ERR_INVALID_ARG. Because of this change, internal.h now includes the system header assert.h. This means that this include coulde be removed from almost all modules. - internal.h now provides the macros xds_init_(en|de)coding_engine(). These can be used to comfortably verify a callback's parameters and to verify the buffer size. All engines have been rewritten to use these. @ text @@ 1.3 log @Added XDS_TRUE and XDS_FALSE defines and started using them in the sources. @ text @a28 1 #include d37 3 a39 3 assert(engines != NULL || last == 0); assert(name != NULL); assert(pos != NULL); @ 1.3.2.1 log @Added xds_check_parameter() macro to short-cut the assert() and if-statements at the begining of every routine. Also rewrote some modules to take advantage of that macro. @ text @d38 3 a40 3 xds_check_parameter(engines != NULL || last == 0); xds_check_parameter(name != NULL); xds_check_parameter(pos != NULL); @ 1.3.2.2 log @Now that internal.h includes assert.h we don't need to do that anymore. @ text @d29 1 @ 1.2 log @xds_find_engine() can now handle a NULL pointer for "engines" as long as "last" is set correctly to 0. This is necessary so that we don't have to allocate an array before we actually have any entries. @ text @d56 1 a56 1 return (1 == 1); d66 1 a66 1 return (1 != 1); @ 1.1 log @The xds_find_engine() routine will binary search through the engine_map_t to find an engine or the spot where it should be inserted to keep the correct alphabetical ordering. @ text @d38 1 a38 1 assert(engines != NULL); a40 2 if (engines == NULL || name == NULL || pos == NULL) return XDS_ERR_INVALID_ARG; @