static int check_file_sorted(const char *file_path) { FILE *f; void *record = NULL; int record_size; unsigned nrecords = (unsigned) (sizeof(data) / sizeof(int)); unsigned i; f = fopen(file_path, "rb"); cb_assert(f != NULL); for (i = 0; i < nrecords; ++i) { record_size = read_record(f, &record, NULL); cb_assert(record_size == sizeof(int)); if (*((int *) record) != sorted_data[i]) { fclose(f); free_record(record, NULL); return 0; } free_record(record, NULL); } /* Check file has no extra (duplicated or garbage) records. */ cb_assert(read_record(f, &record, NULL) == 0); fclose(f); return 1; }
static unsigned long check_file_sorted(const char *file_path) { FILE *f; void *a = NULL, *b; int record_size; unsigned long num_records = 0; f = fopen(file_path, "rb"); cb_assert(f != NULL); record_size = read_record(f, &a, NULL); cb_assert(record_size > 0); num_records += 1; while (record_size > 0) { record_size = read_record(f, &b, NULL); cb_assert(record_size >= 0); if (record_size > 0) { num_records += 1; cb_assert(compare_records(a, b, NULL) < 0); free_record(a, NULL); a = b; } } free_record(a, NULL); fclose(f); return num_records; }
int update_record(ALLOC * a, table_t * t, handle_t h, record_t * r) { unsigned char *buf, *p; record_t *old; size_t len = 0; int ret; if (_validate_record(a, t, r) < 0) return -1; if ((old = read_record(a, t, h)) == NULL) return -1; for (int i = 0; i < t->ncols; i++) { if (t->cols[i].unique == COL_NORMAL) continue; if (_equal(&old->vals[i], &r->vals[i])) continue; if (t->cols[i].index != 0) { if (index_exist(t->cols[i].idx, &r->vals[i])) { xerrno = ERR_UNIQ; goto Error; } continue; } for (handle_t h = t->head; h != 0;) { record_t *x; int eq; if ((x = read_record(a, t, h)) == NULL) goto Error; h = x->next; eq = _equal(&x->vals[i], &r->vals[i]); _free_record(x); if (eq) { xerrno = ERR_UNIQ; goto Error; } } } if ((buf = read_blk(a, h, NULL, &len)) == NULL) goto Error; _free_record(old); p = record2b_skip(buf, t, r); ret = realloc_blk(a, h, buf, p - buf); buf_put(a, buf); return ret; Error: preserve_errno(_free_record(old)); return -1; }
/* * Do the handshaking from the beginning. */ int do_client_connect(SSL *ssl) { int ret = SSL_OK; send_client_hello(ssl); /* send the client hello */ ssl->bm_read_index = 0; ssl->next_state = HS_SERVER_HELLO; ssl->hs_status = SSL_NOT_OK; /* not connected */ /* sit in a loop until it all looks good */ if (!IS_SET_SSL_FLAG(SSL_CONNECT_IN_PARTS)) { while (ssl->hs_status != SSL_OK) { ret = read_record(ssl); if (ret < SSL_OK) break; ret = process_data(ssl, NULL, 0); if (ret < SSL_OK) break; } ssl->hs_status = ret; /* connected? */ } return ret; }
/* Returns the number of attempts, thus far, to advance past end-of-file in reader R. Reads forward in HANDLE's file, if necessary, to find out. Normally, the user stops attempting to read from the file the first time EOF is reached (a return value of 1). If the user tries to read past EOF again (a return value of 2 or more), an error message is issued, and the caller should more forcibly abort to avoid an infinite loop. */ unsigned dfm_eof (struct dfm_reader *r) { if (r->flags & DFM_ADVANCE) { r->flags &= ~DFM_ADVANCE; if (r->eof_cnt == 0 && read_record (r) ) { r->pos = 0; return 0; } r->eof_cnt++; if (r->eof_cnt == 2) { if (r->fh != fh_inline_file ()) msg (ME, _("Attempt to read beyond end-of-file on file %s."), fh_get_name (r->fh)); else msg (ME, _("Attempt to read beyond END DATA.")); } } return r->eof_cnt; }
int main(int argc, const char **argv){ if (argc < 3) { fprintf(stderr, "Usage: %s <filename> <analyzer> [analyzer args]\n", argv[0]); return 1; } struct analyzer *p = analyzer_table; while(p->name) { int len = strlen(p->name); if (strncmp(argv[2], p->name, len) == 0) break; p++; } if (!p->name) { fprintf(stderr, "No such analyzer %s\n", argv[2]); return 1; } struct record_handle *rh = open_record(argv[1]); void *sh = NULL; if (p->init) { sh = p->init(argc-3, argv+3); if (!sh) { fprintf(stderr, "Init error\n"); return 1; } } struct record *r; while((r = read_record(rh))) p->next_record(sh, r); if (p->finish) p->finish(sh); return 0; }
record_t *cursor_next(ALLOC * a, cursor_t * cur) { handle_t h; record_t *r; while (true) { if (cur->idx != NULL) { // using index if (IsEqual(cur->iter, cur->to)) { cur->end = 1; return NULL; } h = BTValue(cur->iter); } else { // full scan if (cur->hdl == 0) { cur->end = 1; return NULL; } h = cur->hdl; } if ((r = read_record(a, cur->tbl, h)) == NULL) { cur->error = 1; return NULL; } if (cur->idx != NULL) MoveNext(cur->iter); else cur->hdl = r->next; if (cursor_match(cur, cur->tbl, r)) return r; _free_record(r); } }
void file_bstore::safe_read_record(off_t offset, char req_prefix, std::vector<char>& record) { char prefix; bool r = read_record(offset, prefix, record); if (!r) throw io_exception("EOF in read of data"); if (prefix != req_prefix) throw io_exception("Mismatched prefix"); }
static uint8_t PairingECMRotation(struct s_reader * reader, const ECM_REQUEST *er, int32_t n) { unsigned char cta_res[CTA_RES_LEN] = {0x00}; uchar ins26[] = {0xDD, 0x26, 0x00, 0x00, 0x03, 0x10, 0x01, 0x00}; uint8_t cnxcurrecm = 0; if(0x0 != reader->rsa_mod[0] && n > 3 && 0x54 == er->ecm[n-3] && 0x02 == er->ecm[n-2] && 0x00 == er->ecm[n-1]) { cnxcurrecm = 1; } if((0 == reader->cnxlastecm) != (0 == cnxcurrecm)) { if(0 == cnxcurrecm) // not paired ins26[7] = 0x30; else ins26[7] = 0x40; if(read_record(reader, ins26, ins26+5, cta_res)<=0) rdr_log(reader, "PairingECMRotation - ERROR"); } reader->cnxlastecm = cnxcurrecm; return cnxcurrecm; }
int read_p3_file(const char *file_name, const p3_file_type file_type, p3_global_settings *pa, seq_args *sa, pr_append_str *fatal_err, pr_append_str *nonfatal_err) { /* Parameter for read_record */ FILE *file; int echo_output = 0; int ret_par = 1; int strict_tags = 0; int io_version = 1; /* Check if a file name was provided */ PR_ASSERT(NULL != file_name); /* Open the file */ if((file = fopen(file_name,"r")) != NULL) { ret_par = read_record(file, &strict_tags, &io_version, echo_output, file_type, pa, sa, fatal_err, nonfatal_err); } else { pr_append_new_chunk(fatal_err, "Cannot open "); pr_append(fatal_err, file_name); } if (file) fclose(file); return ret_par; }
int _validate_unique(ALLOC * a, table_t * t, record_t * r) { for (int i = 0; i < t->ncols; i++) { if (t->cols[i].unique == COL_NORMAL) continue; // primary or unique // use index if (t->cols[i].index != 0) { if (index_exist(t->cols[i].idx, &r->vals[i])) { xerrno = ERR_UNIQ; return -1; } continue; } // full scan for (handle_t h = t->head; h != 0;) { record_t *x; int eq; if ((x = read_record(a, t, h)) == NULL) return -1; h = x->next; eq = _equal(&x->vals[i], &r->vals[i]); _free_record(x); if (eq) { xerrno = ERR_UNIQ; return -1; } } } return 0; }
void entry_menu() { int ch,num; clrscr(); cout<<"\n\n\n\t\tENTRY MENU"; cout<<"\n\n\t1.CREATE STUDENT RECORD"; cout<<"\n\n\t2.DISPLAY ALL STUDENTS RECORD"; cout<<"\n\n\t3.SEARCH STUDENT RECORD"; cout<<"\n\n\t4.MODIFY STUDENT RECORD "; cout<<"\n\n\t5.DELETE STUDENT RECORD "; cout<<"\n\n\t6.RETURN TO MAIN MENU"; cout<<"\n\nPlease Enter Your Choice(1-6)......."; cin>>ch; clrscr(); switch(ch) { case 1:write_record();break; case 2:read_record();break; case 3:cout<<"\n\n\tPlease enter the roll no. of student "; cin>>num; display(num); break; case 4:cout<<"\n\n\tPlease enter the roll no. of student "; cin>>num; modify_record(num); break; case 5:cout<<"\n\n\tPlease enter the roll no. of student "; cin>>num; delete_record(num); break; case 6:break; default : cout<<"\a";entry_menu(); } }
void file_bstore::add_file(const std::string& name) { file_info fi; fi.name = m_dir + "/" + name; file_io* file = new file_io(fi.name); fi.io = file; char prefix; std::vector<char> record; file->seek(0); if (!read_record(file, prefix, record)) throw io_exception("File has no header data"); if (prefix != 'S') throw io_exception("File has incorrect header data"); vector_reader vr(record); off_t start_loc; deserialize(vr, start_loc); m_slabs.insert(std::make_pair(start_loc, fi)); file->seek_end(); off_t file_size = file->get_offset(); if (start_loc + file_size > m_size) { m_cur_slab = file; m_size = start_loc + file_size; } }
static ulong load_serial(ulong offset) { char record[SREC_MAXRECLEN + 1]; /* buffer for one S-Record */ char binbuf[SREC_MAXBINLEN]; /* buffer for binary data */ int binlen; /* no. of data bytes in S-Rec. */ int type; /* return code for record type */ ulong addr; /* load address from S-Record */ ulong size; /* number of bytes transferred */ char buf[32]; ulong store_addr; ulong start_addr = ~0; ulong end_addr = 0; int line_count = 0; while (read_record(record, SREC_MAXRECLEN + 1) >= 0) { type = srec_decode(record, &binlen, &addr, binbuf); if (type < 0) { return ~0; /* Invalid S-Record */ } switch (type) { case SREC_DATA2: case SREC_DATA3: case SREC_DATA4: store_addr = addr + offset; memcpy((char *)(store_addr), binbuf, binlen); if ((store_addr) < start_addr) start_addr = store_addr; if ((store_addr + binlen - 1) > end_addr) end_addr = store_addr + binlen - 1; break; case SREC_END2: case SREC_END3: case SREC_END4: udelay(10000); size = end_addr - start_addr + 1; printf("\n" "## First Load Addr = 0x%08lX\n" "## Last Load Addr = 0x%08lX\n" "## Total Size = 0x%08lX = %ld Bytes\n", start_addr, end_addr, size, size ); sprintf(buf, "%lX", size); setenv("filesize", buf); return addr; case SREC_START: break; default: break; } if (!do_echo) { /* print a '.' every 100 lines */ if ((++line_count % 100) == 0) console_putc(CONSOLE_STDOUT, '.'); } } return ~0; /* Download aborted */ }
int usbip_vhci_imported_device_dump(struct usbip_imported_device *idev) { char product_name[100]; char host[NI_MAXHOST] = "unknown host"; char serv[NI_MAXSERV] = "unknown port"; char remote_busid[SYSFS_BUS_ID_SIZE]; int ret; int i; if (idev->status == VDEV_ST_NULL || idev->status == VDEV_ST_NOTASSIGNED) { info("Port %02d: <%s>", idev->port, usbip_status_string(idev->status)); return 0; } ret = read_record(idev->port, host, serv, remote_busid); if (ret) { err("read_record"); return -1; } info("Port %02d: <%s> at %s", idev->port, usbip_status_string(idev->status), usbip_speed_string(idev->udev.speed)); usbip_names_get_product(product_name, sizeof(product_name), idev->udev.idVendor, idev->udev.idProduct); info(" %s", product_name); info("%10s -> usbip://%s:%s/%s (remote devid %08x (bus/dev %03d/%03d))", idev->udev.busid, host, serv, remote_busid, idev->devid, idev->busnum, idev->devnum); for (i=0; i < idev->udev.bNumInterfaces; i++) { /* show interface information */ struct sysfs_device *suinf; suinf = open_usb_interface(&idev->udev, i); if (!suinf) continue; info(" %6s used by %-17s", suinf->bus_id, suinf->driver_name); sysfs_close_device(suinf); /* show class device information */ struct class_device *cdev; dlist_for_each_data(idev->cdev_list, cdev, struct class_device) { int ifnum = get_interface_number(cdev->devpath); if (ifnum == i) { info(" %s", cdev->clspath); } } } return 0; }
static void arraystorage_load(void *self, FILE *f){ if (self == 0) return; int i; CountryStorage *rs = (CountryStorage *) self; for (i = 0; i <= rs->maxid; i++){ rs->countries[i] = (Recs) read_record(f); } }
const_result_iterator &begin(void) { for (unsigned loop=0; loop<outer_->num_partitions_; ++loop) { kvlist_[loop] = std::make_pair(boost::shared_ptr<std::ifstream>(new std::ifstream), keyvalue_t()); kvlist_[loop].first->open(outer_->intermediate_files_.find(loop)->second.first.c_str()); BOOST_ASSERT(kvlist_[loop].first->is_open()); read_record(*kvlist_[loop].first, kvlist_[loop].second.first, kvlist_[loop].second.second); } set_current(); return *this; }
struct response_struct read_command(char* token_vector[], int token_count) { char* part = NULL; char* value; int retval = 0; char key[KEY_LEN] = ""; int length = 0; struct db_ptr db_rec; int responselen = 0; int i; struct response_struct response; response.status = 0; response.msg = malloc(sizeof(char) * MSG_SIZE); bzero(response.msg, MSG_SIZE); if (token_count == 1) { sprintf(response.msg, "No keys supplied."); response.status = 1; return response; } for (i = 1; token_vector[i] && i < MAX_ARGS; i++) { strcat(key, token_vector[i]); if (strlen(key) > KEY_LEN - 1) { sprintf(response.msg, "Key too long."); response.status = 1; return response; } } db_rec = find_db_ptr(key); if (db_rec.block_offset != -1) { value = read_record(db_rec); responselen = strlen(value); if (responselen >= MSG_SIZE) { // need to expand response. free(response.msg); response.msg = malloc(sizeof(char) * (responselen + 2)); } sprintf(response.msg, "%s", value); free(value); } else { sprintf(response.msg, "Not found."); response.status = 1; } return response; }
void parse_log(FILE *fp, user_table_t *table, char **sites, int count_sites) { int lines_c = 0; struct log_entry entry; char *url; char *other_url; int lines; char *referer; other_url = "other"; if (is_verbose && fp) { lines_c = count_lines(fp); rewind(fp); } lines = 0; while (read_record(fp, &entry) == 0) { lines++; if (entry.time > time_h) { time_h = entry.time; } if (entry.time < time_l) { time_l = entry.time; } entry.head_st[8] = '\0'; url = chop_lvl2_domain(cut_site(entry.uri)); referer = chop_lvl2_domain(cut_site(entry.referer)); if (is_debug) printf("url = |%s|\nref = |%s|\n", url, referer); if (is_debug) printf("url_origin = |%s|\nref_origin = |%s|\n", entry.uri, entry.referer); if (strcmp(entry.head_st, "TCP_MISS") == 0 && strcmp(entry.method, "GET") == 0 && strcmp(entry.mime_type, "text/html") == 0 && (strcmp(referer, "-") == 0 || strcmp(referer, url) == 0)) { if (!is_exist_elem(url, sites, count_sites)) url = other_url; user_table_add_entry(table, chop_uname(entry.username), url); } if (is_verbose && (lines % N_LINES == 0 || lines == lines_c)) { progress(lines_c, lines); } } }
off_t file_bstore::find_root(off_t offset, file_io* f) { off_t best_root = 0; char prefix = 0; f->seek(0); std::vector<char> record; off_t cur_offset = offset + f->get_offset(); while(read_record(f, prefix, record)) { if (prefix == 'R') { best_root = cur_offset; } cur_offset = offset + f->get_offset(); } return best_root; }
int clear_table(ALLOC * a, table_t * t) { handle_t h; record_t *r; int ret; for (h = t->head; h != 0;) { if ((r = read_record(a, t, h)) == NULL) return -1; h = r->next; ret = delete_record(a, t, r->self); preserve_errno(_free_record(r)); if (ret < 0) return -1; } return 0; }
bool file_bstore::read_record(off_t offset, char& prefix, std::vector<char>& record) { if (offset == m_size) return false; slabs_t::iterator it = m_slabs.upper_bound(offset); if (it == m_slabs.begin()) throw io_exception(printstring("Invalid offset on read: %d", (int) offset)); it--; file_io* file = it->second.io; file->seek(offset - it->first); bool r = read_record(file, prefix, record); if (r == false && file != m_slabs.rbegin()->second.io) throw io_exception("End of file in inter-slab region"); return true; }
int usbip_vhci_imported_device_dump(struct usbip_imported_device *idev) { char product_name[100]; char host[NI_MAXHOST] = "unknown host"; char serv[NI_MAXSERV] = "unknown port"; char remote_busid[SYSFS_BUS_ID_SIZE]; int ret; int read_record_error = 0; if (idev->status == VDEV_ST_NULL || idev->status == VDEV_ST_NOTASSIGNED) return 0; ret = read_record(idev->port, host, sizeof(host), serv, sizeof(serv), remote_busid); if (ret) { err("read_record"); read_record_error = 1; } printf("Port %02d: <%s> at %s\n", idev->port, usbip_status_string(idev->status), usbip_speed_string(idev->udev.speed)); usbip_names_get_product(product_name, sizeof(product_name), idev->udev.idVendor, idev->udev.idProduct); printf(" %s\n", product_name); if (!read_record_error) { printf("%10s -> usbip://%s:%s/%s\n", idev->udev.busid, host, serv, remote_busid); printf("%10s -> remote bus/dev %03d/%03d\n", " ", idev->busnum, idev->devnum); } else { printf("%10s -> unknown host, remote port and remote busid\n", idev->udev.busid); printf("%10s -> remote bus/dev %03d/%03d\n", " ", idev->busnum, idev->devnum); } return 0; }
void combine(FnObj &fn_obj) { this->close_files(); for (intermediates_t::iterator it=intermediate_files_.begin(); it!=intermediate_files_.end(); ++it) { std::string infilename = it->second.first; std::string outfilename = platform::get_temporary_filename(); // sort the input file SortFn()(infilename.c_str(), outfilename.c_str(), 11); boost::filesystem::remove(infilename); std::swap(infilename, outfilename); std::string key, last_key; typename reduce_task_type::value_type value; std::ifstream infile(infilename.c_str()); while (read_record(infile, key, value)) { if (key != last_key && key.length() > 0) { if (last_key.length() > 0) fn_obj.finish(last_key, *this); if (key.length() > 0) { fn_obj.start(key); std::swap(key, last_key); } } fn_obj(value); } if (last_key.length() > 0) fn_obj.finish(last_key, *this); infile.close(); boost::filesystem::remove(infilename); } this->close_files(); }
void reduce(unsigned const partition, Callback &callback) { intermediates_t::iterator it = intermediate_files_.find(partition); BOOST_ASSERT(it != intermediate_files_.end()); std::string filename; std::swap(filename, it->second.first); intermediate_files_.erase(it); typename reduce_task_type::key_type key; typename reduce_task_type::key_type last_key; typename reduce_task_type::value_type value; std::list<typename reduce_task_type::value_type> values; std::ifstream infile(filename.c_str()); while (read_record(infile, key, value)) { if (key != last_key && length(key) > 0) { if (length(last_key) > 0) { callback(last_key, values.begin(), values.end()); values.clear(); } if (length(key) > 0) std::swap(key, last_key); } values.push_back(value); } if (length(last_key) > 0) { callback(last_key, values.begin(), values.end()); } infile.close(); boost::filesystem::remove(filename.c_str()); intermediate_files_.find(partition)->second.second->close(); }
int delete_record(ALLOC * a, table_t * t, handle_t h) { record_t *r; int ret = -1; if ((r = read_record(a, t, h)) == NULL) return -1; for (int i = 0; i < t->ncols; i++) if (t->cols[i].index != 0) index_del(t->cols[i].idx, &r->vals[i], r->self); if (_list_del_record(a, t, r) < 0) goto Error; if (dealloc_blk(a, h) < 0) goto Error; ret = 0; Error: preserve_errno(_free_record(r)); return ret; }
int write_read(off_t seek_pt, int fd) { /* if (lock(fd, seek_pt) < 0) { * return ERR_CODE; * } */ if (write_record(fd, seek_pt) < 0) { unlock(fd, seek_pt); return ERR_CODE; } if (read_record(fd, seek_pt) < 0) { unlock(fd, seek_pt); return ERR_CODE; } /* if (unlock(fd, seek_pt) < 0) { * return ERR_CODE; * } */ return 0; }
int main(int argc, char *argv[]) { struct RNAcofold_args_info args_info; unsigned int input_type; char *string, *input_string; char *structure, *cstruc, *rec_sequence, *orig_sequence, *rec_id, **rec_rest; char fname[FILENAME_MAX_LENGTH], ffname[FILENAME_MAX_LENGTH]; char *ParamFile; char *ns_bases, *c; char *Concfile; int i, length, l, sym, r, cl; double min_en; double kT, sfact, betaScale; int pf, istty; int noconv, noPS; int doT; /*compute dimere free energies etc.*/ int doC; /*toggle to compute concentrations*/ int doQ; /*toggle to compute prob of base being paired*/ int cofi; /*toggle concentrations stdin / file*/ plist *prAB; plist *prAA; /*pair probabilities of AA dimer*/ plist *prBB; plist *prA; plist *prB; plist *mfAB; plist *mfAA; /*pair mfobabilities of AA dimer*/ plist *mfBB; plist *mfA; plist *mfB; double *ConcAandB; unsigned int rec_type, read_opt; pf_paramT *pf_parameters; model_detailsT md; /* ############################################# # init variables and parameter options ############################################# */ dangles = 2; sfact = 1.07; bppmThreshold = 1e-5; noconv = 0; noPS = 0; do_backtrack = 1; pf = 0; doT = 0; doC = 0; doQ = 0; cofi = 0; betaScale = 1.; gquad = 0; ParamFile = NULL; pf_parameters = NULL; string = NULL; Concfile = NULL; structure = NULL; cstruc = NULL; ns_bases = NULL; rec_type = read_opt = 0; rec_id = rec_sequence = orig_sequence = NULL; rec_rest = NULL; set_model_details(&md); /* ############################################# # check the command line prameters ############################################# */ if(RNAcofold_cmdline_parser (argc, argv, &args_info) != 0) exit(1); /* temperature */ if(args_info.temp_given) temperature = args_info.temp_arg; /* structure constraint */ if(args_info.constraint_given) fold_constrained=1; /* do not take special tetra loop energies into account */ if(args_info.noTetra_given) md.special_hp = tetra_loop=0; /* set dangle model */ if(args_info.dangles_given){ if((args_info.dangles_arg < 0) || (args_info.dangles_arg > 3)) warn_user("required dangle model not implemented, falling back to default dangles=2"); else md.dangles = dangles = args_info.dangles_arg; } /* do not allow weak pairs */ if(args_info.noLP_given) md.noLP = noLonelyPairs = 1; /* do not allow wobble pairs (GU) */ if(args_info.noGU_given) md.noGU = noGU = 1; /* do not allow weak closing pairs (AU,GU) */ if(args_info.noClosingGU_given) md.noGUclosure = no_closingGU = 1; /* gquadruplex support */ if(args_info.gquad_given) md.gquad = gquad = 1; /* enforce canonical base pairs in any case? */ if(args_info.canonicalBPonly_given) md.canonicalBPonly = canonicalBPonly = 1; /* do not convert DNA nucleotide "T" to appropriate RNA "U" */ if(args_info.noconv_given) noconv = 1; /* set energy model */ if(args_info.energyModel_given) energy_set = args_info.energyModel_arg; /* */ if(args_info.noPS_given) noPS = 1; /* take another energy parameter set */ if(args_info.paramFile_given) ParamFile = strdup(args_info.paramFile_arg); /* Allow other pairs in addition to the usual AU,GC,and GU pairs */ if(args_info.nsp_given) ns_bases = strdup(args_info.nsp_arg); /* set pf scaling factor */ if(args_info.pfScale_given) sfact = args_info.pfScale_arg; if(args_info.all_pf_given) doT = pf = 1; /* concentrations from stdin */ if(args_info.concentrations_given) doC = doT = pf = 1; /* set the bppm threshold for the dotplot */ if(args_info.bppmThreshold_given) bppmThreshold = MIN2(1., MAX2(0.,args_info.bppmThreshold_arg)); /* concentrations in file */ if(args_info.betaScale_given) betaScale = args_info.betaScale_arg; if(args_info.concfile_given){ Concfile = strdup(args_info.concfile_arg); doC = cofi = doT = pf = 1; } /* partition function settings */ if(args_info.partfunc_given){ pf = 1; if(args_info.partfunc_arg != -1) do_backtrack = args_info.partfunc_arg; } /* free allocated memory of command line data structure */ RNAcofold_cmdline_parser_free (&args_info); /* ############################################# # begin initializing ############################################# */ if(pf && gquad){ nrerror("G-Quadruplex support is currently not available for partition function computations"); } if (ParamFile != NULL) read_parameter_file(ParamFile); if (ns_bases != NULL) { nonstandards = space(33); c=ns_bases; i=sym=0; if (*c=='-') { sym=1; c++; } while (*c!='\0') { if (*c!=',') { nonstandards[i++]=*c++; nonstandards[i++]=*c; if ((sym)&&(*c!=*(c-1))) { nonstandards[i++]=*c; nonstandards[i++]=*(c-1); } } c++; } } istty = isatty(fileno(stdout))&&isatty(fileno(stdin)); /* print user help if we get input from tty */ if(istty){ printf("Use '&' to connect 2 sequences that shall form a complex.\n"); if(fold_constrained){ print_tty_constraint(VRNA_CONSTRAINT_DOT | VRNA_CONSTRAINT_X | VRNA_CONSTRAINT_ANG_BRACK | VRNA_CONSTRAINT_RND_BRACK); print_tty_input_seq_str("Input sequence (upper or lower case) followed by structure constraint\n"); } else print_tty_input_seq(); } /* set options we wanna pass to read_record */ if(istty) read_opt |= VRNA_INPUT_NOSKIP_BLANK_LINES; if(!fold_constrained) read_opt |= VRNA_INPUT_NO_REST; /* ############################################# # main loop: continue until end of file ############################################# */ while( !((rec_type = read_record(&rec_id, &rec_sequence, &rec_rest, read_opt)) & (VRNA_INPUT_ERROR | VRNA_INPUT_QUIT))){ /* ######################################################## # init everything according to the data we've read ######################################################## */ if(rec_id){ if(!istty) printf("%s\n", rec_id); (void) sscanf(rec_id, ">%" XSTR(FILENAME_ID_LENGTH) "s", fname); } else fname[0] = '\0'; cut_point = -1; rec_sequence = tokenize(rec_sequence); /* frees input_string and sets cut_point */ length = (int) strlen(rec_sequence); structure = (char *) space((unsigned) length+1); /* parse the rest of the current dataset to obtain a structure constraint */ if(fold_constrained){ cstruc = NULL; int cp = cut_point; unsigned int coptions = (rec_id) ? VRNA_CONSTRAINT_MULTILINE : 0; coptions |= VRNA_CONSTRAINT_DOT | VRNA_CONSTRAINT_X | VRNA_CONSTRAINT_ANG_BRACK | VRNA_CONSTRAINT_RND_BRACK; getConstraint(&cstruc, (const char **)rec_rest, coptions); cstruc = tokenize(cstruc); if(cut_point != cp) nrerror("cut point in sequence and structure constraint differs"); cl = (cstruc) ? (int)strlen(cstruc) : 0; if(cl == 0) warn_user("structure constraint is missing"); else if(cl < length) warn_user("structure constraint is shorter than sequence"); else if(cl > length) nrerror("structure constraint is too long"); if(cstruc) strncpy(structure, cstruc, sizeof(char)*(cl+1)); } /* convert DNA alphabet to RNA if not explicitely switched off */ if(!noconv) str_DNA2RNA(rec_sequence); /* store case-unmodified sequence */ orig_sequence = strdup(rec_sequence); /* convert sequence to uppercase letters only */ str_uppercase(rec_sequence); if(istty){ if (cut_point == -1) printf("length = %d\n", length); else printf("length1 = %d\nlength2 = %d\n", cut_point-1, length-cut_point+1); } /* ######################################################## # begin actual computations ######################################################## */ if (doC) { FILE *fp; if (cofi) { /* read from file */ fp = fopen(Concfile, "r"); if (fp==NULL) { fprintf(stderr, "could not open concentration file %s", Concfile); nrerror("\n"); } ConcAandB = read_concentrations(fp); fclose(fp); } else { printf("Please enter concentrations [mol/l]\n format: ConcA ConcB\n return to end\n"); ConcAandB = read_concentrations(stdin); } } /*compute mfe of AB dimer*/ min_en = cofold(rec_sequence, structure); assign_plist_from_db(&mfAB, structure, 0.95); { char *pstring, *pstruct; if (cut_point == -1) { pstring = strdup(orig_sequence); pstruct = strdup(structure); } else { pstring = costring(orig_sequence); pstruct = costring(structure); } printf("%s\n%s", pstring, pstruct); if (istty) printf("\n minimum free energy = %6.2f kcal/mol\n", min_en); else printf(" (%6.2f)\n", min_en); (void) fflush(stdout); if (!noPS) { char annot[512] = ""; if (fname[0]!='\0') { strcpy(ffname, fname); strcat(ffname, "_ss.ps"); } else { strcpy(ffname, "rna.ps"); } if (cut_point >= 0) sprintf(annot, "1 %d 9 0 0.9 0.2 omark\n%d %d 9 1 0.1 0.2 omark\n", cut_point-1, cut_point+1, length+1); if(gquad){ if (!noPS) (void) PS_rna_plot_a_gquad(pstring, pstruct, ffname, annot, NULL); } else { if (!noPS) (void) PS_rna_plot_a(pstring, pstruct, ffname, annot, NULL); } } free(pstring); free(pstruct); } if (length>2000) free_co_arrays(); /*compute partition function*/ if (pf) { cofoldF AB, AA, BB; FLT_OR_DBL *probs; if (dangles==1) { dangles=2; /* recompute with dangles as in pf_fold() */ min_en = energy_of_structure(rec_sequence, structure, 0); dangles=1; } kT = (betaScale*((temperature+K0)*GASCONST))/1000.; /* in Kcal */ pf_scale = exp(-(sfact*min_en)/kT/length); if (length>2000) fprintf(stderr, "scaling factor %f\n", pf_scale); pf_parameters = get_boltzmann_factors(temperature, betaScale, md, pf_scale); if (cstruc!=NULL) strncpy(structure, cstruc, length+1); AB = co_pf_fold_par(rec_sequence, structure, pf_parameters, do_backtrack, fold_constrained); if (do_backtrack) { char *costruc; costruc = (char *) space(sizeof(char)*(strlen(structure)+2)); if (cut_point<0) printf("%s", structure); else { strncpy(costruc, structure, cut_point-1); strcat(costruc, "&"); strcat(costruc, structure+cut_point-1); printf("%s", costruc); } if (!istty) printf(" [%6.2f]\n", AB.FAB); else printf("\n");/*8.6.04*/ } if ((istty)||(!do_backtrack)) printf(" free energy of ensemble = %6.2f kcal/mol\n", AB.FAB); printf(" frequency of mfe structure in ensemble %g", exp((AB.FAB-min_en)/kT)); printf(" , delta G binding=%6.2f\n", AB.FcAB - AB.FA - AB.FB); probs = export_co_bppm(); assign_plist_from_pr(&prAB, probs, length, bppmThreshold); /* if (doQ) make_probsum(length,fname); */ /*compute prob of base paired*/ /* free_co_arrays(); */ if (doT) { /* cofold of all dimers, monomers */ int Blength, Alength; char *Astring, *Bstring, *orig_Astring, *orig_Bstring; char *Newstring; char Newname[30]; char comment[80]; if (cut_point<0) { printf("Sorry, i cannot do that with only one molecule, please give me two or leave it\n"); free(mfAB); free(prAB); continue; } if (dangles==1) dangles=2; Alength=cut_point-1; /*length of first molecule*/ Blength=length-cut_point+1; /*length of 2nd molecule*/ Astring=(char *)space(sizeof(char)*(Alength+1));/*Sequence of first molecule*/ Bstring=(char *)space(sizeof(char)*(Blength+1));/*Sequence of second molecule*/ strncat(Astring,rec_sequence,Alength); strncat(Bstring,rec_sequence+Alength,Blength); orig_Astring=(char *)space(sizeof(char)*(Alength+1));/*Sequence of first molecule*/ orig_Bstring=(char *)space(sizeof(char)*(Blength+1));/*Sequence of second molecule*/ strncat(orig_Astring,orig_sequence,Alength); strncat(orig_Bstring,orig_sequence+Alength,Blength); /* compute AA dimer */ AA=do_partfunc(Astring, Alength, 2, &prAA, &mfAA, pf_parameters); /* compute BB dimer */ BB=do_partfunc(Bstring, Blength, 2, &prBB, &mfBB, pf_parameters); /*free_co_pf_arrays();*/ /* compute A monomer */ do_partfunc(Astring, Alength, 1, &prA, &mfA, pf_parameters); /* compute B monomer */ do_partfunc(Bstring, Blength, 1, &prB, &mfB, pf_parameters); compute_probabilities(AB.F0AB, AB.FA, AB.FB, prAB, prA, prB, Alength); compute_probabilities(AA.F0AB, AA.FA, AA.FA, prAA, prA, prA, Alength); compute_probabilities(BB.F0AB, BB.FA, BB.FA, prBB, prA, prB, Blength); printf("Free Energies:\nAB\t\tAA\t\tBB\t\tA\t\tB\n%.6f\t%6f\t%6f\t%6f\t%6f\n", AB.FcAB, AA.FcAB, BB.FcAB, AB.FA, AB.FB); if (doC) { do_concentrations(AB.FcAB, AA.FcAB, BB.FcAB, AB.FA, AB.FB, ConcAandB); free(ConcAandB);/*freeen*/ } if (fname[0]!='\0') { strcpy(ffname, fname); strcat(ffname, "_dp5.ps"); } else strcpy(ffname, "dot5.ps"); /*output of the 5 dot plots*/ /*AB dot_plot*/ /*write Free Energy into comment*/ sprintf(comment,"\n%%Heterodimer AB FreeEnergy= %.9f\n", AB.FcAB); /*reset cut_point*/ cut_point=Alength+1; /*write New name*/ strcpy(Newname,"AB"); strcat(Newname,ffname); (void)PS_dot_plot_list(orig_sequence, Newname, prAB, mfAB, comment); /*AA dot_plot*/ sprintf(comment,"\n%%Homodimer AA FreeEnergy= %.9f\n",AA.FcAB); /*write New name*/ strcpy(Newname,"AA"); strcat(Newname,ffname); /*write AA sequence*/ Newstring=(char*)space((2*Alength+1)*sizeof(char)); strcpy(Newstring,orig_Astring); strcat(Newstring,orig_Astring); (void)PS_dot_plot_list(Newstring, Newname, prAA, mfAA, comment); free(Newstring); /*BB dot_plot*/ sprintf(comment,"\n%%Homodimer BB FreeEnergy= %.9f\n",BB.FcAB); /*write New name*/ strcpy(Newname,"BB"); strcat(Newname,ffname); /*write BB sequence*/ Newstring=(char*)space((2*Blength+1)*sizeof(char)); strcpy(Newstring,orig_Bstring); strcat(Newstring,orig_Bstring); /*reset cut_point*/ cut_point=Blength+1; (void)PS_dot_plot_list(Newstring, Newname, prBB, mfBB, comment); free(Newstring); /*A dot plot*/ /*reset cut_point*/ cut_point=-1; sprintf(comment,"\n%%Monomer A FreeEnergy= %.9f\n",AB.FA); /*write New name*/ strcpy(Newname,"A"); strcat(Newname,ffname); /*write BB sequence*/ (void)PS_dot_plot_list(orig_Astring, Newname, prA, mfA, comment); /*B monomer dot plot*/ sprintf(comment,"\n%%Monomer B FreeEnergy= %.9f\n",AB.FB); /*write New name*/ strcpy(Newname,"B"); strcat(Newname,ffname); /*write BB sequence*/ (void)PS_dot_plot_list(orig_Bstring, Newname, prB, mfB, comment); free(Astring); free(Bstring); free(orig_Astring); free(orig_Bstring); free(prAB); free(prAA); free(prBB); free(prA); free(prB); free(mfAB); free(mfAA); free(mfBB); free(mfA); free(mfB); } /*end if(doT)*/ free(pf_parameters); }/*end if(pf)*/ if (do_backtrack) { if (fname[0]!='\0') { strcpy(ffname, fname); strcat(ffname, "_dp.ps"); } else strcpy(ffname, "dot.ps"); if (!doT) { if (pf) { (void) PS_dot_plot_list(rec_sequence, ffname, prAB, mfAB, "doof"); free(prAB);} free(mfAB); } } if (!doT) free_co_pf_arrays(); (void) fflush(stdout); /* clean up */ if(cstruc) free(cstruc); if(rec_id) free(rec_id); free(rec_sequence); free(orig_sequence); free(structure); /* free the rest of current dataset */ if(rec_rest){ for(i=0;rec_rest[i];i++) free(rec_rest[i]); free(rec_rest); } rec_id = rec_sequence = orig_sequence = structure = cstruc = NULL; rec_rest = NULL; /* print user help for the next round if we get input from tty */ if(istty){ printf("Use '&' to connect 2 sequences that shall form a complex.\n"); if(fold_constrained){ print_tty_constraint(VRNA_CONSTRAINT_DOT | VRNA_CONSTRAINT_X | VRNA_CONSTRAINT_ANG_BRACK | VRNA_CONSTRAINT_RND_BRACK); print_tty_input_seq_str("Input sequence (upper or lower case) followed by structure constraint\n"); } else print_tty_input_seq(); } } return EXIT_SUCCESS; }
void read_record_matrix(OutputIterIter first) const { for (std::size_t d = 0; d != dim_; ++d, ++first) read_record(d, *first); }
static int32_t conax_card_init(struct s_reader * reader, ATR *newatr) { unsigned char cta_res[CTA_RES_LEN]; int32_t i, j, n; static const uchar ins26[] = {0xDD, 0x26, 0x00, 0x00, 0x03, 0x10, 0x01, 0x40}; uchar ins82[] = {0xDD, 0x82, 0x00, 0x00, 0x11, 0x11, 0x0f, 0x01, 0xb0, 0x0f, 0xff, \ 0xff, 0xfb, 0x00, 0x00, 0x09, 0x04, 0x0b, 0x00, 0xe0, 0x30, 0x2b }; uchar cardver=0; get_hist; if ((hist_size < 4) || (memcmp(hist,"0B00",4))) return ERROR; reader->caid=0xB00; if ((n=read_record(reader, ins26, ins26+5, cta_res))<=0) return ERROR; // read caid, card-version for (i=0; i<n; i+=cta_res[i+1]+2) switch(cta_res[i]) { case 0x20: cardver=cta_res[i+2]; break; case 0x28: reader->caid=(cta_res[i+2]<<8)|cta_res[i+3]; } // Ins82 command needs to use the correct CAID reported in nano 0x28 ins82[17]=(reader->caid>>8)&0xFF; ins82[18]=(reader->caid)&0xFF; if ((n=read_record(reader, ins82, ins82+5, cta_res))<=0) return ERROR; // read serial reader->nprov = 0; for (j=0, i=2; i<n; i+=cta_res[i+1]+2) switch(cta_res[i]) { case 0x23: if (cta_res[i+5] != 0x00) { memcpy(reader->hexserial, &cta_res[i+3], 6); } else { memcpy(reader->sa[j], &cta_res[i+5], 4); j++; reader->nprov++; } break; } memset(reader->prid, 0x00, sizeof(reader->prid)); rdr_log_sensitive(reader, "type: Conax, caid: %04X, serial: {%llu}, hex serial: {%02x%02x%02x%02x}, card: v%d", reader->caid, (unsigned long long) b2ll(6, reader->hexserial), reader->hexserial[2], reader->hexserial[3], reader->hexserial[4], reader->hexserial[5], cardver); rdr_log(reader, "Providers: %d", reader->nprov); for (j=0; j<reader->nprov; j++) { rdr_log(reader, "Provider: %d Provider-Id: %06X", j+1, b2i(4, reader->prid[j])); rdr_log_sensitive(reader, "Provider: %d SharedAddress: {%08X}", j+1, b2i(4, reader->sa[j])); } return OK; }