Update fileio, skip new lines
This commit is contained in:
parent
b3a108d3a3
commit
fab4047d22
@ -35,11 +35,13 @@ int countLines(char *filename) {
|
||||
|
||||
int count = 0;
|
||||
char c;
|
||||
char prevC = '\n';
|
||||
|
||||
while ((c = fgetc(file)) != EOF) {
|
||||
if (c == '\n') {
|
||||
if (c == '\n' && prevC != '\n') {
|
||||
count++;
|
||||
}
|
||||
prevC = c;
|
||||
}
|
||||
|
||||
return count;
|
||||
@ -71,6 +73,11 @@ char **readAssemblyFile(char filename[], int lineCount) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (*buffer == '\n') {
|
||||
// Skip empty lines.
|
||||
continue;
|
||||
}
|
||||
|
||||
lines[currentLine] = malloc(strlen(buffer) + 1);
|
||||
if (lines[currentLine] == NULL) {
|
||||
fprintf(stderr, "Error: Could not allocate memory to store the assembly line");
|
||||
|
||||
@ -213,7 +213,8 @@ void parser_instruction(char asmLine[], a64inst_instruction *instr) {
|
||||
strcpy(stringptr, asmLine);
|
||||
|
||||
char *opcode = strtok(stringptr, " ");
|
||||
char *operands = strtok(NULL, "");
|
||||
char *operands = strtok(stringptr, "");
|
||||
|
||||
|
||||
if(strcmp(opcode, ".int") == 0){
|
||||
//type is directive
|
||||
@ -223,8 +224,8 @@ void parser_instruction(char asmLine[], a64inst_instruction *instr) {
|
||||
//type is label
|
||||
//add to symbol table
|
||||
instr->type = a64inst_LABEL;
|
||||
char *opcodeCpy = NULL;
|
||||
opcodeCpy = strcpy(opcodeCpy, opcode);
|
||||
char opcodeCpy[strlen(opcode)];
|
||||
strcpy(opcodeCpy, opcode);
|
||||
char *labelData = strtok(opcodeCpy, ":");
|
||||
instr->data.LabelData.label = labelData;
|
||||
} else {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user