Exemplo n.º 1
0
spif_bool_t
spif_eterm_action_done(spif_eterm_action_t self)
{
    if (!SPIF_OBJ_ISNULL(self->parameter)) {
        if ((self->type == ETERM_ACTION_STRING)
            || (self->type == ETERM_ACTION_ECHO)
            || (self->type == ETERM_ACTION_SCRIPT)) {
            spif_str_del(SPIF_STR(self->parameter));
        }
    }
    self->type = ETERM_ACTION_NONE;
    self->modifiers = ETERM_MOD_NONE;
    self->button = ETERM_BUTTON_NONE;
    self->keysym = ETERM_KEYSYM_NONE;
    self->handler = (spif_eterm_action_handler_t) NULL;
    self->parameter = (spif_eterm_action_parameter_t) NULL;
    spif_obj_done(SPIF_OBJ(self));
    return TRUE;
}
Exemplo n.º 2
0
Arquivo: str.c Projeto: mej/libast
spif_bool_t
spif_str_splice(spif_str_t self, spif_stridx_t idx, spif_stridx_t cnt, spif_str_t other)
{
    spif_charptr_t tmp, ptmp;
    spif_stridx_t newsize;

    ASSERT_RVAL(!SPIF_STR_ISNULL(self), FALSE);
    if (idx < 0) {
        idx = self->len + idx;
    }
    REQUIRE_RVAL(idx >= 0, FALSE);
    REQUIRE_RVAL(idx < self->len, FALSE);
    if (cnt < 0) {
        cnt = idx + self->len + cnt;
    }
    REQUIRE_RVAL(cnt >= 0, FALSE);
    REQUIRE_RVAL(cnt <= (self->len - idx), FALSE);

    newsize = self->len + ((SPIF_STR_ISNULL(other)) ? (0) : (other->len)) - cnt + 1;
    ptmp = tmp = (spif_charptr_t) MALLOC(newsize);
    if (idx > 0) {
        memcpy(tmp, self->s, idx);
        ptmp += idx;
    }
    if (!SPIF_OBJ_ISNULL(other)) {
        memcpy(ptmp, other->s, other->len);
        ptmp += other->len;
    }
    memcpy(ptmp, self->s + idx + cnt, self->len - idx - cnt + 1);
    if (self->size < newsize) {
        self->s = (spif_charptr_t) REALLOC(self->s, newsize);
        self->size = newsize;
    }
    self->len = newsize - 1;
    memcpy(self->s, tmp, newsize);
    FREE(tmp);
    return TRUE;
}