Skip to content
This repository was archived by the owner on Nov 20, 2020. It is now read-only.

Commit e996857

Browse files
committed
Import from 1.2.0 archive
1 parent 3d5c9bc commit e996857

21 files changed

+106
-38
lines changed

README

100755100644
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ software and uses the same license as Lua 5.1.
88

99
Status
1010

11-
Current version is 1.1.0. It was developed for both Lua 5.0 and Lua 5.1,
11+
Current version is 1.2.0. It was developed for both Lua 5.0 and Lua 5.1,
1212
and has been tested on Linux, Windows (2000/XP) and MacOS X with Expat 2.0.0.
1313

1414
Download
@@ -18,6 +18,11 @@ LuaBinaries a Windows binary version of LuaExpat can be found at the LuaForge pa
1818

1919
History
2020

21+
Version 1.2.0 [02/Jun/2011]
22+
23+
* support for the StartDoctypeDecl handler
24+
* add parser:stop() to abort parsing inside a callback
25+
2126
Version 1.1.0 [05/Jun/2006]
2227

2328
* adapted to work on both Lua 5.0 and Lua 5.1
@@ -52,5 +57,3 @@ Contact
5257

5358
For more information please contact us (info at keplerproject dot org). Comments are welcome!
5459
You can also reach other Kepler developers and users on the Kepler Project mailing list.
55-
56-
$Id: README,v 1.2 2007-06-05 20:03:12 carregal Exp $

config

100755100644
Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
# Installation directories
2-
3-
# Default prefix
4-
PREFIX = /usr/local
5-
62
# System's libraries directory (where binary libraries are installed)
7-
LUA_LIBDIR= $(PREFIX)/lib/lua/5.1
8-
3+
LUA_LIBDIR= /usr/local/lib/lua/5.0
94
# System's lua directory (where Lua libraries are installed)
10-
LUA_DIR= $(PREFIX)/share/lua/5.1
11-
5+
LUA_DIR= /usr/local/share/lua/5.0
126
# Lua includes directory
13-
LUA_INC= $(PREFIX)/include
14-
7+
LUA_INC= /usr/local/include
158
# Expat includes directory
169
EXPAT_INC= /usr/local/include
1710

doc/us/examples.html

100755100644
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ <h2><a name="examples"></a>Examples</h2>
191191
<div id="about">
192192
<p><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p>
193193
<p><small>
194-
$Id: examples.html,v 1.5 2006-03-23 00:19:37 carregal Exp $
194+
$Id: examples.html,v 1.5 2006/03/23 00:19:37 carregal Exp $
195195
</small></p>
196196
</div> <!-- id="about" -->
197197

doc/us/index.html

100755100644
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ <h2><a name="overview"></a>Overview</h2>
6666

6767
<h2><a name="status"></a>Status</h2>
6868

69-
<p>Current version is 1.1.0. It was developed for both Lua 5.0 and Lua 5.1, and has been tested on
69+
<p>Current version is 1.2.0. It was developed for both Lua 5.0 and Lua 5.1, and has been tested on
7070
Linux, Windows (2000/XP) and MacOS X with Expat 2.0.0.</p>
7171

7272
<h2><a name="download"></a>Download</h2>
@@ -79,6 +79,14 @@ <h2><a name="download"></a>Download</h2>
7979
<h2><a name="history"></a>History</h2>
8080

8181
<dl class="history">
82+
<dt><strong>Version 1.2.0</strong> [02/Jun/2011]</dt>
83+
<dd>
84+
<ul>
85+
<li>support for the StartDoctypeDecl handler</li>
86+
<li>add parser:stop() to abort parsing inside a callback</li>
87+
</ul>
88+
</dd>
89+
8290
<dt><strong>Version 1.1.0</strong> [05/Jun/2007]</dt>
8391
<dd>
8492
<ul>
@@ -148,7 +156,7 @@ <h2><a name="contact"></a>Contact</h2>
148156
<div id="about">
149157
<p><a href="http://validator.w3.org/check?uri=referer">
150158
<img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p>
151-
<p><small>$Id: index.html,v 1.45 2007-06-05 21:11:29 carregal Exp $</small></p>
159+
<p><small>$Id: index.html,v 1.45 2007/06/05 21:11:29 carregal Exp $</small></p>
152160
</div> <!-- id="about" -->
153161

154162
</div> <!-- id="container" -->

doc/us/license.html

100755100644
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ <h2>License</h2>
110110
<div id="about">
111111
<p><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p>
112112
<p><small>
113-
$Id: license.html,v 1.9 2007-06-05 20:03:12 carregal Exp $
113+
$Id: license.html,v 1.9 2007/06/05 20:03:12 carregal Exp $
114114
</small></p>
115115
</div> <!-- id="about" -->
116116

doc/us/lom.html

100755100644
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ <h2><a name="examples"></a>Examples</h2>
168168
<div id="about">
169169
<p><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p>
170170
<p><small>
171-
$Id: lom.html,v 1.6 2006-03-20 22:26:00 carregal Exp $
171+
$Id: lom.html,v 1.6 2006/03/20 22:26:00 carregal Exp $
172172
</small></p>
173173
</div> <!-- id="about" -->
174174

doc/us/luaexpat.png

100755100644
File mode changed.

doc/us/manual.html

100755100644
Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ <h4>Methods</h4>
175175
<dd>Set the encoding to be used by the parser. There are four
176176
built-in encodings, passed as strings: "US-ASCII",
177177
"UTF-8", "UTF-16", and "ISO-8859-1".</dd>
178+
179+
<dt><strong>parser:stop()</strong></dt>
180+
<dd>Abort the parser and prevent it from parsing any further
181+
through the data it was last passed. Use to halt parsing the
182+
document when an error is discovered inside a callback, for
183+
example. The parser object cannot accept more data after
184+
this call.</dd>
178185
</dl>
179186

180187
<h4>Callbacks</h4>
@@ -198,7 +205,8 @@ <h4>Callbacks</h4>
198205
<em>ExternalEntityRef</em>, <em>NotStandalone</em>,
199206
<em>NotationDecl</em>, <em>ProcessingInstruction</em>,
200207
<em>StartCDataSection</em>, <em>StartElement</em>,
201-
<em>StartNamespaceDecl</em>, and <em>UnparsedEntityDecl</em>.</p>
208+
<em>StartNamespaceDecl</em>, <em>UnparsedEntityDecl</em>
209+
and <em>StartDoctypeDecl</em>.</p>
202210

203211
<p>These indices can be references to functions with
204212
specific signatures, as seen below. The parser constructor also
@@ -310,8 +318,8 @@ <h4>Callbacks</h4>
310318
</pre>
311319
would be represented as<br/>
312320
<pre class="example">
313-
{[1] = "author",
314-
[2] = "title",
321+
{[1] = "Ierusalimschy, Roberto",
322+
[2] = "Programming in Lua",
315323
author = "Ierusalimschy, Roberto",
316324
format = "printed",
317325
title = "Programming in Lua"}
@@ -337,6 +345,15 @@ <h4>Callbacks</h4>
337345
For this example the <em>publicId</em> parameter would be nil.
338346
The <em>base</em> parameter would be whatever has been set with
339347
<code>parser:setbase</code>. If not set, it would be nil.</dd>
348+
349+
<dt><strong>callbacks.StartDoctypeDecl = function(parser, name, sysid, pubid, has_internal_subset)</strong></dt>
350+
<dd>Called when the <em>parser</em> detects the beginning of an XML
351+
DTD (DOCTYPE) section. These precede the XML root element and take
352+
the form:
353+
<pre class="example">
354+
&lt;!DOCTYPE root_elem PUBLIC "example"&gt;
355+
</pre>
356+
</dd>
340357
</dl>
341358

342359
<h4><a name="separator"></a>The separator character</h4>
@@ -354,7 +371,7 @@ <h4><a name="separator"></a>The separator character</h4>
354371
<div id="about">
355372
<p><a href="http://validator.w3.org/check?uri=referer">
356373
<img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p>
357-
<p><small>$Id: manual.html,v 1.28 2009-04-20 22:45:13 carregal Exp $</small></p>
374+
<p><small>$Id: manual.html,v 1.27 2007/06/05 20:03:12 carregal Exp $</small></p>
358375
</div> <!-- id="about" -->
359376

360377
</div> <!-- id="container" -->

makefile

100755100644
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
T= lxp
2-
V= 1.1.0
2+
V= 1.2.0
33
CONFIG= ./config
44

55
include $(CONFIG)
@@ -27,4 +27,4 @@ install:
2727
clean:
2828
rm -f src/$(LIBNAME) $(OBJS)
2929

30-
# $Id: makefile,v 1.33 2006-06-08 20:41:48 tomas Exp $
30+
# $Id: makefile,v 1.33 2006/06/08 20:41:48 tomas Exp $

makefile.win

100755100644
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ LUA_LIB=c:\lua5.1\lua5.1.lib
55

66
OBJS= src\lxplib.obj
77

8-
EXPAT_INCLUDE=C:\Expat-2.0.1\Source\lib
9-
EXPAT_LIB=C:\Expat-2.0.1\Bin\libexpat.lib
8+
EXPAT_INCLUDE=C:\Expat-2.0.0\Source\lib
9+
EXPAT_LIB=C:\Expat-2.0.0\Libs\libexpat.lib
1010

1111
.c.obj:
1212
cl /c /Fo$@ /O2 /I$(LUA_INC) /I$(EXPAT_INCLUDE) /D_CRT_SECURE_NO_DEPRECATE $<
@@ -26,4 +26,4 @@ clean:
2626
del src\lxp.exp
2727
del src\lxp.lib
2828

29-
# $Id: makefile.win,v 1.4 2007-09-29 22:48:21 carregal Exp $
29+
# $Id: makefile.win,v 1.3 2007/06/05 20:03:12 carregal Exp $

src/lxp.def

100755100644
File mode changed.

src/lxp/lom.lua

100755100644
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- See Copyright Notice in license.html
2-
-- $Id: lom.lua,v 1.6 2005-06-09 19:18:40 tuler Exp $
2+
-- $Id: lom.lua,v 1.6 2005/06/09 19:18:40 tuler Exp $
33

44
require "lxp"
55

src/lxplib.c

100755100644
Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** $Id: lxplib.c,v 1.17 2008-12-11 19:05:13 carregal Exp $
2+
** $Id: lxplib.c,v 1.16 2007/06/05 20:03:12 carregal Exp $
33
** LuaExpat: Lua bind for Expat library
44
** See Copyright Notice in license.html
55
*/
@@ -33,7 +33,6 @@ enum XPState {
3333
struct lxp_userdata {
3434
lua_State *L;
3535
XML_Parser parser; /* associated expat parser */
36-
int busy; /* true while parsing, used to avoid calling XML_Parse() recursively */
3736
int tableref; /* table with callbacks for this parser */
3837
enum XPState state;
3938
luaL_Buffer *b; /* to concatenate sequences of cdata pieces */
@@ -56,8 +55,9 @@ static int reporterror (lxp_userdata *xpu) {
5655

5756
static lxp_userdata *createlxp (lua_State *L) {
5857
lxp_userdata *xpu = (lxp_userdata *)lua_newuserdata(L, sizeof(lxp_userdata));
59-
memset(xpu, 0, sizeof(*xpu));
6058
xpu->tableref = LUA_REFNIL; /* in case of errors... */
59+
xpu->parser = NULL;
60+
xpu->L = NULL;
6161
xpu->state = XPSpre;
6262
luaL_getmetatable(L, ParserType);
6363
lua_setmetatable(L, -2);
@@ -311,6 +311,19 @@ static void f_UnparsedEntityDecl (void *ud, const char *entityName,
311311
docall(xpu, 5, 0);
312312
}
313313

314+
static void f_StartDoctypeDecl (void *ud, const XML_Char *doctypeName,
315+
const XML_Char *sysid,
316+
const XML_Char *pubid,
317+
int has_internal_subset) {
318+
lxp_userdata *xpu = (lxp_userdata *)ud;
319+
if (getHandle(xpu, StartDoctypeDeclKey) == 0) return; /* no handle */
320+
lua_pushstring(xpu->L, doctypeName);
321+
lua_pushstring(xpu->L, sysid);
322+
lua_pushstring(xpu->L, pubid);
323+
lua_pushboolean(xpu->L, has_internal_subset);
324+
docall(xpu, 4, 0);
325+
}
326+
314327
/* }====================================================== */
315328

316329

@@ -331,7 +344,7 @@ static void checkcallbacks (lua_State *L) {
331344
"Default", "DefaultExpand", "StartElement", "EndElement",
332345
"ExternalEntityRef", "StartNamespaceDecl", "EndNamespaceDecl",
333346
"NotationDecl", "NotStandalone", "ProcessingInstruction",
334-
"UnparsedEntityDecl", NULL};
347+
"UnparsedEntityDecl", "StartDoctypeDecl", NULL};
335348
if (hasfield(L, "_nonstrict")) return;
336349
lua_pushnil(L);
337350
while (lua_next(L, 1)) {
@@ -384,6 +397,8 @@ static int lxp_make_parser (lua_State *L) {
384397
XML_SetProcessingInstructionHandler(p, f_ProcessingInstruction);
385398
if (hasfield(L, UnparsedEntityDeclKey))
386399
XML_SetUnparsedEntityDeclHandler(p, f_UnparsedEntityDecl);
400+
if (hasfield(L, StartDoctypeDeclKey))
401+
XML_SetStartDoctypeDeclHandler(p, f_StartDoctypeDecl);
387402
return 1;
388403
}
389404

@@ -435,9 +450,7 @@ static int parse_aux (lua_State *L, lxp_userdata *xpu, const char *s,
435450
xpu->b = &b;
436451
lua_settop(L, 2);
437452
lua_getref(L, xpu->tableref); /* to be used by handlers */
438-
xpu->busy = 1;
439453
status = XML_Parse(xpu->parser, s, (int)len, s == NULL);
440-
xpu->busy = 0;
441454
if (xpu->state == XPSstring) dischargestring(xpu);
442455
if (xpu->state == XPSerror) { /* callback error? */
443456
lua_rawgeti(L, LUA_REGISTRYINDEX, xpu->tableref); /* get original msg. */
@@ -458,7 +471,6 @@ static int lxp_parse (lua_State *L) {
458471
lxp_userdata *xpu = checkparser(L, 1);
459472
size_t len;
460473
const char *s = luaL_optlstring(L, 2, NULL, &len);
461-
luaL_argcheck(L, !xpu->busy, 1, "expat parser is busy");
462474
if (xpu->state == XPSfinished && s != NULL) {
463475
lua_pushnil(L);
464476
lua_pushliteral(L, "cannot parse - document is finished");
@@ -472,7 +484,6 @@ static int lxp_close (lua_State *L) {
472484
int status = 1;
473485
lxp_userdata *xpu = (lxp_userdata *)luaL_checkudata(L, 1, ParserType);
474486
luaL_argcheck(L, xpu, 1, "expat parser expected");
475-
luaL_argcheck(L, !xpu->busy, 1, "expat parser is busy");
476487
if (xpu->state != XPSfinished)
477488
status = parse_aux(L, xpu, NULL, 0);
478489
lxpclose(L, xpu);
@@ -500,6 +511,11 @@ static int lxp_setencoding (lua_State *L) {
500511
return 0;
501512
}
502513

514+
static int lxp_stop (lua_State *L) {
515+
lxp_userdata *xpu = checkparser(L, 1);
516+
lua_pushboolean(L, XML_StopParser(xpu->parser, XML_FALSE) == XML_STATUS_OK);
517+
return 1;
518+
}
503519

504520
static const struct luaL_reg lxp_meths[] = {
505521
{"parse", lxp_parse},
@@ -510,6 +526,7 @@ static const struct luaL_reg lxp_meths[] = {
510526
{"getcallbacks", getcallbacks},
511527
{"getbase", getbase},
512528
{"setbase", setbase},
529+
{"stop", lxp_stop},
513530
{NULL, NULL}
514531
};
515532

@@ -530,7 +547,7 @@ static void set_info (lua_State *L) {
530547
lua_pushliteral (L, "LuaExpat is a SAX XML parser based on the Expat library");
531548
lua_settable (L, -3);
532549
lua_pushliteral (L, "_VERSION");
533-
lua_pushliteral (L, "LuaExpat 1.1.0");
550+
lua_pushliteral (L, "LuaExpat 1.2.0");
534551
lua_settable (L, -3);
535552
}
536553

src/lxplib.h

100755100644
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@
1919
#define NotStandaloneKey "NotStandalone"
2020
#define ProcessingInstructionKey "ProcessingInstruction"
2121
#define UnparsedEntityDeclKey "UnparsedEntityDecl"
22+
#define StartDoctypeDeclKey "StartDoctypeDecl"
2223

2324
int luaopen_lxp (lua_State *L);

tests/test-lom.lua

100755100644
File mode changed.

tests/test.lua

100755100644
Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/local/bin/lua5.1
22
-- See Copyright Notice in license.html
3-
-- $Id: test.lua,v 1.6 2006-06-08 20:34:52 tomas Exp $
3+
-- $Id: test.lua,v 1.6 2006/06/08 20:34:52 tomas Exp $
44

55
require"lxp"
66
print (lxp._VERSION)
@@ -228,7 +228,18 @@ assert(x[1] == "e" and x[3] == "a/namespace?a")
228228
x = X[6]
229229
assert(x[1] == "en" and x[3] == "space" and table.getn(x) == 3)
230230

231+
----------------------------
232+
print("testing doctype declarations")
231233

234+
callbacks = {
235+
StartDoctypeDecl = getargs
236+
}
237+
p = lxp.new(callbacks)
238+
assert(p:parse([[<!DOCTYPE root PUBLIC "foo" "hello-world">]]))
239+
assert(p:parse[[<root/>]])
240+
p:close()
241+
assert(X[2] == "root" and X[3] == "hello-world" and X[4] == "foo" and
242+
X[5] == false)
232243

233244
-- Error reporting
234245
p = lxp.new{}
@@ -280,6 +291,24 @@ assert(p:parse[[<to>]])
280291
local status, err = pcall(p.close, p)
281292
assert(not status and string.find(err, "error closing parser"))
282293

294+
-- closing unfinished document
295+
print("testing parser:stop()");
296+
local stopped;
297+
p = lxp.new{
298+
StartElement = function (parser, name, attr)
299+
if name == "stop" then
300+
parser:stop()
301+
stopped = true
302+
else
303+
stopped = false
304+
end
305+
end
306+
}
307+
local ok, err = p:parse[[<root><parseme>Hello</parseme><stop>here</stop><notparsed/></root>]];
308+
assert(not ok)
309+
assert(err == "parsing aborted")
310+
assert(stopped == true, "parser not stopped")
311+
283312

284313
-- test for GC
285314
print("\ntesting garbage collection")

vc6/README

100755100644
File mode changed.

vc6/luaexpat.dsw

100755100644
File mode changed.

vc6/luaexpat_dll.dsp

100755100644
File mode changed.

vc6/luaexpat_static.dsp

100755100644
File mode changed.

vc6/lxp.def

100755100644
File mode changed.

0 commit comments

Comments
 (0)