From b68acf9988c51bc8afb91ab80569aad89b70d4dc Mon Sep 17 00:00:00 2001 From: Rob Savoye Date: Sun, 28 Nov 2010 13:14:04 -0700 Subject: fix xyzzy_file_exists() and test case --- gr-run-waveform/test_xyzzy.cc | 16 ++++++++++++++-- gr-run-waveform/xyzzy.cc | 21 ++++++++++----------- 2 files changed, 24 insertions(+), 13 deletions(-) (limited to 'gr-run-waveform') diff --git a/gr-run-waveform/test_xyzzy.cc b/gr-run-waveform/test_xyzzy.cc index b6497432a..4a3756d41 100644 --- a/gr-run-waveform/test_xyzzy.cc +++ b/gr-run-waveform/test_xyzzy.cc @@ -122,18 +122,30 @@ main(int argc, char *argv[]) // Does a file with name 'filename' exist in magic filesystem? if (xyzzy_file_exists("srfi/srfi-35.scm")) { + cout << "FAILED: xyzzy_file_exists()" << endl; + } else { + cout << "PASSED: xyzzy_file_exists()" << endl; + } + + // Does a file with name 'filename' exist in magic filesystem? + if (xyzzy_file_exists("/-xyzzy-/srfi/srfi-35.scm")) { cout << "PASSED: xyzzy_file_exists()" << endl; } else { cout << "FAILED: xyzzy_file_exists()" << endl; - } + } + +// xyzzy_file_exists("abcd.scm") -> always false +// xyzzy_file_exists("/-xyzzy-/abcd.scm") -> depends on whether "abcd.scm" is in // Return a C port that will read the file contents - +#if 0 if (xyzzy_make_read_only_port("gnuradio")) { cout << "PASSED: xyzzy_make_read_only_port()" << endl; } else { cout << "FAILED: xyzzy_make_read_only_port()" << endl; } + +#endif scm_boot_guile (argc, argv, inner_main, 0); } diff --git a/gr-run-waveform/xyzzy.cc b/gr-run-waveform/xyzzy.cc index 059edbe08..6179fa5ab 100644 --- a/gr-run-waveform/xyzzy.cc +++ b/gr-run-waveform/xyzzy.cc @@ -115,10 +115,14 @@ XYZZY::init(const std::string &file) bool XYZZY::file_exists(const std::string &filespec) { - std::map::iterator it; - it = _contents.find(filespec); - if (it != _contents.end()) { - return true; + if (filespec.substr(0, 9) == "/-xyzzy-/") { + // look for prefix + std::map::iterator it; + it = _contents.find(filespec.substr(9, filespec.size())); + if (it != _contents.end()) { + return true; + } + return false; } return false; } @@ -128,15 +132,10 @@ XYZZY::file_exists(const std::string &filespec) SCM XYZZY::make_read_only_port(const std::string &filespec) { -#if 0 - char *filename = const_cast(filespec.c_str()); - _portbits = scm_make_port_type(filename, xyzzy_fill_input, xyzzy_write); + _portbits = scm_make_port_type(const_cast(filespec.c_str()), + xyzzy_fill_input, xyzzy_write); scm_set_port_flush (_portbits, xyzzy_flush); scm_set_port_close (_portbits, xyzzy_close); -#else - SCM result; - return result; -#endif } string -- cgit