static TextRowData* TextRowList_InsertNewRow( TextRowList *rowlist, int i_row ) { int i; TextRowData *row_ptr, **new_rowlist; if( i_row > rowlist->rows ) { return NULL; } ++rowlist->rows; if( rowlist->max_rows <= rowlist->rows ) { new_rowlist = (TextRowData**)realloc( rowlist->rowdata, sizeof(TextRowData*)*(rowlist->rows+1) ); if( !new_rowlist ) { --rowlist->rows; return NULL; } rowlist->rowdata = new_rowlist; rowlist->max_rows = rowlist->rows; } row_ptr = (TextRowData*)malloc( sizeof(TextRowData) ); if( !row_ptr ) { return NULL; } TextRow_Init( row_ptr ); for( i=rowlist->rows-1; i>i_row; --i ) { rowlist->rowdata[i] = rowlist->rowdata[i-1]; } rowlist->rowdata[i_row] = row_ptr; return row_ptr; }
static inline TextRowData* TextRowList_AddNewRow( TextRowList *rowlist ) { TextRowData *row_ptr, **new_rowlist; ++rowlist->rows; if( rowlist->max_rows <= rowlist->rows ) { new_rowlist = (TextRowData**)realloc( rowlist->rowdata, sizeof(TextRowData*)*(rowlist->rows+1) ); if( !new_rowlist ) { --rowlist->rows; return NULL; } rowlist->rowdata = new_rowlist; rowlist->max_rows = rowlist->rows; } row_ptr = (TextRowData*)malloc( sizeof(TextRowData) ); if( !row_ptr ) { return NULL; } TextRow_Init( row_ptr ); rowlist->rowdata[rowlist->rows-1] = row_ptr; return row_ptr; }
/** 向文本行列表中插入新的文本行 */ static TextRow TextRowList_InsertNewRow( TextRowList rowlist, int i_row ) { int i, size; TextRow txtrow, *txtrows; if( i_row > rowlist->length ) { i_row = rowlist->length; } ++rowlist->length; size = sizeof( TextRow )*(rowlist->length + 1); txtrows = realloc( rowlist->rows, size ); if( !txtrows ) { --rowlist->length; return NULL; } txtrows[rowlist->length] = NULL; txtrow = malloc( sizeof( TextRowRec ) ); if( !txtrow ) { --rowlist->length; return NULL; } TextRow_Init( txtrow ); for( i = rowlist->length - 1; i > i_row; --i ) { txtrows[i] = txtrows[i - 1]; } txtrows[i_row] = txtrow; rowlist->rows = txtrows; return txtrow; }