coreutils/fmt/fmt.rs

237 lines
8.4 KiB
Rust
Raw Normal View History

2014-07-06 08:13:36 +00:00
#![crate_name = "fmt"]
initial release of working fmt Note: for now, this version does not use Knuth-Plass, but everything else is in place with "greedy" breaking. All options (should) work, and performance is nearly on par with GNU fmt. Squashed commit of the following local commits: commit ebc12f5e7d19d351ada9273ec0c42d66d3730431 commit 125fdabcb2a32de161c7a8b76c3e766a40ff9f76 commit dadd62acc093b5bd4bc94ad4f8a499d2663a7097 commit e436fdaade3876e92020c61a736eba54eb5ca0cf commit bbc4f4f6ad749753efe9b2df871ddb257f33de4b commit 12bc4ecb0c56c0d43515a111e9129a4bfaf36531 commit 2e693553ed9af59c53ee13026d19c9f82f2973fc commit 9b15a130148d62dd6a1d2765848ddc4daf30c649 commit ea335eb2869afcc94709345118fab3fb2e612954 Merge: ee92573 23cc41d commit 23cc41d188cb3134c04872fd77acb331d86a64ea commit 2fa7c48133001d86da39feda04d870ff67e88400 commit eb71558ee46654b568adf167f194cb854bbf7056 commit c8baabc0b86d831b5741fa496c312134db652c55 commit ee4fab44b216c1d9c7dcdcdc29ca587c76284834 commit c5444416a531ae1341dddbfd528e4a3ee5f106bf commit e1177d47941654b8834d18599c80065943a26159 commit c7fb30e2ff32313974f99d34ba4735be064b0cc5 commit 99a9406bc6fff33fc64c190356e48f443312a6c4 commit 3d244d62c9b60b579f2e5b723da6389a5dbc8805 commit 2d4f09cb2ff83664730edba209ec129abdcf1403 commit 947c32b72bff8d50e362555ec21a6b848d5fec9f commit 8556d2a3467651ee7833ad800876af35a7dd5db7 commit a2e4bc3dc45e5f39b402e6fdd3e19edcea6d3c34 Merge: 0308884 439e65d commit 03088844f1fd2faca6c3471230730136dd140f35 commit ac80d888649dd1311fdaa68400ea45d52b2e23ab commit c1d6b36acb7038e14d5b3e1fb6a44614a3351f96 commit 6539b102593aa9d9570df8be99ca1a1bf01ea1f4 commit 439e65d3331936e00fa89a4b2f88c343b9e28c5b commit fac27de7c4918bc5cf1a1ac1a43550236ba8af4d commit 365989c5bbe5c2289648f6efbc3c9388388e30a0 commit 3dd71364cce9aaaa773fc88eb206aba31aa61390
2014-06-19 00:43:26 +00:00
/*
* This file is part of `fmt` from the uutils coreutils package.
*
* (c) kwantam <kwantam@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
#![feature(macro_rules)]
extern crate core;
extern crate getopts;
use std::cmp;
initial release of working fmt Note: for now, this version does not use Knuth-Plass, but everything else is in place with "greedy" breaking. All options (should) work, and performance is nearly on par with GNU fmt. Squashed commit of the following local commits: commit ebc12f5e7d19d351ada9273ec0c42d66d3730431 commit 125fdabcb2a32de161c7a8b76c3e766a40ff9f76 commit dadd62acc093b5bd4bc94ad4f8a499d2663a7097 commit e436fdaade3876e92020c61a736eba54eb5ca0cf commit bbc4f4f6ad749753efe9b2df871ddb257f33de4b commit 12bc4ecb0c56c0d43515a111e9129a4bfaf36531 commit 2e693553ed9af59c53ee13026d19c9f82f2973fc commit 9b15a130148d62dd6a1d2765848ddc4daf30c649 commit ea335eb2869afcc94709345118fab3fb2e612954 Merge: ee92573 23cc41d commit 23cc41d188cb3134c04872fd77acb331d86a64ea commit 2fa7c48133001d86da39feda04d870ff67e88400 commit eb71558ee46654b568adf167f194cb854bbf7056 commit c8baabc0b86d831b5741fa496c312134db652c55 commit ee4fab44b216c1d9c7dcdcdc29ca587c76284834 commit c5444416a531ae1341dddbfd528e4a3ee5f106bf commit e1177d47941654b8834d18599c80065943a26159 commit c7fb30e2ff32313974f99d34ba4735be064b0cc5 commit 99a9406bc6fff33fc64c190356e48f443312a6c4 commit 3d244d62c9b60b579f2e5b723da6389a5dbc8805 commit 2d4f09cb2ff83664730edba209ec129abdcf1403 commit 947c32b72bff8d50e362555ec21a6b848d5fec9f commit 8556d2a3467651ee7833ad800876af35a7dd5db7 commit a2e4bc3dc45e5f39b402e6fdd3e19edcea6d3c34 Merge: 0308884 439e65d commit 03088844f1fd2faca6c3471230730136dd140f35 commit ac80d888649dd1311fdaa68400ea45d52b2e23ab commit c1d6b36acb7038e14d5b3e1fb6a44614a3351f96 commit 6539b102593aa9d9570df8be99ca1a1bf01ea1f4 commit 439e65d3331936e00fa89a4b2f88c343b9e28c5b commit fac27de7c4918bc5cf1a1ac1a43550236ba8af4d commit 365989c5bbe5c2289648f6efbc3c9388388e30a0 commit 3dd71364cce9aaaa773fc88eb206aba31aa61390
2014-06-19 00:43:26 +00:00
use std::io::{BufferedReader, BufferedWriter, File, IoResult};
use std::io::stdio::{stdin_raw, stdout_raw};
use linebreak::break_lines;
use parasplit::ParagraphStream;
initial release of working fmt Note: for now, this version does not use Knuth-Plass, but everything else is in place with "greedy" breaking. All options (should) work, and performance is nearly on par with GNU fmt. Squashed commit of the following local commits: commit ebc12f5e7d19d351ada9273ec0c42d66d3730431 commit 125fdabcb2a32de161c7a8b76c3e766a40ff9f76 commit dadd62acc093b5bd4bc94ad4f8a499d2663a7097 commit e436fdaade3876e92020c61a736eba54eb5ca0cf commit bbc4f4f6ad749753efe9b2df871ddb257f33de4b commit 12bc4ecb0c56c0d43515a111e9129a4bfaf36531 commit 2e693553ed9af59c53ee13026d19c9f82f2973fc commit 9b15a130148d62dd6a1d2765848ddc4daf30c649 commit ea335eb2869afcc94709345118fab3fb2e612954 Merge: ee92573 23cc41d commit 23cc41d188cb3134c04872fd77acb331d86a64ea commit 2fa7c48133001d86da39feda04d870ff67e88400 commit eb71558ee46654b568adf167f194cb854bbf7056 commit c8baabc0b86d831b5741fa496c312134db652c55 commit ee4fab44b216c1d9c7dcdcdc29ca587c76284834 commit c5444416a531ae1341dddbfd528e4a3ee5f106bf commit e1177d47941654b8834d18599c80065943a26159 commit c7fb30e2ff32313974f99d34ba4735be064b0cc5 commit 99a9406bc6fff33fc64c190356e48f443312a6c4 commit 3d244d62c9b60b579f2e5b723da6389a5dbc8805 commit 2d4f09cb2ff83664730edba209ec129abdcf1403 commit 947c32b72bff8d50e362555ec21a6b848d5fec9f commit 8556d2a3467651ee7833ad800876af35a7dd5db7 commit a2e4bc3dc45e5f39b402e6fdd3e19edcea6d3c34 Merge: 0308884 439e65d commit 03088844f1fd2faca6c3471230730136dd140f35 commit ac80d888649dd1311fdaa68400ea45d52b2e23ab commit c1d6b36acb7038e14d5b3e1fb6a44614a3351f96 commit 6539b102593aa9d9570df8be99ca1a1bf01ea1f4 commit 439e65d3331936e00fa89a4b2f88c343b9e28c5b commit fac27de7c4918bc5cf1a1ac1a43550236ba8af4d commit 365989c5bbe5c2289648f6efbc3c9388388e30a0 commit 3dd71364cce9aaaa773fc88eb206aba31aa61390
2014-06-19 00:43:26 +00:00
#[macro_export]
macro_rules! silent_unwrap(
($exp:expr) => (
match $exp {
Ok(_) => (),
Err(_) => unsafe { ::util::libc::exit(1) }
initial release of working fmt Note: for now, this version does not use Knuth-Plass, but everything else is in place with "greedy" breaking. All options (should) work, and performance is nearly on par with GNU fmt. Squashed commit of the following local commits: commit ebc12f5e7d19d351ada9273ec0c42d66d3730431 commit 125fdabcb2a32de161c7a8b76c3e766a40ff9f76 commit dadd62acc093b5bd4bc94ad4f8a499d2663a7097 commit e436fdaade3876e92020c61a736eba54eb5ca0cf commit bbc4f4f6ad749753efe9b2df871ddb257f33de4b commit 12bc4ecb0c56c0d43515a111e9129a4bfaf36531 commit 2e693553ed9af59c53ee13026d19c9f82f2973fc commit 9b15a130148d62dd6a1d2765848ddc4daf30c649 commit ea335eb2869afcc94709345118fab3fb2e612954 Merge: ee92573 23cc41d commit 23cc41d188cb3134c04872fd77acb331d86a64ea commit 2fa7c48133001d86da39feda04d870ff67e88400 commit eb71558ee46654b568adf167f194cb854bbf7056 commit c8baabc0b86d831b5741fa496c312134db652c55 commit ee4fab44b216c1d9c7dcdcdc29ca587c76284834 commit c5444416a531ae1341dddbfd528e4a3ee5f106bf commit e1177d47941654b8834d18599c80065943a26159 commit c7fb30e2ff32313974f99d34ba4735be064b0cc5 commit 99a9406bc6fff33fc64c190356e48f443312a6c4 commit 3d244d62c9b60b579f2e5b723da6389a5dbc8805 commit 2d4f09cb2ff83664730edba209ec129abdcf1403 commit 947c32b72bff8d50e362555ec21a6b848d5fec9f commit 8556d2a3467651ee7833ad800876af35a7dd5db7 commit a2e4bc3dc45e5f39b402e6fdd3e19edcea6d3c34 Merge: 0308884 439e65d commit 03088844f1fd2faca6c3471230730136dd140f35 commit ac80d888649dd1311fdaa68400ea45d52b2e23ab commit c1d6b36acb7038e14d5b3e1fb6a44614a3351f96 commit 6539b102593aa9d9570df8be99ca1a1bf01ea1f4 commit 439e65d3331936e00fa89a4b2f88c343b9e28c5b commit fac27de7c4918bc5cf1a1ac1a43550236ba8af4d commit 365989c5bbe5c2289648f6efbc3c9388388e30a0 commit 3dd71364cce9aaaa773fc88eb206aba31aa61390
2014-06-19 00:43:26 +00:00
}
)
)
#[path = "../common/util.rs"]
mod util;
mod linebreak;
mod parasplit;
mod charwidth;
initial release of working fmt Note: for now, this version does not use Knuth-Plass, but everything else is in place with "greedy" breaking. All options (should) work, and performance is nearly on par with GNU fmt. Squashed commit of the following local commits: commit ebc12f5e7d19d351ada9273ec0c42d66d3730431 commit 125fdabcb2a32de161c7a8b76c3e766a40ff9f76 commit dadd62acc093b5bd4bc94ad4f8a499d2663a7097 commit e436fdaade3876e92020c61a736eba54eb5ca0cf commit bbc4f4f6ad749753efe9b2df871ddb257f33de4b commit 12bc4ecb0c56c0d43515a111e9129a4bfaf36531 commit 2e693553ed9af59c53ee13026d19c9f82f2973fc commit 9b15a130148d62dd6a1d2765848ddc4daf30c649 commit ea335eb2869afcc94709345118fab3fb2e612954 Merge: ee92573 23cc41d commit 23cc41d188cb3134c04872fd77acb331d86a64ea commit 2fa7c48133001d86da39feda04d870ff67e88400 commit eb71558ee46654b568adf167f194cb854bbf7056 commit c8baabc0b86d831b5741fa496c312134db652c55 commit ee4fab44b216c1d9c7dcdcdc29ca587c76284834 commit c5444416a531ae1341dddbfd528e4a3ee5f106bf commit e1177d47941654b8834d18599c80065943a26159 commit c7fb30e2ff32313974f99d34ba4735be064b0cc5 commit 99a9406bc6fff33fc64c190356e48f443312a6c4 commit 3d244d62c9b60b579f2e5b723da6389a5dbc8805 commit 2d4f09cb2ff83664730edba209ec129abdcf1403 commit 947c32b72bff8d50e362555ec21a6b848d5fec9f commit 8556d2a3467651ee7833ad800876af35a7dd5db7 commit a2e4bc3dc45e5f39b402e6fdd3e19edcea6d3c34 Merge: 0308884 439e65d commit 03088844f1fd2faca6c3471230730136dd140f35 commit ac80d888649dd1311fdaa68400ea45d52b2e23ab commit c1d6b36acb7038e14d5b3e1fb6a44614a3351f96 commit 6539b102593aa9d9570df8be99ca1a1bf01ea1f4 commit 439e65d3331936e00fa89a4b2f88c343b9e28c5b commit fac27de7c4918bc5cf1a1ac1a43550236ba8af4d commit 365989c5bbe5c2289648f6efbc3c9388388e30a0 commit 3dd71364cce9aaaa773fc88eb206aba31aa61390
2014-06-19 00:43:26 +00:00
// program's NAME and VERSION are used for -V and -h
static NAME: &'static str = "fmt";
static VERSION: &'static str = "0.0.3";
initial release of working fmt Note: for now, this version does not use Knuth-Plass, but everything else is in place with "greedy" breaking. All options (should) work, and performance is nearly on par with GNU fmt. Squashed commit of the following local commits: commit ebc12f5e7d19d351ada9273ec0c42d66d3730431 commit 125fdabcb2a32de161c7a8b76c3e766a40ff9f76 commit dadd62acc093b5bd4bc94ad4f8a499d2663a7097 commit e436fdaade3876e92020c61a736eba54eb5ca0cf commit bbc4f4f6ad749753efe9b2df871ddb257f33de4b commit 12bc4ecb0c56c0d43515a111e9129a4bfaf36531 commit 2e693553ed9af59c53ee13026d19c9f82f2973fc commit 9b15a130148d62dd6a1d2765848ddc4daf30c649 commit ea335eb2869afcc94709345118fab3fb2e612954 Merge: ee92573 23cc41d commit 23cc41d188cb3134c04872fd77acb331d86a64ea commit 2fa7c48133001d86da39feda04d870ff67e88400 commit eb71558ee46654b568adf167f194cb854bbf7056 commit c8baabc0b86d831b5741fa496c312134db652c55 commit ee4fab44b216c1d9c7dcdcdc29ca587c76284834 commit c5444416a531ae1341dddbfd528e4a3ee5f106bf commit e1177d47941654b8834d18599c80065943a26159 commit c7fb30e2ff32313974f99d34ba4735be064b0cc5 commit 99a9406bc6fff33fc64c190356e48f443312a6c4 commit 3d244d62c9b60b579f2e5b723da6389a5dbc8805 commit 2d4f09cb2ff83664730edba209ec129abdcf1403 commit 947c32b72bff8d50e362555ec21a6b848d5fec9f commit 8556d2a3467651ee7833ad800876af35a7dd5db7 commit a2e4bc3dc45e5f39b402e6fdd3e19edcea6d3c34 Merge: 0308884 439e65d commit 03088844f1fd2faca6c3471230730136dd140f35 commit ac80d888649dd1311fdaa68400ea45d52b2e23ab commit c1d6b36acb7038e14d5b3e1fb6a44614a3351f96 commit 6539b102593aa9d9570df8be99ca1a1bf01ea1f4 commit 439e65d3331936e00fa89a4b2f88c343b9e28c5b commit fac27de7c4918bc5cf1a1ac1a43550236ba8af4d commit 365989c5bbe5c2289648f6efbc3c9388388e30a0 commit 3dd71364cce9aaaa773fc88eb206aba31aa61390
2014-06-19 00:43:26 +00:00
struct FmtOptions {
crown : bool,
tagged : bool,
mail : bool,
split_only : bool,
use_prefix : bool,
prefix : String,
xprefix : bool,
initial release of working fmt Note: for now, this version does not use Knuth-Plass, but everything else is in place with "greedy" breaking. All options (should) work, and performance is nearly on par with GNU fmt. Squashed commit of the following local commits: commit ebc12f5e7d19d351ada9273ec0c42d66d3730431 commit 125fdabcb2a32de161c7a8b76c3e766a40ff9f76 commit dadd62acc093b5bd4bc94ad4f8a499d2663a7097 commit e436fdaade3876e92020c61a736eba54eb5ca0cf commit bbc4f4f6ad749753efe9b2df871ddb257f33de4b commit 12bc4ecb0c56c0d43515a111e9129a4bfaf36531 commit 2e693553ed9af59c53ee13026d19c9f82f2973fc commit 9b15a130148d62dd6a1d2765848ddc4daf30c649 commit ea335eb2869afcc94709345118fab3fb2e612954 Merge: ee92573 23cc41d commit 23cc41d188cb3134c04872fd77acb331d86a64ea commit 2fa7c48133001d86da39feda04d870ff67e88400 commit eb71558ee46654b568adf167f194cb854bbf7056 commit c8baabc0b86d831b5741fa496c312134db652c55 commit ee4fab44b216c1d9c7dcdcdc29ca587c76284834 commit c5444416a531ae1341dddbfd528e4a3ee5f106bf commit e1177d47941654b8834d18599c80065943a26159 commit c7fb30e2ff32313974f99d34ba4735be064b0cc5 commit 99a9406bc6fff33fc64c190356e48f443312a6c4 commit 3d244d62c9b60b579f2e5b723da6389a5dbc8805 commit 2d4f09cb2ff83664730edba209ec129abdcf1403 commit 947c32b72bff8d50e362555ec21a6b848d5fec9f commit 8556d2a3467651ee7833ad800876af35a7dd5db7 commit a2e4bc3dc45e5f39b402e6fdd3e19edcea6d3c34 Merge: 0308884 439e65d commit 03088844f1fd2faca6c3471230730136dd140f35 commit ac80d888649dd1311fdaa68400ea45d52b2e23ab commit c1d6b36acb7038e14d5b3e1fb6a44614a3351f96 commit 6539b102593aa9d9570df8be99ca1a1bf01ea1f4 commit 439e65d3331936e00fa89a4b2f88c343b9e28c5b commit fac27de7c4918bc5cf1a1ac1a43550236ba8af4d commit 365989c5bbe5c2289648f6efbc3c9388388e30a0 commit 3dd71364cce9aaaa773fc88eb206aba31aa61390
2014-06-19 00:43:26 +00:00
use_anti_prefix : bool,
anti_prefix : String,
xanti_prefix : bool,
uniform : bool,
quick : bool,
width : uint,
goal : uint,
tabwidth : uint,
initial release of working fmt Note: for now, this version does not use Knuth-Plass, but everything else is in place with "greedy" breaking. All options (should) work, and performance is nearly on par with GNU fmt. Squashed commit of the following local commits: commit ebc12f5e7d19d351ada9273ec0c42d66d3730431 commit 125fdabcb2a32de161c7a8b76c3e766a40ff9f76 commit dadd62acc093b5bd4bc94ad4f8a499d2663a7097 commit e436fdaade3876e92020c61a736eba54eb5ca0cf commit bbc4f4f6ad749753efe9b2df871ddb257f33de4b commit 12bc4ecb0c56c0d43515a111e9129a4bfaf36531 commit 2e693553ed9af59c53ee13026d19c9f82f2973fc commit 9b15a130148d62dd6a1d2765848ddc4daf30c649 commit ea335eb2869afcc94709345118fab3fb2e612954 Merge: ee92573 23cc41d commit 23cc41d188cb3134c04872fd77acb331d86a64ea commit 2fa7c48133001d86da39feda04d870ff67e88400 commit eb71558ee46654b568adf167f194cb854bbf7056 commit c8baabc0b86d831b5741fa496c312134db652c55 commit ee4fab44b216c1d9c7dcdcdc29ca587c76284834 commit c5444416a531ae1341dddbfd528e4a3ee5f106bf commit e1177d47941654b8834d18599c80065943a26159 commit c7fb30e2ff32313974f99d34ba4735be064b0cc5 commit 99a9406bc6fff33fc64c190356e48f443312a6c4 commit 3d244d62c9b60b579f2e5b723da6389a5dbc8805 commit 2d4f09cb2ff83664730edba209ec129abdcf1403 commit 947c32b72bff8d50e362555ec21a6b848d5fec9f commit 8556d2a3467651ee7833ad800876af35a7dd5db7 commit a2e4bc3dc45e5f39b402e6fdd3e19edcea6d3c34 Merge: 0308884 439e65d commit 03088844f1fd2faca6c3471230730136dd140f35 commit ac80d888649dd1311fdaa68400ea45d52b2e23ab commit c1d6b36acb7038e14d5b3e1fb6a44614a3351f96 commit 6539b102593aa9d9570df8be99ca1a1bf01ea1f4 commit 439e65d3331936e00fa89a4b2f88c343b9e28c5b commit fac27de7c4918bc5cf1a1ac1a43550236ba8af4d commit 365989c5bbe5c2289648f6efbc3c9388388e30a0 commit 3dd71364cce9aaaa773fc88eb206aba31aa61390
2014-06-19 00:43:26 +00:00
}
2014-06-19 23:03:04 +00:00
pub fn uumain(args: Vec<String>) -> int {
initial release of working fmt Note: for now, this version does not use Knuth-Plass, but everything else is in place with "greedy" breaking. All options (should) work, and performance is nearly on par with GNU fmt. Squashed commit of the following local commits: commit ebc12f5e7d19d351ada9273ec0c42d66d3730431 commit 125fdabcb2a32de161c7a8b76c3e766a40ff9f76 commit dadd62acc093b5bd4bc94ad4f8a499d2663a7097 commit e436fdaade3876e92020c61a736eba54eb5ca0cf commit bbc4f4f6ad749753efe9b2df871ddb257f33de4b commit 12bc4ecb0c56c0d43515a111e9129a4bfaf36531 commit 2e693553ed9af59c53ee13026d19c9f82f2973fc commit 9b15a130148d62dd6a1d2765848ddc4daf30c649 commit ea335eb2869afcc94709345118fab3fb2e612954 Merge: ee92573 23cc41d commit 23cc41d188cb3134c04872fd77acb331d86a64ea commit 2fa7c48133001d86da39feda04d870ff67e88400 commit eb71558ee46654b568adf167f194cb854bbf7056 commit c8baabc0b86d831b5741fa496c312134db652c55 commit ee4fab44b216c1d9c7dcdcdc29ca587c76284834 commit c5444416a531ae1341dddbfd528e4a3ee5f106bf commit e1177d47941654b8834d18599c80065943a26159 commit c7fb30e2ff32313974f99d34ba4735be064b0cc5 commit 99a9406bc6fff33fc64c190356e48f443312a6c4 commit 3d244d62c9b60b579f2e5b723da6389a5dbc8805 commit 2d4f09cb2ff83664730edba209ec129abdcf1403 commit 947c32b72bff8d50e362555ec21a6b848d5fec9f commit 8556d2a3467651ee7833ad800876af35a7dd5db7 commit a2e4bc3dc45e5f39b402e6fdd3e19edcea6d3c34 Merge: 0308884 439e65d commit 03088844f1fd2faca6c3471230730136dd140f35 commit ac80d888649dd1311fdaa68400ea45d52b2e23ab commit c1d6b36acb7038e14d5b3e1fb6a44614a3351f96 commit 6539b102593aa9d9570df8be99ca1a1bf01ea1f4 commit 439e65d3331936e00fa89a4b2f88c343b9e28c5b commit fac27de7c4918bc5cf1a1ac1a43550236ba8af4d commit 365989c5bbe5c2289648f6efbc3c9388388e30a0 commit 3dd71364cce9aaaa773fc88eb206aba31aa61390
2014-06-19 00:43:26 +00:00
let opts = [
getopts::optflag("c", "crown-margin", "First and second line of paragraph may have different indentations, in which case the first line's indentation is preserved, and each subsequent line's indentation matches the second line."),
getopts::optflag("t", "tagged-paragraph", "Like -c, except that the first and second line of a paragraph *must* have different indentation or they are treated as separate paragraphs."),
getopts::optflag("m", "preserve-headers", "Attempt to detect and preserve mail headers in the input. Be careful when combining this flag with -p."),
getopts::optflag("s", "split-only", "Split lines only, do not reflow."),
getopts::optflag("u", "uniform-spacing", "Insert exactly one space between words, and two between sentences. Sentence breaks in the input are detected as [?!.] followed by two spaces or a newline; other punctuation is not interpreted as a sentence break."),
getopts::optopt("p", "prefix", "Reformat only lines beginning with PREFIX, reattaching PREFIX to reformatted lines. Unless -x is specified, leading whitespace will be ignored when matching PREFIX.", "PREFIX"),
getopts::optopt("P", "skip-prefix", "Do not reformat lines beginning with PSKIP. Unless -X is specified, leading whitespace will be ignored when matching PSKIP", "PSKIP"),
getopts::optflag("x", "exact-prefix", "PREFIX must match at the beginning of the line with no preceding whitespace."),
getopts::optflag("X", "exact-skip-prefix", "PSKIP must match at the beginning of the line with no preceding whitespace."),
getopts::optopt("w", "width", "Fill output lines up to a maximum of WIDTH columns, default 79.", "WIDTH"),
getopts::optopt("g", "goal", "Goal width, default ~0.94*WIDTH. Must be less than WIDTH.", "GOAL"),
getopts::optflag("q", "quick", "Break lines more quickly at the expense of a potentially more ragged appearance."),
initial release of working fmt Note: for now, this version does not use Knuth-Plass, but everything else is in place with "greedy" breaking. All options (should) work, and performance is nearly on par with GNU fmt. Squashed commit of the following local commits: commit ebc12f5e7d19d351ada9273ec0c42d66d3730431 commit 125fdabcb2a32de161c7a8b76c3e766a40ff9f76 commit dadd62acc093b5bd4bc94ad4f8a499d2663a7097 commit e436fdaade3876e92020c61a736eba54eb5ca0cf commit bbc4f4f6ad749753efe9b2df871ddb257f33de4b commit 12bc4ecb0c56c0d43515a111e9129a4bfaf36531 commit 2e693553ed9af59c53ee13026d19c9f82f2973fc commit 9b15a130148d62dd6a1d2765848ddc4daf30c649 commit ea335eb2869afcc94709345118fab3fb2e612954 Merge: ee92573 23cc41d commit 23cc41d188cb3134c04872fd77acb331d86a64ea commit 2fa7c48133001d86da39feda04d870ff67e88400 commit eb71558ee46654b568adf167f194cb854bbf7056 commit c8baabc0b86d831b5741fa496c312134db652c55 commit ee4fab44b216c1d9c7dcdcdc29ca587c76284834 commit c5444416a531ae1341dddbfd528e4a3ee5f106bf commit e1177d47941654b8834d18599c80065943a26159 commit c7fb30e2ff32313974f99d34ba4735be064b0cc5 commit 99a9406bc6fff33fc64c190356e48f443312a6c4 commit 3d244d62c9b60b579f2e5b723da6389a5dbc8805 commit 2d4f09cb2ff83664730edba209ec129abdcf1403 commit 947c32b72bff8d50e362555ec21a6b848d5fec9f commit 8556d2a3467651ee7833ad800876af35a7dd5db7 commit a2e4bc3dc45e5f39b402e6fdd3e19edcea6d3c34 Merge: 0308884 439e65d commit 03088844f1fd2faca6c3471230730136dd140f35 commit ac80d888649dd1311fdaa68400ea45d52b2e23ab commit c1d6b36acb7038e14d5b3e1fb6a44614a3351f96 commit 6539b102593aa9d9570df8be99ca1a1bf01ea1f4 commit 439e65d3331936e00fa89a4b2f88c343b9e28c5b commit fac27de7c4918bc5cf1a1ac1a43550236ba8af4d commit 365989c5bbe5c2289648f6efbc3c9388388e30a0 commit 3dd71364cce9aaaa773fc88eb206aba31aa61390
2014-06-19 00:43:26 +00:00
getopts::optopt("T", "tab-width", "Treat tabs as TABWIDTH spaces for determining line length, default 8. Note that this is used only for calculating line lengths; tabs are preserved in the output.", "TABWIDTH"),
getopts::optflag("V", "version", "Output version information and exit."),
getopts::optflag("h", "help", "Display this help message and exit.")
];
let matches = match getopts::getopts(args.tail(), opts.as_slice()) {
Ok(m) => m,
Err(f) => crash!(1, "{}\nTry `{} --help' for more information.", f, args.get(0))
};
if matches.opt_present("h") {
print_usage(args.get(0).as_slice(), opts.as_slice(), "");
}
if matches.opt_present("V") || matches.opt_present("h") {
println!("uutils {} v{}", NAME, VERSION);
return 0
}
let mut fmt_opts = FmtOptions {
crown : false,
tagged : false,
mail : false,
uniform : false,
quick : false,
split_only : false,
use_prefix : false,
prefix : String::new(),
xprefix : false,
use_anti_prefix : false,
anti_prefix : String::new(),
xanti_prefix : false,
width : 79,
goal : 74,
tabwidth : 8,
};
initial release of working fmt Note: for now, this version does not use Knuth-Plass, but everything else is in place with "greedy" breaking. All options (should) work, and performance is nearly on par with GNU fmt. Squashed commit of the following local commits: commit ebc12f5e7d19d351ada9273ec0c42d66d3730431 commit 125fdabcb2a32de161c7a8b76c3e766a40ff9f76 commit dadd62acc093b5bd4bc94ad4f8a499d2663a7097 commit e436fdaade3876e92020c61a736eba54eb5ca0cf commit bbc4f4f6ad749753efe9b2df871ddb257f33de4b commit 12bc4ecb0c56c0d43515a111e9129a4bfaf36531 commit 2e693553ed9af59c53ee13026d19c9f82f2973fc commit 9b15a130148d62dd6a1d2765848ddc4daf30c649 commit ea335eb2869afcc94709345118fab3fb2e612954 Merge: ee92573 23cc41d commit 23cc41d188cb3134c04872fd77acb331d86a64ea commit 2fa7c48133001d86da39feda04d870ff67e88400 commit eb71558ee46654b568adf167f194cb854bbf7056 commit c8baabc0b86d831b5741fa496c312134db652c55 commit ee4fab44b216c1d9c7dcdcdc29ca587c76284834 commit c5444416a531ae1341dddbfd528e4a3ee5f106bf commit e1177d47941654b8834d18599c80065943a26159 commit c7fb30e2ff32313974f99d34ba4735be064b0cc5 commit 99a9406bc6fff33fc64c190356e48f443312a6c4 commit 3d244d62c9b60b579f2e5b723da6389a5dbc8805 commit 2d4f09cb2ff83664730edba209ec129abdcf1403 commit 947c32b72bff8d50e362555ec21a6b848d5fec9f commit 8556d2a3467651ee7833ad800876af35a7dd5db7 commit a2e4bc3dc45e5f39b402e6fdd3e19edcea6d3c34 Merge: 0308884 439e65d commit 03088844f1fd2faca6c3471230730136dd140f35 commit ac80d888649dd1311fdaa68400ea45d52b2e23ab commit c1d6b36acb7038e14d5b3e1fb6a44614a3351f96 commit 6539b102593aa9d9570df8be99ca1a1bf01ea1f4 commit 439e65d3331936e00fa89a4b2f88c343b9e28c5b commit fac27de7c4918bc5cf1a1ac1a43550236ba8af4d commit 365989c5bbe5c2289648f6efbc3c9388388e30a0 commit 3dd71364cce9aaaa773fc88eb206aba31aa61390
2014-06-19 00:43:26 +00:00
if matches.opt_present("t") { fmt_opts.tagged = true; }
if matches.opt_present("c") { fmt_opts.crown = true; fmt_opts.tagged = false; }
if matches.opt_present("m") { fmt_opts.mail = true; }
if matches.opt_present("u") { fmt_opts.uniform = true; }
if matches.opt_present("q") { fmt_opts.quick = true; }
if matches.opt_present("s") { fmt_opts.split_only = true; fmt_opts.crown = false; fmt_opts.tagged = false; }
initial release of working fmt Note: for now, this version does not use Knuth-Plass, but everything else is in place with "greedy" breaking. All options (should) work, and performance is nearly on par with GNU fmt. Squashed commit of the following local commits: commit ebc12f5e7d19d351ada9273ec0c42d66d3730431 commit 125fdabcb2a32de161c7a8b76c3e766a40ff9f76 commit dadd62acc093b5bd4bc94ad4f8a499d2663a7097 commit e436fdaade3876e92020c61a736eba54eb5ca0cf commit bbc4f4f6ad749753efe9b2df871ddb257f33de4b commit 12bc4ecb0c56c0d43515a111e9129a4bfaf36531 commit 2e693553ed9af59c53ee13026d19c9f82f2973fc commit 9b15a130148d62dd6a1d2765848ddc4daf30c649 commit ea335eb2869afcc94709345118fab3fb2e612954 Merge: ee92573 23cc41d commit 23cc41d188cb3134c04872fd77acb331d86a64ea commit 2fa7c48133001d86da39feda04d870ff67e88400 commit eb71558ee46654b568adf167f194cb854bbf7056 commit c8baabc0b86d831b5741fa496c312134db652c55 commit ee4fab44b216c1d9c7dcdcdc29ca587c76284834 commit c5444416a531ae1341dddbfd528e4a3ee5f106bf commit e1177d47941654b8834d18599c80065943a26159 commit c7fb30e2ff32313974f99d34ba4735be064b0cc5 commit 99a9406bc6fff33fc64c190356e48f443312a6c4 commit 3d244d62c9b60b579f2e5b723da6389a5dbc8805 commit 2d4f09cb2ff83664730edba209ec129abdcf1403 commit 947c32b72bff8d50e362555ec21a6b848d5fec9f commit 8556d2a3467651ee7833ad800876af35a7dd5db7 commit a2e4bc3dc45e5f39b402e6fdd3e19edcea6d3c34 Merge: 0308884 439e65d commit 03088844f1fd2faca6c3471230730136dd140f35 commit ac80d888649dd1311fdaa68400ea45d52b2e23ab commit c1d6b36acb7038e14d5b3e1fb6a44614a3351f96 commit 6539b102593aa9d9570df8be99ca1a1bf01ea1f4 commit 439e65d3331936e00fa89a4b2f88c343b9e28c5b commit fac27de7c4918bc5cf1a1ac1a43550236ba8af4d commit 365989c5bbe5c2289648f6efbc3c9388388e30a0 commit 3dd71364cce9aaaa773fc88eb206aba31aa61390
2014-06-19 00:43:26 +00:00
if matches.opt_present("x") { fmt_opts.xprefix = true; }
if matches.opt_present("X") { fmt_opts.xanti_prefix = true; }
match matches.opt_str("p") {
Some(s) => {
fmt_opts.prefix = s;
fmt_opts.use_prefix = true;
}
None => ()
initial release of working fmt Note: for now, this version does not use Knuth-Plass, but everything else is in place with "greedy" breaking. All options (should) work, and performance is nearly on par with GNU fmt. Squashed commit of the following local commits: commit ebc12f5e7d19d351ada9273ec0c42d66d3730431 commit 125fdabcb2a32de161c7a8b76c3e766a40ff9f76 commit dadd62acc093b5bd4bc94ad4f8a499d2663a7097 commit e436fdaade3876e92020c61a736eba54eb5ca0cf commit bbc4f4f6ad749753efe9b2df871ddb257f33de4b commit 12bc4ecb0c56c0d43515a111e9129a4bfaf36531 commit 2e693553ed9af59c53ee13026d19c9f82f2973fc commit 9b15a130148d62dd6a1d2765848ddc4daf30c649 commit ea335eb2869afcc94709345118fab3fb2e612954 Merge: ee92573 23cc41d commit 23cc41d188cb3134c04872fd77acb331d86a64ea commit 2fa7c48133001d86da39feda04d870ff67e88400 commit eb71558ee46654b568adf167f194cb854bbf7056 commit c8baabc0b86d831b5741fa496c312134db652c55 commit ee4fab44b216c1d9c7dcdcdc29ca587c76284834 commit c5444416a531ae1341dddbfd528e4a3ee5f106bf commit e1177d47941654b8834d18599c80065943a26159 commit c7fb30e2ff32313974f99d34ba4735be064b0cc5 commit 99a9406bc6fff33fc64c190356e48f443312a6c4 commit 3d244d62c9b60b579f2e5b723da6389a5dbc8805 commit 2d4f09cb2ff83664730edba209ec129abdcf1403 commit 947c32b72bff8d50e362555ec21a6b848d5fec9f commit 8556d2a3467651ee7833ad800876af35a7dd5db7 commit a2e4bc3dc45e5f39b402e6fdd3e19edcea6d3c34 Merge: 0308884 439e65d commit 03088844f1fd2faca6c3471230730136dd140f35 commit ac80d888649dd1311fdaa68400ea45d52b2e23ab commit c1d6b36acb7038e14d5b3e1fb6a44614a3351f96 commit 6539b102593aa9d9570df8be99ca1a1bf01ea1f4 commit 439e65d3331936e00fa89a4b2f88c343b9e28c5b commit fac27de7c4918bc5cf1a1ac1a43550236ba8af4d commit 365989c5bbe5c2289648f6efbc3c9388388e30a0 commit 3dd71364cce9aaaa773fc88eb206aba31aa61390
2014-06-19 00:43:26 +00:00
};
match matches.opt_str("P") {
Some(s) => {
fmt_opts.anti_prefix = s;
fmt_opts.use_anti_prefix = true;
}
None => ()
initial release of working fmt Note: for now, this version does not use Knuth-Plass, but everything else is in place with "greedy" breaking. All options (should) work, and performance is nearly on par with GNU fmt. Squashed commit of the following local commits: commit ebc12f5e7d19d351ada9273ec0c42d66d3730431 commit 125fdabcb2a32de161c7a8b76c3e766a40ff9f76 commit dadd62acc093b5bd4bc94ad4f8a499d2663a7097 commit e436fdaade3876e92020c61a736eba54eb5ca0cf commit bbc4f4f6ad749753efe9b2df871ddb257f33de4b commit 12bc4ecb0c56c0d43515a111e9129a4bfaf36531 commit 2e693553ed9af59c53ee13026d19c9f82f2973fc commit 9b15a130148d62dd6a1d2765848ddc4daf30c649 commit ea335eb2869afcc94709345118fab3fb2e612954 Merge: ee92573 23cc41d commit 23cc41d188cb3134c04872fd77acb331d86a64ea commit 2fa7c48133001d86da39feda04d870ff67e88400 commit eb71558ee46654b568adf167f194cb854bbf7056 commit c8baabc0b86d831b5741fa496c312134db652c55 commit ee4fab44b216c1d9c7dcdcdc29ca587c76284834 commit c5444416a531ae1341dddbfd528e4a3ee5f106bf commit e1177d47941654b8834d18599c80065943a26159 commit c7fb30e2ff32313974f99d34ba4735be064b0cc5 commit 99a9406bc6fff33fc64c190356e48f443312a6c4 commit 3d244d62c9b60b579f2e5b723da6389a5dbc8805 commit 2d4f09cb2ff83664730edba209ec129abdcf1403 commit 947c32b72bff8d50e362555ec21a6b848d5fec9f commit 8556d2a3467651ee7833ad800876af35a7dd5db7 commit a2e4bc3dc45e5f39b402e6fdd3e19edcea6d3c34 Merge: 0308884 439e65d commit 03088844f1fd2faca6c3471230730136dd140f35 commit ac80d888649dd1311fdaa68400ea45d52b2e23ab commit c1d6b36acb7038e14d5b3e1fb6a44614a3351f96 commit 6539b102593aa9d9570df8be99ca1a1bf01ea1f4 commit 439e65d3331936e00fa89a4b2f88c343b9e28c5b commit fac27de7c4918bc5cf1a1ac1a43550236ba8af4d commit 365989c5bbe5c2289648f6efbc3c9388388e30a0 commit 3dd71364cce9aaaa773fc88eb206aba31aa61390
2014-06-19 00:43:26 +00:00
};
match matches.opt_str("w") {
Some(s) => {
fmt_opts.width =
match from_str(s.as_slice()) {
Some(t) => t,
None => { crash!(1, "Invalid WIDTH specification: `{}'", s); }
};
fmt_opts.goal = cmp::min(fmt_opts.width * 94 / 100, fmt_opts.width - 3);
}
None => ()
initial release of working fmt Note: for now, this version does not use Knuth-Plass, but everything else is in place with "greedy" breaking. All options (should) work, and performance is nearly on par with GNU fmt. Squashed commit of the following local commits: commit ebc12f5e7d19d351ada9273ec0c42d66d3730431 commit 125fdabcb2a32de161c7a8b76c3e766a40ff9f76 commit dadd62acc093b5bd4bc94ad4f8a499d2663a7097 commit e436fdaade3876e92020c61a736eba54eb5ca0cf commit bbc4f4f6ad749753efe9b2df871ddb257f33de4b commit 12bc4ecb0c56c0d43515a111e9129a4bfaf36531 commit 2e693553ed9af59c53ee13026d19c9f82f2973fc commit 9b15a130148d62dd6a1d2765848ddc4daf30c649 commit ea335eb2869afcc94709345118fab3fb2e612954 Merge: ee92573 23cc41d commit 23cc41d188cb3134c04872fd77acb331d86a64ea commit 2fa7c48133001d86da39feda04d870ff67e88400 commit eb71558ee46654b568adf167f194cb854bbf7056 commit c8baabc0b86d831b5741fa496c312134db652c55 commit ee4fab44b216c1d9c7dcdcdc29ca587c76284834 commit c5444416a531ae1341dddbfd528e4a3ee5f106bf commit e1177d47941654b8834d18599c80065943a26159 commit c7fb30e2ff32313974f99d34ba4735be064b0cc5 commit 99a9406bc6fff33fc64c190356e48f443312a6c4 commit 3d244d62c9b60b579f2e5b723da6389a5dbc8805 commit 2d4f09cb2ff83664730edba209ec129abdcf1403 commit 947c32b72bff8d50e362555ec21a6b848d5fec9f commit 8556d2a3467651ee7833ad800876af35a7dd5db7 commit a2e4bc3dc45e5f39b402e6fdd3e19edcea6d3c34 Merge: 0308884 439e65d commit 03088844f1fd2faca6c3471230730136dd140f35 commit ac80d888649dd1311fdaa68400ea45d52b2e23ab commit c1d6b36acb7038e14d5b3e1fb6a44614a3351f96 commit 6539b102593aa9d9570df8be99ca1a1bf01ea1f4 commit 439e65d3331936e00fa89a4b2f88c343b9e28c5b commit fac27de7c4918bc5cf1a1ac1a43550236ba8af4d commit 365989c5bbe5c2289648f6efbc3c9388388e30a0 commit 3dd71364cce9aaaa773fc88eb206aba31aa61390
2014-06-19 00:43:26 +00:00
};
match matches.opt_str("g") {
Some(s) => {
fmt_opts.goal =
match from_str(s.as_slice()) {
Some(t) => t,
None => { crash!(1, "Invalid GOAL specification: `{}'", s); }
};
if !matches.opt_present("w") {
fmt_opts.width = cmp::max(fmt_opts.goal * 100 / 94, fmt_opts.goal + 3);
} else if fmt_opts.goal > fmt_opts.width {
crash!(1, "GOAL cannot be greater than WIDTH.");
}
}
None => ()
initial release of working fmt Note: for now, this version does not use Knuth-Plass, but everything else is in place with "greedy" breaking. All options (should) work, and performance is nearly on par with GNU fmt. Squashed commit of the following local commits: commit ebc12f5e7d19d351ada9273ec0c42d66d3730431 commit 125fdabcb2a32de161c7a8b76c3e766a40ff9f76 commit dadd62acc093b5bd4bc94ad4f8a499d2663a7097 commit e436fdaade3876e92020c61a736eba54eb5ca0cf commit bbc4f4f6ad749753efe9b2df871ddb257f33de4b commit 12bc4ecb0c56c0d43515a111e9129a4bfaf36531 commit 2e693553ed9af59c53ee13026d19c9f82f2973fc commit 9b15a130148d62dd6a1d2765848ddc4daf30c649 commit ea335eb2869afcc94709345118fab3fb2e612954 Merge: ee92573 23cc41d commit 23cc41d188cb3134c04872fd77acb331d86a64ea commit 2fa7c48133001d86da39feda04d870ff67e88400 commit eb71558ee46654b568adf167f194cb854bbf7056 commit c8baabc0b86d831b5741fa496c312134db652c55 commit ee4fab44b216c1d9c7dcdcdc29ca587c76284834 commit c5444416a531ae1341dddbfd528e4a3ee5f106bf commit e1177d47941654b8834d18599c80065943a26159 commit c7fb30e2ff32313974f99d34ba4735be064b0cc5 commit 99a9406bc6fff33fc64c190356e48f443312a6c4 commit 3d244d62c9b60b579f2e5b723da6389a5dbc8805 commit 2d4f09cb2ff83664730edba209ec129abdcf1403 commit 947c32b72bff8d50e362555ec21a6b848d5fec9f commit 8556d2a3467651ee7833ad800876af35a7dd5db7 commit a2e4bc3dc45e5f39b402e6fdd3e19edcea6d3c34 Merge: 0308884 439e65d commit 03088844f1fd2faca6c3471230730136dd140f35 commit ac80d888649dd1311fdaa68400ea45d52b2e23ab commit c1d6b36acb7038e14d5b3e1fb6a44614a3351f96 commit 6539b102593aa9d9570df8be99ca1a1bf01ea1f4 commit 439e65d3331936e00fa89a4b2f88c343b9e28c5b commit fac27de7c4918bc5cf1a1ac1a43550236ba8af4d commit 365989c5bbe5c2289648f6efbc3c9388388e30a0 commit 3dd71364cce9aaaa773fc88eb206aba31aa61390
2014-06-19 00:43:26 +00:00
};
match matches.opt_str("T") {
Some(s) => {
fmt_opts.tabwidth =
match from_str(s.as_slice()) {
Some(t) => t,
None => { crash!(1, "Invalid TABWIDTH specification: `{}'", s); }
};
}
None => ()
initial release of working fmt Note: for now, this version does not use Knuth-Plass, but everything else is in place with "greedy" breaking. All options (should) work, and performance is nearly on par with GNU fmt. Squashed commit of the following local commits: commit ebc12f5e7d19d351ada9273ec0c42d66d3730431 commit 125fdabcb2a32de161c7a8b76c3e766a40ff9f76 commit dadd62acc093b5bd4bc94ad4f8a499d2663a7097 commit e436fdaade3876e92020c61a736eba54eb5ca0cf commit bbc4f4f6ad749753efe9b2df871ddb257f33de4b commit 12bc4ecb0c56c0d43515a111e9129a4bfaf36531 commit 2e693553ed9af59c53ee13026d19c9f82f2973fc commit 9b15a130148d62dd6a1d2765848ddc4daf30c649 commit ea335eb2869afcc94709345118fab3fb2e612954 Merge: ee92573 23cc41d commit 23cc41d188cb3134c04872fd77acb331d86a64ea commit 2fa7c48133001d86da39feda04d870ff67e88400 commit eb71558ee46654b568adf167f194cb854bbf7056 commit c8baabc0b86d831b5741fa496c312134db652c55 commit ee4fab44b216c1d9c7dcdcdc29ca587c76284834 commit c5444416a531ae1341dddbfd528e4a3ee5f106bf commit e1177d47941654b8834d18599c80065943a26159 commit c7fb30e2ff32313974f99d34ba4735be064b0cc5 commit 99a9406bc6fff33fc64c190356e48f443312a6c4 commit 3d244d62c9b60b579f2e5b723da6389a5dbc8805 commit 2d4f09cb2ff83664730edba209ec129abdcf1403 commit 947c32b72bff8d50e362555ec21a6b848d5fec9f commit 8556d2a3467651ee7833ad800876af35a7dd5db7 commit a2e4bc3dc45e5f39b402e6fdd3e19edcea6d3c34 Merge: 0308884 439e65d commit 03088844f1fd2faca6c3471230730136dd140f35 commit ac80d888649dd1311fdaa68400ea45d52b2e23ab commit c1d6b36acb7038e14d5b3e1fb6a44614a3351f96 commit 6539b102593aa9d9570df8be99ca1a1bf01ea1f4 commit 439e65d3331936e00fa89a4b2f88c343b9e28c5b commit fac27de7c4918bc5cf1a1ac1a43550236ba8af4d commit 365989c5bbe5c2289648f6efbc3c9388388e30a0 commit 3dd71364cce9aaaa773fc88eb206aba31aa61390
2014-06-19 00:43:26 +00:00
};
if fmt_opts.tabwidth < 1 {
fmt_opts.tabwidth = 1;
}
// immutable now
let fmt_opts = fmt_opts;
let mut files = matches.free;
if files.is_empty() {
files.push("-".to_string());
}
let mut ostream = box BufferedWriter::new(stdout_raw()) as Box<Writer>;
for i in files.iter().map(|x| x.as_slice()) {
let mut fp =
match open_file(i) {
Err(e) => {
show_warning!("{}: {}", i, e);
continue;
}
Ok(f) => f
};
initial release of working fmt Note: for now, this version does not use Knuth-Plass, but everything else is in place with "greedy" breaking. All options (should) work, and performance is nearly on par with GNU fmt. Squashed commit of the following local commits: commit ebc12f5e7d19d351ada9273ec0c42d66d3730431 commit 125fdabcb2a32de161c7a8b76c3e766a40ff9f76 commit dadd62acc093b5bd4bc94ad4f8a499d2663a7097 commit e436fdaade3876e92020c61a736eba54eb5ca0cf commit bbc4f4f6ad749753efe9b2df871ddb257f33de4b commit 12bc4ecb0c56c0d43515a111e9129a4bfaf36531 commit 2e693553ed9af59c53ee13026d19c9f82f2973fc commit 9b15a130148d62dd6a1d2765848ddc4daf30c649 commit ea335eb2869afcc94709345118fab3fb2e612954 Merge: ee92573 23cc41d commit 23cc41d188cb3134c04872fd77acb331d86a64ea commit 2fa7c48133001d86da39feda04d870ff67e88400 commit eb71558ee46654b568adf167f194cb854bbf7056 commit c8baabc0b86d831b5741fa496c312134db652c55 commit ee4fab44b216c1d9c7dcdcdc29ca587c76284834 commit c5444416a531ae1341dddbfd528e4a3ee5f106bf commit e1177d47941654b8834d18599c80065943a26159 commit c7fb30e2ff32313974f99d34ba4735be064b0cc5 commit 99a9406bc6fff33fc64c190356e48f443312a6c4 commit 3d244d62c9b60b579f2e5b723da6389a5dbc8805 commit 2d4f09cb2ff83664730edba209ec129abdcf1403 commit 947c32b72bff8d50e362555ec21a6b848d5fec9f commit 8556d2a3467651ee7833ad800876af35a7dd5db7 commit a2e4bc3dc45e5f39b402e6fdd3e19edcea6d3c34 Merge: 0308884 439e65d commit 03088844f1fd2faca6c3471230730136dd140f35 commit ac80d888649dd1311fdaa68400ea45d52b2e23ab commit c1d6b36acb7038e14d5b3e1fb6a44614a3351f96 commit 6539b102593aa9d9570df8be99ca1a1bf01ea1f4 commit 439e65d3331936e00fa89a4b2f88c343b9e28c5b commit fac27de7c4918bc5cf1a1ac1a43550236ba8af4d commit 365989c5bbe5c2289648f6efbc3c9388388e30a0 commit 3dd71364cce9aaaa773fc88eb206aba31aa61390
2014-06-19 00:43:26 +00:00
let mut pStream = ParagraphStream::new(&fmt_opts, &mut fp);
for paraResult in pStream {
match paraResult {
Err(s) => silent_unwrap!(ostream.write(s.as_bytes())),
Ok(para) => break_lines(&para, &fmt_opts, &mut ostream)
initial release of working fmt Note: for now, this version does not use Knuth-Plass, but everything else is in place with "greedy" breaking. All options (should) work, and performance is nearly on par with GNU fmt. Squashed commit of the following local commits: commit ebc12f5e7d19d351ada9273ec0c42d66d3730431 commit 125fdabcb2a32de161c7a8b76c3e766a40ff9f76 commit dadd62acc093b5bd4bc94ad4f8a499d2663a7097 commit e436fdaade3876e92020c61a736eba54eb5ca0cf commit bbc4f4f6ad749753efe9b2df871ddb257f33de4b commit 12bc4ecb0c56c0d43515a111e9129a4bfaf36531 commit 2e693553ed9af59c53ee13026d19c9f82f2973fc commit 9b15a130148d62dd6a1d2765848ddc4daf30c649 commit ea335eb2869afcc94709345118fab3fb2e612954 Merge: ee92573 23cc41d commit 23cc41d188cb3134c04872fd77acb331d86a64ea commit 2fa7c48133001d86da39feda04d870ff67e88400 commit eb71558ee46654b568adf167f194cb854bbf7056 commit c8baabc0b86d831b5741fa496c312134db652c55 commit ee4fab44b216c1d9c7dcdcdc29ca587c76284834 commit c5444416a531ae1341dddbfd528e4a3ee5f106bf commit e1177d47941654b8834d18599c80065943a26159 commit c7fb30e2ff32313974f99d34ba4735be064b0cc5 commit 99a9406bc6fff33fc64c190356e48f443312a6c4 commit 3d244d62c9b60b579f2e5b723da6389a5dbc8805 commit 2d4f09cb2ff83664730edba209ec129abdcf1403 commit 947c32b72bff8d50e362555ec21a6b848d5fec9f commit 8556d2a3467651ee7833ad800876af35a7dd5db7 commit a2e4bc3dc45e5f39b402e6fdd3e19edcea6d3c34 Merge: 0308884 439e65d commit 03088844f1fd2faca6c3471230730136dd140f35 commit ac80d888649dd1311fdaa68400ea45d52b2e23ab commit c1d6b36acb7038e14d5b3e1fb6a44614a3351f96 commit 6539b102593aa9d9570df8be99ca1a1bf01ea1f4 commit 439e65d3331936e00fa89a4b2f88c343b9e28c5b commit fac27de7c4918bc5cf1a1ac1a43550236ba8af4d commit 365989c5bbe5c2289648f6efbc3c9388388e30a0 commit 3dd71364cce9aaaa773fc88eb206aba31aa61390
2014-06-19 00:43:26 +00:00
}
}
// flush the output after each file
silent_unwrap!(ostream.flush());
}
0
}
fn print_usage(arg0: &str, opts: &[getopts::OptGroup], errmsg: &str) {
2014-07-03 00:43:48 +00:00
println!("Usage: {} [OPTION]... [FILE]...\n\n{}{}", arg0, getopts::usage("Reformat paragraphs from input files (or stdin) to stdout.", opts), errmsg);
initial release of working fmt Note: for now, this version does not use Knuth-Plass, but everything else is in place with "greedy" breaking. All options (should) work, and performance is nearly on par with GNU fmt. Squashed commit of the following local commits: commit ebc12f5e7d19d351ada9273ec0c42d66d3730431 commit 125fdabcb2a32de161c7a8b76c3e766a40ff9f76 commit dadd62acc093b5bd4bc94ad4f8a499d2663a7097 commit e436fdaade3876e92020c61a736eba54eb5ca0cf commit bbc4f4f6ad749753efe9b2df871ddb257f33de4b commit 12bc4ecb0c56c0d43515a111e9129a4bfaf36531 commit 2e693553ed9af59c53ee13026d19c9f82f2973fc commit 9b15a130148d62dd6a1d2765848ddc4daf30c649 commit ea335eb2869afcc94709345118fab3fb2e612954 Merge: ee92573 23cc41d commit 23cc41d188cb3134c04872fd77acb331d86a64ea commit 2fa7c48133001d86da39feda04d870ff67e88400 commit eb71558ee46654b568adf167f194cb854bbf7056 commit c8baabc0b86d831b5741fa496c312134db652c55 commit ee4fab44b216c1d9c7dcdcdc29ca587c76284834 commit c5444416a531ae1341dddbfd528e4a3ee5f106bf commit e1177d47941654b8834d18599c80065943a26159 commit c7fb30e2ff32313974f99d34ba4735be064b0cc5 commit 99a9406bc6fff33fc64c190356e48f443312a6c4 commit 3d244d62c9b60b579f2e5b723da6389a5dbc8805 commit 2d4f09cb2ff83664730edba209ec129abdcf1403 commit 947c32b72bff8d50e362555ec21a6b848d5fec9f commit 8556d2a3467651ee7833ad800876af35a7dd5db7 commit a2e4bc3dc45e5f39b402e6fdd3e19edcea6d3c34 Merge: 0308884 439e65d commit 03088844f1fd2faca6c3471230730136dd140f35 commit ac80d888649dd1311fdaa68400ea45d52b2e23ab commit c1d6b36acb7038e14d5b3e1fb6a44614a3351f96 commit 6539b102593aa9d9570df8be99ca1a1bf01ea1f4 commit 439e65d3331936e00fa89a4b2f88c343b9e28c5b commit fac27de7c4918bc5cf1a1ac1a43550236ba8af4d commit 365989c5bbe5c2289648f6efbc3c9388388e30a0 commit 3dd71364cce9aaaa773fc88eb206aba31aa61390
2014-06-19 00:43:26 +00:00
}
// uniform interface for opening files
// since we don't need seeking
type FileOrStdReader = BufferedReader<Box<Reader>>;
fn open_file(filename: &str) -> IoResult<FileOrStdReader> {
if filename == "-" {
Ok(BufferedReader::new(box stdin_raw() as Box<Reader>))
} else {
match File::open(&Path::new(filename)) {
Ok(f) => Ok(BufferedReader::new(box f as Box<Reader>)),
Err(e) => return Err(e)
initial release of working fmt Note: for now, this version does not use Knuth-Plass, but everything else is in place with "greedy" breaking. All options (should) work, and performance is nearly on par with GNU fmt. Squashed commit of the following local commits: commit ebc12f5e7d19d351ada9273ec0c42d66d3730431 commit 125fdabcb2a32de161c7a8b76c3e766a40ff9f76 commit dadd62acc093b5bd4bc94ad4f8a499d2663a7097 commit e436fdaade3876e92020c61a736eba54eb5ca0cf commit bbc4f4f6ad749753efe9b2df871ddb257f33de4b commit 12bc4ecb0c56c0d43515a111e9129a4bfaf36531 commit 2e693553ed9af59c53ee13026d19c9f82f2973fc commit 9b15a130148d62dd6a1d2765848ddc4daf30c649 commit ea335eb2869afcc94709345118fab3fb2e612954 Merge: ee92573 23cc41d commit 23cc41d188cb3134c04872fd77acb331d86a64ea commit 2fa7c48133001d86da39feda04d870ff67e88400 commit eb71558ee46654b568adf167f194cb854bbf7056 commit c8baabc0b86d831b5741fa496c312134db652c55 commit ee4fab44b216c1d9c7dcdcdc29ca587c76284834 commit c5444416a531ae1341dddbfd528e4a3ee5f106bf commit e1177d47941654b8834d18599c80065943a26159 commit c7fb30e2ff32313974f99d34ba4735be064b0cc5 commit 99a9406bc6fff33fc64c190356e48f443312a6c4 commit 3d244d62c9b60b579f2e5b723da6389a5dbc8805 commit 2d4f09cb2ff83664730edba209ec129abdcf1403 commit 947c32b72bff8d50e362555ec21a6b848d5fec9f commit 8556d2a3467651ee7833ad800876af35a7dd5db7 commit a2e4bc3dc45e5f39b402e6fdd3e19edcea6d3c34 Merge: 0308884 439e65d commit 03088844f1fd2faca6c3471230730136dd140f35 commit ac80d888649dd1311fdaa68400ea45d52b2e23ab commit c1d6b36acb7038e14d5b3e1fb6a44614a3351f96 commit 6539b102593aa9d9570df8be99ca1a1bf01ea1f4 commit 439e65d3331936e00fa89a4b2f88c343b9e28c5b commit fac27de7c4918bc5cf1a1ac1a43550236ba8af4d commit 365989c5bbe5c2289648f6efbc3c9388388e30a0 commit 3dd71364cce9aaaa773fc88eb206aba31aa61390
2014-06-19 00:43:26 +00:00
}
}
}