Compare commits

..

No commits in common. "master" and "v1.1.1" have entirely different histories.

4 changed files with 8 additions and 18 deletions

View File

@ -1,7 +1,6 @@
project(roflcat)
cmake_minimum_required(VERSION 3.1)
include(CMakeDependentOption)
include(GNUInstallDirs)
cmake_minimum_required(VERSION 3.1)
project(roflcat)
#c++17 without compiler extensions
set(CMAKE_CXX_STANDARD 17)

1
TODO
View File

@ -1,2 +1 @@
move GNU cat logic out of printer class to make it more modular
fix ^` not printing

View File

@ -25,7 +25,7 @@
#include <cstdlib> //atol
cmd_args::cmd_args(void)noexcept:
truecol(0), color(0), invert(0), number(0), ends(0), squeeze(0), tabs(0), nonprinting(0), treatbinary(0), error(0), usage(0), version(0){}
truecol(0), color(0), number(0), ends(0), squeeze(0), tabs(0), nonprinting(0), error(0), usage(0), version(0){}
void cmd_args::clear_gnu_options(void){
number = PRINT_LINE_NEVER;
ends = squeeze = tabs = nonprinting = 0;

View File

@ -141,25 +141,16 @@ void nonprinting_notation(int in, char* dest){
bool is_directory(const char* file){
struct stat st;
if(stat(file, &st) != 0){
return false;
return true;
}
return S_ISDIR(st.st_mode);
}
bool file_exists(const char* file){
struct stat st;
return stat(file, &st) == 0;
}
FILE* open_file(const char* file, const char* mode){
if(is_directory(file)){
fflush(stdout);
fprintf(stderr, "Unable to open file \"%s\": Is a directory \n", file);
return nullptr;
}
if(!file_exists(file)){
fflush(stdout);
fprintf(stderr, "Unable to open file \"%s\": No such file\n", file);
return nullptr;
}
FILE* fp = fopen(file, mode);
if(!fp){
fflush(stdout);
@ -187,7 +178,7 @@ int real_print_files(const cmd_args& args){
if(args.treatbinary){
//Don't check if buf is empty because that's not how GNU cat handles Ctrl+D in middle of line
for(int in;(in = fgetc(stdin)) != EOF;){
for(int in;(in = fgetc(stdin)) != WEOF;){
p.print(static_cast<char>(in));
if(in == L'\n') //Only reset on newline to save print overhead
p.reset();
@ -210,13 +201,13 @@ int real_print_files(const cmd_args& args){
}
if(args.treatbinary){
if(args.nonprinting){
for(int in;(in = fgetc(fp)) != EOF;){
for(int in;(in = fgetc(fp)) != WEOF;){
char tmp[5];
nonprinting_notation(in, tmp);
p.print(tmp);
}
}else{
for(int in;(in = fgetc(fp)) != EOF;)
for(int in;(in = fgetc(fp)) != WEOF;)
p.print(static_cast<char>(in));
}
}else{
@ -276,5 +267,6 @@ int main(int argc, char** argv){
}else if(avail_colors == 256){
return print_files<basic_color_printer<256>>(args);
}
return 0;
}