EnumSig *Parser::parse_enum_sig() { size_t id = read_uint(); EnumSigState *sig = lookup(enums, id); if (!sig) { /* parse the signature */ sig = new EnumSigState; sig->id = id; sig->num_values = read_uint(); EnumValue *values = new EnumValue[sig->num_values]; for (EnumValue *it = values; it != values + sig->num_values; ++it) { it->name = read_string(); it->value = read_sint(); } sig->values = values; sig->fileOffset = file->currentOffset(); enums[id] = sig; } else if (file->currentOffset() < sig->fileOffset) { /* skip over the signature */ int num_values = read_uint(); for (int i = 0; i < num_values; ++i) { skip_string(); /*name */ skip_sint(); /* value */ } } assert(sig); return sig; }
StructSig *Parser::parse_struct_sig() { size_t id = read_uint(); StructSigState *sig = lookup(structs, id); if (!sig) { /* parse the signature */ sig = new StructSigState; sig->id = id; sig->name = read_string(); sig->num_members = read_uint(); const char **member_names = new const char *[sig->num_members]; for (unsigned i = 0; i < sig->num_members; ++i) { member_names[i] = read_string(); } sig->member_names = member_names; sig->fileOffset = file->currentOffset(); structs[id] = sig; } else if (file->currentOffset() < sig->fileOffset) { /* skip over the signature */ skip_string(); /* name */ unsigned num_members = read_uint(); for (unsigned i = 0; i < num_members; ++i) { skip_string(); /* member_name */ } } assert(sig); return sig; }
Value *Parser::parse_wstring() { size_t len = read_uint(); wchar_t * value = new wchar_t[len + 1]; for (size_t i = 0; i < len; ++i) { value[i] = read_uint(); } value[len] = 0; #if TRACE_VERBOSE std::cerr << "\tWSTRING \"" << value << "\"\n"; #endif return new WString(value); }
void Version::from_bip(char*& cursor) { set_label(read_string(cursor)); if(!label().empty()) set_exists(); int num_deps = read_uint(cursor); _deps.clear(); _deps.reserve(num_deps); for(int i=0; i < num_deps; i++) { Package::Ptr pkg = dataset.package(read_uint(cursor)); Version::Ptr dep = pkg->version(time()); add_dep(dep); } }
void lbm_read_state_binary(FILE * handle, LbmState * lbm_state) { size_t i; read_uint(handle, &lbm_state->lx); read_uint(handle, &lbm_state->ly); size_t nodes = lbm_state->lx * lbm_state->ly; for(i = 0; i < Q; ++i) read_n_doubles(handle, lbm_state->f[i], nodes); for(i = 0; i < Q; ++i) read_n_doubles(handle, lbm_state->f_next[i], nodes); }
bool SkFontDescriptor::Deserialize(SkStream* stream, SkFontDescriptor* result) { result->fStyle = (SkTypeface::Style)stream->readPackedUInt(); SkAutoSTMalloc<4, SkFixed> axis; size_t axisCount = 0; size_t index = 0; for (size_t id; (id = stream->readPackedUInt()) != kSentinel;) { switch (id) { case kFontFamilyName: read_string(stream, &result->fFamilyName); break; case kFullName: read_string(stream, &result->fFullName); break; case kPostscriptName: read_string(stream, &result->fPostscriptName); break; case kFontAxes: axisCount = read_uint(stream); axis.reset(axisCount); for (size_t i = 0; i < axisCount; ++i) { axis[i] = read_uint(stream); } break; case kFontIndex: index = read_uint(stream); break; case kFontFileName: // Remove when MIN_PICTURE_VERSION > 41 skip_string(stream); break; default: SkDEBUGFAIL("Unknown id used by a font descriptor"); return false; } } size_t length = stream->readPackedUInt(); if (length > 0) { SkAutoTUnref<SkData> data(SkData::NewUninitialized(length)); if (stream->read(data->writable_data(), length) == length) { result->fFontData.reset(new SkFontData(new SkMemoryStream(data), index, axis, axisCount)); } else { SkDEBUGFAIL("Could not read font data"); return false; } } return true; }
bool Parser::open(const char *filename) { assert(!file); if (filename) { #ifndef __EMSCRIPTEN__ file = File::createForRead(filename); #endif if (!file) { return false; } version = read_uint(); if (version > TRACE_VERSION) { std::cerr << "error: unsupported trace format version " << version << "\n"; delete file; file = NULL; return false; } } else { version = 5; // TODO version is temporary hard coded file = File::createBufferReader(); if (!file) { return false; } file->open("", File::Mode::ReadWrite); } api = API_UNKNOWN; return true; }
Call *Parser::parse_leave(Mode mode) { unsigned call_no = read_uint(); Call *call = NULL; for (CallList::iterator it = calls.begin(); it != calls.end(); ++it) { if ((*it)->no == call_no) { call = *it; calls.erase(it); break; } } if (!call) { /* This might happen on random access, when an asynchronous call is stranded * between two frames. We won't return this call, but we still need to skip * over its data. */ const FunctionSig sig = {0, NULL, 0, NULL}; call = new Call(&sig, 0, 0); parse_call_details(call, SCAN); delete call; return NULL; } if (parse_call_details(call, mode)) { return call; } else { delete call; return NULL; } }
static void rd_monster(monster_type *m_ptr) { start_section_read("monster"); /* Hack -- wipe */ WIPE(m_ptr, monster_type); skip_value("name"); /* Read the monster race */ m_ptr->r_idx = read_int("r_idx"); /* Read the other information */ m_ptr->fy = read_int("fy"); m_ptr->fx = read_int("fx"); m_ptr->dun_depth = read_int("dun_depth"); m_ptr->hp = read_int("hp"); m_ptr->maxhp = read_int("maxhp"); m_ptr->csleep = read_int("csleep"); m_ptr->mspeed = read_int("mspeed"); m_ptr->energy = read_uint("energy"); m_ptr->stunned = read_int("stunned"); m_ptr->confused = read_int("confused"); m_ptr->monfear = read_int("afraid"); end_section_read("monster"); }
/* * Old enum signatures would cover a single name/value only: * * enum_sig = id name value * | id */ EnumSig *Parser::parse_old_enum_sig() { size_t id = read_uint(); EnumSigState *sig = lookup(enums, id); if (!sig) { /* parse the signature */ sig = new EnumSigState; sig->id = id; sig->num_values = 1; EnumValue *values = new EnumValue[sig->num_values]; values->name = read_string(); values->value = read_sint(); sig->values = values; sig->offset = file->currentOffset(); enums[id] = sig; } else if (file->currentOffset() < sig->offset) { /* skip over the signature */ skip_string(); /*name*/ scan_value(); } assert(sig); return sig; }
Value *Parser::parse_bitmask() { BitmaskSig *sig = parse_bitmask_sig(); unsigned long long value = read_uint(); return new Bitmask(sig, value); }
/* * For the time being, a signed int is encoded as any other value, but we here parse * it without the extra baggage of the Value class. */ signed long long Parser::read_sint(void) { int c; c = read_byte(); switch (c) { case trace::TYPE_SINT: return -read_uint(); case trace::TYPE_UINT: return read_uint(); default: std::cerr << "error: unexpected type " << c << "\n"; exit(1); case -1: return 0; } }
/* Test writing single values of various types to board's global memory. * The test passes if we read back what we wrote. */ void test_small_writes (ssize_t f) { unsigned char uc; unsigned short us; unsigned int ui; unsigned long int uli; write_uchar (f, 0, 0, 19); uc = read_uchar (f, 0, 0); assert (uc == 19); write_ushort (f, 0, 0, 13); us = read_ushort(f, 0, 0); assert (us == 13); write_ulong (f, 0, 0, 0x3037383633352030); uli = read_ulong (f, 0, 0); assert (uli == 0x3037383633352030); write_uint (f, 0, 0, 18987983); ui = read_uint (f, 0, 0); assert (ui == 18987983); printf ("test_small_writes PASSED\n"); }
bool Model::load(std::istream & ifs) { char chunk[16]; ifs.read(chunk, 16); if (!strcmp(chunk, SEGMENTOR_MODEL_FULL)) { full = true; } else if (!strcmp(chunk, SEGMENTOR_MODEL) || !strcmp(chunk, SEGMENTOR_MODEL_MINIMAL)) { full = false; } else { return false; } if (full) { ifs.read(reinterpret_cast<char *>(&end_time), sizeof(int)); } else { end_time = 0; } unsigned labels_offset = read_uint(ifs); unsigned lexicon_offset = read_uint(ifs); unsigned feature_offset = read_uint(ifs); unsigned parameter_offset = read_uint(ifs); ifs.seekg(labels_offset); if (!labels.load(ifs)) { return false; } ifs.seekg(lexicon_offset); if (!internal_lexicon.load(ifs)) { return false; } ifs.seekg(feature_offset); if (!space.load(labels.size(), ifs)) { return false; } ifs.seekg(parameter_offset); if (!param.load(ifs, full)) { return false; } return true; }
void Parser::parse_arg(Call *call) { unsigned index = read_uint(); Value *value = parse_value(); if (index >= call->args.size()) { call->args.resize(index + 1); } call->args[index] = value; }
static void rd_wild(int n) { wilderness_type *w_ptr = &wild_info[-n]; /* the flags */ w_ptr->flags = read_uint("flags"); }
STATIC qstr load_qstr(mp_reader_t *reader) { size_t len = read_uint(reader); char *str = m_new(char, len); read_bytes(reader, (byte*)str, len); qstr qst = qstr_from_strn(str, len); m_del(char, str, len); return qst; }
Value *Parser::parse_array(void) { size_t len = read_uint(); Array *array = new Array(len); for (size_t i = 0; i < len; ++i) { array->values[i] = parse_value(); } return array; }
Value *Parser::parse_blob(void) { size_t size = read_uint(); Blob *blob = new Blob(size); if (size) { file->read(blob->buf, (unsigned)size); } return blob; }
/* read a.b.c */ static long read_version(char **s) { long a, b, c; a = read_uint(s); b = read_dot_uint(s); c = read_dot_uint(s); return PARI_VERSION(a,b,c); }
bool Parser::parse_call_backtrace(Call *call, Mode mode) { unsigned num_frames = read_uint(); Backtrace* backtrace = new Backtrace(num_frames); for (unsigned i = 0; i < num_frames; ++i) { (*backtrace)[i] = parse_backtrace_frame(mode); } call->backtrace = backtrace; return true; }
/* * Read the birth options */ static errr rd_birthoptions(player_type *p_ptr) { s32b i, id; u16b tmp16u, ind; if (!section_exists("options")) { /* Fine, no options */ return (0); } /* Begin */ start_section_read("options"); /* Read number */ tmp16u = read_int("num"); /* Read each record */ id = 0; for (i = 0; i < OPT_MAX; i++) { const option_type *opt_ptr = &option_info[i]; /* Real index is in the o_uid! */ ind = option_info[i].o_uid; if (opt_ptr->o_page != 1) continue; /* Next entry is what we expect */ if (value_exists(opt_ptr->o_text)) { /* Read it */ u32b val = read_uint(opt_ptr->o_text); /* Set it */ p_ptr->options[ind] = val ? TRUE : FALSE; } else { end_section_read("options"); /* Unexpected option */ return (29); } id++; /* Don't read anymore */ if (id >= tmp16u) break; } /* Done */ end_section_read("options"); /* Success */ return (0); }
void Package::from_bip(char*& cursor) { set_cluster(dataset.cluster(read_uint(cursor))); set_label(read_string(cursor)); for(int t=0; t < max_t; t++) { _versions[t]->set_package(dataset.package(id())); _versions[t]->from_bip(cursor); } }
boost::int32_t BitsReader::read_sint(unsigned short bitcount) { boost::int32_t value = boost::int32_t(read_uint(bitcount)); // Sign extend... if (value & (1 << (bitcount - 1))) value |= -1 << bitcount; return value; }
mmath_matrix* mnist_read_labels (const char *path) { FILE *f; mmath_matrix *r = NULL; unsigned i, rows; if ((f = fopen(path, "r"))) { if (read_uint(f) == (MAGIC_UNSIGNED_BYTE | 1)) { rows = read_uint(f); r = mmath_malloc(rows, 1, MMATH_ROW_MAJOR); for (i = 0; i < r->rows; ++i) { mmath_set(r, i, 0, (double)getc(f)); } } fclose(f); } return r; }
/* * For the time being, a signed int is encoded as any other value, but we here parse * it without the extra baggage of the Value class. */ signed long long Parser::read_sint(void) { int c; c = read_byte(); switch (c) { case trace::TYPE_SINT: return -(signed long long)read_uint(); case trace::TYPE_UINT: return read_uint(); default: { std::cerr << "error: unexpected type " << c << "\n"; File::Offset o = file->currentOffset(); std::cerr << "error: Current offset: " << o.chunk << ", " << o.offsetInChunk << "\n"; exit(1); } case -1: return 0; } }
const char * Parser::read_string(void) { size_t len = read_uint(); char * value = new char[len + 1]; if (len) { file->read(value, (unsigned)len); } value[len] = 0; #if TRACE_VERBOSE std::cerr << "\tSTRING \"" << value << "\"\n"; #endif return value; }
bool Parser::open(const char *filename) { file = gzopen(filename, "rb"); if (!file) { return false; } version = read_uint(); if (version > TRACE_VERSION) { std::cerr << "error: unsupported trace format version " << version << "\n"; return false; } return true; }
mmath_matrix* mnist_read_images (const char *path) { FILE *f; mmath_matrix *r = NULL; unsigned i, j, rows, cols; if ((f = fopen(path, "r"))) { if (read_uint(f) == (MAGIC_UNSIGNED_BYTE | 3)) { rows = read_uint(f); cols = read_uint(f) * read_uint(f); r = mmath_malloc(rows, cols, MMATH_ROW_MAJOR); for (i = 0; i < r->rows; ++i) { for (j = 0; j < r->cols; ++j) { mmath_set(r, i, j, (double)getc(f)); } } } fclose(f); } return r; }
int double_correlation_read_data_from_file(double_correlation* self, const char * filename, bool binary){ FILE* fp=0; fp=fopen(filename, "r"); if (!fp) { return 2; } for (unsigned int i=0; i<self->hierarchy_depth; i++) { for (unsigned int j=0; j<self->tau_lin+1; j++) { if (read_double(fp,self->A[i][j],self->dim_A,binary)) return 1; } } if (!self->autocorrelation){ for (unsigned int i=0; i<self->hierarchy_depth; i++) { for (unsigned int j=0; j<self->tau_lin+1; j++) { if (read_double(fp,self->B[i][j],self->dim_B,binary)) return 1; } } } for (unsigned int i=0; i<self->n_result; i++) { if (read_double(fp,self->result[i],self->dim_corr,binary))return 1; } if (read_uint(fp,self->n_sweeps,self->n_result ,binary))return 1; if (read_uint(fp,self->n_vals ,self->hierarchy_depth,binary))return 1; if (read_uint(fp,self->newest ,self->hierarchy_depth,binary))return 1; if (read_double(fp,self->A_accumulated_average ,self->dim_A,binary))return 1; if (read_double(fp,self->A_accumulated_variance,self->dim_A,binary))return 1; if (!self->autocorrelation){ if (read_double(fp,self->B_accumulated_average ,self->dim_B,binary))return 1; if (read_double(fp,self->B_accumulated_variance,self->dim_B,binary))return 1; } if (read_uint(fp,&(self->n_data),1,binary))return 1; if (read_uint(fp,&(self->t ),1,binary))return 1; if (read_double(fp,&(self->last_update),1,binary))return 1; fclose(fp); return 0; }