1212// - Questionable behavior: if write_all() produces Err, the program will
1313// continue to the next file, rather than stopping.
1414
15- use clap:: Parser ;
16- use gettextrs:: { bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory } ;
17- use plib:: PROJECT_NAME ;
1815use std:: io:: { self , Read , Write } ;
1916use std:: path:: PathBuf ;
2017
18+ use clap:: Parser ;
19+ use gettextrs:: { bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory } ;
20+ use plib:: io:: input_stream;
21+ use plib:: BUFSZ ;
22+
2123#[ derive( Parser ) ]
2224#[ command( version, about = gettext( "cat - concatenate and print files" ) ) ]
2325struct Args {
@@ -34,8 +36,8 @@ struct Args {
3436}
3537
3638fn cat_file ( pathname : & PathBuf ) -> io:: Result < ( ) > {
37- let mut file = plib :: io :: input_stream ( pathname, true ) ?;
38- let mut buffer = [ 0 ; plib :: BUFSZ ] ;
39+ let mut file = input_stream ( pathname, true ) ?;
40+ let mut buffer = [ 0 ; BUFSZ ] ;
3941
4042 loop {
4143 let n_read = file. read ( & mut buffer[ ..] ) ?;
@@ -50,12 +52,11 @@ fn cat_file(pathname: &PathBuf) -> io::Result<()> {
5052}
5153
5254fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
53- // parse command line arguments
54- let mut args = Args :: parse ( ) ;
55-
5655 setlocale ( LocaleCategory :: LcAll , "" ) ;
57- textdomain ( PROJECT_NAME ) ?;
58- bind_textdomain_codeset ( PROJECT_NAME , "UTF-8" ) ?;
56+ textdomain ( env ! ( "PROJECT_NAME" ) ) ?;
57+ bind_textdomain_codeset ( env ! ( "PROJECT_NAME" ) , "UTF-8" ) ?;
58+
59+ let mut args = Args :: parse ( ) ;
5960
6061 // if no file args, read from stdin
6162 if args. files . is_empty ( ) {
0 commit comments