Exemplo n.º 1
0
static int iniSectionToElektraKey (void *vhandle, const char *section)
{
	CallbackHandle *handle = (CallbackHandle *)vhandle;
	Key *appendKey = keyDup (handle->parentKey);
	keySetMeta(appendKey, "ini/lastSection", 0);
	createUnescapedKey(appendKey, section);
	Key *existingKey = NULL;
	if ((existingKey = ksLookup(handle->result, appendKey, KDB_O_NONE)))
	{
		keyDel(appendKey);
		if(!handle->mergeSections)
		{
			ELEKTRA_SET_ERRORF(140, handle->parentKey, "Section name: %s\n", section);
			return 0;
		}
		keySetMeta(existingKey, "ini/duplicate", "");
		return 1;
	}
	setSectionNumber(handle->parentKey, appendKey, handle->result);
	setOrderNumber(handle->parentKey, appendKey);
	keySetBinary(appendKey, 0, 0);	
	flushCollectedComment (handle, appendKey);
	ksAppendKey(handle->result, appendKey);

	return 1;
}
Exemplo n.º 2
0
void setOrderAddress(Order *orders, int pos) {
    setOrderStreet(orders, pos);
    setOrderNumber(orders, pos);
    setOrderPostalCode(orders, pos);
    setOrderCity(orders, pos);
}
Exemplo n.º 3
0
static int iniKeyToElektraKey (void *vhandle, const char *section, const char *name, const char *value, unsigned short lineContinuation)
{
	CallbackHandle *handle = (CallbackHandle *)vhandle;
	Key *appendKey = keyDup (handle->parentKey);
	keySetMeta(appendKey, "ini/lastSection", 0);
	if (!section || *section == '\0')
	{
		section = INTERNAL_ROOT_SECTION;
	}
	appendKey = createUnescapedKey(appendKey, section);
	short mergeSections = 0;
	Key *existingKey = NULL;
	if ((existingKey = ksLookup(handle->result, appendKey, KDB_O_NONE)))
	{
		if (keyGetMeta(existingKey, "ini/duplicate"))
		{
			mergeSections = 1;
		}
	}
	setSectionNumber(handle->parentKey, appendKey, handle->result);
	appendKey = createUnescapedKey(appendKey, name);
	existingKey = ksLookup(handle->result, appendKey, KDB_O_NONE);

	if (existingKey)
	{
		//a key with the same name already exists
		if (handle->array)
		{
			//array support is turned on 
			keySetMeta(appendKey, "ini/section", 0);
			if (keyGetMeta(existingKey, "ini/array"))
			{
				//array already exists, appending new key
				const char *lastIndex = keyString(keyGetMeta(existingKey, "ini/array"));
				keyAddBaseName(appendKey, lastIndex);
				keySetMeta(appendKey, "order/parent", 0);
				keySetMeta(appendKey, "ini/array", 0);
				keySetMeta(appendKey, "order", 0);
				if (elektraArrayIncName(appendKey) == 1)
				{
					return -1;
				}
				keySetString(appendKey, value);
				keySetMeta(appendKey, "ini/key", 0);
				ksAppendKey(handle->result, appendKey);
				keySetMeta(existingKey, "ini/array", keyBaseName(appendKey));
				ksAppendKey(handle->result, existingKey);
			}
			else
			{
				//creating a new array
				Key *sectionKey = keyDup(appendKey);
				keyAddName(sectionKey, "..");
				char *origVal = strdup(keyString(existingKey));
				keySetString(appendKey, "");
				keySetMeta(appendKey, "ini/array", "#1");
				keySetMeta(appendKey, "order/parent", keyName(sectionKey));
				setSectionNumber(handle->parentKey, appendKey, handle->result);
				setOrderNumber(handle->parentKey, appendKey);
				keySetMeta(appendKey, "ini/key", "");
				ksAppendKey(handle->result, keyDup(appendKey));
				keySetMeta(appendKey, "ini/key", 0);
				keySetMeta(appendKey, "ini/array", 0);
				keySetMeta(appendKey, "parent", 0);
				keyAddName(appendKey, "#");
				keySetMeta(appendKey, "order", 0);
				if (elektraArrayIncName(appendKey) == -1)
				{
					free(origVal);
					return -1;
				}
				keySetString(appendKey, origVal);
				ksAppendKey(handle->result, keyDup(appendKey));
				free(origVal);
				if (elektraArrayIncName(appendKey) == -1)
				{
					return -1;
				}
				keySetMeta(appendKey, "parent", 0);
				keySetString(appendKey, value);
				ksAppendKey(handle->result, keyDup(appendKey));
				keyDel(appendKey);
				keyDel(sectionKey);
			}
			return 1;
		}
		else if(!lineContinuation)
		{
			ELEKTRA_SET_ERRORF(141, handle->parentKey, "Key: %s\n", name);
			return -1;
		}
	}

	setSectionNumber(handle->parentKey, appendKey, handle->result);
	if (value == NULL)
		keySetMeta(appendKey, "ini/empty", "");
	if (!lineContinuation)
	{
		flushCollectedComment (handle, appendKey);
		keySetString (appendKey, value);
		keySetMeta(appendKey, "ini/key", "");
		ksAppendKey (handle->result, appendKey);
		if (mergeSections)
		{
			keySetMeta(appendKey, "order", 0);
			insertNewKeyIntoExistendOrder(appendKey, handle->result);
		}
		else
		{
			setOrderNumber(handle->parentKey, appendKey);
		}
	}
	else
	{
		existingKey = ksLookup (handle->result, appendKey, KDB_O_NONE);
		keyDel (appendKey);
		/* something went wrong before because this key should exist */
		if (!existingKey) return -1;

		elektraKeyAppendLine(existingKey, value);
	}


	return 1;
}