Example #1
0
void dump_strings ( char **strings, int num_strings, FILE *fp )
{
  dump_int ( num_strings, fp );
  dump_string_array ( strings, num_strings, fp );
  return;
}
Example #2
0
BOOL save_config(BOOL save_channels, char **err_msg)
{
	BOOL failed = FALSE;
	int loop = 0;
	FILE *fh = NULL;

	*err_msg = NULL;

	if (!conf_file)	
	{
		*err_msg = strdup("No configuration file selected");
		return FALSE;
	}

	fh = fopen(conf_file, "wb");

	if (!fh)
	{
		asprintf(err_msg, "Cannot open %s for write access", conf_file);
		return FALSE;
	}

	failed |= fprintf(fh, "keep_channels_sorted=%s\n", true_false_str(keep_channels_sorted)) == -1;

	failed |= fprintf(fh, "default_colorpair=") == -1;
	emit_colorpair(fh, default_colorpair);
	failed |= fprintf(fh, "\n") == -1;
	failed |= fprintf(fh, "highlight_colorpair=") == -1;
	emit_colorpair(fh, highlight_colorpair);
	failed |= fprintf(fh, "\n") == -1;
	failed |= fprintf(fh, "meta_colorpair=") == -1;
	emit_colorpair(fh, meta_colorpair);
	failed |= fprintf(fh, "\n") == -1;
	failed |= fprintf(fh, "error_colorpair=") == -1;
	emit_colorpair(fh, error_colorpair);
	failed |= fprintf(fh, "\n") == -1;
	failed |= fprintf(fh, "temp_colorpair=") == -1;
	emit_colorpair(fh, temp_colorpair);
	failed |= fprintf(fh, "\n") == -1;
	failed |= fprintf(fh, "markerline_colorpair=") == -1;
	emit_colorpair(fh, markerline_colorpair);
	failed |= fprintf(fh, "\n") == -1;

	failed |= fprintf(fh, "\n") == -1;

	for(loop=0; loop<n_servers && !failed; loop++)
	{
		int sal = 0, achl = 0;
		server *ps = &server_list[loop];

		failed |= fprintf(fh, "server=%s:%d\n", ps -> server_host, ps -> server_port) == -1;
		failed |= fprintf(fh, "description=%s\n", ps -> description ? ps -> description : ps -> server_host) == -1;
		failed |= fprintf(fh, "name=%s\n", ps -> user_complete_name) == -1;
		failed |= fprintf(fh, "username=%s\n", ps -> username) == -1;
		failed |= fprintf(fh, "password=%s\n", ps -> password) == -1;
		failed |= fprintf(fh, "nickname=%s\n", ps -> nickname) == -1;

		for(achl=0; achl<string_array_get_n(&ps -> auto_join) && !failed; achl++)
			failed |= fprintf(fh, "auto_join=%s\n", string_array_get(&ps -> auto_join, achl)) == -1;

		for(sal=0; sal<string_array_get_n(&ps -> send_after_login) && !failed; sal++)
			failed |= fprintf(fh, "send_after_login=%s\n", string_array_get(&ps -> send_after_login, sal)) == -1;

		if (remember_channels)
		{
			int chl = 0;

			for(chl=0; chl<ps -> n_channels && !failed; chl++)
			{
				BOOL is_auto_join = FALSE;
				const char *cur_channel = ps -> pchannels[chl].channel_name;

				if (!is_channel(cur_channel))
					continue;

				for(achl=0; achl<string_array_get_n(&ps -> auto_join); achl++)
				{
					if (strcasecmp(string_array_get(&ps -> auto_join, achl), cur_channel) == 0)
					{
						is_auto_join = TRUE;
						break;
					}
				}

				if (!is_auto_join)
					failed |= fprintf(fh, "rejoin=%s\n", cur_channel) == -1;
			}
		}

		failed |= fprintf(fh, ";\n") == -1;
	}

	for(loop=0; loop<n_favorite_channels && !failed; loop++)
	{
		favorite *pf = &favorite_channels[loop];

		if (pf -> server)
			failed |= fprintf(fh, "favorite=%s %s\n", pf -> server, pf -> channel) == 0;
		else
			failed |= fprintf(fh, "favorite=%s\n", pf -> channel) == 0;

		if (failed)
			break;
	}

	if (n_favorite_channels)
		failed |= fprintf(fh, ";\n") == -1;

	failed |= fprintf(fh, "all-colors=%s\n", true_false_str(colors_all)) == -1;
	failed |= fprintf(fh, "meta-colors=%s\n", true_false_str(colors_meta)) == -1;
	failed |= fprintf(fh, "nick-color=%s\n", true_false_str(nick_color)) == -1;
	failed |= fprintf(fh, "partial_highlight_match=%s\n", true_false_str(partial_highlight_match)) == -1;
	failed |= fprintf(fh, "notice_in_serverchannel=%s\n", true_false_str(notice_in_server_channel)) == -1;
	failed |= fprintf(fh, "highlight=%s\n", true_false_str(highlight)) == -1;
	failed |= fprintf(fh, "auto_private_channel=%s\n", true_false_str(auto_private_channel)) == -1;
	failed |= fprintf(fh, "update_clock_at_data=%s\n", true_false_str(update_clock_at_data)) == -1;
	failed |= fprintf(fh, "max_channel_record_lines=%d\n", max_channel_record_lines) == -1;
	failed |= fprintf(fh, "word_cloud_n=%d\n", word_cloud_n) == -1;
	failed |= fprintf(fh, "delay_before_reconnect=%d\n", delay_before_reconnect) == -1;
	failed |= fprintf(fh, "word_cloud_refresh=%d\n", word_cloud_refresh) == -1;
	failed |= fprintf(fh, "word_cloud_win_height=%d\n", word_cloud_win_height) == -1;
	failed |= fprintf(fh, "word_cloud_min_word_size=%d\n", word_cloud_min_word_size) == -1;
	failed |= fprintf(fh, "store_config_on_exit=%s\n", true_false_str(store_config_on_exit)) == -1;
	failed |= fprintf(fh, "topic_scroll=%s\n", true_false_str(topic_scroll)) == -1;
	failed |= fprintf(fh, "allow_invite=%s\n", true_false_str(allow_invite)) == -1;
	failed |= fprintf(fh, "show_parts=%s\n", true_false_str(show_parts)) == -1;
	failed |= fprintf(fh, "show_mode_changes=%s\n", true_false_str(show_mode_changes)) == -1;
	failed |= fprintf(fh, "show_nick_change=%s\n", true_false_str(show_nick_change)) == -1;
	failed |= fprintf(fh, "show_joins=%s\n", true_false_str(show_joins)) == -1;
	failed |= fprintf(fh, "auto_rejoin=%s\n", true_false_str(auto_rejoin)) == -1;
	failed |= fprintf(fh, "use_nonbasic_colors=%s\n", true_false_str(use_nonbasic_colors)) == -1;
	failed |= fprintf(fh, "inverse_window_heading=%s\n", true_false_str(inverse_window_heading)) == -1;
	failed |= fprintf(fh, "remember_channels=%s\n", true_false_str(remember_channels)) == -1;
	failed |= fprintf(fh, "mark_personal_messages=%s\n", true_false_str(mark_personal_messages)) == -1;
	failed |= fprintf(fh, "space_after_start_marker=%s\n", true_false_str(space_after_start_marker)) == -1;
	failed |= fprintf(fh, "fuzzy_highlight=%s\n", true_false_str(fuzzy_highlight)) == -1;
	failed |= fprintf(fh, "allow_userinfo=%s\n", true_false_str(allow_userinfo)) == -1;
	failed |= fprintf(fh, "ignore_mouse=%s\n", true_false_str(ignore_mouse)) == -1;
	failed |= fprintf(fh, "jumpy_navigation=%s\n", true_false_str(jumpy_navigation)) == -1;
	failed |= fprintf(fh, "user_column=%s\n", true_false_str(user_column)) == -1;
	failed |= fprintf(fh, "user_column_width=%d\n", user_column_width) == -1;
	failed |= fprintf(fh, "mark_meta=%s\n", true_false_str(mark_meta)) == -1;
	failed |= fprintf(fh, "full_user=%s\n", true_false_str(full_user)) == -1;
	failed |= fprintf(fh, "show_headlines=%s\n", true_false_str(show_headlines)) == -1;
	failed |= fprintf(fh, "irc_keepalive=%s\n", true_false_str(irc_keepalive)) == -1;
	failed |= fprintf(fh, "auto_markerline=%s\n", true_false_str(auto_markerline)) == -1;
	failed |= fprintf(fh, "ignore_unknown_irc_protocol_msgs=%s\n", true_false_str(ignore_unknown_irc_protocol_msgs)) == -1;
	failed |= fprintf(fh, "only_one_markerline=%s\n", true_false_str(only_one_markerline)) == -1;

	if (dcc_bind_to)
		failed |= fprintf(fh, "dcc_bind_to=%s\n", dcc_bind_to) == -1;

	if (log_dir)
		failed |= fprintf(fh, "log_dir=%s\n", log_dir) == -1;

	if (userinfo)
		failed |= fprintf(fh, "userinfo=%s\n", userinfo) == -1;

	if (notify_nick)
		failed |= fprintf(fh, "notify_nick=%s\n", notify_nick) == -1;

	if (dictionary_file)
		failed |= fprintf(fh, "dictionary_file=%s\n", dictionary_file) == -1;

	if (finger_str)
		failed |= fprintf(fh, "finger_str=%s\n", finger_str) == -1;

	if (dcc_path)
		failed |= fprintf(fh, "dcc_path=%s\n", dcc_path) == -1;

	if (ignore_file)
		failed |= fprintf(fh, "ignore_file=%s\n", ignore_file) == -1;

	if (theme_file)
		failed |= fprintf(fh, "theme=%s\n", theme_file) == -1;

	if (part_message)
		failed |= fprintf(fh, "part_message=%s\n", part_message) == -1;

	if (server_exit_message)
		failed |= fprintf(fh, "server_exit_message=%s\n", server_exit_message) == -1;

	failed |= dump_grep_filters(gp, "grep_filter", fh) == FALSE;

	failed |= dump_grep_filters(hlgp, "headline_filter", fh) == FALSE;

	failed |= dump_headline_matchers(fh) == FALSE;

	failed |= dump_string_array(&extra_highlights, "extra_highlights", fh) == FALSE;

	if (failed)
	{
		asprintf(err_msg, "Failed writing to %s: disk full?", conf_file);
		fclose(fh);
		return FALSE;
	}

	asprintf(err_msg, "All fine, written %ld bytes to %s", ftell(fh), conf_file);

	if (fclose(fh))
	{
		asprintf(err_msg, "Problem finalizing %s", conf_file);
		return FALSE;
	}

	return TRUE;
}