Added very simple parsing logic.
This commit is contained in:
+56
-1
@@ -1,7 +1,15 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
typedef struct opcode {
|
||||||
|
char op[255];
|
||||||
|
char param1[255];
|
||||||
|
char param2[255];
|
||||||
|
} Opcode;
|
||||||
|
|
||||||
void print_file(char*);
|
void print_file(char*);
|
||||||
|
Opcode* get_opcode(char*);
|
||||||
|
|
||||||
int main(int argc, char* args[]) {
|
int main(int argc, char* args[]) {
|
||||||
const char *input_files[argc - 1];
|
const char *input_files[argc - 1];
|
||||||
@@ -33,7 +41,21 @@ void print_file(char* file_path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
while((bytes_read = getline(&line, &len, file)) != -1) {
|
while((bytes_read = getline(&line, &len, file)) != -1) {
|
||||||
printf("%s", line);
|
//printf("%s", line);
|
||||||
|
|
||||||
|
unsigned short int count = 0;
|
||||||
|
char* c;
|
||||||
|
char* opcode;
|
||||||
|
char* param1;
|
||||||
|
char* param2;
|
||||||
|
|
||||||
|
//for(c = line; *c != '\0'; c++) {
|
||||||
|
Opcode* op = get_opcode(line);
|
||||||
|
//}
|
||||||
|
//printf("\n");
|
||||||
|
if (strcmp(op->op, "NA") == 0) continue;
|
||||||
|
|
||||||
|
printf("%s %s, %s\n", op->op, op->param1, op->param2);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
@@ -42,3 +64,36 @@ void print_file(char* file_path) {
|
|||||||
|
|
||||||
if (line) free(line);
|
if (line) free(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Opcode* get_opcode(char* line) {
|
||||||
|
Opcode *op = malloc(sizeof(Opcode));
|
||||||
|
strcpy(op->op, "NA");
|
||||||
|
|
||||||
|
if (strlen(line) == 0 ) return op;
|
||||||
|
if (line[0] == ';') return op;
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
for (char* c = line; *c != '\0'; c++) {
|
||||||
|
if (*c == ';') break;
|
||||||
|
if (*c == ' ') {
|
||||||
|
i = 0;
|
||||||
|
count++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*c == ',') {
|
||||||
|
i = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count == 0) op->op[i] = *c;
|
||||||
|
else if (count == 1) op->param1[i] = *c;
|
||||||
|
else if (count == 2) op->param2[i] = *c;
|
||||||
|
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return op;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user