コード例 #1
0
ファイル: buffer.c プロジェクト: ab25cq/clover2
void sBuf_append_char(sBuf* self, char c)
{
    if(self->mSize <= self->mLen + 1 + 1) {
        self->mSize = (self->mLen + 1 + 1) * 2;
        self->mBuf = (char*)MREALLOC(self->mBuf, self->mSize);
    }

    self->mBuf[self->mLen] = c;
    self->mLen++;
    self->mBuf[self->mLen] = 0;
}
コード例 #2
0
ファイル: buffer.c プロジェクト: ab25cq/clover2
void sBuf_append(sBuf* self, void* str, size_t size)
{
    void* str2;

    str2 = MCALLOC(1, size);        // prevent deleting from bellow REALLOC
    memcpy(str2, str, size);

    if(self->mSize <= self->mLen + size + 1) {
        self->mSize = (self->mLen + size + 1) * 2;
        self->mBuf = MREALLOC(self->mBuf, sizeof(char)*self->mSize);
    }

    memcpy(self->mBuf + self->mLen, str2, size);

    self->mLen += size;
    self->mBuf[self->mLen] = 0;

    MFREE(str2);
}
コード例 #3
0
ファイル: xfunc.c プロジェクト: ab25cq/clover
void* xxrealloc(void* old_data, size_t old_data_size, size_t new_size)
{
/*
    void* result;

    if(new_size <= old_data_size) {
        fprintf(stderr, "invalid new_size on xxrealloc\n");
        exit(2);
    }

    result = CALLOC(1, new_size);

    memcpy(result, old_data, old_data_size);

    return result;
*/

    assert(new_size > 0);

    return MREALLOC(old_data, new_size);
}
コード例 #4
0
ファイル: ematexp.c プロジェクト: Rajesh-Veeranki/MACEK
int	ematrix_printmore_flats(ematrix *rf, int rk, int wh) {
	static long	*save=NULL, sl=0,si;
	ematrix		*rrf;
	long		l;
	int		i,j,k, r = 1;
	
	if (wh!=1) if (!save || !sl)  {PROGERROR("must be initialized first!"); return 0;}
	if (wh==1) {
		sl = 1000;  save = MMALLOC(sl*sizeof(save[0]));
	} else if (wh==-1) {
		FREE(save);  save = NULL;  si = sl = 0;
	} else {
		if (si>=sl-4)  save = MREALLOC(save,(sl*=2)*sizeof(save[0]));
		rrf = REFMAT(rf);
			/**
			 * The previously allowed flats are stored as set bitmaps to the list
			 * save, and the new flat given by rf is compared against all saved
			 * ones bit by bit.
			 * If it equals, or it is just by the rank difference bigger, to saved
			 * one, the new flat is rejected (and not stored).
			**/
		for (i=0,l=0; i<ROWSM(rf)+COLSM(rf); i++)
			l |= 1l<<(i<ROWSM(rf)? GETREFMROW(rf,i):
					GETREFMCOL(rf,i-ROWSM(rf))+ROWSM(rrf));
		for (i=0; i<si/2 && r>=0; i++) {
			for (j=k=0; j<ROWSM(rrf)+COLSM(rrf); j++)
				k += ((l&(1l<<j))!=(save[2*i]&(1l<<j)));
			if ((k==1 && rk==save[2*i+1]) || (k==0 && rk!=save[2*i+1]))
				{PROGERROR("something wrong with the saved flats... (k=%d, %d~%ld)",k,rk,save[2*i+1]);}
			if (k<=rk-save[2*i+1])  r = -1;
		}
		if (r>=0) {
			save[si] = l;  save[si+1] = rk;
			si += 2;
		}
	}
	return r;
}