summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c/luatexdir/utils
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/texk/web2c/luatexdir/utils')
-rw-r--r--Build/source/texk/web2c/luatexdir/utils/avlstuff.w18
-rw-r--r--Build/source/texk/web2c/luatexdir/utils/managed-sa.w20
-rw-r--r--Build/source/texk/web2c/luatexdir/utils/unistring.h40
-rw-r--r--Build/source/texk/web2c/luatexdir/utils/unistring.w213
-rw-r--r--Build/source/texk/web2c/luatexdir/utils/utils.h4
-rw-r--r--Build/source/texk/web2c/luatexdir/utils/utils.w31
6 files changed, 292 insertions, 34 deletions
diff --git a/Build/source/texk/web2c/luatexdir/utils/avlstuff.w b/Build/source/texk/web2c/luatexdir/utils/avlstuff.w
index 81b0bd92028..d39a4d8d516 100644
--- a/Build/source/texk/web2c/luatexdir/utils/avlstuff.w
+++ b/Build/source/texk/web2c/luatexdir/utils/avlstuff.w
@@ -1,33 +1,33 @@
% avlstuff.w
-
+%
% Copyright 1996-2006 Han The Thanh <thanh@@pdftex.org>
% Copyright 2006-2009 Taco Hoekwater <taco@@luatex.org>
-
+%
% This file is part of LuaTeX.
-
+%
% LuaTeX is free software; you can redistribute it and/or modify it under
% the terms of the GNU General Public License as published by the Free
% Software Foundation; either version 2 of the License, or (at your
% option) any later version.
-
+%
% LuaTeX 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 Lesser General Public
% License for more details.
-
+%
% You should have received a copy of the GNU General Public License along
% with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
@* AVL helper functions.
@ @c
+static const char _svn_version[] =
+ "$Id: avlstuff.w 4442 2012-05-25 22:40:34Z hhenkel $"
+ "$URL: http://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/utils/avlstuff.w $";
+
#include "ptexlib.h"
#include "utils/avl.h"
-static const char _svn_version[] =
- "$Id: avlstuff.w 3584 2010-04-02 17:45:55Z hhenkel $ "
- "$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/utils/avlstuff.w $";
-
@ memory management functions for AVL
@c
static void *avl_xmalloc(struct libavl_allocator *allocator, size_t size)
diff --git a/Build/source/texk/web2c/luatexdir/utils/managed-sa.w b/Build/source/texk/web2c/luatexdir/utils/managed-sa.w
index a9cd131d64a..890e1eca0d4 100644
--- a/Build/source/texk/web2c/luatexdir/utils/managed-sa.w
+++ b/Build/source/texk/web2c/luatexdir/utils/managed-sa.w
@@ -1,30 +1,30 @@
% managed-sa.w
-%
+%
% Copyright 2006-2010 Taco Hoekwater <taco@@luatex.org>
-
+%
% This file is part of LuaTeX.
-
+%
% LuaTeX is free software; you can redistribute it and/or modify it under
% the terms of the GNU General Public License as published by the Free
% Software Foundation; either version 2 of the License, or (at your
% option) any later version.
-
+%
% LuaTeX 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 Lesser General Public
% License for more details.
-
+%
% You should have received a copy of the GNU General Public License along
-% with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
+% with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
@* Sparse arrays with an embedded save stack.
@ @c
-#include "ptexlib.h"
-
static const char _svn_version[] =
- "$Id: managed-sa.w 3584 2010-04-02 17:45:55Z hhenkel $ "
-"$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/utils/managed-sa.w $";
+ "$Id: managed-sa.w 4442 2012-05-25 22:40:34Z hhenkel $"
+ "$URL: http://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/utils/managed-sa.w $";
+
+#include "ptexlib.h"
@ @c
static void store_sa_stack(sa_tree a, int n, sa_tree_item v, int gl)
diff --git a/Build/source/texk/web2c/luatexdir/utils/unistring.h b/Build/source/texk/web2c/luatexdir/utils/unistring.h
new file mode 100644
index 00000000000..810f5526d46
--- /dev/null
+++ b/Build/source/texk/web2c/luatexdir/utils/unistring.h
@@ -0,0 +1,40 @@
+/* unistring.h
+
+ Copyright 2013 Taco Hoekwater <taco@luatex.org>
+
+ This file is part of LuaTeX.
+
+ LuaTeX is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2 of the License, or (at your
+ option) any later version.
+
+ LuaTeX 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 Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
+
+/* $Id: unistring.h 4599 2013-03-19 15:41:07Z taco $ */
+
+#ifndef UNISTRING_H
+# define UNISTRING_H
+
+extern unsigned char *uni2str(unsigned);
+extern unsigned str2uni(const unsigned char *);
+extern int buffer_to_unichar(int k);
+
+extern char *uni2string(char *utf8_text, unsigned ch);
+extern unsigned u_length(register unsigned int *str);
+extern void utf2uni_strcpy(unsigned int *ubuf, const char *utf8buf);
+
+#define is_utf8_follow(A) (A >= 0x80 && A < 0xC0)
+
+#define utf8_size(a) (a>0xFFFF ? 4 : (a>0x7FF ? 3 : (a>0x7F? 2 : 1)))
+
+extern char *utf16be_str(long code);
+
+#endif
+
diff --git a/Build/source/texk/web2c/luatexdir/utils/unistring.w b/Build/source/texk/web2c/luatexdir/utils/unistring.w
new file mode 100644
index 00000000000..6761769ddc1
--- /dev/null
+++ b/Build/source/texk/web2c/luatexdir/utils/unistring.w
@@ -0,0 +1,213 @@
+% unistring.w
+%
+% Copyright 2013 Taco Hoekwater <taco@@luatex.org>
+%
+% This file is part of LuaTeX.
+%
+% LuaTeX is free software; you can redistribute it and/or modify it under
+% the terms of the GNU General Public License as published by the Free
+% Software Foundation; either version 2 of the License, or (at your
+% option) any later version.
+%
+% LuaTeX 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 Lesser General Public
+% License for more details.
+%
+% You should have received a copy of the GNU General Public License along
+% with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
+
+@ @c
+static const char _svn_version[] =
+ "$Id: unistring.w 4600 2013-03-19 15:50:19Z taco $"
+ "$URL: https://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/utils/unistring.w $";
+
+@ @c
+#include <string.h>
+#include "ptexlib.h"
+
+@ @c
+static void utf_error(void)
+{
+ const char *hlp[] =
+ { "A funny symbol that I can't read has just been (re)read.",
+ "Just continue, I'll change it to 0xFFFD.",
+ NULL
+ };
+ deletions_allowed = false;
+ tex_error("String contains an invalid utf-8 sequence", hlp);
+ deletions_allowed = true;
+}
+
+@ @c
+unsigned str2uni(const unsigned char *k)
+{
+ register int ch;
+ int val = 0xFFFD;
+ const unsigned char *text = k;
+ if ((ch = *text++) < 0x80) {
+ val = (unsigned) ch;
+ } else if (ch <= 0xbf) { /* error */
+ } else if (ch <= 0xdf) {
+ if (*text >= 0x80 && *text < 0xc0)
+ val = (unsigned) (((ch & 0x1f) << 6) | (*text++ & 0x3f));
+ } else if (ch <= 0xef) {
+ if (*text >= 0x80 && *text < 0xc0 && text[1] >= 0x80 && text[1] < 0xc0) {
+ val = (unsigned)
+ (((ch & 0xf) << 12) | ((text[0] & 0x3f) << 6) |
+ (text[1] & 0x3f));
+ }
+ } else if (ch <= 0xf7) {
+ int w = (((ch & 0x7) << 2) | ((text[0] & 0x30) >> 4)) - 1, w2;
+ w = (w << 6) | ((text[0] & 0xf) << 2) | ((text[1] & 0x30) >> 4);
+ w2 = ((text[1] & 0xf) << 6) | (text[2] & 0x3f);
+ val = (unsigned) (w * 0x400 + w2 + 0x10000);
+ if (*text < 0x80 || text[1] < 0x80 || text[2] < 0x80 ||
+ *text >= 0xc0 || text[1] >= 0xc0 || text[2] >= 0xc0)
+ val = 0xFFFD;
+ } else {
+ /* the 5- and 6-byte UTF-8 sequences generate integers
+ that are outside of the valid UCS range, and therefore
+ unsupported
+ */
+ }
+ if (val == 0xFFFD)
+ utf_error();
+ return (val);
+}
+
+@ This is a very basic helper
+@c
+unsigned char *uni2str(unsigned unic)
+{
+ unsigned char *buf = xmalloc(5);
+ unsigned char *pt = buf;
+ if (unic < 0x80)
+ *pt++ = (unsigned char) unic;
+ else if (unic < 0x800) {
+ *pt++ = (unsigned char) (0xc0 | (unic >> 6));
+ *pt++ = (unsigned char) (0x80 | (unic & 0x3f));
+ } else if (unic >= 0x110000) {
+ *pt++ = (unsigned char) (unic - 0x110000);
+ } else if (unic < 0x10000) {
+ *pt++ = (unsigned char) (0xe0 | (unic >> 12));
+ *pt++ = (unsigned char) (0x80 | ((unic >> 6) & 0x3f));
+ *pt++ = (unsigned char) (0x80 | (unic & 0x3f));
+ } else {
+ int u, z, y, x;
+ unsigned val = unic - 0x10000;
+ u = (int) (((val & 0xf0000) >> 16) + 1);
+ z = (int) ((val & 0x0f000) >> 12);
+ y = (int) ((val & 0x00fc0) >> 6);
+ x = (int) (val & 0x0003f);
+ *pt++ = (unsigned char) (0xf0 | (u >> 2));
+ *pt++ = (unsigned char) (0x80 | ((u & 3) << 4) | z);
+ *pt++ = (unsigned char) (0x80 | y);
+ *pt++ = (unsigned char) (0x80 | x);
+ }
+ *pt = '\0';
+ return buf;
+}
+
+@ |buffer_to_unichar| converts a sequence of bytes in the |buffer|
+into a unicode character value. It does not check for overflow
+of the |buffer|, but it is careful to check the validity of the
+UTF-8 encoding.
+
+@c
+int buffer_to_unichar(int k)
+{
+ return str2uni((const unsigned char *)(buffer+k));
+}
+
+
+@ These came from texlang.w
+@c
+char *uni2string(char *utf8_text, unsigned ch)
+{
+ /* Increment and deposit character */
+ if (ch >= 17 * 65536)
+ return (utf8_text);
+
+ if (ch <= 127)
+ *utf8_text++ = (char) ch;
+ else if (ch <= 0x7ff) {
+ *utf8_text++ = (char) (0xc0 | (ch >> 6));
+ *utf8_text++ = (char) (0x80 | (ch & 0x3f));
+ } else if (ch <= 0xffff) {
+ *utf8_text++ = (char) (0xe0 | (ch >> 12));
+ *utf8_text++ = (char) (0x80 | ((ch >> 6) & 0x3f));
+ *utf8_text++ = (char) (0x80 | (ch & 0x3f));
+ } else {
+ unsigned val = ch - 0x10000;
+ unsigned u = ((val & 0xf0000) >> 16) + 1, z = (val & 0x0f000) >> 12, y =
+ (val & 0x00fc0) >> 6, x = val & 0x0003f;
+ *utf8_text++ = (char) (0xf0 | (u >> 2));
+ *utf8_text++ = (char) (0x80 | ((u & 3) << 4) | z);
+ *utf8_text++ = (char) (0x80 | y);
+ *utf8_text++ = (char) (0x80 | x);
+ }
+ return (utf8_text);
+}
+
+unsigned u_length(register unsigned int *str)
+{
+ register unsigned len = 0;
+ while (*str++ != '\0')
+ ++len;
+ return (len);
+}
+
+
+void utf2uni_strcpy(unsigned int *ubuf, const char *utf8buf)
+{
+ int len = (int) strlen(utf8buf) + 1;
+ unsigned int *upt = ubuf, *uend = ubuf + len - 1;
+ const unsigned char *pt = (const unsigned char *) utf8buf, *end =
+ pt + strlen(utf8buf);
+ int w, w2;
+
+ while (pt < end && *pt != '\0' && upt < uend) {
+ if (*pt <= 127)
+ *upt = *pt++;
+ else if (*pt <= 0xdf) {
+ *upt = (unsigned int) (((*pt & 0x1f) << 6) | (pt[1] & 0x3f));
+ pt += 2;
+ } else if (*pt <= 0xef) {
+ *upt =
+ (unsigned int) (((*pt & 0xf) << 12) | ((pt[1] & 0x3f) << 6) |
+ (pt[2] & 0x3f));
+ pt += 3;
+ } else {
+ w = (((*pt & 0x7) << 2) | ((pt[1] & 0x30) >> 4)) - 1;
+ w = (w << 6) | ((pt[1] & 0xf) << 2) | ((pt[2] & 0x30) >> 4);
+ w2 = ((pt[2] & 0xf) << 6) | (pt[3] & 0x3f);
+ *upt = (unsigned int) (w * 0x400 + w2 + 0x10000);
+ pt += 4;
+ }
+ ++upt;
+ }
+ *upt = '\0';
+}
+
+@ @c
+char *utf16be_str(long code)
+{
+ static char buf[SMALL_BUF_SIZE];
+ long v;
+ unsigned vh, vl;
+
+ assert(code >= 0);
+
+ if (code <= 0xFFFF)
+ sprintf(buf, "%04lX", code);
+ else {
+ v = code - 0x10000;
+ vh = (unsigned) (v / 0x400 + 0xD800);
+ vl = (unsigned) (v % 0x400 + 0xDC00);
+ sprintf(buf, "%04X%04X", vh, vl);
+ }
+ return buf;
+}
+
+
diff --git a/Build/source/texk/web2c/luatexdir/utils/utils.h b/Build/source/texk/web2c/luatexdir/utils/utils.h
index b3bec818e5a..f67f080db11 100644
--- a/Build/source/texk/web2c/luatexdir/utils/utils.h
+++ b/Build/source/texk/web2c/luatexdir/utils/utils.h
@@ -2,6 +2,7 @@
Copyright 1996-2006 Han The Thanh <thanh@pdftex.org>
Copyright 2006-2012 Taco Hoekwater <taco@luatex.org>
+
This file is part of LuaTeX.
LuaTeX is free software; you can redistribute it and/or modify it under
@@ -17,7 +18,7 @@
You should have received a copy of the GNU General Public License along
with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
-/* $Id: utils.h 3261 2009-12-18 11:38:21Z taco $ */
+/* $Id: utils.h 4479 2012-11-07 16:38:55Z taco $ */
#ifndef UTILS_H
# define UTILS_H
@@ -38,7 +39,6 @@ int xfflush(FILE *);
int xgetc(FILE *);
int xputc(int, FILE *);
scaled ext_xn_over_d(scaled, scaled, scaled);
-char *stripzeros(char *);
void initversionstring(char **versions);
extern void check_buffer_overflow(int wsize);
extern void check_pool_overflow(int wsize);
diff --git a/Build/source/texk/web2c/luatexdir/utils/utils.w b/Build/source/texk/web2c/luatexdir/utils/utils.w
index 47978b9f0f4..0ba7ce7b5c9 100644
--- a/Build/source/texk/web2c/luatexdir/utils/utils.w
+++ b/Build/source/texk/web2c/luatexdir/utils/utils.w
@@ -1,27 +1,27 @@
% utils.w
-
+%
% Copyright 1996-2006 Han The Thanh <thanh@@pdftex.org>
-% Copyright 2006-2010 Taco Hoekwater <taco@@luatex.org>
-
+% Copyright 2006-2012 Taco Hoekwater <taco@@luatex.org>
+%
% This file is part of LuaTeX.
-
+%
% LuaTeX is free software; you can redistribute it and/or modify it under
% the terms of the GNU General Public License as published by the Free
% Software Foundation; either version 2 of the License, or (at your
% option) any later version.
-
+%
% LuaTeX 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 Lesser General Public
% License for more details.
-
+%
% You should have received a copy of the GNU General Public License along
-% with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
+% with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
@ @c
static const char _svn_version[] =
- "$Id: utils.w 4244 2011-05-05 09:31:30Z taco $ "
- "$URL: http://foundry.supelec.fr/svn/luatex/branches/0.70.x/source/texk/web2c/luatexdir/utils/utils.w $";
+ "$Id: utils.w 4479 2012-11-07 16:38:55Z taco $"
+ "$URL: http://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/utils/utils.w $";
@ @c
#include <kpathsea/config.h> /* this is a trick to load mingw32's io.h early,
@@ -136,7 +136,7 @@ void tex_printf(const char *fmt, ...)
possibly because pool overflows are detected too late.
The output format of this fuction must be the same as |pdf_error| in
- pdftex.web!
+ pdftex.web!
@c
__attribute__ ((noreturn, format(printf, 1, 2)))
@@ -172,8 +172,10 @@ void pdftex_fail(const char *fmt, ...)
__attribute__ ((format(printf, 1, 2)))
void pdftex_warn(const char *fmt, ...)
{
+ int old_selector = selector;
va_list args;
va_start(args, fmt);
+ selector = term_and_log;
print_ln();
tex_printf("LuaTeX warning");
if (cur_file_name)
@@ -183,6 +185,7 @@ void pdftex_warn(const char *fmt, ...)
tprint(print_buf);
va_end(args);
print_ln();
+ selector = old_selector;
}
@ @c
@@ -264,9 +267,10 @@ scaled ext_xn_over_d(scaled x, scaled n, scaled d)
return (scaled) r;
}
-@ function strips trailing zeros in string with numbers;
-leading zeros are not stripped (as in real life)
+@ function strips trailing zeros in string with numbers;
+leading zeros are not stripped (as in real life)
@c
+#if 0
char *stripzeros(char *a)
{
enum { NONUM, DOTNONUM, INT, DOT, LEADDOT, FRAC } s = NONUM, t = NONUM;
@@ -333,6 +337,7 @@ char *stripzeros(char *a)
*q = '\0';
return a;
}
+#endif
@ @c
void initversionstring(char **versions)
@@ -407,7 +412,7 @@ scaled divide_scaled(scaled s, scaled m, int dd)
return sign * q;
}
-@ Same function, but using doubles instead of integers (faster)
+@ Same function, but using doubles instead of integers (faster)
@c
scaled divide_scaled_n(double sd, double md, double n)
{