No empty .Rs/.Re
[netbsd-mini2440.git] / gnu / dist / gettext / gettext-tools / src / format.h
blob5f9dc28871a608727627115318553073fcdce323
1 /* Format strings.
2 Copyright (C) 2001-2004 Free Software Foundation, Inc.
3 Written by Bruno Haible <haible@clisp.cons.org>, 2001.
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19 #ifndef _FORMAT_H
20 #define _FORMAT_H
22 #include <stdbool.h>
24 #include "pos.h" /* Get lex_pos_ty. */
25 #include "message.h" /* Get NFORMATS. */
26 #include "error.h" /* Get fallback definition of __attribute__. */
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
34 /* This type of callback is responsible for showing an error. */
35 typedef void (*formatstring_error_logger_t) (const char *format, ...)
36 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
37 __attribute__ ((__format__ (__printf__, 1, 2)))
38 #endif
41 /* This structure describes a format string parser for a language. */
42 struct formatstring_parser
44 /* Parse the given string as a format string.
45 If translated is true, some extensions available only to msgstr but not
46 to msgid strings are recognized.
47 Return a freshly allocated structure describing
48 1. the argument types/names needed for the format string,
49 2. the total number of format directives.
50 Return NULL if the string is not a valid format string. In this case,
51 also set *invalid_reason to an error message explaining why. */
52 void * (*parse) (const char *string, bool translated, char **invalid_reason);
54 /* Free a format string descriptor, returned by parse(). */
55 void (*free) (void *descr);
57 /* Return the number of format directives.
58 A string that can be output literally has 0 format directives. */
59 int (*get_number_of_directives) (void *descr);
61 /* Verify that the argument types/names in msgid_descr and those in
62 msgstr_descr are the same (if equality=true), or (if equality=false)
63 that those of msgid_descr extend those of msgstr_descr (i.e.
64 msgstr_descr may omit some of the arguments of msgid_descr).
65 If not, signal an error using error_logger (only if error_logger != NULL)
66 and return true. Otherwise return false. */
67 bool (*check) (void *msgid_descr, void *msgstr_descr, bool equality, formatstring_error_logger_t error_logger, const char *pretty_msgstr);
70 /* Format string parsers, each defined in its own file. */
71 extern DLL_VARIABLE struct formatstring_parser formatstring_c;
72 extern DLL_VARIABLE struct formatstring_parser formatstring_objc;
73 extern DLL_VARIABLE struct formatstring_parser formatstring_sh;
74 extern DLL_VARIABLE struct formatstring_parser formatstring_python;
75 extern DLL_VARIABLE struct formatstring_parser formatstring_lisp;
76 extern DLL_VARIABLE struct formatstring_parser formatstring_elisp;
77 extern DLL_VARIABLE struct formatstring_parser formatstring_librep;
78 extern DLL_VARIABLE struct formatstring_parser formatstring_scheme;
79 extern DLL_VARIABLE struct formatstring_parser formatstring_smalltalk;
80 extern DLL_VARIABLE struct formatstring_parser formatstring_java;
81 extern DLL_VARIABLE struct formatstring_parser formatstring_csharp;
82 extern DLL_VARIABLE struct formatstring_parser formatstring_awk;
83 extern DLL_VARIABLE struct formatstring_parser formatstring_pascal;
84 extern DLL_VARIABLE struct formatstring_parser formatstring_ycp;
85 extern DLL_VARIABLE struct formatstring_parser formatstring_tcl;
86 extern DLL_VARIABLE struct formatstring_parser formatstring_perl;
87 extern DLL_VARIABLE struct formatstring_parser formatstring_perl_brace;
88 extern DLL_VARIABLE struct formatstring_parser formatstring_php;
89 extern DLL_VARIABLE struct formatstring_parser formatstring_gcc_internal;
90 extern DLL_VARIABLE struct formatstring_parser formatstring_qt;
92 /* Table of all format string parsers. */
93 extern DLL_VARIABLE struct formatstring_parser *formatstring_parsers[NFORMATS];
95 /* Returns an array of the ISO C 99 <inttypes.h> format directives and other
96 format flags or directives with a system dependent expansion contained in
97 the argument string. *intervalsp is assigned to a freshly allocated array
98 of intervals (startpos pointing to '<', endpos to the character after '>'),
99 and *lengthp is assigned to the number of intervals in this array. */
100 struct interval
102 size_t startpos;
103 size_t endpos;
105 extern void
106 get_sysdep_c_format_directives (const char *string, bool translated,
107 struct interval **intervalsp, size_t *lengthp);
109 /* Check whether both formats strings contain compatible format
110 specifications. Return true if there is an error. */
111 extern bool
112 check_msgid_msgstr_format (const char *msgid, const char *msgid_plural,
113 const char *msgstr, size_t msgstr_len,
114 enum is_format is_format[NFORMATS],
115 formatstring_error_logger_t error_logger);
118 #ifdef __cplusplus
120 #endif
123 #endif /* _FORMAT_H */