Esempio n. 1
0
File: tags.c Progetto: flrl/goat
GoatError goat_message_set_tag(GoatMessage *message, const char *key, const char *value) {
    if (NULL == message) return EINVAL;
    if (NULL == key) return EINVAL;

    if (NULL == message->m_tags) {
        return tags_init(&message->m_tags, key, value);
    }

    if (_find_tag(message->m_tags->m_bytes, key)) {
        // tag already exists, discard the old one
        goat_message_unset_tag(message, key);
    }

    char buf[GOAT_MESSAGE_MAX_TAGS] = {0};
    char *p = buf;

    if (message->m_tags->m_len + strlen(key) + 1 > GOAT_MESSAGE_MAX_TAGS) {
        return GOAT_E_MSGLEN;
    }

    if (message->m_tags->m_len > 0) {
        // separator if there's already tag data
        *p++ = ';';
    }

    p = stpcpy(p, key);

    if (value) {
        char escaped_value[GOAT_MESSAGE_MAX_TAGS] = {0};
        size_t escaped_value_len = sizeof(escaped_value);

        _escape_value(value, escaped_value, &escaped_value_len);

        if (message->m_tags->m_len + strlen(buf) + escaped_value_len + 1 > GOAT_MESSAGE_MAX_TAGS) {
            return GOAT_E_MSGLEN;
        }

        *p++ = '=';
        p = stpcpy(p, escaped_value);
    }

    strcat(message->m_tags->m_bytes, buf);
    message->m_tags->m_len += strlen(buf);

    return 0;
}
Esempio n. 2
0
long delaunay_seeded(long start_x, long start_y, long end_x, long end_y)
{
    long tri_idx,cor_idx;
    long tri_id2,cor_id2;
    long count;
    NAVIDBG(19,"Starting");
    //return _DK_delaunay_seeded(start_x, start_y, end_x, end_y);
    tags_init();
    delaunay_init();
    delaunay_stack_point(start_x, start_y);
    delaunay_stack_point(start_x, end_y);
    delaunay_stack_point(end_x, start_y);
    delaunay_stack_point(end_x, end_y);
    count = 0;
    while (ix_delaunay > 0)
    {
        ix_delaunay--;
        tri_idx = delaunay_stack[ix_delaunay];
        for (cor_idx=0; cor_idx < 3; cor_idx++)
        {
            if (!optimise_heuristic(tri_idx, cor_idx))
                continue;
            count++;
            edge_rotateAC(tri_idx, cor_idx);
            if (ix_delaunay+4 >= DELAUNAY_COUNT)
            {
              ERRORLOG("stack full");
              return count;
            }
            for (cor_id2=0; cor_id2 < 3; cor_id2++)
            {
                tri_id2 = Triangles[tri_idx].tags[cor_id2];
                if (tri_id2 == -1)
                    continue;
                delaunay_add_triangle(tri_id2);
            }
        }
    }
    return count;
}