From 5692ddcf67eb5e12a28e4ad6506f5681e1f313f6 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 1 May 2025 15:49:31 -0700 Subject: [PATCH] Move sources related to sys files into submodule. --- rust/pspp/src/dictionary.rs | 2 +- rust/pspp/src/format/mod.rs | 4 ++-- rust/pspp/src/format/parse.rs | 4 ++-- rust/pspp/src/lib.rs | 5 +---- rust/pspp/src/main.rs | 4 ++-- rust/pspp/src/output/pivot/mod.rs | 2 +- rust/pspp/src/settings.rs | 2 +- rust/pspp/src/{ => sys}/cooked.rs | 6 +++--- rust/pspp/src/{ => sys}/encoding.rs | 0 rust/pspp/src/sys/mod.rs | 4 ++++ rust/pspp/src/{ => sys}/raw.rs | 2 +- rust/pspp/src/{ => sys}/sack.rs | 2 +- rust/pspp/tests/sack.rs | 2 +- src/language/lexer/macro.c | 25 +++++++++++++++++++------ src/language/lexer/scan.c | 6 ++++++ src/output/cairo-pager.c | 2 +- src/output/table-provider.h | 1 + 17 files changed, 47 insertions(+), 26 deletions(-) rename rust/pspp/src/{ => sys}/cooked.rs (99%) rename rust/pspp/src/{ => sys}/encoding.rs (100%) create mode 100644 rust/pspp/src/sys/mod.rs rename rust/pspp/src/{ => sys}/raw.rs (99%) rename rust/pspp/src/{ => sys}/sack.rs (99%) diff --git a/rust/pspp/src/dictionary.rs b/rust/pspp/src/dictionary.rs index d0941be061..6a0a1843ba 100644 --- a/rust/pspp/src/dictionary.rs +++ b/rust/pspp/src/dictionary.rs @@ -18,7 +18,7 @@ use unicase::UniCase; use crate::{ format::Format, identifier::{ByIdentifier, HasIdentifier, Identifier}, - raw::{Alignment, CategoryLabels, Measure, MissingValues, RawString, VarType}, + sys::raw::{Alignment, CategoryLabels, Measure, MissingValues, RawString, VarType}, }; /// An index within [Dictionary::variables]. diff --git a/rust/pspp/src/format/mod.rs b/rust/pspp/src/format/mod.rs index 3078fffb43..2d17270b84 100644 --- a/rust/pspp/src/format/mod.rs +++ b/rust/pspp/src/format/mod.rs @@ -13,7 +13,7 @@ use unicode_width::UnicodeWidthStr; use crate::{ dictionary::{Value, VarWidth}, - raw::{self, RawString, VarType}, + sys::raw::{self, RawString, VarType}, }; mod display; @@ -377,7 +377,7 @@ impl Type { pub fn default_value(&self) -> Value { match self.var_type() { VarType::Numeric => Value::sysmis(), - VarType::String => Value::String(RawString::default()) + VarType::String => Value::String(RawString::default()), } } } diff --git a/rust/pspp/src/format/parse.rs b/rust/pspp/src/format/parse.rs index 222d61de50..2f5887370f 100644 --- a/rust/pspp/src/format/parse.rs +++ b/rust/pspp/src/format/parse.rs @@ -3,8 +3,8 @@ use crate::{ dictionary::Value, endian::{Endian, Parse}, format::{DateTemplate, Decimals, Settings, TemplateItem, Type}, - raw::{EncodedStr, EncodedString}, settings::{EndianSettings, Settings as PsppSettings}, + sys::raw::{EncodedStr, EncodedString}, }; use encoding_rs::Encoding; use smallstr::SmallString; @@ -911,8 +911,8 @@ mod test { parse::{ParseError, ParseErrorKind, Sign}, Epoch, Format, Settings as FormatSettings, Type, }, - raw::EncodedStr, settings::EndianSettings, + sys::raw::EncodedStr, }; fn test(name: &str, type_: Type) { diff --git a/rust/pspp/src/lib.rs b/rust/pspp/src/lib.rs index 3540125c81..b78b711bb4 100644 --- a/rust/pspp/src/lib.rs +++ b/rust/pspp/src/lib.rs @@ -1,8 +1,6 @@ pub mod calendar; pub mod command; -pub mod cooked; pub mod dictionary; -pub mod encoding; pub mod endian; pub mod engine; pub mod format; @@ -14,6 +12,5 @@ pub mod macros; pub mod message; pub mod output; pub mod prompt; -pub mod raw; -pub mod sack; pub mod settings; +pub mod sys; diff --git a/rust/pspp/src/main.rs b/rust/pspp/src/main.rs index 62ab24337b..35c057a341 100644 --- a/rust/pspp/src/main.rs +++ b/rust/pspp/src/main.rs @@ -17,8 +17,8 @@ use anyhow::Result; use clap::{Parser, ValueEnum}; use encoding_rs::Encoding; -use pspp::cooked::{decode, Headers}; -use pspp::raw::{encoding_from_headers, Decoder, Magic, Reader, Record}; +use pspp::sys::cooked::{decode, Headers}; +use pspp::sys::raw::{encoding_from_headers, Decoder, Magic, Reader, Record}; use std::fs::File; use std::io::BufReader; use std::path::{Path, PathBuf}; diff --git a/rust/pspp/src/output/pivot/mod.rs b/rust/pspp/src/output/pivot/mod.rs index d79e01a3bd..14a6e51055 100644 --- a/rust/pspp/src/output/pivot/mod.rs +++ b/rust/pspp/src/output/pivot/mod.rs @@ -54,8 +54,8 @@ use tlo::parse_tlo; use crate::{ dictionary::Value as DataValue, format::{Decimal, Format, Settings as FormatSettings, Type, UncheckedFormat}, - raw::VarType, settings::{Settings, Show}, + sys::raw::VarType, }; pub mod output; diff --git a/rust/pspp/src/settings.rs b/rust/pspp/src/settings.rs index 6aad340605..3bfb4f0141 100644 --- a/rust/pspp/src/settings.rs +++ b/rust/pspp/src/settings.rs @@ -128,7 +128,7 @@ impl Default for Settings { impl Settings { pub fn global() -> &'static Settings { static GLOBAL: OnceLock = OnceLock::new(); - GLOBAL.get_or_init( Settings::default) + GLOBAL.get_or_init(Settings::default) } } diff --git a/rust/pspp/src/cooked.rs b/rust/pspp/src/sys/cooked.rs similarity index 99% rename from rust/pspp/src/cooked.rs rename to rust/pspp/src/sys/cooked.rs index 8de34d5ac6..43e4aa3da5 100644 --- a/rust/pspp/src/cooked.rs +++ b/rust/pspp/src/sys/cooked.rs @@ -6,11 +6,11 @@ use crate::{ Dictionary, InvalidRole, MultipleResponseSet, MultipleResponseType, Value, VarWidth, Variable, VariableSet, }, - encoding::Error as EncodingError, endian::Endian, format::{Error as FormatError, Format, UncheckedFormat}, identifier::{ByIdentifier, Error as IdError, Identifier}, - raw::{ + sys::encoding::Error as EncodingError, + sys::raw::{ self, Cases, DecodedRecord, DocumentRecord, EncodingRecord, Extension, FileAttributeRecord, FloatInfoRecord, HeaderRecord, IntegerInfoRecord, LongName, LongNamesRecord, LongStringMissingValueRecord, LongStringValueLabelRecord, MissingValues, @@ -24,7 +24,7 @@ use encoding_rs::Encoding; use indexmap::set::MutableValues; use thiserror::Error as ThisError; -pub use crate::raw::{CategoryLabels, Compression}; +pub use crate::sys::raw::{CategoryLabels, Compression}; #[derive(ThisError, Debug)] pub enum Error { diff --git a/rust/pspp/src/encoding.rs b/rust/pspp/src/sys/encoding.rs similarity index 100% rename from rust/pspp/src/encoding.rs rename to rust/pspp/src/sys/encoding.rs diff --git a/rust/pspp/src/sys/mod.rs b/rust/pspp/src/sys/mod.rs new file mode 100644 index 0000000000..57a1d00e56 --- /dev/null +++ b/rust/pspp/src/sys/mod.rs @@ -0,0 +1,4 @@ +pub mod cooked; +pub mod encoding; +pub mod raw; +pub mod sack; diff --git a/rust/pspp/src/raw.rs b/rust/pspp/src/sys/raw.rs similarity index 99% rename from rust/pspp/src/raw.rs rename to rust/pspp/src/sys/raw.rs index 5c3eb85472..7a0af59e1d 100644 --- a/rust/pspp/src/raw.rs +++ b/rust/pspp/src/sys/raw.rs @@ -1,8 +1,8 @@ use crate::{ dictionary::{Attributes, Value, VarWidth}, - encoding::{default_encoding, get_encoding, Error as EncodingError}, endian::{Endian, Parse, ToBytes}, identifier::{Error as IdError, Identifier}, + sys::encoding::{default_encoding, get_encoding, Error as EncodingError}, }; use encoding_rs::{mem::decode_latin1, Encoding}; diff --git a/rust/pspp/src/sack.rs b/rust/pspp/src/sys/sack.rs similarity index 99% rename from rust/pspp/src/sack.rs rename to rust/pspp/src/sys/sack.rs index 8eec1eb1fd..103a9be847 100644 --- a/rust/pspp/src/sack.rs +++ b/rust/pspp/src/sys/sack.rs @@ -523,7 +523,7 @@ impl<'a> Lexer<'a> { #[cfg(test)] mod test { use crate::endian::Endian; - use crate::sack::sack; + use crate::sys::sack::sack; use anyhow::Result; use hexplay::HexView; diff --git a/rust/pspp/tests/sack.rs b/rust/pspp/tests/sack.rs index 49b10e77ac..5be80ea45f 100644 --- a/rust/pspp/tests/sack.rs +++ b/rust/pspp/tests/sack.rs @@ -4,7 +4,7 @@ use std::path::PathBuf; use anyhow::{anyhow, Result}; use clap::Parser; use pspp::endian::Endian; -use pspp::sack::sack; +use pspp::sys::sack::sack; /// SAv Construction Kit /// diff --git a/src/language/lexer/macro.c b/src/language/lexer/macro.c index d7bc1b611f..9536727a0f 100644 --- a/src/language/lexer/macro.c +++ b/src/language/lexer/macro.c @@ -357,10 +357,19 @@ classify_token (enum token_type type) NOT_REACHED (); } -/* Appends syntax for the tokens in MTS to S. */ +/* Appends syntax for the tokens in MTS to S. If OFS and LEN are nonnull, sets + OFS[i] to the offset within S of the start of token 'i' in MTS and LEN[i] to + its length. OFS[i] + LEN[i] is not necessarily OFS[i + 1] because some + tokens are separated by white space. */ void -macro_tokens_to_syntax (struct macro_tokens *mts, struct string *s) +macro_tokens_to_syntax (struct macro_tokens *mts, struct string *s, + size_t *ofs, size_t *len) { + assert ((ofs != NULL) == (len != NULL)); + + if (!mts->n) + return; + for (size_t i = 0; i < mts->n; i++) { if (i > 0) @@ -379,7 +388,11 @@ macro_tokens_to_syntax (struct macro_tokens *mts, struct string *s) } } + if (ofs) + ofs[i] = s->ss.length; macro_token_to_syntax (&mts->mts[i], s); + if (len) + len[i] = s->ss.length - ofs[i]; } } @@ -925,7 +938,7 @@ parse_function_arg (const struct macro_expander *me, if (param) { size_t param_idx = param - me->macro->params; - macro_tokens_to_syntax (me->args[param_idx], farg); + macro_tokens_to_syntax (me->args[param_idx], farg, NULL, NULL); return 1; } @@ -937,7 +950,7 @@ parse_function_arg (const struct macro_expander *me, break; if (i) ds_put_byte (farg, ' '); - macro_tokens_to_syntax (me->args[i], farg); + macro_tokens_to_syntax (me->args[i], farg, NULL, NULL); } return 1; } @@ -1254,7 +1267,7 @@ expand_macro_function (const struct macro_expander *me, if (mts.n > 1) { struct macro_tokens tail = { .mts = mts.mts + 1, .n = mts.n - 1 }; - macro_tokens_to_syntax (&tail, output); + macro_tokens_to_syntax (&tail, output, NULL, NULL); } macro_tokens_uninit (&mts); ds_destroy (&tmp); @@ -1293,7 +1306,7 @@ expand_macro_function (const struct macro_expander *me, subme.stack = &stack; macro_expand (mts.mts, mts.n, &subme, &exp); - macro_tokens_to_syntax (&exp, output); + macro_tokens_to_syntax (&exp, output, NULL, NULL); macro_tokens_uninit (&exp); macro_tokens_uninit (&mts); } diff --git a/src/language/lexer/scan.c b/src/language/lexer/scan.c index e0ab8f872e..e4fe405d47 100644 --- a/src/language/lexer/scan.c +++ b/src/language/lexer/scan.c @@ -222,6 +222,12 @@ scan_punct2__ (char c0, char c1) case '~': return T_NE; + + case '&': + return T_AND; + + case '|': + return T_OR; } NOT_REACHED (); diff --git a/src/output/cairo-pager.c b/src/output/cairo-pager.c index a52d0b095a..1dbffd8270 100644 --- a/src/output/cairo-pager.c +++ b/src/output/cairo-pager.c @@ -246,7 +246,7 @@ void xr_pager_destroy (struct xr_pager *p) { if (p) - {x + { free (p->nodes); xr_page_style_unref (p->page_style); diff --git a/src/output/table-provider.h b/src/output/table-provider.h index ecccbffe4e..a3d1fab78f 100644 --- a/src/output/table-provider.h +++ b/src/output/table-provider.h @@ -47,6 +47,7 @@ struct table_cell unsigned char options; /* TABLE_CELL_*. */ const struct pivot_value *value; + const struct font_style *font_style; const struct cell_style *cell_style; }; -- 2.30.2