[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 04/06: runtime: updates prefs to preserve f
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 04/06: runtime: updates prefs to preserve format of preference file options that are in quotes. |
Date: |
Sat, 8 Mar 2014 16:32:45 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
trondeau pushed a commit to branch master
in repository gnuradio.
commit 0b3d00e508ddb6734f8852d728410159a2fcca5a
Author: Tom Rondeau <address@hidden>
Date: Fri Mar 7 16:21:53 2014 -0500
runtime: updates prefs to preserve format of preference file options that
are in quotes.
---
docs/doxygen/other/main_page.dox | 33 ++++++++++++++++++----------
gnuradio-runtime/lib/prefs.cc | 46 +++++++++++++++++++++++++++++++++-------
2 files changed, 60 insertions(+), 19 deletions(-)
diff --git a/docs/doxygen/other/main_page.dox b/docs/doxygen/other/main_page.dox
index e295638..dde7610 100644
--- a/docs/doxygen/other/main_page.dox
+++ b/docs/doxygen/other/main_page.dox
@@ -80,20 +80,20 @@ them.
\code
from gnuradio import gr, filter, analog
-
+
class my_topblock(gr.top_block):
def __init__(self):
gr.top_block.__init__(self)
-
+
amp = 1
taps = filter.firdes.low_pass(1, 1, 0.1, 0.01)
-
+
self.src = analog.noise_source_c(gr.GR_GAUSSIAN, amp)
self.flt = filter.fir_filter_ccf(1, taps)
self.snk = blocks.null_sink(gr.sizeof_gr_complex)
-
+
self.connect(self.src, self.flt, self.snk)
-
+
if __name__ == "__main__":
tb = my_topblock()
tb.start()
@@ -160,7 +160,7 @@ In some situations, you might actually want to restrict the
size of
the buffer itself. This can help to prevent a buffer who is blocked
for data from just increasing the amount of items in its buffer, which
will then cause an increased latency for new samples. You can set the
-size of an output buffer for each output port for every block.
+size of an output buffer for each output port for every block.
WARNING: This is an advanced feature in GNU Radio and should not be
used without a full understanding of this concept as explained below.
@@ -305,7 +305,7 @@ def main():
tb.src1.set_max_noutput_items(2000)
tb.start(100)
time.sleep(0.01)
-
+
# Stop flowgraph and disconnect the add block
tb.lock()
@@ -356,7 +356,7 @@ The configuration files use the following format:
\code
# Stuff from section 1
[section1]
-var1 = value1
+var1 = value1
var2 = value2 # value of 2
# Stuff from section 2
@@ -368,9 +368,20 @@ In this file, the hash mark ('#') indicates a comment and
blank lines
are ignored. Section labels are defined inside square brackets as a
group distinguisher. All options must be associated with a section
name. The options are listed one per line with the option name is
-given followed by an equals ('=') sign and then the value. All section
-and option names must not have white spaces (actually, all white
-spaces are ignored).
+given followed by an equals ('=') sign and then the value.
+
+All section and option names must not have white spaces. If a value
+must have white space, the it MUST be put inside quotes. Any quoted
+value will have its white space preserved and the quotes internally
+will be stripped. As an example, on Apple desktops, an output device
+of "Display Audio" is a possible output device and can be set as:
+
+\code
+[audio_osx]
+default_output_device = "Display Audio"
+\endcode
+
+The result will pass Display Audio to the audio setup.
The value of an option can be a string or number and retrieved through
a few different interfaces. There is a single preference object
diff --git a/gnuradio-runtime/lib/prefs.cc b/gnuradio-runtime/lib/prefs.cc
index 468532f..d03c677 100644
--- a/gnuradio-runtime/lib/prefs.cc
+++ b/gnuradio-runtime/lib/prefs.cc
@@ -76,7 +76,7 @@ namespace gr {
fs::directory_iterator diritr(dir);
while(diritr != fs::directory_iterator()) {
fs::path p = *diritr++;
- if(p.extension() != ".swp")
+ if(p.extension() == ".conf")
fnames.push_back(p.string());
}
std::sort(fnames.begin(), fnames.end());
@@ -111,6 +111,40 @@ namespace gr {
// remove any comments in the line
size_t hash = t.find("#");
+ // Remove any white space unless it's between quotes
+ // Search if the string has any quotes in it
+ size_t quote1 = t.find("\"");
+ if(quote1 != std::string::npos) {
+ // If yes, find where the start and end quotes are.
+ // Note that this isn't robust if there are multiple
+ // quoted strings in the line; this will just take the
+ // first and last, and if there is only a single quote,
+ // this will treat the entire line after the quote as the
+ // quoted text.
+ // the inq variable is strips the quotes as well.
+ size_t quote2 = t.find_last_of("\"");
+ std::string sol = t.substr(0, quote1);
+ std::string inq = t.substr(quote1+1, quote2-quote1-1);
+ std::string eol = t.substr(quote2+1, t.size()-quote2-1);
+
+ // Remove all white space of the text before the first quote
+ sol.erase(std::remove_if(sol.begin(), sol.end(),
+ ::isspace), sol.end());
+
+ // Remove all white space of the text after the end quote
+ eol.erase(std::remove_if(eol.begin(), eol.end(),
+ ::isspace), eol.end());
+
+ // Pack the stripped start and end of lines with the part
+ // of the string in quotes (but without the quotes).
+ t = sol + inq + eol;
+ }
+ else {
+ // No quotes, just strip all white space
+ t.erase(std::remove_if(t.begin(), t.end(),
+ ::isspace), t.end());
+ }
+
// Use hash marks at the end of each segment as a delimiter
config += t.substr(0, hash) + '#';
}
@@ -118,10 +152,6 @@ namespace gr {
fin.close();
}
- // Remove all whitespace.
- config.erase(std::remove_if(config.begin(), config.end(),
- ::isspace), config.end());
-
// Convert the string into a map
_convert_to_map(config);
}
@@ -136,11 +166,11 @@ namespace gr {
size_t sec_start = sub.find("[");
while(sec_start != std::string::npos) {
sub = sub.substr(sec_start);
-
+
size_t sec_end = sub.find("]");
if(sec_end == std::string::npos)
throw std::runtime_error("Config file error: Mismatched section
label.\n");
-
+
std::string sec = sub.substr(1, sec_end-1);
size_t next_sec_start = sub.find("[", sec_end);
std::string subsec = sub.substr(sec_end+1, next_sec_start-sec_end-2);
@@ -154,7 +184,7 @@ namespace gr {
while(next_opt < subsec.size()-1) {
next_val = subsec.find("=", next_opt);
std::string option = subsec.substr(next_opt+1, next_val-next_opt-1);
-
+
next_opt = subsec.find("#", next_val);
std::string value = subsec.substr(next_val+1, next_opt-next_val-1);
- [Commit-gnuradio] [gnuradio] branch master updated (8f75515 -> 24dc96a), git, 2014/03/08
- [Commit-gnuradio] [gnuradio] 05/06: qtgui: adds ability to set qss style sheet as a preference., git, 2014/03/08
- [Commit-gnuradio] [gnuradio] 03/06: Merge remote-tracking branch 'michaelld/fix_gr_audio_osx' into master_osx, git, 2014/03/08
- [Commit-gnuradio] [gnuradio] 04/06: runtime: updates prefs to preserve format of preference file options that are in quotes.,
git <=
- [Commit-gnuradio] [gnuradio] 06/06: Merge branch 'master_osx', git, 2014/03/08
- [Commit-gnuradio] [gnuradio] 02/06: fix typo in getting default source (output) audio device name from gr::prefs, git, 2014/03/08
- [Commit-gnuradio] [gnuradio] 01/06: fix gr-audio osx: + use GNU Radio preferences file to set default input and output audio device, if provided; + use gr::logger for all non-debug messages; + case-insensitive string find with desired audio device name; + fixes buffer allocation bug with low sample rates; + allows using a specific (named) audio device, or the default; + handles the case when the selected audio device becomes unavailable (e.g., a USB stick is removed while in use); + if no audio device name is provided, uses the default audio device as found in System Preferences::Sound; + handles the case when the default audio device is in use, and the user changes that audio device in System Preferences::Sound, by internally resetting to use the newly selected audio device; + all non-Apple names are now lower_case, not CamelCase; + move osx_impl functions to gr::audio::osx, and use them correctly; + install osx_impl.h to expose gr::audio::osx functions, but iff OSX audio is enabled., git, 2014/03/08