Ejemplo n.º 1
0
//params is string representing path, either absolute or relative in respect to cur_path and root_path
//remove relatives from params and returns path concatenated of root cur_path params, buffer is allocated.
//to cur_path store new current path relative to root, buffer is allocated
char *
get_full_path(char *root, char  **cur_path, char *params)
{
	char *c_path;
	if(is_absolute(params))
	{
		c_path = malloc(strlen(params) + 1);
		strcpy(c_path, params);
	}
	else
	{
		c_path = malloc(strlen(*cur_path) + 1 + strlen(params) + 1);
		strcpy(c_path, *cur_path);
		strcat(c_path, "/");
		strcat(c_path, params);
	}
	
	char *normalized_path = remove_relatives(remove_slashes(c_path));
	free(c_path);

	if(normalized_path)
	{
		*cur_path = normalized_path;
	}
	else
	{
		char *empty = malloc(1);
		*empty = '\0';
		*cur_path = empty; 
	}

	char *res = malloc(strlen(root) + strlen(*cur_path) + 1);
	strcpy(res, root);
	strcat(res, *cur_path);
	return res;
}
Ejemplo n.º 2
0
viewlist* viewlist_construct_view_start (GType object_type, world_wide* w, const gchar* full_path) {
	viewlist* self = NULL;
	world_wide* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_ = NULL;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (full_path != NULL, NULL);
	self = (viewlist*) playlist_construct (object_type);
	_tmp0_ = w;
	((screen*) self)->world = _tmp0_;
	_tmp1_ = full_path;
	_tmp2_ = remove_slashes (_tmp1_);
	_g_free0 (((playlist*) self)->m3u_path);
	((playlist*) self)->m3u_path = _tmp2_;
	{
		gchar* line = NULL;
		const gchar* _tmp3_;
		GFile* _tmp4_ = NULL;
		GFile* file;
		GFile* _tmp5_;
		GFileInputStream* _tmp6_ = NULL;
		GFileInputStream* _tmp7_;
		GFileInputStream* _tmp8_;
		GDataInputStream* _tmp9_;
		GDataInputStream* _tmp10_;
		GDataInputStream* in_stream;
		_tmp3_ = ((playlist*) self)->m3u_path;
		_tmp4_ = g_file_new_for_path (_tmp3_);
		file = _tmp4_;
		_tmp5_ = file;
		_tmp6_ = g_file_read (_tmp5_, NULL, &_inner_error_);
		_tmp7_ = _tmp6_;
		if (_inner_error_ != NULL) {
			_g_object_unref0 (file);
			_g_free0 (line);
			goto __catch6_g_error;
		}
		_tmp8_ = _tmp7_;
		_tmp9_ = g_data_input_stream_new ((GInputStream*) _tmp8_);
		_tmp10_ = _tmp9_;
		_g_object_unref0 (_tmp8_);
		in_stream = _tmp10_;
		while (TRUE) {
			GDataInputStream* _tmp11_;
			gchar* _tmp12_ = NULL;
			gchar* _tmp13_;
			const gchar* _tmp14_;
			const gchar* _tmp15_;
			_tmp11_ = in_stream;
			_tmp12_ = g_data_input_stream_read_line (_tmp11_, NULL, NULL, &_inner_error_);
			_tmp13_ = _tmp12_;
			if (_inner_error_ != NULL) {
				_g_object_unref0 (in_stream);
				_g_object_unref0 (file);
				_g_free0 (line);
				goto __catch6_g_error;
			}
			_g_free0 (line);
			line = _tmp13_;
			_tmp14_ = line;
			if (!(_tmp14_ != NULL)) {
				break;
			}
			_tmp15_ = line;
			if (g_strcmp0 (_tmp15_, "") != 0) {
				const gchar* _tmp16_;
				gchar* _tmp17_;
				_tmp16_ = line;
				_tmp17_ = g_strdup (_tmp16_);
				((playlist*) self)->entry = g_list_append (((playlist*) self)->entry, _tmp17_);
			}
		}
		_g_object_unref0 (in_stream);
		_g_object_unref0 (file);
		_g_free0 (line);
	}
	goto __finally6;
	__catch6_g_error:
	{
		GError* err = NULL;
		world_wide* _tmp18_;
		dbg* _tmp19_;
		const gchar* _tmp20_;
		gchar* _tmp21_;
		gchar* _tmp22_;
		gchar* _tmp23_;
		gchar* _tmp24_;
		GError* _tmp25_;
		const gchar* _tmp26_;
		gchar* _tmp27_;
		gchar* _tmp28_;
		err = _inner_error_;
		_inner_error_ = NULL;
		_tmp18_ = ((screen*) self)->world;
		_tmp19_ = _tmp18_->debug;
		_tmp20_ = ((playlist*) self)->m3u_path;
		_tmp21_ = g_strconcat ("Read text file error: ", _tmp20_, NULL);
		_tmp22_ = _tmp21_;
		_tmp23_ = g_strconcat (_tmp22_, ": ", NULL);
		_tmp24_ = _tmp23_;
		_tmp25_ = err;
		_tmp26_ = _tmp25_->message;
		_tmp27_ = g_strconcat (_tmp24_, _tmp26_, NULL);
		_tmp28_ = _tmp27_;
		dbg_add (_tmp19_, _tmp28_);
		_g_free0 (_tmp28_);
		_g_free0 (_tmp24_);
		_g_free0 (_tmp22_);
		_g_error_free0 (err);
	}
	__finally6:
	if (_inner_error_ != NULL) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return NULL;
	}
	return self;
}