initial commit - Here Be Dragons

This commit is contained in:
2024-06-20 22:31:25 +02:00
commit ab55355e6f
16 changed files with 264 additions and 0 deletions

84
Makefile Normal file
View File

@@ -0,0 +1,84 @@
PROJECT_NAME = ttyfilter
BUILD_DIR = build
CC = gcc
CFLAGS = -std=c99
LDFLAGS =
LIBS =
LDLIBS = $(shell if [ -v "$(LIBS)" ]; then pkg-config -libs $(LIBS); fi)
INCLUDES = $(shell if [ -v "$(LIBS)" ]; then pkg-config -cflags $(LIBS); fi) -Isrc/includes
SRC = $(shell find src/ -type f -name '*.c') main.c
NOM = $(basename $(notdir $(SRC)))
OBJ = $(addprefix $(BUILD_DIR)/,$(addsuffix .o, $(NOM)))
#------------------------------------------------------------------------------
# MAIN BUILD RULES
#------------------------------------------------------------------------------
# Build all the .o files in src dir
$(BUILD_DIR)/%.o: src/%.c
$(CC) $(CFLAGS) -c $< $(INCLUDES) -o $(BUILD_DIR)/$(notdir $@)
# Build all the .o files in base dir
$(BUILD_DIR)/%.o: %.c
$(CC) $(CFLAGS) -c $< $(INCLUDES) -o $(BUILD_DIR)/$(notdir $@)
# Main program
$(PROJECT_NAME): $(OBJ)
$(CC) -o $@ $(LDFLAGS) $^
# Simple local echo tester
localecho: $(BUILD_DIR)/localecho.o
$(CC) -o $@ $(LDFLAGS) $^
#------------------------------------------------------------------------------
# SILLY RULES
#------------------------------------------------------------------------------
always: SUSSYBAKA
@echo "Aloha :3"
SUSSYBAKA:
#------------------------------------------------------------------------------
# UTILITIES
#------------------------------------------------------------------------------
all: init build
build: $(PROJECT_NAME) localecho
rebuild: clean build
dev: build run
init: $(BUILD_DIR) clear
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
test:
@echo CC: $(CC)
@echo CFLAGS: $(CFLAGS)
@echo LDFLAGS: $(LDFLAGS)
@echo LDLIBS: $(LDLIBS)
@echo OBJ: $(OBJ)
@echo SRC: $(SRC)
@echo INCLUDES: $(INCLUDES)
run: $(PROJECT_NAME)
./$(PROJECT_NAME)
clean:
@rm -rif *.o *.gch
clear: clean
@rm $(PROJECT_NAME)
.PHONY: always init SUSSYBAKA test clear clean

BIN
build/filter.o Normal file

Binary file not shown.

BIN
build/main.o Normal file

Binary file not shown.

BIN
build/test.o Normal file

Binary file not shown.

BIN
localecho Executable file

Binary file not shown.

73
localecho.c Normal file
View File

@@ -0,0 +1,73 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <termio.h>
#include <string.h>
/*
*------------------------------------------------------------------------------
* Definitions
*------------------------------------------------------------------------------
*/
#define TERMINATOR '\e'
void terminit( struct termios* ptopt );
void termrst( struct termios* ptopt );
/*
*------------------------------------------------------------------------------
* MAIN - localecho - trivial raw echo stdin to stdout
*------------------------------------------------------------------------------
*/
int main( int argc, char* argv[] ) {
unsigned char bHex = 0;
struct termios sTermOpt;
char c;
/* use --hex to return hex codes instead of character */
bHex = ( argc > 1 ) && ( strcmp(argv[1], "--hex") == 0 );
terminit( &sTermOpt );
while ( c != TERMINATOR ) {
c = getchar();
if ( bHex ) printf("%02X ", c);
else putc( c, stdout );
}
putc( '\n', stdout );
termrst( &sTermOpt );
return 0;
}
/*
*------------------------------------------------------------------------------
* Local Functions
*------------------------------------------------------------------------------
*/
/* Init platform terminal options to remove buffering and local echo -- make it raw! */
void terminit( struct termios* ptopt ) {
static struct termios newt;
tcgetattr( STDIN_FILENO, ptopt);
newt = *ptopt;
/* clear ICANON (buffering) and ECHO */
newt.c_lflag &= ~(ICANON | ECHO);
tcsetattr( STDIN_FILENO, TCSANOW, &newt);
}
/* Reset terminal as it was before invocating this tool */
void termrst( struct termios* ptopt ) {
tcsetattr( STDIN_FILENO, TCSANOW, ptopt);
}

11
main.c Normal file
View File

@@ -0,0 +1,11 @@
#include <stdio.h>
#include "test.h"
int main( int argc, char* argv[] ) {
printf("Test string: %s\n", sTestString);
return 0;
}

0
src/filter.c Normal file
View File

22
src/includes/errors.h Normal file
View File

@@ -0,0 +1,22 @@
#ifndef __LTF_ERRORS_H__
#define __LTF_ERRORS_H__
/*
-------------------------------------------------------------------------------
Common Errors
-------------------------------------------------------------------------------
*/
typedef enum {
NO_ERR = 0x0000, /* No Errors */
ERR_UNKNOWN = 0xFFFF, /* Unknown error */
ERR_NOT_IMPLEMENTED = 0xFF01, /* Not implemented */
ERR_BAD_PARAMS = 0xFF02, /* Bad param (value) */
ERR_USAGE = 0xFF03, /* Incorrect usage */
ERR_SKILL_ISSUE = 0xDEAD, /* Unspecified internal error */
} e_ret;
#endif /* __LTF_ERRORS_H__ */

0
src/includes/filter.h Normal file
View File

4
src/includes/iopipe.h Normal file
View File

@@ -0,0 +1,4 @@

3
src/includes/test.h Normal file
View File

@@ -0,0 +1,3 @@
extern char* sTestString;

32
src/includes/types.h Normal file
View File

@@ -0,0 +1,32 @@
#ifndef __LTF_TYPES_H__
#define __LTF_TYPES_H__
#include <stdint.h>
#include "errors.h"
#define __FUCK_OFF(def) #def
#define _TOSTRING(def) __FUCK_OFF(def)
/*
-------------------------------------------------------------------------------
Common Types
-------------------------------------------------------------------------------
*/
typedef int8_t int8;
typedef uint8_t uint8;
typedef int16_t int16;
typedef uint16_t uint16;
typedef int32_t int32;
typedef uint32_t uint32;
typedef int64_t int64;
typedef uint64_t uint64;
typedef enum e_bool {
FALSE = 0,
TRUE = 1
} boolean;
#endif /* __LTF_TYPES_H__ */

15
src/includes/version.h Normal file
View File

@@ -0,0 +1,15 @@
#ifndef __LTF_VERSION__
#define __LTF_VERSION__
#include "types.h"
#define LTF_VERSION_MAJOR 1
#define LTF_VERSION_MINOR 0
#define LTF_VERSION _TOSTRING(LTF_VERSION_MAJOR)"."_TOSTRING(LTF_VERSION_MINOR)
#define LTF_NAME "TraceFilter"
#endif /* __LTF_VERSION__ */

16
src/iopipe.c Normal file
View File

@@ -0,0 +1,16 @@
#include <sys/types.h>
/*
*------------------------------------------------------------------------------
* Definitions
*------------------------------------------------------------------------------
*/
typedef struct iopipe {
int stdin;
int stdout;
int stderr;
pid_t pid;
} t_iopipe;

4
src/test.c Normal file
View File

@@ -0,0 +1,4 @@
char* sTestString = "Aloha 2";