1/* GNU gettext - internationalization aids 2 Copyright (C) 1995-1998, 2000-2004 Free Software Foundation, Inc. 3 4 This file was written by Peter Miller <millerp@canb.auug.org.au> 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; if not, write to the Free SoftwareFoundation, 18 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 19 20#ifndef _MESSAGE_H 21#define _MESSAGE_H 22 23#include "str-list.h" 24#include "pos.h" 25#include "hash.h" 26 27#include <stdbool.h> 28 29 30#ifdef __cplusplus 31extern "C" { 32#endif 33 34 35/* According to Sun's Uniforum proposal the default message domain is 36 named 'messages'. */ 37#define MESSAGE_DOMAIN_DEFAULT "messages" 38 39 40/* Kinds of format strings. */ 41enum format_type 42{ 43 format_c, 44 format_objc, 45 format_sh, 46 format_python, 47 format_lisp, 48 format_elisp, 49 format_librep, 50 format_scheme, 51 format_smalltalk, 52 format_java, 53 format_csharp, 54 format_awk, 55 format_pascal, 56 format_ycp, 57 format_tcl, 58 format_perl, 59 format_perl_brace, 60 format_php, 61 format_gcc_internal, 62 format_qt 63}; 64#define NFORMATS 20 /* Number of format_type enum values. */ 65extern DLL_VARIABLE const char *const format_language[NFORMATS]; 66extern DLL_VARIABLE const char *const format_language_pretty[NFORMATS]; 67 68/* Is current msgid a format string? */ 69enum is_format 70{ 71 undecided, 72 yes, 73 no, 74 yes_according_to_context, 75 possible, 76 impossible 77}; 78 79extern bool 80 possible_format_p (enum is_format); 81 82 83/* Is current msgid wrappable? */ 84#if 0 85enum is_wrap 86{ 87 undecided, 88 yes, 89 no 90}; 91#else /* HACK - C's enum concept is so stupid */ 92#define is_wrap is_format 93#endif 94 95 96typedef struct message_ty message_ty; 97struct message_ty 98{ 99 /* The msgid string. */ 100 const char *msgid; 101 102 /* The msgid's plural, if present. */ 103 const char *msgid_plural; 104 105 /* The msgstr strings. */ 106 const char *msgstr; 107 /* The number of bytes in msgstr, including the terminating NUL. */ 108 size_t msgstr_len; 109 110 /* Position in the source PO file. */ 111 lex_pos_ty pos; 112 113 /* Plain comments (#) appearing before the message. */ 114 string_list_ty *comment; 115 116 /* Extracted comments (#.) appearing before the message. */ 117 string_list_ty *comment_dot; 118 119 /* File position comments (#:) appearing before the message, one for 120 each unique file position instance, sorted by file name and then 121 by line. */ 122 size_t filepos_count; 123 lex_pos_ty *filepos; 124 125 /* Informations from special comments (e.g. generated by msgmerge). */ 126 bool is_fuzzy; 127 enum is_format is_format[NFORMATS]; 128 129 /* Do we want the string to be wrapped in the emitted PO file? */ 130 enum is_wrap do_wrap; 131 132 /* If set the message is obsolete and while writing out it should be 133 commented out. */ 134 bool obsolete; 135 136 /* Used for checking that messages have been used, in the msgcmp, 137 msgmerge, msgcomm and msgcat programs. */ 138 int used; 139 140 /* Used for looking up the target message, in the msgcat program. */ 141 message_ty *tmp; 142 143 /* Used for combining alternative translations, in the msgcat program. */ 144 int alternative_count; 145 struct altstr 146 { 147 const char *msgstr; 148 size_t msgstr_len; 149 const char *msgstr_end; 150 string_list_ty *comment; 151 string_list_ty *comment_dot; 152 char *id; 153 } 154 *alternative; 155}; 156 157extern message_ty * 158 message_alloc (const char *msgid, const char *msgid_plural, 159 const char *msgstr, size_t msgstr_len, 160 const lex_pos_ty *pp); 161extern void 162 message_free (message_ty *mp); 163extern void 164 message_comment_append (message_ty *mp, const char *comment); 165extern void 166 message_comment_dot_append (message_ty *mp, const char *comment); 167extern void 168 message_comment_filepos (message_ty *mp, const char *name, size_t line); 169extern message_ty * 170 message_copy (message_ty *mp); 171 172 173typedef struct message_list_ty message_list_ty; 174struct message_list_ty 175{ 176 message_ty **item; 177 size_t nitems; 178 size_t nitems_max; 179 bool use_hashtable; 180 hash_table htable; /* Table mapping msgid to 'message_ty *'. */ 181}; 182 183/* Create a fresh message list. 184 If USE_HASHTABLE is true, a hash table will be used to speed up 185 message_list_search(). USE_HASHTABLE can only be set to true if it is 186 known that the message list will not contain duplicate msgids. */ 187extern message_list_ty * 188 message_list_alloc (bool use_hashtable); 189extern void 190 message_list_free (message_list_ty *mlp); 191extern void 192 message_list_append (message_list_ty *mlp, message_ty *mp); 193extern void 194 message_list_prepend (message_list_ty *mlp, message_ty *mp); 195extern void 196 message_list_insert_at (message_list_ty *mlp, size_t n, message_ty *mp); 197extern void 198 message_list_delete_nth (message_list_ty *mlp, size_t n); 199typedef bool message_predicate_ty (const message_ty *mp); 200extern void 201 message_list_remove_if_not (message_list_ty *mlp, 202 message_predicate_ty *predicate); 203/* Recompute the hash table of a message list after the msgids changed. */ 204extern bool 205 message_list_msgids_changed (message_list_ty *mlp); 206extern message_ty * 207 message_list_search (message_list_ty *mlp, const char *msgid); 208extern message_ty * 209 message_list_search_fuzzy (message_list_ty *mlp, const char *msgid); 210 211 212typedef struct message_list_list_ty message_list_list_ty; 213struct message_list_list_ty 214{ 215 message_list_ty **item; 216 size_t nitems; 217 size_t nitems_max; 218}; 219 220extern message_list_list_ty * 221 message_list_list_alloc (void); 222extern void 223 message_list_list_free (message_list_list_ty *mllp); 224extern void 225 message_list_list_append (message_list_list_ty *mllp, 226 message_list_ty *mlp); 227extern void 228 message_list_list_append_list (message_list_list_ty *mllp, 229 message_list_list_ty *mllp2); 230extern message_ty * 231 message_list_list_search (message_list_list_ty *mllp, 232 const char *msgid); 233extern message_ty * 234 message_list_list_search_fuzzy (message_list_list_ty *mllp, 235 const char *msgid); 236 237 238typedef struct msgdomain_ty msgdomain_ty; 239struct msgdomain_ty 240{ 241 const char *domain; 242 message_list_ty *messages; 243}; 244 245extern msgdomain_ty * 246 msgdomain_alloc (const char *domain, bool use_hashtable); 247extern void 248 msgdomain_free (msgdomain_ty *mdp); 249 250 251typedef struct msgdomain_list_ty msgdomain_list_ty; 252struct msgdomain_list_ty 253{ 254 msgdomain_ty **item; 255 size_t nitems; 256 size_t nitems_max; 257 bool use_hashtable; 258 const char *encoding; /* canonicalized encoding or NULL if unknown */ 259}; 260 261extern msgdomain_list_ty * 262 msgdomain_list_alloc (bool use_hashtable); 263extern void 264 msgdomain_list_free (msgdomain_list_ty *mdlp); 265extern void 266 msgdomain_list_append (msgdomain_list_ty *mdlp, msgdomain_ty *mdp); 267extern void 268 msgdomain_list_append_list (msgdomain_list_ty *mdlp, 269 msgdomain_list_ty *mdlp2); 270extern message_list_ty * 271 msgdomain_list_sublist (msgdomain_list_ty *mdlp, const char *domain, 272 bool create); 273extern message_ty * 274 msgdomain_list_search (msgdomain_list_ty *mdlp, const char *msgid); 275extern message_ty * 276 msgdomain_list_search_fuzzy (msgdomain_list_ty *mdlp, const char *msgid); 277 278 279#ifdef __cplusplus 280} 281#endif 282 283 284#endif /* message.h */ 285