[lua] Remove regex matching

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-05-23 13:17:02 +02:00
parent fb822997b3
commit ccb2a2db77
5 changed files with 45 additions and 91 deletions

View File

@ -40,7 +40,7 @@ end
-- set i to 1 to get next, -1 to get previous. -- set i to 1 to get next, -1 to get previous.
function client_next(i) function client_next(i)
-- Get all visible clients -- Get all visible clients
local cls = client.visible_get(mouse.screen_get(), ".*") local cls = client.visible_get(mouse.screen_get())
-- Get currently focused client -- Get currently focused client
local sel = client.focus_get() local sel = client.focus_get()
if not sel then return end if not sel then return end
@ -94,7 +94,7 @@ end
function getselectedtags() function getselectedtags()
local idx = 1 local idx = 1
local screen = mouse.screen_get() local screen = mouse.screen_get()
local tags = tag.get(screen, ".*") local tags = tag.get(screen)
local vtags = {} local vtags = {}
for i, t in ipairs(tags) do for i, t in ipairs(tags) do
if t:isselected() then if t:isselected() then
@ -161,14 +161,14 @@ end
-- View no tag -- View no tag
function tag_viewnone() function tag_viewnone()
local tags = tag.get(mouse.screen_get(), ".*") local tags = tag.get(mouse.screen_get())
for i, t in ipairs(tags) do for i, t in ipairs(tags) do
t:view(false) t:view(false)
end end
end end
function tag_viewidx(r) function tag_viewidx(r)
local tags = tag.get(mouse.screen_get(), ".*") local tags = tag.get(mouse.screen_get())
local sel = getselectedtag() local sel = getselectedtag()
tag_viewnone() tag_viewnone()
for i, t in ipairs(tags) do for i, t in ipairs(tags) do
@ -202,7 +202,7 @@ end
function client_movetotag(target, c) function client_movetotag(target, c)
local sel = c or client.focus_get(); local sel = c or client.focus_get();
local tags = tag.get(mouse.screen_get(), ".*") local tags = tag.get(mouse.screen_get())
for i, t in ipairs(tags) do for i, t in ipairs(tags) do
sel:tag(t, false) sel:tag(t, false)
end end

View File

@ -797,23 +797,12 @@ client_kill(client_t *c)
static int static int
luaA_client_get(lua_State *L) luaA_client_get(lua_State *L)
{ {
int ret, i = 1; int i = 1;
regex_t r;
regmatch_t match;
client_t *c, **cobj; client_t *c, **cobj;
const char *name = luaL_checkstring(L, 1);
char error[512];
if((ret = regcomp(&r, name, REG_EXTENDED)))
{
regerror(ret, &r, error, sizeof(error));
luaL_error(L, "regex compilation error: %s\n", error);
}
lua_newtable(L); lua_newtable(L);
for(c = globalconf.clients; c; c = c->next) for(c = globalconf.clients; c; c = c->next)
if(!regexec(&r, c->name, 1, &match, 0))
{ {
cobj = lua_newuserdata(L, sizeof(client_t *)); cobj = lua_newuserdata(L, sizeof(client_t *));
*cobj = c; *cobj = c;
@ -857,27 +846,16 @@ luaA_client_mouse(lua_State *L)
static int static int
luaA_client_visible_get(lua_State *L) luaA_client_visible_get(lua_State *L)
{ {
int ret, i = 1; int i = 1;
regex_t r;
regmatch_t match;
client_t *c, **cobj; client_t *c, **cobj;
char error[512];
int screen = luaL_checknumber(L, 1) - 1; int screen = luaL_checknumber(L, 1) - 1;
const char *name = luaL_checkstring(L, 2);
luaA_checkscreen(screen); luaA_checkscreen(screen);
if((ret = regcomp(&r, name, REG_EXTENDED)))
{
regerror(ret, &r, error, sizeof(error));
luaL_error(L, "regex compilation error: %s\n", error);
}
lua_newtable(L); lua_newtable(L);
for(c = globalconf.clients; c; c = c->next) for(c = globalconf.clients; c; c = c->next)
if(!c->skip && client_isvisible(c, screen) if(!c->skip && client_isvisible(c, screen))
&& !regexec(&r, c->name, 1, &match, 0))
{ {
cobj = lua_newuserdata(L, sizeof(client_t *)); cobj = lua_newuserdata(L, sizeof(client_t *));
*cobj = c; *cobj = c;

View File

@ -24,8 +24,6 @@
#include <xcb/xcb_event.h> #include <xcb/xcb_event.h>
#include <regex.h>
#include "lua.h" #include "lua.h"
#include "layout.h" #include "layout.h"
#include "common/draw.h" #include "common/draw.h"

13
tag.c
View File

@ -268,25 +268,14 @@ static int
luaA_tag_get(lua_State *L) luaA_tag_get(lua_State *L)
{ {
int screen = luaL_checknumber(L, 1) - 1; int screen = luaL_checknumber(L, 1) - 1;
const char *name = luaL_checkstring(L, 2);
tag_t *tag, **tobj; tag_t *tag, **tobj;
int ret, i = 1; int i = 1;
regex_t r;
regmatch_t match;
char error[512];
luaA_checkscreen(screen); luaA_checkscreen(screen);
if((ret = regcomp(&r, name, REG_EXTENDED)))
{
regerror(ret, &r, error, sizeof(error));
luaL_error(L, "regex compilation error: %s\n", error);
}
lua_newtable(L); lua_newtable(L);
for(tag = globalconf.screens[screen].tags; tag; tag = tag->next) for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
if(!regexec(&r, tag->name, 1, &match, 0))
{ {
tobj = lua_newuserdata(L, sizeof(tag_t *)); tobj = lua_newuserdata(L, sizeof(tag_t *));
*tobj = tag; *tobj = tag;

View File

@ -295,29 +295,18 @@ luaA_widget_eq(lua_State *L)
static int static int
luaA_widget_get(lua_State *L) luaA_widget_get(lua_State *L)
{ {
const char *name = luaL_checkstring(L, 1);
statusbar_t *sb; statusbar_t *sb;
widget_t **wobj; widget_t **wobj;
widget_node_t *widget; widget_node_t *widget;
int ret, i = 1, screen; int i = 1, screen;
regex_t r;
regmatch_t match;
char error[512];
bool add = true; bool add = true;
widget_node_t *wlist = NULL, *witer; widget_node_t *wlist = NULL, *witer;
if((ret = regcomp(&r, name, REG_EXTENDED)))
{
regerror(ret, &r, error, sizeof(error));
luaL_error(L, "regex compilation error: %s\n", error);
}
lua_newtable(L); lua_newtable(L);
for(screen = 0; screen < globalconf.screens_info->nscreen; screen++) for(screen = 0; screen < globalconf.screens_info->nscreen; screen++)
for(sb = globalconf.screens[screen].statusbar; sb; sb = sb->next) for(sb = globalconf.screens[screen].statusbar; sb; sb = sb->next)
for(widget = sb->widgets; widget; widget = widget->next) for(widget = sb->widgets; widget; widget = widget->next)
if(!regexec(&r, widget->widget->name, 1, &match, 0))
{ {
for(witer = wlist; witer; witer = witer->next) for(witer = wlist; witer; witer = witer->next)
if(witer->widget == widget->widget) if(witer->widget == widget->widget)