From 56fb016254f73a808aa6f5003c0b6c2b2c5f2713 Mon Sep 17 00:00:00 2001 From: Liam Waldron Date: Thu, 4 May 2023 12:11:14 -0400 Subject: [PATCH] add modified parser --- src/emk.h | 2 +- src/parse.c | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/emk.h b/src/emk.h index 53520ba..68d6984 100644 --- a/src/emk.h +++ b/src/emk.h @@ -23,6 +23,6 @@ int checkForRoot(); char checkForEmkFile(); char readEmkFile(); -char includeFromConfig(); +char includeConfig(); #endif diff --git a/src/parse.c b/src/parse.c index 225fcf0..3448a3a 100644 --- a/src/parse.c +++ b/src/parse.c @@ -69,32 +69,38 @@ char readEmkFile() { fclose(emkfile); } -char includeFromConfig() { +char includeConfig() { char cwd[PATH_MAX]; - FILE *emkconfig, *emkfile; + file *emkconfig, *emkfile, *emkfile_new; char filename[100], contents; emkconfig = fopen(EMKCONFIG, "r"); - if (emkconfig == NULL) { - printf(COL_BLUE "INF" COL_RESET " | no config.emk found\n"); - } else if (getcwd(cwd, sizeof(cwd)) != NULL) { - printf(COL_BLUE "INF" COL_RESET " | including config.emk at %s\n", cwd); - } + emkfile = fopen(EMKFILE, "r"); - emkfile = fopen(EMKFILE, "w"); + emkfile_new = fopen(EMKFILE_NEW, "a+"); + /* write emkconfig to new emkfile */ contents = fgetc(emkconfig); while (contents != EOF) { - fputc(contents, emkfile); + fputc(contents, emkfile_new); contents = fgetc(emkconfig); } + /* write emkfile to new emkfile */ + contents = fgetc(emkfile): + while (contents != EOF) { + fputc(contents, emkfile_new); + contents = fgetc(emkfile); + } + fclose(emkconfig); fclose(emkfile); + fclose(emkfile_new); } int main() { checkForEmkFile(); readEmkFile(); checkForRoot(); + includeConfig(); }