diff options
author | Eric Blossom <eb@comsec.com> | 2010-12-03 13:14:15 -0800 |
---|---|---|
committer | Eric Blossom <eb@comsec.com> | 2010-12-03 13:14:15 -0800 |
commit | 331a74a4d9f0f983c6892ca5d01e8ef4f5308e76 (patch) | |
tree | bea83f8c70b4bd9285a1f7d4427d3fff485b01fb | |
parent | dd75f58e8b7efb061ff58b29bd1bfa7b306d3058 (diff) |
Make xyzzy_open_file work. (And a bit of renaming.)
xyzzy_open_file (nee make_xyzzy) was not stripping off the magic
prefix before searching, and was thus always creating a new entry in
the map and returning a "" string.
-rw-r--r-- | gr-run-waveform/xyzzy-load.c | 24 | ||||
-rw-r--r-- | gr-run-waveform/xyzzy.cc | 18 | ||||
-rw-r--r-- | gr-run-waveform/xyzzy.h | 4 |
3 files changed, 25 insertions, 21 deletions
diff --git a/gr-run-waveform/xyzzy-load.c b/gr-run-waveform/xyzzy-load.c index 9051883dbd..cc0c3962c2 100644 --- a/gr-run-waveform/xyzzy-load.c +++ b/gr-run-waveform/xyzzy-load.c @@ -305,7 +305,6 @@ SCM_DEFINE (scm_xyzzy_primitive_load, "xyzzy-primitive-load", 1, 0, 0, SCM hook = *scm_loc_load_hook; SCM_VALIDATE_STRING (1, filename); - size_t len = strlen(scm_to_locale_string(filename)); char *ptr = scm_to_locale_string(filename); /* fprintf(stderr, "TRACE %s: %d: %s\n", __FUNCTION__, __LINE__, ptr); */ @@ -318,11 +317,10 @@ SCM_DEFINE (scm_xyzzy_primitive_load, "xyzzy-primitive-load", 1, 0, 0, { /* scope */ SCM port; - const char *magic = "/-xyzzy-"; - if (strncmp(ptr, magic, strlen(magic)) == 0) { - fprintf(stderr, "TRACE: file %s is a XYZZY file system file!\n", - ptr+strlen(magic)); - port = make_xyzzy(filename); + + if (xyzzy_file_exists(ptr)){ + /* fprintf(stderr, "TRACE: file %s is a XYZZY file system file!\n", ptr); */ + port = xyzzy_open_file(filename); } else { port = scm_open_file (filename, scm_from_locale_string ("r")); } @@ -412,12 +410,12 @@ SCM_DEFINE (scm_xyzzy_primitive_load_path, "xyzzy-primitive-load-path", 1, 0, 0, } #undef FUNC_NAME -SCM_DEFINE (scm_make_gnuradio, "make-gnuradio-port", 1, 0, 0, - (SCM port), - "Return a new port which reads from @var{port}") -#define FUNC_NAME s_scm_make_gnuradio +SCM_DEFINE (scm_xyzzy_open_file, "xyzzy-open-file", 1, 0, 0, + (SCM filename), + "Return a new port which reads from @var{filename}") +#define FUNC_NAME s_scm_xyzzy_open_file { - return make_xyzzy (port); + return xyzzy_open_file (filename); } #undef FUNC_NAME @@ -431,10 +429,8 @@ scm_xyzzy_init (void) /* initialize our functions in the scheme VM */ scm_c_define_gsubr ("xyzzy-search-path", 2, 1, 0, (SCM (*)()) scm_xyzzy_search_path); - scm_c_define_gsubr ("make-gnuradio-port", 1, 0, 0, (SCM (*)()) scm_make_gnuradio); + scm_c_define_gsubr ("xyzzy-open-file", 1, 0, 0, (SCM (*)()) scm_xyzzy_open_file); scm_c_define_gsubr ("xyzzy-primitive-load", 1, 0, 0, (SCM (*)()) scm_xyzzy_primitive_load); - scm_c_define_gsubr ("xyzzy-search-load-path", 1, 0, 0, (SCM (*)()) scm_xyzzy_sys_search_load_path); scm_c_define_gsubr ("xyzzy-primitive-load-path", 1, 0, 0, (SCM (*)()) scm_xyzzy_primitive_load_path); } - diff --git a/gr-run-waveform/xyzzy.cc b/gr-run-waveform/xyzzy.cc index 7c3c393f78..537b227b88 100644 --- a/gr-run-waveform/xyzzy.cc +++ b/gr-run-waveform/xyzzy.cc @@ -197,15 +197,23 @@ extern "C" { static XYZZY datafile; SCM -make_xyzzy (SCM binary_port) +xyzzy_open_file(SCM filename) +#define FUNC_NAME "xyzzy-open-file" { - // fprintf(stderr, "TRACE %s: %d, %s\n", __FUNCTION__, __LINE__, scm_to_locale_string(binary_port)); - std::string &contents = datafile.get_contents(scm_to_locale_string(binary_port)); + const char *c_filename = scm_to_locale_string(filename); + // fprintf(stderr, "TRACE %s: %d, %s\n", __FUNCTION__, __LINE__, c_filename); - SCM port = scm_open_input_string (scm_from_locale_string (contents.c_str())); + if (!xyzzy_file_exists(c_filename)){ + SCM_MISC_ERROR("file does not exist: ~S", scm_list_1(filename)); + } + + std::string filespec(c_filename); + std::string &contents = datafile.get_contents(filespec.substr(9, filespec.size())); + SCM port = scm_open_input_string (scm_from_locale_string (contents.c_str())); - return port; + return port; } +#undef FUNC_NAME // Initialize with the data file produced by gen-xyzzy. int diff --git a/gr-run-waveform/xyzzy.h b/gr-run-waveform/xyzzy.h index da87908f0f..5bce799694 100644 --- a/gr-run-waveform/xyzzy.h +++ b/gr-run-waveform/xyzzy.h @@ -118,8 +118,8 @@ int xyzzy_init(const char *filename); // Does a file with name 'filename' exist in magic filesystem? int xyzzy_file_exists(const char *filename); -// Make a readonly port -SCM make_xyzzy (SCM binary_port); +// Return a readonly port that accesses filename. +SCM xyzzy_open_file (SCM filename); #ifdef __cplusplus } // end of extern C |