int combine_level(int dest, const char *src) { char **list, **item; int itemlevel; g_return_val_if_fail(src != NULL, dest); list = g_strsplit(src, " ", -1); for (item = list; *item != NULL; item++) { g_strup(*item); itemlevel = level_get(*item + (**item == '+' || **item == '-' ? 1 : 0)); if (**item == '-') dest &= ~(itemlevel); else dest |= itemlevel; } g_strfreev(list); return dest; }
int level2bits(const char *level, int *errorp) { char *orig, *str, *ptr; int ret, singlelevel, negative; if (errorp != NULL) *errorp = FALSE; g_return_val_if_fail(level != NULL, 0); if (*level == '\0') return 0; orig = str = g_strdup(level); ret = 0; for (ptr = str; ; str++) { if (*str == ' ') *str++ = '\0'; else if (*str != '\0') continue; negative = *ptr == '-'; if (*ptr == '-' || *ptr == '+') ptr++; singlelevel = level_get(ptr); if (singlelevel != 0) { ret = !negative ? (ret | singlelevel) : (ret & ~singlelevel); } else if (errorp != NULL) *errorp = TRUE; while (*str == ' ') str++; if (*str == '\0') break; ptr = str; } g_free(orig); return ret; }
int level2bits(const char *level) { char *orig, *str, *ptr; int ret, slevel, neg; g_return_val_if_fail(level != NULL, 0); if (*level == '\0') return 0; orig = str = g_strdup(level); g_strup(str); ret = 0; for (ptr = str; ; str++) { if (*str == ' ') *str++ = '\0'; else if (*str != '\0') continue; neg = *ptr == '-' ? 1 : 0; if (*ptr == '-' || *ptr == '+') ptr++; slevel = level_get(ptr); if (slevel != 0) { ret = !neg ? (ret | slevel) : (ret & ~slevel); } while (*str == ' ') str++; if (*str == '\0') break; ptr = str; } g_free(orig); return ret; }
int combine_level(int dest, const char *src) { char **list, **item, *itemname; int itemlevel; g_return_val_if_fail(src != NULL, dest); list = g_strsplit(src, " ", -1); for (item = list; *item != NULL; item++) { itemname = *item + (**item == '+' || **item == '-' ? 1 : 0); itemlevel = level_get(itemname); if (g_strcmp0(itemname, "NONE") == 0) dest = 0; else if (**item == '-') dest &= ~(itemlevel); else dest |= itemlevel; } g_strfreev(list); return dest; }
/* Only unknown keys in `optlist' should be levels. Returns -1 if unknown option was given. */ int cmd_options_get_level(const char *cmd, GHashTable *optlist) { GSList *list, *tmp, *next; int level, retlevel; /* get all the options, then remove the known ones. there should be only one left - the server tag. */ list = hashtable_get_keys(optlist); if (cmd != NULL) { for (tmp = list; tmp != NULL; tmp = next) { char *option = tmp->data; next = tmp->next; if (command_have_option(cmd, option)) list = g_slist_remove(list, option); } } retlevel = 0; while (list != NULL) { level = level_get(list->data); if (level == 0) { /* unknown option */ signal_emit("error command", 2, GINT_TO_POINTER(CMDERR_OPTION_UNKNOWN), list->data); retlevel = -1; break; } retlevel |= level; list = g_slist_remove(list, list->data); } return retlevel; }
level_t world_get_level(world_t w) { return level_get(w->level_dat); }
bool is_white(int16_t value) { return level_get(value) == WHITE; }
bool is_grey(int16_t value) { return level_get(value) == GREY; }
//quantises an analog value from sensor into levels defined in config.h bool is_black(int16_t value) { return level_get(value) == BLACK; }