Example #1
0
int main(int argc, char **argv)
{
	GOC_IStream *is = NULL;
	GOC_OStream *os = NULL;
	int c;
//	unsigned char *pBuff;
//	unsigned int nBuff;
	char *line;

	if ( argc < 2 )
	{
		GOC_ERROR("No input file name");
		return -1;
	}

	os = goc_memOStreamOpen();

	GOC_INFO("--- GOC_FileIStream test");
	is = goc_fileIStreamOpen(argv[1]);
//	nBuff = goc_isAvailable(is);
//	pBuff = malloc(nBuff);
	GOC_BINFO("Available: %d\n", goc_isAvailable(is));
//	nBuff = 0;
	while ( (c = goc_isReadChar(is)) > 0 )
	{
		goc_osWriteByte(os, (unsigned char)c);
//		pBuff[nBuff++] = c;
		putchar(c);
	}
	goc_isClose(is);

	GOC_INFO("--- GOC_MemIStream test\n");
	is = goc_memIStreamAttach(goc_memOStreamGet(os), goc_memOStreamSize(os));
//	nBuff = goc_isAvailable(is);
	GOC_BINFO("Available: %d\n", goc_isAvailable(is));
	while ( (c = goc_isReadChar(is)) > 0 )
		putchar(c);
	goc_isClose(is);

	GOC_INFO("--- GOC_FileIStream readLine test");
	is = goc_fileIStreamOpen(argv[1]);
	while ( (line = goc_isReadLine(is)) )
	{
		printf("%s\n", line);
	}
	goc_isClose(is);
	
	return 0;
}
Example #2
0
int main(int argc, char **argv)
{
	GOC_IStream* is = NULL;
	GOC_Iterator* it = NULL;
	GOC_Properties* props = NULL;
	if ( argc != 2 )
	{
		GOC_INFO("Podaj jako argument plik typu properties");
		return -1;
	}
	is = goc_fileIStreamOpen(argv[1]);
	props = goc_propertiesAlloc();
	props = goc_propertiesLoad(props, is);

	it = goc_propertiesListCategories(props);
	while ( goc_iteratorHasNext(it) )
	{
		GOC_Category* cat = (GOC_Category*)goc_iteratorNext(it);
		printf("GOC_Category: %s\n", cat->name);
		GOC_Iterator* pit = goc_propertiesListCategory(props, cat->name);
		while ( goc_iteratorHasNext(pit) )
		{
			GOC_Property* p = (GOC_Property*)goc_iteratorNext(pit);
			printf("\t%s = %s\n", p->name, p->value);
		}
		free(pit);
		printf("\n");
	}
	free(it);


	props = goc_propertiesFree(props);
	goc_isClose(is);
	return 0;
}
Example #3
0
void endProgram(int c)
{
	/*
	if ( outbuf )
	{
		free( outbuf );
		outbuf = NULL;
	}
	*/
	GOC_INFO("Cleaning control module");
	controlCleanup();
	printf("Cleaning playlist handler\n");
	playlistCleanup();

	exit(c);
}
Example #4
0
static void initializeMixerSystem(MixerHandler handler) {
	int camount = 0;
	int eamount = 0;
	int i, j;

	GOC_CHEOP_DEBUG(mixerGetCardsAmount(handler, &camount) == MIXER_CODE_OK, return);
	GOC_CHEOP_DEBUG(camount > 0, return);
	for ( i=0; i<camount; i++ ) {
		GOC_CHEOP_DEBUG(mixerSelectCard(handler, i) == MIXER_CODE_OK, continue );
		GOC_CHEOP_DEBUG(mixerGetElementsAmount(handler, &eamount) == MIXER_CODE_OK, continue);
		GOC_CHEOP_DEBUG(eamount > 0, continue);
		for ( j=0; j<eamount; j++ ) {
			MixerElement* element = NULL;
			GOC_CHEOP_DEBUG(mixerGetElementInfo(handler, j, &element) == MIXER_CODE_OK, continue);
			if ( element->type == MIXER_ELEMENT_PLAYBACK ) {
				GOC_CHEOP_DEBUG(mixerSelectElement(handler, j) == MIXER_CODE_OK, continue);
				GOC_INFO("Select mixer system");
				mixer = handler;
				return;
			}
		}
	}
Example #5
0
static void generateLandMass(
	int code, // genrowany kod
	int *pAllowedCode, // dozwolona tablica kodow do zjadania
	int nAllowedCode)
{
	stChange** pBiomeSet = NULL;
	int nBiomeSet = 0;
	int landMass = context->configuration.minLandMass + goc_random(context->configuration.maxLandMass-context->configuration.minLandMass);
	stChange* point = NULL;
	GOC_BINFO("Generate land %d with landmass size %d", code, landMass);
	point = randomLandMassStartPoint(code, pAllowedCode, nAllowedCode, 20);
	if ( point == NULL )
	{
		GOC_INFO("Start point of landmass not found");
		return;
	}
	pBiomeSet = goc_tableAdd(pBiomeSet, &nBiomeSet, sizeof(void*));
	pBiomeSet[nBiomeSet-1] = point;
	goc_maparawSetPoint(context->mapa, point->x, point->y, point->v);
	while ( landMass )
	{
		if ( ! nBiomeSet )
		{
			break;
		}
		int r = goc_random(nBiomeSet);
		point = pBiomeSet[r];
		int x = point->x;
		int y = point->y;
		// czy ma zginac - TODO: MARGIN
		if (
			( (x+1 >= context->configuration.maxx) || (!isInCodeSet(goc_maparawGetPoint(context->mapa, x+1, y), pAllowedCode, nAllowedCode)) ) &&
			( (y+1 >= context->configuration.maxy) || (!isInCodeSet(goc_maparawGetPoint(context->mapa, x, y+1), pAllowedCode, nAllowedCode)) ) &&
			( (y-1 <= 0) || (!isInCodeSet(goc_maparawGetPoint(context->mapa, x, y-1), pAllowedCode, nAllowedCode)) ) &&
			( (x-1 <= 0) || (!isInCodeSet(goc_maparawGetPoint(context->mapa, x-1, y), pAllowedCode, nAllowedCode)) )
		)
		{
			free(pBiomeSet[r]);
			pBiomeSet = goc_tableRemove(pBiomeSet, &nBiomeSet, sizeof(void*), r);
			continue;
		}
		// znajdz, jakie miejsce moze zarazic
		{
			// RANDOM ONLY in 4 base direction
			int r = goc_random(4);
			switch ( r )
			{
				case 0:
					x++;
					break;
				case 1:
					x--;
					break;
				case 2:
					y++;
					break;
				case 3:
					y--;
					break;
			}
		}
		// wykluczenie
		if (( x >= context->configuration.maxx ) || ( y >= context->configuration.maxy ) || ( x < 0 ) || ( y < 0 ))
		{
			continue;
		}
		if ( !isInCodeSet( goc_maparawGetPoint(context->mapa, x, y), pAllowedCode, nAllowedCode) )
		{
			continue;
		}
		// wykonaj zarazenie
		{
			stChange* newpoint = mallocPoint(x, y, point->v);
			pBiomeSet = goc_tableAdd(pBiomeSet, &nBiomeSet, sizeof(void*));
			pBiomeSet[nBiomeSet-1] = newpoint;
			goc_maparawSetPoint(context->mapa, x, y, point->v);
			landMass--;
			// goc_maskPaintPoint(maska, x, y); // TODO: metoda paintAreaPoint, do rysowania punktu wskazanego z danych
		}
	}
	pBiomeSet = goc_tableClear(pBiomeSet, &nBiomeSet);
}
Example #6
0
static int hotkeyNextTurnDrops(
	GOC_HANDLER u, GOC_StMessage* msg)
{
	// TODO: Setting max and min landmass for forest/hills/land seperate
	GOC_BINFO("Turn: %3d", nBiomeTurn);
	if ( nBiomeTurn <= 0 )
	{
		// fill up with sea
		generateFillUp(6);
	}
	else if ( nBiomeTurn <= biome.lands )
	{
		int *allowed = malloc(sizeof(int)*1);
		allowed[0] = 6;
		generateLandMass(1, allowed, 1);
		free(allowed);
	}
	else if ( nBiomeTurn <= biome.lands + biome.trees )
	{
		int *allowed = malloc(sizeof(int)*1);
		allowed[0] = 1;
		generateLandMass(2, allowed, 1);
		free(allowed);
	}
	else if ( nBiomeTurn <= biome.lands + biome.trees + biome.hills )
	{
		int *allowed = malloc(sizeof(int)*1);
		allowed[0] = 1;
		generateLandMass(4, allowed, 1);
		free(allowed);
	}
	else if ( nBiomeTurn <= biome.lands + biome.trees + biome.hills + biome.desert )
	{
		int *allowed = malloc(sizeof(int)*1);
		allowed[0] = 1;
		generateLandMass(5, allowed, 1);
		free(allowed);
	}
	else if ( nBiomeTurn <= biome.lands + biome.trees + biome.hills + biome.desert + biome.swamp)
	{
		int *allowed = malloc(sizeof(int)*1);
		allowed[0] = 1;
		generateLandMass(7, allowed, 1);
		free(allowed);
	}
	else
	{
		GOC_INFO("This is the end");
		// I think it's the end
		return GOC_ERR_OK;
	}
	nBiomeTurn++;
	GOC_MSG_PAINT( msgPaint );
	goc_systemSendMsg(context->mapa, msgPaint);
	goc_gotoxy(0, 0);
	goc_textallcolor(GOC_WHITE);
	printf("%03d", nBiomeTurn);
	goc_gotoxy(0, 0);
	fflush(stdout);
	return GOC_ERR_OK;
}
Example #7
0
int main(int argc, char **argv)
{
	GOC_IStream *wordStream = NULL;
	GOC_IStream *fileStream = NULL;
	GOC_Properties *props = NULL;
	GOC_Iterator *propIt = NULL;
	char *line;
	char *pos = NULL;

	if ( argc < 3 )
	{
		GOC_BINFO("Usage: %s wordconvert.properties filetochange", argv[0]);
		GOC_INFO("\tApplication changes word in file to another");
		return 0;
	}
	wordStream = goc_fileIStreamOpen(argv[1]);
	if ( wordStream == NULL )
	{
		GOC_BERROR("Cannot open file %s", argv[1]);
		return -1;
	}
	fileStream = goc_fileIStreamOpen(argv[2]);
	if ( fileStream == NULL )
	{
		GOC_BERROR("Cannot open file %s", argv[2]);
		return -1;
	}
	props = goc_propertiesAlloc();
	props = goc_propertiesLoad(props, wordStream);
	while ( line = goc_isReadLine(fileStream) )
	{
		char *bline = NULL;
		char *last = line;
		pos = NULL;
		while ( pos = findNextWordBegin(line, pos) )
		{
			char *word = getWord( pos );
			char *v = goc_propertiesGetValue( props, word );

			*pos = 0;
			bline = goc_stringAdd(bline, last);

			if ( v != NULL )
			{
				bline = goc_stringAdd(bline, v);
			}
			else
			{
				bline = goc_stringAdd(bline, word);
			}
			pos += strlen(word);
			word = goc_stringFree(word);
			last = pos;
		}
		bline = goc_stringAdd(bline, last);
		puts(bline);
		line = goc_stringFree(line);
		bline = goc_stringFree(bline);
	}
	free(propIt);
	goc_isClose(wordStream);
	goc_isClose(fileStream);

	return 0;
}