diff options
author | 2015-08-02 02:05:15 +0200 | |
---|---|---|
committer | 2015-08-03 00:10:22 +0200 | |
commit | d0466dd4dacc43c61aa9d554a025a9d169f3004e (patch) | |
tree | 0671b8a3698a4154ff1a5e97638b8c177a9948e7 /src/tools | |
parent | 0bda22c079f1c2f7775814797d00b356b8bd9b09 (diff) |
Added simple stream classes to netlist code. (nw)
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/nltool.c | 17 | ||||
-rw-r--r-- | src/tools/nlwav.c | 12 |
2 files changed, 15 insertions, 14 deletions
diff --git a/src/tools/nltool.c b/src/tools/nltool.c index 5b6ff343b94..0153653ba25 100644 --- a/src/tools/nltool.c +++ b/src/tools/nltool.c @@ -192,11 +192,11 @@ public: m_setup->init(); } - void read_netlist(const char *buffer, pstring name) + void read_netlist(const pstring &filename, const pstring &name) { // read the netlist ... - m_setup->register_source(palloc(netlist::netlist_source_mem_t(buffer))); + m_setup->register_source(palloc(netlist::source_file_t(filename))); m_setup->include(name); log_setup(); @@ -278,7 +278,7 @@ struct input_t { char buf[400]; double t; - int e = sscanf(line.cstr(), "%lf,%[^,],%lf", &t, buf, &m_value); + int e = line.scanf("%lf,%[^,],%lf", &t, buf, &m_value); if ( e!= 3) throw netlist::fatalerror_e("error %d scanning line %s\n", e, line.cstr()); m_time = netlist::netlist_time::from_double(t); @@ -310,16 +310,15 @@ plist_t<input_t> *read_input(netlist::netlist_t *netlist, pstring fname) plist_t<input_t> *ret = palloc(plist_t<input_t>()); if (fname != "") { - pstring_list_t lines(filetobuf(fname) , "\n"); - for (unsigned i=0; i<lines.size(); i++) - { - pstring l = lines[i].trim(); + pifilestream f(fname); + do { + pstring l = f.readline(); if (l != "") { input_t inp(netlist, l); ret->add(inp); } - } + } while (!f.eof()); } return ret; } @@ -331,7 +330,7 @@ static void run(tool_options_t &opts) nt.m_opts = &opts; nt.init(); - nt.read_netlist(filetobuf(opts.opt_file()), opts.opt_name()); + nt.read_netlist(opts.opt_file(), opts.opt_name()); plist_t<input_t> *inps = read_input(&nt, opts.opt_inp()); diff --git a/src/tools/nlwav.c b/src/tools/nlwav.c index cc6a5988e3e..d2bc2268a3e 100644 --- a/src/tools/nlwav.c +++ b/src/tools/nlwav.c @@ -3,6 +3,7 @@ #include "plib/poptions.h" #include "plib/pstring.h" #include "plib/plists.h" +#include "plib/pstream.h" #include "nl_setup.h" class nlwav_options_t : public poptions @@ -146,8 +147,8 @@ void convert(nlwav_options_t &opts) { wav_t wo(opts.opt_out(), 48000); - FILE *FIN = std::fopen(opts.opt_inp(),"r"); - if (FIN==NULL) + pifilestream fin(opts.opt_inp()); + if (fin.bad()) throw netlist::fatalerror_e("Error opening input file: %s", opts.opt_inp().cstr()); double dt = 1.0 / (double) wo.sample_rate(); @@ -165,11 +166,12 @@ void convert(nlwav_options_t &opts) //short sample = 0; - while(!std::feof(FIN)) + while(!fin.eof()) { #if 1 float t = 0.0; float v = 0.0; - fscanf(FIN, "%f %f", &t, &v); + pstring line = fin.readline(); + line.scanf("%f %f", &t, &v); while (t >= ct) { outsam += (ct - lt) * cursam; @@ -220,7 +222,7 @@ void convert(nlwav_options_t &opts) printf("Amp + %f\n", 32000.0 / (maxsam- mean)); printf("Amp - %f\n", -32000.0 / (minsam- mean)); wo.close(); - fclose(FIN); + fin.close(); } |