From 38db1148ea72be3b09ca432684772964f3d049ca Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sun, 12 Oct 2025 10:09:51 -0700 Subject: [PATCH] work --- rust/doc/src/invoking/pspp-show-spv.md | 10 ++-- rust/pspp/src/output.rs | 80 ++++++++++++-------------- 2 files changed, 43 insertions(+), 47 deletions(-) diff --git a/rust/doc/src/invoking/pspp-show-spv.md b/rust/doc/src/invoking/pspp-show-spv.md index 386f2c32b7..a31ff548c3 100644 --- a/rust/doc/src/invoking/pspp-show-spv.md +++ b/rust/doc/src/invoking/pspp-show-spv.md @@ -39,11 +39,11 @@ The following ``s are accepted: ## Input Selection Options -The `dir` and `convert` commands, by default, operate on all of the -objects in the source SPV file, except for objects that are not visible -in the output viewer window. The user may specify these options to -select a subset of the input objects. When multiple options are used, -only objects that satisfy all of them are selected: +Commands that read an SPV file operate, by default, on all of the +objects in the file, except for objects that are not visible in the +output viewer window. The user may specify these options to select a +subset of the input objects. When multiple options are used, only +objects that satisfy all of them are selected: * `--select=[^]CLASS...` Include only objects of the given `CLASS`; with leading `^`, include diff --git a/rust/pspp/src/output.rs b/rust/pspp/src/output.rs index 544f2353a3..8c307a6c48 100644 --- a/rust/pspp/src/output.rs +++ b/rust/pspp/src/output.rs @@ -846,38 +846,25 @@ impl Criteria { } fn unflatten_items( items: Vec>, - mut index: usize, - include: &BitVec, + include: &mut bit_vec::Iter, out: &mut Vec>, ) { for item in items { - unflatten_item(Arc::unwrap_or_clone(item), index, include, out); - index += 1; + unflatten_item(Arc::unwrap_or_clone(item), include, out); } } - fn unflatten_item( - mut item: Item, - mut index: usize, - include: &BitVec, - out: &mut Vec>, - ) { - let include_item = include[index]; - index += 1; - match item.details { - Details::Group(ref mut children) => { - let in_children = take(children); - if !include_item { - unflatten_items(in_children, index, include, out); - return; - } - unflatten_items(in_children, index, include, children); + fn unflatten_item(mut item: Item, include: &mut bit_vec::Iter, out: &mut Vec>) { + let include_item = include.next().unwrap(); + if let Some(children) = item.details.as_mut_group() { + if !include_item { + unflatten_items(take(children), include, out); + return; } - _ => {} + unflatten_items(take(children), include, children); } if include_item { out.push(Arc::new(item)); } - todo!() } let mut items = Vec::new(); @@ -885,13 +872,22 @@ impl Criteria { flatten_children(take_children(&item), 0, &mut items, &mut depths); let mut include = BitVec::from_elem(items.len(), false); - for selection in &self.0 { + let selections = if self.0.is_empty() { + &[Selection::default()] + } else { + self.0.as_slice() + }; + for selection in selections { select_matches(&items, &depths, selection, &mut include); } let mut output = Item::new_root(); - unflatten_item(item, 0, &include, output.details.as_mut_group().unwrap()); - todo!() + unflatten_item( + item, + &mut include.iter(), + output.details.as_mut_group().unwrap(), + ); + output } } @@ -961,25 +957,25 @@ impl FromArgMatches for Criteria { } } - if values.is_empty() { - return Ok(()); - } - - let mut selection = Selection::default(); - for value in values.into_values() { - match value { - Value::Or => self.0.push(take(&mut selection)), - Value::Classes(classes) => selection.classes = classes, - Value::Commands(commands) => selection.commands = commands, - Value::Subtypes(subtypes) => selection.subtypes = subtypes, - Value::Labels(labels) => selection.labels = labels, - Value::NthCommands(nth_commands) => selection.nth_commands = nth_commands, - Value::Instances(instances) => selection.instances = instances, - Value::ShowHidden(show) => selection.visible = if show { None } else { Some(true) }, - Value::Errors(only) => selection.error = if only { Some(true) } else { None }, + if !self.0.is_empty() { + let mut selection = Selection::default(); + for value in values.into_values() { + match value { + Value::Or => self.0.push(take(&mut selection)), + Value::Classes(classes) => selection.classes = classes, + Value::Commands(commands) => selection.commands = commands, + Value::Subtypes(subtypes) => selection.subtypes = subtypes, + Value::Labels(labels) => selection.labels = labels, + Value::NthCommands(nth_commands) => selection.nth_commands = nth_commands, + Value::Instances(instances) => selection.instances = instances, + Value::ShowHidden(show) => { + selection.visible = if show { None } else { Some(true) } + } + Value::Errors(only) => selection.error = if only { Some(true) } else { None }, + } } + self.0.push(selection); } - self.0.push(selection); Ok(()) } } -- 2.30.2