bool db_chunk::next_file(db_file& file) { static const auto header_size = sizeof(db_uint) * 2; static const auto entry_size = sizeof(db_uint) * 2; if(m_current == m_count) return false; // Each file entry is represented by two db_uints that tell us the size of // the file and an offset where the null terminated filename is stored. auto entry_offset = header_size + m_current * entry_size; db_uint file_size = read_binary(m_data, entry_offset); db_uint name_offset = read_binary(m_data, entry_offset + sizeof(db_uint)); // Filenames come after all the file variables. auto names_base = header_size + m_count * entry_size; file.m_name_start = m_data.c_str() + names_base + name_offset; file.m_name_end = file.m_name_start + std::strlen(file.m_name_start); file.m_start = m_data.c_str() + m_data_offset; file.m_end = file.m_start + file_size; // Advance the data offset so that it points to the next file. m_data_offset += file_size; m_current++; return true; }
db_chunk::db_chunk(const std::string& data) : m_data(data) { // A chunk starts with an offset to the file data and the file count. m_data_offset = read_binary(m_data, 0); m_count = read_binary(m_data, sizeof(db_uint)); m_current = 0; }
binary_reader::stock_data::stock_data( std::ifstream& in ) { read_binary( in, stock_name_ ); read_binary( in, date_time_ ); read_binary( in, price_ ); read_binary( in, vwap_ ); read_binary( in, volume_ ); read_binary( in, f1_ ); read_binary( in, t1_ ); read_binary( in, f2_ ); read_binary( in, f3_ ); read_binary( in, f4_ ); }
static errr rd_cave_memory(player_type *p_ptr) { u16b max_y, max_x; int y, x; char cave_row[MAX_WID+1]; start_section_read("cave_memory"); /* Memory dimensions */ max_y = read_int("max_height"); max_x = read_int("max_width"); for (y = 0; y < max_y; y++) { read_binary("row",cave_row,MAX_WID); for(x = 0; x < max_x; x++) { p_ptr->cave_flag[y][x] = cave_row[x]; } } end_section_read("cave_memory"); /* Success */ return (0); }
int BinaryFileReader::read_omega() { int number = 1; while (read_bit() == 1) { number = read_binary(number); } return number; }
// Read a text file as a std::string, throw error if file is binary inline std::string read_text(const std::string& filename, const boost::uint64_t max_size = 0) { BufferPtr bp = read_binary(filename, max_size); if (bp->contains_null()) OPENVPN_THROW(file_is_binary, "file is binary: " << filename); return std::string((const char *)bp->c_data(), bp->size()); }
static void redis_drv_get(redis_drv_t *redis_drv, Reader *const reader) { int rc; char *val; REDIS redis = redis_drv->redis; const uint64_t *keysize = NULL; const char *key = NULL; if(read_binary(reader, &key, &keysize)){ rc = credis_get(redis, key, &val); if(rc > -1){ ErlDrvTermData spec[] = { ERL_DRV_BINARY, (ErlDrvTermData) val, strlen(val), 0 }; driver_output_term(redis_drv->port, spec, sizeof(spec) / sizeof(spec[0])); } else{ return_error(redis_drv, REDIS_DRV_NIL); } } else{ return_error(redis_drv, REDIS_DRV_ERROR); } }
bool MCSessionReadSession(MCSession *p_session) { bool t_success = true; t_success = read_binary(p_session->filehandle, (void*&)p_session->data, p_session->data_length); return t_success; }
static void redis_drv_srem(redis_drv_t *redis_drv, Reader *const reader) { int rc; REDIS redis = redis_drv->redis; const uint64_t *keysize = NULL; const char *key = NULL; const uint64_t *valuesize = NULL; const char *value = NULL; if(read_binary(reader, &key, &keysize) && read_binary(reader, &value, &valuesize)){ rc = credis_srem(redis, key, value); if(rc > -1){ return_ok(redis_drv, REDIS_DRV_OK); } } }
int main() { for( std::string fname : { "/bin/grep", "/usr/bin/python", "/usr/bin/nm", "/usr/local/bin/clang++" } ) { std::system( ( "wc -c " + fname ).c_str() ) ; std::string contents = read_binary(fname) ; std::cout << fname << ": " << contents.size() << " bytes were read\n\n" << std::flush ; } }
/*START_OF_MAIN*/ int main() { int i=0; combine_type person_info; read_and_write("person_info.txt","person_info.bin"); read_binary("person_info.bin",person_info); return 0; /*END_OF_MAIN*/ }
int BinaryFileReader::read_gamma() { if (!opened) { error_file_not_opened(); return 0; } int n = 0; while (read_bit() == 0) ++n; return read_binary(n); }
/*Reads informations from binary file and records in table array returns number of row*/ int Load_Mpn_table(FILE *binary_input_file, Row mpn_table[], int maxsize) { int location=0; /*Location information in the array*/ int actual_size=0; /*Actual size or number of row in table*/ while(maxsize==10){ maxsize=read_binary(binary_input_file, &mpn_table[location]); actual_size+=maxsize; location+=maxsize; } return actual_size; }
STLFile::STLFile( const std::string &filename, double vertex_matching_eps, double signed_volume_eps ) : _filename(filename), _solid(vertex_matching_eps, signed_volume_eps) { ibsimu.message( 1 ) << "Reading STL-file \'" << filename << "\'\n"; ibsimu.inc_indent(); std::ifstream ifstr( filename.c_str(), std::ios_base::binary ); if( !ifstr.good() ) throw( Error( ERROR_LOCATION, "Couldn't open file \'" + filename + "\'" ) ); /* Check if ascii * Ascii files start with "solid XXX\n", on first line where XXX is free * form text. Second line starts with "facet normal" with possible leading whitespace * Binary files have free form 80 byte header */ _ascii = false; char buf[1024]; ifstr.read( buf, 1024 ); std::streamsize c = ifstr.gcount(); if( c > 6 && !strncasecmp( buf, "solid ", 6 ) ) { // Might be ascii, seek next line int a = 6; while( a < c && buf[a] != '\n' ) a++; while( a < c && isspace(buf[a]) ) a++; if( a+12 < c && !strncasecmp( &buf[a], "facet normal", 12 ) ) _ascii = true; } // Read triangle data ifstr.clear(); // Clear possible eofbit/failbit ifstr.seekg( 0 ); if( _ascii ) read_ascii( ifstr ); else read_binary( ifstr ); ifstr.close(); // Convert to vertex triangle data build_vtriangle_data(); _solid.check_data(); _tri.clear(); ibsimu.dec_indent(); }
static void redis_drv_del(redis_drv_t *redis_drv, Reader *const reader) { int rc; REDIS redis = redis_drv->redis; const uint64_t *keysize = NULL; const char *key = NULL; if(read_binary(reader, &key, &keysize)){ rc = credis_del(redis, key); if(rc > -1){ return_ok(redis_drv, REDIS_DRV_OK); } } return_error(redis_drv, REDIS_DRV_ERROR); }
status_t create_brig_module_from_brig_file(const char* file_name, hsa_ext_brig_module_t** brig_module) { FILE *fp = fopen(file_name, "rb"); status_t status = read_binary(brig_module, fp); if (status != STATUS_SUCCESS) { printf("Could not create BRIG module: %d\n", status); if (status == STATUS_KERNEL_INVALID_SECTION_HEADER || status == STATUS_KERNEL_ELF_INITIALIZATION_FAILED || status == STATUS_KERNEL_INVALID_ELF_CONTAINER) { printf("The ELF file is invalid or possibley corrupted.\n"); } if (status == STATUS_KERNEL_MISSING_DATA_SECTION || status == STATUS_KERNEL_MISSING_CODE_SECTION || status == STATUS_KERNEL_MISSING_OPERAND_SECTION) { printf("One or more ELF sections are missing. Use readelf command to \ to check if hsa_data, hsa_code and hsa_operands exist.\n"); }
int main(int argc, char **argv) { if (argc != 6) { std::cout << "\nUsage:\n" << argv[0] << " file.bin ncols width jump h\n" << "file.bin contains media properties with curvy interface\n" << "ncols is number of columns in binary file\n" << "width is size of part of interface for jump (in cells) - not used with second version\n" << "jump is heigth of jump of interface (in cells)\n" << "h is cell size (m)\n\n"; return 1; } try { const std::string filename = std::string(argv[1]); const int n_cols = atoi(argv[2]); const int width = atoi(argv[3]); const int jump = atoi(argv[4]); const float h = atof(argv[5]); float *values = NULL; int n_rows; read_binary(filename, n_cols, &n_rows, &values); float *curvy_line = new float[n_cols]; // y-coordinates of the line get_curvy_line(values, n_cols, n_rows, h, curvy_line); // make_super_curvy(values, n_cols, n_rows, width, jump); make_super_curvy2(values, n_cols, n_rows, jump, h, curvy_line); write_binary(file_stem(filename) + "_curvy.bin", values, n_cols, n_rows); delete[] values; } catch (const std::exception& e) { std::cout << "\n" << e.what() << "\n" << std::endl; return 2; } catch (...) { std::cout << "\n\n\nUnknown exception!\n\n" << std::endl; return 3; } return 0; }
int main(int argc, char *argv[]) { Params params; struct timeval startTime, endTime; double total_time; long total_bytes; initCL(¶ms); parseCL(¶ms, &argc, &argv); validateCL(¶ms); gettimeofday(&startTime, NULL); if (params.buffer > 0) { if (strncmp(params.mode, "text", 6) == 0) { read_text_buffered(params.file, params.buffer); } else if (strncmp(params.mode, "binary", 6) == 0) { read_binary_buffered(params.file, params.buffer); } else if (strncmp(params.mode, "hdf5", 4) == 0) { read_hdf5_buffered(params.file, params.buffer); } else { errx(EXIT_FAILURE, "unknown mode '%s' for buffered", params.mode); } } else { if (strncmp(params.mode, "text", 4) == 0) { read_text(params.file); } else if (strncmp(params.mode, "binary", 6) == 0) { read_binary(params.file); } else if (strncmp(params.mode, "hdf5", 4) == 0) { read_hdf5(params.file); } else { errx(EXIT_FAILURE, "unknown mode '%s' for unbuffered I/O", params.mode); } } gettimeofday(&endTime, NULL); total_time = endTime.tv_sec - startTime.tv_sec + (endTime.tv_usec - startTime.tv_usec)*1e-6; total_bytes = get_size(params.file); printf("%s\t%ld\t%d\t%.6f\n", params.file, total_bytes, params.buffer, total_time); finalizeCL(¶ms); return EXIT_SUCCESS; }
int search_virus_sig_in_binary(char* black_entry, char* binary){ char b_entry[256]; strcpy(b_entry, black_entry); char* sign = strchr(b_entry, ',')+1; char* entry = strtok(sign," "); char* virus_entries[20];int i = 0; int ret_val = -1; while(entry){ virus_entries[i++] = entry; entry = strtok(NULL," "); } char *bin_arr = NULL; unsigned int bin_sz = 0; int ret = read_binary(binary, &bin_arr, &bin_sz); if (ret < 0) return ret; unsigned int j = 0; int match = 0; int a = 0; for(j=0;j<bin_sz;j++){ match = 1; for(i=0;i<20;i++){ a = (int)strtol(virus_entries[i], NULL, 16); if((bin_arr[j+i] & 0xff) != a){ match = 0; break; } } if(match){ ret_val = 0; #if 0 printf("Virus signature at an offset of %d bytes in the binary!\n", j); #endif break; } } return ret_val; }
// Read a UTF-8 file as a std::string, throw errors if file is binary or malformed UTF-8 inline std::string read_text_utf8(const std::string& filename, const boost::uint64_t max_size = 0) { BufferPtr bp = read_binary(filename, max_size); // check if binary if (bp->contains_null()) OPENVPN_THROW(file_is_binary, "file is binary: " << filename); // remove Windows UTF-8 BOM if present if (bp->size() >= 3) { const unsigned char *data = bp->c_data(); if (data[0] == 0xEF && data[1] == 0xBB && data[2] == 0xBF) bp->advance(3); } // verify that file is valid UTF-8 if (!Unicode::is_valid_utf8(bp->c_data(), bp->size())) OPENVPN_THROW(file_not_utf8, "file is not UTF8: " << filename); return std::string((const char *)bp->c_data(), bp->size()); }
static void redis_drv_smembers(redis_drv_t *redis_drv, Reader *const reader) { char **valv; int rc, max, i; REDIS redis = redis_drv->redis; const uint64_t *keysize = NULL; const char *key = NULL; if(read_binary(reader, &key, &keysize)){ rc = credis_smembers(redis, key, &valv); if(rc > 0){ max = rc*4; ErlDrvTermData spec[max+3]; for (i = 0; i < rc; i++){ spec[i*4] = ERL_DRV_BINARY; spec[i*4+1] = (ErlDrvTermData) valv[rc]; spec[i*4+2] = strlen(valv[rc]); spec[i*4+3] = 0; } spec[rc+1] = ERL_DRV_NIL; spec[rc+2] = ERL_DRV_LIST; spec[rc+3] = rc+1; driver_output_term(redis_drv->port, spec, sizeof(spec) / sizeof(spec[0])); } else{ return_empty_list(redis_drv); } } else{ return_empty_list(redis_drv); } }
int main() { enumerate_broken_digits(); int T; scanf("%d", &T); for (int i = 1; i <= T; i++) { int N; scanf("%d", &N); int d[N]; for (int j = 0; j < N; j++) { d[j] = read_binary(); } printf("Case #%d: ", i); int next; if (N > 10) { int j; for (j = 0; j < N; j++) { if (d[j] != d[j % 10]) { printf("ERROR!\n"); break; } } if (j != N) continue; next = next_state(&d[N-10], 10); } else { next = next_state(d, N); } if (next < 0) printf("ERROR!\n"); else { print_binary(next); printf("\n"); } } return 0; }
int BinaryFileReader::read_delta() { return read_binary(read_gamma() - 1); }
tga_image load_tga_image_from_file(const std::string& path) { std::ifstream stream(path, std::ios::binary); tga_header header; read_binary(stream, header.id_size); read_binary(stream, header.map_type); read_binary(stream, header.image_type); read_binary(stream, header.palette_start); read_binary(stream, header.palette_size); read_binary(stream, header.palette_entry_depth); read_binary(stream, header.x); read_binary(stream, header.y); read_binary(stream, header.width); read_binary(stream, header.height); read_binary(stream, header.color_depth); read_binary(stream, header.descriptor); tga_image image; image.width = header.width; image.height = header.height; size_t pixel_component_count = header.color_depth / CHAR_BIT; std::vector<unsigned char> buffer(header.width * header.height * pixel_component_count); read_binary(stream, buffer); for (size_t y = 0; y < header.height; y++) { size_t row_idx = ((header.descriptor & INVERTED_BIT) ? (header.height - 1 - y) : y) * header.width * pixel_component_count; for (size_t x = 0; x < header.width; x++) { size_t pixel_idx = row_idx + x * pixel_component_count; pixel pix = { (pixel_component_count > 0) ? buffer[pixel_idx + 0] : 0, (pixel_component_count > 1) ? buffer[pixel_idx + 1] : 0, (pixel_component_count > 2) ? buffer[pixel_idx + 2] : 0, (pixel_component_count > 3) ? buffer[pixel_idx + 3] : 255, }; image.data.push_back(pix); } } return image; }
int main() { int fd,atrlen,i,j,len; char mask[100],atr[100],data[100]; fd=serial_init("/dev/smartpoll"); if(send_num_mask(fd, mask)<0) { perror("send_num_mask failed"); return -1; } printf("Mask is : %s\n", mask); if((atrlen = power_up_iso(fd, atr))<0) { perror("power_up_iso failed"); return -1; } printf("ATR: "); for(i=0;i<atrlen;i++) printf("%x ", (unsigned char)atr[i]); printf("\n"); if(select_file(fd, 0x5f00)<0) { printf("Select file failed\n"); return -1; } printf("Selected file 0x5f00\n"); if((len=read_binary(fd, 0, 50, data))<0) { printf("read_binary failed\n"); return -1; } printf("Data (b4 write): "); for(i=0;i<len;i++) printf("%x ", (unsigned char)data[i]); printf("\n"); /* if(erase_binary(fd)<0) return -1; printf("Erased file 0x1f01\n"); */ memset(data,0x05,10); if(update_binary(fd, 0x14, 10, data)<0) return -1; printf("Wrote to file 0x5f00\n"); if((len=read_binary(fd, 0, 50, data))<0) return -1; printf("Data (after write): "); for(i=0;i<len;i++) printf("%x ", (unsigned char)data[i]); printf("\n"); serial_deinit(fd); }
int main(int argc, char**argv) { int i, k; int n; Forceinfo force; Nbodyinfo nbody; init_nbodyinfo(&nbody); vtc_init_cputime(); parse_argv(argc, argv); if (snapin_flag == 0 && !initcond_flag) { fprintf(stderr, "snapshot input file required (-i)\n"); show_usage(argv[0]); } if (initcond_flag) { create_initcond(&nbody, initn); tstart = 0.0; } else { if (ionemo_flag) { read_binary(snapinfile, &tstart, &nbody); } else if (usepob_flag) { read_pob(snapinfile, &tstart, &nbody); } else { read_ascii(snapinfile, &tstart, &nbody); } } n = nbody.n; nbody.a = (double (*)[3])malloc(sizeof(double)*3*n); nbody.p = (double *)malloc(sizeof(double)*n); if (NULL == nbody.a || NULL == nbody.p) { perror("main"); exit(1); } if (tstart > tend) { fprintf(stderr, "start time %f larger than end time %f. abort.\n", tstart, tend); exit(1); } #if DIRECT /* direct sum */ vtc_get_default_direct_params(&force); /* get current values */ #else /* tree */ vtc_get_default_tree_params(&force); /* get current values */ #endif /* direct/tree */ /* modify some of them */ force.theta = theta; force.eps = eps; force.ncrit = ncrit; force.node_div_crit = node_div_crit; force.p = me_order; force.negativemass = negativemass; force.pprad = pprad; force.full_dof = full_dof_flag; if (grape_flag) { force.calculator = GRAPE_FORCEONLY; force.calculator = GRAPE; } force.test_id = test_id; PR(snapinfile,s); PRL(snapoutfile,s); PRL(n,d); PR(eps, f); PR(theta, f); PR(ncrit, d); PRL(node_div_crit, d); { double mmin = 1e10; double mmax = 0.0; for (i = 0; i < nbody.n; i++) { if (mmin > nbody.m[i]) mmin = nbody.m[i]; if (mmax < nbody.m[i]) mmax = nbody.m[i]; } fprintf(stderr, "mmin: %e mmax: %e\n", mmin, mmax); } #if COSMO time_integration_loop_hubble(&force, &nbody); #else time_integration_loop(&force, &nbody); #endif #if USE_GM_API fprintf(stderr, "will m2_gm_finalize...\n"); m2_gm_finalize(); fprintf(stderr, "done m2_gm_finalize.\n"); #endif /* USE_GM_API */ exit(0); }
int main (int argc, char **argv) { int success = 1; int verbose = 0; /* 1: verbose, 0 (or nothing: not verbose) */ int clone = 0; /* 1: verbose, 0 (or nothing: not verbose) */ int binary = 0; FILE *torture_file; char *msg; int pos; int len; for (pos = 3; pos < argc; pos++) { if (0 == strncmp (argv[pos], "-v", 2)) verbose = 1; else if (0 == strncmp (argv[pos], "-c", 2)) clone = 1; else if (0 == strncmp (argv[pos], "-b", 2)) binary = 1; else usage (); } if (argc < 3) { usage (); } torture_file = fopen (argv[1], "r"); if (torture_file == NULL) { usage (); } /* initialize parser */ parser_init (); if (binary) { if (read_binary (&msg, &len, torture_file) < 0) return -1; } else { msg = read_text (atoi (argv[2]), torture_file); if (!msg) return -1; len = strlen (msg); } success = test_message (msg, len, verbose, clone); if (verbose) { fprintf (stdout, "test %s : ============================ \n", argv[2]); fwrite (msg, 1, len, stdout); if (0 == success) fprintf (stdout, "test %s : ============================ OK\n", argv[2]); else fprintf (stdout, "test %s : ============================ FAILED\n", argv[2]); } osip_free (msg); fclose (torture_file); #ifdef __linux if (success) exit (EXIT_FAILURE); else exit (EXIT_SUCCESS); #endif return success; }
/** * Construct by directly reading from file. */ csr_matrix_t (const char* input_file) : M(-1), N(-1), nnz(-1), sorted(false) { read_binary (input_file); sorted=true; }
/* * Actually read the savefile * */ static errr rd_savefile_new_aux(player_type *p_ptr) { int i; u16b tmp16u; u32b tmp32u; bool clear = FALSE; bool had_header = FALSE; char stat_order_hack[6]; start_section_read("mangband_player_save"); start_section_read("version"); read_int("major"); read_int("minor"); read_int("patch"); end_section_read("version"); if (section_exists("header")) { start_section_read("header"); had_header = TRUE; read_str("playername",p_ptr->name); /* 32 */ skip_value("pass"); p_ptr->prace = read_int("prace"); p_ptr->pclass = read_int("pclass"); p_ptr->male = read_int("male"); read_binary("stat_order", stat_order_hack, 6); for (i = 0; i < 6; i++) p_ptr->stat_order[i] = stat_order_hack[i]; end_section_read("header"); } /* Operating system info */ sf_xtra = read_uint("sf_xtra"); /* Time of savefile creation */ sf_when = read_uint("sf_when"); /* Number of resurrections */ sf_lives = read_int("sf_lives"); /* Number of times played */ sf_saves = read_int("sf_saves"); /* Skip the turn info - if present */ skip_value("turn"); /* Turn this character was born on */ if(value_exists("birth_turn")) read_hturn("birth_turn", &p_ptr->birth_turn); else /* Disable character event logging if no birth turn */ ht_clr(&p_ptr->birth_turn); /* Player turns (actually time spent playing) */ if(value_exists("player_turn")) read_hturn("player_turn", &p_ptr->turn); else ht_clr(&p_ptr->turn); /* Read birth options */ if (rd_birthoptions(p_ptr)) { return (28); } /* Monster Memory */ if (section_exists("monster_lore")) { start_section_read("monster_lore"); tmp16u = read_int("max_r_idx"); /* Incompatible save files */ if (tmp16u > z_info->r_max) { note(format("Too many (%u) monster races!", tmp16u)); return (21); } /* Read the available records */ for (i = 0; i < tmp16u; i++) { /* Read the lore */ rd_lore(p_ptr, i); } end_section_read("monster_lore"); } /* Object Memory */ start_section_read("object_memory"); tmp16u = read_int("max_k_idx"); /* Incompatible save files */ if (tmp16u > z_info->k_max) { note(format("Too many (%u) object kinds!", tmp16u)); return (22); } /* Read the object memory */ for (i = 0; i < tmp16u; i++) { byte tmp8u; tmp8u = read_int("flags"); p_ptr->obj_aware[i] = (tmp8u & 0x01) ? TRUE : FALSE; p_ptr->obj_tried[i] = (tmp8u & 0x02) ? TRUE : FALSE; } end_section_read("object_memory"); /*if (arg_fiddle) note("Loaded Object Memory");*/ /* Read the extra stuff */ rd_extra(p_ptr, had_header); /*if (arg_fiddle) note("Loaded extra information");*/ /* Read the player_hp array */ start_section_read("hp"); tmp16u = read_int("py_max_level"); /* Read the player_hp array */ for (i = 0; i < tmp16u; i++) { p_ptr->player_hp[i] = read_int("hp"); } end_section_read("hp"); /* Important -- Initialize the race/class */ p_ptr->rp_ptr = &p_info[p_ptr->prace]; p_ptr->cp_ptr = &c_info[p_ptr->pclass]; /* Important -- Choose the magic info */ p_ptr->mp_ptr = &c_info[p_ptr->pclass].spells; /* Read spell info */ if (section_exists("spell_flags")) { start_section_read("spell_flags"); for (i = 0; i < PY_MAX_SPELLS; i++) { p_ptr->spell_flags[i] = read_int("flag"); } end_section_read("spell_flags"); } else { /* Port spell flags from old format */ u32b spell_learned1, spell_learned2; u32b spell_worked1, spell_worked2; u32b spell_forgotten1, spell_forgotten2; spell_learned1 = read_uint("spell_learned1"); spell_learned2 = read_uint("spell_learned2"); spell_worked1 = read_uint("spell_worked1"); spell_worked2 = read_uint("spell_worked2"); spell_forgotten1 = read_uint("spell_forgotten1"); spell_forgotten2 = read_uint("spell_forgotten2"); for (i = 0; i < PY_MAX_SPELLS; i++) { if ((i < 32) ? (spell_forgotten1 & (1L << i)) : (spell_forgotten2 & (1L << (i - 32)))) { p_ptr->spell_flags[i] |= PY_SPELL_FORGOTTEN; } if ((i < 32) ? (spell_learned1 & (1L << i)) : (spell_learned2 & (1L << (i - 32)))) { p_ptr->spell_flags[i] |= PY_SPELL_LEARNED; } if ((i < 32) ? (spell_worked1 & (1L << i)) : (spell_worked2 & (1L << (i - 32)))) { p_ptr->spell_flags[i] |= PY_SPELL_WORKED; } } } start_section_read("spell_order"); for (i = 0; i < PY_MAX_SPELLS; i++) { p_ptr->spell_order[i] = read_int("order"); } end_section_read("spell_order"); /* Read the inventory */ if (rd_inventory(p_ptr)) { /*note("Unable to read inventory");*/ return (21); } /* Read hostility information if new enough */ if (rd_hostilities(p_ptr)) { return (22); } rd_cave_memory(p_ptr); /* read the wilderness map */ start_section_read("wilderness"); /* get the map size */ tmp32u = read_int("max_wild"); /* if too many map entries */ if (tmp32u > MAX_WILD) { return 23; } /* read in the map */ for (i = 0; i < tmp32u; i++) { p_ptr->wild_map[i] = read_int("wild_map"); } end_section_read("wilderness"); /* Read the character event history */ if(section_exists("event_history")) { char buf[160]; cptr msg; history_event evt; history_event *last = NULL; start_section_read("event_history"); while(value_exists("hist")) { int depth, level; history_event *n_evt = NULL; read_str("hist", buf); if (sscanf(buf, "%02i:%02i:%02i %4ift %2i ", &evt.days, &evt.hours, &evt.mins, &depth, &level) == 5) { msg = &buf[25];/* skip 25 characters ^ */ evt.depth = depth / 50; evt.message = quark_add(msg); } /* Allocate */ MAKE(n_evt, history_event); n_evt->days = evt.days; n_evt->hours = evt.hours; n_evt->mins = evt.mins; n_evt->depth = evt.depth; n_evt->level = level; n_evt->message = evt.message; /* Add to chain */ if (!last) { p_ptr->charhist = n_evt; last = n_evt; } else { last->next = n_evt; last = n_evt; } } end_section_read("event_history"); } /* Read the characters quest list */ if(section_exists("quests")) { start_section_read("quests"); tmp16u = read_int("max_q_idx"); for(i = 0; i < MAX_Q_IDX; i++) { tmp16u = read_int("level"); p_ptr->q_list[i].level = tmp16u; } end_section_read("quests"); } /* Read the characters sold artifact list */ if(section_exists("found_artifacts")) { start_section_read("found_artifacts"); tmp16u = read_int("max_a_idx"); tmp32u = tmp16u; /* If we have an unexpected number of arts, just reset our list * of sold artifacts. It's not so important we want to break * save file compatability for it. */ if( tmp16u != z_info->a_max ) { clear = TRUE; tmp16u = 0; } for(i = 0; i < z_info->a_max; i++) { if(i < tmp32u) { if(!clear) tmp16u = read_int("a_info"); } p_ptr->a_info[i] = tmp16u; } end_section_read("found_artifacts"); } /* Hack -- no ghosts */ /* r_info[z_info->r_max - 1].max_num = 0; */ end_section_read("mangband_player_save"); /* Success */ return (0); }
void read_array(xgobidata *xg) { char fname[128]; FILE *fp; static char *suffixes[] = {".dat", ""}; /* * Check file exists and open it - for stdin no open needs to be done * only assigning fp to be stdin. */ if (strcmp((char *) xg->datafname, "stdin") == 0) { fp = stdin; /* * If reading from stdin, set an alarm. If after 5 seconds, * no data has been read, print an error message and exit. */ if (fp == stdin) { alarm((unsigned int) 5); signal(SIGALRM, stdin_empty); } read_ascii(fp, xg); } else { /* * Are we reading the missing data into xg->raw_data ? */ if (strcmp( ".missing", &xg->datafilename[strlen(xg->datafilename) - strlen(".missing")] ) == 0) { if ((fp = fopen(xg->datafilename, "r")) != NULL) { char *title, fulltitle[256]; xg->is_missing_values_xgobi = True; xg->missing_values_present = True; read_ascii(fp, xg); /* * extend the title */ title = (char *) XtMalloc(256 * sizeof(char)); XtVaGetValues(xg->shell, XtNtitle, (String) &title, NULL); sprintf(fulltitle, "%s", title); /* -vtitle has been used */ if (strcmp(xg->vtitle, "") != 0) { strcpy(fulltitle, xg->vtitle); sprintf(xg->vtitle, ""); } XtVaSetValues(xg->shell, XtNtitle, (String) fulltitle, XtNiconName, (String) fulltitle, NULL); } else { (void) fprintf(stderr, "The file %s can't be opened for reading.\n", xg->datafilename); exit(0); } } else { /* * Try fname.bin before fname, to see whether there is a binary * data file available. If there is, call read_binary(). */ strcpy(fname, (char *) xg->datafname); strcat(fname, ".bin"); if ((fp = fopen(fname, "rb")) != NULL) read_binary(fp, xg); /* * If not, look for an ASCII file */ else { fp = open_xgobi_file((char *) xg->datafname, 2, suffixes, "r", false); if (fp == NULL) exit(0); read_ascii(fp, xg); } } } if (xg->is_scatmat) make_scatmat(xg); }