GNU Radio C++ API
xyzzy.h
Go to the documentation of this file.
1
/* -*- c++ -*- */
2
/*
3
* Copyright 2010 Free Software Foundation, Inc.
4
*
5
* This file is part of GNU Radio
6
*
7
* GNU Radio is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 3, or (at your option)
10
* any later version.
11
*
12
* GNU Radio is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
*
17
* You should have received a copy of the GNU General Public License
18
* along with GNU Radio; see the file COPYING. If not, write to
19
* the Free Software Foundation, Inc., 51 Franklin Street,
20
* Boston, MA 02110-1301, USA.
21
*/
22
23
#ifndef _XYZZY_H_
24
#define _XYZZY_H_ 1
25
26
27
#include <libguile.h>
28
29
#ifdef __cplusplus
30
31
#include <cstdio>
32
#include <cstdlib>
33
#include <string>
34
#include <map>
35
#include <vector>
36
#include <iostream>
37
#include <fstream>
38
#include <boost/cstdint.hpp>
39
#include <boost/shared_ptr.hpp>
40
#include <boost/scoped_ptr.hpp>
41
42
using namespace
std;
43
44
// - Special case filenames that start with /-xyzzy-/... and search for
45
// and load them using the single file. We'd stick "/-zyzzy-" first
46
// in the default load-path.
47
48
// - Create a C read-only "port" that "reads" from the string in the file.
49
// (See guile docs on creating new kinds of ports)
50
51
// - Override the default implementation of "primitive-load" and "%search-load-path"
52
// to make that happen. See load.c in the guile source code. Figure
53
// out how to get the override done before guile is fully
54
// initialized. (Guile loads ice-9/boot9.scm to start itself up. We'd
55
// need to redirect before then.)
56
57
struct
header {
58
char
magic[8];
59
60
boost::uint32_t
offset_to_directory;
// byte offset from start of file
61
boost::uint32_t
size_of_directory;
// bytes
62
boost::uint32_t
number_of_dir_entries;
63
64
boost::uint32_t
offset_to_strings;
// byte offset from start of file
65
boost::uint32_t
size_of_strings;
// bytes
66
};
67
68
struct
directory_entry {
69
boost::uint32_t
offset_to_name;
// from start of strings
70
boost::uint32_t
offset_to_contents;
// from start of strings
71
};
72
73
// Each string starts with a uint32_t length, followed by length bytes.
74
// There is no trailing \0 in the string.
75
struct
string_entry {
76
boost::uint32_t
length;
77
boost::uint8_t
*base;
78
};
79
80
class
XYZZY {
81
public
:
82
XYZZY();
83
~XYZZY();
84
85
// Initialize with the data file produced by gen-xyzzy.
86
bool
init();
87
bool
init(
const
std::string &filespec);
88
89
// Does a file with name 'filename' exist in magic filesystem?
90
bool
file_exists(
const
std::string &filespec);
91
92
/// Parse a string data structure
93
static
std::string read_string(
boost::uint8_t
*entry,
size_t
length);
94
static
std::string read_string(
struct
string_entry &entry);
95
static
std::string read_string(std::ifstream &stream);
96
97
// Read the header of the datafile
98
boost::shared_ptr<struct header>
read_header(
boost::uint8_t
*header);
99
100
boost::shared_ptr<struct directory_entry>
read_dir_entry(
boost::uint8_t
*header);
101
102
std::string &get_contents(
const
std::string &filespec) {
return
_contents[filespec]; };
103
104
private
:
105
std::string _filespec;
106
std::map<std::string, std::string> _contents;
107
};
108
109
// C linkage bindings for Guile
110
extern
"C"
{
111
#endif
112
113
void
scm_xyzzy_init
(
void
);
114
115
// Initialize with the data file produced by gen-xyzzy.
116
int
xyzzy_init
(
const
char
*filename);
117
118
// Does a file with name 'filename' exist in magic filesystem?
119
int
xyzzy_file_exists
(
const
char
*filename);
120
121
// Return a readonly port that accesses filename.
122
SCM
xyzzy_open_file
(SCM filename);
123
124
#ifdef __cplusplus
125
}
// end of extern C
126
#endif
127
128
#endif // _XYZZY_H_ 1
gr-run-waveform
xyzzy.h
Generated on Mon Jul 8 2013 15:25:02 for GNU Radio C++ API by
1.8.4