static void mutate_inputs(void) { if (!tx.vin) tx.vin = parr_new(8, bp_txin_freep); // delete inputs clist *tmp = opt_del_txin; while (tmp) { int idx = ptr_to_int(tmp->data); tmp = tmp->next; if ((idx >= 0) && (idx < tx.vin->len)) parr_remove_idx(tx.vin, idx); } // append new inputs tmp = opt_txin; while (tmp) { char *arg = tmp->data; tmp = tmp->next; size_t alloc_len = strlen(arg) + 1; char txid_str[alloc_len]; strcpy(txid_str, arg); char *colon = strchr(txid_str, ':'); *colon = 0; char vout_str[alloc_len]; strcpy(vout_str, colon + 1); append_input(txid_str, vout_str); } }
static void mutate_outputs(void) { if (!tx.vout) tx.vout = parr_new(8, bp_txout_freep); // delete outputs clist *tmp = opt_del_txout; while (tmp) { int idx = ptr_to_int(tmp->data); tmp = tmp->next; if ((idx >= 0) && (idx < tx.vin->len)) parr_remove_idx(tx.vout, idx); } // append new outputs tmp = opt_txout; while (tmp) { char *arg = tmp->data; tmp = tmp->next; size_t alloc_len = strlen(arg) + 1; char addr_str[alloc_len]; strcpy(addr_str, arg); char *colon = strchr(addr_str, ':'); *colon = 0; char amount_str[alloc_len]; strcpy(amount_str, colon + 1); append_output(addr_str, amount_str); } }
/* open a file with name out_root.name.maf, or returns it if already open. This is a bit messy because in some cases (splitting by feature) there may be more output files than the OS can handle. But it would be computationally expensive to check and see which files are finished, assuming that the MAF is sorted. So, if it tries to open a file and fails, it the goes through the list of filehandles, finds an open one, closes it, and tries to open the new one again. Repeat until successful. Then, if a filehandle needs to be re-opened, it is opened with append. Again, if this is not successful, it looks for another file to close. If it can't find one the program reports an error and dies. Finally, close_outfiles below checks and makes sure that all files are closed with mafBlock_close_file in the end, so that they get the #eof closer. */ FILE *get_outfile(List *outfileList, Hashtable *outfileHash, String *name, char *out_root, int argc, char *argv[]) { int idx, i; FILE *outfile; char *fname = smalloc((strlen(out_root)+name->length+7)*sizeof(char)); sprintf(fname, "%s.%s.maf", out_root, name->chars); idx = ptr_to_int(hsh_get(outfileHash, fname)); if (idx == -1) { hsh_put(outfileHash, fname, int_to_ptr(lst_size(outfileList))); outfile = mafBlock_open_outfile(fname, argc, argv); while (outfile==NULL) { //too many files are open, close one first for (i=0; i<lst_size(outfileList); i++) { outfile = (FILE*)lst_get_ptr(outfileList, i); if (outfile != NULL) break; } if (i == lst_size(outfileList)) { die("ERROR: too many files open in maf_parse\n"); } else { phast_fclose(outfile); lst_set_ptr(outfileList, i, NULL); } outfile = mafBlock_open_outfile(fname, argc, argv); } lst_push_ptr(outfileList, (void*)outfile); sfree(fname); return outfile; } outfile = (FILE*)lst_get_ptr(outfileList, idx); if (outfile == NULL) { //has already been opened but then closed. outfile = phast_fopen_no_exit(fname, "a"); while (outfile == NULL) { for (i=0; i<lst_size(outfileList); i++) { outfile = (FILE*)lst_get_ptr(outfileList, i); if (outfile != NULL) break; } if (i == lst_size(outfileList)) { die("ERROR: too many files open in maf_parse\n"); } else { phast_fclose(outfile); lst_set_ptr(outfileList, i, NULL); } outfile = phast_fopen_no_exit(fname, "a"); } lst_set_ptr(outfileList, idx, (void*)outfile); } sfree(fname); return outfile; }