Esempio n. 1
0
int group_length(const group& gr, int wrap_length) {
    int sum = 3; // length of "{ }"
    for (const auto& key : gr) { 
        sum += 4 + key.size() + value_length(gr.get<value>(key)); // ", = "
    }
    return sum;
}
Esempio n. 2
0
int vector_length(const value_vector_type& vec, int wrap_length) {
    int sum = 3; // length of "[ ]"
    for (const auto& val : vec) {
        sum += 2 + value_length(val); // ", "
    }
    return sum;
}
Esempio n. 3
0
value value_cons(value op1, value op2)
{
	value res = value_init_nil();
	if (op2.type == VALUE_NIL) {
		res = value_init(VALUE_PAR);
		res.core.u_p->head = value_set(op1);
	} else if (op2.type == VALUE_ARY) {
		size_t length = value_length(op2) + 1;
		value array[length];
		array[0] = op1;
		size_t i;
		for (i = 1; i < length; ++i)
			array[i] = op2.core.u_a.a[i-1];
		res = value_set_ary(array, length);
	} else if (op2.type == VALUE_LST) {
		res = value_init(VALUE_LST);
		res.core.u_l[0] = value_set(op1);
		res.core.u_l[1] = value_set(op2);
	} else if (op2.type == VALUE_PAR) {
		res = value_init(VALUE_PAR);
		res.core.u_l[0] = value_set(op1);
		res.core.u_l[1] = value_set(op2);
	} else {
		value_error(1, "Type Error: cons() is undefined where op2 is %ts (nil, array or list expected).", op2);
		res = value_init_error();
	}
	
	return res;
}
Esempio n. 4
0
value value_tail(value op)
{
	if (op.type == VALUE_ARY) {
		size_t length = value_length(op);
		if (length == 0) {
			value_error(1, "Error: cannot find tail() of an empty array.");
			return value_init_error();
		}
		
		value array[length - 1];
		size_t i;
		for (i = 0; i < length-1; ++i)
			array[i] = op.core.u_a.a[i+1];
		
		value res = value_set_ary(array, length-1);
		
		return res;
		
	} else if (op.type == VALUE_LST) {		
		return value_set(op.core.u_l[1]);
		
	} else if (op.type == VALUE_PAR) {
		return value_set(op.core.u_p->tail);
	} else {
		value_error(1, "Type Error: tail() is undefined where op is %ts (array or list expected).", op);
		return value_init_error();
	}

}
void Test_M2MResourceInstance::test_get_value()
{
    u_int8_t test_value[] = {"value3"};
    u_int32_t value_length((u_int32_t)sizeof(test_value));

    resource_instance->_value = (u_int8_t *)malloc(value_length);
    resource_instance->_value_length = value_length;
    memcpy((u_int8_t *)resource_instance->_value, (u_int8_t *)test_value, value_length);

    resource_instance->clear_value();

    CHECK(resource_instance->_value == NULL);

}
Esempio n. 6
0
value value_cons_now2(value *op1, value *op2)
{
	if (op2->type == VALUE_NIL) {
		op2->type = VALUE_PAR;
		value_malloc(op2, 2);
		if (op2->type == VALUE_ERROR) return;
		op2->core.u_p->head = *op1;
		op2->core.u_p->tail = value_init_nil();
		
	} else if (op2->type == VALUE_ARY) {
		value res;
		res.type = VALUE_ARY;
		size_t i, length = value_length(*op2);
		if (resize_p(length+1)) {
			value_realloc(op1, next_size(length+1) + 1);
			if (op1->type == VALUE_ERROR)
				return value_init_error();
		}
		for (i = 1; i < length; ++i)
			res.core.u_a.a[i+1] = op2->core.u_a.a[i];
		res.core.u_a.a[0] = *op1;
		res.core.u_a.length = op2->core.u_a.length + 1;
		*op2 = res;
	} else if (op2->type == VALUE_LST) {
		value res;
		res.type = VALUE_LST;
		value_malloc(&res, 2);
		if (res.type == VALUE_ERROR) {
			return value_init_error();
		}
		res.core.u_l[0] = *op1;
		res.core.u_l[1] = *op2;
		*op2 = res;		
	} else if (op2->type == VALUE_PAR) {
		value res;
		res.type = VALUE_PAR;
		value_malloc(&res, 2);
		return_if_error(res);
		res.core.u_l[0] = *op1;
		res.core.u_l[1] = *op2;
		*op2 = res;		
	} else {
		value_error(1, "Type Error: cons() is undefined where op2 is %ts (nil, array or list expected).", *op2);
		return value_init_error();
	}
	
	return value_init_nil();
}
Esempio n. 7
0
value value_head(value op)
{
	if (op.type == VALUE_ARY) {
		if (value_length(op) == 0) {
			value_error(1, "Error: cannot find head() of an empty array.");
			return value_init_error();
		}

		return value_set(op.core.u_a.a[0]);
	} else if (op.type == VALUE_LST) {
		return value_set(op.core.u_l[0]);
	} else if (op.type == VALUE_PAR) {
		return value_set(op.core.u_p->head);
	} else {
		value_error(1, "Type Error: head() is undefined where op is %ts (array or list expected).", op);
		return value_init_error();
	}
}
Esempio n. 8
0
value value_tail_now(value *op)
{
	if (op->type == VALUE_NIL) {
		value_error(1, "Error: cannot find tail!() of an empty list.");
		return value_init_error();
	} else if (op->type == VALUE_ARY) {
		size_t i, length = value_length(*op);
		if (length == 0) {
			value_error(1, "Error: cannot find tail!() of an empty array.");
			return value_init_error();
		}
		
		value_clear(&op->core.u_a.a[0]);
		for (i = 0; i < length-1; ++i)
			op->core.u_a.a[i] = op->core.u_a.a[i+1];
		
		--op->core.u_a.length;
	} else if (op->type == VALUE_LST) {
		if (value_empty_p(*op)) {
			value_error(1, "Error: cannot find tail!() of an empty list.");
			return value_init_error();
		} else {
			value_clear(&op->core.u_l[0]);
			value_free(op->core.u_l);
			*op = op->core.u_l[1];
		}
	} else if (op->type == VALUE_PAR) {
		value tmp = op->core.u_p->tail;
		value_clear(&op->core.u_p->head);
		value_free(op->core.u_p);
		*op = tmp;
	} else {
		value_error(1, "Type Error: tail!() is undefined where op is %ts (array or list expected).", *op);
		return value_init_error();
	}

	
	return value_init_nil();
}
Esempio n. 9
0
void add_values(char *pString, char_list **ppList)
{
    char_list **ppTraverse = NULL;
    char_list *pEntry = NULL;
    int iLength = 0;
    int iBackslash = 0;

    if(pString == NULL || *pString == '\0' || ppList == NULL)   {
	return;
    }

    while(pString)  {
	/*  Find start of value.
	 */
	iBackslash = 0;
	while(*pString) {
	    if(*pString == '\\')    {
		iBackslash++;
	    }
	    else if(*pString == '\n')   {
		if(iBackslash == 0)  {
		    /*  End of values.
		     *  Setting to NULL gets out of all loops.
		     */
		    pString = NULL;
		    break;
		}
		iBackslash = 0;
	    }
	    else if(!isspace(*pString))  {
		/*  Backslashes part of string.
		 *  This screws up if a backslash is in the middle of the string.
		 */
		pString -= iBackslash;
		break;
	    }

	    pString++;
	}
	if(pString == NULL || *pString == '\0') {
	    break;
	}

	/*  Do not honor anything beginning with a #
	 */
	if(*pString == '#') {
	    /*  End of line.
	     */
	    while(*pString && *pString != '\n') {
		pString++;
	    }
	    continue;
	}

	/*  Very first part of the string is value name.
	 *  How long is it?
	 */
	iLength = value_length(pString);

	/*  Do not honor $(NULL)
	 */
	if(_strnicmp(pString, "$(NULL)", 7) == 0)    {
	    pString += iLength;
	    continue;
	}

	/*  Allocate a new list entry for the next value.
	 */
	pEntry = (char_list *)calloc(1, sizeof(char_list));

	pEntry->m_pString = (char *)calloc(iLength + 1, 1);
	strncpy(pEntry->m_pString, pString, iLength);

	/*  Add new value entry to the end of the list.
	 */
	ppTraverse = ppList;
	while(*ppTraverse)  {
	    ppTraverse = &((*ppTraverse)->m_pNext);
	}
	*ppTraverse = pEntry;

	/*  Go on to next value.
	 */
	pString += iLength;
    }
}