Exemplo n.º 1
0
static char getChar(GOC_Properties* p, char* name, char defValue)
{
	char* value = NULL;
	if ( !p )
		return defValue;
	value = goc_propertiesGetValue(p, name);
	if ( !value )
		return defValue;
	if ( strlen(value) == 0 )
		return defValue;
	return value[0];
}
Exemplo n.º 2
0
static int getColor(GOC_Properties* p, char* name, int defValue)
{
	char* value = NULL;
	if ( !p )
		return defValue;
	value = goc_propertiesGetValue(p, name);
	if ( !value )
		return defValue;
	if ( strlen(value) == 0 )
		return defValue;
	return goc_stringToColor(value);
}
Exemplo n.º 3
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;
}