mirror of
https://github.com/lua/lua.git
synced 2026-08-03 03:49:04 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
42359b8b13 | ||
|
|
169870e37d | ||
|
|
78e454d864 |
5
iolib.c
5
iolib.c
@@ -122,9 +122,10 @@ static void io_read (void)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
char *ep = item_end(p); /* get what is next */
|
char *ep = item_end(p); /* get what is next */
|
||||||
int m;
|
int m; /* match result */
|
||||||
if (c == NEED_OTHER) c = getc(lua_infile);
|
if (c == NEED_OTHER) c = getc(lua_infile);
|
||||||
if ((m = singlematch(c, p)) != 0) {
|
m = (c == EOF) ? 0 : singlematch((char)c, p);
|
||||||
|
if (m) {
|
||||||
if (!inskip) luaI_addchar(c);
|
if (!inskip) luaI_addchar(c);
|
||||||
c = NEED_OTHER;
|
c = NEED_OTHER;
|
||||||
}
|
}
|
||||||
|
|||||||
4
lua.h
4
lua.h
@@ -2,14 +2,14 @@
|
|||||||
** LUA - Linguagem para Usuarios de Aplicacao
|
** LUA - Linguagem para Usuarios de Aplicacao
|
||||||
** Grupo de Tecnologia em Computacao Grafica
|
** Grupo de Tecnologia em Computacao Grafica
|
||||||
** TeCGraf - PUC-Rio
|
** TeCGraf - PUC-Rio
|
||||||
** $Id: lua.h,v 3.30 1996/11/07 20:26:08 roberto Exp roberto $
|
** $Id: lua.h,v 3.31 1996/11/12 16:00:16 roberto Exp roberto $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef lua_h
|
#ifndef lua_h
|
||||||
#define lua_h
|
#define lua_h
|
||||||
|
|
||||||
#define LUA_VERSION "Lua 2.5"
|
#define LUA_VERSION "Lua 2.5.1"
|
||||||
#define LUA_COPYRIGHT "Copyright (C) 1994-1996 TeCGraf"
|
#define LUA_COPYRIGHT "Copyright (C) 1994-1996 TeCGraf"
|
||||||
#define LUA_AUTHORS "W. Celes, R. Ierusalimschy & L. H. de Figueiredo"
|
#define LUA_AUTHORS "W. Celes, R. Ierusalimschy & L. H. de Figueiredo"
|
||||||
|
|
||||||
|
|||||||
36
strlib.c
36
strlib.c
@@ -3,7 +3,7 @@
|
|||||||
** String library to LUA
|
** String library to LUA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *rcs_strlib="$Id: strlib.c,v 1.31 1996/10/31 20:18:05 roberto Exp roberto $";
|
char *rcs_strlib="$Id: strlib.c,v 1.32 1996/11/07 20:26:19 roberto Exp roberto $";
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -238,7 +238,7 @@ static int matchclass (int c, int cl)
|
|||||||
|
|
||||||
int singlematch (int c, char *p)
|
int singlematch (int c, char *p)
|
||||||
{
|
{
|
||||||
if (c <= 0) return 0; /* \0, EOF or other strange flags */
|
if (c == 0) return 0;
|
||||||
switch (*p) {
|
switch (*p) {
|
||||||
case '.': return 1;
|
case '.': return 1;
|
||||||
case ESC: return matchclass(c, *(p+1));
|
case ESC: return matchclass(c, *(p+1));
|
||||||
@@ -300,6 +300,21 @@ static int capture_to_close (int level)
|
|||||||
return 0; /* to avoid warnings */
|
return 0; /* to avoid warnings */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *matchbalance (char *s, int b, int e)
|
||||||
|
{
|
||||||
|
if (*s != b) return NULL;
|
||||||
|
else {
|
||||||
|
int cont = 1;
|
||||||
|
while (*(++s)) {
|
||||||
|
if (*s == e) {
|
||||||
|
if (--cont == 0) return s+1;
|
||||||
|
}
|
||||||
|
else if (*s == b) cont++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL; /* string ends out of balance */
|
||||||
|
}
|
||||||
|
|
||||||
static char *match (char *s, char *p, int level)
|
static char *match (char *s, char *p, int level)
|
||||||
{
|
{
|
||||||
init: /* using goto's to optimize tail recursion */
|
init: /* using goto's to optimize tail recursion */
|
||||||
@@ -317,16 +332,25 @@ static char *match (char *s, char *p, int level)
|
|||||||
capture[l].len = -1; /* undo capture */
|
capture[l].len = -1; /* undo capture */
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
case ESC: /* possibly a capture (if followed by a digit) */
|
case ESC:
|
||||||
if (!isdigit(*(p+1))) goto dflt;
|
if (isdigit(*(p+1))) { /* capture */
|
||||||
else {
|
|
||||||
int l = check_cap(*(p+1), level);
|
int l = check_cap(*(p+1), level);
|
||||||
if (strncmp(capture[l].init, s, capture[l].len) == 0) {
|
if (strncmp(capture[l].init, s, capture[l].len) == 0) {
|
||||||
/* return match(p+2, s+capture[l].len, level); */
|
/* return match(p+2, s+capture[l].len, level); */
|
||||||
p+=2; s+=capture[l].len; goto init;
|
p+=2; s+=capture[l].len; goto init;
|
||||||
}
|
}
|
||||||
else return NULL;
|
else return NULL;
|
||||||
}
|
}
|
||||||
|
else if (*(p+1) == 'b') { /* balanced string */
|
||||||
|
if (*(p+2) == 0 || *(p+3) == 0)
|
||||||
|
lua_error("bad balanced pattern specification");
|
||||||
|
s = matchbalance(s, *(p+2), *(p+3));
|
||||||
|
if (s == NULL) return NULL;
|
||||||
|
else { /* return match(p+4, s, level); */
|
||||||
|
p+=4; goto init;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else goto dflt;
|
||||||
case '\0': case '$': /* (possibly) end of pattern */
|
case '\0': case '$': /* (possibly) end of pattern */
|
||||||
if (*p == 0 || (*(p+1) == 0 && *s == 0)) {
|
if (*p == 0 || (*(p+1) == 0 && *s == 0)) {
|
||||||
num_captures = level;
|
num_captures = level;
|
||||||
|
|||||||
Reference in New Issue
Block a user