summaryrefslogtreecommitdiff
path: root/usr/src/cmd/msgfmt/gnu_msgfmt.h
blob: f171dcccfac275f0e70c4d0e061ac41f16539b95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#ifndef	_GNU_MSGFMT_H
#define	_GNU_MSGFMT_H

#pragma ident	"%Z%%M%	%I%	%E% SMI"

#include <stdio.h>
#include <limits.h>
#include <stdarg.h>
#include <locale.h>
#include <libintl.h>
#include <string.h>
#include <stdlib.h>
#include <iconv.h>
#include <ctype.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <alloca.h>
#include <unistd.h>
#include <errno.h>
#include "gnu_errmsg.h"
#include "common.h"

#ifdef	__cplusplus
extern "C" {
#endif

#define	_ENCODING_ALIAS_PATH	"/usr/lib/iconv/alias"
#define	DEST_CHARSET	"UTF-8"
#define	CHARSET_STR	"charset="
#define	CHARSET_LEN	8
#define	NPLURALS_STR	"nplurals="
#define	NPLURALS_LEN	9

#define	CBUFSIZE	128
#define	MBUFSIZE	128
#define	KBUFSIZE	16
#define	NBUFSIZE	8

#define	cur_po	(po_names[cur_po_index])

struct loc {
	off_t	off;	/* offset to the string */
	size_t	len;	/* length of the string including null-termination */
	unsigned int	num;	/* line number */
};

struct entry {
	int	no;			/* # of plural forms */
	unsigned int	num;	/* line number */
	char	*str;	/* string */
	size_t	len;	/* length of the string including null-termination */
	struct loc	*pos;
};

struct messages {
	char	*id;			/* msgid + (msgid_plural) */
	char	*str;			/* msgstr + (msgstr[n]) */
	size_t	id_len;			/* length of id */
	size_t	str_len;		/* length of str */
	unsigned int	hash;	/* hash value of msgid */
	unsigned int	num;	/* line number */
	int	po;		/* po index */
};

#define	DEF_MSG_NUM	100

struct catalog {
	int	header;			/* 1: header found, 0: header missing */
	char	*fname;			/* mo filename */
	struct messages	*msg;	/* ptr to the messages struct array */
	unsigned int	nmsg;	/* # of messages */
	unsigned int	msg_size;	/* message_size */
	unsigned int	fnum;	/* # of fuzzy translations */
	unsigned int	unum;	/* # of untranslated msgs */
	unsigned int	hash_size;	/* hash table size */
	unsigned int	nplurals;	/* # of plural forms */
	unsigned int	*thash;
	unsigned int	thash_size;
	struct catalog	*next;		/* next catalog */
};

struct msgtbl {
	unsigned int	len;
	unsigned int	offset;
};

extern int	yyparse(void);
extern int	yylex(void);
extern void	yyerror(const char *);
extern void	handle_domain(char *);
extern void	handle_comment(char *);
extern void	handle_message(struct entry *, struct entry *);
extern void	clear_state(void);
extern void	po_init(const char *);
extern void	po_fini(void);
extern void	catalog_init(const char *);

extern struct messages *search_msg(struct catalog *,
	const char *, unsigned int);
extern unsigned int	hashpjw(const char *);
extern unsigned int	find_prime(unsigned int);
extern void	output_all_gnu_mo_files(void);
extern unsigned int	get_hash_index(unsigned int *,
	unsigned int, unsigned int);
extern void	check_format(struct entry *, struct entry *, int);

extern char	**po_names;
extern int	cur_po_index;
extern int	po_error;
extern char	*inputdir;
extern char	*outfile;
extern int	cur_line;
extern int	fuzzy_flag;
extern int	verbose_flag;
extern int	strict_flag;
extern struct catalog	*catalog_head;
extern FILE	*fp;
extern iconv_t	cd;

#ifdef	__cplusplus
}
#endif

#endif /* _GNU_MSGFMT_H */