xref: /titanic_41/usr/src/cmd/msgfmt/gnu_msgfmt.h (revision 7c2fbfb345896881c631598ee3852ce9ce33fb07)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <stdio.h>
33 #include <limits.h>
34 #include <stdarg.h>
35 #include <locale.h>
36 #include <libintl.h>
37 #include <string.h>
38 #include <stdlib.h>
39 #include <iconv.h>
40 #include <ctype.h>
41 #include <fcntl.h>
42 #include <sys/types.h>
43 #include <sys/stat.h>
44 #include <sys/mman.h>
45 #include <alloca.h>
46 #include <unistd.h>
47 #include <errno.h>
48 #include "gnu_errmsg.h"
49 #include "common.h"
50 
51 #ifdef	__cplusplus
52 extern "C" {
53 #endif
54 
55 #define	_ENCODING_ALIAS_PATH	"/usr/lib/iconv/alias"
56 #define	DEST_CHARSET	"UTF-8"
57 #define	CHARSET_STR	"charset="
58 #define	CHARSET_LEN	8
59 #define	NPLURALS_STR	"nplurals="
60 #define	NPLURALS_LEN	9
61 
62 #define	CBUFSIZE	128
63 #define	MBUFSIZE	128
64 #define	KBUFSIZE	16
65 #define	NBUFSIZE	8
66 
67 #define	cur_po	(po_names[cur_po_index])
68 
69 struct loc {
70 	off_t	off;	/* offset to the string */
71 	size_t	len;	/* length of the string including null-termination */
72 	unsigned int	num;	/* line number */
73 };
74 
75 struct entry {
76 	int	no;			/* # of plural forms */
77 	unsigned int	num;	/* line number */
78 	char	*str;	/* string */
79 	size_t	len;	/* length of the string including null-termination */
80 	struct loc	*pos;
81 };
82 
83 struct messages {
84 	char	*id;			/* msgid + (msgid_plural) */
85 	char	*str;			/* msgstr + (msgstr[n]) */
86 	size_t	id_len;			/* length of id */
87 	size_t	str_len;		/* length of str */
88 	unsigned int	hash;	/* hash value of msgid */
89 	unsigned int	num;	/* line number */
90 	int	po;		/* po index */
91 };
92 
93 #define	DEF_MSG_NUM	100
94 
95 struct catalog {
96 	int	header;			/* 1: header found, 0: header missing */
97 	char	*fname;			/* mo filename */
98 	struct messages	*msg;	/* ptr to the messages struct array */
99 	unsigned int	nmsg;	/* # of messages */
100 	unsigned int	msg_size;	/* message_size */
101 	unsigned int	fnum;	/* # of fuzzy translations */
102 	unsigned int	unum;	/* # of untranslated msgs */
103 	unsigned int	hash_size;	/* hash table size */
104 	unsigned int	nplurals;	/* # of plural forms */
105 	unsigned int	*thash;
106 	unsigned int	thash_size;
107 	struct catalog	*next;		/* next catalog */
108 };
109 
110 struct msgtbl {
111 	unsigned int	len;
112 	unsigned int	offset;
113 };
114 
115 extern int	yyparse(void);
116 extern int	yylex(void);
117 extern void	yyerror(const char *);
118 extern void	handle_domain(char *);
119 extern void	handle_comment(char *);
120 extern void	handle_message(struct entry *, struct entry *);
121 extern void	clear_state(void);
122 extern void	po_init(const char *);
123 extern void	po_fini(void);
124 extern void	catalog_init(const char *);
125 
126 extern struct messages *search_msg(struct catalog *,
127 	const char *, unsigned int);
128 extern unsigned int	hashpjw(const char *);
129 extern unsigned int	find_prime(unsigned int);
130 extern void	output_all_gnu_mo_files(void);
131 extern unsigned int	get_hash_index(unsigned int *,
132 	unsigned int, unsigned int);
133 extern void	check_format(struct entry *, struct entry *, int);
134 
135 extern char	**po_names;
136 extern int	cur_po_index;
137 extern int	po_error;
138 extern char	*inputdir;
139 extern char	*outfile;
140 extern int	cur_line;
141 extern int	fuzzy_flag;
142 extern int	verbose_flag;
143 extern int	strict_flag;
144 extern struct catalog	*catalog_head;
145 extern FILE	*fp;
146 extern iconv_t	cd;
147 
148 #ifdef	__cplusplus
149 }
150 #endif
151 
152 #endif /* _GNU_MSGFMT_H */
153