Commit 90c96e42 authored by Matthew Burket's avatar Matthew Burket
Browse files

Started History

parent 8a900b9a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -3,5 +3,5 @@ project(coms352_shell C)

set(CMAKE_C_STANDARD 11)

add_executable(coms352_shell main.c tokenize.c tokenize.h)
add_executable(coms352_shell main.c tokenize.c tokenize.h file_operations.c file_operations.h)
target_link_libraries(coms352_shell)

file_operations.c

0 → 100644
+5 −0
Original line number Diff line number Diff line
//
// Created by mburket on 2/28/18.
//

#include "file_operations.h"

file_operations.h

0 → 100644
+8 −0
Original line number Diff line number Diff line
//
// Created by mburket on 2/28/18.
//

#ifndef COMS352_SHELL_FILE_OPERATIONS_H
#define COMS352_SHELL_FILE_OPERATIONS_H

#endif //COMS352_SHELL_FILE_OPERATIONS_H
+45 −35
Original line number Diff line number Diff line
@@ -7,24 +7,35 @@
#include "tokenize.h"

#define TRUE 0
#define READ 0
#define BUFFSIZE (sizeof(char) * 5000)

int main() {
    // Read line examples: https://eli.thegreenplace.net/2016/basics-of-using-the-readline-library/
    // Setup Some Vars
    int should_run = 1;
    char *readBuff = malloc(sizeof(char) * 5000);
    char *readBuff = malloc(BUFFSIZE);
    char *HOME = getenv("HOME");
    char *HISTORY_FILE = HOME;
    strcat(HISTORY_FILE, "/.bsh_history");
    // Copyright statement
    fprintf(stdout, "Welcome to Burket Shell (bsh)\n");
    fprintf(stdout, "Copyright 2018 Matthew Burket\n");
    fprintf(stdout, "Released under the GPL v3 License\n");
    // Time to start the main loop
    while (should_run) {
        // Burket Shell (bsh) prompt
        fprintf(stdout, "bsh # ");
        // Getting User Input
        fgets(readBuff, sizeof(char) * 5000, stdin);
        // Remove the newline from fgets
        strtok(readBuff, "\n");
        //while ((readBuff = readline("bsh >> ")) != 0) {
        // If input wr
        if (strlen(readBuff) > 0) {
                // History stuff and errors
            }
            FILE *fp = fopen(HISTORY_FILE, "a+");
            write(fp->_fileno, readBuff, BUFFSIZE);
            close(fp);

        }
        // Remove the newline from fgets
        strtok(readBuff, "\n");
        if (strcmp("exit", readBuff) == TRUE) {
            should_run = 0;
            free(readBuff);
@@ -47,9 +58,9 @@ int main() {
            runInBackground = 1;
            tokens[numTokens - 2] = NULL;
        }

        if (fork() == 0) {
                int returnCode = execvp(tokens[0], tokens);
                printf("Return code %d\n", returnCode);
            execvp(tokens[0], tokens);
        } else {
            if (runInBackground == 0) {
                wait(NULL);
@@ -57,5 +68,4 @@ int main() {
        }
        free(tokens);
    }
    //}
}
 No newline at end of file