use more tokenizer, with len
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
f0a01c6131
commit
ab5119732d
|
@ -86,7 +86,8 @@ SET(AWE_MAN_SRCS
|
|||
ADD_EXECUTABLE(${PROJECT_AWE_NAME} ${AWE_SRCS}
|
||||
${CMAKE_CURRENT_BINARY_DIR}/common/tokenize.c)
|
||||
|
||||
ADD_EXECUTABLE(${PROJECT_AWECLIENT_NAME} ${AWE_CLIENT_SRCS})
|
||||
ADD_EXECUTABLE(${PROJECT_AWECLIENT_NAME} ${AWE_CLIENT_SRCS}
|
||||
${CMAKE_CURRENT_BINARY_DIR}/common/tokenize.c)
|
||||
|
||||
TARGET_LINK_LIBRARIES(${PROJECT_AWE_NAME}
|
||||
${AWESOME_REQUIRED_LIBRARIES}
|
||||
|
|
3
client.c
3
client.c
|
@ -293,6 +293,7 @@ client_raise(client_t *c)
|
|||
|
||||
for(screen = 0; screen < globalconf.screens_info->nscreen; screen++)
|
||||
for(sb = globalconf.screens[screen].statusbar; sb; sb = sb->next)
|
||||
if(sb->sw)
|
||||
{
|
||||
xcb_configure_window(globalconf.connection,
|
||||
sb->sw->window,
|
||||
|
@ -957,7 +958,7 @@ luaA_client_border_set(lua_State *L)
|
|||
{
|
||||
client_t **c = luaA_checkudata(L, 1, "client");
|
||||
int width = luaA_getopt_number(L, 2, "width", (*c)->border);
|
||||
const char *colorstr = luaA_getopt_string(L, 2, "color", NULL);
|
||||
const char *colorstr = luaA_getopt_string(L, 2, "color", NULL, NULL);
|
||||
xcolor_t color;
|
||||
|
||||
client_setborder(*c, width);
|
||||
|
|
|
@ -201,6 +201,7 @@ static void
|
|||
draw_markup_on_element(markup_parser_data_t *p, const char *elem,
|
||||
const char **names, const char **values)
|
||||
{
|
||||
size_t len;
|
||||
draw_parser_data_t *data = p->priv;
|
||||
|
||||
/* hack: markup.c validates tags so we can avoid strcmps here */
|
||||
|
@ -222,10 +223,10 @@ draw_markup_on_element(markup_parser_data_t *p, const char *elem,
|
|||
break;
|
||||
case 't': /* text */
|
||||
for(; *names; names++, values++)
|
||||
switch(a_tokenize(*names, -1))
|
||||
switch(a_tokenize(*names, (len = a_strlen(*names))))
|
||||
{
|
||||
case A_TK_ALIGN:
|
||||
data->align = draw_align_get_from_str(*values);
|
||||
data->align = draw_align_fromstr(*values, len);
|
||||
break;
|
||||
case A_TK_SHADOW:
|
||||
xcolor_new(data->connection, data->phys_screen, *values,
|
||||
|
@ -1019,11 +1020,12 @@ draw_text_extents(xcb_connection_t *conn, int phys_screen, font_t *font, const c
|
|||
/** Transform a string to a alignment_t type.
|
||||
* Recognized string are left, center or right. Everything else will be
|
||||
* recognized as AlignAuto.
|
||||
* \param align string with align text
|
||||
* \return alignment_t type
|
||||
* \param align Atring with align text.
|
||||
* \param len The string length.
|
||||
* \return An alignment_t type.
|
||||
*/
|
||||
alignment_t
|
||||
draw_align_get_from_str(const char *align)
|
||||
draw_align_fromstr(const char *align, ssize_t len)
|
||||
{
|
||||
switch (a_tokenize(align, -1))
|
||||
{
|
||||
|
|
|
@ -188,7 +188,7 @@ void draw_image(draw_context_t *, int, int, int, draw_image_t *);
|
|||
void draw_image_from_argb_data(draw_context_t *, int, int, int, int, int, unsigned char *);
|
||||
void draw_rotate(draw_context_t *, xcb_drawable_t, xcb_drawable_t, int, int, int, int, double, int, int);
|
||||
area_t draw_text_extents(xcb_connection_t *, int, font_t *, const char *, draw_parser_data_t *);
|
||||
alignment_t draw_align_get_from_str(const char *);
|
||||
alignment_t draw_align_fromstr(const char *, ssize_t);
|
||||
bool xcolor_new(xcb_connection_t *, int, const char *, xcolor_t *);
|
||||
|
||||
void area_array_remove(area_array_t *, area_t);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
align
|
||||
auto
|
||||
bg
|
||||
border_padding
|
||||
border_width
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include <limits.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "tokenize.h"
|
||||
|
||||
/** Print error and exit with EXIT_FAILURE code.
|
||||
*/
|
||||
|
@ -94,24 +95,37 @@ name_func_rlookup(void * funcp, const name_func_link_t *list)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/** Get a position type from a string.
|
||||
* \param pos The position.
|
||||
* \param len The string length, -1 if unknown.
|
||||
* \return A position.
|
||||
*/
|
||||
position_t
|
||||
position_get_from_str(const char *pos)
|
||||
position_fromstr(const char *pos, ssize_t len)
|
||||
{
|
||||
if(!a_strcmp(pos, "top"))
|
||||
switch(a_tokenize(pos, len))
|
||||
{
|
||||
case A_TK_TOP:
|
||||
return Top;
|
||||
else if(!a_strcmp(pos, "bottom"))
|
||||
case A_TK_BOTTOM:
|
||||
return Bottom;
|
||||
else if(!a_strcmp(pos, "right"))
|
||||
case A_TK_RIGHT:
|
||||
return Right;
|
||||
else if(!a_strcmp(pos, "left"))
|
||||
case A_TK_LEFT:
|
||||
return Left;
|
||||
else if(!a_strcmp(pos, "auto"))
|
||||
case A_TK_AUTO:
|
||||
return Auto;
|
||||
default:
|
||||
return Off;
|
||||
}
|
||||
}
|
||||
|
||||
/** Convert a position type to a string.
|
||||
* \param p The position.
|
||||
* \return A position string.
|
||||
*/
|
||||
char *
|
||||
position_to_str(position_t p)
|
||||
position_tostr(position_t p)
|
||||
{
|
||||
switch(p)
|
||||
{
|
||||
|
|
|
@ -321,8 +321,8 @@ void _fatal(int, const char *, const char *, ...)
|
|||
void _warn(int, const char *, const char *, ...)
|
||||
__attribute__ ((format(printf, 3, 4)));
|
||||
|
||||
position_t position_get_from_str(const char *);
|
||||
char * position_to_str(position_t);
|
||||
position_t position_fromstr(const char *, ssize_t);
|
||||
char * position_tostr(position_t);
|
||||
void *name_func_lookup(const char *, const name_func_link_t *);
|
||||
const char * name_func_rlookup(void *, const name_func_link_t *);
|
||||
void a_exec(const char *);
|
||||
|
|
4
lua.c
4
lua.c
|
@ -404,10 +404,10 @@ luaA_colors_set(lua_State *L)
|
|||
{
|
||||
const char *fg, *bg;
|
||||
luaA_checktable(L, 1);
|
||||
if((fg = luaA_getopt_string(L, 1, "fg", NULL)))
|
||||
if((fg = luaA_getopt_string(L, 1, "fg", NULL, NULL)))
|
||||
xcolor_new(globalconf.connection, globalconf.default_screen,
|
||||
fg, &globalconf.colors.fg);
|
||||
if((bg = luaA_getopt_string(L, 1, "bg",NULL)))
|
||||
if((bg = luaA_getopt_string(L, 1, "bg", NULL, NULL)))
|
||||
xcolor_new(globalconf.connection, globalconf.default_screen,
|
||||
bg, &globalconf.colors.bg);
|
||||
return 0;
|
||||
|
|
4
lua.h
4
lua.h
|
@ -147,12 +147,12 @@ luaA_getopt_number(lua_State *L, int idx, const char *name, lua_Number def)
|
|||
}
|
||||
|
||||
static inline const char *
|
||||
luaA_getopt_string(lua_State *L, int idx, const char *name, const char *def)
|
||||
luaA_getopt_string(lua_State *L, int idx, const char *name, const char *def, size_t *len)
|
||||
{
|
||||
/* assume that table is first on stack */
|
||||
lua_getfield(L, idx, name);
|
||||
/* return luaL_optnumber result */
|
||||
return luaL_optstring(L, -1, def);
|
||||
return luaL_optlstring(L, -1, def, len);
|
||||
}
|
||||
|
||||
static inline bool
|
||||
|
|
9
mouse.c
9
mouse.c
|
@ -58,12 +58,14 @@ typedef enum
|
|||
|
||||
/** Convert a corner name into a corner type.
|
||||
* \param str A string.
|
||||
* \param len String length.
|
||||
* \return A corner type.
|
||||
*/
|
||||
static corner_t
|
||||
a_strtocorner(const char *str)
|
||||
a_strtocorner(const char *str, size_t len)
|
||||
{
|
||||
switch (a_tokenize(str, -1)) {
|
||||
switch (a_tokenize(str, len))
|
||||
{
|
||||
case A_TK_BOTTOMRIGHT: return BottomRightCorner;
|
||||
case A_TK_BOTTOMLEFT: return BottomLeftCorner;
|
||||
case A_TK_TOPLEFT: return TopLeftCorner;
|
||||
|
@ -1058,11 +1060,12 @@ luaA_client_mouse_resize(lua_State *L)
|
|||
client_t **c = luaA_checkudata(L, 1, "client");
|
||||
corner_t corner = AutoCorner;
|
||||
bool infobox = true;
|
||||
size_t len;
|
||||
|
||||
if(lua_gettop(L) == 2 && !lua_isnil(L, 2))
|
||||
{
|
||||
luaA_checktable(L, 2);
|
||||
corner = a_strtocorner(luaA_getopt_string(L, 2, "corner", "auto"));
|
||||
corner = a_strtocorner(luaA_getopt_string(L, 2, "corner", "auto", &len), len);
|
||||
infobox = luaA_getopt_boolean(L, 2, "infobox", true);
|
||||
}
|
||||
|
||||
|
|
28
statusbar.c
28
statusbar.c
|
@ -287,9 +287,10 @@ statusbar_position_update(statusbar_t *statusbar, position_t position)
|
|||
static int
|
||||
luaA_statusbar_position_set(lua_State *L)
|
||||
{
|
||||
size_t len;
|
||||
statusbar_t *s, **sb = luaA_checkudata(L, 1, "statusbar");
|
||||
const char *pos = luaL_checkstring(L, 2);
|
||||
position_t position = position_get_from_str(pos);
|
||||
const char *pos = luaL_checklstring(L, 2, &len);
|
||||
position_t position = position_fromstr(pos, len);
|
||||
|
||||
if(position != (*sb)->position)
|
||||
{
|
||||
|
@ -314,7 +315,7 @@ static int
|
|||
luaA_statusbar_position_get(lua_State *L)
|
||||
{
|
||||
statusbar_t **sb = luaA_checkudata(L, 1, "statusbar");
|
||||
lua_pushstring(L, position_to_str((*sb)->position));
|
||||
lua_pushstring(L, position_tostr((*sb)->position));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -328,9 +329,10 @@ luaA_statusbar_position_get(lua_State *L)
|
|||
static int
|
||||
luaA_statusbar_align_set(lua_State *L)
|
||||
{
|
||||
size_t len;
|
||||
statusbar_t **sb = luaA_checkudata(L, 1, "statusbar");
|
||||
const char *al = luaL_checkstring(L, 2);
|
||||
alignment_t align = draw_align_get_from_str(al);
|
||||
const char *al = luaL_checklstring(L, 2, &len);
|
||||
alignment_t align = draw_align_fromstr(al, len);
|
||||
|
||||
(*sb)->align = align;
|
||||
statusbar_position_update(*sb, (*sb)->position);
|
||||
|
@ -492,7 +494,8 @@ static int
|
|||
luaA_statusbar_new(lua_State *L)
|
||||
{
|
||||
statusbar_t *sb;
|
||||
const char *color;
|
||||
const char *buf;
|
||||
size_t len;
|
||||
|
||||
luaA_checktable(L, 1);
|
||||
|
||||
|
@ -501,20 +504,20 @@ luaA_statusbar_new(lua_State *L)
|
|||
sb->name = luaA_name_init(L);
|
||||
|
||||
lua_getfield(L, 1, "fg");
|
||||
if((color = luaL_optstring(L, -1, NULL)))
|
||||
if((buf = luaL_optstring(L, -1, NULL)))
|
||||
xcolor_new(globalconf.connection, globalconf.default_screen,
|
||||
color, &sb->colors.fg);
|
||||
buf, &sb->colors.fg);
|
||||
else
|
||||
sb->colors.fg = globalconf.colors.fg;
|
||||
|
||||
lua_getfield(L, 1, "bg");
|
||||
if((color = luaL_optstring(L, -1, NULL)))
|
||||
if((buf = luaL_optstring(L, -1, NULL)))
|
||||
xcolor_new(globalconf.connection, globalconf.default_screen,
|
||||
color, &sb->colors.bg);
|
||||
buf, &sb->colors.bg);
|
||||
else
|
||||
sb->colors.bg = globalconf.colors.bg;
|
||||
|
||||
sb->align = draw_align_get_from_str(luaA_getopt_string(L, 1, "align", "left"));
|
||||
sb->align = draw_align_fromstr(luaA_getopt_string(L, 1, "align", "left", &len), len);
|
||||
|
||||
sb->width = luaA_getopt_number(L, 1, "width", 0);
|
||||
if(sb->width > 0)
|
||||
|
@ -524,7 +527,8 @@ luaA_statusbar_new(lua_State *L)
|
|||
/* 1.5 as default factor, it fits nice but no one knows why */
|
||||
sb->height = 1.5 * globalconf.font->height;
|
||||
|
||||
sb->position = position_get_from_str(luaA_getopt_string(L, 1, "position", "top"));
|
||||
buf = luaA_getopt_string(L, 1, "position", "top", &len);
|
||||
sb->position = position_fromstr(buf, len);
|
||||
|
||||
return luaA_statusbar_userdata_new(L, sb);
|
||||
}
|
||||
|
|
2
tag.c
2
tag.c
|
@ -357,7 +357,7 @@ luaA_tag_new(lua_State *L)
|
|||
mwfact = luaA_getopt_number(L, 1, "mwfact", 0.5);
|
||||
ncol = luaA_getopt_number(L, 1, "ncol", 1);
|
||||
nmaster = luaA_getopt_number(L, 1, "nmaster", 1);
|
||||
lay = luaA_getopt_string(L, 1, "layout", "tile");
|
||||
lay = luaA_getopt_string(L, 1, "layout", "tile", NULL);
|
||||
|
||||
layout = name_func_lookup(lay, LayoutList);
|
||||
|
||||
|
|
17
titlebar.c
17
titlebar.c
|
@ -298,12 +298,13 @@ luaA_titlebar_new(lua_State *L)
|
|||
{
|
||||
titlebar_t *tb;
|
||||
const char *color;
|
||||
size_t len;
|
||||
|
||||
luaA_checktable(L, 1);
|
||||
|
||||
tb = p_new(titlebar_t, 1);
|
||||
|
||||
tb->align = draw_align_get_from_str(luaA_getopt_string(L, 1, "align", "left"));
|
||||
tb->align = draw_align_fromstr(luaA_getopt_string(L, 1, "align", "left", &len), len);
|
||||
|
||||
tb->width = luaA_getopt_number(L, 1, "width", 0);
|
||||
tb->height = luaA_getopt_number(L, 1, "height", 0);
|
||||
|
@ -311,21 +312,21 @@ luaA_titlebar_new(lua_State *L)
|
|||
/* 1.5 as default factor, it fits nice but no one knows why */
|
||||
tb->height = 1.5 * globalconf.font->height;
|
||||
|
||||
tb->position = position_get_from_str(luaA_getopt_string(L, 1, "position", "top"));
|
||||
tb->position = position_fromstr(luaA_getopt_string(L, 1, "position", "top", &len), len);
|
||||
|
||||
if((color = luaA_getopt_string(L, -1, "fg", NULL)))
|
||||
if((color = luaA_getopt_string(L, -1, "fg", NULL, NULL)))
|
||||
xcolor_new(globalconf.connection, globalconf.default_screen,
|
||||
color, &tb->colors.fg);
|
||||
else
|
||||
tb->colors.fg = globalconf.colors.fg;
|
||||
|
||||
if((color = luaA_getopt_string(L, 1, "bg", NULL)))
|
||||
if((color = luaA_getopt_string(L, 1, "bg", NULL, NULL)))
|
||||
xcolor_new(globalconf.connection, globalconf.default_screen,
|
||||
color, &tb->colors.bg);
|
||||
else
|
||||
tb->colors.bg = globalconf.colors.bg;
|
||||
|
||||
if((color = luaA_getopt_string(L, 1, "border_color", NULL)))
|
||||
if((color = luaA_getopt_string(L, 1, "border_color", NULL, NULL)))
|
||||
xcolor_new(globalconf.connection, globalconf.default_screen,
|
||||
color, &tb->border.color);
|
||||
|
||||
|
@ -428,11 +429,11 @@ luaA_titlebar_colors_set(lua_State *L)
|
|||
|
||||
luaA_checktable(L, 2);
|
||||
|
||||
if((color = luaA_getopt_string(L, 2, "fg", NULL)))
|
||||
if((color = luaA_getopt_string(L, 2, "fg", NULL, NULL)))
|
||||
xcolor_new(globalconf.connection, globalconf.default_screen,
|
||||
color, &(*tb)->colors.fg);
|
||||
|
||||
if((color = luaA_getopt_string(L, 2, "bg", NULL)))
|
||||
if((color = luaA_getopt_string(L, 2, "bg", NULL, NULL)))
|
||||
xcolor_new(globalconf.connection, globalconf.default_screen,
|
||||
color, &(*tb)->colors.bg);
|
||||
|
||||
|
@ -459,7 +460,7 @@ luaA_titlebar_border_set(lua_State *L)
|
|||
|
||||
luaA_checktable(L, 2);
|
||||
|
||||
if((color = luaA_getopt_string(L, 2, "color", NULL)))
|
||||
if((color = luaA_getopt_string(L, 2, "color", NULL, NULL)))
|
||||
{
|
||||
xcolor_new(globalconf.connection, globalconf.default_screen,
|
||||
color, &(*tb)->border.color);
|
||||
|
|
5
widget.c
5
widget.c
|
@ -310,11 +310,12 @@ luaA_widget_new(lua_State *L)
|
|||
widget_t *w = NULL;
|
||||
widget_constructor_t *wc;
|
||||
alignment_t align;
|
||||
size_t len;
|
||||
|
||||
luaA_checktable(L, 1);
|
||||
align = draw_align_get_from_str(luaA_getopt_string(L, 1, "align", "left"));
|
||||
align = draw_align_fromstr(luaA_getopt_string(L, 1, "align", "left", &len), len);
|
||||
|
||||
type = luaA_getopt_string(L, 1, "type", NULL);
|
||||
type = luaA_getopt_string(L, 1, "type", NULL, NULL);
|
||||
|
||||
if((wc = name_func_lookup(type, WidgetList)))
|
||||
w = wc(align);
|
||||
|
|
|
@ -322,7 +322,7 @@ graph_tell(widget_t *widget, const char *property, const char *new_value)
|
|||
return WIDGET_ERROR_FORMAT_COLOR;
|
||||
return WIDGET_NOERROR;
|
||||
case A_TK_GROW:
|
||||
switch((d->grow = position_get_from_str(new_value)))
|
||||
switch((d->grow = position_fromstr(new_value, -1)))
|
||||
{
|
||||
case Left:
|
||||
case Right:
|
||||
|
|
Loading…
Reference in New Issue