Added Rule Help
Cleaned up some other stuff Sane Defaults aswell
This commit is contained in:
parent
b764750bdd
commit
3a56e56820
10
README.md
10
README.md
|
|
@ -39,14 +39,14 @@ make run
|
|||
```sh
|
||||
make run
|
||||
|
||||
# or
|
||||
|
||||
make traces
|
||||
# or (for strace)
|
||||
make trace
|
||||
```
|
||||
|
||||
As of right now there are only 7 hardcoded replacements (for color) in the src/main.c file.
|
||||
These are actually regex patterns.
|
||||
```c
|
||||
// all are temporary
|
||||
// OUT OF DATE. IM LAZY AND DIDNT UPDATE THEM YET
|
||||
"^d" //-> Magenta
|
||||
"r--" //-> Green
|
||||
"rw-" //-> Red
|
||||
|
|
@ -68,7 +68,7 @@ If you need to use these kinds of applications, do not use this program to wrap
|
|||
|
||||
|
||||
|
||||
## Installation
|
||||
## "Installation"
|
||||
|
||||
Normal build: `make`
|
||||
|
||||
|
|
|
|||
|
|
@ -6,12 +6,12 @@
|
|||
#define VERSION_MAJOR 0
|
||||
#define VERSION_MINOR 2
|
||||
#define VERSION_HOTFIX 0
|
||||
#define VERSION_BUILD 354
|
||||
#define VERSION_BUILD 368
|
||||
|
||||
//#define DEFAULT_CMD "/bin/sh"
|
||||
#define CONF_DO_CMD_ACK 1
|
||||
|
||||
#define DEBG_DO_EOL_MARK 1
|
||||
#define DEBG_DO_EOL_MARK 0
|
||||
//EOLMARK defined in parsebuffer()
|
||||
|
||||
|
||||
|
|
@ -35,6 +35,6 @@
|
|||
//child stdout read buffer size
|
||||
#define BUFCHUNKSIZE 4096
|
||||
#define BUFSAFEPAD 8 //shut it, ik its useless
|
||||
|
||||
#define REG_NOFLAG 0
|
||||
|
||||
#endif
|
||||
68
src/main.c
68
src/main.c
|
|
@ -9,12 +9,11 @@
|
|||
#include <sysexits.h>
|
||||
#include <fcntl.h>
|
||||
#include <readline/readline.h>
|
||||
//#include <readline/history.h>
|
||||
//regex branch init
|
||||
//#include <readline/history.h> /* who needs history anyway */
|
||||
#include <regex.h>
|
||||
|
||||
|
||||
// Custom debug include for some debug macros and functions
|
||||
// custom headers
|
||||
#include <config.h>
|
||||
#include <debug.h>
|
||||
#include <structdef.h>
|
||||
|
|
@ -22,44 +21,67 @@
|
|||
#include <linework.h>
|
||||
#include <notmine.h>
|
||||
|
||||
//temporary
|
||||
//NOTE: temporarly in here for config, but probably will create a seperate file that loads the rules down the line
|
||||
|
||||
/*
|
||||
Rule Writiting Help:
|
||||
Available Color Codes: KRED KGRN KYEL KBLU KMAG KCYN KWHT
|
||||
KNRM to reset to default
|
||||
If you want a smattering of the colors, `make debug` and `make run`
|
||||
|
||||
Available Regex Flags: REG_NOFLAG REG_EXTENDED, REG_ICASE
|
||||
REPLACE_GROUP selects the submatch of the regex to replace;
|
||||
if your regex looks like this: /(matchme)otherstuff$/ ,you probably want to change it from 0
|
||||
|
||||
For now, there is no implementation for non static regex replacing. ex: x2tx ~ /x([02])tx/1/--$1-/ => x--2-tx
|
||||
there is the function for it (line_regex_wrap_match), its just not used. its coming later
|
||||
|
||||
Gotta be careful right now because earlier replaces also effect later ones (see processline());
|
||||
also these rules get applied to EVERY line
|
||||
*/
|
||||
|
||||
|
||||
/*== USER CHANGE CONFIG ==*/
|
||||
ct_match replace_rules[]= {
|
||||
//gotta be careful right now because earlier replaces also effect later ones
|
||||
{ "alpine", 0, 0, KMAG"alpine"KNRM },
|
||||
{ "r--", 0, 0, KGRN"r--"KNRM },
|
||||
{ "rw-", 0, 0, KRED"rw-"KNRM },
|
||||
{ " \\.\\.$", 0, 0, KBLU" .."KNRM },
|
||||
{ " \\.$", 0, 0, KBLU" ."KNRM },
|
||||
{ "^d", 0, 0, KMAG"d"KNRM },
|
||||
{ "z9Da0Da1", 0, 0, KRED"z9Da0Da1"KNRM },
|
||||
/* {REGEX_PATTERN, REG_FLAGS, REPLACE_GROUP, REPLACE_WITH} */
|
||||
{ "(alpine)[[:blank:]01]", REG_EXTENDED, 1, KMAG"alpine"KNRM }, /* matches alpine alpine0 alpine1 and only colorizes "alpine" */
|
||||
{ "r--", REG_NOFLAG, 0, KGRN"r--"KNRM },
|
||||
{ "rw-", REG_NOFLAG, 0, KRED"rw-"KNRM },
|
||||
{ "^d[r\\-].* (\\.\\.)$", REG_EXTENDED, 1, KGRN".."KNRM },
|
||||
{ "^d[r\\-].* (\\.)$", REG_EXTENDED, 1, KGRN"."KNRM },
|
||||
{ "^d[r\\-].* ().*?$", REG_EXTENDED, 1, KBLU }, /* color directories blue; this one is such a hack omg just implement the function you keep talking about */
|
||||
{ "z9Da0Da1", REG_NOFLAG, 0, KRED"(SUS STRING)z9Da0Da1"KNRM }, /* NOTE: this string is in the testing/long file btw. */
|
||||
};
|
||||
char ps1[] = KGRN"~>"KNRM;
|
||||
char ps1_ack[] = KBLU"1~"KNRM;
|
||||
//CONF_DO_CMD_ACK defined in include/config.h to disable the ack above
|
||||
//DBUG_DO_EOL_MARK defined in include/config.h if you want & at the end of lines
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*== REST IS CODE ==*/
|
||||
/* pls dont break it */
|
||||
|
||||
ct_line processline(ct_line current_line){
|
||||
|
||||
int rules_length = (sizeof(replace_rules)/sizeof(replace_rules[0]));
|
||||
|
||||
//TODO: implement line_regex_wrap_match as well for easier rule writing
|
||||
for (int i=0; i<rules_length; i++) {
|
||||
regex_t comp_regex;
|
||||
int match1_comp_result = regcomp(&comp_regex, replace_rules[i].match_regex, replace_rules[i].match_cflags); //unused but needed
|
||||
int regex_result = line_regex_replace(¤t_line, &comp_regex, replace_rules[i].replace_group, replace_rules[i].replace_with, 255);
|
||||
int match1_comp_result = regcomp(&comp_regex, replace_rules[i].match_regex, replace_rules[i].match_cflags); //unused but needed; also slowwwwwwwww
|
||||
int regex_result = line_regex_replace(¤t_line, &comp_regex, replace_rules[i].replace_group, replace_rules[i].replace_with, 4096); //4096 jank rn
|
||||
regfree(&comp_regex);
|
||||
}
|
||||
|
||||
|
||||
return current_line;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void parsebuffer(char *roll_buffer, size_t read_length, int buffer_read_count) {
|
||||
#if !DEBG_DO_EOL_MARK
|
||||
char endstring[] = KNRM"\n";
|
||||
|
|
@ -71,7 +93,7 @@ void parsebuffer(char *roll_buffer, size_t read_length, int buffer_read_count) {
|
|||
int line_number = 0; //true
|
||||
if (buffer_read_count != 0) line_number=1;
|
||||
|
||||
char *found_char = strtok(roll_buffer, "\r\n"); //basically replace "\r\n" with NULL
|
||||
char *found_char = strtok(roll_buffer, "\r\n"); //basically replace next "\r\n" with NULL
|
||||
while(found_char != NULL){
|
||||
ct_line current_line = {found_char, 0};
|
||||
ct_line post_processed_line = processline(current_line);
|
||||
|
|
@ -83,7 +105,7 @@ void parsebuffer(char *roll_buffer, size_t read_length, int buffer_read_count) {
|
|||
if (post_processed_line.need_free == 1) free(post_processed_line.line_str);
|
||||
|
||||
line_number++;
|
||||
found_char = strtok(NULL, "\r\n"); // I really do not like this repetition
|
||||
found_char = strtok(NULL, "\r\n"); //NOTE: I really do not like this repetition
|
||||
}
|
||||
//no more lines in buffer
|
||||
}
|
||||
|
|
@ -101,9 +123,9 @@ void supervise(int master_fd, int child_pid){
|
|||
//read child stdout to child_out_roll_buffer
|
||||
//send to processing & output
|
||||
int read_loop_no = 0;
|
||||
while(1){ //continuely read until none left
|
||||
while(1){ // continuely read until none left
|
||||
memset(child_out_roll_buffer, 0, BUFCHUNKSIZE+BUFSAFEPAD);
|
||||
errno = 0; //force reset errno
|
||||
errno = 0; //force reset errno
|
||||
ssize_t read_size = read(master_fd, &child_out_roll_buffer[0], BUFCHUNKSIZE - 0);
|
||||
if (read_size > 0) {
|
||||
parsebuffer(child_out_roll_buffer, read_size, read_loop_no);
|
||||
|
|
@ -123,9 +145,8 @@ void supervise(int master_fd, int child_pid){
|
|||
write(master_fd, parent_in_buffer, strlen(parent_in_buffer));
|
||||
write(master_fd, "\n", 1);
|
||||
|
||||
usleep(100*1000);
|
||||
usleep(200*1000); //dirty hack because *some* commands are slow
|
||||
}
|
||||
|
||||
free(child_out_roll_buffer);
|
||||
free(parent_in_buffer);
|
||||
}
|
||||
|
|
@ -149,7 +170,6 @@ int main(int argc, char *argv[]) {
|
|||
exit(EX_USAGE);
|
||||
}
|
||||
|
||||
|
||||
int master_fd;
|
||||
pid_t child_pid;
|
||||
//if the pty window size is to be assigned. shoudnt be a concern since only used by tui programs
|
||||
|
|
|
|||
Loading…
Reference in New Issue