Ejemplo n.º 1
0
void w_more(int c, WFILE *p)
{
    //log_message("In w_more", p->r);
    if (p->str == NULL)
        return; /* An error already occurred, we're screwed */
    expand_memory(p, 0);
    *p->ptr++ = (char)c;
}
Ejemplo n.º 2
0
void insert_data(WFILE* dest, WFILE* src)
{
    long src_len, dest_avail, len_need;

    //log_message("inserting data", dest->r);

    src_len = src->ptr - src->str;
    dest_avail = dest->end - dest->ptr;
    len_need = src_len - dest_avail;
    if (len_need > 0) {  // potential off by one here
    expand_memory(dest, len_need+2);
    }
    memcpy(dest->ptr, src->str, src_len);
    dest->ptr = dest->ptr + src_len;
    //log_message("done inserting data", dest->r);

}
Ejemplo n.º 3
0
void insert_seqList_elem( 

        seqList_t   *pList,
        int         index, 
        element_t   elem )
{

#ifdef DEBUG_F
    //check if the seqlist is still available to use
    //bug #1, fixed
    if( pList->length < 0 || pList->size <= 0 ){
        raise(ERROR, "seqlist is not initialized\n");
        return;
    }

    //check if the index is in range
    if( index < 0 || index > pList->length ){
        raise(ERROR, "insert index is out of range!\n");
        return;
    }
#endif
    
    //allocate new memory space if necessary
    //better performance could be achieved.
    element_t *pOldElems = NULL;

    if( pList->length == pList->size ){
        pList->aElem = expand_memory( pList->aElem, pList->size );
        pList->size *= EXPAND_FACTOR;
    }

    //insert new element finally
    int i = 0;
    element_t *aElem = pList->aElem;

    for( i = pList->length; i > index ; i-- ){
        aElem[i] = aElem[i-1];
    }

    aElem[index] = elem;

    pList->length += 1;

    return;
}