/** Get the index of the given code in the codes array. */ gint language_get_code_index(const gchar *code) { #ifdef DEBUG printf("language_get_code_index\n"); #endif gint i, return_value = -1; GPtrArray *codes = misc_separate_strings(const_str("string_language_codes")); gchar local_code[SMALL]; strcpy(local_code, code); if(strcmp(code, "en") == 0) strcpy(local_code, "C"); for(i=0;i<codes->len;i++) if(strcmp(local_code, (gchar*)g_ptr_array_index(codes, i)) == 0) { return_value = i; break; } free_gchar_array(&codes); return return_value; }
/** Try to load a savegame given on the command line. */ gboolean load_game_from_command_line(const gchar *filename) { #ifdef DEBUG printf("load_game_from_command_line\n"); #endif gchar *fullname = NULL, *support_file_name = NULL; if(strcmp(filename, "last_save") == 0) return load_save_load_game(filename, TRUE); 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")); if(g_file_test(fullname, G_FILE_TEST_EXISTS)) { if(load_save_load_game(fullname, TRUE)) { g_free(fullname); return TRUE; } else return FALSE; } support_file_name = file_find_support_file(fullname, FALSE); if(g_file_test(support_file_name, G_FILE_TEST_EXISTS)) { if(load_save_load_game(support_file_name, TRUE)) { g_free(fullname); g_free(support_file_name); return TRUE; } else return FALSE; } debug_print_message("Could not find file %s.\n", fullname); g_free(fullname); return FALSE; }
/** Put the country matching the local language to the beginning of the array if possible. */ void language_pick_country(GPtrArray *country_files) { #ifdef DEBUG printf("language_pick_country\n"); #endif gint i, j; GPtrArray *codes = misc_separate_strings(const_str("string_language_codes")); GPtrArray *defs = misc_separate_strings(const_str("string_language_defs")); gpointer prefdef = NULL; const gchar *lang = g_getenv("LANGUAGE"); if(lang == NULL || strcmp(lang, "") == 0) lang = g_getenv("LANG"); if(lang == NULL || strcmp(lang, "") == 0) lang = g_getenv("LC_ALL"); if(lang != NULL) for(i=0;i<codes->len;i++) { if(((g_str_has_prefix(lang, "en") && strcmp((gchar*)g_ptr_array_index(codes, i), "C") == 0) || g_str_has_prefix(lang, (gchar*)g_ptr_array_index(codes, i))) && strcmp((gchar*)g_ptr_array_index(defs, i), "NONE") != 0) { for(j=0;j<country_files->len;j++) if(g_str_has_suffix((gchar*)g_ptr_array_index(country_files, j), (gchar*)g_ptr_array_index(defs, i))) { prefdef = g_ptr_array_index(country_files, j); break; } break; } } g_ptr_array_sort_with_data( country_files, (GCompareDataFunc)language_compare_country_files, prefdef); free_gchar_array(&codes); free_gchar_array(&defs); }
/** 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); }
static void db_info_dump(FILE * f, struct db_info * inf) { fprintf(f, " - Desc: \"%s\"\n", const_str(inf->desc)); fprintf(f, " - Version: %d.%d.%d\n", inf->version[0], inf->version[1], inf->version[2]); fprintf(f, " - JSON: txt=0x%08x len=%d crc=0x%04x\n", (uint32_t)inf->json.txt, inf->json.len ,inf->json.crc); }
static void model_dump(FILE * f, struct db_dev_model * sens) { fprintf(f, "\"%s\" \"%s\"\n", const_str(sens->model), const_str(sens->desc)); fprintf(f, "SIM: %s\n", model_sim_name(sens->sim)); fprintf(f, "PW1:"); pw_list_dump(f, sens->pw1lst); fprintf(f, "PW2:"); pw_list_dump(f, sens->pw2lst); fprintf(f, "PW3:"); pw_list_dump(f, sens->pw3lst); fprintf(f, "PW4:"); pw_list_dump(f, sens->pw4lst); fprintf(f, "PW5:"); pw_list_dump(f, sens->pw5lst); cmd_list_dump(f, sens->cmd); fprintf(f, "\n"); }
static void pw_list_dump(FILE * f, const struct pw_list * lst) { int i; if (lst == NULL) { DCC_LOG(LOG_WARNING, "lst == NULL!"); return; } DCC_LOG1(LOG_INFO, "lst=0x%08x", lst); for (i = 0; i < lst->cnt; ++i) { const struct pw_entry * pw = &lst->pw[i]; DCC_LOG2(LOG_INFO, "lst->pw[%d]=0x%08x", i, pw); fprintf(f, "\t[%4d %4d] %s\n", pw->min, pw->max, const_str(pw->desc)); } }
static void cmd_list_dump(FILE * f, struct cmd_list * lst) { int i; // int j; if (lst == NULL) return; DCC_LOG1(LOG_INFO, "lst=0x%08x", lst); for (i = 0; i < lst->cnt; ++i) { struct cmd_entry * cmd = &lst->cmd[i]; char s[20]; cmd_seq_dec(s, &cmd->seq); fprintf(f, "CMD[%d]: \"%s\" %s [%04x %04x]\n", i, const_str(cmd->tag), s, cmd->seq.msk, cmd->seq.val); // for (j = 0; j < SLCDEV_CMD_JS_LINE_MAX; ++j) { // if (cmd->js[j] > 0) // fprintf(f, "\"%s\"\n", const_str(cmd->js[j])); // } } }
/** Save the game to the specified file. */ void load_save_save_game(const gchar *filename) { #ifdef DEBUG printf("load_save_save_game\n"); #endif gchar buf[SMALL]; gchar *prefix = (g_str_has_suffix(filename, const_str("string_fs_save_suffix"))) ? g_strndup(filename, strlen(filename) - strlen(const_str("string_fs_save_suffix"))) : g_strdup(filename); GString *fullname = g_string_new(""); g_string_append(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"))); misc_string_assign(&save_file, fullname->str); if(g_file_test(fullname->str, G_FILE_TEST_EXISTS)) g_remove(fullname->str); if(debug > 60) g_print("load_save_save options\n"); gui_show_progress(0, _("Saving options..."), PIC_TYPE_SAVE); sprintf(buf, "%s___options", prefix); file_save_opt_file(buf, &options); sprintf(buf, "%s___settings", prefix); file_save_opt_file(buf, &settings); if(debug > 60) g_print("load_save_save leagues/cups \n"); gui_show_progress( ((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX, _("Saving leagues and cups..."), PIC_TYPE_SAVE); xml_loadsave_leagues_cups_write(prefix); if(debug > 60) g_print("load_save_save users \n"); gui_show_progress( ((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX, _("Saving users..."), PIC_TYPE_SAVE); xml_loadsave_users_write(prefix); if(debug > 60) g_print("load_save_save transfers \n"); gui_show_progress( ((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX, _("Saving transfer list..."), PIC_TYPE_SAVE); xml_loadsave_transfers_write(prefix); if(debug > 60) g_print("load_save_save stats \n"); gui_show_progress( ((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX, _("Saving season stats..."), PIC_TYPE_SAVE); xml_loadsave_season_stats_write(prefix); if(debug > 60) g_print("load_save_save 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. */ _("Saving job exchange..."), PIC_TYPE_SAVE); xml_loadsave_jobs_write(prefix); if(debug > 60) g_print("load_save_save newspaper \n"); gui_show_progress( ((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX, _("Saving newspaper..."), PIC_TYPE_SAVE); xml_loadsave_newspaper_write(prefix); if(debug > 60) g_print("load_save_save misc \n"); gui_show_progress( ((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX, _("Saving miscellaneous..."), PIC_TYPE_SAVE); xml_loadsave_misc_write(prefix); gui_show_progress( ((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX, _("Compressing savegame..."), PIC_TYPE_SAVE); sprintf(buf, "%s___", prefix); file_compress_files(fullname->str, buf); if(debug > 60) g_print("load_save_save done \n"); gui_show_progress(1, _("Done."), PIC_TYPE_SAVE); file_store_text_in_saves("last_save", fullname->str); g_free(prefix); g_string_free(fullname, TRUE); gui_show_progress(-1, "", PIC_TYPE_SAVE); setsav1; }
/** 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; }
int crackident (char *s) { struct keywords { char *k_name; /* the keyword string itself. */ short k_token; /* yacc %token for the keyword */ short k_yylval; /* the value associated with token.*/ }; static struct keywords kw[] = { /* Control flow keywords. */ { "while", Y_WHILE, 0 }, { "if", Y_IF, 0 }, { "else", Y_ELSE, 0 }, { "switch", Y_SWITCH, 0 }, { "case", Y_CASE, 0 }, { "default", Y_DEFAULT, 0 }, { "break", Y_BREAK, 0 }, { "next", Y_NEXT, 0 }, { "return", Y_RETURN, 0 }, { "goto", Y_GOTO, 0 }, { "for", Y_FOR, 0 }, { "procedure", Y_PROCEDURE, 0 }, { "begin", Y_BEGIN, 0 }, { "end", Y_END, 0 }, { "iferr", Y_IFERR, 0 }, { "ifnoerr", Y_IFNOERR, 0 }, { "then", Y_THEN, 0 }, /* Parameter and variable types. */ { "int", Y_INT, 0 }, { "char", Y_STRING, 0 }, { "real", Y_REAL, 0 }, { "string", Y_STRING, 0 }, { "file", Y_FILE, 0 }, { "gcur", Y_GCUR, 0 }, { "imcur", Y_IMCUR, 0 }, { "ukey", Y_UKEY, 0 }, { "pset", Y_PSET, 0 }, { "bool", Y_BOOL, 0 }, { "struct", Y_STRUCT, 0 }, /* debugging commands. */ { "d_d", D_D, 0 }, { "d_peek", D_PEEK, 0 }, { "", 0, 0 } /* sentinel; leave it here... */ }; static struct keywords kf[] = { /* Keywords of intrinsic functions that get built into * the grammar. Most intrinsics handled by intrinsic(). */ { "scan", Y_SCAN, 0 }, { "scanf", Y_SCANF, 0 }, { "fscan", Y_FSCAN, 0 }, { "fscanf", Y_FSCANF, 0 }, /* sentinel; leave it here... */ { "", 0, 0 } }; register struct keywords *kp; XINT oldtopd; static char sch, kch; /* static storage is faster here */ char *scopy; /* non-makelower'd copy */ char sb[REALWIDTH]; oldtopd = topd; /* save topd */ scopy = comdstr(s); /* make a copy in the dictionary */ makelower (scopy); /* make it lower case for compares */ topd = oldtopd; /*restore topd but scopy still there!*/ /* Put the first character of the identifier we are searching for * in local storage to permit fast rejection of keywords without all * the overhead involved in a call to strcmp. This is an easy way * to speed things up several times w/o coding fancy data structures. */ sch = *scopy; kch = *s; /* save original string */ /* Check for and handle special-case keywords first. */ if (sch == *truestr && !strcmp (scopy, truestr)) { yylval = addconst (truestr, OT_BOOL); return (Y_CONSTANT); } else if (sch == *falsestr && !strcmp (scopy, falsestr)) { yylval = addconst (falsestr, OT_BOOL); return (Y_CONSTANT); } else if (sch == *indeflc && !strcmp (scopy, indeflc)) { yylval = addconst (scopy, OT_INT); return (Y_CONSTANT); } else if (sch == *eoflc && !strcmp (scopy, eoflc)) { yylval = addconst (CL_EOFSTR, OT_INT); return (Y_CONSTANT); } else if (sch == *errorstr && !strcmp (scopy, errorstr)) { yylval = addconst (errorstr, OT_STRING); return (Y_IDENT); /* Check for defined numerical constants. For backwards compatability * we match 'epsilon', however this particular value is deprecated by * the fp_equal() builtin and we assume CL constants will be upper * case strings. */ } else if ((sch == *epsilonstr && !strcmp (scopy, epsilonstr)) || (kch == *epsilonuc && !strcmp (s, epsilonuc))) { sprintf (sb, "%e", EPSILON); yylval = addconst (sb, OT_REAL); return (Y_CONSTANT); } else if (const_str (pistr)) { retconst (PI); } else if (const_str (twopistr)) { retconst (TWOPI); } else if (const_str (fourpistr)) { retconst (FOURPI); } else if (const_str (halfpistr)) { retconst (HALFPI); } else if (const_str (sqrtpistr)) { retconst (SQRTOFPI); } else if (const_str (sqrttwostr)) { retconst (SQRTOF2); } else if (const_str (baseestr)) { retconst (BASE_E); } else if (const_str (ln2str)) { retconst (LN_2); } else if (const_str (ln10str)) { retconst (LN_10); } else if (const_str (lnpistr)) { retconst (LN_PI); } else if (const_str (logestr)) { retconst (LOG_E); } else if (const_str (gammastr)) { retconst (GAMMA); } else if (const_str (radianstr)) { retconst (RADIAN); } else if (const_str (austr)) { retconst (AU); } else if (const_str (gaccelstr)) { retconst (GRAV_ACCEL); } else if (const_str (gconststr)) { retconst (GRAV_CONST); } else if (const_str (lystr)) { retconst (LIGHT_YEAR); } else if (const_str (parsecstr)) { retconst (PARSEC); } else if (const_str (lightstr)) { retconst (SPEED_OF_LIGHT); } else if (const_str (solmassstr)) { retconst (SOLAR_MASS); } else if (!inarglist && parenlevel == 0) { /* Search the keyword list; kewords are not recognized in argument * lists and expressions, else unquoted strings like "for" and * "file" will cause syntax errors. */ for (kp=kw; (kch = *kp->k_name); kp++) if (kch == sch) if (strcmp (scopy, kp->k_name) == 0) { yylval = kp->k_yylval; return (kp->k_token); } } else { /* Search the list of intrinsic functions. */ for (kp=kf; (kch = *kp->k_name); kp++) if (kch == sch) if (strcmp (scopy, kp->k_name) == 0) { yylval = kp->k_yylval; return (kp->k_token); } } /* S not a keyword, so it's just an identifier. */ yylval = addconst (s, OT_STRING); /* use original */ return (Y_IDENT); }