smart.c
/*
 * Create a match specification from the given attribute
 *
 * Attribute format is
 *     <Page ID>:<Attribute ID>
 * where page and attribute IDs are integers. If the page ID is missing,
 * match the specified attribute ID on any page (i.e. -1). Valid forms are
 *    <int>:<int>
 *    :<int>
 *    <int>
 *
 * Returns 0 on success
 */
Create a match specification from the given attribute
Attribute format is
:
where page and attribute IDs are integers. If the page ID is missing,
match the specified attribute ID on any page . Valid forms are
:
:


Returns 0 on success
Create a match specification from the given attribute Attribute format is : where page and attribute IDs are integers . If the page ID is missing match the specified attribute ID on any page . Valid forms are : : Returns 0 on success
static int
add_match(smart_matches_t **matches, char *attr)
{
	char *next;
	int32_t page = -1, id;
	uint32_t count = 0;
	id = get_val(attr, &next);
	if (id < 0)
		return id;
	if (*next == ':') {
		page = id;
		id = get_val(next + 1, &next);
		if (id < 0)
			return id;
	}
	if (*matches == NULL) {
		*matches = calloc(1, sizeof(smart_matches_t) + sizeof(smart_match_t));
		if (*matches == NULL)
			return ENOMEM;
	} else {
		void *tmp;
		count = (*matches)->count;
		tmp = realloc(*matches, sizeof(smart_matches_t) + ((count + 1) * sizeof(smart_match_t)));
		if (tmp == NULL)
			return ENOMEM;
		*matches = tmp;
	}
	(*matches)->m[count].page = page;
	(*matches)->m[count].id = id;
	(*matches)->count++;
	return 0;
}
static int add_match ( smart_matches_t * * matches , char * attr ) { char * next ; int32_t page = -1 , id ; uint32_t count = 0 ; id = get_val ( attr , & next ) ; if ( id < 0 ) return id ; if ( * next == ' ' ) { page = id ; id = get_val ( next + 1 , & next ) ; if ( id < 0 ) return id ; } if ( * matches == NULL ) { * matches = calloc ( 1 , sizeof ( smart_matches_t ) + sizeof ( smart_match_t ) ) ; if ( * matches == NULL ) return ENOMEM ; } else { void * tmp ; count = ( * matches ) -> count ; tmp = realloc ( * matches , sizeof ( smart_matches_t ) + ( ( count + 1 ) * sizeof ( smart_match_t ) ) ) ; if ( tmp == NULL ) return ENOMEM ; * matches = tmp ; } ( * matches ) -> m [ count ] . page = page ; ( * matches ) -> m [ count ] . id = id ; ( * matches ) -> count ++ ; return 0 ; }
Create a match specification from the given attribute
 Attribute format is
     <Page ID>:<Attribute ID>
 where page and attribute IDs are integers.
Create a match specification from the given attribute Attribute format is <Page ID > : <Attribute ID > where page and attribute IDs are integers .