示例#1
0
static GsfInput *
gsf_infile_stdio_child_by_index (GsfInfile *infile, int target, GError **err)
{
	GsfInfileStdio *ifs = GSF_INFILE_STDIO (infile);
	const char *name = gsf_infile_stdio_name_by_index (infile, target);
	return name ? open_child (ifs, name, err) : NULL;
}
示例#2
0
static GsfInput *
gsf_infile_stdio_child_by_name (GsfInfile *infile, char const *name, GError **err)
{
	GsfInfileStdio *ifs = GSF_INFILE_STDIO (infile);
	unsigned ui;

	for (ui = 0; ui < ifs->children->len; ui++) {
		const char *child = g_ptr_array_index (ifs->children, ui);
		if (!strcmp (child, name))
			return open_child (ifs, name, err);
	}

	return NULL;
}
示例#3
0
int
fileget(char *url)
{
	char *argv[6];

	argv[0] = "ftp";
	argv[1] = "-V";
	argv[2] = "-o";
	argv[3] = "-";
	argv[4] = url;
	argv[5] = NULL;

	if (debug)
		fprintf(stderr, "Getting %s\n", url);

	return (open_child(PATH_FTP, argv));
}
示例#4
0
int
open_file(char *method, char *file)
{
	char *url;
	char **ap, **argv;
	int len, i, oerrno;

	if ((method == NULL) || (strcmp(method, "file") == 0))
		return (open(file, O_RDONLY));
	if ((strcmp(method, "http") == 0) ||
	    strcmp(method, "ftp") == 0) {
		asprintf(&url, "%s://%s", method, file);
		if (url == NULL)
			return (-1);
		i = fileget(url);
		free(url);
		return (i);
	} else if (strcmp(method, "exec") == 0) {
		len = strlen(file);
		argv = calloc(len, sizeof(char *));
		if (argv == NULL)
			errx(1, "malloc failed");
		for (ap = argv; ap < &argv[len - 1] &&
		    (*ap = strsep(&file, " \t")) != NULL;) {
			if (**ap != '\0')
				ap++;
		}
		*ap = NULL;
		i = open_child(argv[0], argv);
		oerrno = errno;
		free(argv);
		errno = oerrno;
		return (i);
	}
	errx(1, "Unknown method %s", method);
	return (-1); /* NOTREACHED */
}
示例#5
0
//	Display the main window.  All the players achievemnt icons and the controls.
//	Handle the mouse over events for the icons and the controls.
//
int Achievements_Window::display_handler(window_info *win)
{
	Achievements_System *as = Achievements_System::get_instance();

	int icon_per = (256 / as->get_size());
	int icon_per_texture = icon_per * icon_per;
	bool another_page = false;

	glEnable(GL_TEXTURE_2D);
	glColor3f(1.0f,1.0f,1.0f);

	for (size_t i=first; i<their_achievements.size(); ++i)
	{
		size_t shown_num = i-first;

		if ((static_cast<int>(shown_num)/as->get_per_row()) >= physical_rows)
		{
			another_page = true;
			break;
		}

		int texture = -1;
		const Achievement * achievement = as->achievement(their_achievements[i]);
		if (achievement)
			texture = as->texture(achievement->get_id() / icon_per_texture);

		if (texture >= 0)
		{
			int cur_item = achievement->get_id() % icon_per_texture;

			float u_start = 1.0f/static_cast<float>(icon_per) * (cur_item % icon_per);
			float u_end = u_start + static_cast<float>(as->get_size())/256;
			float v_start = 1.0f/static_cast<float>(icon_per) * (cur_item / icon_per);
			float v_end = v_start + static_cast<float>(as->get_size()) / 256;
			int start_x = as->get_border() + as->get_display() * (shown_num % as->get_per_row());
			int start_y = as->get_border() + as->get_display() * (shown_num / as->get_per_row());

			bind_texture(texture);
			glEnable(GL_ALPHA_TEST);
			glAlphaFunc(GL_GREATER, 0.05f);
			glBegin(GL_QUADS);
			draw_2d_thing( u_start, v_start, u_end, v_end,
				start_x, start_y, start_x+as->get_display(), start_y+as->get_display() );
			glEnd();
			glDisable(GL_ALPHA_TEST);
		}
		else
		{
			int pos_x = as->get_border() + (shown_num % as->get_per_row()) * as->get_display()
				+ (as->get_display() - win->default_font_len_x) / 2;
			int pos_y = as->get_border() + (shown_num / as->get_per_row()) * as->get_display()
				+ (as->get_display() - win->default_font_len_y) / 2;
			draw_string_zoomed(pos_x+gx_adjust, pos_y+gy_adjust, (const unsigned char *)"?", 1, win->current_scale);
		}
	}

	size_t now_over = Achievement::npos;

	if ((cm_window_shown() == CM_INIT_VALUE) && (win_mouse_x > as->get_border()) && (win_mouse_y > as->get_border()))
	{
		int row = (win_mouse_y - as->get_border()) / as->get_display();
		int col = (win_mouse_x - as->get_border()) / as->get_display();
		if ((row >= 0) && (row < physical_rows) && (col >= 0) && (col < as->get_per_row()))
		{
			size_t current_index = first + row * as->get_per_row() + col;
			if (current_index < their_achievements.size())
				now_over = their_achievements[current_index];
		}
	}

	if (now_over != last_over)
	{
		if (last_over != Achievement::npos)
			hide_window(child_win_id);
		last_over = now_over;
		if (last_over != Achievement::npos)
			open_child();
	}

	int prev_start = gx_adjust + as->get_border();
	int prev_end = prev_start + as->get_font_x() * as->get_prev().size();
	int next_start = prev_end + 2 * as->get_border();
	int next_end = next_start + as->get_font_x() * as->get_next().size();
	int close_start = gx_adjust + win->len_x - (as->get_border() + as->get_font_x() * as->get_close().size());
	int close_end = gx_adjust + win->len_x - as->get_border();

	bool over_controls = (win_mouse_y > (win->len_y - (as->get_font_y() + as->get_border())));
	bool over_close = (over_controls && (win_mouse_x > close_start) && (win_mouse_x < close_end));
	bool over_prev = (over_controls && (win_mouse_x > prev_start) && (win_mouse_x < prev_end));
	bool over_next = (over_controls && (win_mouse_x > next_start) && (win_mouse_x < next_end));

	float active_colour[3] = { 1.0f, 1.0f, 1.0f };
	float inactive_colour[3] =  { 0.5f, 0.5f, 0.5f };
	float mouse_over_colour[3] = { 1.0f, 0.5f, 0.0f };

	glColor3fv((first) ?((over_prev) ?mouse_over_colour :active_colour) :inactive_colour);
	draw_string_small_zoomed(prev_start, gy_adjust + win->len_y - (as->get_font_y() + as->get_border()),
		reinterpret_cast<const unsigned char *>(as->get_prev().c_str()), 1, as->get_current_scale());

	glColor3fv((another_page) ?((over_next) ?mouse_over_colour :active_colour) :inactive_colour);
	draw_string_small_zoomed(next_start, gy_adjust + win->len_y - (as->get_font_y() + as->get_border()),
		reinterpret_cast<const unsigned char *>(as->get_next().c_str()), 1, as->get_current_scale());

	glColor3fv((over_close) ?mouse_over_colour :active_colour);
	draw_string_small_zoomed(close_start, gy_adjust + win->len_y - (as->get_font_y() + as->get_border()),
		reinterpret_cast<const unsigned char *>(as->get_close().c_str()), 1, as->get_current_scale());

	if (over_close && ctrl_clicked)
		as->hide_all();
	if (over_close && clicked)
		hide_window(main_win_id);
	else if (over_prev && first && clicked)
		first -= physical_rows * as->get_per_row();
	else if (over_next && another_page && clicked)
		first += physical_rows * as->get_per_row();

	if (clicked && (over_prev || over_next))
		do_click_sound();
	if ((ctrl_clicked || clicked) && over_close)
		do_window_close_sound();

	if (over_controls && show_help_text)
	{
		if (over_close)
			show_help(as->get_close_help(), 0, win->len_y + as->get_y_win_offset(), win->current_scale);
		else if (over_prev)
			show_help((first)?as->get_prev_help() :as->get_no_prev_help(), 0, win->len_y + as->get_y_win_offset(), win->current_scale);
		else if (over_next)
			show_help((another_page)?as->get_next_help() :as->get_no_next_help(), 0, win->len_y + as->get_y_win_offset(), win->current_scale);
	}

	win_mouse_x = win_mouse_y = -1;
	ctrl_clicked = clicked = false;

	return 1;
}
示例#6
0
void config_writer::write_child(const std::string &key, const config &cfg)
{
	open_child(key);
	::write(out_, cfg, level_);
	close_child(key);
}