head 1.5; access; symbols last-version-in-peti-style:1.4 callback-semantic-rewrite:1.2.0.2; locks; strict; comment @ * @; 1.5 date 2001.08.08.19.15.24; author rse; state dead; branches; next 1.4; 1.4 date 2001.08.02.08.10.13; author simons; state Exp; branches; next 1.3; 1.3 date 2001.08.01.15.25.47; author simons; state Exp; branches; next 1.2; 1.2 date 2001.07.24.13.52.41; author simons; state Exp; branches 1.2.2.1; next 1.1; 1.1 date 2001.07.23.16.17.43; author simons; state Exp; branches; next ; 1.2.2.1 date 2001.08.01.13.26.30; author simons; state Exp; branches; next 1.2.2.2; 1.2.2.2 date 2001.08.01.15.08.02; 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 "xds.h" int xml_encode_uint32(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, size_t* used_buffer_size, va_list* args) { xds_uint32_t value; char buf[32]; size_t i, j; char* p; xds_init_encoding_engine(8 + 9 + 10); /* Format value into our buffer. */ value = va_arg(*args, xds_uint32_t); i = 0; do { unsigned char remainder = value % 10; value = value / 10; buf[i++] = '0' + remainder; } while (value != 0); /* Store the correct buffer size. */ *used_buffer_size = 8 + 9 + i; /* Write result into the buffer. */ p = buffer; memmove(p, "", 8); p += 8; for (j = i; j > 0; ) { *p++ = buf[--j]; } memmove(p, "", 9); return XDS_OK; } @ 1.4 log @Include xds.h, not internal.h! @ text @@ 1.3 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 @d29 1 a29 1 #include "internal.h" @ 1.2 log @If there are any ladies reading this: Please pardon my language in the following paragraph! Fuck snprintf(). Since apparently the Unix vendors are too bloody stupid to provide a working snprintf() implementation that conforms to an 8 year old standard, we don't use snprintf() at all but convert the numbers ourselves. I re-implemented all XML callbacks to do maths on their own. @ text @a28 1 #include d31 3 a33 1 int xml_encode_uint32(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, va_list* args) d40 1 a40 8 /* Consistency checks. */ assert(xds != NULL); assert(buffer != NULL); assert(buffer_size != 0); assert(args != NULL); if (xds == NULL || buffer == NULL || buffer_size == 0 || args == NULL) return XDS_ERR_INVALID_ARG; d54 1 a54 1 /* Check the buffer size. */ d56 1 a56 2 if (buffer_size < 8 + 9 + i) return 8 + 9 + i; d61 1 a61 1 strcpy(p, ""); d67 1 a67 1 strcpy(p, ""); d69 1 a69 1 return 8 + 9 + i; @ 1.2.2.1 log @Now that internal.h includes assert.h we don't need to do that anymore. @ text @d29 1 @ 1.2.2.2 log @Rewrote callbacks for new semantic. @ text @d31 1 a31 3 int xml_encode_uint32(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, size_t* used_buffer_size, va_list* args) d38 8 a45 1 xds_init_encoding_engine(8 + 9 + 10); d59 1 a59 1 /* Store the correct buffer size. */ d61 2 a62 1 *used_buffer_size = 8 + 9 + i; d67 1 a67 1 memmove(p, "", 8); d73 1 a73 1 memmove(p, "", 9); d75 1 a75 1 return XDS_OK; @ 1.1 log @Added XML implementations for uint32, int64, and uint64. @ text @d28 1 a28 1 #include a33 1 int rc; d35 3 d48 1 a48 1 /* Format value into buffer. */ d51 24 a74 4 rc = snprintf(buffer, buffer_size, "%u", value); if (rc < 0) return buffer_size*2; assert(rc >= 15); d76 1 a76 1 return rc; @