Example #1
0
void string_unit_test()
{
    {
        string s[ 1 ];
        int i;
        int const limit = sizeof( s->opt ) * 2 + 2;
        string_new( s );
        assert( s->value == s->opt );
        for ( i = 0; i < limit; ++i )
        {
            string_push_back( s, (char)( i + 1 ) );
            assert( s->size == i + 1 );
        }
        assert( s->size == limit );
        assert( s->value != s->opt );
        for ( i = 0; i < limit; ++i )
            assert( s->value[ i ] == (char)( i + 1 ) );
        string_free( s );
    }

    {
        char * const original = "  \n\t\v  Foo \r\n\v \tBar\n\n\r\r\t\n\v\t \t";
        string copy[ 1 ];
        string_copy( copy, original );
        assert( !strcmp( copy->value, original ) );
        assert( copy->size == strlen( original ) );
        string_free( copy );
    }

    {
        char * const foo = "Foo    ";
        string foo_copy[ 1 ];
        string_copy( foo_copy, foo );
        string_rtrim( foo_copy );
        assert( !strcmp( foo_copy->value, "Foo" ) );

        string_rtrim( foo_copy );
        assert( !strcmp( foo_copy->value, "Foo" ) );
    }
    {
        char * const bar = "Bar\0\0\0";
        string bar_copy[ 1 ];
        string_copy( bar_copy, bar );
        string_rtrim( bar_copy );
        assert( !strcmp( bar_copy->value, "Bar" ) );

        string_rtrim( bar_copy );
        assert( !strcmp( bar_copy->value, "Bar" ) );
    }
}
Example #2
0
static int _settings_browse(Settings * settings)
{
	int ret = 0;
	Config * config;
	GtkTreeModel * model;
	char const * path;
	char * p;
	size_t i;
	size_t j;
	int datadir = 1;

	if((config = config_new()) == NULL)
		return -_settings_error(error_get(NULL), 1);
	model = _settings_get_model(settings);
	gtk_list_store_clear(GTK_LIST_STORE(model));
	/* read through every XDG application folder */
	if((path = getenv("XDG_DATA_DIRS")) == NULL || strlen(path) == 0)
	{
		path = "/usr/local/share:/usr/share";
		datadir = 0;
	}
	if((p = strdup(path)) == NULL)
		_settings_error(error_get(NULL), 1);
	else
		for(i = 0, j = 0;; i++)
			if(p[i] == '\0')
			{
				string_rtrim(&p[j], "/");
				_settings_browse_folder(settings, config,
						&p[j]);
				datadir |= (strcmp(&p[j], DATADIR) == 0);
				break;
			}
			else if(p[i] == ':')
			{
				p[i] = '\0';
				string_rtrim(&p[j], "/");
				_settings_browse_folder(settings, config,
						&p[j]);
				datadir |= (strcmp(&p[j], DATADIR) == 0);
				j = i + 1;
			}
	free(p);
	if(datadir == 0)
		ret = _settings_browse_folder(settings, config, DATADIR);
	ret |= _settings_browse_home(settings, config);
	config_delete(config);
	return ret;
}
Example #3
0
 string string_trim( const string &str )
 {
     string s = str;
     return string_ltrim(string_rtrim(s));
 }
Example #4
0
static void _read_parse(PlayerBackend * player, char const * buf)
{
	unsigned int u1;
	unsigned int u2;
	gdouble db;
	char str[256];
	time_t t;
	struct tm tm;

	if(sscanf(buf, "ANS_META_ALBUM='%255[^'\n]\n", str) == 1)
	{
		str[sizeof(str) - 1] = '\0';
		string_rtrim(str, NULL);
		player_set_metadata(player->player, PM_ALBUM, str);
	}
	else if(sscanf(buf, "ANS_META_ARTIST='%255[^'\n]\n", str) == 1)
	{
		str[sizeof(str) - 1] = '\0';
		string_rtrim(str, NULL);
		player_set_metadata(player->player, PM_ARTIST, str);
	}
	else if(sscanf(buf, "ANS_META_COMMENT='%255[^'\n]\n", str) == 1)
	{
		str[sizeof(str) - 1] = '\0';
		string_rtrim(str, NULL);
		player_set_metadata(player->player, PM_COMMENT, str);
	}
	else if(sscanf(buf, "ANS_META_GENRE='%255[^'\n]\n", str) == 1)
	{
		str[sizeof(str) - 1] = '\0';
		string_rtrim(str, NULL);
		player_set_metadata(player->player, PM_GENRE, str);
	}
	else if(sscanf(buf, "ANS_META_TITLE='%255[^'\n]\n", str) == 1)
	{
		str[sizeof(str) - 1] = '\0';
		string_rtrim(str, NULL);
		player_set_metadata(player->player, PM_TITLE, str);
	}
	else if(sscanf(buf, "ANS_META_TRACK='%255[^'\n]\n", str) == 1)
	{
		str[sizeof(str) - 1] = '\0';
		string_rtrim(str, NULL);
		player_set_metadata(player->player, PM_TRACK, str);
	}
	else if(sscanf(buf, "ANS_META_YEAR='%255[^'\n]\n", str) == 1)
	{
		str[sizeof(str) - 1] = '\0';
		string_rtrim(str, NULL);
		player_set_metadata(player->player, PM_YEAR, str);
	}
	else if(sscanf(buf, "ANS_PERCENT_POSITION=%u\n", &u1) == 1)
	{
		player_set_progress(player->player, u1);
		if(u1 == 100)
			player_next(player->player);
	}
	else if(sscanf(buf, "ANS_TIME_POSITION=%lf\n", &db) == 1)
	{
		t = db;
		gmtime_r(&t, &tm);
		strftime(str, sizeof(str), "%H:%M:%S", &tm);
		player_set_metadata(player->player, PM_LENGTH, str);
	}
	else if(sscanf(buf, "ANS_VIDEO_RESOLUTION='%u x %u'\n", &u1, &u2) == 2)
		_playerbackend_set_size(player, u1, u2);
	else if(sscanf(buf, "ID_AUDIO_BITRATE=%u\n", &u1) == 1)
		player->audio_bitrate = u1;
	else if(sscanf(buf, "ID_AUDIO_CODEC=%255[^\n]", str) == 1)
	{
		str[sizeof(str) - 1] = '\0';
		string_rtrim(str, NULL);
		if(player->audio_codec != NULL)
			free(player->audio_codec);
		player->audio_codec = strdup(str);
	}
	else if(sscanf(buf, "ID_AUDIO_NCH=%u\n", &u1) == 1)
		player->audio_channels = u1;
	else if(sscanf(buf, "ID_AUDIO_RATE=%u\n", &u1) == 1)
		player->audio_rate = u1;
	else if(sscanf(buf, "ID_CLIP_INFO_NAME%u=%255s", &u1, str) == 2)
	{
		str[sizeof(str) - 1] = '\0';
		string_rtrim(str, NULL);
		if(strcmp(str, "Album") == 0)
			player->album = u1;
		else if(strcmp(str, "Artist") == 0)
			player->artist = u1;
		else if(strcmp(str, "Title") == 0)
			player->title = u1;
	}
	else if(sscanf(buf, "ID_CLIP_INFO_VALUE%u=%255[^\n]", &u1, str) == 2)
	{
		str[sizeof(str) - 1] = '\0';
		string_rtrim(str, NULL);
		if(player->album >= 0 && (unsigned)player->album == u1)
			player_set_metadata(player->player, PM_ALBUM, str);
		else if(player->artist >= 0 && (unsigned)player->artist == u1)
			player_set_metadata(player->player, PM_ARTIST, str);
		else if(player->title >= 0 && (unsigned)player->title == u1)
			player_set_metadata(player->player, PM_TITLE, str);
		/* FIXME also update the duration */
	}
	else if(sscanf(buf, "ID_LENGTH=%lf\n", &db) == 1)
		player->length = db;
	else if(sscanf(buf, "ID_SEEKABLE=%u\n", &u1) == 1)
		player_set_seekable(player->player, u1 ? TRUE : FALSE);
	else if(sscanf(buf, "ID_VIDEO_ASPECT=%lf\n", &db) == 1)
		player->video_aspect = db;
	else if(sscanf(buf, "ID_VIDEO_BITRATE=%u\n", &u1) == 1)
		player->video_bitrate = u1;
	else if(sscanf(buf, "ID_VIDEO_CODEC=%255[^\n]", str) == 1)
	{
		str[sizeof(str) - 1] = '\0';
		string_rtrim(str, NULL);
		if(player->video_codec != NULL)
			free(player->video_codec);
		player->video_codec = strdup(str);
	}
	else if(sscanf(buf, "ID_VIDEO_FPS=%lf\n", &db) == 1)
		player->video_fps = db;
	else if(sscanf(buf, "ID_VIDEO_HEIGHT=%u\n", &u1) == 1)
		_playerbackend_set_size(player, -1, u1);
	else if(sscanf(buf, "ID_VIDEO_RATE=%u\n", &u1) == 1)
		player->video_rate = u1;
	else if(sscanf(buf, "ID_VIDEO_WIDTH=%u\n", &u1) == 1)
		_playerbackend_set_size(player, u1, -1);
#ifdef DEBUG
	else
		fprintf(stderr, "DEBUG: unknown output \"%s\"\n", buf);
#endif
}
Example #5
0
void string_trim(char* string, char character_to_strip)
{
  string_ltrim(string, character_to_strip);
  string_rtrim(string, character_to_strip);
}