コード例 #1
0
ファイル: language.c プロジェクト: kashifsoofi/bygfoot
/** Find out which language to use (e.g. for live game commentary).
    Write the code (en, de etc.) into the buffer. */
void
language_get_code(gchar *buf)
{
#ifdef DEBUG
    printf("language_get_code\n");
#endif

    gchar *cur_locale = NULL;
#ifdef G_OS_UNIX
     cur_locale = setlocale(LC_MESSAGES, NULL);
#else
    cur_locale = g_win32_getlocale ();
#endif

    if(strcmp(opt_str("string_opt_language_code"), "C") == 0)
	strcpy(buf, "en");
    else if(strcmp(opt_str("string_opt_language_code"), "") == 0 &&
	    cur_locale != NULL)
    {
	strncpy(buf, cur_locale, 2);
	buf[2] = '\0';
    }
    else
	strcpy(buf, opt_str("string_opt_language_code"));
}
コード例 #2
0
ファイル: language.c プロジェクト: kashifsoofi/bygfoot
/** Set the game language to the specified one. */
void
language_set(gint index)
{
#ifdef DEBUG
    printf("language_set\n");
#endif

    gchar buf[SMALL], buf2[SMALL];
    gchar *dir;
    GPtrArray *codes =
	misc_separate_strings(const_str("string_language_codes"));

    if(index > 0)
	strcpy(buf, (gchar*)g_ptr_array_index(codes, index - 1));
    else
	strcpy(buf, "");

    if(strcmp(buf, opt_str("string_opt_language_code")) != 0 ||
       window.main == NULL)
    {
#ifndef MAC_BUILD
        dir = g_get_current_dir();
	sprintf(buf2, "%s%slocale", dir, G_DIR_SEPARATOR_S);
#else
        dir = file_get_mac_resource_path("locale");
        strcpy(buf2, dir);
#endif
        g_free(dir);

#ifdef ENABLE_NLS
	if(g_file_test(buf2, G_FILE_TEST_EXISTS))
	{
	    bindtextdomain (GETTEXT_PACKAGE, buf2);
	    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	    textdomain (GETTEXT_PACKAGE);
	}
#endif

	g_setenv ("LANGUAGE", buf, TRUE);
	opt_set_str("string_opt_language_code", buf);

	{
	    extern int _nl_msg_cat_cntr;
	    ++_nl_msg_cat_cntr;
	}

	if(window.main != NULL)
	{
	    window_destroy(&window.main);
	    window_create(WINDOW_MAIN);
	    on_button_back_to_main_clicked(NULL, NULL);
	}
    }

    lg_commentary_load_commentary_file_from_option();
    news_load_news_file_from_option();
    free_gchar_array(&codes);
}
コード例 #3
0
ファイル: helper.c プロジェクト: yjh0502/critbit
static int opt_int(const char *name, int fallback) {
    const char *env = opt_str(name);
    if(!env)
        return fallback;
    int val = atoi(env);
    if(!val)
        return fallback;
    return val;
}
コード例 #4
0
/// =-=-=-=-=-=-=-
/// @brief function which determines if a client/server negotiation is needed
///        on the server side
    bool do_client_server_negotiation_for_server( ) {
        // =-=-=-=-=-=-=-
        // check the SP_OPTION for the string stating a negotiation is requested
        char* opt_ptr = getenv( RODS_CS_NEG );

        // =-=-=-=-=-=-=-
        // if it is not set then move on
        if ( !opt_ptr || strlen( opt_ptr ) == 0 ) {
            return false;
        }

        // =-=-=-=-=-=-=-
        // if it is set then check for our magic token which requests
        // the negotiation, if its not there then return success
        std::string opt_str( opt_ptr );
        if ( std::string::npos == opt_str.find( REQ_SVR_NEG ) ) {
            return false;
        }

        // =-=-=-=-=-=-=-
        // otherwise, its a go.
        return true;

    } // do_client_server_negotiation_for_server
コード例 #5
0
ファイル: load_save.c プロジェクト: kashifsoofi/bygfoot
/** Load the game from the specified file.
    @param create_main_window Whether to create and show the main window. */
gboolean
load_save_load_game(const gchar* filename, gboolean create_main_window)
{
#ifdef DEBUG
    printf("load_save_load_game\n");
#endif

    GString *buf = g_string_new("");
    gchar *fullname = (g_str_has_suffix(filename, const_str("string_fs_save_suffix"))) ?
                      g_strdup(filename) :
                      g_strdup_printf("%s%s", filename, const_str("string_fs_save_suffix"));
    gchar *basename = g_path_get_basename(fullname),
                      *dirname = g_path_get_dirname(fullname);
    gchar *prefix = (g_str_has_suffix(basename, const_str("string_fs_save_suffix"))) ?
                    g_strndup(basename, strlen(basename) - strlen(const_str("string_fs_save_suffix"))) :
                    g_strdup(basename);
    gchar *pwd = g_get_current_dir();

    if(g_str_has_suffix(filename, "last_save"))
    {
        g_free(basename);
        g_free(dirname);
        g_free(prefix);
        g_free(fullname);

        basename = file_load_text_from_saves("last_save");

        if(basename != NULL)
        {
            load_save_load_game(basename, create_main_window);
            g_free(basename);
            return TRUE;
        }
        else
        {
            game_gui_show_warning(_("Last save file not found."));
            return FALSE;
        }
    }

    if(window.main != NULL)
        gtk_widget_hide(window.main);

    gui_show_progress(0, _("Uncompressing savegame..."),
                      PIC_TYPE_LOAD);

    file_decompress(fullname);

    if(debug > 60)
        g_print("load_save_load options\n");

    gui_show_progress(
        ((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
        _("Loading options..."),
        PIC_TYPE_LOAD);

    g_string_sprintf(buf, "%s%s%s___options", dirname, G_DIR_SEPARATOR_S, prefix);
    file_load_opt_file(buf->str, &options, FALSE);
    g_string_sprintf(buf, "%s%s%s___settings", dirname, G_DIR_SEPARATOR_S, prefix);
    file_load_opt_file(buf->str, &settings, FALSE);
    language_set(language_get_code_index(opt_str("string_opt_language_code")) + 1);

    if(debug > 60)
        g_print("load_save_load leagues \n");

    gui_show_progress(
        ((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
        _("Loading leagues and cups..."),
        PIC_TYPE_LOAD);

    xml_loadsave_leagues_cups_read(dirname, prefix);

    if(debug > 60)
        g_print("load_save_load users \n");

    gui_show_progress(
        ((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
        _("Loading users..."),
        PIC_TYPE_LOAD);

    xml_load_users(dirname, prefix);

    if(debug > 60)
        g_print("load_save_load transfers \n");

    gui_show_progress(
        ((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
        _("Loading transfer list..."),
        PIC_TYPE_LOAD);

    xml_load_transfers(dirname, prefix);

    if(debug > 60)
        g_print("load_save_load stats \n");

    gui_show_progress(
        ((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
        _("Loading season stats..."),
        PIC_TYPE_LOAD);

    xml_loadsave_season_stats_read(dirname, prefix);

    if(debug > 60)
        g_print("load_save_load jobs \n");

    gui_show_progress(
        ((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
        /* The 'job exchange' is a list of teams looking for a manager. */
        _("Loading job exchange..."),
        PIC_TYPE_LOAD);

    xml_loadsave_jobs_read(dirname, prefix);

    if(debug > 60)
        g_print("load_save_load newspaper \n");

    gui_show_progress(
        ((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
        _("Loading newspaper..."),
        PIC_TYPE_LOAD);

    xml_loadsave_newspaper_read(dirname, prefix);

    if(debug > 60)
        g_print("load_save_load misc \n");

    gui_show_progress(
        ((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
        _("Loading miscellaneous..."),
        PIC_TYPE_LOAD);

    xml_loadsave_misc_read(dirname, prefix);

    if(debug > 60)
        g_print("load_save_load done \n");

    gui_show_progress(1, _("Done."),
                      PIC_TYPE_LOAD);

    chdir(dirname);
    GPtrArray *files = file_dir_get_contents(dirname, prefix, "");
    // Remove the zipfile from the list
    gint i;
    for(i=0; i<files->len; i++)
    {
        if (g_strcmp0((gchar*)g_ptr_array_index(files, i),basename)==0)
        {
            g_ptr_array_remove_index_fast(files, i);
        }
    }
    file_remove_files(files);
    chdir(pwd);
    g_free(pwd);
    free_gchar_array(&files);


    misc_string_assign(&save_file, fullname);

    file_store_text_in_saves("last_save", fullname);

    gui_show_progress(-1, "",
                      PIC_TYPE_LOAD);

    if(create_main_window)
    {
        window_create(WINDOW_MAIN);
        on_button_back_to_main_clicked(NULL, NULL);
    }
    else if(window.main != NULL)
    {
        gtk_widget_show(window.main);
        window_main_load_geometry();
    }

    g_string_free(buf, TRUE);

    g_free(basename);
    g_free(dirname);
    g_free(prefix);
    g_free(fullname);

    return TRUE;
}