From 3627b76951077797308d9775f90f4cebab63de58 Mon Sep 17 00:00:00 2001 From: bigsketti Date: Sun, 9 Feb 2025 18:01:47 -0500 Subject: [PATCH] cleaned up folder and added pure clam gen --- cshell | Bin 16920 -> 17168 bytes handleJSON.c => eventually/handleJSON.c | 5 +- main.c => src/cShell.c | 211 +++++++++++------------- src/cShell.h | 23 +++ src/history.c | 3 + src/history.h | 11 ++ src/main.c | 29 ++++ 7 files changed, 164 insertions(+), 118 deletions(-) rename handleJSON.c => eventually/handleJSON.c (92%) rename main.c => src/cShell.c (87%) create mode 100644 src/cShell.h create mode 100644 src/history.c create mode 100644 src/history.h create mode 100644 src/main.c diff --git a/cshell b/cshell index 9f7eeb1a0c82b651d0ae3ce840f7a1dab7b5c017..b261d70f9f7c4194eb4689f227b9fc96d4f22aad 100755 GIT binary patch delta 3671 zcmaJ^3s98T6~6y2uSIZqExXI2vl0y(H4uzdAU>A3#GeE+Itd*om_fv?U=WchEYby2=uTx~ zR^Um2M%p$3lQw^^&ZwmA{pi@m_Nr4cx9QFuFK60Je|xv>6@Q=JI9>UWUQE78&zh{B z_9#Ns?&5&jO;qnEsxNwOA^`9CK*o3BaMwU{d_U6+w849X7AI+U{>y0&WD*HE0RQ4OIrPtyiW7#seSuQ3wg;u zvjzu2P`$+=wX;1$nproH4g=svKc44e8~6&WoS#ayBoy>6bqvK0w( zox?bNtl|%u?mD4+N@5$Bt{SO(Rz`2$r+F6B%EX6Shh*d)%OgVTHHpPA>`Od|M|y0N z(cMC8{N97U*2>5)Sl$tq=ZpSsn&|ZyXrn!mTFYg|{QGp&@`T64-QpnX1=#}sil;HU zG%{&iN?zlYja{P=r-{EImnG@9oP^`$iyjovY0yca6gV)yqE&v-O@FD}AedJ+mm7&iO z!dny@z>7)7jGTiFoR7U5Q+hrdDpS2*Kxwt46H%#Ey5k{U*mF|){}BEi>0TA?68W(H zAlxqL{!X}mltZdP zU)oh~J8neWiat{&XYkk1e3yQfV)J~%B|Z@s<5x__i!;^P9wg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WFZc zsxWV1l4CRSi2oIL&%uoe9{kGj3$p!%g@(K^OD@Vvd>X)mVOEUk9!%c|vlW;g!!&1- zJ&ftcn08LGUtv0h>0c+=mBOr=9OUmpeY^05P#RJ#I}J@KiN@^-NU!7os)hYuU+MZ8 zUgs_Q`zq{#hTDIWfc-ql#+Fp6mOxU8-N;tDGMT$JVV$bjlnZr;iF>SKZdGD`j$$Uh z9#yd`q52pi<#LDxxaAUPbGpggz|;i0x>}4|*hN=1OD{`z972UoB~uBy$&JK5;dg+K zjuBv-@vu!A#i}tKW8GzT$A2-ifMLunt+8=JFiZ;uGqNl&m=z1(oVdrv&Xn2JLOwbg zxev0uwm>?pBfk~GimegW#54(alC@nh^or3h#{FUpu)K1+8su}=M-;n_VxOnjPYCzW zPCZWeRrZ|8?wW?xYRFVhy9p+dj2qpG6)R2&@D|{YgIz?%C46+a;bT!8ilsr?V&f5J zt+2bA$$G&Z!=+pWobNzgmefV}V0y1$-Ymwa#Q1A5?ib^q_?Y_+VtKW*-@+N-PIl0c zriQtnX$txxuDk5`Nb_uywEDkMF$Ekq;35;JhCqlPGgqZOvkq1(R;JL(=>NRJ!j&WJ z__D;T^}pQG+1b{$QQ6kBv7^h~a?ej1o7R_=l$BJlkCr{nHdQ?~Z)@A5+uGN6bZzzY zu>Vxmu*KC?tg~7VJhA*fHSmv`Hlz9=bJdq7#k$49I_g{0)9heJ^1q%hH&oaYKsRBw^l*iL9^jj-;iP5?RR(HZDtgwpwZ#th?^E F?*L{Uj&J|~ diff --git a/handleJSON.c b/eventually/handleJSON.c similarity index 92% rename from handleJSON.c rename to eventually/handleJSON.c index c35840d..4f8c0fe 100644 --- a/handleJSON.c +++ b/eventually/handleJSON.c @@ -1,4 +1,7 @@ -// This file exists because I hate myself too much to use cJSON +// I was gonna make a json parser from scratch but ive +// had my fill of writing lexers/parsers lately, +// might finish it eventually but for now itll be +// basic config files #include #include diff --git a/main.c b/src/cShell.c similarity index 87% rename from main.c rename to src/cShell.c index 2840528..ec3aaef 100644 --- a/main.c +++ b/src/cShell.c @@ -7,100 +7,11 @@ #include #include -#define INPUT_SIZE 1024 -#define VERSION 0.1f +#include "cShell.h" // TODO: research tab completion, very big quality of life feature -char *trimCWD(char *cwd) { - char *token = strtok(cwd, "/"); - char *trimmedCWD = NULL; - - while (token != NULL) { - trimmedCWD = token; - token = strtok(NULL, "/"); - } - - return trimmedCWD; -} - -void execute(char **args) { - pid_t pid = fork(); - if (pid == 0) { - execvp(args[0], args); - perror("execvp failed"); - exit(EXIT_FAILURE); - } else if (pid > 0) { - wait(NULL); - } else { - perror("fork failed"); - } -} - -void parse_input(char *input, char **args) { - char *token = strtok(input, " "); - int i = 0; - while (token != NULL) { - args[i++] = token; - token = strtok(NULL, " "); - } - args[i] = NULL; -} - -char* getCWD() { // current working directory - char *cwd = malloc(1024); - - if (cwd == NULL) { - perror("Malloc failed"); - return NULL; - } - - if (getcwd(cwd, 1024) != NULL) { - return cwd; - } else { - perror("Could not get current working directory"); - free(cwd); - return NULL; - } -} - -void listDirectorys(const char *path) { - struct dirent *entry; - DIR *dp = opendir(path); - - if (dp == NULL) { - perror("Directory read failed"); - return; - } - - while ((entry = readdir(dp))) { - // skips hidden entries - if (entry->d_name[0] == '.') { - continue; - } - printf("%s\n", entry->d_name); - } - - closedir(dp); - } - - void printClamShell() { - printf(" ████ ██████ \n"); - printf(" ████░░░░████░░░░░░██ \n"); - printf(" ██░░░░░░░░░░░░██░░░░░░██ \n"); - printf(" ██░░░░░░▒▒▒▒░░░░░░░░░░▒▒██\n"); - printf("██░░░░░░▒▒░░░░░░░░░░░░██▒▒██\n"); - printf("██░░░░▒▒░░░░░░░░░░░░░░░░██ \n"); - printf("██░░▒▒░░░░░░░░░░░░▒▒░░░░░░██\n"); - printf("██░░▒▒░░░░░░░░░░░░▒▒░░░░░░██\n"); - printf(" ██░░░░░░░░░░░░▒▒░░░░░░▒▒██\n"); - printf(" ██░░░░░░░░░░▒▒░░░░░░░░██ \n"); - printf(" ██░░░░▒▒▒▒░░░░░░░░▒▒██ \n"); - printf(" ████░░░░░░▒▒▒▒████ \n"); - printf(" ██████████ \n"); -} - -void handle_command(char **args, char **cwd, char **trimmedCWD) { +void handleCommand(char **args, char **cwd, char **trimmedCWD) { if (args[0] == NULL) { return; } @@ -117,6 +28,7 @@ void handle_command(char **args, char **cwd, char **trimmedCWD) { "\texit\n" "\thelp\n" "\tversion\n" + "\tgenerate_clam\n" "\tcd \n" "\tmkdir \n" "\trmdir \n" @@ -213,34 +125,99 @@ void handle_command(char **args, char **cwd, char **trimmedCWD) { } } + if (strcmp("generate_clam", args[0]) == 0) { + printClamShell(); + return; + } + // execute the external command execute(args); } -int main() { - char input[INPUT_SIZE]; - char *args[100]; - char user[100] = "defaultusr"; - char *cwd = getCWD(); - char *trimmedCWD = trimCWD(cwd); - - while (1) { - if (cwd != NULL) { - printf("[cShell-%s] /%s $> ", user, trimmedCWD); - } else { - printf("[cShell-%s] $> ", user); - } - - if (!fgets(input, sizeof(input), stdin)) { - break; - } - - input[strcspn(input, "\n")] = '\0'; - - parse_input(input, args); - - handle_command(args, &cwd, &trimmedCWD); - } - free(cwd); - return 0; +void printClamShell() { + printf(" ████ ██████ \n"); + printf(" ████░░░░████░░░░░░██ \n"); + printf(" ██░░░░░░░░░░░░██░░░░░░██ \n"); + printf(" ██░░░░░░▒▒▒▒░░░░░░░░░░▒▒██\n"); + printf("██░░░░░░▒▒░░░░░░░░░░░░██▒▒██\n"); + printf("██░░░░▒▒░░░░░░░░░░░░░░░░██ \n"); + printf("██░░▒▒░░░░░░░░░░░░▒▒░░░░░░██\n"); + printf("██░░▒▒░░░░░░░░░░░░▒▒░░░░░░██\n"); + printf(" ██░░░░░░░░░░░░▒▒░░░░░░▒▒██\n"); + printf(" ██░░░░░░░░░░▒▒░░░░░░░░██ \n"); + printf(" ██░░░░▒▒▒▒░░░░░░░░▒▒██ \n"); + printf(" ████░░░░░░▒▒▒▒████ \n"); + printf(" ██████████ \n"); } + +char *trimCWD(char *cwd) { + char *token = strtok(cwd, "/"); + char *trimmedCWD = NULL; + + while (token != NULL) { + trimmedCWD = token; + token = strtok(NULL, "/"); + } + + return trimmedCWD; +} + +void execute(char **args) { + pid_t pid = fork(); + if (pid == 0) { + execvp(args[0], args); + perror("execvp failed"); + exit(EXIT_FAILURE); + } else if (pid > 0) { + wait(NULL); + } else { + perror("fork failed"); + } +} + +void parseInput(char *input, char **args) { + char *token = strtok(input, " "); + int i = 0; + while (token != NULL) { + args[i++] = token; + token = strtok(NULL, " "); + } + args[i] = NULL; +} + +char* getCWD() { // current working directory + char *cwd = (char *)malloc(INPUT_SIZE); + + if (cwd == NULL) { + perror("Malloc failed"); + return NULL; + } + + if (getcwd(cwd, 1024) != NULL) { + return cwd; + } else { + perror("Could not get current working directory"); + free(cwd); + return NULL; + } +} + +void listDirectorys(const char *path) { + struct dirent *entry; + DIR *dp = opendir(path); + + if (dp == NULL) { + perror("Directory read failed"); + return; + } + + while ((entry = readdir(dp))) { + // skips hidden entries + if (entry->d_name[0] == '.') { + continue; + } + printf("%s\n", entry->d_name); + } + + closedir(dp); + } diff --git a/src/cShell.h b/src/cShell.h new file mode 100644 index 0000000..3ff3255 --- /dev/null +++ b/src/cShell.h @@ -0,0 +1,23 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef CSHELL_H +#define CSHELL_H +#define INPUT_SIZE 1024 +#define VERSION 0.1f + +void handleCommand(char **args, char **cwd, char **trimmedCWD); +void printClamShell(void); +char *trimCWD(char *cwd); +void execute(char **args); +void parseInput(char *input, char **args); +char* getCWD(void); +void listDirectorys(const char *path); + +#endif \ No newline at end of file diff --git a/src/history.c b/src/history.c new file mode 100644 index 0000000..48429d3 --- /dev/null +++ b/src/history.c @@ -0,0 +1,3 @@ +#include "history.h" + +// TODO: define functions in history.h \ No newline at end of file diff --git a/src/history.h b/src/history.h new file mode 100644 index 0000000..a5e8977 --- /dev/null +++ b/src/history.h @@ -0,0 +1,11 @@ +#ifndef HISTORY_H +#define HISTORY_H + +char* history[500]; + +void createHistoryDir() {}; +void initHistory() {}; +void writeHistory() {}; +void accessHistory() {}; + +#endif \ No newline at end of file diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..b93a584 --- /dev/null +++ b/src/main.c @@ -0,0 +1,29 @@ +#include "cShell.h" + +int main() { + char input[INPUT_SIZE]; + char *args[100]; + char user[100] = "defaultusr"; + char *cwd = getCWD(); + char *trimmedCWD = trimCWD(cwd); + + while (1) { + if (cwd != NULL) { + printf("[cShell-%s] /%s $> ", user, trimmedCWD); + } else { + printf("[cShell-%s] $> ", user); + } + + if (!fgets(input, sizeof(input), stdin)) { + break; + } + + input[strcspn(input, "\n")] = '\0'; + + parseInput(input, args); + + handleCommand(args, &cwd, &trimmedCWD); + } + free(cwd); + return 0; +}