diff --git a/Makefile b/Makefile index 3800835..4eb9e68 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ OBJd := obj INCd := inc CC = gcc LDFLAGS = -CFLAGS = -Iinclude -Iinc -Wall -O2 -g +CFLAGS = -Iinc -Wall -O2 -g SRC = $(wildcard $(SRCd)/*.c) OBJ = $(SRC:$(SRCd)/%.c=$(OBJd)/%.o) @@ -13,7 +13,7 @@ TARGETS = $(SRC:$(SRCd)/%.c=$(BINd)/%) main: $(OBJ) $(OBJd)/nprint.o # The option of a single program instead of a suite. WARN: Requires modification of source to remove multiple main() $(CC) $(LDFLAGS) -o $(BINd)/fex $^ -multi: $(TARGETS) +multi: $(TARGETS) # Makes a single executable per object instead of congealing them into a single "fex" $(BINd)/%: $(OBJd)/%.o $(OBJd)/nprint.o $(CC) $(LDFLAGS) -o $@ $^ @@ -28,4 +28,4 @@ $(OBJd)/nprint.o: $(INCd)/nprint.c $(INCd)/nprint.h clean: rm -f $(OBJd)/*.o $(BINd)/* -.PHONY: all clean \ No newline at end of file +.PHONY: main clean \ No newline at end of file diff --git a/bin/fex b/bin/fex index 8f1149c..aebf62d 100755 Binary files a/bin/fex and b/bin/fex differ diff --git a/inc/config.h b/inc/config.h new file mode 100644 index 0000000..d010035 --- /dev/null +++ b/inc/config.h @@ -0,0 +1,10 @@ +// +// Created by auric on 2/22/24. +// + +#ifndef CONFIG_H +#define CONFIG_H + +#define debugEnabled + +#endif //CONFIG_H diff --git a/inc/debug.h b/inc/debug.h new file mode 100644 index 0000000..92c125c --- /dev/null +++ b/inc/debug.h @@ -0,0 +1,16 @@ +// +// Created by auric on 2/22/24. +// + +#ifndef DEBUG_H +#define DEBUG_H + +#include "nprint.h" + +#ifdef debugEnabled + #define DEBUG_PRINT(fmt, ...) nprint("D", fmt, ##__VA_ARGS__) +#else + #define DEBUG_PRINT(fmg, ...) void(0) +#endif + +#endif //DEBUG_H diff --git a/inc/sanity.h b/inc/sanity.h index c41bc2b..d2c92ef 100644 --- a/inc/sanity.h +++ b/inc/sanity.h @@ -5,8 +5,19 @@ #ifndef SANITY_H #define SANITY_H -# include +#include -int sanity_check(); +#define SANITY_SUCCESS 0 // 0000 - All checks passed +#define SANITY_CON_FAIL 1 // 0001 - /con check failed +#define SANITY_EXE_FAIL 2 // 0010 - /exe check failed +#define SANITY_UTI_FAIL 4 // 0100 - /uti check failed + +/*typedef struct { + bool conEx; + bool exeEx; + bool utiEx; +} SanityCheckResult;*/ + +const int isSysSane(); #endif //SANITY_H diff --git a/obj/fex.o b/obj/fex.o index b255e9a..0f9225c 100644 Binary files a/obj/fex.o and b/obj/fex.o differ diff --git a/obj/sanity.o b/obj/sanity.o index cbc6b22..9797db5 100644 Binary files a/obj/sanity.o and b/obj/sanity.o differ diff --git a/src/fex.c b/src/fex.c index 00fe3b4..af07eb3 100644 --- a/src/fex.c +++ b/src/fex.c @@ -6,31 +6,79 @@ #include #include #include +#include +#include +#include + + -char* opt = NULL; void help() { nprint("E", "Usage: fex (OPT) (PACKAGES)"); } + int main(int argc, char** argv) { + int fIns = 0, fUpd = 0, fSrc = 0, fUin = 0, fLis = 0, fSer = 0, fVer = 0, fFrc = 0, fUpg = 0; + char* packages[argc - 1]; + int pkgCount = 0; if (argc < 2) { help(); return 1; } - if (argv[1][0] == '-' || argv[1][0] == '+' ) { - opt = argv[1]; - } else { - nprint("E", "First argument must be OPT"); - return 1; + const char* flagNames[] = {"Install", "Update", "Source", "Remove", "List", "Search","Verbose", "Force", "Upgrade"}; + int* flagValues[] = {&fIns, &fUpd, &fSrc, &fUin, &fLis, &fSer, &fVer, &fFrc, &fUpg}; + int flagCount = sizeof(flagNames) / sizeof(flagNames[0]); // This should match the number of flags + + for(int i = 1; i < argc; i++) { + if(argv[i][0] == '-') { + for(int j = 1; argv[i][j] != '\0'; j++) { + switch(argv[i][j]) { + case 'i': // install + fIns = 1; + break; + case 'u': // update + fUpd = 1; + break; + case 'S': // source + fSrc = 1; + break; + case 'r': // remove + fUin = 1; + break; + case 'l': // list + fLis = 1; + break; + case 's': // search + fSer = 1; + break; + case 'v': // verbose + fVer = 1; + break; + case 'f': // force + fFrc = 1; + break; + case 'c': // upgrade; don't ask why I'm using 'c' + fUpg = 1; + break; + default: + nprint("E", "Flag '%c' is unknown.", argv[i][j]); + return 1; + } + } + } else { + packages[pkgCount++] = argv[i]; + } } - if (opt[0] == '+' && opt[1] != '\0') { - nprint("D", "Placeholder"); - } + const int sysSanity = isSysSane(); - if (argc < 3) { - nprint("E", "No packages specified"); - return 1; - } + #ifdef debugEnabled + for(int i = 0; i < flagCount; i++) { + nprint("D", "Flag %s: %d", flagNames[i], *flagValues[i]); + } + for(int i = 0; i < pkgCount; i++) { + nprint("D", "Package %d: %s", i, packages[i]); + } + #endif return 0; } \ No newline at end of file diff --git a/src/sanity.c b/src/sanity.c index 5292b3c..26ce81a 100644 --- a/src/sanity.c +++ b/src/sanity.c @@ -1,28 +1,47 @@ -// -// Created by auric on 2/22/24. -// +#include +#include +#include +#include /* - * 0: Success - * 1: Failure - * 2: Root check failure - * 3: /con check failure - * 4: /exe check filuse - * 5: /con and /exe check failure + * 0: success + * 1: con failure + * 2: exe failure + * 3: con and exe failure + * 4: uti failure + * 5: uti and con failure + * 6: uti and exe failure + * 7: total failure */ -#include -#include +/*SanityCheckResult isSane() { + struct stat conStat, exeStat, utiStat; + SanityCheckResult result = {true, true, true}; // Default to true, assume checks will pass*/ +struct stat conStat; +struct stat exeStat; +struct stat utiStat; +int result; -bool isSane = true; -bool isRoot = false; - -int sanity_check() { - if (getuid() == 0) { - isRoot = true; +const int isSysSane() { + if (stat("/con", &conStat) != 0 || !(conStat.st_mode & S_IWUSR)) { + //result.conEx = false; + result |= SANITY_CON_FAIL; } + if (stat("/exe", &exeStat) != 0 || !(exeStat.st_mode & S_IWUSR)) { + //result.exeEx = false; + result |= SANITY_EXE_FAIL; + } + if (stat("/uti", &utiStat) != 0 || !(utiStat.st_mode & S_IWUSR)) { + //result.utiEx = false; + result |= SANITY_UTI_FAIL; + } + + /*nprint("D", "con: %d", result.conEx); + nprint("D", "exe: %d", result.exeEx); + nprint("D", "uti: %d", result.utiEx);*/ + //nprint("D", "Result: %d", sumResult); + return result; +} - return 0; -} \ No newline at end of file