1 /* Part of SWI-Prolog 2 3 Author: Jan Wielemaker 4 E-mail: J.Wielemaker@vu.nl 5 WWW: http://www.swi-prolog.org 6 Copyright (c) 2006-2016, University of Amsterdam 7 VU University Amsterdam 8 All rights reserved. 9 10 Redistribution and use in source and binary forms, with or without 11 modification, are permitted provided that the following conditions 12 are met: 13 14 1. Redistributions of source code must retain the above copyright 15 notice, this list of conditions and the following disclaimer. 16 17 2. Redistributions in binary form must reproduce the above copyright 18 notice, this list of conditions and the following disclaimer in 19 the documentation and/or other materials provided with the 20 distribution. 21 22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 POSSIBILITY OF SUCH DAMAGE. 34 */ 35 36 #ifndef ATOM_H_INCLUDED 37 #define ATOM_H_INCLUDED 38 #include <SWI-Stream.h> 39 #include <SWI-Prolog.h> 40 #include <wchar.h> 41 42 #define MAX_LIKE_CHOICES 100 /* max *'s in like pattern */ 43 44 #define STR_MATCH_CASE 0x0 /* Default: perfect match */ 45 #define STR_MATCH_PLAIN 0x1 /* Same, also match qualifier */ 46 #define STR_MATCH_ICASE 0x2 /* case-insensitive */ 47 /* keep after ICASE */ 48 #define STR_MATCH_SUBSTRING 0x3 /* substring */ 49 #define STR_MATCH_WORD 0x4 /* whole word */ 50 #define STR_MATCH_PREFIX 0x5 /* prefix */ 51 #define STR_MATCH_LIKE 0x6 /* SeRQL *like* match */ 52 /* Keep after LIKE */ 53 #define STR_MATCH_LT 0x7 /* < */ 54 #define STR_MATCH_LE 0x8 /* =< */ 55 #define STR_MATCH_EQ 0x9 /* == */ 56 #define STR_MATCH_GE 0xA /* >= */ 57 #define STR_MATCH_GT 0xB /* > */ 58 #define STR_MATCH_BETWEEN 0xC /* X .. Y */ 59 /* MAX: 0xf (4 bits in triple) */ 60 61 typedef unsigned char charA; 62 typedef wchar_t charW; 63 64 typedef struct text 65 { const charA *a; 66 const charW *w; 67 size_t length; 68 } text; 69 70 71 typedef struct atom_info 72 { atom_t handle; 73 text text; 74 int resolved; 75 int rc; /* TRUE if text atom */ 76 } atom_info; 77 78 79 #ifdef COMPACT 80 typedef unsigned int atom_id; 81 #define ATOM_ID_SHIFT 7 /* Sync with SWI-Prolog */ 82 #if PLVERSION >= 70101 83 #define TAG_ATOM 0x00000005L 84 #else 85 #define TAG_ATOM 0x00000004L 86 #endif 87 88 #define ATOM_ID(a) ((atom_id)(((uintptr_t)(a))>>ATOM_ID_SHIFT)) 89 #define ID_ATOM(id) (((uintptr_t)(id)<<ATOM_ID_SHIFT)|TAG_ATOM) 90 #else 91 typedef atom_t atom_id; 92 #define ATOM_ID(a) (a) 93 #define ID_ATOM(id) (id) 94 #endif 95 96 COMMON(int) cmp_atoms(atom_t a1, atom_t a2); 97 COMMON(int) cmp_atom_info(atom_info *a1, atom_t a2); 98 COMMON(atom_t) first_atom(atom_t a, int match); 99 COMMON(int) match_atoms(int how, atom_t search, atom_t label); 100 COMMON(int) match_text(int how, text *search, text *label); 101 COMMON(unsigned int) atom_hash_case(atom_t a); 102 COMMON(int) atom_lang_matches(atom_t lang, atom_t pattern); 103 COMMON(int) fill_atom_info(atom_info *info); 104 COMMON(int) fetch_atom_text(atom_t atom, text *txt); 105 106 #endif /*ATOM_H_INCLUDED*/ 107