void print_failed_external() { print_verbose( "Found no matching externalhost, will now try to contact node by address\n"); }
int brot_main(const char *cmdline) { struct brot_args_info brot_args; SeqMatrix* sm = NULL; int retval = 0; Scmf_Rna_Opt_data* sim_data = NULL; GFile* entropy_file = NULL; GFile* simulation_file = NULL; /* command line parsing */ brot_cmdline_parser_init (&brot_args); retval = brot_cmdline_parser_string (cmdline, &brot_args, get_progname()); if (retval == 0) { retval = brot_cmdline_parser_required (&brot_args, get_progname()); } /* postprocess arguments */ if (retval == 0) { retval = brot_cmdline_parser_postprocess (&brot_args, cmdline); } /* init simulation data */ if (retval == 0) { sim_data = SCMF_RNA_OPT_DATA_NEW_INIT(brot_args.inputs[1], strlen (brot_args.inputs[1]), RNA_ALPHABET, strlen(RNA_ALPHABET)/2, ((-1) * ((logf (1 / 0.000001f)) / (strlen (brot_args.inputs[1])))), brot_args.file_given); if (sim_data == NULL) { retval = 1; } } /* init matrix */ if (retval == 0) { sm = SEQMATRIX_NEW; if (sm != NULL) { retval = SEQMATRIX_INIT ( alphabet_size (scmf_rna_opt_data_get_alphabet (sim_data)), scmf_rna_opt_data_get_rna_size(sim_data), /* strlen (brot_args.inputs[1]), */ sm); /*seqmatrix_print_2_stdout (6, sm);*/ } else { retval = 1; } } /* fix certain sites in the matrix */ if (retval == 0) { retval = adopt_site_presettings (&brot_args, scmf_rna_opt_data_get_alphabet (sim_data), sim_data, sm); } /* open entropy file if name given */ if (retval == 0) { print_verbose ("# Entropy file (-p): "); if (brot_args.entropy_output_given) { print_verbose ("%s", brot_args.entropy_output_arg); entropy_file = GFILE_OPEN (brot_args.entropy_output_arg, strlen (brot_args.entropy_output_arg), GFILE_VOID, "a"); if (entropy_file == NULL) { retval = 1; } else { retval = brot_settings_2_file (entropy_file, cmdline); } } /* open simulation/ matrix file if name given */ print_verbose ("\n# Simulation/ Matrix file (-m): "); if (brot_args.simulation_output_given) { print_verbose ("%s", brot_args.simulation_output_arg); simulation_file = GFILE_OPEN (brot_args.simulation_output_arg, strlen (brot_args.simulation_output_arg), GFILE_VOID, "a"); if (simulation_file == NULL) { retval = 1; } else { retval = brot_settings_2_file (simulation_file, cmdline); if (retval == 0) { if (gfile_printf (simulation_file, "START\n") < 0) { retval = 1; } } } } } if (retval == 0) { print_verbose ("\n# Scoring scheme (-c): "); if (brot_args.scoring_arg == scoring_arg_simpleNN) { print_verbose ("simpleNN\n"); /* special to NN usage: structure has to be of size >= 2 */ if (strlen (brot_args.inputs[1]) > 1) { retval = simulate_using_simplenn_scoring (&brot_args, sm, sim_data, entropy_file, simulation_file); } else { THROW_ERROR_MSG (NN_2_SMALL_WARNING, brot_args.inputs[1], (unsigned long) strlen (brot_args.inputs[1])); retval = 1; } } else if (brot_args.scoring_arg == scoring_arg_nussinov) { print_verbose ("nussinov\n"); retval = simulate_using_nussinov_scoring (&brot_args, sm, sim_data, entropy_file, simulation_file); } else if (brot_args.scoring_arg == scoring_arg_NN) { print_verbose ("NN\n"); /* special to NN usage: structure has to be of size >= 2 */ if (strlen (brot_args.inputs[1]) > 1) { retval = simulate_using_nn_scoring (&brot_args, sm, sim_data, entropy_file, simulation_file); } else { THROW_ERROR_MSG (NN_2_SMALL_WARNING, brot_args.inputs[1], (unsigned long) strlen (brot_args.inputs[1])); retval = 1; } } } /* close files */ if (retval == 0) { retval = gfile_close (entropy_file); } else { gfile_close (entropy_file); } if (simulation_file != NULL) { if (gfile_printf (simulation_file, "END\n") < 0) { retval = 1; } } if (retval == 0) { retval = gfile_close (simulation_file); } else { gfile_close (simulation_file); } if (retval == 0) { /*seqmatrix_print_2_stdout (2, sm);*/ mprintf ("%s\n", scmf_rna_opt_data_get_seq(sim_data)); } /* finalise */ brot_cmdline_parser_free (&brot_args); seqmatrix_delete (sm); scmf_rna_opt_data_delete (sim_data); if (retval == 0) { return EXIT_SUCCESS; } else { return EXIT_FAILURE; } }
static int find_common(struct fetch_pack_args *args, int fd[2], struct object_id *result_oid, struct ref *refs) { int fetching; int count = 0, flushes = 0, flush_at = INITIAL_FLUSH, retval; const struct object_id *oid; unsigned in_vain = 0; int got_continue = 0; int got_ready = 0; struct strbuf req_buf = STRBUF_INIT; size_t state_len = 0; if (args->stateless_rpc && multi_ack == 1) die(_("--stateless-rpc requires multi_ack_detailed")); if (marked) for_each_ref(clear_marks, NULL); marked = 1; for_each_ref(rev_list_insert_ref_oid, NULL); for_each_cached_alternate(insert_one_alternate_object); fetching = 0; for ( ; refs ; refs = refs->next) { struct object_id *remote = &refs->old_oid; const char *remote_hex; struct object *o; /* * If that object is complete (i.e. it is an ancestor of a * local ref), we tell them we have it but do not have to * tell them about its ancestors, which they already know * about. * * We use lookup_object here because we are only * interested in the case we *know* the object is * reachable and we have already scanned it. */ if (((o = lookup_object(remote->hash)) != NULL) && (o->flags & COMPLETE)) { continue; } remote_hex = oid_to_hex(remote); if (!fetching) { struct strbuf c = STRBUF_INIT; if (multi_ack == 2) strbuf_addstr(&c, " multi_ack_detailed"); if (multi_ack == 1) strbuf_addstr(&c, " multi_ack"); if (no_done) strbuf_addstr(&c, " no-done"); if (use_sideband == 2) strbuf_addstr(&c, " side-band-64k"); if (use_sideband == 1) strbuf_addstr(&c, " side-band"); if (args->deepen_relative) strbuf_addstr(&c, " deepen-relative"); if (args->use_thin_pack) strbuf_addstr(&c, " thin-pack"); if (args->no_progress) strbuf_addstr(&c, " no-progress"); if (args->include_tag) strbuf_addstr(&c, " include-tag"); if (prefer_ofs_delta) strbuf_addstr(&c, " ofs-delta"); if (deepen_since_ok) strbuf_addstr(&c, " deepen-since"); if (deepen_not_ok) strbuf_addstr(&c, " deepen-not"); if (agent_supported) strbuf_addf(&c, " agent=%s", git_user_agent_sanitized()); if (args->filter_options.choice) strbuf_addstr(&c, " filter"); packet_buf_write(&req_buf, "want %s%s\n", remote_hex, c.buf); strbuf_release(&c); } else packet_buf_write(&req_buf, "want %s\n", remote_hex); fetching++; } if (!fetching) { strbuf_release(&req_buf); packet_flush(fd[1]); return 1; } if (is_repository_shallow()) write_shallow_commits(&req_buf, 1, NULL); if (args->depth > 0) packet_buf_write(&req_buf, "deepen %d", args->depth); if (args->deepen_since) { timestamp_t max_age = approxidate(args->deepen_since); packet_buf_write(&req_buf, "deepen-since %"PRItime, max_age); } if (args->deepen_not) { int i; for (i = 0; i < args->deepen_not->nr; i++) { struct string_list_item *s = args->deepen_not->items + i; packet_buf_write(&req_buf, "deepen-not %s", s->string); } } if (server_supports_filtering && args->filter_options.choice) packet_buf_write(&req_buf, "filter %s", args->filter_options.filter_spec); packet_buf_flush(&req_buf); state_len = req_buf.len; if (args->deepen) { char *line; const char *arg; struct object_id oid; send_request(args, fd[1], &req_buf); while ((line = packet_read_line(fd[0], NULL))) { if (skip_prefix(line, "shallow ", &arg)) { if (get_oid_hex(arg, &oid)) die(_("invalid shallow line: %s"), line); register_shallow(&oid); continue; } if (skip_prefix(line, "unshallow ", &arg)) { if (get_oid_hex(arg, &oid)) die(_("invalid unshallow line: %s"), line); if (!lookup_object(oid.hash)) die(_("object not found: %s"), line); /* make sure that it is parsed as shallow */ if (!parse_object(&oid)) die(_("error in object: %s"), line); if (unregister_shallow(&oid)) die(_("no shallow found: %s"), line); continue; } die(_("expected shallow/unshallow, got %s"), line); } } else if (!args->stateless_rpc) send_request(args, fd[1], &req_buf); if (!args->stateless_rpc) { /* If we aren't using the stateless-rpc interface * we don't need to retain the headers. */ strbuf_setlen(&req_buf, 0); state_len = 0; } flushes = 0; retval = -1; if (args->no_dependents) goto done; while ((oid = get_rev())) { packet_buf_write(&req_buf, "have %s\n", oid_to_hex(oid)); print_verbose(args, "have %s", oid_to_hex(oid)); in_vain++; if (flush_at <= ++count) { int ack; packet_buf_flush(&req_buf); send_request(args, fd[1], &req_buf); strbuf_setlen(&req_buf, state_len); flushes++; flush_at = next_flush(args->stateless_rpc, count); /* * We keep one window "ahead" of the other side, and * will wait for an ACK only on the next one */ if (!args->stateless_rpc && count == INITIAL_FLUSH) continue; consume_shallow_list(args, fd[0]); do { ack = get_ack(fd[0], result_oid); if (ack) print_verbose(args, _("got %s %d %s"), "ack", ack, oid_to_hex(result_oid)); switch (ack) { case ACK: flushes = 0; multi_ack = 0; retval = 0; goto done; case ACK_common: case ACK_ready: case ACK_continue: { struct commit *commit = lookup_commit(result_oid); if (!commit) die(_("invalid commit %s"), oid_to_hex(result_oid)); if (args->stateless_rpc && ack == ACK_common && !(commit->object.flags & COMMON)) { /* We need to replay the have for this object * on the next RPC request so the peer knows * it is in common with us. */ const char *hex = oid_to_hex(result_oid); packet_buf_write(&req_buf, "have %s\n", hex); state_len = req_buf.len; /* * Reset in_vain because an ack * for this commit has not been * seen. */ in_vain = 0; } else if (!args->stateless_rpc || ack != ACK_common) in_vain = 0; mark_common(commit, 0, 1); retval = 0; got_continue = 1; if (ack == ACK_ready) { clear_prio_queue(&rev_list); got_ready = 1; } break; } } } while (ack); flushes--; if (got_continue && MAX_IN_VAIN < in_vain) { print_verbose(args, _("giving up")); break; /* give up */ } } } done: if (!got_ready || !no_done) { packet_buf_write(&req_buf, "done\n"); send_request(args, fd[1], &req_buf); } print_verbose(args, _("done")); if (retval != 0) { multi_ack = 0; flushes++; } strbuf_release(&req_buf); if (!got_ready || !no_done) consume_shallow_list(args, fd[0]); while (flushes || multi_ack) { int ack = get_ack(fd[0], result_oid); if (ack) { print_verbose(args, _("got %s (%d) %s"), "ack", ack, oid_to_hex(result_oid)); if (ack == ACK) return 0; multi_ack = 1; continue; } flushes--; } /* it is no error to fetch into a completely empty repo */ return count ? retval : 0; }
int diagonalize_bisection(localized_matrix<double, MATRIX_MAJOR>& mata, localized_matrix<double, MATRIX_MAJOR>& matb, double* eigvals, localized_matrix<double, MATRIX_MAJOR>& eigvecs, parameters const& params, timer& timer) { rokko::parameters params_out; char jobz = 'V'; // eigenvalues / eigenvectors int dim = mata.innerSize(); int lda = mata.outerSize(); int ldb = matb.outerSize(); int ldim_eigvec = eigvecs.innerSize(); std::vector<lapack_int> ifail(dim); lapack_int m; // output: found eigenvalues double abstol; get_key(params, "abstol", abstol); if (abstol < 0) { std::cerr << "Error in diagonalize_bisection" << std::endl << "abstol is negative value, which means QR method." << std::endl << "To use dsygvx as bisection solver, set abstol a positive value" << std::endl; throw; } if (!params.defined("abstol")) { // default: optimal value for bisection method abstol = 2 * LAPACKE_dlamch('S'); } params_out.set("abstol", abstol); char uplow = get_matrix_part(params); lapack_int il, iu; double vl, vu; char range = get_eigenvalues_range(params, vl, vu, il, iu); timer.start(timer_id::diagonalize_diagonalize); int info; if(mata.is_col_major()) info = LAPACKE_dsygvx(LAPACK_COL_MAJOR, 1, jobz, range, uplow, dim, &mata(0,0), lda, &matb(0,0), ldb, vl, vu, il, iu, abstol, &m, eigvals, &eigvecs(0,0), ldim_eigvec, &ifail[0]); else info = LAPACKE_dsygvx(LAPACK_ROW_MAJOR, 1, jobz, range, uplow, dim, &mata(0,0), lda, &matb(0,0), ldb, vl, vu, il, iu, abstol, &m, eigvals, &eigvecs(0,0), ldim_eigvec, &ifail[0]); timer.stop(timer_id::diagonalize_diagonalize); timer.start(timer_id::diagonalize_finalize); if (info) { std::cerr << "Error at dsygvx function. info=" << info << std::endl; if (params.get_bool("verbose")) { std::cerr << "This means that "; if (info < 0) { std::cerr << "the " << abs(info) << "-th argument had an illegal value." << std::endl; } else { std::cerr << "This means that " << info << " eigenvectors failed to converge." << std::endl; std::cerr << "The indices of the eigenvectors that failed to converge:" << std::endl; for (int i=0; i<ifail.size(); ++i) { if (ifail[i] == 0) break; std::cerr << ifail[i] << " "; } std::cerr << std::endl; } } exit(1); } params_out.set("m", m); params_out.set("ifail", ifail); if (params.get_bool("verbose")) { print_verbose("dsygvx (bisecition)", jobz, range, uplow, vl, vu, il, iu, params_out); } timer.stop(timer_id::diagonalize_finalize); return info; }
static int adopt_site_presettings (const struct brot_args_info* args_info, Alphabet* sigma, Scmf_Rna_Opt_data* data, SeqMatrix* sm) { unsigned long i; unsigned long position = 0; unsigned long struct_len; char base = CHAR_UNDEF; char* endptr; assert (sm); struct_len = seqmatrix_get_width (sm); print_verbose ("# Fixed sites (-n): "); /* check presettings */ for (i = 0; i < args_info->fixed_nuc_given; i++) { /* check format & alphabet */ if ( (strlen (args_info->fixed_nuc_arg[i]) > 2) &&(args_info->fixed_nuc_arg[i][1] == ':')) { base = alphabet_base_2_no (args_info->fixed_nuc_arg[i][0], sigma); if (base == CHAR_UNDEF) { return 1; } } else { THROW_ERROR_MSG ("Found fixed base of wrong format: \'%s\'. Try " "`%s --help` for more information.", args_info->fixed_nuc_arg[i], get_progname()); return 1; } position = strtoul (args_info->fixed_nuc_arg[i] + 2, &endptr, 10); if (*endptr != '\0') { THROW_ERROR_MSG ("Fixed bases require a positive integer as " "position, found: %s. Try `%s --help` for more " "information.", args_info->fixed_nuc_arg[i], get_progname()); return 1; } if (position >= struct_len) { THROW_ERROR_MSG ("Preset position (%lu) larger than or equal to " "structure length (%lu) for presetting \"%s\"", position, struct_len, args_info->fixed_nuc_arg[i]); return 1; } if (seqmatrix_is_col_fixed (position, sm)) { THROW_ERROR_MSG ("Presetting conflict for position %lu (\"%c\"): " "Already set", position, alphabet_no_2_base (base, sigma)); return 1; } seqmatrix_fix_col (base, position, data, sm); print_verbose ("%s ", args_info->fixed_nuc_arg[i]); } print_verbose ("\n"); return 0; }
int fiemap_f( int argc, char **argv) { struct fiemap *fiemap; int max_extents = 0; int num_extents = 32; int last = 0; int lflag = 0; int vflag = 0; int fiemap_flags = FIEMAP_FLAG_SYNC; int c; int i; int map_size; int ret; int cur_extent = 0; int foff_w = 16; /* 16 just for a good minimum range */ int boff_w = 16; int tot_w = 5; /* 5 since its just one number */ int flg_w = 5; __u64 blocksize = 512; __u64 last_logical = 0; struct stat st; while ((c = getopt(argc, argv, "aln:v")) != EOF) { switch (c) { case 'a': fiemap_flags |= FIEMAP_FLAG_XATTR; break; case 'l': lflag = 1; break; case 'n': max_extents = atoi(optarg); break; case 'v': vflag++; break; default: return command_usage(&fiemap_cmd); } } if (max_extents) num_extents = min(num_extents, max_extents); map_size = sizeof(struct fiemap) + (num_extents * sizeof(struct fiemap_extent)); fiemap = malloc(map_size); if (!fiemap) { fprintf(stderr, _("%s: malloc of %d bytes failed.\n"), progname, map_size); exitcode = 1; return 0; } printf("%s:\n", file->name); while (!last && ((cur_extent + 1) != max_extents)) { if (max_extents) num_extents = min(num_extents, max_extents - (cur_extent + 1)); memset(fiemap, 0, map_size); fiemap->fm_flags = fiemap_flags; fiemap->fm_start = last_logical; fiemap->fm_length = -1LL; fiemap->fm_extent_count = num_extents; ret = ioctl(file->fd, FS_IOC_FIEMAP, (unsigned long)fiemap); if (ret < 0) { fprintf(stderr, "%s: ioctl(FS_IOC_FIEMAP) [\"%s\"]: " "%s\n", progname, file->name, strerror(errno)); free(fiemap); exitcode = 1; return 0; } /* No more extents to map, exit */ if (!fiemap->fm_mapped_extents) break; for (i = 0; i < fiemap->fm_mapped_extents; i++) { struct fiemap_extent *extent; extent = &fiemap->fm_extents[i]; if (vflag) { if (cur_extent == 0) { calc_print_format(fiemap, blocksize, &foff_w, &boff_w, &tot_w, &flg_w); } print_verbose(extent, blocksize, foff_w, boff_w, tot_w, flg_w, max_extents, &cur_extent, &last_logical); } else print_plain(extent, lflag, blocksize, max_extents, &cur_extent, &last_logical); if (extent->fe_flags & FIEMAP_EXTENT_LAST) { last = 1; break; } if ((cur_extent + 1) == max_extents) break; } } if ((cur_extent + 1) == max_extents) goto out; memset(&st, 0, sizeof(st)); if (fstat(file->fd, &st)) { fprintf(stderr, "%s: fstat failed: %s\n", progname, strerror(errno)); free(fiemap); exitcode = 1; return 0; } if (cur_extent && last_logical < st.st_size) { char lbuf[32]; snprintf(lbuf, sizeof(lbuf), "[%llu..%llu]:", last_logical / blocksize, (st.st_size / blocksize) - 1); if (vflag) { printf("%4d: %-*s %-*s %*llu\n", cur_extent, foff_w, lbuf, boff_w, _("hole"), tot_w, (st.st_size - last_logical) / blocksize); } else { printf("\t%d: %s %s", cur_extent, lbuf, _("hole")); if (lflag) printf(_(" %llu blocks\n"), (st.st_size - last_logical) / blocksize); else printf("\n"); } } out: free(fiemap); return 0; }
char *pong() { print_verbose("pong\n"); return strdup("pong\n"); }
budget_category_collection *budget_category_get_all_categories(sqlite3 **db) { int row_count, count = 0, rc; sqlite3_stmt *statement, *statement_count; budget_category_collection *return_collection; if (*db == NULL) { print_verbose((stdout, "LIBBUDGET: ERROR: budget_category_get_all_categories input validation failed\n")); return NULL; } print_debug((stderr, "LIBBUDGET: Generate list of categories\n")); /* prepare query to count records */ if (sqlite3_prepare_v2(*db, QUERY_CATEGORY_GET_CATEGORIES_COUNT, strnlen(QUERY_CATEGORY_GET_CATEGORIES_COUNT, INT_MAX), &statement_count, NULL) == SQLITE_OK) { /* step to execute query */ if (sqlite3_step(statement_count) == SQLITE_ROW) { row_count = sqlite3_column_int(statement_count, 0); sqlite3_finalize(statement_count); /* prepare query */ if (sqlite3_prepare_v2(*db, QUERY_CATEGORY_GET_CATEGORIES, strnlen(QUERY_CATEGORY_GET_CATEGORIES, INT_MAX), &statement, NULL) == SQLITE_OK) { /* step to execute query */ rc = sqlite3_step(statement); if (rc == SQLITE_ROW) { return_collection = malloc(sizeof(budget_category_collection)); return_collection->num_items = row_count; return_collection->category_items = calloc(row_count, sizeof(budget_category_item *)); while (rc == SQLITE_ROW) { return_collection->category_items[count] = malloc(sizeof(budget_category_item)); return_collection->category_items[count]->category_id = sqlite3_column_int(statement, 0); return_collection->category_items[count]->category_name = strdup((const char *)sqlite3_column_text(statement, 1)); rc = sqlite3_step(statement); count++; } sqlite3_finalize(statement); return return_collection; } else { print_verbose((stdout, "LIBBUDGET: ERROR: Retrieving data failed (%d)\n", rc)); sqlite3_finalize(statement); return NULL; } } else { print_verbose((stdout, "LIBBUDGET: ERROR: Failed to prepare SQL -> %s\n", sqlite3_errmsg(*db))); sqlite3_finalize(statement); return NULL; } } else { print_verbose((stdout, "LIBBUDGET: ERROR: Counting of data failed\n")); sqlite3_finalize(statement); return NULL; } } else { print_verbose((stdout, "LIBBUDGET: ERROR: Failed to store parameter in SQL -> %s\n", sqlite3_errmsg(*db))); sqlite3_finalize(statement); return NULL; } }
Error AudioDriverPulseAudio::init_device() { // If there is a specified device check that it is really present if (device_name != "Default") { Array list = get_device_list(); if (list.find(device_name) == -1) { device_name = "Default"; new_device = "Default"; } } // Detect the amount of channels PulseAudio is using // Note: If using an even amount of channels (2, 4, etc) channels and pa_map.channels will be equal, // if not then pa_map.channels will have the real amount of channels PulseAudio is using and channels // will have the amount of channels Godot is using (in this case it's pa_map.channels + 1) detect_channels(); switch (pa_map.channels) { case 1: // Mono case 3: // Surround 2.1 case 5: // Surround 5.0 case 7: // Surround 7.0 channels = pa_map.channels + 1; break; case 2: // Stereo case 4: // Surround 4.0 case 6: // Surround 5.1 case 8: // Surround 7.1 channels = pa_map.channels; break; default: WARN_PRINTS("PulseAudio: Unsupported number of channels: " + itos(pa_map.channels)); pa_channel_map_init_stereo(&pa_map); channels = 2; break; } int latency = GLOBAL_DEF_RST("audio/output_latency", DEFAULT_OUTPUT_LATENCY); buffer_frames = closest_power_of_2(latency * mix_rate / 1000); pa_buffer_size = buffer_frames * pa_map.channels; print_verbose("PulseAudio: detected " + itos(pa_map.channels) + " channels"); print_verbose("PulseAudio: audio buffer frames: " + itos(buffer_frames) + " calculated latency: " + itos(buffer_frames * 1000 / mix_rate) + "ms"); pa_sample_spec spec; spec.format = PA_SAMPLE_S16LE; spec.channels = pa_map.channels; spec.rate = mix_rate; pa_str = pa_stream_new(pa_ctx, "Sound", &spec, &pa_map); if (pa_str == NULL) { ERR_PRINTS("PulseAudio: pa_stream_new error: " + String(pa_strerror(pa_context_errno(pa_ctx)))); ERR_FAIL_V(ERR_CANT_OPEN); } pa_buffer_attr attr; // set to appropriate buffer length (in bytes) from global settings // Note: PulseAudio defaults to 4 fragments, which means that the actual // latency is tlength / fragments. It seems that the PulseAudio has no way // to get the fragments number so we're hardcoding this to the default of 4 const int fragments = 4; attr.tlength = pa_buffer_size * sizeof(int16_t) * fragments; // set them to be automatically chosen attr.prebuf = (uint32_t)-1; attr.maxlength = (uint32_t)-1; attr.minreq = (uint32_t)-1; const char *dev = device_name == "Default" ? NULL : device_name.utf8().get_data(); pa_stream_flags flags = pa_stream_flags(PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_ADJUST_LATENCY | PA_STREAM_AUTO_TIMING_UPDATE); int error_code = pa_stream_connect_playback(pa_str, dev, &attr, flags, NULL, NULL); ERR_FAIL_COND_V(error_code < 0, ERR_CANT_OPEN); samples_in.resize(buffer_frames * channels); samples_out.resize(pa_buffer_size); // Reset audio input to keep synchronisation. input_position = 0; input_size = 0; return OK; }
int main(int argc, char *argv[]) { int c; static struct option long_options[] = { {"manufacturer", 1, 0, 'm'}, {"product", 1, 0, 'p'}, {"serial", 1, 0, 's'}, {"verbose", 0, 0, 'v'}, {"help", 0, 0, 'h'}, {NULL, 0, NULL, 0} }; char orig_manufacturer[128]; char* manufacturer = NULL; char orig_product[128]; char* product = NULL; char orig_serial[128]; char* serial = NULL; int bus = -1; int device = -1; struct ftdi_context ftdi; int ires = 0; while ((c = getopt_long(argc, argv, "m:p:s:vh", long_options, &optind)) != -1) { switch (c) { case 'm': manufacturer = optarg; break; case 'p': product = optarg; break; case 's': serial = optarg; break; case 'v': verbose_mode = true; break; case 'h': print_help(argc, argv); return EXIT_SUCCESS; break; } } if (optind + 1 != argc) { print_help(argc, argv); return EXIT_FAILURE; } else { if (!parse_device_identifier(&bus, &device, argv[optind])) { fprintf(stderr, "Unable to parse `%s'\n", argv[optind]); return EXIT_FAILURE; } print_verbose("Using device %03d:%03d\n", bus, device); } libusb_init(NULL); libusb_device** usb_devices; ssize_t n_devices = libusb_get_device_list(NULL, &usb_devices); if (n_devices < 0) { fprintf(stderr, "ERROR: Unable to list USB devices [%zd]: %s\n", n_devices, libusb_strerror((enum libusb_error) n_devices)); return EXIT_FAILURE; } libusb_device* usb_device = NULL; for (int i = 0 ; i < n_devices ; i++) { if (libusb_get_bus_number(usb_devices[i]) == bus && libusb_get_device_address(usb_devices[i]) == device) { usb_device = usb_devices[i]; break; } } if (usb_device == NULL) { fprintf(stderr, "ERROR: Unable to find USB device at %03d:%03d\n", bus, device); return EXIT_FAILURE; } if ((ires = ftdi_init(&ftdi)) != 0) { fprintf(stderr, "ERROR: Unable to initialize libftdi (%d)\n", ires); return EXIT_FAILURE; } if ((ires = ftdi_usb_open_dev(&ftdi, usb_device)) != 0) { fprintf(stderr, "ERROR: Unable to open device (%d)\n", ires); fprintf(stderr, " Perhaps you don't have sufficient permissions (i.e., you aren't root)?\n"); return EXIT_FAILURE; } { struct libusb_device_descriptor desc; if ((ires = libusb_get_device_descriptor(libusb_get_device (ftdi.usb_dev), &desc)) < 0) { fprintf(stderr, "ERROR: Unable to retrieve device descriptor (%d): %s\n", ires, libusb_strerror((enum libusb_error) ires)); return EXIT_FAILURE; } if ((ires = libusb_get_string_descriptor_ascii(ftdi.usb_dev, desc.iManufacturer, (unsigned char*) orig_manufacturer, sizeof(orig_manufacturer))) < 0) { fprintf(stderr, "ERROR: Unable to retrieve manufacturer (%d): %s\n", ires, libusb_strerror((enum libusb_error) ires)); return EXIT_FAILURE; } print_verbose("Old manufacturer: %s\n", orig_manufacturer); if (manufacturer == NULL) manufacturer = orig_manufacturer; if ((ires = libusb_get_string_descriptor_ascii(ftdi.usb_dev, desc.iProduct, (unsigned char*) orig_product, sizeof(orig_product))) < 0) { fprintf(stderr, "ERROR: Unable to retrieve product (%d): %s\n", ires, libusb_strerror((enum libusb_error) ires)); return EXIT_FAILURE; } print_verbose("Old product: %s\n", orig_product); if (product == NULL) product = orig_product; if ((ires = libusb_get_string_descriptor_ascii(ftdi.usb_dev, desc.iSerialNumber, (unsigned char*) orig_serial, sizeof(orig_serial))) < 0) { fprintf(stderr, "ERROR: Unable to retrieve serial (%d): %s\n", ires, libusb_strerror((enum libusb_error) ires)); return EXIT_FAILURE; } print_verbose("Old serial: %s\n", orig_serial); if (serial == NULL) serial = orig_serial; } print_verbose("New manufacturer: %s\n", manufacturer); print_verbose("New product: %s\n", product); print_verbose("New serial: %s\n", serial); if ((ires = ftdi_eeprom_initdefaults (&ftdi, manufacturer, product, serial)) < 0) { fprintf(stderr, "Unable to set EEPROM defaults: %d\n", ires); return EXIT_FAILURE; } if ((ires = ftdi_eeprom_build (&ftdi)) < 0) { fprintf(stderr, "Unable to build EEPROM: %d\n", ires); return EXIT_FAILURE; } if ((ires = ftdi_write_eeprom (&ftdi)) < 0) { fprintf(stderr, "Unable to write EEPROM: %d\n", ires); return EXIT_FAILURE; } ftdi_deinit(&ftdi); return EXIT_SUCCESS; }
budget_category_collection *budget_category_get_categories_by_name_filter(sqlite3 **db, const char *filter, const size_t filter_len) { int row_count, count = 0; size_t i; sqlite3_stmt *statement, *statement_count; budget_category_collection *return_collection; char *filter_padded; if (*db == NULL || filter_len <= 0 || filter_len != strnlen(filter, filter_len)) { print_verbose((stdout, "LIBBUDGET: ERROR: budget_category_get_categories_by_name_filter input validation failed\n")); return NULL; } print_debug((stderr, "LIBBUDGET: Generate list of categories where name contains -> '%s'\n", filter)); /* prepare query to count records */ if (sqlite3_prepare_v2(*db, QUERY_CATEGORY_GET_SPECIFIC_NAMES_COUNT, strnlen(QUERY_CATEGORY_GET_SPECIFIC_NAMES_COUNT, INT_MAX), &statement_count, NULL) == SQLITE_OK) { /* Add wildcart to filter */ filter_padded = calloc((filter_len + 3), sizeof(char)); filter_padded[0] = '%'; for (i = 0; i < filter_len; i++) { filter_padded[1 + i] = filter[i]; } filter_padded[1 + filter_len] = '%'; filter_padded[2 + filter_len] = '\0'; /* set filter in query*/ if (sqlite3_bind_text(statement_count, 1, filter_padded, filter_len + 2, SQLITE_STATIC) == SQLITE_OK) { /* step to execute query */ if (sqlite3_step(statement_count) == SQLITE_ROW) { row_count = sqlite3_column_int(statement_count, 0); sqlite3_finalize(statement_count); /* prepare query */ if (sqlite3_prepare_v2(*db, QUERY_CATEGORY_GET_SPECIFIC_NAMES, strnlen(QUERY_CATEGORY_GET_SPECIFIC_NAMES, INT_MAX), &statement, NULL) == SQLITE_OK) { /* set filter in query*/ if (sqlite3_bind_text(statement, 1, filter_padded, filter_len + 2, SQLITE_STATIC) == SQLITE_OK) { /* step to execute query */ int rc = sqlite3_step(statement); if (rc == SQLITE_ROW) { return_collection = malloc(sizeof(budget_category_collection)); return_collection->num_items = row_count; return_collection->category_items = calloc(row_count, sizeof(budget_category_item *)); while (rc == SQLITE_ROW) { return_collection->category_items[count] = malloc(sizeof(budget_category_item)); return_collection->category_items[count]->category_id = sqlite3_column_int(statement, 0); return_collection->category_items[count]->category_name = strdup((const char *)sqlite3_column_text(statement, 1)); rc = sqlite3_step(statement); count++; } sqlite3_finalize(statement); free(filter_padded); filter_padded = NULL; return return_collection; } else { print_verbose((stdout, "LIBBUDGET: ERROR: Retrieving data failed\n")); free(filter_padded); filter_padded = NULL; sqlite3_finalize(statement); return NULL; } } else { print_verbose((stdout, "LIBBUDGET: ERROR: Failed to store parameter in SQL -> %s\n", sqlite3_errmsg(*db))); free(filter_padded); filter_padded = NULL; sqlite3_finalize(statement); return NULL; } } else { print_verbose((stdout, "LIBBUDGET: ERROR: Failed to prepare SQL -> %s\n", sqlite3_errmsg(*db))); free(filter_padded); filter_padded = NULL; sqlite3_finalize(statement); return NULL; } } else { print_verbose((stdout, "LIBBUDGET: ERROR: Counting of data failed\n")); free(filter_padded); filter_padded = NULL; sqlite3_finalize(statement_count); return NULL; } } else { print_verbose((stdout, "LIBBUDGET: ERROR: Failed to store parameter in SQL -> %s\n", sqlite3_errmsg(*db))); free(filter_padded); filter_padded = NULL; sqlite3_finalize(statement_count); return NULL; } } else { print_verbose((stdout, "LIBBUDGET: ERROR: Failed to prepare SQL -> %s\n", sqlite3_errmsg(*db))); sqlite3_finalize(statement_count); return NULL; } }
static void fill_bits(const BitMap *p_src, Ref<BitMap> &p_map, const Point2i &p_pos, const Rect2i &rect) { // Using a custom stack to work iteratively to avoid stack overflow on big bitmaps PoolVector<FillBitsStackEntry> stack; // Tracking size since we won't be shrinking the stack vector int stack_size = 0; Point2i pos = p_pos; int next_i = 0; int next_j = 0; bool reenter = true; bool popped = false; do { if (reenter) { next_i = pos.x - 1; next_j = pos.y - 1; reenter = false; } for (int i = next_i; i <= pos.x + 1; i++) { for (int j = next_j; j <= pos.y + 1; j++) { if (popped) { // The next loop over j must start normally next_j = pos.y; popped = false; // Skip because an iteration was already executed with current counter values continue; } if (i < rect.position.x || i >= rect.position.x + rect.size.x) continue; if (j < rect.position.y || j >= rect.position.y + rect.size.y) continue; if (p_map->get_bit(Vector2(i, j))) continue; else if (p_src->get_bit(Vector2(i, j))) { p_map->set_bit(Vector2(i, j), true); FillBitsStackEntry se = { pos, i, j }; stack.resize(MAX(stack_size + 1, stack.size())); stack.set(stack_size, se); stack_size++; pos = Point2i(i, j); reenter = true; break; } } if (reenter) { break; } } if (!reenter) { if (stack_size) { FillBitsStackEntry se = stack.get(stack_size - 1); stack_size--; pos = se.pos; next_i = se.i; next_j = se.j; popped = true; } } } while (reenter || popped); print_verbose("BitMap: Max stack size: " + itos(stack.size())); }
int pass_3(void) { struct section_def *s; struct label_def *l; struct block *b; FILE *f_in; int bank = 0, slot = 0, add = 0, file_name_id = 0, inz, line_number = 0, o, add_old = 0; #ifdef W65816 int base = 0x00; #endif char c; s = NULL; print_verbose("Internal pass 1...\n"); if ((f_in = fopen(gba_tmp_name, "rb")) == NULL) { fprintf(stderr, "INTERNAL_PASS_1: Error opening file \"%s\".\n", gba_tmp_name); return FAILED; } /* first loop */ o = 0; if (output_format == OUTPUT_OBJECT) { while (o == 0 && fread(&c, 1, 1, f_in) != 0) { switch (c) { case ' ': case 'E': continue; case 'P': add_old = add; continue; case 'p': add = add_old; continue; case 'x': fscanf(f_in, "%d %*d ", &inz); if (section_status == ON) { add += inz; continue; } fprintf(stderr, "INTERNAL_PASS_1: .ORG needs to be set before any code/data can be accepted.\n"); return FAILED; case 'd': if (section_status == ON) { fscanf(f_in, "%*s "); add++; continue; } fprintf(stderr, "INTERNAL_PASS_1: .ORG needs to be set before any code/data can be accepted.\n"); return FAILED; case 'y': if (section_status == ON) { fscanf(f_in, "%*d "); add += 2; continue; } fprintf(stderr, "INTERNAL_PASS_1: .ORG needs to be set before any code/data can be accepted.\n"); return FAILED; #ifdef W65816 case 'b': fscanf(f_in, "%d ", &base); continue; #endif case 'f': fscanf(f_in, "%d ", &file_name_id); continue; case 'B': fscanf(f_in, "%d %d ", &bank, &slot); continue; case 'k': fscanf(f_in, "%d ", &line_number); continue; case 'g': b = malloc(sizeof(struct block)); if (b == NULL) { fscanf(f_in, "%64s ", tmp); fprintf(stderr, "%s:%d INTERNAL_PASS_1: Out of memory while trying to allocate room for block \"%s\".\n", get_file_name(file_name_id), line_number, tmp); return FAILED; } b->filename_id = file_name_id; b->line_number = line_number; b->next = blocks; blocks = b; fscanf(f_in, "%64s ", b->name); b->address = add; continue; case 'G': b = blocks; blocks = blocks->next; fprintf(stderr, "INTERNAL_PASS_1: Block \"%s\" is %d bytes.\n", b->name, add - b->address); free(b); continue; case 'Z': case 'Y': case 'L': l = malloc(sizeof(struct label_def)); if (l == NULL) { fscanf(f_in, "%64s ", tmp); fprintf(stderr, "%s:%d INTERNAL_PASS_1: Out of memory while trying to allocate room for label \"%s\".\n", get_file_name(file_name_id), line_number, tmp); return FAILED; } if (c == 'Y') l->symbol = 1; else if (c == 'L') l->symbol = 0; else l->symbol = 2; if (c == 'Z') l->label[0] = 0; else fscanf(f_in, "%64s ", l->label); l->next = NULL; l->section_status = ON; l->filename_id = file_name_id; l->linenumber = line_number; l->alive = ON; l->section_id = s->id; /* section labels get a relative address */ l->address = add; l->bank = s->bank; l->slot = s->slot; #ifdef W65816 l->base = base; #endif if (c == 'Z' || is_label_anonymous(l->label) == SUCCEEDED || strcmp(l->label, "__") == 0) { if (labels != NULL) { label_last->next = l; label_last = l; } else { labels = l; label_last = l; } continue; } label_next = labels; while (label_next != NULL) { if (strcmp(l->label, label_next->label) == 0) { if ((l->label[0] != '_') || /* both are not local labels */ (section_status == OFF && label_next->section_status == OFF) || (section_status == ON && label_next->section_status == ON && label_next->section_id == l->section_id)) { fprintf(stderr, "%s:%d: INTERNAL_PASS_1: Label \"%s\" was defined for the second time.\n", get_file_name(file_name_id), line_number, l->label); return FAILED; } } label_next = label_next->next; } if (labels != NULL) { label_last->next = l; label_last = l; } else { labels = l; label_last = l; } continue; case 'S': fscanf(f_in, "%d ", &inz); add_old = add; s = sections_first; while (s->id != inz) s = s->next; /* a RAMSECTION? */ if (s->status == SECTION_STATUS_RAM) { s->address = 0; s->listfile_items = 1; s->listfile_ints = NULL; s->listfile_cmds = NULL; add = 0; section_status = ON; continue; } fprintf(stderr, "INTERNAL_PASS_1: .ORG needs to be set before any code/data can be accepted.\n"); return FAILED; case 's': s->size = add - s->address; /* discard an empty section? */ if (s->size == 0) { fprintf(stderr, "INTERNAL_PASS_1: %s: Discarding an empty section \"%s\".\n", get_file_name(file_name_id), s->name); s->alive = OFF; /* discard all labels which belong to this section */ l = labels; while (l != NULL) { if (l->section_status == ON && l->section_id == s->id) l->alive = OFF; l = l->next; } } if (s->advance_org == NO) add = add_old; section_status = OFF; s = NULL; continue; case 'O': fscanf(f_in, "%d ", &add); o++; continue; default: fprintf(stderr, "INTERNAL_PASS_1: .ORG needs to be set before any code/data can be accepted.\n"); return FAILED; } } } else { while (o == 0 && fread(&c, 1, 1, f_in) != 0) { switch (c) { case ' ': case 'E': continue; case 'f': fscanf(f_in, "%d ", &file_name_id); continue; case 'S': fscanf(f_in, "%d ", &inz); add_old = add; s = sections_first; while (s->id != inz) s = s->next; if (s->status == SECTION_STATUS_FREE) add = 0; s->address = add; s->bank = bank; s->slot = slot; s->listfile_items = 1; s->listfile_ints = NULL; s->listfile_cmds = NULL; section_status = ON; o++; continue; default: fprintf(stderr, "INTERNAL_PASS_1: A section must be open before any code/data can be accepted.\n"); return FAILED; } } } /* second (major) loop */ while (fread(&c, 1, 1, f_in) != 0) { switch (c) { case ' ': case 'E': continue; case 'P': add_old = add; continue; case 'p': add = add_old; continue; case 'A': case 'S': if (c == 'A') fscanf(f_in, "%d %*d", &inz); else fscanf(f_in, "%d ", &inz); add_old = add; s = sections_first; while (s->id != inz) s = s->next; if (s->status == SECTION_STATUS_FREE || s->status == SECTION_STATUS_RAM) add = 0; if (s->status != SECTION_STATUS_RAM) { s->bank = bank; s->slot = slot; } s->address = add; s->listfile_items = 1; s->listfile_ints = NULL; s->listfile_cmds = NULL; section_status = ON; continue; case 's': s->size = add - s->address; /* discard an empty section? */ if (s->size == 0) { fprintf(stderr, "DISCARD: %s: Discarding an empty section \"%s\".\n", get_file_name(file_name_id), s->name); s->alive = OFF; /* discard all labels which belong to this section */ l = labels; while (l != NULL) { if (l->section_status == ON && l->section_id == s->id) l->alive = OFF; l = l->next; } } /* some sections don't affect the ORG outside of them */ if (s->advance_org == NO) add = add_old; section_status = OFF; s = NULL; continue; case 'x': fscanf(f_in, "%d %*d ", &inz); add += inz; continue; case 'X': fscanf(f_in, "%d %*d ", &inz); add += inz << 1; continue; #ifdef W65816 case 'z': case 'q': fscanf(f_in, "%*s "); add += 3; continue; case 'T': fscanf(f_in, "%*d "); add += 3; continue; case 'b': fscanf(f_in, "%d ", &base); continue; #endif case 'R': case 'Q': case 'd': case 'c': fscanf(f_in, "%*s "); add++; continue; #ifdef W65816 case 'M': #endif case 'r': fscanf(f_in, "%*s "); add += 2; continue; case 'y': case 'C': fscanf(f_in, "%*d "); add += 2; continue; case 'D': fscanf(f_in, "%*d %*d %*d %d ", &inz); add += inz; continue; case 'O': fscanf(f_in, "%d ", &add); continue; case 'B': fscanf(f_in, "%d %d ", &bank, &slot); continue; case 'g': b = malloc(sizeof(struct block)); if (b == NULL) { fscanf(f_in, "%64s ", tmp); fprintf(stderr, "%s:%d INTERNAL_PASS_1: Out of memory while trying to allocate room for block \"%s\".\n", get_file_name(file_name_id), line_number, tmp); return FAILED; } b->filename_id = file_name_id; b->line_number = line_number; b->next = blocks; blocks = b; fscanf(f_in, "%64s ", b->name); b->address = add; continue; case 'G': b = blocks; blocks = blocks->next; fprintf(stderr, "INTERNAL_PASS_1: Block \"%s\" is %d bytes.\n", b->name, add - b->address); free(b); continue; case 'Z': case 'Y': case 'L': l = malloc(sizeof(struct label_def)); if (l == NULL) { fscanf(f_in, "%64s ", tmp); fprintf(stderr, "%s:%d INTERNAL_PASS_1: Out of memory while trying to allocate room for label \"%s\".\n", get_file_name(file_name_id), line_number, tmp); return FAILED; } if (c == 'Y') l->symbol = 1; else if (c == 'L') l->symbol = 0; else l->symbol = 2; if (c == 'Z') l->label[0] = 0; else fscanf(f_in, "%64s ", l->label); l->next = NULL; l->section_status = section_status; l->filename_id = file_name_id; l->linenumber = line_number; l->alive = ON; if (section_status == ON) { l->section_id = s->id; /* section labels get a relative address */ l->address = add - s->address; l->bank = s->bank; l->slot = s->slot; } else { l->section_id = 0; l->address = add; l->bank = bank; l->slot = slot; } #ifdef W65816 l->base = base; #endif if (c == 'Z' || is_label_anonymous(l->label) == SUCCEEDED || strcmp(l->label, "__") == 0) { if (labels != NULL) { label_last->next = l; label_last = l; } else { labels = l; label_last = l; } continue; } label_next = labels; while (label_next != NULL) { if (strcmp(l->label, label_next->label) == 0) { if ((l->label[0] != '_') || /* both are not local labels */ (section_status == OFF && label_next->section_status == OFF) || (section_status == ON && label_next->section_status == ON && label_next->section_id == l->section_id)) { fprintf(stderr, "%s:%d: INTERNAL_PASS_1: Label \"%s\" was defined for the second time.\n", get_file_name(file_name_id), line_number, l->label); return FAILED; } } label_next = label_next->next; } if (labels != NULL) { label_last->next = l; label_last = l; } else { labels = l; label_last = l; } continue; case 'f': fscanf(f_in, "%d ", &file_name_id); if (s != NULL) s->listfile_items++; continue; case 'k': fscanf(f_in, "%d ", &line_number); if (s != NULL) s->listfile_items++; continue; default: fprintf(stderr, "%s: INTERNAL_PASS_1: Unknown internal symbol \"%c\".\n", get_file_name(file_name_id), c); return FAILED; } } fclose(f_in); if (blocks != NULL) { fprintf(stderr, "%s:%d INTERNAL_PASS_1: .BLOCK \"%s\" was left open.\n", get_file_name(blocks->filename_id), blocks->line_number, blocks->name); return FAILED; } return SUCCEEDED; }
void print_failed_address() { print_verbose("Could not reach node by address\n"); }
static struct ref *do_fetch_pack(struct fetch_pack_args *args, int fd[2], const struct ref *orig_ref, struct ref **sought, int nr_sought, struct shallow_info *si, char **pack_lockfile) { struct ref *ref = copy_ref_list(orig_ref); unsigned char sha1[20]; const char *agent_feature; int agent_len; sort_ref_list(&ref, ref_compare_name); QSORT(sought, nr_sought, cmp_ref_by_name); if ((args->depth > 0 || is_repository_shallow()) && !server_supports("shallow")) die(_("Server does not support shallow clients")); if (args->depth > 0 || args->deepen_since || args->deepen_not) args->deepen = 1; if (server_supports("multi_ack_detailed")) { print_verbose(args, _("Server supports multi_ack_detailed")); multi_ack = 2; if (server_supports("no-done")) { print_verbose(args, _("Server supports no-done")); if (args->stateless_rpc) no_done = 1; } } else if (server_supports("multi_ack")) { print_verbose(args, _("Server supports multi_ack")); multi_ack = 1; } if (server_supports("side-band-64k")) { print_verbose(args, _("Server supports side-band-64k")); use_sideband = 2; } else if (server_supports("side-band")) { print_verbose(args, _("Server supports side-band")); use_sideband = 1; } if (server_supports("allow-tip-sha1-in-want")) { print_verbose(args, _("Server supports allow-tip-sha1-in-want")); allow_unadvertised_object_request |= ALLOW_TIP_SHA1; } if (server_supports("allow-reachable-sha1-in-want")) { print_verbose(args, _("Server supports allow-reachable-sha1-in-want")); allow_unadvertised_object_request |= ALLOW_REACHABLE_SHA1; } if (!server_supports("thin-pack")) args->use_thin_pack = 0; if (!server_supports("no-progress")) args->no_progress = 0; if (!server_supports("include-tag")) args->include_tag = 0; if (server_supports("ofs-delta")) print_verbose(args, _("Server supports ofs-delta")); else prefer_ofs_delta = 0; if ((agent_feature = server_feature_value("agent", &agent_len))) { agent_supported = 1; if (agent_len) print_verbose(args, _("Server version is %.*s"), agent_len, agent_feature); } if (server_supports("deepen-since")) deepen_since_ok = 1; else if (args->deepen_since) die(_("Server does not support --shallow-since")); if (server_supports("deepen-not")) deepen_not_ok = 1; else if (args->deepen_not) die(_("Server does not support --shallow-exclude")); if (!server_supports("deepen-relative") && args->deepen_relative) die(_("Server does not support --deepen")); if (everything_local(args, &ref, sought, nr_sought)) { packet_flush(fd[1]); goto all_done; } if (find_common(args, fd, sha1, ref) < 0) if (!args->keep_pack) /* When cloning, it is not unusual to have * no common commit. */ warning(_("no common commits")); if (args->stateless_rpc) packet_flush(fd[1]); if (args->deepen) setup_alternate_shallow(&shallow_lock, &alternate_shallow_file, NULL); else if (si->nr_ours || si->nr_theirs) alternate_shallow_file = setup_temporary_shallow(si->shallow); else alternate_shallow_file = NULL; if (get_pack(args, fd, pack_lockfile)) die(_("git fetch-pack: fetch failed.")); all_done: return ref; }
static void show_summary(void) { /* OK, if verbosity set, print summary of options selected */ if (!INFO) { if (!TEST_ONLY) print_verbose("The following options are in effect for this %s.\n", DECOMPRESS ? "DECOMPRESSION" : "COMPRESSION"); print_verbose("Threading is %s. Number of CPUs detected: %d\n", control->threads > 1? "ENABLED" : "DISABLED", control->threads); print_verbose("Detected %lld bytes ram\n", control->ramsize); print_verbose("Compression level %d\n", control->compression_level); print_verbose("Nice Value: %d\n", control->nice_val); print_verbose("Show Progress\n"); print_maxverbose("Max "); print_verbose("Verbose\n"); if (FORCE_REPLACE) print_verbose("Overwrite Files\n"); if (!KEEP_FILES) print_verbose("Remove input files on completion\n"); if (control->outdir) print_verbose("Output Directory Specified: %s\n", control->outdir); else if (control->outname) print_verbose("Output Filename Specified: %s\n", control->outname); if (TEST_ONLY) print_verbose("Test file integrity\n"); if (control->tmpdir) print_verbose("Temporary Directory set as: %s\n", control->tmpdir); /* show compression options */ if (!DECOMPRESS && !TEST_ONLY) { print_verbose("Compression mode is: "); if (LZMA_COMPRESS) print_verbose("LZMA. LZO Compressibility testing %s\n", (LZO_TEST? "enabled" : "disabled")); else if (LZO_COMPRESS) print_verbose("LZO\n"); else if (BZIP2_COMPRESS) print_verbose("BZIP2. LZO Compressibility testing %s\n", (LZO_TEST? "enabled" : "disabled")); else if (ZLIB_COMPRESS) print_verbose("GZIP\n"); else if (ZPAQ_COMPRESS) print_verbose("ZPAQ. LZO Compressibility testing %s\n", (LZO_TEST? "enabled" : "disabled")); else if (NO_COMPRESS) print_verbose("RZIP pre-processing only\n"); if (control->window) print_verbose("Compression Window: %lld = %lldMB\n", control->window, control->window * 100ull); /* show heuristically computed window size */ if (!control->window && !UNLIMITED) { i64 temp_chunk, temp_window; if (STDOUT || STDIN) temp_chunk = control->maxram; else temp_chunk = control->ramsize * 2 / 3; temp_window = temp_chunk / (100 * 1024 * 1024); print_verbose("Heuristically Computed Compression Window: %lld = %lldMB\n", temp_window, temp_window * 100ull); } if (UNLIMITED) print_verbose("Using Unlimited Window size\n"); } if (!DECOMPRESS && !TEST_ONLY) print_maxverbose("Storage time in seconds %lld\n", control->secs); if (ENCRYPT) print_maxverbose("Encryption hash loops %lld\n", control->encloops); } }
RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p_no_cache, Error *r_error) { if (r_error) *r_error = ERR_CANT_OPEN; String local_path; if (p_path.is_rel_path()) local_path = "res://" + p_path; else local_path = ProjectSettings::get_singleton()->localize_path(p_path); if (!p_no_cache) { //lock first if possible if (ResourceCache::lock) { ResourceCache::lock->read_lock(); } //get ptr Resource **rptr = ResourceCache::resources.getptr(local_path); if (rptr) { RES res(*rptr); //it is possible this resource was just freed in a thread. If so, this referencing will not work and resource is considered not cached if (res.is_valid()) { //referencing is fine if (r_error) *r_error = OK; if (ResourceCache::lock) { ResourceCache::lock->read_unlock(); } print_verbose("Loading resource: " + local_path + " (cached)"); return res; } } if (ResourceCache::lock) { ResourceCache::lock->read_unlock(); } } bool xl_remapped = false; String path = _path_remap(local_path, &xl_remapped); ERR_FAIL_COND_V(path == "", RES()); print_verbose("Loading resource: " + path); RES res = _load(path, local_path, p_type_hint, p_no_cache, r_error); if (res.is_null()) { return RES(); } if (!p_no_cache) res->set_path(local_path); if (xl_remapped) res->set_as_translation_remapped(true); #ifdef TOOLS_ENABLED res->set_edited(false); if (timestamp_on_load) { uint64_t mt = FileAccess::get_modified_time(path); //printf("mt %s: %lli\n",remapped_path.utf8().get_data(),mt); res->set_last_modified_time(mt); } #endif return res; }
void EditorFileServer::_subthread_start(void *s) { ClientData *cd = (ClientData *)s; cd->connection->set_no_delay(true); uint8_t buf4[8]; Error err = cd->connection->get_data(buf4, 4); if (err != OK) { _close_client(cd); ERR_FAIL_COND(err != OK); } int passlen = decode_uint32(buf4); if (passlen > 512) { _close_client(cd); ERR_FAIL_COND(passlen > 512); } else if (passlen > 0) { Vector<char> passutf8; passutf8.resize(passlen + 1); err = cd->connection->get_data((uint8_t *)passutf8.ptr(), passlen); if (err != OK) { _close_client(cd); ERR_FAIL_COND(err != OK); } passutf8.write[passlen] = 0; String s; s.parse_utf8(passutf8.ptr()); if (s != cd->efs->password) { encode_uint32(ERR_INVALID_DATA, buf4); cd->connection->put_data(buf4, 4); OS::get_singleton()->delay_usec(1000000); _close_client(cd); ERR_PRINT("CLIENT PASSWORD MISMATCH"); ERR_FAIL(); } } else { if (cd->efs->password != "") { encode_uint32(ERR_INVALID_DATA, buf4); cd->connection->put_data(buf4, 4); OS::get_singleton()->delay_usec(1000000); _close_client(cd); ERR_PRINT("CLIENT PASSWORD MISMATCH (should be empty!)"); ERR_FAIL(); } } encode_uint32(OK, buf4); cd->connection->put_data(buf4, 4); while (!cd->quit) { //wait for ID err = cd->connection->get_data(buf4, 4); DEBUG_TIME("get_data") if (err != OK) { _close_client(cd); ERR_FAIL_COND(err != OK); } int id = decode_uint32(buf4); //wait for command err = cd->connection->get_data(buf4, 4); if (err != OK) { _close_client(cd); ERR_FAIL_COND(err != OK); } int cmd = decode_uint32(buf4); switch (cmd) { case FileAccessNetwork::COMMAND_FILE_EXISTS: case FileAccessNetwork::COMMAND_GET_MODTIME: case FileAccessNetwork::COMMAND_OPEN_FILE: { DEBUG_TIME("open_file") err = cd->connection->get_data(buf4, 4); if (err != OK) { _close_client(cd); ERR_FAIL_COND(err != OK); } int namelen = decode_uint32(buf4); Vector<char> fileutf8; fileutf8.resize(namelen + 1); err = cd->connection->get_data((uint8_t *)fileutf8.ptr(), namelen); if (err != OK) { _close_client(cd); ERR_FAIL_COND(err != OK); } fileutf8.write[namelen] = 0; String s; s.parse_utf8(fileutf8.ptr()); if (cmd == FileAccessNetwork::COMMAND_FILE_EXISTS) { print_verbose("FILE EXISTS: " + s); } if (cmd == FileAccessNetwork::COMMAND_GET_MODTIME) { print_verbose("MOD TIME: " + s); } if (cmd == FileAccessNetwork::COMMAND_OPEN_FILE) { print_verbose("OPEN: " + s); } if (!s.begins_with("res://")) { _close_client(cd); ERR_FAIL_COND(!s.begins_with("res://")); } ERR_CONTINUE(cd->files.has(id)); if (cmd == FileAccessNetwork::COMMAND_FILE_EXISTS) { encode_uint32(id, buf4); cd->connection->put_data(buf4, 4); encode_uint32(FileAccessNetwork::RESPONSE_FILE_EXISTS, buf4); cd->connection->put_data(buf4, 4); encode_uint32(FileAccess::exists(s), buf4); cd->connection->put_data(buf4, 4); DEBUG_TIME("open_file_end") break; } if (cmd == FileAccessNetwork::COMMAND_GET_MODTIME) { encode_uint32(id, buf4); cd->connection->put_data(buf4, 4); encode_uint32(FileAccessNetwork::RESPONSE_GET_MODTIME, buf4); cd->connection->put_data(buf4, 4); encode_uint64(FileAccess::get_modified_time(s), buf4); cd->connection->put_data(buf4, 8); DEBUG_TIME("open_file_end") break; } FileAccess *fa = FileAccess::open(s, FileAccess::READ); if (!fa) { //not found, continue encode_uint32(id, buf4); cd->connection->put_data(buf4, 4); encode_uint32(FileAccessNetwork::RESPONSE_OPEN, buf4); cd->connection->put_data(buf4, 4); encode_uint32(ERR_FILE_NOT_FOUND, buf4); cd->connection->put_data(buf4, 4); DEBUG_TIME("open_file_end") break; } encode_uint32(id, buf4); cd->connection->put_data(buf4, 4); encode_uint32(FileAccessNetwork::RESPONSE_OPEN, buf4); cd->connection->put_data(buf4, 4); encode_uint32(OK, buf4); cd->connection->put_data(buf4, 4); encode_uint64(fa->get_len(), buf4); cd->connection->put_data(buf4, 8); cd->files[id] = fa; DEBUG_TIME("open_file_end") } break;
void kill_daemon() { print_verbose("Received stop command. Goodbye.\n"); terminate_config(); exit(0); }
Error AudioDriverCoreAudio::init() { mutex = Mutex::create(); AudioComponentDescription desc; zeromem(&desc, sizeof(desc)); desc.componentType = kAudioUnitType_Output; #ifdef OSX_ENABLED desc.componentSubType = kAudioUnitSubType_HALOutput; #else desc.componentSubType = kAudioUnitSubType_RemoteIO; #endif desc.componentManufacturer = kAudioUnitManufacturer_Apple; AudioComponent comp = AudioComponentFindNext(NULL, &desc); ERR_FAIL_COND_V(comp == NULL, FAILED); OSStatus result = AudioComponentInstanceNew(comp, &audio_unit); ERR_FAIL_COND_V(result != noErr, FAILED); #ifdef OSX_ENABLED AudioObjectPropertyAddress prop; prop.mSelector = kAudioHardwarePropertyDefaultOutputDevice; prop.mScope = kAudioObjectPropertyScopeGlobal; prop.mElement = kAudioObjectPropertyElementMaster; result = AudioObjectAddPropertyListener(kAudioObjectSystemObject, &prop, &output_device_address_cb, this); ERR_FAIL_COND_V(result != noErr, FAILED); prop.mSelector = kAudioHardwarePropertyDefaultInputDevice; result = AudioObjectAddPropertyListener(kAudioObjectSystemObject, &prop, &input_device_address_cb, this); ERR_FAIL_COND_V(result != noErr, FAILED); #endif AudioStreamBasicDescription strdesc; zeromem(&strdesc, sizeof(strdesc)); UInt32 size = sizeof(strdesc); result = AudioUnitGetProperty(audio_unit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, kOutputBus, &strdesc, &size); ERR_FAIL_COND_V(result != noErr, FAILED); switch (strdesc.mChannelsPerFrame) { case 2: // Stereo case 4: // Surround 3.1 case 6: // Surround 5.1 case 8: // Surround 7.1 channels = strdesc.mChannelsPerFrame; break; default: // Unknown number of channels, default to stereo channels = 2; break; } zeromem(&strdesc, sizeof(strdesc)); size = sizeof(strdesc); result = AudioUnitGetProperty(audio_unit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, kInputBus, &strdesc, &size); ERR_FAIL_COND_V(result != noErr, FAILED); switch (strdesc.mChannelsPerFrame) { case 1: // Mono capture_channels = 1; break; case 2: // Stereo capture_channels = 2; break; default: // Unknown number of channels, default to stereo capture_channels = 2; break; } mix_rate = GLOBAL_DEF_RST("audio/mix_rate", DEFAULT_MIX_RATE); zeromem(&strdesc, sizeof(strdesc)); strdesc.mFormatID = kAudioFormatLinearPCM; strdesc.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked; strdesc.mChannelsPerFrame = channels; strdesc.mSampleRate = mix_rate; strdesc.mFramesPerPacket = 1; strdesc.mBitsPerChannel = 16; strdesc.mBytesPerFrame = strdesc.mBitsPerChannel * strdesc.mChannelsPerFrame / 8; strdesc.mBytesPerPacket = strdesc.mBytesPerFrame * strdesc.mFramesPerPacket; result = AudioUnitSetProperty(audio_unit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, kOutputBus, &strdesc, sizeof(strdesc)); ERR_FAIL_COND_V(result != noErr, FAILED); strdesc.mChannelsPerFrame = capture_channels; result = AudioUnitSetProperty(audio_unit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, kInputBus, &strdesc, sizeof(strdesc)); ERR_FAIL_COND_V(result != noErr, FAILED); int latency = GLOBAL_DEF_RST("audio/output_latency", DEFAULT_OUTPUT_LATENCY); // Sample rate is independent of channels (ref: https://stackoverflow.com/questions/11048825/audio-sample-frequency-rely-on-channels) buffer_frames = closest_power_of_2(latency * mix_rate / 1000); #ifdef OSX_ENABLED result = AudioUnitSetProperty(audio_unit, kAudioDevicePropertyBufferFrameSize, kAudioUnitScope_Global, kOutputBus, &buffer_frames, sizeof(UInt32)); ERR_FAIL_COND_V(result != noErr, FAILED); #endif unsigned int buffer_size = buffer_frames * channels; samples_in.resize(buffer_size); input_buf.resize(buffer_size); input_buffer.resize(buffer_size * 8); input_position = 0; input_size = 0; print_verbose("CoreAudio: detected " + itos(channels) + " channels"); print_verbose("CoreAudio: audio buffer frames: " + itos(buffer_frames) + " calculated latency: " + itos(buffer_frames * 1000 / mix_rate) + "ms"); AURenderCallbackStruct callback; zeromem(&callback, sizeof(AURenderCallbackStruct)); callback.inputProc = &AudioDriverCoreAudio::output_callback; callback.inputProcRefCon = this; result = AudioUnitSetProperty(audio_unit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, kOutputBus, &callback, sizeof(callback)); ERR_FAIL_COND_V(result != noErr, FAILED); zeromem(&callback, sizeof(AURenderCallbackStruct)); callback.inputProc = &AudioDriverCoreAudio::input_callback; callback.inputProcRefCon = this; result = AudioUnitSetProperty(audio_unit, kAudioOutputUnitProperty_SetInputCallback, kAudioUnitScope_Global, 0, &callback, sizeof(callback)); ERR_FAIL_COND_V(result != noErr, FAILED); result = AudioUnitInitialize(audio_unit); ERR_FAIL_COND_V(result != noErr, FAILED); return OK; }
Error AudioDriverRtAudio::init() { active = false; mutex = Mutex::create(true); dac = memnew(RtAudio); ERR_EXPLAIN("Cannot initialize RtAudio audio driver: No devices present.") ERR_FAIL_COND_V(dac->getDeviceCount() < 1, ERR_UNAVAILABLE); // FIXME: Adapt to the OutputFormat -> SpeakerMode change /* String channels = GLOBAL_DEF_RST("audio/output","stereo"); if (channels=="5.1") output_format=OUTPUT_5_1; else if (channels=="quad") output_format=OUTPUT_QUAD; else if (channels=="mono") output_format=OUTPUT_MONO; else output_format=OUTPUT_STEREO; */ RtAudio::StreamParameters parameters; parameters.deviceId = dac->getDefaultOutputDevice(); RtAudio::StreamOptions options; // set the desired numberOfBuffers options.numberOfBuffers = 4; parameters.firstChannel = 0; mix_rate = GLOBAL_DEF_RST("audio/mix_rate", DEFAULT_MIX_RATE); int latency = GLOBAL_DEF("audio/output_latency", DEFAULT_OUTPUT_LATENCY); unsigned int buffer_frames = closest_power_of_2(latency * mix_rate / 1000); print_verbose("Audio buffer frames: " + itos(buffer_frames) + " calculated latency: " + itos(buffer_frames * 1000 / mix_rate) + "ms"); short int tries = 2; while (tries >= 0) { switch (speaker_mode) { case SPEAKER_MODE_STEREO: parameters.nChannels = 2; break; case SPEAKER_SURROUND_51: parameters.nChannels = 6; break; case SPEAKER_SURROUND_71: parameters.nChannels = 8; break; }; try { dac->openStream(¶meters, NULL, RTAUDIO_SINT32, mix_rate, &buffer_frames, &callback, this, &options); active = true; break; } catch (RtAudioError) { // try with less channels ERR_PRINT("Unable to open audio, retrying with fewer channels..."); switch (speaker_mode) { case SPEAKER_SURROUND_51: speaker_mode = SPEAKER_MODE_STEREO; break; case SPEAKER_SURROUND_71: speaker_mode = SPEAKER_SURROUND_51; break; } tries--; } } return active ? OK : ERR_UNAVAILABLE; }
int detect_prime() { pid_t p; int priorities[2]; String vendors[2]; String renderers[2]; vendors[0] = "Unknown"; vendors[1] = "Unknown"; renderers[0] = "Unknown"; renderers[1] = "Unknown"; for (int i = 0; i < 2; ++i) { int fdset[2]; if (pipe(fdset) == -1) { print_verbose("Failed to pipe(), using default GPU"); return 0; } // Fork so the driver initialization can crash without taking down the engine. p = fork(); if (p > 0) { // Main thread int stat_loc = 0; char string[201]; string[200] = '\0'; close(fdset[1]); waitpid(p, &stat_loc, 0); if (!stat_loc) { // No need to do anything complicated here. Anything less than // PIPE_BUF will be delivered in one read() call. read(fdset[0], string, sizeof(string) - 1); vendors[i] = string; renderers[i] = string + strlen(string) + 1; } close(fdset[0]); } else { // In child, exit() here will not quit the engine. char string[201]; close(fdset[0]); if (i) setenv("DRI_PRIME", "1", 1); create_context(); const char *vendor = (const char *)glGetString(GL_VENDOR); const char *renderer = (const char *)glGetString(GL_RENDERER); unsigned int vendor_len = strlen(vendor) + 1; unsigned int renderer_len = strlen(renderer) + 1; if (vendor_len + renderer_len >= sizeof(string)) { renderer_len = 200 - vendor_len; } memcpy(&string, vendor, vendor_len); memcpy(&string[vendor_len], renderer, renderer_len); write(fdset[1], string, vendor_len + renderer_len); close(fdset[1]); exit(0); } } int preferred = 0; int priority = 0; if (vendors[0] == vendors[1]) { print_verbose("Only one GPU found, using default."); return 0; } for (int i = 1; i >= 0; --i) { vendor *v = vendormap; while (v->glxvendor) { if (v->glxvendor == vendors[i]) { priorities[i] = v->priority; if (v->priority >= priority) { priority = v->priority; preferred = i; } } ++v; } } print_verbose("Found renderers:"); for (int i = 0; i < 2; ++i) { print_verbose("Renderer " + itos(i) + ": " + renderers[i] + " with priority: " + itos(priorities[i])); } print_verbose("Using renderer: " + renderers[preferred]); return preferred; }
void DependencyRemoveDialog::ok_pressed() { for (int i = 0; i < files_to_delete.size(); ++i) { if (ResourceCache::has(files_to_delete[i])) { Resource *res = ResourceCache::get(files_to_delete[i]); res->set_path(""); } // If the file we are deleting is the main scene or default environment, clear its definition. if (files_to_delete[i] == ProjectSettings::get_singleton()->get("application/run/main_scene")) { ProjectSettings::get_singleton()->set("application/run/main_scene", ""); } if (files_to_delete[i] == ProjectSettings::get_singleton()->get("rendering/environment/default_environment")) { ProjectSettings::get_singleton()->set("rendering/environment/default_environment", ""); } String path = OS::get_singleton()->get_resource_dir() + files_to_delete[i].replace_first("res://", "/"); print_verbose("Moving to trash: " + path); Error err = OS::get_singleton()->move_to_trash(path); if (err != OK) { EditorNode::get_singleton()->add_io_error(TTR("Cannot remove:") + "\n" + files_to_delete[i] + "\n"); } else { emit_signal("file_removed", files_to_delete[i]); } } if (dirs_to_delete.size() == 0) { // If we only deleted files we should only need to tell the file system about the files we touched. for (int i = 0; i < files_to_delete.size(); ++i) EditorFileSystem::get_singleton()->update_file(files_to_delete[i]); } else { for (int i = 0; i < dirs_to_delete.size(); ++i) { String path = OS::get_singleton()->get_resource_dir() + dirs_to_delete[i].replace_first("res://", "/"); print_verbose("Moving to trash: " + path); Error err = OS::get_singleton()->move_to_trash(path); if (err != OK) { EditorNode::get_singleton()->add_io_error(TTR("Cannot remove:") + "\n" + dirs_to_delete[i] + "\n"); } else { emit_signal("folder_removed", dirs_to_delete[i]); } } EditorFileSystem::get_singleton()->scan_changes(); } // If some files/dirs would be deleted, favorite dirs need to be updated Vector<String> previous_favorites = EditorSettings::get_singleton()->get_favorites(); Vector<String> new_favorites; for (int i = 0; i < previous_favorites.size(); ++i) { if (previous_favorites[i].ends_with("/")) { if (dirs_to_delete.find(previous_favorites[i]) < 0) new_favorites.push_back(previous_favorites[i]); } else { if (files_to_delete.find(previous_favorites[i]) < 0) new_favorites.push_back(previous_favorites[i]); } } if (new_favorites.size() < previous_favorites.size()) { EditorSettings::get_singleton()->set_favorites(new_favorites); } }
static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out, const struct fetch_pack_args *args, const struct ref *wants, struct oidset *common, int *haves_to_send, int *in_vain) { int ret = 0; struct strbuf req_buf = STRBUF_INIT; if (server_supports_v2("fetch", 1)) packet_buf_write(&req_buf, "command=fetch"); if (server_supports_v2("agent", 0)) packet_buf_write(&req_buf, "agent=%s", git_user_agent_sanitized()); if (args->server_options && args->server_options->nr && server_supports_v2("server-option", 1)) { int i; for (i = 0; i < args->server_options->nr; i++) packet_write_fmt(fd_out, "server-option=%s", args->server_options->items[i].string); } packet_buf_delim(&req_buf); if (args->use_thin_pack) packet_buf_write(&req_buf, "thin-pack"); if (args->no_progress) packet_buf_write(&req_buf, "no-progress"); if (args->include_tag) packet_buf_write(&req_buf, "include-tag"); if (prefer_ofs_delta) packet_buf_write(&req_buf, "ofs-delta"); /* Add shallow-info and deepen request */ if (server_supports_feature("fetch", "shallow", 0)) add_shallow_requests(&req_buf, args); else if (is_repository_shallow(the_repository) || args->deepen) die(_("Server does not support shallow requests")); /* Add filter */ if (server_supports_feature("fetch", "filter", 0) && args->filter_options.choice) { print_verbose(args, _("Server supports filter")); packet_buf_write(&req_buf, "filter %s", args->filter_options.filter_spec); } else if (args->filter_options.choice) { warning("filtering not recognized by server, ignoring"); } /* add wants */ add_wants(args->no_dependents, wants, &req_buf); if (args->no_dependents) { packet_buf_write(&req_buf, "done"); ret = 1; } else { /* Add all of the common commits we've found in previous rounds */ add_common(&req_buf, common); /* Add initial haves */ ret = add_haves(negotiator, &req_buf, haves_to_send, in_vain); } /* Send request */ packet_buf_flush(&req_buf); write_or_die(fd_out, req_buf.buf, req_buf.len); strbuf_release(&req_buf); return ret; }
static int simulate_using_nn_scoring (struct brot_args_info* brot_args, SeqMatrix* sm, Scmf_Rna_Opt_data* data, GFile* entropy_file, GFile* simulation_file) { int error = 0; char** bp_allowed = NULL; char bi, bj; long int seed; unsigned long i, j, k; unsigned long alpha_size = alphabet_size (scmf_rna_opt_data_get_alphabet(data)); unsigned long allowed_bp = 0; NN_scores* scores = /* SB: 17.11.09 50 */ NN_SCORES_NEW_INIT(50.0f, scmf_rna_opt_data_get_alphabet (data)); if (scores == NULL) { error = 1; } /* prepare index of allowed base pairs */ if (!error) { /* "randomise" scoring function */ print_verbose ("# Random seed (-r): "); if (brot_args->seed_given) { if (brot_args->seed_arg != 0) { print_verbose ("%ld\n", brot_args->seed_arg); nn_scores_add_thermal_noise (alpha_size, brot_args->seed_arg, scores); } else { print_verbose ("disabled\n"); } } else { /* if no seed is given, use time */ seed = (long int) time(NULL); print_verbose ("%ld\n", seed); nn_scores_add_thermal_noise (alpha_size, seed, scores); } bp_allowed = XMALLOC(alpha_size * sizeof (*bp_allowed)); if (bp_allowed == NULL) { error = 1; } } if (!error) { allowed_bp = nn_scores_no_allowed_basepairs (scores); /* we need 1 byte for each possible pair + 1byte for the NULL byte for each letter in the alphabet */ bp_allowed[0] = XCALLOC (allowed_bp + alpha_size, sizeof (**(bp_allowed))); if (bp_allowed[0] == NULL) { error = 1; } } if (!error) { i = 0; k = 0; while (i < alpha_size) { bp_allowed[i] = bp_allowed[0] + (k * sizeof (**(bp_allowed))); for (j = 0; j < allowed_bp; j++) { nn_scores_get_allowed_basepair (j, &bi, &bj, scores); if (i == (unsigned) bi) { bp_allowed[0][k] = (char)(bj + 1); k++; } } k++; i++; } } /* decompose secondary structure */ if (!error) { error = scmf_rna_opt_data_secstruct_init (data); } /*mfprintf (stdout, "TREATMENT of fixed sites: If both sites of a pair are " "fixed, delete from list? Verbose info!!!\n");*/ /* set our special function for calc. cols.: Iterate over sec.struct., not sequence matrix! */ if (!error) { scmf_rna_opt_data_set_scores (scores, data); scmf_rna_opt_data_set_bp_allowed (bp_allowed, data); scmf_rna_opt_data_set_scales (brot_args->negative_design_scaling_arg, brot_args->heterogenity_term_scaling_arg, data); scmf_rna_opt_data_set_het_window (brot_args->window_size_arg, data); seqmatrix_set_func_calc_eeff_col (scmf_rna_opt_calc_col_nn, sm); seqmatrix_set_gas_constant (8.314472, sm); seqmatrix_set_transform_row (scmf_rna_opt_data_transform_row_2_base, sm); /* SB 27.11.09 moved here */ seqmatrix_set_get_seq_string (scmf_rna_opt_data_get_seq_sm, sm); error = seqmatrix_simulate_scmf (brot_args->steps_arg, brot_args->temp_arg, brot_args->beta_long_arg, brot_args->beta_short_arg, brot_args->speedup_threshold_arg, brot_args->min_cool_arg, /* brot_args->scale_cool_arg,*/ brot_args->lambda_arg, brot_args->sm_entropy_arg, entropy_file, simulation_file, sm, data); } /* collate */ if (!error) { /*seqmatrix_print_2_stdout (2, sm);*/ /* seqmatrix_set_transform_row (scmf_rna_opt_data_transform_row_2_base, sm); SB 27.11.09 moved before simulation*/ error = seqmatrix_collate_is (COLLATE_THRESH, brot_args->steps_arg / 2, brot_args->temp_arg, brot_args->beta_long_arg, brot_args->beta_short_arg, brot_args->speedup_threshold_arg, brot_args->min_cool_arg, brot_args->lambda_arg, /* brot_args->sm_entropy_arg, */ sm, data); /*error = seqmatrix_collate_mv (sm, data);*/ } /* first: iterate scmf on secstruct, not sm! */ nn_scores_delete (scores); scmf_rna_opt_data_set_scores (NULL, data); scmf_rna_opt_data_set_bp_allowed (NULL, data); XFREE (bp_allowed[0]); XFREE (bp_allowed); return error; }
void GDMono::initialize() { ERR_FAIL_NULL(Engine::get_singleton()); print_verbose("Mono: Initializing module..."); #ifdef DEBUG_METHODS_ENABLED _initialize_and_check_api_hashes(); #endif GDMonoLog::get_singleton()->initialize(); #ifdef MONO_PRINT_HANDLER_ENABLED mono_trace_set_print_handler(gdmono_MonoPrintCallback); mono_trace_set_printerr_handler(gdmono_MonoPrintCallback); #endif #ifdef WINDOWS_ENABLED mono_reg_info = MonoRegUtils::find_mono(); CharString assembly_dir; CharString config_dir; if (mono_reg_info.assembly_dir.length() && DirAccess::exists(mono_reg_info.assembly_dir)) { assembly_dir = mono_reg_info.assembly_dir.utf8(); } if (mono_reg_info.config_dir.length() && DirAccess::exists(mono_reg_info.config_dir)) { config_dir = mono_reg_info.config_dir.utf8(); } mono_set_dirs(assembly_dir.length() ? assembly_dir.get_data() : NULL, config_dir.length() ? config_dir.get_data() : NULL); #elif OSX_ENABLED mono_set_dirs(NULL, NULL); { const char *assembly_rootdir = mono_assembly_getrootdir(); const char *config_dir = mono_get_config_dir(); if (!assembly_rootdir || !config_dir || !DirAccess::exists(assembly_rootdir) || !DirAccess::exists(config_dir)) { Vector<const char *> locations; locations.push_back("/Library/Frameworks/Mono.framework/Versions/Current/"); locations.push_back("/usr/local/var/homebrew/linked/mono/"); for (int i = 0; i < locations.size(); i++) { String hint_assembly_rootdir = path_join(locations[i], "lib"); String hint_mscorlib_path = path_join(hint_assembly_rootdir, "mono", "4.5", "mscorlib.dll"); String hint_config_dir = path_join(locations[i], "etc"); if (FileAccess::exists(hint_mscorlib_path) && DirAccess::exists(hint_config_dir)) { mono_set_dirs(hint_assembly_rootdir.utf8().get_data(), hint_config_dir.utf8().get_data()); break; } } } } #else mono_set_dirs(NULL, NULL); #endif GDMonoAssembly::initialize(); #ifdef DEBUG_ENABLED gdmono_debug_init(); #endif mono_config_parse(NULL); mono_install_unhandled_exception_hook(&unhandled_exception_hook, NULL); root_domain = mono_jit_init_version("GodotEngine.RootDomain", "v4.0.30319"); ERR_EXPLAIN("Mono: Failed to initialize runtime"); ERR_FAIL_NULL(root_domain); GDMonoUtils::set_main_thread(GDMonoUtils::get_current_thread()); setup_runtime_main_args(); // Required for System.Environment.GetCommandLineArgs runtime_initialized = true; print_verbose("Mono: Runtime initialized"); // mscorlib assembly MUST be present at initialization ERR_EXPLAIN("Mono: Failed to load mscorlib assembly"); ERR_FAIL_COND(!_load_corlib_assembly()); #ifdef TOOLS_ENABLED // The tools domain must be loaded here, before the scripts domain. // Otherwise domain unload on the scripts domain will hang indefinitely. ERR_EXPLAIN("Mono: Failed to load tools domain"); ERR_FAIL_COND(_load_tools_domain() != OK); // TODO move to editor init callback, and do it lazily when required before editor init (e.g.: bindings generation) ERR_EXPLAIN("Mono: Failed to load Editor Tools assembly"); ERR_FAIL_COND(!_load_editor_tools_assembly()); #endif ERR_EXPLAIN("Mono: Failed to load scripts domain"); ERR_FAIL_COND(_load_scripts_domain() != OK); #ifdef DEBUG_ENABLED bool debugger_attached = _wait_for_debugger_msecs(500); if (!debugger_attached && OS::get_singleton()->is_stdout_verbose()) print_error("Mono: Debugger wait timeout"); #endif _register_internal_calls(); // The following assemblies are not required at initialization #ifdef MONO_GLUE_ENABLED if (_load_api_assemblies()) { if (!core_api_assembly_out_of_sync && !editor_api_assembly_out_of_sync && GDMonoUtils::mono_cache.godot_api_cache_updated) { // Everything is fine with the api assemblies, load the project assembly _load_project_assembly(); } else { #ifdef TOOLS_ENABLED // The assembly was successfully loaded, but the full api could not be cached. // This is most likely an outdated assembly loaded because of an invalid version in the metadata, // so we invalidate the version in the metadata and unload the script domain. if (core_api_assembly_out_of_sync) { ERR_PRINT("The loaded Core API assembly is out of sync"); metadata_set_api_assembly_invalidated(APIAssembly::API_CORE, true); } else if (!GDMonoUtils::mono_cache.godot_api_cache_updated) { ERR_PRINT("The loaded Core API assembly is in sync, but the cache update failed"); metadata_set_api_assembly_invalidated(APIAssembly::API_CORE, true); } if (editor_api_assembly_out_of_sync) { ERR_PRINT("The loaded Editor API assembly is out of sync"); metadata_set_api_assembly_invalidated(APIAssembly::API_EDITOR, true); } print_line("Mono: Proceeding to unload scripts domain because of invalid API assemblies."); Error err = _unload_scripts_domain(); if (err != OK) { WARN_PRINT("Mono: Failed to unload scripts domain"); } #else ERR_PRINT("The loaded API assembly is invalid"); CRASH_NOW(); #endif } } #else print_verbose("Mono: Glue disabled, ignoring script assemblies."); #endif print_verbose("Mono: INITIALIZED"); }
static int brot_cmdline_parser_postprocess (const struct brot_args_info* args_info, const char* cmdline) { /* check input structure */ if (args_info->inputs_num == 1) { THROW_ERROR_MSG ("RNA structure required as argument, try " "`%s --help` for more information.", get_progname()); return 1; } if (args_info->inputs_num != 2) { THROW_ERROR_MSG ("Only one RNA structure allowed as argument, try " "`%s --help` for more information.", get_progname()); return 1; } if (args_info->verbose_given) { enable_verbose_messaging(); print_verbose ("# This is %s %s out of the %s\n# %s\n" "# Input structure: %s\n", BROT_CMDLINE_PARSER_PACKAGE, BROT_CMDLINE_PARSER_VERSION, PACKAGE_STRING, cmdline, args_info->inputs[1]); } /* check steps */ if (args_info->steps_given) { if (args_info->steps_arg < 0) { THROW_ERROR_MSG ("Option \"--steps\" requires positive integer as" "argument, found: %ld", args_info->steps_arg); return 1; } } print_verbose ("# Max. steps (-s): %li\n", args_info->steps_arg); /* check temperature */ if (args_info->temp_given) { if (args_info->temp_arg < 0) { THROW_ERROR_MSG ("Option \"--temp\" requires positive floating point " "value as argument, found: %2.2f", args_info->temp_arg); return 1; } } print_verbose ("# Start-temp. (-t): %.2f\n", args_info->temp_arg); if (args_info->window_size_given) { if (args_info->window_size_arg < 0) { THROW_ERROR_MSG ("Option \"--window_size\" requires positive integer " "as argument, found: %ld", args_info->window_size_arg); return 1; } if ((unsigned) args_info->window_size_arg > (strlen (args_info->inputs[1])/2 - 1)) { THROW_ERROR_MSG ("Option \"--window_size\" must be less than or equal to half of the size of the input structure. Is: \"%ld\", allowed: \"%lu\"", args_info->window_size_arg, (unsigned long) strlen (args_info->inputs[1])/2 - 1); return 1; } } print_verbose ("# Neg. design term (-d): %.2f\n", args_info->negative_design_scaling_arg); print_verbose ("# Het. term (-h): %.2f\n", args_info->heterogenity_term_scaling_arg); print_verbose ("# Het. term window size (-w): %ld\n", args_info->window_size_arg); print_verbose ("# Entropy dropoff thresh. (-e): %.2f\n", args_info->sm_entropy_arg); print_verbose ("# Lambda (-l): %.2f\n", args_info->lambda_arg); print_verbose ("# B_long (-o): %.2f\n", args_info->beta_long_arg); print_verbose ("# B_short (-i): %.2f\n", args_info->beta_short_arg); print_verbose ("# Speedup thresh. (-u): %.2f\n", args_info->speedup_threshold_arg); print_verbose ("# Min. cool. factor (-j): %.2f\n", args_info->min_cool_arg); return 0; }
static int everything_local(struct fetch_pack_args *args, struct ref **refs, struct ref **sought, int nr_sought) { struct ref *ref; int retval; unsigned long cutoff = 0; save_commit_buffer = 0; for (ref = *refs; ref; ref = ref->next) { struct object *o; if (!has_object_file(&ref->old_oid)) continue; o = parse_object(ref->old_oid.hash); if (!o) continue; /* We already have it -- which may mean that we were * in sync with the other side at some time after * that (it is OK if we guess wrong here). */ if (o->type == OBJ_COMMIT) { struct commit *commit = (struct commit *)o; if (!cutoff || cutoff < commit->date) cutoff = commit->date; } } if (!args->deepen) { for_each_ref(mark_complete_oid, NULL); for_each_alternate_ref(mark_alternate_complete, NULL); commit_list_sort_by_date(&complete); if (cutoff) mark_recent_complete_commits(args, cutoff); } /* * Mark all complete remote refs as common refs. * Don't mark them common yet; the server has to be told so first. */ for (ref = *refs; ref; ref = ref->next) { struct object *o = deref_tag(lookup_object(ref->old_oid.hash), NULL, 0); if (!o || o->type != OBJ_COMMIT || !(o->flags & COMPLETE)) continue; if (!(o->flags & SEEN)) { rev_list_push((struct commit *)o, COMMON_REF | SEEN); mark_common((struct commit *)o, 1, 1); } } filter_refs(args, refs, sought, nr_sought); for (retval = 1, ref = *refs; ref ; ref = ref->next) { const unsigned char *remote = ref->old_oid.hash; struct object *o; o = lookup_object(remote); if (!o || !(o->flags & COMPLETE)) { retval = 0; print_verbose(args, "want %s (%s)", sha1_to_hex(remote), ref->name); continue; } print_verbose(args, _("already have %s (%s)"), sha1_to_hex(remote), ref->name); } return retval; }
static int everything_local(struct fetch_pack_args *args, struct ref **refs, struct ref **sought, int nr_sought) { struct ref *ref; int retval; int old_save_commit_buffer = save_commit_buffer; timestamp_t cutoff = 0; struct oidset loose_oid_set = OIDSET_INIT; int use_oidset = 0; struct loose_object_iter iter = {&loose_oid_set, *refs}; /* Enumerate all loose objects or know refs are not so many. */ use_oidset = !for_each_loose_object(add_loose_objects_to_set, &iter, 0); save_commit_buffer = 0; for (ref = *refs; ref; ref = ref->next) { struct object *o; unsigned int flags = OBJECT_INFO_QUICK; if (use_oidset && !oidset_contains(&loose_oid_set, &ref->old_oid)) { /* * I know this does not exist in the loose form, * so check if it exists in a non-loose form. */ flags |= OBJECT_INFO_IGNORE_LOOSE; } if (!has_object_file_with_flags(&ref->old_oid, flags)) continue; o = parse_object(&ref->old_oid); if (!o) continue; /* We already have it -- which may mean that we were * in sync with the other side at some time after * that (it is OK if we guess wrong here). */ if (o->type == OBJ_COMMIT) { struct commit *commit = (struct commit *)o; if (!cutoff || cutoff < commit->date) cutoff = commit->date; } } oidset_clear(&loose_oid_set); if (!args->no_dependents) { if (!args->deepen) { for_each_ref(mark_complete_oid, NULL); for_each_cached_alternate(mark_alternate_complete); commit_list_sort_by_date(&complete); if (cutoff) mark_recent_complete_commits(args, cutoff); } /* * Mark all complete remote refs as common refs. * Don't mark them common yet; the server has to be told so first. */ for (ref = *refs; ref; ref = ref->next) { struct object *o = deref_tag(lookup_object(ref->old_oid.hash), NULL, 0); if (!o || o->type != OBJ_COMMIT || !(o->flags & COMPLETE)) continue; if (!(o->flags & SEEN)) { rev_list_push((struct commit *)o, COMMON_REF | SEEN); mark_common((struct commit *)o, 1, 1); } } } filter_refs(args, refs, sought, nr_sought); for (retval = 1, ref = *refs; ref ; ref = ref->next) { const struct object_id *remote = &ref->old_oid; struct object *o; o = lookup_object(remote->hash); if (!o || !(o->flags & COMPLETE)) { retval = 0; print_verbose(args, "want %s (%s)", oid_to_hex(remote), ref->name); continue; } print_verbose(args, _("already have %s (%s)"), oid_to_hex(remote), ref->name); } save_commit_buffer = old_save_commit_buffer; return retval; }
void print_try_address() { print_verbose("Will now try to contact node by address\n"); }