Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
03d2f386e1 | ||
|
|
9e1e01bb62 | ||
|
|
911375627f | ||
|
|
3928766c6b | ||
|
|
ee4c9a6ea1 | ||
|
|
ca79f26d4e |
@ -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
1
TODO
@ -1 +1,2 @@
|
||||
move GNU cat logic out of printer class to make it more modular
|
||||
fix ^` not printing
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user