1 /* Part of XPCE --- The SWI-Prolog GUI toolkit 2 3 Author: Jan Wielemaker and Anjo Anjewierden 4 E-mail: jan@swi.psy.uva.nl 5 WWW: http://www.swi.psy.uva.nl/projects/xpce/ 6 Copyright (c) 1985-2002, University of Amsterdam 7 All rights reserved. 8 9 Redistribution and use in source and binary forms, with or without 10 modification, are permitted provided that the following conditions 11 are met: 12 13 1. Redistributions of source code must retain the above copyright 14 notice, this list of conditions and the following disclaimer. 15 16 2. Redistributions in binary form must reproduce the above copyright 17 notice, this list of conditions and the following disclaimer in 18 the documentation and/or other materials provided with the 19 distribution. 20 21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 31 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 POSSIBILITY OF SUCH DAMAGE. 33 */ 34 35 #ifndef _STR_H_INCLUDED 36 #define _STR_H_INCLUDED 37 38 #include <wchar.h> 39 #include <wctype.h> 40 #include <ctype.h> 41 42 #undef charA /* from pce-include.h */ 43 44 typedef unsigned char charA; /* 8-bit character */ 45 typedef wchar_t charW; /* wide character */ 46 47 #define STR_SIZE_BITS 30 48 #define STR_MAX_SIZE ((1L<<STR_SIZE_BITS)-1) 49 50 typedef struct _string 51 { union 52 { struct 53 { unsigned size : STR_SIZE_BITS; /* size indication (512 MB) */ 54 unsigned iswide : 1; /* char- or wide characters */ 55 unsigned readonly : 1; /* storage is externally managed */ 56 } f; 57 unsigned mask; 58 } hdr; 59 union 60 { charA * textA; 61 charW * textW; 62 } text_union; 63 } string; 64 65 #define s_text text_union.textA 66 #define s_textA text_union.textA 67 #define s_textW text_union.textW 68 #define s_size hdr.f.size 69 #define s_iswide hdr.f.iswide 70 #define s_readonly hdr.f.readonly 71 72 #define isstrA(s) ((s)->s_iswide == 0) /* 8-bit string */ 73 #define isstrW(s) ((s)->s_iswide == 1) /* 16-bit string */ 74 75 #define str_len(s) ((s)->s_size) /* length of the string */ 76 #define str_wsize(s) ((((s)->s_iswide \ 77 ? (s)->size * sizeof(charW) \ 78 : (s)->size) + sizeof(wint_t) - 1) / sizeof(wint_t)) 79 #define str_fetchA(s, i) (s->s_textA[(i)]) 80 #define str_fetchW(s, i) (s->s_textW[(i)]) 81 #define str_storeA(s, i, c) (s->s_textA[(i)] = (charA)(c)) 82 #define str_storeW(s, i, c) (s->s_textW[(i)] = (charW)(c)) 83 84 #define str_cphdr(t, f) do { (t)->hdr.mask = (f)->hdr.mask; \ 85 } while(0) 86 #define str_inithdr(s, w) do { (s)->hdr.mask = 0; \ 87 (s)->s_iswide = w; \ 88 } while(0) 89 90 #define str_datasize(s) (isstrA(s) ? (s)->s_size : (s)->s_size * sizeof(charW)) 91 92 #ifndef FALSE 93 #define FALSE 0 94 #define TRUE 1 95 #endif 96 97 98 /******************************* 99 * TMP STRINGS * 100 *******************************/ 101 102 typedef struct tmp_string 103 { string s; /* string itself */ 104 long allocated; /* allocated size */ 105 charA buffer[1024]; /* initial buffer */ 106 } tmp_string; 107 108 109 /******************************* 110 * ENCODING * 111 *******************************/ 112 113 typedef struct 114 { charA newline; 115 charA *tolower; 116 charA *toupper; 117 } str_encodingA, *StrEncodingA; 118 119 120 typedef struct 121 { charW newline; 122 int min_byte1; 123 int max_byte1; 124 charW **tolower; 125 charW **toupper; 126 } str_encodingW, *StrEncodingW; 127 128 #endif /*_STR_H_INCLUDED*/ 129