1/* Reading PO files. 2 Copyright (C) 1995-1998, 2000-2003, 2005-2006 Free Software Foundation, Inc. 3 This file was written by Bruno Haible <haible@clisp.cons.org>. 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2, or (at your option) 8 any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software Foundation, 17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 18 19#ifndef _READ_CATALOG_H 20#define _READ_CATALOG_H 21 22#include "message.h" 23#include "read-catalog-abstract.h" 24 25#include <stdbool.h> 26#include <stdio.h> 27 28 29/* For including this file in C++ mode. */ 30#ifdef __cplusplus 31# define this thiss 32#endif 33 34#ifdef __cplusplus 35extern "C" { 36#endif 37 38 39/* The following pair of structures cooperate to create a derived class from 40 class abstract_catalog_reader_ty. (See read-catalog-abstract.h for an 41 explanation.) It implements the default behaviour of reading a PO file 42 and converting it to an 'msgdomain_list_ty *'. */ 43 44/* Forward declaration. */ 45struct default_catalog_reader_ty; 46 47 48typedef struct default_catalog_reader_class_ty default_catalog_reader_class_ty; 49struct default_catalog_reader_class_ty 50{ 51 /* Methods inherited from superclass. */ 52 struct abstract_catalog_reader_class_ty super; 53 54 /* How to change the current domain. */ 55 void (*set_domain) (struct default_catalog_reader_ty *pop, char *name); 56 57 /* How to add a message to the list. */ 58 void (*add_message) (struct default_catalog_reader_ty *pop, 59 char *msgctxt, 60 char *msgid, lex_pos_ty *msgid_pos, char *msgid_plural, 61 char *msgstr, size_t msgstr_len, lex_pos_ty *msgstr_pos, 62 char *prev_msgctxt, 63 char *prev_msgid, 64 char *prev_msgid_plural, 65 bool force_fuzzy, bool obsolete); 66 67 /* How to modify a new message before adding it to the list. */ 68 void (*frob_new_message) (struct default_catalog_reader_ty *pop, 69 message_ty *mp, 70 const lex_pos_ty *msgid_pos, 71 const lex_pos_ty *msgstr_pos); 72}; 73 74 75#define DEFAULT_CATALOG_READER_TY \ 76 ABSTRACT_CATALOG_READER_TY \ 77 \ 78 /* If true, pay attention to comments and filepos comments. */ \ 79 bool handle_comments; \ 80 \ 81 /* If true, remember comments for file name and line number for each \ 82 msgid, if present in the reference input. */ \ 83 bool handle_filepos_comments; \ 84 \ 85 /* If false, domain directives lead to an error messsage. */ \ 86 bool allow_domain_directives; \ 87 \ 88 /* If false, duplicate msgids in the same domain and file generate an \ 89 error. If true, such msgids are allowed; the caller should treat \ 90 them appropriately. */ \ 91 bool allow_duplicates; \ 92 \ 93 /* If true, allow duplicates if they have the same translation. */ \ 94 bool allow_duplicates_if_same_msgstr; \ 95 \ 96 /* List of messages already appeared in the current file. */ \ 97 msgdomain_list_ty *mdlp; \ 98 \ 99 /* Name of domain we are currently examining. */ \ 100 const char *domain; \ 101 \ 102 /* List of messages belonging to the current domain. */ \ 103 message_list_ty *mlp; \ 104 \ 105 /* Accumulate comments for next message directive. */ \ 106 string_list_ty *comment; \ 107 string_list_ty *comment_dot; \ 108 \ 109 /* Accumulate filepos comments for the next message directive. */ \ 110 size_t filepos_count; \ 111 lex_pos_ty *filepos; \ 112 \ 113 /* Flags transported in special comments. */ \ 114 bool is_fuzzy; \ 115 enum is_format is_format[NFORMATS]; \ 116 enum is_wrap do_wrap; \ 117 118typedef struct default_catalog_reader_ty default_catalog_reader_ty; 119struct default_catalog_reader_ty 120{ 121 DEFAULT_CATALOG_READER_TY 122}; 123 124extern void default_constructor (abstract_catalog_reader_ty *that); 125extern void default_destructor (abstract_catalog_reader_ty *that); 126extern void default_parse_brief (abstract_catalog_reader_ty *that); 127extern void default_parse_debrief (abstract_catalog_reader_ty *that); 128extern void default_directive_domain (abstract_catalog_reader_ty *that, 129 char *name); 130extern void default_directive_message (abstract_catalog_reader_ty *that, 131 char *msgctxt, 132 char *msgid, 133 lex_pos_ty *msgid_pos, 134 char *msgid_plural, 135 char *msgstr, size_t msgstr_len, 136 lex_pos_ty *msgstr_pos, 137 char *prev_msgctxt, 138 char *prev_msgid, 139 char *prev_msgid_plural, 140 bool force_fuzzy, bool obsolete); 141extern void default_comment (abstract_catalog_reader_ty *that, const char *s); 142extern void default_comment_dot (abstract_catalog_reader_ty *that, 143 const char *s); 144extern void default_comment_filepos (abstract_catalog_reader_ty *that, 145 const char *name, size_t line); 146extern void default_comment_special (abstract_catalog_reader_ty *that, 147 const char *s); 148extern void default_set_domain (default_catalog_reader_ty *this, char *name); 149extern void default_add_message (default_catalog_reader_ty *this, 150 char *msgctxt, 151 char *msgid, 152 lex_pos_ty *msgid_pos, 153 char *msgid_plural, 154 char *msgstr, size_t msgstr_len, 155 lex_pos_ty *msgstr_pos, 156 char *prev_msgctxt, 157 char *prev_msgid, 158 char *prev_msgid_plural, 159 bool force_fuzzy, bool obsolete); 160 161/* Allocate a fresh default_catalog_reader_ty (or derived class) instance and 162 call its constructor. */ 163extern default_catalog_reader_ty * 164 default_catalog_reader_alloc (default_catalog_reader_class_ty *method_table); 165 166 167/* If nonzero, remember comments for file name and line number for each 168 msgid, if present in the reference input. Defaults to true. */ 169extern DLL_VARIABLE int line_comment; 170 171/* If false, duplicate msgids in the same domain and file generate an error. 172 If true, such msgids are allowed; the caller should treat them 173 appropriately. Defaults to false. */ 174extern DLL_VARIABLE bool allow_duplicates; 175 176/* Read the input file from a stream. Returns a list of messages. */ 177extern msgdomain_list_ty * 178 read_catalog_stream (FILE *fp, 179 const char *real_filename, 180 const char *logical_filename, 181 catalog_input_format_ty input_syntax); 182 183/* Read the input file with the name INPUT_NAME. The ending .po is added 184 if necessary. If INPUT_NAME is not an absolute file name and the file is 185 not found, the list of directories in "dir-list.h" is searched. Returns 186 a list of messages. */ 187extern msgdomain_list_ty * 188 read_catalog_file (const char *input_name, 189 catalog_input_format_ty input_syntax); 190 191 192#ifdef __cplusplus 193} 194#endif 195 196 197#endif /* _READ_CATALOG_H */ 198