fix syntax errors in fileio.c

This commit is contained in:
EDiasAlberto 2024-06-11 21:23:26 +01:00
parent 647f47e39d
commit 62ff6e9e02
3 changed files with 14 additions and 14 deletions

View File

@ -1,8 +1,8 @@
#include <stdlib.h>
#include <stdio.h>
#include "parser.c"
#include "fileio.c"
int main(int argc, char **argv) {
return EXIT_SUCCESS;
}

View File

@ -4,7 +4,7 @@
#define MAX_ASM_LINE_LENGTH 30
int isValidFileFormat(char filename[], char expectedExtension[]){
int *pointLoc = strrchr(filename, '.');
char *pointLoc = strrchr(filename, '.');
if(pointLoc != NULL){
if(strcmp(pointLoc, expectedExtension)==0){
@ -14,9 +14,9 @@ int isValidFileFormat(char filename[], char expectedExtension[]){
return(0);
}
int writeBinaryFile(word instrs[], char outputFile[]){
int writeBinaryFile(word instrs[], char outputFile[], int numInstrs){
if (!isValidFileFormat(filename, "bin")){
if (!isValidFileFormat(outputFile, "bin")){
return(-1);
}
@ -28,14 +28,14 @@ int writeBinaryFile(word instrs[], char outputFile[]){
return(-1);
}
fwrite(instrs, 4, sizeof(instrs), fp);
fwrite(instrs, 4, sizeof(word) * numInstrs, fp);
fclose(fp);
return(0);
}
char **readAssemblyFile(char inputFile[]) {
if (!isValidFileFormat(filename, "s")){
if (!isValidFileFormat(inputFile, "s")){
return(NULL);
}
@ -51,24 +51,24 @@ char **readAssemblyFile(char inputFile[]) {
{
if (ch == '\n' || ch == '\0')
{
count++;
lineCount++;
}
}
char **heap = malloc(sizeof(char *) * count);
char **heap = malloc(sizeof(char *) * lineCount);
rewind(fp);
for( int i=0; i<count; i++) {
for( int i=0; i<lineCount; i++) {
char tmp[512];
// read line into tmp
fgets(tmp, MAX_ASM_LINE_LENGTH-1, fp);
size = strlen(tmp)
int size = strlen(tmp);
char *line = malloc(size+1) // allocate mem for text line
char *line = malloc(size+1); // allocate mem for text line
strcpy(line, tmp);

View File

@ -1,6 +1,6 @@
# include "global.h"
# include "a64instruction.h"
# include "symboltable.h"
#include "global.h"
#include "a64instruction.h"
#include "symboltable.h"
//generates assembled code based on two pass assembly method