coan 4.2.4
|
00001 /*************************************************************************** 00002 * Copyright (C) 2007-2011 Mike Kinghan, imk@strudl.org * 00003 * All rights reserved. * 00004 * * 00005 * Contributed originally by Mike Kinghan, imk@strudl.org * 00006 * * 00007 * Redistribution and use in source and binary forms, with or without * 00008 * modification, are permitted provided that the following conditions * 00009 * are met: * 00010 * * 00011 * Redistributions of source code must retain the above copyright * 00012 * notice, this list of conditions and the following disclaimer. * 00013 * * 00014 * Redistributions in binary form must reproduce the above copyright * 00015 * notice, this list of conditions and the following disclaimer in the * 00016 * documentation and/or other materials provided with the distribution. * 00017 * * 00018 * Neither the name of Symbian Software Ltd. nor the names of its * 00019 * contributors may be used to endorse or promote products derived from * 00020 * this software without specific prior written permission. * 00021 * * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * 00023 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * 00024 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * 00025 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * 00026 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * 00027 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * 00028 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * 00029 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * 00030 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,* 00031 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF * 00032 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * 00033 * DAMAGE. * 00034 * * 00035 **************************************************************************/ 00036 #include "configured_symbols.h" 00037 #include "report.h" 00038 #include "io.h" 00039 00047 NO_PRIVATE_STATE(configured_symbols); 00052 IMPLEMENT(configured_symbols,USER_INITABLE); 00053 00054 DEFINE_USER_INIT(configured_symbols)(STATE_T(configured_symbols) * st_state) 00055 { 00056 st_state->global_sym_tab = ptr_set_new((comparator_t)symbol_compare, 00057 (dtor_t)symbol_dispose, 00058 (cloner_t)symbol_copy); 00059 00060 st_state->sym_tab = ptr_set_new((comparator_t)symbol_compare, 00061 (dtor_t)symbol_dispose, 00062 (cloner_t)symbol_copy); 00063 00064 } 00065 00066 DEFINE_USER_FINIS(configured_symbols)(STATE_T(configured_symbols) * st_state) 00067 { 00068 ptr_set_dispose(st_state->global_sym_tab); 00069 ptr_set_dispose(st_state->sym_tab); 00070 } 00073 /* API*/ 00074 00075 symbol_const_h 00076 configured_symbol_seek_const(char const **cpp) 00077 { 00078 canonical_string_h symname ; 00079 assert(cpp); 00080 symname = canonical_identifier(cpp); 00081 if (!*canonical_string_text(symname)) { 00082 bail( GRIPE_NOT_IDENTIFIER, 00083 "Identifier needed instead of \"%s\"", 00084 *cpp); 00085 } 00086 return configured_symbol_match_const(canonical_string_text(symname),0); 00087 } 00088 00089 symbol_h 00090 configured_symbol_seek(char const **cpp) 00091 { 00092 return (symbol_h)configured_symbol_seek_const(cpp); 00093 } 00094 00095 symbol_const_h 00096 configured_symbol_match_const(char const * symname, size_t namelen) 00097 { 00098 symbol_const_h sym = NULL; 00099 ptr_set_h sym_tab = INSOURCE ? 00100 GET_PUBLIC(configured_symbols,sym_tab) : GET_PUBLIC(configured_symbols,global_sym_tab); 00101 assert(symname); 00102 if (symname[0]) { 00103 if (!namelen) { 00104 namelen = strlen(symname); 00105 } 00106 sym = ptr_set_search(sym_tab,symname,namelen); 00107 if (sym) { 00108 debug(DBG_18, symbol_name(sym),symbol_definition(sym)); 00109 if (!symbol_is_configured(sym)) { 00110 sym = NULL; 00111 } 00112 } 00113 } 00114 return sym; 00115 } 00116 00117 symbol_h 00118 configured_symbol_match(char const * symname, size_t namelen) 00119 { 00120 return (symbol_h)configured_symbol_match_const(symname,namelen); 00121 } 00122 00123 line_type_t 00124 configured_symbol_add(bool define, symbol_h sym, char const *tail, char const **pend) 00125 { 00126 ptr_set_h sym_tab = INSOURCE ? GET_PUBLIC(configured_symbols,sym_tab) : GET_PUBLIC(configured_symbols,global_sym_tab); 00127 line_type_t retval = define ? symbol_define(sym,tail,pend) : symbol_undefine(sym,tail,pend); 00128 if (retval == LT_DIRECTIVE_KEEP && symbol_is_configured(sym)) { 00129 ptr_set_insert(sym_tab,sym); 00130 } 00131 return retval; 00132 } 00133 00134 void 00135 configured_symbols_rewind(void) 00136 { 00137 ptr_set_assign(GET_PUBLIC(configured_symbols,sym_tab),GET_PUBLIC(configured_symbols,global_sym_tab)); 00138 } 00139 00140 symbol_h 00141 configured_symbol_find(canonical_string_const_h cs, size_t *start) 00142 { 00143 size_t offset; 00144 ptr_set_const_h ps; 00145 symbol_h hit = NULL; 00146 assert(cs); 00147 assert(start); 00148 offset = *start; 00149 if (offset < canonical_string_length(cs)) { 00150 symbol_h * psym; 00151 symbol_h *pend; 00152 char const *text = canonical_string_text(cs) + offset; 00153 char const *textend = text + strlen(text); 00154 ps = GET_PUBLIC(configured_symbols,sym_tab); 00155 psym = (symbol_h *)ptr_set_begin_const(ps); 00156 pend = (symbol_h *)ptr_set_end_const(ps); 00157 for ( ;psym < pend && !hit; ++psym) { 00158 symbol_h sym = *psym; 00159 char const *symname = symbol_name(sym); 00160 char const *where = strstr(text,symname); 00161 if (where) { 00162 char const *symend = where + strlen(symname); 00163 if (((where == text) || !is_symbol_inner_char(where[-1])) 00164 && ((symend == textend) || !is_symbol_inner_char(symend[0]))) { 00165 *start = where - canonical_string_text(cs); 00166 hit = sym; 00167 } 00168 } 00169 } 00170 } 00171 return hit; 00172 } 00173 00174 00175 /* EOF*/