Restored old method of checking for presence of arguments.

This commit is contained in:
Jacob 2016-04-27 11:30:58 -04:00
parent dc67c24899
commit 490d8cafde

14
csim.c
View File

@ -61,8 +61,8 @@ size_t parse_int_arg(char* arg, char opt)
int main(int argc, char* argv[])
{
size_t index_bits = 1, lines = ~0, block_bits = 1; // Useful variables.
char *filename;
size_t index_bits = 0, lines = 0, block_bits = 0; // Useful variables.
char *filename = NULL;
int opt = 0, argflags = 0;
while ((opt=getopt(argc, argv, "hvs:E:b:t:")) != -1) {
switch (opt) {
@ -72,19 +72,15 @@ int main(int argc, char* argv[])
break;
case 's': // 2^s = number of sets
index_bits = parse_int_arg(optarg, 's');
argflags |= 8; // 0b1000
break;
case 'E': // associativity - lines per set
lines = parse_int_arg(optarg, 'E');
argflags |= 4; // 0b0100
break;
case 'b': // 2^b = block size
block_bits = parse_int_arg(optarg, 'b');
argflags |= 2; // 0b0010
break;
case 't':
filename = optarg;
argflags |= 1; // 0b0001
break;
case 'h':
print_usage();
@ -95,16 +91,12 @@ int main(int argc, char* argv[])
}
}
/* If any required arguments were not provided. (argflags != 0b1111) */
if (argflags != 15) {
if (!index_bits || !lines || !block_bits || !filename) {
printf("Usage: ./csim [-hv] -s <number> -E <number> -b <number> -t <file>\n");
return 1;
}
/* End of argument parsing. */
printf("Arguments: %zd, %zd, %zd, %hd, %s\n", index_bits, lines, block_bits, VERBOSE, filename);
if(!index_bits || !lines || !block_bits || !filename) {
print_usage();
}
printSummary(0, 0, 0);
return 0;