Started adding parsing of command-line options
This commit is contained in:
parent
89712fc9dc
commit
bf1ae99a9a
4 changed files with 56 additions and 15 deletions
32
connect4.c
32
connect4.c
|
|
@ -17,6 +17,7 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <getopt.h>
|
||||
#include "macros.h"
|
||||
#include "config.h"
|
||||
#include "logic.h"
|
||||
|
|
@ -25,8 +26,33 @@
|
|||
|
||||
#define VERSION 0.0.3
|
||||
|
||||
int main(){
|
||||
// First the boilerplate stuffs
|
||||
int main( int argc, char *argv[] ){
|
||||
// Parse options
|
||||
for(;;){
|
||||
static struct option long_options[] = {
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
{ "license", no_argument, NULL, 'l' },
|
||||
{ "version", no_argument, NULL, '\0' },
|
||||
{ 0 }
|
||||
};
|
||||
int option_index = 0;
|
||||
char c = getopt_long( argc, argv, "hl", long_options, &option_index );
|
||||
|
||||
if( c == -1 ) break;
|
||||
|
||||
switch( c ){
|
||||
case 'h':
|
||||
printf( "Usage: connect4 [OPTIONS]\n\n" );
|
||||
for( int i = 0; long_options[i].name != NULL; i++ ){
|
||||
if( long_options[i].val != '\0' )
|
||||
printf( " -%c --", long_options[i].val );
|
||||
else printf( " --" );
|
||||
printf( long_options[i].name );
|
||||
putchar( '\n' );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
printf(
|
||||
"AnnaConnect version "XSTR(VERSION)", Copyright (C) Anna Snoeijs\n"
|
||||
"AnnaConnect comes with ABSOLUTELY NO WARRANTY\n"
|
||||
|
|
@ -63,6 +89,6 @@ int main(){
|
|||
int column = askColumn( playboard, move );
|
||||
playMove( &playboard, move, column );
|
||||
calcWins( &wins, playboard );
|
||||
updateBoard( wins, playboard, column );
|
||||
updateBoard( wins, playboard, move, column );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue