Esempio n. 1
0
File: nomad.c Progetto: eddie/clearn
int main()
{

  nd_file file;
  create_pack(&file);
  add_file(&file,"a.out");
  add_file(&file,"test.txt");
  write_pack(&file,"out.p");
  free_pack(&file);

  nd_file x = {0};
  read_pack(&x,"out.p");
  //dump_pack(&x);
  extract_file(&x,"test.txt","test.xxx");
  free_pack(&x);

  return 0;
}
Esempio n. 2
0
void
save_game(void)
{
    char fname[64];

#if defined( JAPAN )
    if (!get_input_line("セーブするファイル名は?", save_file, fname,
			"ゲームのセーブを中止しました。", 0, 1)) {
#else /* not JAPAN */
    if (!get_input_line("File name?", save_file, fname,
			"Game not saved", 0, 1)) {
#endif /* not JAPAN */
	return;
    }
    check_message();
    message(fname, 0);
    save_into_file(fname);
}

void
save_into_file(char *sfile)
{
    FILE *fp;
    int file_id;
    char name_buffer[80];
    char *hptr;
    struct rogue_time rt_buf;

#if !defined( ORIGINAL )
    if (org_dir && *org_dir) {
	chdir(org_dir);
    }
#endif /* not ORIGINAL */
    if (sfile[0] == '~') {
	if ((hptr = md_ghome())) {
	    (void) strcpy(name_buffer, hptr);
	    (void) strcat(name_buffer, sfile + 1);
	    sfile = name_buffer;
	}
    }
    if (((fp = fopen(sfile, "wb")) == NULL) ||
	((file_id = md_get_file_id(sfile)) == -1)) {
#if defined( JAPAN )
	message("セーブファイルにアクセスできません。", 0);
#else /* not JAPAN */
	message("Problem accessing the save file", 0);
#endif /* not JAPAN */
	goto err_return;
    }
    md_ignore_signals();
    write_failed = 0;
    (void) xxx(1);
    r_write(fp, (char *) &detect_monster, sizeof(detect_monster));
    r_write(fp, (char *) &cur_level, sizeof(cur_level));
    r_write(fp, (char *) &max_level, sizeof(max_level));
    write_string(hunger_str, fp);
    write_string(login_name, fp);
    r_write(fp, (char *) &party_room, sizeof(party_room));
    r_write(fp, (char *) &party_counter, sizeof(party_counter));
    write_pack(&level_monsters, fp);
    write_pack(&level_objects, fp);
    r_write(fp, (char *) &file_id, sizeof(file_id));
    rw_dungeon(fp, 1);
    r_write(fp, (char *) &foods, sizeof(foods));
    r_write(fp, (char *) &rogue, sizeof(fighter));
    write_pack(&rogue.pack, fp);
    rw_id(id_potions, fp, POTIONS, 1);
    rw_id(id_scrolls, fp, SCROLS, 1);
    rw_id(id_wands, fp, WANDS, 1);
    rw_id(id_rings, fp, RINGS, 1);
    r_write(fp, (char *) traps, (MAX_TRAPS * sizeof(trap)));
    r_write(fp, (char *) is_wood, (WANDS * sizeof(boolean)));
    r_write(fp, (char *) &cur_room, sizeof(cur_room));
    rw_rooms(fp, 1);
    r_write(fp, (char *) &being_held, sizeof(being_held));
    r_write(fp, (char *) &bear_trap, sizeof(bear_trap));
    r_write(fp, (char *) &halluc, sizeof(halluc));
    r_write(fp, (char *) &blind, sizeof(blind));
    r_write(fp, (char *) &confused, sizeof(confused));
    r_write(fp, (char *) &levitate, sizeof(levitate));
    r_write(fp, (char *) &haste_self, sizeof(haste_self));
    r_write(fp, (char *) &see_invisible, sizeof(see_invisible));
    r_write(fp, (char *) &detect_monster, sizeof(detect_monster));
    r_write(fp, (char *) &wizard, sizeof(wizard));
    r_write(fp, (char *) &score_only, sizeof(score_only));
    r_write(fp, (char *) &m_moves, sizeof(m_moves));
    md_gct(&rt_buf);
    rt_buf.second += 10;	/* allow for some processing time */
    r_write(fp, (char *) &rt_buf, sizeof(rt_buf));
    fclose(fp);

    if (write_failed) {
	(void) md_df(sfile);	/* delete file */
    } else {
	clean_up("");
    }

err_return:
    ;
#if !defined( ORIGINAL )
    if (game_dir && *game_dir) {
	chdir(game_dir);
    }
#endif /* not ORIGINAL */
}