Clean up project for sharing
This commit is contained in:
parent
cbfc61ce5f
commit
7f717d578a
|
|
@ -0,0 +1,18 @@
|
||||||
|
{
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Linux",
|
||||||
|
"includePath": [
|
||||||
|
"${workspaceFolder}/**",
|
||||||
|
"${workspaceFolder}/include"
|
||||||
|
],
|
||||||
|
"defines": [],
|
||||||
|
"compilerPath": "/bin/gcc",
|
||||||
|
"cStandard": "c17",
|
||||||
|
"cppStandard": "c++98",
|
||||||
|
"intelliSenseMode": "linux-gcc-x64",
|
||||||
|
"configurationProvider": "ms-vscode.makefile-tools"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"version": 4
|
||||||
|
}
|
||||||
|
|
@ -10,14 +10,16 @@ Requirements
|
||||||
|
|
||||||
RHEL-like:
|
RHEL-like:
|
||||||
`sudo dnf install readline-devel`
|
`sudo dnf install readline-devel`
|
||||||
|
Debian[12]: `sudo apt install libreadline-dev`
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
`make`
|
Normal Build: `make`
|
||||||
|
Debug Build: `make debug`
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
`bin/run`
|
`make test`
|
||||||
|
|
||||||
## Considerations and Caveats
|
## Considerations and Caveats
|
||||||
|
|
||||||
|
|
@ -28,7 +30,6 @@ If you need to use these kinds of applications, do not use this program to wrap
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
`bin/run`
|
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
|
#ifndef DEBUG_H
|
||||||
|
#define DEBUG_H
|
||||||
|
|
||||||
#if defined(DEBUG) && DEBUG > 0
|
#if defined(DEBUG) && DEBUG > 0
|
||||||
#define DEBUG_PRINT(fmt, ...) fprintf(stderr, "DEBUG: %s:%d:%s(): " fmt, \
|
#define DEBUG_PRINT(fmt, ...) fprintf(stderr, "DEBUG: %s:%d:%s(): " fmt, \
|
||||||
__FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
__FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||||
|
|
@ -11,51 +14,4 @@
|
||||||
#define COLORTEST()
|
#define COLORTEST()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
// You must free the result if result is non-NULL.
|
|
||||||
char *str_replace(char *orig, char *rep, char *with) {
|
|
||||||
char *result; // the return string
|
|
||||||
char *ins; // the next insert point
|
|
||||||
char *tmp; // varies
|
|
||||||
int len_rep; // length of rep (the string to remove)
|
|
||||||
int len_with; // length of with (the string to replace rep with)
|
|
||||||
int len_front; // distance between rep and end of last rep
|
|
||||||
int count; // number of replacements
|
|
||||||
|
|
||||||
// sanity checks and initialization
|
|
||||||
if (!orig || !rep)
|
|
||||||
return NULL;
|
|
||||||
len_rep = strlen(rep);
|
|
||||||
if (len_rep == 0)
|
|
||||||
return NULL; // empty rep causes infinite loop during count
|
|
||||||
if (!with)
|
|
||||||
with = "";
|
|
||||||
len_with = strlen(with);
|
|
||||||
|
|
||||||
// count the number of replacements needed
|
|
||||||
ins = orig;
|
|
||||||
for (count = 0; tmp = strstr(ins, rep); ++count) {
|
|
||||||
ins = tmp + len_rep;
|
|
||||||
}
|
|
||||||
|
|
||||||
tmp = result = malloc(strlen(orig) + (len_with - len_rep) * count + 1);
|
|
||||||
|
|
||||||
if (!result)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
// first time through the loop, all the variable are set correctly
|
|
||||||
// from here on,
|
|
||||||
// tmp points to the end of the result string
|
|
||||||
// ins points to the next occurrence of rep in orig
|
|
||||||
// orig points to the remainder of orig after "end of rep"
|
|
||||||
while (count--) {
|
|
||||||
ins = strstr(orig, rep);
|
|
||||||
len_front = ins - orig;
|
|
||||||
tmp = strncpy(tmp, orig, len_front) + len_front;
|
|
||||||
tmp = strcpy(tmp, with) + len_with;
|
|
||||||
orig += len_front + len_rep; // move to next "end of rep"
|
|
||||||
}
|
|
||||||
strcpy(tmp, orig);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
#ifndef NOTMINE_H
|
||||||
|
#define NOTMINE_H
|
||||||
|
|
||||||
|
// You must free the result if result is non-NULL.
|
||||||
|
char *str_replace(char *orig, char *rep, char *with);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
// Custom debug include for some debug macros and functions
|
// Custom debug include for some debug macros and functions
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
#include <notmine.h>
|
||||||
|
|
||||||
#define BUFCHUNKSIZE 4096
|
#define BUFCHUNKSIZE 4096
|
||||||
#define BUFSAFEPAD 8
|
#define BUFSAFEPAD 8
|
||||||
|
|
@ -38,7 +39,7 @@ void child_process(char *argv[]){
|
||||||
}
|
}
|
||||||
|
|
||||||
void processline(char *line){
|
void processline(char *line){
|
||||||
char debugstring[] = "HEHE:"KRED;
|
//char debugstring[] = "HEHE:"KRED;
|
||||||
char endstring[] = KNRM"\n";
|
char endstring[] = KNRM"\n";
|
||||||
char *newline;
|
char *newline;
|
||||||
newline = str_replace(line, "rw-", KRED"rw-"KNRM);
|
newline = str_replace(line, "rw-", KRED"rw-"KNRM);
|
||||||
|
|
@ -59,7 +60,7 @@ void processline(char *line){
|
||||||
|
|
||||||
void processbuffer(char *roll_buffer, size_t read_length) {
|
void processbuffer(char *roll_buffer, size_t read_length) {
|
||||||
//this is where some optimization could come in with using malloc and then freeing subset of memory; dog garn dynamic memory allocation
|
//this is where some optimization could come in with using malloc and then freeing subset of memory; dog garn dynamic memory allocation
|
||||||
int found_index;
|
//int found_index;
|
||||||
char *found_char = strtok(roll_buffer, "\r\n");
|
char *found_char = strtok(roll_buffer, "\r\n");
|
||||||
while(found_char != NULL){
|
while(found_char != NULL){
|
||||||
processline(found_char);
|
processline(found_char);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
#include <notmine.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
//https://stackoverflow.com/a/779960/8229149
|
||||||
|
char *str_replace(char *orig, char *rep, char *with) {
|
||||||
|
char *result; // the return string
|
||||||
|
char *ins; // the next insert point
|
||||||
|
char *tmp; // varies
|
||||||
|
int len_rep; // length of rep (the string to remove)
|
||||||
|
int len_with; // length of with (the string to replace rep with)
|
||||||
|
int len_front; // distance between rep and end of last rep
|
||||||
|
int count; // number of replacements
|
||||||
|
|
||||||
|
// sanity checks and initialization
|
||||||
|
if (!orig || !rep)
|
||||||
|
return NULL;
|
||||||
|
len_rep = strlen(rep);
|
||||||
|
if (len_rep == 0)
|
||||||
|
return NULL; // empty rep causes infinite loop during count
|
||||||
|
if (!with)
|
||||||
|
with = "";
|
||||||
|
len_with = strlen(with);
|
||||||
|
|
||||||
|
// count the number of replacements needed
|
||||||
|
ins = orig;
|
||||||
|
for (count = 0; tmp = strstr(ins, rep); ++count) {
|
||||||
|
ins = tmp + len_rep;
|
||||||
|
}
|
||||||
|
|
||||||
|
tmp = result = malloc(strlen(orig) + (len_with - len_rep) * count + 1);
|
||||||
|
|
||||||
|
if (!result)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
// first time through the loop, all the variable are set correctly
|
||||||
|
// from here on,
|
||||||
|
// tmp points to the end of the result string
|
||||||
|
// ins points to the next occurrence of rep in orig
|
||||||
|
// orig points to the remainder of orig after "end of rep"
|
||||||
|
while (count--) {
|
||||||
|
ins = strstr(orig, rep);
|
||||||
|
len_front = ins - orig;
|
||||||
|
tmp = strncpy(tmp, orig, len_front) + len_front;
|
||||||
|
tmp = strcpy(tmp, with) + len_with;
|
||||||
|
orig += len_front + len_rep; // move to next "end of rep"
|
||||||
|
}
|
||||||
|
strcpy(tmp, orig);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue