std::string slotinfo(int slot) { char tmp[1024]; char slotfile[1024]; std::string title; sprintf(slotfile,"%s/slot%d.stsg",st_save_dir,slot); lisp_object_t* savegame = lisp_read_from_file(slotfile); if (savegame) { LispReader reader(lisp_cdr(savegame)); reader.read_string("title", &title); lisp_free(savegame); } if (access(slotfile, F_OK) == 0) { if (!title.empty()) snprintf(tmp,1024,"Slot %d - %s",slot, title.c_str()); else snprintf(tmp, 1024,"Slot %d - Savegame",slot); } else sprintf(tmp,"Slot %d - Free",slot); return tmp; }
VALUE build_py_sexpr(lisp_object_t* cur) { if (lisp_cons_p(cur)) { VALUE lst = rb_ary_new(); while (cur) { rb_ary_push(lst, build_py_sexpr(lisp_car(cur))); cur = lisp_cdr(cur); } return lst; } else if (lisp_string_p(cur)) { return rb_str_new2(lisp_string(cur)); } else if (lisp_symbol_p(cur)) { return ID2SYM(rb_intern(lisp_symbol(cur))); } else if (lisp_integer_p(cur)) { return INT2NUM(lisp_integer(cur)); } else if (lisp_real_p(cur)) { return rb_float_new(lisp_real(cur)); } else if (lisp_boolean_p(cur)) { if (lisp_boolean(cur)) return Qtrue; else return Qfalse; } else { return Qnil; } }
/** * Load configuration file from "~/.tlkgames/powermanga.conf" * @return TRUE if it completed successfully or FALSE otherwise */ bool configfile_load (void) { #if !defined(_WIN32_WCE) Uint32 length; #endif lisp_object_t *root_obj, *lst, *sub; char *str; /* allocate config structure */ if (power_conf == NULL) { power_conf = (config_file *) memory_allocation (sizeof (config_file)); if (power_conf == NULL) { LOG_ERR ("not enough memory to allocate 'power_conf'!"); return FALSE; } } configfile_reset_values (); if (!configfile_check_dir ()) { return TRUE; } if (configname == NULL) { #if defined(_WIN32_WCE) configname = locate_data_file (config_file_name); if (configname == NULL) { LOG_ERR ("can't locate file: %s", config_file_name); return FALSE; } #else length = strlen (config_dir) + strlen (config_file_name) + 2; configname = memory_allocation (length); if (configname == NULL) { LOG_ERR ("not enough memory to allocate %i bytes!", length); return FALSE; } #endif } sprintf (configname, "%s/%s", config_dir, config_file_name); LOG_INF ("configuration filename: %s", configname); root_obj = lisp_read_file (configname); if (root_obj == NULL) { LOG_ERR ("lisp_read_file(%s) failed!", configname); return TRUE; } if (root_obj->type == LISP_TYPE_EOF || root_obj->type == LISP_TYPE_PARSE_ERROR) { LOG_ERR ("lisp_read_file(%s) failed!", configname); lisp_free (root_obj); return TRUE; } if (strcmp (lisp_symbol (lisp_car (root_obj)), "powermanga-config") != 0) { LOG_ERR ("lisp_read_file(%s) failed!", configname); lisp_free (root_obj); return TRUE; } lst = lisp_cdr (root_obj); if (!lisp_read_string (lst, "lang", &str)) { power_conf->lang = EN_LANG; } else { if (strcmp (str, "fr") == 0) { power_conf->lang = FR_LANG; } else if (strcmp (str, "it") == 0) { power_conf->lang = IT_LANG; } else { power_conf->lang = EN_LANG; } } if (!lisp_read_bool (lst, "fullscreen", &power_conf->fullscreen)) { power_conf->fullscreen = TRUE; } if (!lisp_read_bool (lst, "nosound", &power_conf->nosound)) { power_conf->nosound = FALSE; } if (!lisp_read_bool (lst, "nosync", &power_conf->nosync)) { power_conf->nosync = FALSE; } if (!lisp_read_int (lst, "verbose", &power_conf->verbose)) { power_conf->verbose = 0; } if (!lisp_read_int (lst, "scale_x", &power_conf->scale_x)) { power_conf->scale_x = 2; } if (power_conf->scale_x < 1 || power_conf->scale_x > 4) { power_conf->scale_x = 2; } if (!lisp_read_int (lst, "resolution", &power_conf->resolution)) { power_conf->resolution = 640; } if (power_conf->resolution != 320 && power_conf->resolution != 640) { power_conf->resolution = 640; } if (power_conf->scale_x > 1) { power_conf->resolution = 640; } sub = search_for (lst, "joy_config"); if (sub) sub = lisp_car_int (sub, &power_conf->joy_x_axis); if (sub) sub = lisp_car_int (sub, &power_conf->joy_y_axis); if (sub) sub = lisp_car_int (sub, &power_conf->joy_fire); if (sub) sub = lisp_car_int (sub, &power_conf->joy_option); if (sub) sub = lisp_car_int (sub, &power_conf->joy_start); lisp_free (root_obj); configfile_print(); return TRUE; }