Skip to content

Commit 448755c

Browse files
committed
Keep running until a fixed point is reached.
1 parent 7e69373 commit 448755c

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/main.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ enum PubKind {
1515
Private,
1616
}
1717

18-
fn process(cmd: &str, p: &Path) {
18+
fn process(cmd: &str, p: &Path) -> u64 {
1919
let pub_regex = RegexBuilder::new("pub(?:\\s*\\(\\s*(.*?)\\s*\\))?")
2020
.multi_line(true)
2121
.build()
2222
.unwrap();
2323
let mut cur_txt = read_to_string(p).unwrap();
2424
let mut i = 0;
2525
let mut cl = pub_regex.capture_locations();
26+
let mut num_changed = 0;
2627
while i < cur_txt.len() {
2728
print!(".");
2829
stdout().flush().ok();
@@ -66,6 +67,7 @@ fn process(cmd: &str, p: &Path) {
6667
.status()
6768
{
6869
Ok(s) if s.success() => {
70+
num_changed += 1;
6971
next_txt = try_txt;
7072
}
7173
_ => break,
@@ -80,6 +82,7 @@ fn process(cmd: &str, p: &Path) {
8082
}
8183
}
8284
write(p, cur_txt).unwrap();
85+
num_changed
8386
}
8487

8588
fn progname() -> String {
@@ -113,10 +116,23 @@ fn main() {
113116
}
114117

115118
let cmd_str = matches.opt_str("c").unwrap();
116-
for p in matches.free {
117-
print!("{}: ", p);
118-
stdout().flush().ok();
119-
process(cmd_str.as_str(), &Path::new(&p));
120-
println!("");
119+
let mut round = 1;
120+
loop {
121+
println!("===> Round {}", round);
122+
let mut changed = false;
123+
for p in &matches.free {
124+
print!("{}: ", p);
125+
stdout().flush().ok();
126+
let num_changed = process(cmd_str.as_str(), &Path::new(&p));
127+
if num_changed > 0 {
128+
print!(" ({} elements depub'ed)", num_changed);
129+
changed = true;
130+
}
131+
println!("");
132+
}
133+
if !changed {
134+
break;
135+
}
136+
round += 1;
121137
}
122138
}

0 commit comments

Comments
 (0)