From 4f09ea0249e46f0b386af77fd8f821b7667e6089 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Wed, 27 Apr 2016 12:12:11 -0400 Subject: [PATCH] Add basic file parsing --- csim.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/csim.c b/csim.c index bab4fde..9ac1d73 100644 --- a/csim.c +++ b/csim.c @@ -62,6 +62,30 @@ int main(int argc, char* argv[]) /* End of argument parsing. */ printf("Arguments: %zd, %zd, %zd, %hd, %s\n", set_index_bits, lines, block_bits, VERBOSE, filename); + char buffer[20]; + FILE* f = fopen(filename, "r"); + if(!f) + { + printf("Invalid file name: %s", filename); + exit(-1); + } + + while (fgets(buffer, 20, f)) + { + if (buffer[0] == 'I') + continue; + + char* end; + char op = buffer[1]; + long address = strtol(buffer+3, &end, 16); + if (*end != ',' || !(op == 'S' || op == 'L' || op == 'M')) + { + printf("Invalid input file, last line:\n%s\n", buffer); + return -1; + } + printf("%c %ld\n", op, address); + } + printSummary(0, 0, 0); return 0; }