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;
}
示例#2
0
void load_hs(void)
{
  hs_score = 100;
  hs_name  = "Grandma";

  FILE * fi;
  lisp_object_t* root_obj = 0;
  fi = fopen(highscore_filename, "r");
  if (fi == NULL)
    {
      perror(highscore_filename);
      return;
    }

  lisp_stream_t stream;
  lisp_stream_init_file (&stream, fi);
  root_obj = lisp_read (&stream);

  if (root_obj->type == LISP_TYPE_EOF || root_obj->type == LISP_TYPE_PARSE_ERROR)
    {
      printf("HighScore: Parse Error in file %s", highscore_filename);
    }


  if (strcmp(lisp_symbol(lisp_car(root_obj)), "supertux-highscore") == 0)
    {
      LispReader reader(lisp_cdr(root_obj));
      reader.read_int("score",  &hs_score);
      reader.read_string("name", &hs_name);
    }
 
  fclose(fi);
  lisp_free(root_obj);
}
VALUE sexpr_read_from_file(const char* filename)
{
  lisp_object_t* cur = lisp_read_from_file(filename);

  if (cur)
    {
      VALUE obj = build_py_sexpr(cur);
      lisp_free(cur);
      return obj;
    }
  else
    {
      return Qnil;
    }
}
示例#4
0
int
main (int argc, char *argv[])
{
    int small_width = DEFAULT_WIDTH, small_height = DEFAULT_HEIGHT;

    while (1)
    {
	static struct option long_options[] =
            {
		{ "width", required_argument, 0, 'w' },
		{ "height", required_argument, 0, 'h' },
		{ 0, 0, 0, 0 }
	    };

	int option, option_index;

	option = getopt_long(argc, argv, "w:h:", long_options, &option_index);

	if (option == -1)
	    break;

	switch (option)
	{
	    case 'w' :
		small_width = atoi(optarg);
		break;

	    case 'h' :
		small_height = atoi(optarg);
		break;

	    default :
		assert(0);
	}
    }

    printf("; -*- lisp -*-\n");

    do
    {
	int i, channel;
	char filename[1024];
	lisp_object_t *obj;
	float means[NUM_CHANNELS];

	scanf("%s", filename);
	if (feof(stdin))
	    break;

	assert(strlen(filename) > 0);

	printf("(small-image ");

	obj = lisp_make_string(filename);
	lisp_dump(obj, stdout);
	lisp_free(obj);

	printf(" (size %d %d) ", small_width, small_height);

	for (channel = 0; channel < NUM_CHANNELS; ++channel)
	    scanf("%f", &means[channel]);

	printf("(wavelet (means %f %f %f) (coeffs", means[0], means[1], means[2]);

	for (i = 0; i < NUM_COEFFS; ++i)
	{
	    int index;

	    scanf("%d", &index);
	    printf(" %d", index);
	}

	printf(")) (subpixel");

	for (channel = 0; channel < NUM_CHANNELS; ++channel)
	{
	    static char *channel_names[NUM_CHANNELS] = { "y", "i", "q" };

	    printf(" (%s", channel_names[channel]);

	    for (i = 0; i < NUM_SUBPIXELS; ++i)
	    {
		int val;

		scanf("%d", &val);
		printf(" %d", val);
	    }

	    printf(")");
	}

	printf("))\n");
    } while (!feof(stdin));

    return 0;
}
示例#5
0
/**
 * 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;
}