From 2a8124df0991a99a68b1de23d269c573e4d2ef8e Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Mon, 25 Apr 2016 17:07:24 -0400 Subject: [PATCH] Added basic argument parsing --- csim.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/csim.c b/csim.c index 44fdd4b..e66cd5a 100644 --- a/csim.c +++ b/csim.c @@ -1,7 +1,56 @@ +#include +#include #include "cachelab.h" -int main() +void print_usage() { + printf("Usage:\n"); + exit(0); +} + +int parse_int_arg(char* arg) +{ + int i = atoi(arg); + if (i != 0) + return i; + else + exit(-1); +} + +int main(int argc, char* argv[]) +{ + int set_bits = 0, lines = 0, block_bits = 0, verbose = 0; + char* filename; + int ii; + for (ii = 0; ii < argc; ii++) + { + switch (argv[ii][1]) + { + case 'h': + //print_usage(); + break; + case 'v': + verbose = 1; + break; + case 's': + set_bits = parse_int_arg(argv[ii+1]); + break; + case 'E': + lines = parse_int_arg(argv[ii+1]); + break; + case 'b': + block_bits = parse_int_arg(argv[ii+1]); + break; + case 't': + filename = argv[ii+1]; + break; + } + } + + printf("Arguments: %d, %d, %d, %d, %s\n", set_bits, lines, block_bits, verbose, filename); + if(!set_bits|| !lines || !block_bits || !filename) + print_usage(); + printSummary(0, 0, 0); return 0; }