diff --git a/include/printer_base.tpp b/include/printer_base.tpp index 9a9a02b..8c5eab7 100644 --- a/include/printer_base.tpp +++ b/include/printer_base.tpp @@ -96,9 +96,7 @@ auto printer_base::print(const wchar_t* s)noexcept(noexcept(std::declva } template auto printer_base::print(char s) -> Derived&{ - wchar_t tmp; - mbstowcs(&tmp, &s, 1); - return print(tmp); + return print(static_cast(s)); } template auto printer_base::print(const char* s) -> Derived&{ diff --git a/src/roflcat.cpp b/src/roflcat.cpp index 3791cc5..6d9fc4a 100644 --- a/src/roflcat.cpp +++ b/src/roflcat.cpp @@ -135,8 +135,9 @@ void nonprinting_notation(int in, char* dest){ } //Use the given type of printer to output the contents of files and/or stdin +//treat the file as text in the current locale template -int print_normal_files(cmd_args& args){ +int print_normal_files(const cmd_args& args){ int ret = 0; Printer p(args); for(size_t i = 0;i < args.filenames.size();++i){ @@ -169,8 +170,9 @@ int print_normal_files(cmd_args& args){ return ret; } //Use the given type of printer to output the contents of files and/or stdin +//Treat the file as a binary file (ascii) template -int print_binary_files(cmd_args& args){ +int print_binary_files(const cmd_args& args){ int ret = 0; Printer p(args); for(size_t i = 0;i < args.filenames.size();++i){ @@ -191,13 +193,17 @@ int print_binary_files(cmd_args& args){ ret = 2; continue; } - for(int in;(in = fgetc(fp)) != WEOF;) - if(args.nonprinting){ + if(args.nonprinting){ + for(int in;(in = fgetc(fp)) != WEOF;){ char tmp[5]; nonprinting_notation(in, tmp); p.print(tmp); - }else + } + }else{ + for(int in;(in = fgetc(fp)) != WEOF;){ p.print(static_cast(in)); + } + } p.reset(); fclose(fp); } @@ -217,11 +223,10 @@ int print_files(cmd_args& args){ return 0; } - if(args.treatbinary){ + if(args.treatbinary) return print_binary_files(args); - }else{ + else return print_normal_files(args); - } } auto get_time(void){