Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
03d2f386e1 | ||
|
|
9e1e01bb62 | ||
|
|
911375627f | ||
|
|
3928766c6b | ||
|
|
ee4c9a6ea1 | ||
|
|
ca79f26d4e | ||
|
|
e3586a9e93 | ||
|
|
72891834c2 |
@ -1,6 +1,7 @@
|
|||||||
include(CMakeDependentOption)
|
|
||||||
cmake_minimum_required(VERSION 3.1)
|
|
||||||
project(roflcat)
|
project(roflcat)
|
||||||
|
cmake_minimum_required(VERSION 3.1)
|
||||||
|
include(CMakeDependentOption)
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
#c++17 without compiler extensions
|
#c++17 without compiler extensions
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
|||||||
29
README.md
29
README.md
@ -1,31 +1,42 @@
|
|||||||
# README
|
# README
|
||||||
|
|
||||||
## About
|
## About
|
||||||
roflcat is a C++ rewrite of [lolcat][1] which runs much faster and supports all the options of GNU cat. I am not going to support the animation options of lolcat (--animate, --duration, --speed) because there is no real purpose to them.
|
roflcat is a C++ rewrite of [lolcat][1] which runs much faster and supports all the options of GNU cat. I am not going to support the animation options of lolcat (--animate, --duration, --speed) because there is no real purpose to them.
|
||||||
Currently I can only confirm it runs on a linux system and I have no desire to expand to supporting anything else at this time.
|
Currently I can only confirm it runs on a linux system and I have no desire to expand to supporting anything else at this time.
|
||||||
|
|
||||||
To keep compatability with both GNU cat and lolcat, I wanted all command line options from both to either be implemented or ignored. However there are a few conflicts between the two, namely -s -t and -v. For these I will be implementing the GNU cat functionality.
|
To keep compatability with both GNU cat and lolcat, I wanted all command line options from both to either be implemented or ignored. However there are a few conflicts between the two, namely -s -t and -v. For these I will be implementing the GNU cat functionality.
|
||||||
|
|
||||||
Current version is 0.1a as of writing this, so if the version is much newer, remind me to update this readme :)
|
Current version is 1.1 as of writing this, so if the version is much newer, remind me to update this readme :)
|
||||||

|

|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
ncurses
|
||||||
|
cmake
|
||||||
|
|
||||||
## Building
|
## Building
|
||||||
There is no release right now. There is only the debug build which will produce an executable called 'tester'.
|
```
|
||||||
To build just run `make`.
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake ..
|
||||||
|
make
|
||||||
|
```
|
||||||
|
|
||||||
## Installing
|
## Installing
|
||||||
I would not recommend installing at this time. There is no install target in the makefile.
|
From within the build directory:
|
||||||
|
```
|
||||||
|
make install
|
||||||
|
```
|
||||||
|
|
||||||
## More Screenshots
|
## More Screenshots
|
||||||
Some test outputs on a file filled with laughing cat emojis
|
Some test outputs on a file filled with laughing cat emojis
|
||||||
|
|
||||||
256 color:
|
256 color:
|
||||||

|

|
||||||
|
|
||||||
Truecolor (24 bit):
|
Truecolor (24 bit):
|
||||||

|

|
||||||
|
|
||||||
16 color (type that will work in a tty):
|
16 color (type that will work in a tty):
|
||||||

|

|
||||||
|
|
||||||
[1]: https://github.com/busyloop/lolcat
|
[1]: https://github.com/busyloop/lolcat
|
||||||
|
|||||||
1
TODO
1
TODO
@ -1 +1,2 @@
|
|||||||
move GNU cat logic out of printer class to make it more modular
|
move GNU cat logic out of printer class to make it more modular
|
||||||
|
fix ^` not printing
|
||||||
|
|||||||
@ -25,7 +25,7 @@
|
|||||||
#include <cstdlib> //atol
|
#include <cstdlib> //atol
|
||||||
|
|
||||||
cmd_args::cmd_args(void)noexcept:
|
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){
|
void cmd_args::clear_gnu_options(void){
|
||||||
number = PRINT_LINE_NEVER;
|
number = PRINT_LINE_NEVER;
|
||||||
ends = squeeze = tabs = nonprinting = 0;
|
ends = squeeze = tabs = nonprinting = 0;
|
||||||
|
|||||||
@ -94,6 +94,7 @@ constexpr void print_usage(Printer&& p){
|
|||||||
p.print(L'\n');
|
p.print(L'\n');
|
||||||
}
|
}
|
||||||
p.print(L"\nroflcat Copyright (C) 2019 rexy712\n");
|
p.print(L"\nroflcat Copyright (C) 2019 rexy712\n");
|
||||||
|
p.print(L"Source code can be found at https://gitlab.com/rexy712/roflcat\n");
|
||||||
p.print(L"This program comes with ABSOLUTELY NO WARRANTY\n");
|
p.print(L"This program comes with ABSOLUTELY NO WARRANTY\n");
|
||||||
p.print(L"This is free software, and you are welcome to redistribute it\n");
|
p.print(L"This is free software, and you are welcome to redistribute it\n");
|
||||||
p.print(L"under certain conditions; see the GNU GPLv3 for details.\n");
|
p.print(L"under certain conditions; see the GNU GPLv3 for details.\n");
|
||||||
@ -140,16 +141,25 @@ void nonprinting_notation(int in, char* dest){
|
|||||||
bool is_directory(const char* file){
|
bool is_directory(const char* file){
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if(stat(file, &st) != 0){
|
if(stat(file, &st) != 0){
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
return S_ISDIR(st.st_mode);
|
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){
|
FILE* open_file(const char* file, const char* mode){
|
||||||
if(is_directory(file)){
|
if(is_directory(file)){
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
fprintf(stderr, "Unable to open file \"%s\": Is a directory \n", file);
|
fprintf(stderr, "Unable to open file \"%s\": Is a directory \n", file);
|
||||||
return nullptr;
|
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);
|
FILE* fp = fopen(file, mode);
|
||||||
if(!fp){
|
if(!fp){
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
@ -172,47 +182,52 @@ template<class Printer>
|
|||||||
int real_print_files(const cmd_args& args){
|
int real_print_files(const cmd_args& args){
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
Printer p(args);
|
Printer p(args);
|
||||||
if(args.treatbinary){ //binary files
|
for(size_t i = 0;i < args.filenames.size();++i){
|
||||||
for(size_t i = 0;i < args.filenames.size();++i){
|
if(!strcmp(args.filenames[i], "-")){ //stdin
|
||||||
if(!strcmp(args.filenames[i], "-")){ //stdin
|
|
||||||
do_stdin<char>(p, fgetc);
|
|
||||||
}else{ //everything besides stdin
|
|
||||||
FILE* fp = open_file(args.filenames[i], "rb");
|
|
||||||
if(!fp){
|
|
||||||
ret = 2;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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;){
|
||||||
|
p.print(static_cast<char>(in));
|
||||||
|
if(in == L'\n') //Only reset on newline to save print overhead
|
||||||
|
p.reset();
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
for(wint_t in;(in = fgetwc(stdin)) != WEOF;){
|
||||||
|
p.print(static_cast<wchar_t>(in));
|
||||||
|
if(in == L'\n')
|
||||||
|
p.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
clearerr(stdin);
|
||||||
|
|
||||||
|
}else{ //everything besides stdin
|
||||||
|
|
||||||
|
FILE* fp = open_file(args.filenames[i], "r");
|
||||||
|
if(!fp){
|
||||||
|
ret = 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(args.treatbinary){
|
||||||
if(args.nonprinting){
|
if(args.nonprinting){
|
||||||
for(char in;(in = fgetc(fp)) != EOF;){
|
for(int in;(in = fgetc(fp)) != EOF;){
|
||||||
char tmp[5];
|
char tmp[5];
|
||||||
nonprinting_notation(in, tmp);
|
nonprinting_notation(in, tmp);
|
||||||
p.print(tmp);
|
p.print(tmp);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
for(char in;(in = fgetc(fp)) != EOF;)
|
for(int in;(in = fgetc(fp)) != EOF;)
|
||||||
p.print(in);
|
p.print(static_cast<char>(in));
|
||||||
}
|
}
|
||||||
p.reset();
|
|
||||||
fclose(fp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}else{ //non binary files
|
|
||||||
for(size_t i = 0;i < args.filenames.size();++i){
|
|
||||||
if(!strcmp(args.filenames[i], "-")){
|
|
||||||
do_stdin<wchar_t>(p, fgetwc);
|
|
||||||
}else{
|
}else{
|
||||||
FILE* fp = open_file(args.filenames[i], "r");
|
//set to wide character mode before anything
|
||||||
if(!fp){
|
fwide(fp, 1);
|
||||||
ret = 2;
|
for(wint_t in;(in = fgetwc(fp)) != WEOF;)
|
||||||
continue;
|
p.print(static_cast<wchar_t>(in));
|
||||||
}
|
|
||||||
for(wchar_t in;(in = fgetwc(fp)) != WEOF;){
|
|
||||||
p.print(in);
|
|
||||||
}
|
|
||||||
p.reset();
|
|
||||||
fclose(fp);
|
|
||||||
}
|
}
|
||||||
|
p.reset();
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.reset();
|
p.reset();
|
||||||
@ -261,6 +276,5 @@ int main(int argc, char** argv){
|
|||||||
}else if(avail_colors == 256){
|
}else if(avail_colors == 256){
|
||||||
return print_files<basic_color_printer<256>>(args);
|
return print_files<basic_color_printer<256>>(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user