shl: add shl_string_list_is() helper

This helper tests whether a string-list has only a single entry and
compares this with the given entry.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
David Herrmann 2012-10-28 16:01:47 +01:00
parent bedba7a7e3
commit fb2006fe9a
4 changed files with 12 additions and 26 deletions

View File

@ -375,28 +375,6 @@ static int aftercheck_help(struct conf_option *opt, int argc, char **argv,
return 0;
}
static int aftercheck_seats(struct conf_option *opt, int argc, char **argv,
int idx)
{
struct kmscon_conf_t *conf = KMSCON_CONF_FROM_FIELD(opt->mem, seats);
if (conf->seats[0] &&
!conf->seats[1] &&
!strcmp(conf->seats[0], "all"))
conf->all_seats = true;
return 0;
}
static int copy_seats(struct conf_option *opt, const struct conf_option *src)
{
struct kmscon_conf_t *conf = KMSCON_CONF_FROM_FIELD(opt->mem, seats);
struct kmscon_conf_t *s = KMSCON_CONF_FROM_FIELD(src->mem, seats);
conf->all_seats = s->all_seats;
return 0;
}
static int aftercheck_drm(struct conf_option *opt, int argc, char **argv,
int idx)
{
@ -470,7 +448,7 @@ int kmscon_conf_new(struct conf_ctx **out)
/* Seat Options */
CONF_OPTION(0, 0, "vt", &conf_vt, NULL, NULL, NULL, &conf->vt, NULL),
CONF_OPTION_BOOL('s', "switchvt", &conf->switchvt, true),
CONF_OPTION_STRING_LIST_FULL(0, "seats", aftercheck_seats, copy_seats, NULL, &conf->seats, def_seats),
CONF_OPTION_STRING_LIST(0, "seats", &conf->seats, def_seats),
/* Session Options */
CONF_OPTION_UINT(0, "session-max", &conf->session_max, 50),

View File

@ -57,8 +57,6 @@ struct kmscon_conf_t {
bool switchvt;
/* seats */
char **seats;
/* true if \seats is "all" */
bool all_seats;
/* Session Options */
/* sessions */

View File

@ -118,7 +118,7 @@ static int app_seat_new(struct kmscon_app *app, struct app_seat **out,
bool found;
found = false;
if (app->conf->all_seats) {
if (shl_string_list_is(app->conf->seats, "all")) {
found = true;
} else {
for (i = 0; app->conf->seats[i]; ++i) {

View File

@ -189,6 +189,16 @@ static inline int shl_dup_array(char ***out, char **argv)
return shl_dup_array_size(out, argv, i);
}
/* returns true if the string-list contains only a single entry \entry */
static inline bool shl_string_list_is(char **list, const char *entry)
{
if (!list || !entry)
return false;
if (!list[0] || list[1])
return false;
return !strcmp(list[0], entry);
}
/* TODO: xkbcommon should provide these flags!
* We currently copy them into each library API we use so we need to keep
* them in sync. Currently, they're used in uterm-input and tsm-vte. */