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

Commit

Permalink
Import from 1.2.0 archive
Browse files Browse the repository at this point in the history
  • Loading branch information
drahosp committed Oct 29, 2012
1 parent 3d5c9bc commit e996857
Show file tree
Hide file tree
Showing 21 changed files with 106 additions and 38 deletions.
9 changes: 6 additions & 3 deletions README
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ software and uses the same license as Lua 5.1.

Status

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

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

History

Version 1.2.0 [02/Jun/2011]

* support for the StartDoctypeDecl handler
* add parser:stop() to abort parsing inside a callback

Version 1.1.0 [05/Jun/2006]

* adapted to work on both Lua 5.0 and Lua 5.1
Expand Down Expand Up @@ -52,5 +57,3 @@ Contact

For more information please contact us (info at keplerproject dot org). Comments are welcome!
You can also reach other Kepler developers and users on the Kepler Project mailing list.

$Id: README,v 1.2 2007-06-05 20:03:12 carregal Exp $
13 changes: 3 additions & 10 deletions config
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
# Installation directories

# Default prefix
PREFIX = /usr/local

# System's libraries directory (where binary libraries are installed)
LUA_LIBDIR= $(PREFIX)/lib/lua/5.1

LUA_LIBDIR= /usr/local/lib/lua/5.0
# System's lua directory (where Lua libraries are installed)
LUA_DIR= $(PREFIX)/share/lua/5.1

LUA_DIR= /usr/local/share/lua/5.0
# Lua includes directory
LUA_INC= $(PREFIX)/include

LUA_INC= /usr/local/include
# Expat includes directory
EXPAT_INC= /usr/local/include

Expand Down
2 changes: 1 addition & 1 deletion doc/us/examples.html
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ <h2><a name="examples"></a>Examples</h2>
<div id="about">
<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>
<p><small>
$Id: examples.html,v 1.5 2006-03-23 00:19:37 carregal Exp $
$Id: examples.html,v 1.5 2006/03/23 00:19:37 carregal Exp $
</small></p>
</div> <!-- id="about" -->

Expand Down
12 changes: 10 additions & 2 deletions doc/us/index.html
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ <h2><a name="overview"></a>Overview</h2>

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

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

<h2><a name="download"></a>Download</h2>
Expand All @@ -79,6 +79,14 @@ <h2><a name="download"></a>Download</h2>
<h2><a name="history"></a>History</h2>

<dl class="history">
<dt><strong>Version 1.2.0</strong> [02/Jun/2011]</dt>
<dd>
<ul>
<li>support for the StartDoctypeDecl handler</li>
<li>add parser:stop() to abort parsing inside a callback</li>
</ul>
</dd>

<dt><strong>Version 1.1.0</strong> [05/Jun/2007]</dt>
<dd>
<ul>
Expand Down Expand Up @@ -148,7 +156,7 @@ <h2><a name="contact"></a>Contact</h2>
<div id="about">
<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>
<p><small>$Id: index.html,v 1.45 2007-06-05 21:11:29 carregal Exp $</small></p>
<p><small>$Id: index.html,v 1.45 2007/06/05 21:11:29 carregal Exp $</small></p>
</div> <!-- id="about" -->

</div> <!-- id="container" -->
Expand Down
2 changes: 1 addition & 1 deletion doc/us/license.html
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ <h2>License</h2>
<div id="about">
<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>
<p><small>
$Id: license.html,v 1.9 2007-06-05 20:03:12 carregal Exp $
$Id: license.html,v 1.9 2007/06/05 20:03:12 carregal Exp $
</small></p>
</div> <!-- id="about" -->

Expand Down
2 changes: 1 addition & 1 deletion doc/us/lom.html
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ <h2><a name="examples"></a>Examples</h2>
<div id="about">
<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>
<p><small>
$Id: lom.html,v 1.6 2006-03-20 22:26:00 carregal Exp $
$Id: lom.html,v 1.6 2006/03/20 22:26:00 carregal Exp $
</small></p>
</div> <!-- id="about" -->

Expand Down
Empty file modified doc/us/luaexpat.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 21 additions & 4 deletions doc/us/manual.html
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ <h4>Methods</h4>
<dd>Set the encoding to be used by the parser. There are four
built-in encodings, passed as strings: "US-ASCII",
"UTF-8", "UTF-16", and "ISO-8859-1".</dd>

<dt><strong>parser:stop()</strong></dt>
<dd>Abort the parser and prevent it from parsing any further
through the data it was last passed. Use to halt parsing the
document when an error is discovered inside a callback, for
example. The parser object cannot accept more data after
this call.</dd>
</dl>

<h4>Callbacks</h4>
Expand All @@ -198,7 +205,8 @@ <h4>Callbacks</h4>
<em>ExternalEntityRef</em>, <em>NotStandalone</em>,
<em>NotationDecl</em>, <em>ProcessingInstruction</em>,
<em>StartCDataSection</em>, <em>StartElement</em>,
<em>StartNamespaceDecl</em>, and <em>UnparsedEntityDecl</em>.</p>
<em>StartNamespaceDecl</em>, <em>UnparsedEntityDecl</em>
and <em>StartDoctypeDecl</em>.</p>

<p>These indices can be references to functions with
specific signatures, as seen below. The parser constructor also
Expand Down Expand Up @@ -310,8 +318,8 @@ <h4>Callbacks</h4>
</pre>
would be represented as<br/>
<pre class="example">
{[1] = "author",
[2] = "title",
{[1] = "Ierusalimschy, Roberto",
[2] = "Programming in Lua",
author = "Ierusalimschy, Roberto",
format = "printed",
title = "Programming in Lua"}
Expand All @@ -337,6 +345,15 @@ <h4>Callbacks</h4>
For this example the <em>publicId</em> parameter would be nil.
The <em>base</em> parameter would be whatever has been set with
<code>parser:setbase</code>. If not set, it would be nil.</dd>

<dt><strong>callbacks.StartDoctypeDecl = function(parser, name, sysid, pubid, has_internal_subset)</strong></dt>
<dd>Called when the <em>parser</em> detects the beginning of an XML
DTD (DOCTYPE) section. These precede the XML root element and take
the form:
<pre class="example">
&lt;!DOCTYPE root_elem PUBLIC "example"&gt;
</pre>
</dd>
</dl>

<h4><a name="separator"></a>The separator character</h4>
Expand All @@ -354,7 +371,7 @@ <h4><a name="separator"></a>The separator character</h4>
<div id="about">
<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>
<p><small>$Id: manual.html,v 1.28 2009-04-20 22:45:13 carregal Exp $</small></p>
<p><small>$Id: manual.html,v 1.27 2007/06/05 20:03:12 carregal Exp $</small></p>
</div> <!-- id="about" -->

</div> <!-- id="container" -->
Expand Down
4 changes: 2 additions & 2 deletions makefile
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
T= lxp
V= 1.1.0
V= 1.2.0
CONFIG= ./config

include $(CONFIG)
Expand Down Expand Up @@ -27,4 +27,4 @@ install:
clean:
rm -f src/$(LIBNAME) $(OBJS)

# $Id: makefile,v 1.33 2006-06-08 20:41:48 tomas Exp $
# $Id: makefile,v 1.33 2006/06/08 20:41:48 tomas Exp $
6 changes: 3 additions & 3 deletions makefile.win
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ LUA_LIB=c:\lua5.1\lua5.1.lib

OBJS= src\lxplib.obj

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

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

# $Id: makefile.win,v 1.4 2007-09-29 22:48:21 carregal Exp $
# $Id: makefile.win,v 1.3 2007/06/05 20:03:12 carregal Exp $
Empty file modified src/lxp.def
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion src/lxp/lom.lua
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- See Copyright Notice in license.html
-- $Id: lom.lua,v 1.6 2005-06-09 19:18:40 tuler Exp $
-- $Id: lom.lua,v 1.6 2005/06/09 19:18:40 tuler Exp $

require "lxp"

Expand Down
35 changes: 26 additions & 9 deletions src/lxplib.c
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
** $Id: lxplib.c,v 1.17 2008-12-11 19:05:13 carregal Exp $
** $Id: lxplib.c,v 1.16 2007/06/05 20:03:12 carregal Exp $
** LuaExpat: Lua bind for Expat library
** See Copyright Notice in license.html
*/
Expand Down Expand Up @@ -33,7 +33,6 @@ enum XPState {
struct lxp_userdata {
lua_State *L;
XML_Parser parser; /* associated expat parser */
int busy; /* true while parsing, used to avoid calling XML_Parse() recursively */
int tableref; /* table with callbacks for this parser */
enum XPState state;
luaL_Buffer *b; /* to concatenate sequences of cdata pieces */
Expand All @@ -56,8 +55,9 @@ static int reporterror (lxp_userdata *xpu) {

static lxp_userdata *createlxp (lua_State *L) {
lxp_userdata *xpu = (lxp_userdata *)lua_newuserdata(L, sizeof(lxp_userdata));
memset(xpu, 0, sizeof(*xpu));
xpu->tableref = LUA_REFNIL; /* in case of errors... */
xpu->parser = NULL;
xpu->L = NULL;
xpu->state = XPSpre;
luaL_getmetatable(L, ParserType);
lua_setmetatable(L, -2);
Expand Down Expand Up @@ -311,6 +311,19 @@ static void f_UnparsedEntityDecl (void *ud, const char *entityName,
docall(xpu, 5, 0);
}

static void f_StartDoctypeDecl (void *ud, const XML_Char *doctypeName,
const XML_Char *sysid,
const XML_Char *pubid,
int has_internal_subset) {
lxp_userdata *xpu = (lxp_userdata *)ud;
if (getHandle(xpu, StartDoctypeDeclKey) == 0) return; /* no handle */
lua_pushstring(xpu->L, doctypeName);
lua_pushstring(xpu->L, sysid);
lua_pushstring(xpu->L, pubid);
lua_pushboolean(xpu->L, has_internal_subset);
docall(xpu, 4, 0);
}

/* }====================================================== */


Expand All @@ -331,7 +344,7 @@ static void checkcallbacks (lua_State *L) {
"Default", "DefaultExpand", "StartElement", "EndElement",
"ExternalEntityRef", "StartNamespaceDecl", "EndNamespaceDecl",
"NotationDecl", "NotStandalone", "ProcessingInstruction",
"UnparsedEntityDecl", NULL};
"UnparsedEntityDecl", "StartDoctypeDecl", NULL};
if (hasfield(L, "_nonstrict")) return;
lua_pushnil(L);
while (lua_next(L, 1)) {
Expand Down Expand Up @@ -384,6 +397,8 @@ static int lxp_make_parser (lua_State *L) {
XML_SetProcessingInstructionHandler(p, f_ProcessingInstruction);
if (hasfield(L, UnparsedEntityDeclKey))
XML_SetUnparsedEntityDeclHandler(p, f_UnparsedEntityDecl);
if (hasfield(L, StartDoctypeDeclKey))
XML_SetStartDoctypeDeclHandler(p, f_StartDoctypeDecl);
return 1;
}

Expand Down Expand Up @@ -435,9 +450,7 @@ static int parse_aux (lua_State *L, lxp_userdata *xpu, const char *s,
xpu->b = &b;
lua_settop(L, 2);
lua_getref(L, xpu->tableref); /* to be used by handlers */
xpu->busy = 1;
status = XML_Parse(xpu->parser, s, (int)len, s == NULL);
xpu->busy = 0;
if (xpu->state == XPSstring) dischargestring(xpu);
if (xpu->state == XPSerror) { /* callback error? */
lua_rawgeti(L, LUA_REGISTRYINDEX, xpu->tableref); /* get original msg. */
Expand All @@ -458,7 +471,6 @@ static int lxp_parse (lua_State *L) {
lxp_userdata *xpu = checkparser(L, 1);
size_t len;
const char *s = luaL_optlstring(L, 2, NULL, &len);
luaL_argcheck(L, !xpu->busy, 1, "expat parser is busy");
if (xpu->state == XPSfinished && s != NULL) {
lua_pushnil(L);
lua_pushliteral(L, "cannot parse - document is finished");
Expand All @@ -472,7 +484,6 @@ static int lxp_close (lua_State *L) {
int status = 1;
lxp_userdata *xpu = (lxp_userdata *)luaL_checkudata(L, 1, ParserType);
luaL_argcheck(L, xpu, 1, "expat parser expected");
luaL_argcheck(L, !xpu->busy, 1, "expat parser is busy");
if (xpu->state != XPSfinished)
status = parse_aux(L, xpu, NULL, 0);
lxpclose(L, xpu);
Expand Down Expand Up @@ -500,6 +511,11 @@ static int lxp_setencoding (lua_State *L) {
return 0;
}

static int lxp_stop (lua_State *L) {
lxp_userdata *xpu = checkparser(L, 1);
lua_pushboolean(L, XML_StopParser(xpu->parser, XML_FALSE) == XML_STATUS_OK);
return 1;
}

static const struct luaL_reg lxp_meths[] = {
{"parse", lxp_parse},
Expand All @@ -510,6 +526,7 @@ static const struct luaL_reg lxp_meths[] = {
{"getcallbacks", getcallbacks},
{"getbase", getbase},
{"setbase", setbase},
{"stop", lxp_stop},
{NULL, NULL}
};

Expand All @@ -530,7 +547,7 @@ static void set_info (lua_State *L) {
lua_pushliteral (L, "LuaExpat is a SAX XML parser based on the Expat library");
lua_settable (L, -3);
lua_pushliteral (L, "_VERSION");
lua_pushliteral (L, "LuaExpat 1.1.0");
lua_pushliteral (L, "LuaExpat 1.2.0");
lua_settable (L, -3);
}

Expand Down
1 change: 1 addition & 0 deletions src/lxplib.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
#define NotStandaloneKey "NotStandalone"
#define ProcessingInstructionKey "ProcessingInstruction"
#define UnparsedEntityDeclKey "UnparsedEntityDecl"
#define StartDoctypeDeclKey "StartDoctypeDecl"

int luaopen_lxp (lua_State *L);
Empty file modified tests/test-lom.lua
100755 → 100644
Empty file.
31 changes: 30 additions & 1 deletion tests/test.lua
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/local/bin/lua5.1
-- See Copyright Notice in license.html
-- $Id: test.lua,v 1.6 2006-06-08 20:34:52 tomas Exp $
-- $Id: test.lua,v 1.6 2006/06/08 20:34:52 tomas Exp $

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

----------------------------
print("testing doctype declarations")

callbacks = {
StartDoctypeDecl = getargs
}
p = lxp.new(callbacks)
assert(p:parse([[<!DOCTYPE root PUBLIC "foo" "hello-world">]]))
assert(p:parse[[<root/>]])
p:close()
assert(X[2] == "root" and X[3] == "hello-world" and X[4] == "foo" and
X[5] == false)

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

-- closing unfinished document
print("testing parser:stop()");
local stopped;
p = lxp.new{
StartElement = function (parser, name, attr)
if name == "stop" then
parser:stop()
stopped = true
else
stopped = false
end
end
}
local ok, err = p:parse[[<root><parseme>Hello</parseme><stop>here</stop><notparsed/></root>]];
assert(not ok)
assert(err == "parsing aborted")
assert(stopped == true, "parser not stopped")


-- test for GC
print("\ntesting garbage collection")
Expand Down
Empty file modified vc6/README
100755 → 100644
Empty file.
Empty file modified vc6/luaexpat.dsw
100755 → 100644
Empty file.
Empty file modified vc6/luaexpat_dll.dsp
100755 → 100644
Empty file.
Empty file modified vc6/luaexpat_static.dsp
100755 → 100644
Empty file.
Empty file modified vc6/lxp.def
100755 → 100644
Empty file.

0 comments on commit e996857

Please sign in to comment.