diff --git a/src/fileaccess.c b/src/fileaccess.c index e3e5df8..3ee3831 100644 --- a/src/fileaccess.c +++ b/src/fileaccess.c @@ -1,32 +1,56 @@ #include #include -bool isValidFileFormat(char filename[], char expectedExtension[]){ +#define MAX_ASM_LINE_LENGTH 100 + +int isValidFileFormat(char filename[], char expectedExtension[]){ int *pointLoc = strrchr(filename, '.'); if(pointLoc != NULL){ if(strcmp(pointLoc, expectedExtension)==0){ - return true; + return(1); } } - return false; + return(0); } int writeBinaryFile(word instrs[], char outputFile[]){ if (!isValidFileFormat(filename, "bin")){ - return(1); + return(-1); } FILE *fp; fp = fopen(outputFile, "wb"); + + if(fp == NULL){ + return(-1); + } + fwrite(instrs, 4, sizeof(instrs), fp); fclose(fp); return(0); } -int readAssemblyFile() { +int readAssemblyFile(char inputFile[]) { + if (!isValidFileFormat(filename, "s")){ + return(1); + } + FILE *fp; + char savedLine[MAX_ASM_LINE_LENGTH]; + + fp = fopen(inputFile, "r"); + + if(fp == NULL){ + return(-1); + } + + while (fgets(savedLine, MAX_ASM_LINE_LENGTH-1, fp) != NULL) { + //pass line to parser + } + + return(0); } \ No newline at end of file