hnjhyphen.h /size: 3631 b    last modification: 2025-02-21 11:03
1/*
2    See license.txt in the root of this project.
3*/
4
5/*
6
7    The code is derived from LibHnj which is is dual licensed under LGPL and MPL. Boilerplate for
8    both licenses follows.
9
10*/
11
12/*
13
14    LibHnj - a library for high quality hyphenation and justification
15
16    Copyright (C) 1998 Raph Levien, (C) 2001 ALTLinux, Moscow
17
18    This library is free software; you can redistribute it and/or modify it under the terms of the
19    GNU Library General Public License as published by the Free Software Foundation; either version
20    2 of the License, or (at your option) any later version.
21
22    This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
23    without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
24    the GNU Library General Public License for more details.
25
26    You should have received a copy of the GNU Library General Public License along with this
27    library; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28    Boston, MA 02111-1307 USA.
29
30*/
31
32/*
33    The contents of this file are subject to the Mozilla Public License Version 1.0 (the "MPL");
34    you may not use this file except in compliance with the MPL. You may obtain a copy of the MPL
35    at http://www.mozilla.org/MPL/
36
37    Software distributed under the MPL is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
38    KIND, either express or implied. See the MPL for the specific language governing rights and
39    limitations under the MPL.
40
41 */
42
43# ifndef LMT_HNJHYPHEN_H
44# define LMT_HNJHYPHEN_H
45
46/*tex
47
48    First some type definitions and a little bit of a hash table implementation. This simply maps
49    strings to state numbers. In \LUATEX\ we have node related code in |hnjhyphen.c| but in
50    \LUAMETATEX\ we moved that to |texlanguage.c| so we need to make some type definitions public.
51
52*/
53
54# define HNJ_MAXPATHS  40960
55# define HNJ_HASH_SIZE 31627
56# define HNJ_MAX_CHARS   256
57# define HNJ_MAX_NAME     24
58
59typedef struct _hjn_hashtable    hjn_hashtable;
60typedef struct _hjn_hashentry    hjn_hashentry;
61typedef struct _hjn_hashiterator hjn_hashiterator;
62typedef union  _hjn_hashvalue    hjn_hashvalue;
63
64/*tex A cheap, but effective, hack. */
65
66struct _hjn_hashtable {
67    hjn_hashentry *entries[HNJ_HASH_SIZE];
68};
69
70union _hjn_hashvalue {
71    char *hyppat;
72    int   state;
73    int   padding;
74};
75
76struct _hjn_hashentry {
77    hjn_hashentry *next;
78    unsigned char *key;
79    hjn_hashvalue  u;
80};
81
82struct _hjn_hashiterator {
83    hjn_hashentry **e;
84    hjn_hashentry  *cur;
85    int             ndx;
86    int             padding;
87};
88
89/*tex The state state machine. */
90
91typedef struct _hjn_transition hjn_transition;
92typedef struct _hjn_state      hjn_state;
93typedef struct _hjn_dictionary hjn_dictionary;
94
95struct _hjn_transition {
96    int uni_ch;
97    int new_state;
98};
99
100struct _hjn_state {
101    char           *match;
102    int             fallback_state;
103    int             num_trans;
104    hjn_transition *trans;
105};
106
107struct _hjn_dictionary {
108    int            num_states;
109    int            pat_length;
110    char           cset[HNJ_MAX_NAME];
111    hjn_state     *states;
112    hjn_hashtable *patterns;
113    hjn_hashtable *merged;
114    hjn_hashtable *state_num;
115};
116
117extern hjn_dictionary *hnj_dictionary_new      (void);
118extern void            hnj_dictionary_load     (hjn_dictionary *dict, const unsigned char *fn, int trace);
119extern void            hnj_dictionary_free     (hjn_dictionary *dict);
120extern void            hnj_dictionary_clear    (hjn_dictionary *dict);
121extern unsigned char  *hnj_dictionary_tostring (hjn_dictionary *dict);
122
123# endif
124