Compare commits

...

6 Commits

Author SHA1 Message Date
rexy712
03d2f386e1 Fix invert flag not being zero initialized 2020-08-05 13:36:36 -07:00
rexy712
9e1e01bb62 Merge branch 'master' of ssh://rexy712.chickenkiller.com:1995/var/git/repos/rexy712/roflcat 2020-04-09 15:20:44 -07:00
rexy712
911375627f Fix CMakeLists.txt 2020-04-09 15:20:39 -07:00
rexy712
3928766c6b Fix uninitialized variable in cmdargs and incorrect WEOF usage 2019-12-27 10:21:59 -08:00
rexy712
ee4c9a6ea1 add to todo 2019-10-24 12:19:42 -07:00
rexy712
ca79f26d4e Fixed error output on nonexistent file 2019-09-16 16:16:14 -07:00
4 changed files with 18 additions and 8 deletions

View File

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

1
TODO
View File

@ -1 +1,2 @@
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), number(0), ends(0), squeeze(0), tabs(0), nonprinting(0), error(0), usage(0), version(0){}
truecol(0), color(0), invert(0), number(0), ends(0), squeeze(0), tabs(0), nonprinting(0), treatbinary(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,16 +141,25 @@ void nonprinting_notation(int in, char* dest){
bool is_directory(const char* file){
struct stat st;
if(stat(file, &st) != 0){
return true;
return false;
}
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);
@ -178,7 +187,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)) != WEOF;){
for(int in;(in = fgetc(stdin)) != EOF;){
p.print(static_cast<char>(in));
if(in == L'\n') //Only reset on newline to save print overhead
p.reset();
@ -201,13 +210,13 @@ int real_print_files(const cmd_args& args){
}
if(args.treatbinary){
if(args.nonprinting){
for(int in;(in = fgetc(fp)) != WEOF;){
for(int in;(in = fgetc(fp)) != EOF;){
char tmp[5];
nonprinting_notation(in, tmp);
p.print(tmp);
}
}else{
for(int in;(in = fgetc(fp)) != WEOF;)
for(int in;(in = fgetc(fp)) != EOF;)
p.print(static_cast<char>(in));
}
}else{
@ -267,6 +276,5 @@ int main(int argc, char** argv){
}else if(avail_colors == 256){
return print_files<basic_color_printer<256>>(args);
}
return 0;
}