summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c/luatexdir/lang/hyphen.w
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/texk/web2c/luatexdir/lang/hyphen.w')
-rw-r--r--Build/source/texk/web2c/luatexdir/lang/hyphen.w142
1 files changed, 69 insertions, 73 deletions
diff --git a/Build/source/texk/web2c/luatexdir/lang/hyphen.w b/Build/source/texk/web2c/luatexdir/lang/hyphen.w
index a5ad227d740..3188473c446 100644
--- a/Build/source/texk/web2c/luatexdir/lang/hyphen.w
+++ b/Build/source/texk/web2c/luatexdir/lang/hyphen.w
@@ -1,34 +1,36 @@
+% hyphen.w
+%
% Libhnj is dual licensed under LGPL and MPL. Boilerplate for both
% licenses follows.
-%
-%
+%
+%
% LibHnj - a library for high quality hyphenation and justification
-% Copyright (C) 1998 Raph Levien,
-% (C) 2001 ALTLinux, Moscow (http://www.alt-linux.org),
+% Copyright (C) 1998 Raph Levien,
+% (C) 2001 ALTLinux, Moscow (http://www.alt-linux.org),
% (C) 2001 Peter Novodvorsky (nidd@@cs.msu.su)
-%
+%
% This library is free software; you can redistribute it and/or
% modify it under the terms of the GNU Library General Public
% License as published by the Free Software Foundation; either
% version 2 of the License, or (at your option) any later version.
-%
+%
% This library is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
% Library General Public License for more details.
-%
+%
% You should have received a copy of the GNU Library General Public
-% License along with this library; if not, write to the
-% Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+% License along with this library; if not, write to the
+% Free Software Foundation, Inc., 59 Temple Place - Suite 330,
% Boston, MA 02111-1307 USA.
-%
-%
-%
+%
+%
+%
% The contents of this file are subject to the Mozilla Public License
% Version 1.0 (the "MPL"); you may not use this file except in
% compliance with the MPL. You may obtain a copy of the MPL at
% http://www.mozilla.org/MPL/
-%
+%
% Software distributed under the MPL is distributed on an "AS IS" basis,
% WITHOUT WARRANTY OF ANY KIND, either express or implied. See the MPL
% for the specific language governing rights and limitations under the
@@ -36,6 +38,10 @@
@ @c
+static const char _svn_version[] =
+ "$Id: hyphen.w 4599 2013-03-19 15:41:07Z taco $ "
+ "$URL: https://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lang/hyphen.w $";
+
#include <stdlib.h> /* for NULL, malloc */
#include <stdio.h> /* for fprintf */
#include <string.h> /* for strdup */
@@ -54,11 +60,6 @@
#include "lang/hnjalloc.h"
#include "lang/hyphen.h"
-@ @c
-static const char _svn_version[] =
- "$Id: hyphen.w 3831 2010-08-25 04:35:34Z taco $ "
-"$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lang/hyphen.w $";
-
@ TODO: should be moved to separate library
@c
@@ -74,13 +75,6 @@ static unsigned char *hnj_strdup(const unsigned char *s)
return new;
}
-static int is_utf8_follow(unsigned char c)
-{
- if (c >= 0x80 && c < 0xC0)
- return 1;
- return 0;
-}
-
@* Type definitions.
@ a little bit of a hash table implementation. This simply maps strings
@@ -589,7 +583,6 @@ for a hyphenation point between characters
void hnj_hyphen_load(HyphenDict * dict, const unsigned char *f)
{
int state_num, last_state;
- int i, j = 0;
int ch;
int found;
HashEntry *e;
@@ -603,7 +596,7 @@ void hnj_hyphen_load(HyphenDict * dict, const unsigned char *f)
unsigned char *pat;
char *org;
while ((format = next_pattern(&l, &f)) != NULL) {
- int i, j, e;
+ int i, j, e1;
if (l>=255) {
help1("Individual patterns should not be longer than 254 bytes total.");
print_err("Pattern of enormous length ignored");
@@ -633,31 +626,31 @@ void hnj_hyphen_load(HyphenDict * dict, const unsigned char *f)
repl = hnj_strdup(repl + 1);
}
#endif
- for (i = 0, j = 0, e = 0; (unsigned) i < l; i++) {
+ for (i = 0, j = 0, e1 = 0; (unsigned) i < l; i++) {
if (format[i] >= '0' && format[i] <= '9')
j++;
if (is_utf8_follow(format[i]))
- e++;
+ e1++;
}
- /* |l-e| => number of {\it characters} not {\it bytes} */
+ /* |l-e1| => number of {\it characters} not {\it bytes} */
/* |l-j| => number of pattern bytes */
- /* |l-e-j| => number of pattern characters */
+ /* |l-e1-j| => number of pattern characters */
pat = (unsigned char *) malloc((1 + l - (size_t) j));
- org = (char *) malloc((size_t) (2 + l - (size_t) e - (size_t) j));
+ org = (char *) malloc((size_t) (2 + l - (size_t) e1 - (size_t) j));
/* remove hyphenation encoders (digits) from pat */
org[0] = '0';
- for (i = 0, j = 0, e = 0; (unsigned) i < l; i++) {
+ for (i = 0, j = 0, e1 = 0; (unsigned) i < l; i++) {
unsigned char c = format[i];
if (is_utf8_follow(c)) {
- pat[j + e++] = c;
+ pat[j + e1++] = c;
} else if (c < '0' || c > '9') {
- pat[e + j++] = c;
+ pat[e1 + j++] = c;
org[j] = '0';
} else {
org[j] = (char) c;
}
}
- pat[e + j] = 0;
+ pat[e1 + j] = 0;
org[j + 1] = 0;
hyppat_insert(dict->patterns, pat, org);
}
@@ -666,31 +659,31 @@ void hnj_hyphen_load(HyphenDict * dict, const unsigned char *f)
v = new_HashIter(dict->patterns);
while (nextHash(v, &word)) {
int wordsize = (int) strlen((char *) word);
- int j, l;
- for (l = 1; l <= wordsize; l++) {
- if (is_utf8_follow(word[l]))
+ int j1, l1;
+ for (l1 = 1; l1 <= wordsize; l1++) {
+ if (is_utf8_follow(word[l1]))
continue; /* Do not clip an utf8 sequence */
- for (j = 1; j <= l; j++) {
+ for (j1 = 1; j1 <= l1; j1++) {
char *subpat_pat;
- int i = l - j;
- if (is_utf8_follow(word[i]))
+ int i1 = l1 - j1;
+ if (is_utf8_follow(word[i1]))
continue; /* Do not start halfway an utf8 sequence */
if ((subpat_pat =
- hyppat_lookup(dict->patterns, word + i, j)) != NULL) {
+ hyppat_lookup(dict->patterns, word + i1, j1)) != NULL) {
char *newpat_pat;
if ((newpat_pat =
- hyppat_lookup(dict->merged, word, l)) == NULL) {
+ hyppat_lookup(dict->merged, word, l1)) == NULL) {
char *neworg;
unsigned char *newword =
- (unsigned char *) malloc((size_t) (l + 1));
- int e = 0;
- strncpy((char *) newword, (char *) word, (size_t) l);
- newword[l] = 0;
- for (i = 0; i < l; i++)
- if (is_utf8_follow(newword[i]))
- e++;
- neworg = malloc((size_t) (l + 2 - e));
- sprintf(neworg, "%0*d", l + 1 - e, 0); /* fill with right amount of '0' */
+ (unsigned char *) malloc((size_t) (l1 + 1));
+ int e1 = 0;
+ strncpy((char *) newword, (char *) word, (size_t) l1);
+ newword[l1] = 0;
+ for (i1 = 0; i1 < l1; i1++)
+ if (is_utf8_follow(newword[i1]))
+ e1++;
+ neworg = malloc((size_t) (l1 + 2 - e1));
+ sprintf(neworg, "%0*d", l1 + 1 - e1, 0); /* fill with right amount of '0' */
hyppat_insert(dict->merged, newword,
combine(neworg, subpat_pat));
} else {
@@ -707,31 +700,31 @@ void hnj_hyphen_load(HyphenDict * dict, const unsigned char *f)
v = new_HashIter(dict->merged);
while (nextHashStealPattern(v, &word, &pattern)) {
static unsigned char mask[] = { 0x3F, 0x1F, 0xF, 0x7 };
- int j = (int) strlen((char *) word);
+ int j1 = (int) strlen((char *) word);
#ifdef VERBOSE
- printf("word %s pattern %s, j = %d\n", word, pattern, j);
+ printf("word %s pattern %s, j = %d\n", word, pattern, j1);
#endif
state_num = hnj_get_state(dict, word, &found);
dict->states[state_num].match = pattern;
/* now, put in the prefix transitions */
while (found < 0) {
- j--;
+ j1--;
last_state = state_num;
- ch = word[j];
+ ch = word[j1];
if (ch >= 0x80) {
int m;
- int i = 1;
- while (is_utf8_follow(word[j - i]))
- i++;
- ch = word[j - i] & mask[i];
- m = j - i;
- while (i--) {
- ch = (ch << 6) + (0x3F & word[j - i]);
+ int i1 = 1;
+ while (is_utf8_follow(word[j1 - i1]))
+ i1++;
+ ch = word[j1 - i1] & mask[i1];
+ m = j1 - i1;
+ while (i1--) {
+ ch = (ch << 6) + (0x3F & word[j1 - i1]);
}
- j = m;
+ j1 = m;
}
- word[j] = '\0';
+ word[j1] = '\0';
state_num = hnj_get_state(dict, word, &found);
hnj_add_trans(dict, state_num, last_state, ch);
}
@@ -740,6 +733,8 @@ void hnj_hyphen_load(HyphenDict * dict, const unsigned char *f)
clear_hyppat_hash(&dict->merged);
/* put in the fallback states */
+ {
+ int i, j = 0;
for (i = 0; i < HASH_SIZE; i++) {
for (e = dict->state_num->entries[i]; e; e = e->next) {
/* do not do state==0 otherwise things get confused */
@@ -766,13 +761,14 @@ void hnj_hyphen_load(HyphenDict * dict, const unsigned char *f)
}
}
#endif
+ }
clear_state_hash(&dict->state_num);
}
@ @c
void hnj_hyphen_hyphenate(HyphenDict * dict,
- halfword first,
- halfword last,
+ halfword first1,
+ halfword last1,
int length,
halfword left, halfword right, lang_variables * lan)
{
@@ -785,9 +781,9 @@ void hnj_hyphen_hyphenate(HyphenDict * dict,
char *hyphens = hnj_malloc(hyphen_len + 1);
/* Add a '.' to beginning and end to facilitate matching */
- set_vlink(begin_point, first);
- set_vlink(end_point, get_vlink(last));
- set_vlink(last, end_point);
+ set_vlink(begin_point, first1);
+ set_vlink(end_point, get_vlink(last1));
+ set_vlink(last1, end_point);
for (char_num = 0; char_num < hyphen_len; char_num++) {
hyphens[char_num] = '0';
@@ -847,12 +843,12 @@ void hnj_hyphen_hyphenate(HyphenDict * dict,
}
/* restore the correct pointers */
- set_vlink(last, get_vlink(end_point));
+ set_vlink(last1, get_vlink(end_point));
/* pattern is \.{\^.\^w\^o\^r\^d\^.\^} |word_len|=4, |ext_word_len|=6, |hyphens|=7
* check \.{ \^ \^ \^ } so drop first two and stop after |word_len-1|
*/
- for (here = first, char_num = 2; here != left; here = get_vlink(here))
+ for (here = first1, char_num = 2; here != left; here = get_vlink(here))
char_num++;
for (; here != right; here = get_vlink(here)) {
if (hyphens[char_num] & 1)