Browse Source

Restored old method of checking for presence of arguments.

masstesting
Jacob 6 years ago
parent
commit
490d8cafde
  1. 14
      csim.c

14
csim.c

@ -61,8 +61,8 @@ size_t parse_int_arg(char* arg, char opt) @@ -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[]) @@ -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[]) @@ -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;