/* ----------------------------------------------------------------------- * * * Copyright 1996-2019 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following * conditions are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * CONTRIBUTORS "AS IS" AND ANY EXPRESS 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 COPYRIGHT OWNER OR * 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. * * ----------------------------------------------------------------------- */ /* * quote.c */ #include "compiler.h" #include "nasmlib.h" #include "quote.h" #include "nctype.h" #include "error.h" /* * Create a NASM quoted string in newly allocated memory. Update the * *lenp parameter with the output length (sans final NUL). */ char *nasm_quote(const char *str, size_t *lenp) { … } static unsigned char *emit_utf8(unsigned char *q, uint32_t v) { … } static inline uint32_t ctlbit(uint32_t v) { … } #define CTL_ERR(c) … #define EMIT_UTF8(c) … #define EMIT … /* * Same as nasm_quote, but take the length of a C string; * the lenp argument is optional. */ char *nasm_quote_cstr(const char *str, size_t *lenp) { … } /* * Do an *in-place* dequoting of the specified string, returning the * resulting length (which may be containing embedded nulls.) * * In-place replacement is possible since the unquoted length is always * shorter than or equal to the quoted length. * * *ep points to the final quote, or to the null if improperly quoted. * * Issue an error if the string contains control characters * corresponding to bits set in badctl; in that case, the output * string, but not *ep, is truncated before the first invalid * character. */ static size_t nasm_unquote_common(char *str, char **ep, const uint32_t badctl) { … } #undef EMIT size_t nasm_unquote(char *str, char **ep) { … } size_t nasm_unquote_cstr(char *str, char **ep) { … } /* * Find the end of a quoted string; returns the pointer to the terminating * character (either the ending quote or the null character, if unterminated.) * If the input is not a quoted string, return NULL. */ char *nasm_skip_string(const char *str) { … }