javacall_result bt_push_parse_url(const char *url, bt_port_t *port, bt_params_t *params) { int i; if (test_prefix(&url, "btl2cap://")) { port->protocol = BT_L2CAP; } else if (test_prefix(&url, "btspp://")) { port->protocol = BT_SPP; } else if (test_prefix(&url, "btgoep://")) { port->protocol = BT_GOEP; } else { return JAVACALL_FAIL; } if (!test_prefix(&url, "localhost:")) { return JAVACALL_FAIL; } for (i = 0; i < 16; i++) { int hex1, hex2; hex1 = get_hex(*url++); if (hex1 < 0) { return JAVACALL_FAIL; } hex2 = get_hex(*url++); if (hex2 < 0) { return JAVACALL_FAIL; } port->uuid[i] = hex1 << 4 | hex2; } if (params == NULL) { /* params parsing is not needed */ return JAVACALL_OK; } params->authenticate = JAVACALL_FALSE; params->authorize = JAVACALL_FALSE; params->encrypt = JAVACALL_FALSE; params->rmtu = DEFAULT_MTU; params->tmtu = -1; url = strchr(url, ';'); while (url != NULL) { if (test_prefix(&url, ";authenticate=")) { params->authenticate = read_bool(&url); } else if (test_prefix(&url, ";authorize=")) { params->authorize = read_bool(&url); } else if (test_prefix(&url, ";encrypt=")) { params->encrypt = read_bool(&url); } else if (test_prefix(&url, ";master=")) { params->master = read_bool(&url); } else if (test_prefix(&url, ";receiveMTU=")) { params->rmtu = read_short(&url); } else if (test_prefix(&url, ";transmitMTU=")) { params->tmtu = read_short(&url); } url = strchr(url + 1, ';'); } if (params->authorize || params->encrypt) { params->authenticate = JAVACALL_TRUE; } return JAVACALL_OK; }
void GameObjectMessage::read() { object_id_ = read_uint32(socket_); position_ = read_vector(socket_); object_type_ = read_char(socket_); read_object_points(); alive_ = read_bool(socket_); }
button pcb_button(const JSON::node& root, const JSON::pointer& ptr) { auto pshadow = ptr.field("shadow"); auto pname = ptr.field("name"); auto psymbol = ptr.field("symbol"); auto pmacro = ptr.field("macro"); auto pmovie = ptr.field("movie"); struct button ret; ret.type = button::TYPE_BUTTON; ret.name = read_str(root, pname); std::u32string symbol = (root.type_of(psymbol) != JSON::none) ? read_str32(root, psymbol) : utf8::to32(ret.name); if(symbol.length() != 1) (stringfmt() << "Symbol at '" << ptr << "' must be 1 codepoint").throwex(); ret.symbol = symbol[0]; ret.rmin = 0; ret.rmax = 0; ret.centers = false; ret.macro = (root.type_of(pmacro) != JSON::none) ? read_str(root, pmacro) : utf8::to8(symbol); std::string movie = (root.type_of(pmovie) != JSON::none) ? read_str(root, pmovie) : utf8::to8(symbol); if(movie.length() != 1) (stringfmt() << "Movie at '" << ptr << "' must be 1 character").throwex(); ret.msymbol = movie[0]; ret.shadow = (root.type_of(pshadow) != JSON::none) ? read_bool(root, pshadow) : false; return ret; }
void add_rom(const char *prefix, FILE *file) { int i; t_rom *rom = malloc(sizeof(t_rom)); rom->prefix = prefix; // Load ROM file eat_comment(file); fscanf(file, "%d %d\n", &(rom->words_defined), &(rom->word_size)); rom->data = malloc(rom->words_defined * sizeof(t_value)); for (i = 0; i < rom->words_defined; i++) { eat_comment(file); if (fscanf(file, "/%lu", &(rom->data[i]))) { // ok, value is read } else if (fscanf(file, "x%lx", &(rom->data[i]))) { // ok, value is read } else { rom->data[i] = read_bool(file, NULL); } } rom->next = roms; roms = rom; }
int main (void) { printf ("Hello World\n"); OpenIniFile ("Test.Ini"); #ifdef INIFILE_TEST_READ_AND_WRITE write_string ("Test", "Name", "Value"); write_string ("Test", "Name", "OverWrittenValue"); write_string ("Test", "Port", "COM1"); write_string ("Test", "User", "James Brown jr."); write_string ("Configuration", "eDriver", "MBM2.VXD"); write_string ("Configuration", "Wrap", "LPT.VXD"); write_int ("IO-Port", "Com", 2); write_bool ("IO-Port", "IsValid", 0); write_double ("TheMoney", "TheMoney", 67892.00241); write_int ("Test" , "ToDelete", 1234); WriteIniFile ("Test.Ini"); printf ("Key ToDelete created. Check ini file. Any key to continue"); while (!kbhit()); OpenIniFile ("Test.ini"); delete_key ("Test" , "ToDelete"); WriteIniFile ("Test.ini"); #endif printf ("[Test] Name = %s\n", read_string ("Test", "Name", "NotFound")); printf ("[Test] Port = %s\n", read_string ("Test", "Port", "NotFound")); printf ("[Test] User = %s\n", read_string ("Test", "User", "NotFound")); printf ("[Configuration] eDriver = %s\n", read_string ("Configuration", "eDriver", "NotFound")); printf ("[Configuration] Wrap = %s\n", read_string ("Configuration", "Wrap", "NotFound")); printf ("[IO-Port] Com = %d\n", read_int ("IO-Port", "Com", 0)); printf ("[IO-Port] IsValid = %d\n", read_bool ("IO-Port", "IsValid", 0)); printf ("[TheMoney] TheMoney = %1.10lf\n", read_double ("TheMoney", "TheMoney", 111)); CloseIniFile (); return 0; }
// // read a boolean value from the storage set PyObject *PyStorageSet_readBool (PyObject *self, PyObject *args) { char *key = PyStorageSet_readParseKey(args); if(key != NULL) { bool val = read_bool(((PyStorageSet *)self)->set, key); return Py_BuildValue("O", (val ? Py_True : Py_False)); } else return NULL; }
button pcb_axis(const JSON::node& root, const JSON::pointer& ptr, const std::string& type) { auto pshadow = ptr.field("shadow"); auto pname = ptr.field("name"); auto pcenters = ptr.field("centers"); struct button ret; if(type == "axis") ret.type = button::TYPE_AXIS; if(type == "raxis") ret.type = button::TYPE_RAXIS; if(type == "taxis") ret.type = button::TYPE_TAXIS; if(type == "lightgun") ret.type = button::TYPE_LIGHTGUN; ret.name = read_str(root, pname); ret.symbol = U'\0'; ret.shadow = (root.type_of(pshadow) != JSON::none) ? read_bool(root, pshadow) : false; ret.rmin = ret.shadow ? -32768 : read_int(root, ptr.field("min")); ret.rmax = ret.shadow ? 32767 : read_int(root, ptr.field("max")); ret.centers = (root.type_of(pcenters) != JSON::none) ? read_bool(root, pcenters) : false; ret.macro = ""; ret.msymbol = '\0'; return ret; }
void ReadFileWithLua::read(){ bool status; // Extract data from LUA parameterfile sim._aexp = sim._aexp_ini = read_double("aexp_ini", &status, true); sim._BoxSize = read_double("BoxSize", &status, true); sim._courant_fac = read_double("courant_fac", &status, true); sim._omega_m = read_double("omega_m", &status, true); sim._ngrid = read_int ("ngrid", &status, true); sim._NGS_FINE = read_int ("NGS_FINE", &status, false); if(!status) sim._NGS_FINE = 5; sim._NGS_COARSE = read_int ("NGS_COARSE", &status, false); if(!status) sim._NGS_COARSE = 5; sim._EPS_CONVERGE = read_int ("EPS_CONVERGE", &status, false); if(!status) sim._EPS_CONVERGE= 1e-5; sim._static = read_bool ("static", &status, true); if(!status) sim._static = false; sim._verboseMG = read_bool ("verboseMG", &status, true); sim._analytic_matter_density = read_bool ("verboseMG", &status, true); sim._modified_gravity = read_bool ("modified_gravity", &status, false); if(!status) sim._modified_gravity = false; #if defined(FOFR) sim._nfofr = read_double("nfofr", &status, true); sim._fofr0 = read_double("fofr0", &status, true); #elif defined(SYMMETRON) sim._assb_symm = read_double("assb_symm", &status, true); sim._beta_symm = read_double("beta_symm", &status, true); sim._lambda_symm = read_double("lambda_symm", &status, true); #endif sim._particlefile = read_string("particlefile", &status, false); // If no particlefile assume static-mode if(!status) sim._static = sim._analytic_matter_density = true; // Derived parameters and checks sim._omega_lambda = 1.0 - sim._omega_m; sim._ngrid_tot = pow3( sim._ngrid ); assert( sim._ngrid == (1 << int(log2(sim._ngrid))) ); if(sim._analytic_matter_density) sim._npart = 0; }
button pcb_null(const JSON::node& root, const JSON::pointer& ptr) { auto pshadow = ptr.field("shadow"); struct button ret; ret.type = button::TYPE_NULL; ret.name = ""; ret.symbol = U'\0'; ret.rmin = 0; ret.rmax = 0; ret.centers = false; ret.macro = ""; ret.msymbol = '\0'; ret.shadow = (root.type_of(pshadow) != JSON::none) ? read_bool(root, pshadow) : false; return ret; }
HOT_INLINE static void read_boolList( int *size, hot_bool_t **bp ) { int i; hot_uint32 tmp ; assert(size); assert(bp); read_int(&tmp) ; *size = tmp ; *bp = alloc_bool_array(ch_bool_array, *size); for (i = 0; i < *size; i++) read_bool (*bp + i); }
void KfmServIpc::parse_selectRootIcons( char *_data, int _len ) { int pos = 0; // Parsing int int _x; _x = read_int( _data, pos, _len ); // Parsing int int _y; _y = read_int( _data, pos, _len ); // Parsing int int _w; _w = read_int( _data, pos, _len ); // Parsing int int _h; _h = read_int( _data, pos, _len ); // Parsing bool bool _add; _add = read_bool( _data, pos, _len ); // Calling function emit selectRootIcons( _x, _y, _w, _h, _add ); }
int main(int argc, char* argv[]) { // Print help if necessary bool help = read_bool(argc, argv, "--help", false); if ((argc < 2) || (help)) { usage(argv); return 0; } // Use parameters struct for passing parameters to kernels efficiently parameters prm; // Parse inputs prm.matDims[0] = read_int(argc, argv, "--m", 2); prm.matDims[1] = read_int(argc, argv, "--k", 2); prm.matDims[2] = read_int(argc, argv, "--n", 2); prm.rank = read_int(argc, argv, "--rank", 7); prm.method = read_string(argc, argv, "--method", (char *)"als"); int maxIters = read_int(argc, argv, "--maxiters", 1000); int maxSecs = read_int(argc, argv, "--maxsecs", 1000); double tol = read_double(argc, argv, "--tol", 1e-8); int printItn = read_int(argc, argv, "--printitn", 0); double printTol = read_double(argc, argv, "--printtol", 1.0); int seed = read_int(argc, argv, "--seed", 0); int numSeeds = read_int(argc, argv, "--numseeds", 1); bool verbose = read_bool(argc, argv, "--verbose", false); prm.rnd_maxVal = read_double(argc,argv,"--maxval",1.0); prm.rnd_pwrOfTwo = read_int(argc,argv,"--pwrof2",0); bool roundFinal = read_bool(argc, argv, "--rndfin",false); prm.alpha = read_double(argc,argv, "--alpha", 0.1); int M = read_int(argc,argv, "--M", 0); if (M) { prm.M[0] = M; prm.M[1] = M; prm.M[2] = M; } else { prm.M[0] = read_int(argc, argv, "--M0", -1); prm.M[1] = read_int(argc, argv, "--M1", -1); prm.M[2] = read_int(argc, argv, "--M2", -1); } char * infile = read_string(argc, argv, "--input", NULL); char * outfile = read_string(argc, argv, "--output", NULL); if (verbose) { setbuf(stdout, NULL); printf("\n\n---------------------------------------------------------\n"); printf("PARAMETERS\n"); printf("dimensions = %d %d %d\n",prm.matDims[0],prm.matDims[1],prm.matDims[2]); printf("rank = %d\n",prm.rank); printf("method = %s\n",prm.method); if (infile) printf("input = %s\n",infile); else { if (numSeeds == 1) printf("input = seed %d\n",seed); else printf("inputs = seeds %d-%d\n",seed,seed+numSeeds-1); } if (outfile) printf("output = %s\n",outfile); else printf("output = none\n"); if (!strcmp(prm.method,"als")) { printf("tol = %1.2e\n",tol); printf("alpha = %1.2e\n",prm.alpha); printf("maval = %1.2e\n",prm.rnd_maxVal); printf("M's = (%d,%d,%d)\n",prm.M[0],prm.M[1],prm.M[2]); printf("maxiters = %d\n",maxIters); printf("maxsecs = %d\n",maxSecs); printf("printitn = %d\n",printItn); printf("printtol = %1.2e\n",printTol); } printf("---------------------------------------------------------\n"); } // Initialize other variables int i, j, k, numIters, mkn, tidx[3]; double err, errOld, errChange = 0.0, start_als, start_search, elapsed, threshold; // Compute tensor dimensions prm.dims[0] = prm.matDims[0]*prm.matDims[1]; prm.dims[1] = prm.matDims[1]*prm.matDims[2]; prm.dims[2] = prm.matDims[0]*prm.matDims[2]; // Compute tensor's nnz, total number of entries, and Frobenius norm mkn = prm.matDims[0]*prm.matDims[1]*prm.matDims[2]; prm.mkn2 = mkn*mkn; prm.xNorm = sqrt(mkn); // Compute number of columns in matricized tensors for (i = 0; i < 3; i++) prm.mtCols[i] = prm.mkn2 / prm.dims[i]; // Construct three matricizations of matmul tensor prm.X = (double**) malloc( 3 * sizeof(double*) ); for (i = 0; i < 3; i++) prm.X[i] = (double*) calloc( prm.mkn2, sizeof(double) ); for (int mm = 0; mm < prm.matDims[0]; mm++) for (int kk = 0; kk < prm.matDims[1]; kk++) for (int nn = 0; nn < prm.matDims[2]; nn++) { tidx[0] = mm + kk*prm.matDims[0]; tidx[1] = kk + nn*prm.matDims[1]; tidx[2] = mm + nn*prm.matDims[0]; prm.X[0][tidx[0]+prm.dims[0]*(tidx[1]+prm.dims[1]*tidx[2])] = 1; prm.X[1][tidx[1]+prm.dims[1]*(tidx[0]+prm.dims[0]*tidx[2])] = 1; prm.X[2][tidx[2]+prm.dims[2]*(tidx[0]+prm.dims[0]*tidx[1])] = 1; } // Allocate factor weights and matrices: working, initial, and model prm.lambda = (double*) malloc( prm.rank * sizeof(double) ); prm.U = (double**) malloc( 3 * sizeof(double*) ); double** U0 = (double**) malloc( 3 * sizeof(double*) ); prm.model = (double**) malloc( 3 * sizeof(double*) ); for (i = 0; i < 3; i++) { prm.U[i] = (double*) calloc( prm.mkn2, sizeof(double) ); U0[i] = (double*) calloc( prm.dims[i]*prm.rank, sizeof(double) ); prm.model[i] = (double*) calloc( prm.dims[i]*prm.rank, sizeof(double) ); } // Allocate coefficient matrix within ALS (Khatri-Rao product) int maxMatDim = prm.matDims[0]; if (maxMatDim < prm.matDims[1]) maxMatDim = prm.matDims[1]; if (maxMatDim < prm.matDims[2]) maxMatDim = prm.matDims[2]; prm.A = (double*) malloc( maxMatDim*mkn*prm.rank * sizeof(double) ); // Allocate workspaces prm.tau = (double*) malloc( mkn * sizeof(double) ); prm.lwork = maxMatDim*mkn*prm.rank; prm.work = (double*) malloc( prm.lwork * sizeof(double) ); prm.iwork = (int*) malloc( prm.mkn2 * sizeof(int) ); // Allocate matrices for normal equations int maxDim = prm.dims[0]; if (maxDim < prm.dims[1]) maxDim = prm.dims[1]; if (maxDim < prm.dims[2]) maxDim = prm.dims[2]; prm.NE_coeff = (double*) malloc( prm.rank*prm.rank * sizeof(double) ); prm.NE_rhs = (double*) malloc( maxDim*prm.rank * sizeof(double) ); prm.residual = (double*) malloc( prm.mkn2 * sizeof(double) ); //-------------------------------------------------- // Search Loop //-------------------------------------------------- int mySeed = seed, numGoodSeeds = 0, statusCnt = 0, status = 1; start_search = wall_time(); for (int seed_cnt = 0; seed_cnt < numSeeds; ++seed_cnt) { // Set starting point from random seed (match Matlab Tensor Toolbox) RandomMT cRMT(mySeed); for (i = 0; i < 3; i++) for (j = 0; j < prm.dims[i]; j++) for (k = 0; k < prm.rank; k++) U0[i][j+k*prm.dims[i]] = cRMT.genMatlabMT(); for (i = 0; i < prm.rank; i++) prm.lambda[i] = 1.0; // Copy starting point for (i = 0; i < 3; i++) cblas_dcopy(prm.dims[i]*prm.rank,U0[i],1,prm.U[i],1); // read from file if input is given if( infile ) read_input( infile, prm ); if (verbose) { printf("\nSTARTING POINT...\n"); for (i = 0; i < 3; i++) { printf("Factor matrix %d:\n",i); print_matrix(prm.U[i],prm.dims[i],prm.rank,prm.dims[i]); } printf("\n"); } //-------------------------------------------------- // Main ALS Loop //-------------------------------------------------- start_als = wall_time(); err = 1.0; threshold = 1e-4; for (numIters = 0; numIters < maxIters && (wall_time()-start_als) < maxSecs; numIters++) { errOld = err; if (!strcmp(prm.method,"als")) { // Perform an iteration of ALS using NE with Smirnov's penalty term err = als( prm ); } else if (!strcmp(prm.method,"sparsify")) { // print stats before sparsifying printf("Old residual: %1.2e\n",compute_residual(prm,2,true)); printf("Old nnz (larger than %1.1e): %d %d %d\n", threshold, nnz(prm.U[0],prm.dims[0]*prm.rank,threshold), nnz(prm.U[1],prm.dims[1]*prm.rank,threshold), nnz(prm.U[2],prm.dims[2]*prm.rank,threshold) ); // sparsify and return printf("\nSparsifying...\n\n"); sparsify( prm ); numIters = maxIters; // print stats after sparsifying printf("New residual: %1.2e\n",compute_residual(prm,2,true)); printf("New nnz (larger than %1.1e): %d %d %d\n", threshold, nnz(prm.U[0],prm.dims[0]*prm.rank,threshold), nnz(prm.U[1],prm.dims[1]*prm.rank,threshold), nnz(prm.U[2],prm.dims[2]*prm.rank,threshold) ); } else if (!strcmp(prm.method,"round")) { // print stats before rounding printf("Old residual: %1.2e\n",compute_residual(prm,2,true)); printf("Old nnz (larger than %1.1e): %d %d %d\n", threshold, nnz(prm.U[0],prm.dims[0]*prm.rank,threshold), nnz(prm.U[1],prm.dims[1]*prm.rank,threshold), nnz(prm.U[2],prm.dims[2]*prm.rank,threshold) ); // round and return for (i = 0; i < 3; i++) { capping(prm.U[i],prm.dims[i]*prm.rank,prm.rnd_maxVal); rounding(prm.U[i],prm.dims[i]*prm.rank,prm.rnd_pwrOfTwo); } numIters = maxIters; // print stats after rounding printf("New residual: %1.2e\n",compute_residual(prm,2,true)); printf("New nnz (larger than %1.1e): %d %d %d\n", threshold, nnz(prm.U[0],prm.dims[0]*prm.rank,threshold), nnz(prm.U[1],prm.dims[1]*prm.rank,threshold), nnz(prm.U[2],prm.dims[2]*prm.rank,threshold) ); } else die("Invalid method\n"); // Compute change in relative residual norm errChange = fabs(err - errOld); // Print info at current iteration if ((printItn > 0) && (((numIters + 1) % printItn) == 0)) { // print info printf ("Iter %d: residual = %1.5e change = %1.5e\n", numIters + 1, err, errChange); } // Check for convergence if ( numIters > 0 && errChange < tol ) break; } // If rounding, round final solution and re-compute residual if(roundFinal) { // normalize columns in A and B factors, put arbitrary weights into C normalize_model( prm, 2 ); // cap large values and round to nearest power of 2 for (i = 0; i < 3; i++) { capping(prm.U[i],prm.dims[i]*prm.rank,prm.rnd_maxVal); rounding(prm.U[i],prm.dims[i]*prm.rank,prm.rnd_pwrOfTwo); } err = compute_residual(prm,0,true); } // Print status if searching over many seeds statusCnt++; if (numSeeds > 1000 && statusCnt == numSeeds/10) { printf("...%d%% complete...\n",10*status); status++; statusCnt = 0; } // Print final info elapsed = wall_time() - start_als; if ((printItn > 0 || verbose) && !strcmp(prm.method,"als")) { if (infile) printf("\nInput %s ",infile); else printf("\nInitial seed %d ",mySeed); printf("achieved residual %1.3e in %d iterations and %1.3e seconds\n \t final residual change: %1.3e\n \t average time per iteration: %1.3e s\n", err, numIters, elapsed, errChange, elapsed/numIters); } if (verbose) { printf("\nSOLUTION...\n"); for (i = 0; i < 3; i++) { printf("Factor matrix %d:\n",i); if (roundFinal || !strcmp(prm.method,"round")) print_int_matrix(prm.U[i], prm.dims[i], prm.rank, prm.dims[i], prm.rnd_pwrOfTwo); else print_matrix(prm.U[i],prm.dims[i],prm.rank,prm.dims[i]); } if (err < printTol) numGoodSeeds++; } else if (err < printTol) { numGoodSeeds++; printf("\n\n***************************************\n"); if (infile) printf("Input %s: ",infile); else printf("Initial seed %d: ",mySeed); printf("after %d iterations, achieved residual %1.3e with final residual change of %1.3e\n", numIters, err, errChange); if (roundFinal) { for (i = 0; i < 3; i++) { printf("Factor matrix %d:\n",i); print_int_matrix(prm.U[i], prm.dims[i], prm.rank, prm.dims[i], prm.rnd_pwrOfTwo); } int count = 0; for (i = 0; i < 3; i++) count += nnz(prm.U[i],prm.dims[i]*prm.rank); printf("\ttotal nnz in solution: %d\n",count); printf("\tnaive adds/subs: %d\n",count - prm.dims[2] - 2*prm.rank); } printf("***************************************\n\n\n"); } // write to output if( outfile ) write_output( outfile, prm ); mySeed++; } // Final report of processor statistics elapsed = wall_time()-start_search; // Print stats if (!strcmp(prm.method,"als")) { printf("\n\n------------------------------------------------------------\n"); printf("Time elapsed: \t%1.1e\tseconds\n",elapsed); printf("Total number of seeds tried: \t%d\n",numSeeds); printf("Total number of good seeds: \t%d",numGoodSeeds); printf("\t(residual < %2.1e)\n",printTol); printf("------------------------------------------------------------\n"); } // free allocated memory for (i = 0; i < 3; i++) { free( prm.X[i] ); free( prm.U[i] ); free( U0[i] ); free( prm.model[i] ); } free( prm.X ); free( prm.U ); free( U0 ); free( prm.model ); free( prm.lambda ); free( prm.A ); free( prm.NE_coeff ); free( prm.NE_rhs ); free( prm.residual ); free( prm.tau ); free( prm.work ); free( prm.iwork ); return 0; }
bool VC2Decoder::parseSeqHeader(char *_idata) { #define EXPECT_VAL(N) { uint32_t d = read_uint(idata, bits);\ if (d != (N)) {\ writelog(LOG_WARN, "%s:%d: Expected %d, got %d when parsing sequence header\n", __FILE__, __LINE__, (N), d); \ }\ } uint8_t *idata = (uint8_t *)_idata; if ((!mSeqHeaderEncoded) || mSeqHeaderEncodedLength == 0 || (memcmp(mSeqHeaderEncoded, idata, mSeqHeaderEncodedLength) != 0)) { writelog(LOG_INFO, "Processing Sequence Header"); int bits = 7; EXPECT_VAL(2); EXPECT_VAL(0); EXPECT_VAL(3); int level = read_uint(idata, bits); if (level != 3 && level != 6) { writelog(LOG_WARN, "%s:%d: Expected 3 or 6, got %d when reading level\n", __FILE__, __LINE__, level); } VC2DecoderParamsInternal params; params = mParams; params.video_format.base_video_format = read_uint(idata, bits); params.video_format.custom_dimensions_flag = read_bool(idata, bits); if (params.video_format.custom_dimensions_flag) { params.video_format.frame_width = read_uint(idata, bits); params.video_format.frame_height = read_uint(idata, bits); } params.video_format.custom_color_diff_format_flag = read_bool(idata, bits); if (params.video_format.custom_color_diff_format_flag) { params.video_format.color_diff_format_index = read_uint(idata, bits); } params.video_format.custom_scan_format_flag = read_bool(idata, bits); if (params.video_format.custom_scan_format_flag) { params.video_format.source_sampling = read_uint(idata, bits); } params.video_format.custom_frame_rate_flag = read_bool(idata, bits); if (params.video_format.custom_frame_rate_flag) { params.video_format.frame_rate_index = read_uint(idata, bits); if (params.video_format.frame_rate_index == 0) { params.video_format.frame_rate_numer = read_uint(idata, bits); params.video_format.frame_rate_denom = read_uint(idata, bits); } } params.video_format.custom_pixel_aspect_ratio_flag = read_bool(idata, bits); if (params.video_format.custom_pixel_aspect_ratio_flag) { params.video_format.pixel_aspect_ratio_index = read_uint(idata, bits); if (params.video_format.pixel_aspect_ratio_index == 0) { params.video_format.pixel_aspect_ratio_numer = read_uint(idata, bits); params.video_format.pixel_aspect_ratio_denom = read_uint(idata, bits); } } params.video_format.custom_clean_area_flag = read_bool(idata, bits); if (params.video_format.custom_clean_area_flag) { params.video_format.clean_width = read_uint(idata, bits); params.video_format.clean_height = read_uint(idata, bits); params.video_format.left_offset = read_uint(idata, bits); params.video_format.top_offset = read_uint(idata, bits); } params.video_format.custom_signal_range_flag = read_bool(idata, bits); if (params.video_format.custom_signal_range_flag) { params.video_format.signal_range_index = read_uint(idata, bits); if (params.video_format.signal_range_index == 0) { params.video_format.luma_offset = read_uint(idata, bits); params.video_format.luma_excursion = read_uint(idata, bits); params.video_format.color_diff_offset = read_uint(idata, bits); params.video_format.color_diff_excursion = read_uint(idata, bits); } } params.video_format.custom_color_spec_flag = read_bool(idata, bits); if (params.video_format.custom_color_spec_flag) { params.video_format.color_spec_index = read_uint(idata, bits); if (params.video_format.color_spec_index == 0) { params.video_format.custom_color_primaries_flag = read_bool(idata, bits); if (params.video_format.custom_color_primaries_flag) { params.video_format.color_primaries_index = read_uint(idata, bits); } params.video_format.custom_color_matrix_flag = read_bool(idata, bits); if (params.video_format.custom_color_matrix_flag) { params.video_format.color_matrix_index = read_uint(idata, bits); } params.video_format.custom_transfer_function_flag = read_bool(idata, bits); if (params.video_format.custom_transfer_function_flag) { params.video_format.transfer_function_index = read_uint(idata, bits); } } } uint32_t picture_coding_mode = read_uint(idata, bits); mInterlaced = (picture_coding_mode != 0); mParams = params; mConfigured = false; setVideoFormat(mParams); byte_align(idata, bits); if (mSeqHeaderEncoded) delete[] mSeqHeaderEncoded; mSeqHeaderEncodedLength = idata - (uint8_t *)_idata; mSeqHeaderEncoded = new uint8_t[mSeqHeaderEncodedLength]; memcpy(mSeqHeaderEncoded, _idata, mSeqHeaderEncodedLength); mSequenceInfo.video_format = params.video_format; mSequenceInfo.picture_coding_mode = picture_coding_mode; mSequenceInfo.sequence_headers_seen++; return true; } return false; }
HOT_INLINE static void cb_View( hot_contextID_t id, unsigned *cs ) { hot_uint32 tmp ; hot_view_state_t vs; hot_context_t s; void *env; hot_ens_AcceptedView_cback accepted_view; unsigned ncl; trace("VIEW"); read_string_prealloc(vs.version); trace("\t version: %s", vs.version); read_string_prealloc(vs.group_name); trace("\t group_name: %s", vs.group_name); read_endpList(&vs.nmembers, &vs.members); trace("\t nmembers: %d", vs.nmembers); { unsigned i; for (i = 0; i < vs.nmembers; i++) trace("\t\t member[%d] = %s", i, vs.members[i].name); } read_int(&tmp) ; vs.rank = tmp ; trace("\t rank: %d", vs.rank); read_string_prealloc(vs.protocol); trace("\t protocol: %s", vs.protocol); read_bool(&vs.groupd); trace("\t groupd: %d", vs.groupd); read_int(&tmp); vs.view_id.ltime = tmp ; trace("\t view_id.ltime: %d", vs.view_id.ltime); read_endpID(&vs.view_id.coord); trace("\t view_id.coord: %s", vs.view_id.coord.name); read_string_prealloc(vs.params); trace("\t params: %s", vs.params); read_bool(&vs.xfer_view); trace("\t xfer_view: %d", vs.xfer_view); read_bool(&vs.primary); trace("\t primary: %d", vs.primary); read_boolList(&ncl, &vs.clients); assert(ncl == vs.nmembers); read_string_prealloc(vs.key); trace("\t key: %s", vs.key); begin_critical(); { s = lookup_context(id); env = s->env; accepted_view = s->conf.accepted_view; /* The group is unblocked now. */ s->blocked = 0; } end_critical(); if (s->view) { assert(s->nmembers > 0) ; release_endpt_array(ch_endpt_array, s->view, s->nmembers) ; } s->nmembers = vs.nmembers ; assert(s->nmembers > 0) ; s->view = alloc_endpt_array(ch_endpt_array, s->nmembers) ; memcpy(s->view,vs.members,s->nmembers * sizeof(*vs.members)) ; if (accepted_view != NULL) { (*accepted_view)(s, env, &vs); } begin_critical(); { if (vs.members != NULL) { release_endpt_array(ch_endpt_array, vs.members, vs.nmembers) ; } if (vs.clients != NULL) { release_bool_array(ch_bool_array, vs.clients, vs.nmembers) ; } s->joining = 0 ; } end_critical(); }
/* Allocate an entry from POOL and read it from [*BUF, END). The buffer may be modified in place while parsing. Return the new entry in *NEW_ENTRY. Advance *BUF to point at the end of the entry record. The entries file format should be provided in ENTRIES_FORMAT. */ static svn_error_t * read_entry(svn_wc_entry_t **new_entry, char **buf, const char *end, int entries_format, apr_pool_t *pool) { svn_wc_entry_t *entry = alloc_entry(pool); const char *name; #define MAYBE_DONE if (**buf == '\f') goto done /* Find the name and set up the entry under that name. */ SVN_ERR(read_path(&name, buf, end, pool)); entry->name = name ? name : SVN_WC_ENTRY_THIS_DIR; /* Set up kind. */ { const char *kindstr; SVN_ERR(read_val(&kindstr, buf, end)); if (kindstr) { if (strcmp(kindstr, ENTRIES_VALUE_FILE) == 0) entry->kind = svn_node_file; else if (strcmp(kindstr, ENTRIES_VALUE_DIR) == 0) entry->kind = svn_node_dir; else return svn_error_createf (SVN_ERR_NODE_UNKNOWN_KIND, NULL, _("Entry '%s' has invalid node kind"), (name ? name : SVN_WC_ENTRY_THIS_DIR)); } else entry->kind = svn_node_none; } MAYBE_DONE; /* Attempt to set revision (resolve_to_defaults may do it later, too) */ SVN_ERR(read_revnum(&entry->revision, buf, end, pool)); MAYBE_DONE; /* Attempt to set up url path (again, see resolve_to_defaults). */ SVN_ERR(read_url(&entry->url, buf, end, entries_format, pool)); MAYBE_DONE; /* Set up repository root. Make sure it is a prefix of url. */ SVN_ERR(read_url(&entry->repos, buf, end, entries_format, pool)); if (entry->repos && entry->url && ! svn_uri__is_ancestor(entry->repos, entry->url)) return svn_error_createf(SVN_ERR_WC_CORRUPT, NULL, _("Entry for '%s' has invalid repository " "root"), name ? name : SVN_WC_ENTRY_THIS_DIR); MAYBE_DONE; /* Look for a schedule attribute on this entry. */ { const char *schedulestr; SVN_ERR(read_val(&schedulestr, buf, end)); entry->schedule = svn_wc_schedule_normal; if (schedulestr) { if (strcmp(schedulestr, ENTRIES_VALUE_ADD) == 0) entry->schedule = svn_wc_schedule_add; else if (strcmp(schedulestr, ENTRIES_VALUE_DELETE) == 0) entry->schedule = svn_wc_schedule_delete; else if (strcmp(schedulestr, ENTRIES_VALUE_REPLACE) == 0) entry->schedule = svn_wc_schedule_replace; else return svn_error_createf( SVN_ERR_ENTRY_ATTRIBUTE_INVALID, NULL, _("Entry '%s' has invalid 'schedule' value"), name ? name : SVN_WC_ENTRY_THIS_DIR); } } MAYBE_DONE; /* Attempt to set up text timestamp. */ SVN_ERR(read_time(&entry->text_time, buf, end, pool)); MAYBE_DONE; /* Checksum. */ SVN_ERR(read_str(&entry->checksum, buf, end, pool)); MAYBE_DONE; /* Setup last-committed values. */ SVN_ERR(read_time(&entry->cmt_date, buf, end, pool)); MAYBE_DONE; SVN_ERR(read_revnum(&entry->cmt_rev, buf, end, pool)); MAYBE_DONE; SVN_ERR(read_str(&entry->cmt_author, buf, end, pool)); MAYBE_DONE; /* has-props, has-prop-mods, cachable-props, present-props are all deprecated. Read any values that may be in the 'entries' file, but discard them, and just put default values into the entry. */ { const char *unused_value; /* has-props flag. */ SVN_ERR(read_val(&unused_value, buf, end)); entry->has_props = FALSE; MAYBE_DONE; /* has-prop-mods flag. */ SVN_ERR(read_val(&unused_value, buf, end)); entry->has_prop_mods = FALSE; MAYBE_DONE; /* Use the empty string for cachable_props, indicating that we no longer attempt to cache any properties. An empty string for present_props means that no cachable props are present. */ /* cachable-props string. */ SVN_ERR(read_val(&unused_value, buf, end)); entry->cachable_props = ""; MAYBE_DONE; /* present-props string. */ SVN_ERR(read_val(&unused_value, buf, end)); entry->present_props = ""; MAYBE_DONE; } /* Is this entry in a state of mental torment (conflict)? */ { SVN_ERR(read_path(&entry->prejfile, buf, end, pool)); MAYBE_DONE; SVN_ERR(read_path(&entry->conflict_old, buf, end, pool)); MAYBE_DONE; SVN_ERR(read_path(&entry->conflict_new, buf, end, pool)); MAYBE_DONE; SVN_ERR(read_path(&entry->conflict_wrk, buf, end, pool)); MAYBE_DONE; } /* Is this entry copied? */ SVN_ERR(read_bool(&entry->copied, ENTRIES_BOOL_COPIED, buf, end)); MAYBE_DONE; SVN_ERR(read_url(&entry->copyfrom_url, buf, end, entries_format, pool)); MAYBE_DONE; SVN_ERR(read_revnum(&entry->copyfrom_rev, buf, end, pool)); MAYBE_DONE; /* Is this entry deleted? */ SVN_ERR(read_bool(&entry->deleted, ENTRIES_BOOL_DELETED, buf, end)); MAYBE_DONE; /* Is this entry absent? */ SVN_ERR(read_bool(&entry->absent, ENTRIES_BOOL_ABSENT, buf, end)); MAYBE_DONE; /* Is this entry incomplete? */ SVN_ERR(read_bool(&entry->incomplete, ENTRIES_BOOL_INCOMPLETE, buf, end)); MAYBE_DONE; /* UUID. */ SVN_ERR(read_str(&entry->uuid, buf, end, pool)); MAYBE_DONE; /* Lock token. */ SVN_ERR(read_str(&entry->lock_token, buf, end, pool)); MAYBE_DONE; /* Lock owner. */ SVN_ERR(read_str(&entry->lock_owner, buf, end, pool)); MAYBE_DONE; /* Lock comment. */ SVN_ERR(read_str(&entry->lock_comment, buf, end, pool)); MAYBE_DONE; /* Lock creation date. */ SVN_ERR(read_time(&entry->lock_creation_date, buf, end, pool)); MAYBE_DONE; /* Changelist. */ SVN_ERR(read_str(&entry->changelist, buf, end, pool)); MAYBE_DONE; /* Keep entry in working copy after deletion? */ SVN_ERR(read_bool(&entry->keep_local, ENTRIES_BOOL_KEEP_LOCAL, buf, end)); MAYBE_DONE; /* Translated size */ { const char *val; /* read_val() returns NULL on an empty (e.g. default) entry line, and entry has already been initialized accordingly already */ SVN_ERR(read_val(&val, buf, end)); if (val) entry->working_size = (apr_off_t)apr_strtoi64(val, NULL, 0); } MAYBE_DONE; /* Depth. */ { const char *result; SVN_ERR(read_val(&result, buf, end)); if (result) { svn_boolean_t invalid; svn_boolean_t is_this_dir; entry->depth = svn_depth_from_word(result); /* Verify the depth value: THIS_DIR should not have an excluded value and SUB_DIR should only have excluded value. Remember that infinity value is not stored and should not show up here. Otherwise, something bad may have happened. However, infinity value itself will always be okay. */ is_this_dir = !name; /* '!=': XOR */ invalid = is_this_dir != (entry->depth != svn_depth_exclude); if (entry->depth != svn_depth_infinity && invalid) return svn_error_createf( SVN_ERR_ENTRY_ATTRIBUTE_INVALID, NULL, _("Entry '%s' has invalid 'depth' value"), name ? name : SVN_WC_ENTRY_THIS_DIR); } else entry->depth = svn_depth_infinity; } MAYBE_DONE; /* Tree conflict data. */ SVN_ERR(read_str(&entry->tree_conflict_data, buf, end, pool)); MAYBE_DONE; /* File external URL and revision. */ { const char *str; SVN_ERR(read_str(&str, buf, end, pool)); SVN_ERR(svn_wc__unserialize_file_external(&entry->file_external_path, &entry->file_external_peg_rev, &entry->file_external_rev, str, pool)); } MAYBE_DONE; done: *new_entry = entry; return SVN_NO_ERROR; }
void obstypes_read(char fname[], int* n, obstype** types, double rfactor_base) { FILE* f = NULL; char buf[MAXSTRLEN]; int line; obstype* now = NULL; int i; assert(*n == 0); f = enkf_fopen(fname, "r"); line = 0; while (fgets(buf, MAXSTRLEN, f) != NULL) { char seps[] = " =\t\n"; char* token; line++; if (buf[0] == '#') continue; if ((token = strtok(buf, seps)) == NULL) continue; if (strcasecmp(token, "NAME") == 0) { if ((token = strtok(NULL, seps)) == NULL) enkf_quit("%s, l.%d: NAME not specified", fname, line); if (obstype_getid(*n, *types, token) >= 0) enkf_quit("%s: l.%d: type \"%s\" already specified", fname, line, token); *types = realloc(*types, (*n + 1) * sizeof(obstype)); now = &(*types)[*n]; obstype_new(now, *n, token); (*n)++; continue; } if (now == NULL) enkf_quit("%s, l.%d: NAME not specified", fname, line); if (strcasecmp(token, "ISSURFACE") == 0) { if ((token = strtok(NULL, seps)) == NULL) enkf_quit("%s, l.%d: ISSURFACE not specified", fname, line); now->issurface = read_bool(token); if (now->issurface < 0) enkf_quit("%s, l.%d: could not convert \"%s\" to boolean", fname, line, token); } else if (strcasecmp(token, "VAR") == 0) { if ((token = strtok(NULL, seps)) == NULL) enkf_quit("%s, l.%d: VAR not specified", fname, line); if (now->varname != NULL) enkf_quit("%s, l.%d: VAR already specified", fname, line); now->varname = strdup(token); } else if (strcasecmp(token, "VAR2") == 0) { if ((token = strtok(NULL, seps)) == NULL) enkf_quit("%s, l.%d: VAR2 not specified", fname, line); if (now->varname2 != NULL) enkf_quit("%s, l.%d: VAR2 already specified", fname, line); now->varname2 = strdup(token); } else if (strcasecmp(token, "OFFSET") == 0) { if ((token = strtok(NULL, seps)) == NULL) enkf_quit("%s, l.%d: OFFSET file name not specified", fname, line); if (now->offset_fname != NULL) enkf_quit("%s, l.%d: OFFSET entry already specified", fname, line); now->offset_fname = strdup(token); if ((token = strtok(NULL, seps)) == NULL) enkf_quit("%s, l.%d: OFFSET variable name not specified", fname, line); now->offset_varname = strdup(token); } else if (strcasecmp(token, "HFUNCTION") == 0) { if ((token = strtok(NULL, seps)) == NULL) enkf_quit("%s, l.%d: HFUNCTION not specified", fname, line); if (now->hfunction != NULL) enkf_quit("%s, l.%d: HFUNCTION already specified", fname, line); now->hfunction = strdup(token); } else if (strcasecmp(token, "MINVALUE") == 0) { if ((token = strtok(NULL, seps)) == NULL) enkf_quit("%s, l.%d: MINVALUE not specified", fname, line); if (!str2double(token, &now->allowed_min)) enkf_quit("%s, l.%d: could not convert \"%s\" to double", fname, line, token); } else if (strcasecmp(token, "MAXVALUE") == 0) { if ((token = strtok(NULL, seps)) == NULL) enkf_quit("%s, l.%d: MAXVALUE not specified", fname, line); if (!str2double(token, &now->allowed_max)) enkf_quit("%s, l.%d: could not convert \"%s\" to double", fname, line, token); } else if (strncasecmp(token, "ASYNC", 5) == 0) { now->isasync = 1; if ((token = strtok(NULL, seps)) == NULL) enkf_quit("%s, l.%d: ASYNC time interval not specified", fname, line); if (!str2double(token, &now->async_tstep)) enkf_quit("%s, l.%d: could not convert \"%s\" to double", fname, line, token); } else if (strcasecmp(token, "RFACTOR") == 0) { if ((token = strtok(NULL, seps)) == NULL) enkf_quit("%s, l.%d: RFACTOR not specified", fname, line); if (!str2double(token, &now->rfactor)) enkf_quit("%s, l.%d: could not convert \"%s\" to double", fname, line, token); } else if (strcasecmp(token, "XMIN") == 0) { if ((token = strtok(NULL, seps)) == NULL) enkf_quit("%s, l.%d: XMIN not specified", fname, line); if (!str2double(token, &now->xmin)) enkf_quit("%s, l.%d: could not convert \"%s\" to double", fname, line, token); } else if (strcasecmp(token, "XMAX") == 0) { if ((token = strtok(NULL, seps)) == NULL) enkf_quit("%s, l.%d: XMAX not specified", fname, line); if (!str2double(token, &now->xmax)) enkf_quit("%s, l.%d: could not convert \"%s\" to double", fname, line, token); } else if (strcasecmp(token, "YMIN") == 0) { if ((token = strtok(NULL, seps)) == NULL) enkf_quit("%s, l.%d: YMIN not specified", fname, line); if (!str2double(token, &now->ymin)) enkf_quit("%s, l.%d: could not convert \"%s\" to double", fname, line, token); } else if (strcasecmp(token, "YMAX") == 0) { if ((token = strtok(NULL, seps)) == NULL) enkf_quit("%s, l.%d: YMAX not specified", fname, line); if (!str2double(token, &now->ymax)) enkf_quit("%s, l.%d: could not convert \"%s\" to double", fname, line, token); } else if (strcasecmp(token, "ZMIN") == 0) { if ((token = strtok(NULL, seps)) == NULL) enkf_quit("%s, l.%d: ZMIN not specified", fname, line); if (!str2double(token, &now->zmin)) enkf_quit("%s, l.%d: could not convert \"%s\" to double", fname, line, token); } else if (strcasecmp(token, "ZMAX") == 0) { if ((token = strtok(NULL, seps)) == NULL) enkf_quit("%s, l.%d: ZMAX not specified", fname, line); if (!str2double(token, &now->zmax)) enkf_quit("%s, l.%d: could not convert \"%s\" to double", fname, line, token); } else enkf_quit("%s, l.%d: unknown token \"%s\"", fname, line, token); } fclose(f); for (i = 0; i < *n; ++i) (*types)[i].rfactor *= rfactor_base; for (i = 0; i < *n; ++i) { obstype_check(&(*types)[i]); obstype_print(&(*types)[i]); } }
// ------------------------------------------ // data set // ------------------------------------------ DataSet::DataSet *Storage::Binary::read_data_set() { DataSet::DataSet *data_set = NULL; bool sparse = read_bool(); // determine the type of data set to create if(sparse) data_set = new DataSet::SparseDataSet(); else data_set = new DataSet::DenseDataSet(); // initialise the data set data_set->name = read_string(); data_set->category_index = read_int(); data_set->counted = read_bool(); data_set->indexed = read_bool(); // initialise the data set's features DataSet::NominalFeature *nominal_feature; DataSet::NumericFeature *numeric_feature; int index = 0, count = 0; bool nominal = false; string name; // determine the number of features to read; count caches need to know the number of categories up front int num_features = read_int(); int num_categories = read_int(); for(int i = 0; i < num_features; i++) { nominal = read_bool(); index = read_int(); name = read_string(); if(nominal) { nominal_feature = data_set->new_nominal_feature(name); nominal_feature->index = index; // read the nominal category names count = read_int(); for(int i = 0; i < count; i++) nominal_feature->add_value(read_string()); // read cached frequencies and probabilities if present if(data_set->counted) { vector<int> *frequencies = read_vector<int>(); vector<double> *probabilities = read_vector<double>(); nominal_feature->frequencies = *frequencies; nominal_feature->probabilities = *probabilities; nominal_feature->category_frequencies.resize(num_categories + 1); nominal_feature->category_probabilities.resize(num_categories + 1); delete frequencies; delete probabilities; for(int i = 1; i <= num_categories; i++) { frequencies = read_vector<int>(); nominal_feature->category_frequencies[i] = *frequencies; delete frequencies; } for(int i = 1; i <= num_categories; i++) { probabilities = read_vector<double>(); nominal_feature->category_probabilities[i] = *probabilities; delete probabilities; } } // TODO: read cached indexes if(data_set->indexed) { } } else { numeric_feature = data_set->new_numeric_feature(name); numeric_feature->index = index; // cached counts if(data_set->counted) { file.read((char *)&(numeric_feature->counts), sizeof(DataSet::NumericFeature::Counts)); numeric_feature->category_counts = (DataSet::NumericFeature::Counts *) malloc(sizeof(DataSet::NumericFeature::Counts) * (num_categories + 1)); for(int i = 1; i <= num_categories; i++) file.read((char *)&(numeric_feature->category_counts[i]), sizeof(DataSet::NumericFeature::Counts)); } // TODO: cached indexes if(data_set->indexed) { } } } // read examples if present should_write_examples = read_bool(); if(should_write_examples) { int num_examples = read_int(); if(sparse) { DataSet::SparseExample *sparse_example; for(int i = 0; i < num_examples; i++) { // number of non-zero values count = read_int(); // construct & read the example sparse_example = ((DataSet::SparseDataSet *) data_set)->new_example(count); file.read((char *)sparse_example->values, count * sizeof(DataSet::SparseExample::Value)); sparse_example->size = count; } } else { // each dense example stores the same number of values count = read_int(); // read each example DataSet::DenseExample *dense_example; for(int i = 0; i < num_examples; i++) { dense_example = ((DataSet::DenseDataSet *) data_set)->new_example(); file.read((char *)dense_example->values, count * sizeof(double)); } } } return data_set; }
virtual void read(bool& out_value) override { out_value = read_bool(); }
int main (int argc, char **argv) { int c; const char *truth_file = NULL; const char *test_file = NULL; const char *format = NULL; int compare_before = FALSE; int compare_after = TRUE; int seed = 0; const struct option lopt[] = { {"help", 0, 0, 'h'}, {"seed", 1, 0, 'd'}, {"truth", 1, 0, 'b'}, {"test", 1, 0, 't'}, {"format", 1, 0, 'f'}, {"rand_time", 1, 0, 'n'}, {"fail_prob", 1, 0, 'u'}, {"cancel_prob", 1, 0, 'c'}, {"flush_prob", 1, 0, 'w'}, {"round", 1, 0, 'r'}, {"parallel", 1, 0, 'p'}, {"compare_before", 1, 0, 'm'}, {"verify_write", 1, 0, 'v'}, {"compare_after", 1, 0, 'a'}, {"max_iov", 1, 0, 'i'}, {"io_size", 1, 0, 's'}, {"instant_qemubh", 1, 0, 'q'}, {NULL, 0, NULL, 0} }; progname = basename (argv[0]); while ((c = getopt_long (argc, argv, "hc:u:p:q:i:f:d:b:t:r:m:v:a:s:", lopt, NULL)) != -1) { switch (c) { case 'h': usage (); return 0; case 'q': instant_qemubh = read_bool (optarg); break; case 'w': flush_prob = atof (optarg); break; case 'c': cancel_prob = atof (optarg); break; case 'u': fail_prob = atof (optarg); break; case 'n': rand_time = atoll (optarg); break; case 'i': max_iov = atoi (optarg); break; case 'p': parallel = atoi (optarg); break; case 'v': verify_write = read_bool (optarg); break; case 'm': compare_before = read_bool (optarg); break; case 'a': compare_after = read_bool (optarg); break; case 'd': seed = atoll (optarg); break; case 'f': format = optarg; break; case 'b': truth_file = optarg; break; case 't': test_file = optarg; break; case 's': io_size = atoll (optarg); break; case 'r': round = atoll (optarg); break; default: usage (); return 1; } } if (!truth_file || !test_file) { usage (); return 1; } if (parallel <= 0) { parallel = 1; } srandom (seed); /* Convince FVD this is not in a qemu-tool. */ in_qemu_tool = false; enable_block_sim (FALSE /*no print */ , rand_time); fvd_enable_host_crash_test (); bdrv_init (); perform_test (truth_file, test_file, format, compare_before, compare_after); return 0; }
PERSISTENT_DATA *persistentDataRead(STORAGE_SET *set) { PERSISTENT_DATA *data = newPersistentData(); data->persistent = read_bool(set, "persistent"); data->activity = read_int(set, "activity"); return data; }
int VC2Decoder::processTransformParams(uint8_t *_idata, int ilength) { (void)ilength; uint8_t *idata = (uint8_t *)_idata; if (!mConfigured || !mTransformParamsEncoded || mTransformParamsEncodedLength == 0 || memcmp(mTransformParamsEncoded, idata, mTransformParamsEncodedLength)) { writelog(LOG_INFO, "Processing Transform Params"); int bits = 7; VC2DecoderTransformParams transform_params; transform_params.wavelet_index = read_uint(idata, bits); transform_params.wavelet_depth = read_uint(idata, bits); transform_params.slices_x = read_uint(idata, bits); transform_params.slices_y = read_uint(idata, bits); int prefix_bytes = read_uint(idata, bits); int slice_size_scalar = read_uint(idata, bits); transform_params.custom_quant_matrix_flag = read_bool(idata, bits); if (transform_params.custom_quant_matrix_flag) { transform_params.quant_matrix_LL = read_uint(idata, bits); for (int l = 0; l < (int)transform_params.wavelet_depth - 1; l++) { transform_params.quant_matrix_HL[l] = read_uint(idata, bits); transform_params.quant_matrix_LH[l] = read_uint(idata, bits); transform_params.quant_matrix_HH[l] = read_uint(idata, bits); } } byte_align(idata, bits); mTransformParamsEncodedLength = (idata - (uint8_t*)_idata); if (mTransformParamsEncoded) delete[] mTransformParamsEncoded; mTransformParamsEncoded = new uint8_t[mTransformParamsEncodedLength]; memcpy(mTransformParamsEncoded, _idata, mTransformParamsEncodedLength); VC2DecoderParamsInternal params = mParams; params.transform_params = transform_params; params.slice_size_scalar = slice_size_scalar; params.slice_prefix_bytes = prefix_bytes; setParams(params); mSequenceInfo.transform_params = transform_params; mConfigured = true; #ifdef DEBUG { printf("--------------------------------------------------------------------\n"); printf(" Picture Header Stream Data\n"); printf("--------------------------------------------------------------------\n"); uint8_t *data = (uint8_t *)&_idata; for (int y = 0; y * 16 < mTransformParamsEncodedLength; y++) { printf(" "); for (int x = 0; x < 16 && y * 16 + x < mTransformParamsEncodedLength; x++) { printf(" %02x", data[y * 16 + x]); } printf("\n"); } printf("--------------------------------------------------------------------\n"); } #endif } else { idata += mTransformParamsEncodedLength; } return idata - _idata; }
bool get_bool(HSQUIRRELVM vm, const char* name, bool& val) { if (!has_bool(vm, name)) return false; val = read_bool(vm, name); return true; }
// // overloaded version without default // short read_bool(char *prompt) { return (read_bool(prompt, true)); }
// returns: 0 on success, 1 on key error, 2 on parse error int pop_bool(std::string key, bool &n) { std::string v; if(pop(key, v)) return 1; return read_bool(v.c_str(), n) ? 0 : 2; }