Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fmt: stop breaking up words #866

Merged
merged 1 commit into from
Dec 6, 2024
Merged

fmt: stop breaking up words #866

merged 1 commit into from
Dec 6, 2024

Conversation

mknos
Copy link
Contributor

@mknos mknos commented Dec 6, 2024

  • I was annoyed with the old fmt algorithm because a word gets incorrectly chopped in the middle
  • Take a hint about parsing from NetBSD fmt.c source which splits input into word/whitespace_suffix pairs
  • Take another hint about paragraphing from GNU version output
  • We know the paragraph is finished when the indentation level of current word differs from the previous, or if we see two newlines in a row
%ifconfig | head -n 16 | perl fmt -w 52
eth0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500 
        ether dc:a6:32:e1:12:27  txqueuelen 1000  
        (Ethernet) RX packets 0  bytes 0 (0.0 B) 
        RX errors 0  dropped 0  overruns 0  frame 0 
        TX packets 0  bytes 0 (0.0 B) 
        TX errors 0  dropped 0 overruns 0  carrier 0  
        collisions 0 

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536 
        inet 127.0.0.1  netmask 255.0.0.0 
        inet6 ::1  prefixlen 128  scopeid 0x10<host> 
        loop  txqueuelen 1000  (Local Loopback) 
        RX packets 42  bytes 4449 (4.3 KiB) 
        RX errors 0  dropped 0  overruns 0  frame 0 
        TX packets 42  bytes 4449 (4.3 KiB) 
        TX errors 0  dropped 0 overruns 0  carrier 0  
        collisions 0 


%ifconfig | head -n 16 | perl fmt -w 42
eth0: flags=4099<UP,BROADCAST,MULTICAST>  
mtu 1500 
        ether dc:a6:32:e1:12:27  txqueuelen 
        1000  (Ethernet) RX packets 0  
        bytes 0 (0.0 B) RX errors 0  
        dropped 0  overruns 0  frame 0 TX 
        packets 0  bytes 0 (0.0 B) TX 
        errors 0  dropped 0 overruns 0  
        carrier 0  collisions 0 

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 
65536 
        inet 127.0.0.1  netmask 255.0.0.0 
        inet6 ::1  prefixlen 128  scopeid 
        0x10<host> loop  txqueuelen 1000  
        (Local Loopback) RX packets 42  
        bytes 4449 (4.3 KiB) RX errors 0  
        dropped 0  overruns 0  frame 0 TX 
        packets 42  bytes 4449 (4.3 KiB) TX 
        errors 0  dropped 0 overruns 0  
        carrier 0  collisions 0

* I was annoyed with the old fmt algorithm because a word gets incorrectly chopped in the middle
* Take a hint about parsing from NetBSD fmt.c source which splits input into word/whitespace_suffix pairs
* Take a hint about paragraphing from GNU version output
* We know the paragraph is finished when the indentation level of current word differs from the previous, or if we see two newlines in a row

%ifconfig | head -n 16 | perl fmt -w 52
eth0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500 
        ether dc:a6:32:e1:12:27  txqueuelen 1000  
        (Ethernet) RX packets 0  bytes 0 (0.0 B) 
        RX errors 0  dropped 0  overruns 0  frame 0 
        TX packets 0  bytes 0 (0.0 B) 
        TX errors 0  dropped 0 overruns 0  carrier 0  
        collisions 0 

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536 
        inet 127.0.0.1  netmask 255.0.0.0 
        inet6 ::1  prefixlen 128  scopeid 0x10<host> 
        loop  txqueuelen 1000  (Local Loopback) 
        RX packets 42  bytes 4449 (4.3 KiB) 
        RX errors 0  dropped 0  overruns 0  frame 0 
        TX packets 42  bytes 4449 (4.3 KiB) 
        TX errors 0  dropped 0 overruns 0  carrier 0  
        collisions 0 


%ifconfig | head -n 16 | perl fmt -w 42
eth0: flags=4099<UP,BROADCAST,MULTICAST>  
mtu 1500 
        ether dc:a6:32:e1:12:27  txqueuelen 
        1000  (Ethernet) RX packets 0  
        bytes 0 (0.0 B) RX errors 0  
        dropped 0  overruns 0  frame 0 TX 
        packets 0  bytes 0 (0.0 B) TX 
        errors 0  dropped 0 overruns 0  
        carrier 0  collisions 0 

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 
65536 
        inet 127.0.0.1  netmask 255.0.0.0 
        inet6 ::1  prefixlen 128  scopeid 
        0x10<host> loop  txqueuelen 1000  
        (Local Loopback) RX packets 42  
        bytes 4449 (4.3 KiB) RX errors 0  
        dropped 0  overruns 0  frame 0 TX 
        packets 42  bytes 4449 (4.3 KiB) TX 
        errors 0  dropped 0 overruns 0  
        carrier 0  collisions 0
@github-actions github-actions bot added Type: enhancement improve a feature that already exists Priority: low get to this whenever Program: fmt The fat program labels Dec 6, 2024
@mknos mknos temporarily deployed to automated_testing December 6, 2024 08:35 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing December 6, 2024 08:35 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing December 6, 2024 08:35 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing December 6, 2024 08:35 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing December 6, 2024 08:35 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing December 6, 2024 08:35 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing December 6, 2024 08:35 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing December 6, 2024 08:35 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing December 6, 2024 08:35 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing December 6, 2024 08:35 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing December 6, 2024 08:35 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing December 6, 2024 08:35 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing December 6, 2024 08:35 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing December 6, 2024 08:35 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing December 6, 2024 08:35 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing December 6, 2024 08:35 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing December 6, 2024 08:35 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing December 6, 2024 08:35 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing December 6, 2024 08:35 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing December 6, 2024 08:36 — with GitHub Actions Inactive
@coveralls
Copy link

coveralls commented Dec 6, 2024

Pull Request Test Coverage Report for Build 12195575995

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 72.464%

Totals Coverage Status
Change from base Build 12185242343: 0.0%
Covered Lines: 350
Relevant Lines: 483

💛 - Coveralls

@briandfoy briandfoy self-assigned this Dec 6, 2024
@briandfoy briandfoy merged commit 079abb7 into briandfoy:master Dec 6, 2024
23 checks passed
@briandfoy
Copy link
Owner

changes: use GNU's method for formatting so single words aren't broken up

@briandfoy briandfoy added Status: accepted The fix is accepted Type: bug an existing feature does not work Status: released there is a new release with this fix and removed Priority: low get to this whenever Type: enhancement improve a feature that already exists Status: accepted The fix is accepted labels Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Program: fmt The fat program Status: released there is a new release with this fix Type: bug an existing feature does not work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants