Beispiel #1
0
static bool get_audio_params(struct audio_params *audio, int *argc,
		char ***argv)
{
	if (!get_opt_str(argc, argv, &audio->name, "audio track name"))
		return false;
	if (!get_opt_int(argc, argv, &audio->abitrate, "audio bitrate"))
		return false;
	if (!get_opt_int(argc, argv, &audio->sample_rate, "audio sample rate"))
		return false;
	if (!get_opt_int(argc, argv, &audio->channels, "audio channels"))
		return false;
	return true;
}
Beispiel #2
0
/* Layout for generic boxes */
void
dlg_format_listbox(struct dialog_data *dlg_data,
		   struct widget_data *widget_data,
	           int x, int *y, int w, int max_height, int *rw,
	           enum format_align align, int format_only)
{
	int min, optimal_h, height;

	/* Height bussiness follows: */

	/* This is only weird heuristic, it could scale well I hope. */
	optimal_h = max_height * 7 / 10 - VERTICAL_LISTBOX_MARGIN;
	min = get_opt_int((const unsigned char *)"ui.dialogs.listbox_min_height", NULL);

	if (max_height - VERTICAL_LISTBOX_MARGIN < min) {
		/* Big trouble: can't satisfy even the minimum :-(. */
		height = max_height - VERTICAL_LISTBOX_MARGIN;
	} else if (optimal_h < min) {
		height = min;
	} else {
		height = optimal_h;
	}

	set_box(&widget_data->box, x, *y, w, height);
	(*y) += height;
	if (rw) *rw = w;
}
Beispiel #3
0
int ex_cmd_height()
{
  int height = 1;
  if (ex.ex_state == EX_CMD_STATE)
    height += get_opt_int("menu_rows") + 1;
  return height;
}
Beispiel #4
0
/* Timer callback for @periodic_save_timer.  As explained in @install_timer,
 * this function must erase the expired timer ID from all variables.  */
static void
periodic_save_handler(void *xxx)
{
	static int periodic_save_event_id = EVENT_NONE;
	milliseconds_T interval;

	if (get_cmd_opt_bool((const unsigned char *)"anonymous")) return;

	/* Don't trigger anything at startup */
	if (periodic_save_event_id == EVENT_NONE)
		set_event_id(periodic_save_event_id, (unsigned char *)"periodic-saving");
	else
		trigger_event(periodic_save_event_id);

	interval = sec_to_ms(get_opt_int((const unsigned char *)"infofiles.save_interval", NULL));
	if (!interval) {
		/* We should get here only if @periodic_save_handler
		 * is being called from @periodic_save_change_hook or
		 * @init_timer, rather than from the timer system.  */
		assert(periodic_save_timer == TIMER_ID_UNDEF);
		return;
	}

	install_timer(&periodic_save_timer, interval, periodic_save_handler, NULL);
	/* The expired timer ID has now been erased.  */
}
Beispiel #5
0
Datei: ed.c Projekt: jollywho/nav
static void ed_direct_prompt(void **args)
{
    ed_data *data = args[0];

    if (get_opt_int("askrename")) {
        bool ans = 0;

        if (data->src.argc > 1)
            ans = confirm("Rename %d items to %s ?", data->src.argc, data->dst);
        else
            ans = confirm("Rename %s to %s ?", data->src.argv[0], data->dst);

        if (!ans)
            goto cleanup;
    }

    char from[PATH_MAX];
    char to[PATH_MAX];
    char *curdir = fs_pwd();

    //NOTE: multiargs rename all to same dest
    for (int i = 0; i < data->src.argc; i++) {
        log_err("ED", "[%s] [%s]", data->src.argv[i], data->dst);
        conspath_buf(from, curdir, data->src.argv[i]);
        conspath_buf(to,   curdir, data->dst);
        file_move_str(from, to, NULL);
    }
cleanup:
    del_param_list(data->src.argv,  data->src.argc);
    free(data->dst);
    free(data);
}
Beispiel #6
0
static bool init_params(int *argc, char ***argv, struct main_params *params,
		struct audio_params **p_audio)
{
	struct audio_params *audio = NULL;

	if (!get_opt_str(argc, argv, &params->file, "file name"))
		return false;
	if (!get_opt_int(argc, argv, &params->has_video, "video track count"))
		return false;
	if (!get_opt_int(argc, argv, &params->tracks, "audio track count"))
		return false;

	if (params->has_video > 1 || params->has_video < 0) {
		puts("Invalid number of video tracks\n");
		return false;
	}
	if (params->tracks < 0) {
		puts("Invalid number of audio tracks\n");
		return false;
	}
	if (params->has_video == 0 && params->tracks == 0) {
		puts("Must have at least 1 audio track or 1 video track\n");
		return false;
	}

	if (params->has_video) {
		if (!get_opt_str(argc, argv, &params->vcodec, "video codec"))
			return false;
		if (!get_opt_int(argc, argv, &params->vbitrate,"video bitrate"))
			return false;
		if (!get_opt_int(argc, argv, &params->width, "video width"))
			return false;
		if (!get_opt_int(argc, argv, &params->height, "video height"))
			return false;
		if (!get_opt_int(argc, argv, &params->fps_num, "video fps num"))
			return false;
		if (!get_opt_int(argc, argv, &params->fps_den, "video fps den"))
			return false;
	}

	if (params->tracks) {
		if (!get_opt_str(argc, argv, &params->acodec, "audio codec"))
			return false;

		audio = calloc(1, sizeof(*audio) * params->tracks);

		for (int i = 0; i < params->tracks; i++) {
			if (!get_audio_params(&audio[i], argc, argv)) {
				free(audio);
				return false;
			}
		}
	}

	*p_audio = audio;

	get_opt_str(argc, argv, &params->muxer_settings, "muxer settings");

	return true;
}
Beispiel #7
0
/* The timeout mechanism is used for both inactive incoming peer connections
 * and peer connections attached to a BitTorrent (master) connection. */
void
set_bittorrent_peer_connection_timeout(struct bittorrent_peer_connection *peer)
{
	milliseconds_T timeout = sec_to_ms(get_opt_int("protocol.bittorrent.peerwire.timeout", NULL));

	kill_timer(&peer->timer);
	install_timer(&peer->timer, timeout,
		      (void (*)(void *)) bittorrent_peer_connection_timeout,
		      peer);
}
Beispiel #8
0
static JSBool
safeguard(JSContext *ctx, JSScript *script)
{
	struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx);
	struct session *ses = interpreter->vs->doc_view->session;
	int max_exec_time = get_opt_int("ecmascript.max_exec_time", ses);

	if (time(NULL) - interpreter->exec_start > max_exec_time) {
		struct terminal *term = ses->tab->term;

		/* A killer script! Alert! */
		ecmascript_timeout_dialog(term, max_exec_time);
		return JS_FALSE;
	}
	return JS_TRUE;
}
Beispiel #9
0
void
init_document_options(struct session *ses, struct document_options *doo)
{
	/* Ensure that any padding bytes are cleared. */
	memset(doo, 0, sizeof(*doo));

	doo->assume_cp = get_opt_codepage("document.codepage.assume", ses);
	doo->hard_assume = get_opt_bool("document.codepage.force_assumed", ses);

	doo->use_document_colors = get_opt_int("document.colors.use_document_colors", ses);
	doo->margin = get_opt_int("document.browse.margin_width", ses);
	doo->num_links_key = get_opt_int("document.browse.links.number_keys_select_link", ses);
	doo->meta_link_display = get_opt_int("document.html.link_display", ses);
	doo->default_form_input_size = get_opt_int("document.browse.forms.input_size", ses);

	/* Color options. */
	doo->default_style.color.foreground = get_opt_color("document.colors.text", ses);
	doo->default_style.color.background = get_opt_color("document.colors.background", ses);
	doo->default_color.link = get_opt_color("document.colors.link", ses);
	doo->default_color.vlink = get_opt_color("document.colors.vlink", ses);
#ifdef CONFIG_BOOKMARKS
	doo->default_color.bookmark_link = get_opt_color("document.colors.bookmark", ses);
#endif
	doo->default_color.image_link = get_opt_color("document.colors.image", ses);

	doo->active_link.color.foreground = get_opt_color("document.browse.links.active_link.colors.text", ses);
	doo->active_link.color.background = get_opt_color("document.browse.links.active_link.colors.background", ses);

	if (get_opt_bool("document.colors.increase_contrast", ses))
		doo->color_flags |= COLOR_INCREASE_CONTRAST;

	if (get_opt_bool("document.colors.ensure_contrast", ses))
		doo->color_flags |= COLOR_ENSURE_CONTRAST;

	/* Boolean options. */
#ifdef CONFIG_CSS
	doo->css_enable = get_opt_bool("document.css.enable", ses);
	doo->css_ignore_display_none = get_opt_bool("document.css.ignore_display_none", ses);
	doo->css_import = get_opt_bool("document.css.import", ses);
#endif

	doo->plain_display_links = get_opt_bool("document.plain.display_links", ses);
	doo->plain_compress_empty_lines = get_opt_bool("document.plain.compress_empty_lines", ses);
	doo->underline_links = get_opt_bool("document.html.underline_links", ses);
	doo->wrap_nbsp = get_opt_bool("document.html.wrap_nbsp", ses);
	doo->use_tabindex = get_opt_bool("document.browse.links.use_tabindex", ses);
	doo->links_numbering = get_opt_bool("document.browse.links.numbering", ses);

	doo->active_link.enable_color = get_opt_bool("document.browse.links.active_link.enable_color", ses);
	doo->active_link.invert = get_opt_bool("document.browse.links.active_link.invert", ses);
	doo->active_link.underline = get_opt_bool("document.browse.links.active_link.underline", ses);
	doo->active_link.bold = get_opt_bool("document.browse.links.active_link.bold", ses);

	doo->table_order = get_opt_bool("document.browse.table_move_order", ses);
	doo->tables = get_opt_bool("document.html.display_tables", ses);
	doo->frames = get_opt_bool("document.html.display_frames", ses);
	doo->images = get_opt_bool("document.browse.images.show_as_links", ses);
	doo->display_subs = get_opt_bool("document.html.display_subs", ses);
	doo->display_sups = get_opt_bool("document.html.display_sups", ses);

	doo->framename = "";

	doo->image_link.prefix = "";
	doo->image_link.suffix = "";
	doo->image_link.filename_maxlen = get_opt_int("document.browse.images.filename_maxlen", ses);
	doo->image_link.label_maxlen = get_opt_int("document.browse.images.label_maxlen", ses);
	doo->image_link.display_style = get_opt_int("document.browse.images.display_style", ses);
	doo->image_link.tagging = get_opt_int("document.browse.images.image_link_tagging", ses);
	doo->image_link.show_any_as_links = get_opt_bool("document.browse.images.show_any_as_links", ses);
}
Beispiel #10
0
/* Based on network/socket.c:get_pasv_socket() but modified to try and bind to a
 * port range instead of any port. */
struct connection_state
init_bittorrent_listening_socket(struct connection *conn)
{
	struct bittorrent_connection *bittorrent = conn->info;
	struct sockaddr_in addr, addr2;
	uint16_t port, max_port;
	int len;

	/* XXX: Always add the connection to the list even if we fail so we can
	 * safely assume it is in done_bittorrent_listening_socket(). */
	add_to_list(bittorrent_connections, bittorrent);

	/* Has the socket already been initialized? */
	if (!list_is_singleton(bittorrent_connections))
		return connection_state(S_OK);

	/* We could have bailed out from an earlier attempt. */
	if (bittorrent_socket != -1)
		close(bittorrent_socket);

	bittorrent_socket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
	if (bittorrent_socket < 0)
		return connection_state_for_errno(errno);

	/* Set it non-blocking */

	if (set_nonblocking_fd(bittorrent_socket) < 0)
		return connection_state_for_errno(errno);

	/* Bind it to some port */

	port	 = get_opt_int("protocol.bittorrent.ports.min", NULL);
	max_port = get_opt_int("protocol.bittorrent.ports.max", NULL);

	memset(&addr, 0, sizeof(addr));
	addr.sin_port = htons(port);

	/* Repeatedly try the configured port range. */
	while (bind(bittorrent_socket, (struct sockaddr *) &addr, sizeof(addr))) {
		if (errno != EADDRINUSE)
			return connection_state_for_errno(errno);

		/* If all ports was in use fail with EADDRINUSE. */
		if (++port > max_port)
			return connection_state_for_errno(errno);

		memset(&addr, 0, sizeof(addr));
		addr.sin_port = htons(port);
	}

	/* Get the endpoint info about the new socket and save it */

	memset(&addr2, 0, sizeof(addr2));
	len = sizeof(addr2);
	if (getsockname(bittorrent_socket, (struct sockaddr *) &addr2, &len))
		return connection_state_for_errno(errno);

	bittorrent->port = ntohs(addr2.sin_port);

	/* Go listen */

	if (listen(bittorrent_socket, LISTEN_BACKLOG))
		return connection_state_for_errno(errno);

	set_ip_tos_throughput(bittorrent_socket);
	set_handlers(bittorrent_socket, accept_bittorrent_peer_connection,
		     NULL, NULL, NULL);

	return connection_state(S_OK);
}