add assembly file reading
This commit is contained in:
parent
fa17a7fda3
commit
6203e65bdc
@ -1,32 +1,56 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
bool isValidFileFormat(char filename[], char expectedExtension[]){
|
#define MAX_ASM_LINE_LENGTH 100
|
||||||
|
|
||||||
|
int isValidFileFormat(char filename[], char expectedExtension[]){
|
||||||
int *pointLoc = strrchr(filename, '.');
|
int *pointLoc = strrchr(filename, '.');
|
||||||
|
|
||||||
if(pointLoc != NULL){
|
if(pointLoc != NULL){
|
||||||
if(strcmp(pointLoc, expectedExtension)==0){
|
if(strcmp(pointLoc, expectedExtension)==0){
|
||||||
return true;
|
return(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int writeBinaryFile(word instrs[], char outputFile[]){
|
int writeBinaryFile(word instrs[], char outputFile[]){
|
||||||
|
|
||||||
if (!isValidFileFormat(filename, "bin")){
|
if (!isValidFileFormat(filename, "bin")){
|
||||||
return(1);
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
fp = fopen(outputFile, "wb");
|
fp = fopen(outputFile, "wb");
|
||||||
|
|
||||||
|
if(fp == NULL){
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
|
||||||
fwrite(instrs, 4, sizeof(instrs), fp);
|
fwrite(instrs, 4, sizeof(instrs), fp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
return(0);
|
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);
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user