xref: /illumos-gate/usr/src/cmd/msgfmt/gnu_msgfmt.h (revision e3ae4b35c024af1196582063ecee3ab79367227d)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_GNU_MSGFMT_H
28 #define	_GNU_MSGFMT_H
29 
30 #include <stdio.h>
31 #include <limits.h>
32 #include <stdarg.h>
33 #include <locale.h>
34 #include <libintl.h>
35 #include <string.h>
36 #include <stdlib.h>
37 #include <iconv.h>
38 #include <ctype.h>
39 #include <fcntl.h>
40 #include <sys/types.h>
41 #include <sys/stat.h>
42 #include <sys/mman.h>
43 #include <alloca.h>
44 #include <unistd.h>
45 #include <errno.h>
46 #include "gnu_errmsg.h"
47 #include "common.h"
48 
49 #ifdef	__cplusplus
50 extern "C" {
51 #endif
52 
53 #define	_ENCODING_ALIAS_PATH	"/usr/lib/iconv/alias"
54 #define	DEST_CHARSET	"UTF-8"
55 #define	CHARSET_STR	"charset="
56 #define	CHARSET_LEN	8
57 #define	NPLURALS_STR	"nplurals="
58 #define	NPLURALS_LEN	9
59 
60 #define	CBUFSIZE	128
61 #define	MBUFSIZE	128
62 #define	KBUFSIZE	16
63 #define	NBUFSIZE	8
64 
65 #define	cur_po	(po_names[cur_po_index])
66 
67 struct loc {
68 	off_t	off;	/* offset to the string */
69 	size_t	len;	/* length of the string including null-termination */
70 	unsigned int	num;	/* line number */
71 };
72 
73 struct entry {
74 	int	no;			/* # of plural forms */
75 	unsigned int	num;	/* line number */
76 	char	*str;	/* string */
77 	size_t	len;	/* length of the string including null-termination */
78 	struct loc	*pos;
79 };
80 
81 struct messages {
82 	char	*id;			/* msgid + (msgid_plural) */
83 	char	*str;			/* msgstr + (msgstr[n]) */
84 	size_t	id_len;			/* length of id */
85 	size_t	str_len;		/* length of str */
86 	unsigned int	hash;	/* hash value of msgid */
87 	unsigned int	num;	/* line number */
88 	int	po;		/* po index */
89 };
90 
91 #define	DEF_MSG_NUM	100
92 
93 struct catalog {
94 	int	header;			/* 1: header found, 0: header missing */
95 	char	*fname;			/* mo filename */
96 	struct messages	*msg;	/* ptr to the messages struct array */
97 	unsigned int	nmsg;	/* # of messages */
98 	unsigned int	msg_size;	/* message_size */
99 	unsigned int	fnum;	/* # of fuzzy translations */
100 	unsigned int	unum;	/* # of untranslated msgs */
101 	unsigned int	hash_size;	/* hash table size */
102 	unsigned int	nplurals;	/* # of plural forms */
103 	unsigned int	*thash;
104 	unsigned int	thash_size;
105 	struct catalog	*next;		/* next catalog */
106 };
107 
108 struct msgtbl {
109 	unsigned int	len;
110 	unsigned int	offset;
111 };
112 
113 extern int	yyparse(void);
114 extern int	yylex(void);
115 extern void	yyerror(const char *);
116 extern void	handle_domain(char *);
117 extern void	handle_comment(char *);
118 extern void	handle_message(struct entry *, struct entry *);
119 extern void	clear_state(void);
120 extern void	po_init(const char *);
121 extern void	po_fini(void);
122 extern void	catalog_init(const char *);
123 
124 extern struct messages *search_msg(struct catalog *,
125 	const char *, unsigned int);
126 extern unsigned int	hashpjw(const char *);
127 extern unsigned int	find_prime(unsigned int);
128 extern void	output_all_gnu_mo_files(void);
129 extern unsigned int	get_hash_index(unsigned int *,
130 	unsigned int, unsigned int);
131 extern void	check_format(struct entry *, struct entry *, int);
132 
133 extern char	**po_names;
134 extern int	cur_po_index;
135 extern int	po_error;
136 extern char	*inputdir;
137 extern char	*outfile;
138 extern int	cur_line;
139 extern int	fuzzy_flag;
140 extern int	verbose_flag;
141 extern int	strict_flag;
142 extern struct catalog	*catalog_head;
143 extern FILE	*fp;
144 extern iconv_t	cd;
145 
146 #ifdef	__cplusplus
147 }
148 #endif
149 
150 #endif /* _GNU_MSGFMT_H */
151