Beispiel #1
0
void _stack_wordize(char *in_string, char **out_items[], long **out_offsets, int *out_count)
{
    assert(out_items != NULL);
    assert(out_count != NULL);
    
    if (!in_string) in_string = "";
    
    *out_items = NULL;
    *out_count = 0;
    if (out_offsets) *out_offsets = NULL;
    int alloc_words = 0;
    
    char const *word_begin = xte_cstring_index_word(in_string, 0);
    while (word_begin)
    {
        char const *word_end = xte_cstring_index_word_end(word_begin);
        
        if (*out_count + 1 > alloc_words)
        {
            char **new_words = _stack_realloc(*out_items, sizeof(char*) * (alloc_words + WORDIZE_ALLOC_SIZE));
            if (!new_words) return app_out_of_memory_void();
            *out_items = new_words;
            
            if (out_offsets)
            {
                long *new_offsets = _stack_realloc(*out_offsets, sizeof(long) * (alloc_words + WORDIZE_ALLOC_SIZE));
                if (!new_offsets) return app_out_of_memory_void();
                *out_offsets = new_offsets;
            }
            
            alloc_words += WORDIZE_ALLOC_SIZE;
        }
        
        char *the_word = _stack_malloc(word_end - word_begin + 1);
        if (!the_word) return app_out_of_memory_void();
        memcpy(the_word, word_begin, word_end - word_begin);
        the_word[word_end - word_begin] = 0;
        (*out_items)[*out_count] = the_word;
        
        if (out_offsets)
            (*out_offsets)[*out_count] = xte_cstring_chars_between(in_string, word_begin);
        
        (*out_count)++;
        
        word_begin = xte_cstring_index_word(word_begin, 1);
    }
}
Beispiel #2
0
void Stack_push(Stack _stk, var _data)
{
    _stk->stack[_stk->stack_top_ptr] = _data;
    _stk->stack_top_ptr++;
    if (unlikely(_stk->stack_top_ptr == _stk->stack_length))
    {
        _stack_realloc(_stk);
    }
}
Beispiel #3
0
static int _begin_write(SerBuff *in_buff, long in_required)
{
    if (in_required + in_buff->size > in_buff->alloc)
    {
        long new_size = in_required + in_buff->size;
        char *new_data = _stack_realloc(in_buff->data, new_size);
        if (!new_data) return _stack_panic_false(in_buff->stack, STACK_ERR_MEMORY);
        
        in_buff->alloc = new_size;
        in_buff->data = new_data;
    }
    return STACK_YES;
}
Beispiel #4
0
void _undo_record_step(Stack *in_stack, enum UndoAction in_action, SerBuff *in_data)
{
    
    
    if ((!in_stack->undo_stack) || (!in_stack->record_undo_steps)) {
        if (in_data)
            serbuff_destroy(in_data, 1);
        return;
    }
    
    struct UndoFrame *frame = in_stack->undo_stack + in_stack->undo_redo_ptr;
    
    struct UndoStep *new_steps = _stack_realloc(frame->steps, sizeof(struct UndoStep) * (frame->step_count + 1));
    if (!new_steps) return;
    frame->steps = new_steps;
    struct UndoStep *step = new_steps + frame->step_count;
    frame->step_count++;
    
    step->action = in_action;
    step->data = in_data;
}