static void query_vcf(args_t *args) { kstring_t str = {0,0,0}; if ( args->print_header ) { convert_header(args->convert,&str); fwrite(str.s, str.l, 1, args->out); } while ( bcf_sr_next_line(args->files) ) { if ( !bcf_sr_has_line(args->files,0) ) continue; bcf1_t *line = args->files->readers[0].buffer[0]; bcf_unpack(line, args->files->max_unpack); if ( args->filter ) { int pass = filter_test(args->filter, line, NULL); if ( args->filter_logic & FLT_EXCLUDE ) pass = pass ? 0 : 1; if ( !pass ) continue; } str.l = 0; convert_line(args->convert, line, &str); if ( str.l ) fwrite(str.s, str.l, 1, args->out); } if ( str.m ) free(str.s); }
int main(int argc, char** argv) { FILE* in_file; FILE* out_file; int i; u32 sample_count; int sample_index; int step_index; int start_sample; ADPCMInfo adpcm; u32* offsets; unsigned long start_offset; unsigned long bytes_read = 0; unsigned long total_bytes_read; byte* buffer; s16* out_buffer; unsigned long in_file_size; SAMPLE_HEADER smp_header; if(argc != 4) { printf("usage: %s infile.bin outfile.raw sample_index\n", argv[0]); return -1; } if(strcmp(argv[1], "-") == 0) in_file = stdin; else in_file = fopen(argv[1], "rb"); if(in_file == 0) { printf("%s: Can't open input file!\n", argv[0]); return -1; } if(strcmp(argv[2], "-") == 0) in_file = stdout; else out_file = fopen(argv[2], "wb"); if(out_file == 0) { printf("%s: Can't open output file!\n", argv[0]); return -1; } sscanf(argv[3], "%d", &sample_index); fseek(in_file, 0, SEEK_END); in_file_size = ftell(in_file); fseek(in_file, 0, SEEK_SET); fread(&sample_count, 4, 1, in_file); sample_count = get32bit_LE((u8*) &sample_count); // read offset table offsets = (u32*) malloc(sample_count * 4); fread(offsets, 4, sample_count, in_file); start_offset = get32bit_LE((u8*) &offsets[sample_index]); fseek(in_file, start_offset, SEEK_SET); fread(&smp_header, sizeof(SAMPLE_HEADER), 1, in_file); convert_header(&smp_header); step_index = smp_header.init_step_index; start_sample = (s16)smp_header.init_sample; init_adpcm(&adpcm, step_index, start_sample); printf("%s: sample rate = %d Hz\n", argv[0], smp_header.sample_rate); buffer = (byte*) malloc(BLOCKSIZE); out_buffer = (s16*) malloc(BLOCKSIZE * 2 * sizeof(s16)); fseek(in_file, start_offset + sizeof(SAMPLE_HEADER), SEEK_SET); total_bytes_read = 0; while(total_bytes_read < smp_header.samples) { bytes_read = fread(buffer, 1, BLOCKSIZE, in_file); decode_adpcm(&adpcm, buffer, out_buffer, bytes_read); fwrite(out_buffer, bytes_read * 2, 2, out_file); total_bytes_read += bytes_read; } free(offsets); free(buffer); free(out_buffer); fclose(in_file); fclose(out_file); return 0; }
/*! * \brief qucs2spice::convert_netlist Convert Qucs netlist to Spice netlist * \param[in] netlist Qucs netlist as single string * \param xyce True if xyce-compatible netlist is needed. * \return Spice netlist as a single string */ QString qucs2spice::convert_netlist(QString netlist, bool xyce) { QStringList net_lst=netlist.split("\n"); QRegExp res_pattern("^[ \t]*R:[A-Za-z]+.*"); QRegExp cap_pattern("^[ \t]*C:[A-Za-z]+.*"); QRegExp ind_pattern("^[ \t]*L:[A-Za-z]+.*"); QRegExp diode_pattern("^[ \t]*Diode:[A-Za-z]+.*"); QRegExp mosfet_pattern("^[ \t]*MOSFET:[A-Za-z]+.*"); QRegExp jfet_pattern("^[ \t]*JFET:[A-Za-z]+.*"); QRegExp bjt_pattern("^[ \t]*BJT:[A-Za-z]+.*"); QRegExp ccvs_pattern("^[ \t]*CCVS:[A-Za-z]+.*"); QRegExp cccs_pattern("^[ \t]*CCCS:[A-Za-z]+.*"); QRegExp vcvs_pattern("^[ \t]*VCVS:[A-Za-z]+.*"); QRegExp vccs_pattern("^[ \t]*VCCS:[A-Za-z]+.*"); QRegExp subckt_head_pattern("^[ \t]*\\.Def:[A-Za-z]+.*"); QRegExp ends_pattern("^[ \t]*\\.Def:End[ \t]*$"); QRegExp dc_pattern("^[ \t]*[VI]dc:[A-Za-z]+.*"); QRegExp edd_pattern("^[ \t]*EDD:[A-Za-z]+.*"); QRegExp eqn_pattern("^[ \t]*Eqn:[A-Za-z]+.*"); QRegExp subckt_pattern("^[ \t]*Sub:[A-Za-z]+.*"); QRegExp gyrator_pattern("^[ \t]*Gyrator:[A-Za-z]+.*"); QString s=""; QStringList EqnsAndVars; foreach(QString line,net_lst) { // Find equations if (eqn_pattern.exactMatch(line)) { line.remove(QRegExp("^[ \t]*Eqn:[A-Za-z]+\\w+\\s+")); ExtractVarsAndValues(line,EqnsAndVars); } } EqnsAndVars.removeAll("Export"); EqnsAndVars.removeAll("no"); EqnsAndVars.removeAll("yes"); qDebug()<<EqnsAndVars; foreach(QString line,net_lst) { if (subckt_head_pattern.exactMatch(line)) { if (ends_pattern.exactMatch(line)) s += ".ENDS\n"; else s += convert_header(line); } if (res_pattern.exactMatch(line)) s += convert_rcl(line); if (cap_pattern.exactMatch(line)) s += convert_rcl(line); if (ind_pattern.exactMatch(line)) s += convert_rcl(line); if (diode_pattern.exactMatch(line)) s += convert_diode(line,xyce); if (mosfet_pattern.exactMatch(line)) s += convert_mosfet(line,xyce); if (jfet_pattern.exactMatch(line)) s += convert_jfet(line,xyce); if (bjt_pattern.exactMatch(line)) s += convert_bjt(line); if (vccs_pattern.exactMatch(line)) s += convert_vccs(line); if (vcvs_pattern.exactMatch(line)) s += convert_vcvs(line); if (cccs_pattern.exactMatch(line)) s+= convert_cccs(line); if (ccvs_pattern.exactMatch(line)) s+= convert_ccvs(line); if (dc_pattern.exactMatch(line)) s += convert_dc_src(line); if (edd_pattern.exactMatch(line)) s += convert_edd(line,EqnsAndVars); if (subckt_pattern.exactMatch(line)) s+= convert_subckt(line); if (gyrator_pattern.exactMatch(line)) s+= convert_gyrator(line); } //s.replace(" gnd "," 0 "); return s; }