Restored old method of checking for presence of arguments.
This commit is contained in:
parent
dc67c24899
commit
490d8cafde
14
csim.c
14
csim.c
@ -61,8 +61,8 @@ size_t parse_int_arg(char* arg, char opt)
|
|||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
size_t index_bits = 1, lines = ~0, block_bits = 1; // Useful variables.
|
size_t index_bits = 0, lines = 0, block_bits = 0; // Useful variables.
|
||||||
char *filename;
|
char *filename = NULL;
|
||||||
int opt = 0, argflags = 0;
|
int opt = 0, argflags = 0;
|
||||||
while ((opt=getopt(argc, argv, "hvs:E:b:t:")) != -1) {
|
while ((opt=getopt(argc, argv, "hvs:E:b:t:")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
@ -72,19 +72,15 @@ int main(int argc, char* argv[])
|
|||||||
break;
|
break;
|
||||||
case 's': // 2^s = number of sets
|
case 's': // 2^s = number of sets
|
||||||
index_bits = parse_int_arg(optarg, 's');
|
index_bits = parse_int_arg(optarg, 's');
|
||||||
argflags |= 8; // 0b1000
|
|
||||||
break;
|
break;
|
||||||
case 'E': // associativity - lines per set
|
case 'E': // associativity - lines per set
|
||||||
lines = parse_int_arg(optarg, 'E');
|
lines = parse_int_arg(optarg, 'E');
|
||||||
argflags |= 4; // 0b0100
|
|
||||||
break;
|
break;
|
||||||
case 'b': // 2^b = block size
|
case 'b': // 2^b = block size
|
||||||
block_bits = parse_int_arg(optarg, 'b');
|
block_bits = parse_int_arg(optarg, 'b');
|
||||||
argflags |= 2; // 0b0010
|
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
filename = optarg;
|
filename = optarg;
|
||||||
argflags |= 1; // 0b0001
|
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
print_usage();
|
print_usage();
|
||||||
@ -95,16 +91,12 @@ int main(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* If any required arguments were not provided. (argflags != 0b1111) */
|
/* 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");
|
printf("Usage: ./csim [-hv] -s <number> -E <number> -b <number> -t <file>\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
/* End of argument parsing. */
|
/* End of argument parsing. */
|
||||||
|
|
||||||
printf("Arguments: %zd, %zd, %zd, %hd, %s\n", index_bits, lines, block_bits, VERBOSE, filename);
|
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);
|
printSummary(0, 0, 0);
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user