Ejemplo n.º 1
0
int Cparseini::parse(char *file)
{
//	printf("parseini file=%s\n",file);//test ok
	CAllotMem allot(file);
	CGet get;
	char *src=allot.allot.start;

	if((this->head=(Ciniformat*)malloc(sizeof(Ciniformat)))==NULL){ //will fill zero
		printf("Error:if((this->head=(Ciniformat*)malloc(sizeof(Ciniformat)))==NULL)\n");
		return -1;
	}
	this->head->init();

	this->count=0;
	this->current=this->head;
	for(;src<allot.allot.end&&src;)
	{
		src=get.getLine(src,allot.allot.end);
		if(!this->parse(get.buf,this->current)) continue; //no use current  continue
		this->count++;

		if((this->next=(Ciniformat*)malloc(sizeof(Ciniformat)))==NULL){ //will fill zero
			printf("Error:if((this->next=(Ciniformat*)malloc(sizeof(Ciniformat)))==NULL)\n");
			this->freeH(this->head);
			return -1;
		}

		this->next->init(); //init 
		//set link 
		this->current->next=this->next;
		this->next->before=this->current;
		this->current=this->next;
		this->tail=this->next;
	}
	return this->count;	
}
Ejemplo n.º 2
0
// copy
//
str* copy(char* data, int len) {
	str* s = allot(len);
	memcpy(s->data,data,len);
	return s;
}
Ejemplo n.º 3
0
// concat
//
str* concat(str* a, str* b) {
	str* s = allot(a->length + b->length);
	memcpy(s->data,a->data,a->length);
	memcpy(s->data + a->length,b->data,b->length);
	return s;
}
Ejemplo n.º 4
0
// strnum
// 
// 	returns a string version of a number
// 	use immediately or it might be mutated
//
str* strnum(int i) {
	str* _numstr = allot(16);
	_numstr->length = snprintf(_numstr->buffer,16,"%ld",i);
	return _numstr;
}