1 /* $Id$ 2 3 Part of SWI-Prolog 4 5 Author: Jan Wielemaker and Anjo Anjewierden 6 E-mail: jan@swi.psy.uva.nl 7 WWW: http://www.swi-prolog.org 8 Copyright (C): 1985-2002, University of Amsterdam 9 10 This library is free software; you can redistribute it and/or 11 modify it under the terms of the GNU Lesser General Public 12 License as published by the Free Software Foundation; either 13 version 2.1 of the License, or (at your option) any later version. 14 15 This library is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 Lesser General Public License for more details. 19 20 You should have received a copy of the GNU Lesser General Public 21 License along with this library; if not, write to the Free Software 22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 */ 24 25 #ifndef PL_TEXT_H_INCLUDED 26 #define PL_TEXT_H_INCLUDED 27 28 typedef enum 29 { PL_CHARS_MALLOC, /* malloced data */ 30 PL_CHARS_RING, /* stored in the buffer ring */ 31 PL_CHARS_HEAP, /* stored in program area (atoms) */ 32 PL_CHARS_STACK, /* stored on the global stack */ 33 PL_CHARS_LOCAL /* stored in in-line buffer */ 34 } PL_chars_alloc_t; 35 36 37 typedef struct 38 { union 39 { char *t; /* tranditional 8-bit char* */ 40 pl_wchar_t *w; /* wide character string */ 41 } text; 42 size_t length; 43 /* private stuff */ 44 IOENC encoding; /* how it is encoded */ 45 PL_chars_alloc_t storage; /* how it is stored */ 46 int canonical; /* TRUE: ENC_ISO_LATIN_1 or ENC_WCHAR */ 47 char buf[100]; /* buffer for simple stuff */ 48 } PL_chars_t; 49 50 #define PL_init_text(txt) \ 51 { (txt)->text.t = NULL; \ 52 (txt)->encoding = ENC_UNKNOWN; \ 53 (txt)->storage = PL_CHARS_LOCAL; \ 54 (txt)->canonical = FALSE; \ 55 } 56 57 extern int PL_unify_text(term_t term, term_t tail, PL_chars_t *text, int type); 58 extern int PL_unify_text_range(term_t term, PL_chars_t *text, 59 size_t from, size_t len, int type); 60 61 extern int PL_promote_text(PL_chars_t *text); 62 extern int PL_demote_text(PL_chars_t *text); 63 extern int PL_mb_text(PL_chars_t *text, int flags); 64 extern int PL_canonise_text(PL_chars_t *text); 65 66 extern int PL_cmp_text(PL_chars_t *t1, size_t o1, PL_chars_t *t2, size_t o2, 67 size_t len); 68 extern int PL_concat_text(int n, PL_chars_t **text, PL_chars_t *result); 69 70 extern void PL_free_text(PL_chars_t *text); 71 extern void PL_save_text(PL_chars_t *text, int flags); 72 73 extern int PL_get_text__LD(term_t l, PL_chars_t *text, int flags ARG_LD); 74 extern atom_t textToAtom(PL_chars_t *text); 75 extern word textToString(PL_chars_t *text); 76 77 extern IOSTREAM * Sopen_text(PL_chars_t *text, const char *mode); 78 extern void PL_text_recode(PL_chars_t *text, IOENC encoding); 79 80 81 #endif /*PL_TEXT_H_INCLUDED*/ 82