CCSSettingValueList ccsGetValueListFromMatchArray (const char ** array, int num, CCSSetting *parent) { CCSSettingValueList l = NULL; int i; for (i = 0; i < num; i++) { CCSSettingValue *value = calloc (1, sizeof (CCSSettingValue)); if (!value) return l; value->refCount = 1; value->isListChild = TRUE; value->parent = parent; value->value.asMatch = strdup (array[i]); l = ccsSettingValueListAppend (l, value); } return l; }
CCSSettingValueList ccsGetValueListFromColorArray (CCSSettingColorValue * array, int num, CCSSetting *parent) { CCSSettingValueList l = NULL; int i; for (i = 0; i < num; i++) { CCSSettingValue *value = calloc (1, sizeof (CCSSettingValue)); if (!value) return l; value->refCount = 1; value->isListChild = TRUE; value->parent = parent; value->value.asColor = array[i]; l = ccsSettingValueListAppend (l, value); } return l; }
CCSSettingValueList ccsGetValueListFromStringList (CCSStringList list, CCSSetting *parent) { CCSSettingValueList rv = NULL; while (list) { CCSSettingValue *value = calloc (1, sizeof (CCSSettingValue)); if (!value) return rv; value->refCount = 1; value->isListChild = TRUE; value->parent = parent; value->value.asString = strdup (((CCSString *)list->data)->value); rv = ccsSettingValueListAppend (rv, value); list = list->next; } return rv; }
static void ccpValueToSetting (CompObject *object, CCSSetting *s, CompOptionValue *v) { CCSSettingValue *value; value = calloc (1, sizeof (CCSSettingValue)); if (!value) return; value->parent = s; if (s->type == TypeList) { int i; for (i = 0; i < v->list.nValue; i++) { CCSSettingValue *val; val = calloc (1, sizeof (CCSSettingValue)); if (val) { val->parent = s; val->isListChild = TRUE; ccpInitValue (object, val, &v->list.value[i], s->info.forList.listType); value->value.asList = ccsSettingValueListAppend (value->value.asList, val); } } } else ccpInitValue (object, value, v, s->type); ccsSetValue (s, value); ccsFreeSettingValue (value); }
Bool ccsIniGetList (IniDictionary *dictionary, const char *section, const char *entry, CCSSettingValueList *value, CCSSetting *parent) { CCSSettingValueList list = NULL; char *valueString, *valueStart, *valString; char *token; int nItems = 1, i = 0, len; valString = getIniString (dictionary, section, entry); if (!valString) return FALSE; if (isEmptyString (valString)) { *value = NULL; return TRUE; } valueString = strdup (valString); valueStart = valueString; /* remove trailing semicolon that we added to be able to differentiate between an empty list and a list with one empty item */ len = strlen (valueString); if (valueString[len - 1] == ';') valueString[len - 1] = 0; token = strchr (valueString, ';'); while (token) { token = strchr (token + 1, ';'); nItems++; } token = strsep (&valueString, ";"); switch (parent->info.forList.listType) { case TypeString: case TypeMatch: { char **array = malloc (nItems * sizeof (char*)); if (!array) break; while (token) { array[i++] = strdup (token); token = strsep (&valueString, ";"); } list = ccsGetValueListFromStringArray (array, nItems, parent); for (i = 0; i < nItems; i++) free (array[i]); free (array); } break; case TypeColor: { CCSSettingColorValue *array; array = malloc (nItems * sizeof (CCSSettingColorValue)); if (!array) break; while (token) { memset (&array[i], 0, sizeof (CCSSettingColorValue)); ccsStringToColor (token, &array[i]); token = strsep (&valueString, ";"); i++; } list = ccsGetValueListFromColorArray (array, nItems, parent); free (array); } break; case TypeBool: { Bool *array = malloc (nItems * sizeof (Bool)); Bool isTrue; if (!array) break; while (token) { isTrue = (token[0] == 'y' || token[0] == 'Y' || token[0] == '1' || token[0] == 't' || token[0] == 'T'); array[i++] = isTrue; token = strsep (&valueString, ";"); } list = ccsGetValueListFromBoolArray (array, nItems, parent); free (array); } break; case TypeInt: { int *array = malloc (nItems * sizeof (int)); if (!array) break; while (token) { array[i++] = strtoul (token, NULL, 10); token = strsep (&valueString, ";"); } list = ccsGetValueListFromIntArray (array, nItems, parent); free (array); } break; case TypeFloat: { float *array = malloc (nItems * sizeof (float)); if (!array) break; while (token) { array[i++] = strtod (token, NULL); token = strsep (&valueString, ";"); } list = ccsGetValueListFromFloatArray (array, nItems, parent); free (array); } break; case TypeKey: { CCSSettingValue *val = NULL; list = NULL; while (token) { val = malloc (sizeof (CCSSettingValue)); if (!val) break; if (ccsStringToKeyBinding (token, &val->value.asKey)) list = ccsSettingValueListAppend (list, val); else free (val); token = strsep (&valueString, ";"); } } break; case TypeButton: { CCSSettingValue *val = NULL; list = NULL; while (token) { val = malloc (sizeof (CCSSettingValue)); if (!val) break; if (ccsStringToButtonBinding (token, &val->value.asButton)) list = ccsSettingValueListAppend (list, val); else free (val); token = strsep (&valueString, ";"); } } break; case TypeEdge: { CCSSettingValue *val = NULL; list = NULL; while (token) { val = malloc (sizeof (CCSSettingValue)); if (!val) break; val->value.asEdge = ccsStringToEdges (token); list = ccsSettingValueListAppend (list, val); token = strsep (&valueString, ";"); } } break; case TypeBell: { CCSSettingValue *val = NULL; list = NULL; Bool isTrue; while (token) { val = malloc (sizeof (CCSSettingValue)); if (!val) break; isTrue = (token[0] == 'y' || token[0] == 'Y' || token[0] == '1' || token[0] == 't' || token[0] == 'T'); val->value.asBell = isTrue; list = ccsSettingValueListAppend (list, val); token = strsep (&valueString, ";"); } } break; default: break; } *value = list; free (valueStart); return TRUE; }