Skip to content

Commit

Permalink
bin.rs fix --separator, use for utmpx
Browse files Browse the repository at this point in the history
Change --sysline-separator to --separator.

Print separator value for utmpx records.
  • Loading branch information
jtmoon79 committed Mar 18, 2023
1 parent e933474 commit 24f00e7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ Options:
Align column widths of prepended data.
--prepend-separator <PREPEND_SEPARATOR>
Separator string for prepended data. [default: :]
--sysline-separator <SYSLINE_SEPARATOR>
An extra separator string between printed log lines.
--separator <LOG_MESSAGE_SEPARATOR>
An extra separator string between printed log messages.
One "syslog line", or "sysline", may have multiple lines of text.
Accepts a basic set of backslash escape sequences,
e.g. "\0" for the null character.
Expand Down Expand Up @@ -236,7 +236,7 @@ the Datetime Filter is presumed to be the local system timezone.
Ambiguous named timezones will be rejected, e.g. "SST".
Backslash escape sequences accepted by "--sysline-separator" are:
Backslash escape sequences accepted by "--separator" are:
"\0",
"\a",
"\b",
Expand Down
34 changes: 21 additions & 13 deletions src/bin/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ the Datetime Filter is presumed to be the local system timezone.
Ambiguous named timezones will be rejected, e.g. \"SST\".
Backslash escape sequences accepted by \"--sysline-separator\" are:
Backslash escape sequences accepted by \"--separator\" are:
\"", unescape::BACKSLASH_ESCAPE_SEQUENCES0, "\",
\"", unescape::BACKSLASH_ESCAPE_SEQUENCES1, "\",
\"", unescape::BACKSLASH_ESCAPE_SEQUENCES2, "\",
Expand Down Expand Up @@ -557,18 +557,18 @@ struct CLI_Args {
)]
prepend_separator: String,

/// An extra separator string between printed log lines.
/// An extra separator string between printed log messages.
/// One "syslog line", or "sysline", may have multiple lines of text.
/// Accepts a basic set of backslash escape sequences,
/// e.g. "\0" for the null character.
#[clap(
long = "sysline-separator",
long = "separator",
required = false,
verbatim_doc_comment,
default_value_t = String::from(""),
hide_default_value = true,
)]
sysline_separator: String,
log_message_separator: String,

/// Choose to print to terminal using colors.
#[clap(
Expand Down Expand Up @@ -1212,7 +1212,7 @@ fn cli_process_args() -> (
CLI_Color_Choice::never => ColorChoice::Never,
};

let sysline_separator: String = match unescape::unescape_str(args.sysline_separator.as_str()) {
let log_message_separator: String = match unescape::unescape_str(args.log_message_separator.as_str()) {
Ok(val) => val,
Err(err) => {
eprintln!("ERROR: {:?}", err);
Expand All @@ -1228,7 +1228,7 @@ fn cli_process_args() -> (
defo!("prepend_filepath {:?}", args.prepend_filepath);
defo!("prepend_file_align {:?}", args.prepend_file_align);
defo!("prepend_separator {:?}", args.prepend_separator);
defo!("sysline_separator {:?}", sysline_separator);
defo!("log_message_separator {:?}", log_message_separator);
defo!("summary {:?}", args.summary);

(
Expand All @@ -1245,7 +1245,7 @@ fn cli_process_args() -> (
args.prepend_filepath,
args.prepend_file_align,
args.prepend_separator,
sysline_separator,
log_message_separator,
args.summary,
)
}
Expand Down Expand Up @@ -1277,7 +1277,7 @@ pub fn main() -> ExitCode {
cli_opt_prepend_filepath,
cli_opt_prepend_file_align,
cli_prepend_separator,
sysline_separator,
log_message_separator,
cli_opt_summary,
) = cli_process_args();

Expand Down Expand Up @@ -1307,7 +1307,7 @@ pub fn main() -> ExitCode {
cli_opt_prepend_filepath,
cli_opt_prepend_file_align,
cli_prepend_separator,
sysline_separator,
log_message_separator,
cli_opt_summary,
);

Expand Down Expand Up @@ -2307,7 +2307,7 @@ fn processing_loop(
cli_opt_prepend_filepath: bool,
cli_opt_prepend_file_align: bool,
cli_prepend_separator: String,
sysline_separator: String,
log_message_separator: String,
cli_opt_summary: bool,
) -> bool {
defn!(
Expand Down Expand Up @@ -2619,8 +2619,10 @@ fn processing_loop(

// channels that should be disconnected per "game loop" loop iteration
let mut disconnect = Vec::<PathId>::with_capacity(file_count);
// shortcut to the bytes of the `sysline_separator`
let sepb: &[u8] = sysline_separator.as_str().as_bytes();
// shortcut to the "sep"arator "b"ytes of the `log_message_separator`
let sepb: &[u8] = log_message_separator.as_str().as_bytes();
// shortcut to check if `sepb` should be printed
let sepb_print: bool = ! sepb.is_empty();

// buffer to assist printing Utmpx; passed to `Utmpx::as_bytes`
let mut buffer_utmp: [u8; UTMPX_SZ * 2] = [0; UTMPX_SZ * 2];
Expand Down Expand Up @@ -2934,7 +2936,7 @@ fn processing_loop(
}
}
}
if ! sepb.is_empty() {
if sepb_print {
write_stdout(sepb);
if cli_opt_summary {
summaryprinted.bytes += sepb.len() as Count;
Expand Down Expand Up @@ -2980,6 +2982,12 @@ fn processing_loop(
}
}
}
if sepb_print {
write_stdout(sepb);
if cli_opt_summary {
summaryprinted.bytes += sepb.len() as Count;
}
}
if cli_opt_summary {
paths_printed_logmessages.insert(*pathid);
// update the per processing file `SummaryPrinted`
Expand Down

0 comments on commit 24f00e7

Please sign in to comment.