Rework contest argument parsing.

This commit is contained in:
Yorick Barbanneau 2021-09-17 16:43:35 +02:00
parent b16d91fb2e
commit 90508a3b3b

View file

@ -104,12 +104,10 @@ int main(int argc, char* argv[]) {
case 'c': case 'c':
if ( OPTIONAL_ARGUMENT_IS_PRESENT ) { if ( OPTIONAL_ARGUMENT_IS_PRESENT ) {
if ( access(optarg, R_OK) == 0) { if ( access(optarg, F_OK | R_OK) == -1) {
printf("Contest file valid\n");
}
else {
fprintf(stderr, "Can't access to file %s\n", optarg); fprintf(stderr, "Can't access to file %s\n", optarg);
} exit (EXIT_FAILURE); exit (EXIT_FAILURE);
}
} }
else { else {
fprintf(stderr, "Error: contest need a file\n"); fprintf(stderr, "Error: contest need a file\n");
@ -127,11 +125,11 @@ int main(int argc, char* argv[]) {
printf("utictactoe %d.%d.%d\n", VERSION, SUBVERSION, REVISION); printf("utictactoe %d.%d.%d\n", VERSION, SUBVERSION, REVISION);
printf("This software implements a full ultimate tictactoe game.\n"); printf("This software implements a full ultimate tictactoe game.\n");
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
case 'h': case 'h':
help(); help();
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
default: default:
fprintf(stderr, "Try `utictactie --help' for more information.\n"); fprintf(stderr, "Try `utictactie --help' for more information.\n");
exit (EXIT_FAILURE); exit (EXIT_FAILURE);