From f59be8398dbde340d95f506879a46c526ea064dd Mon Sep 17 00:00:00 2001 From: AnnaSnoeijs Date: Thu, 14 Aug 2025 22:49:04 +0200 Subject: [PATCH] Added option to disable command-line options --- connect4.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/connect4.c b/connect4.c index 38c3269..818ee72 100644 --- a/connect4.c +++ b/connect4.c @@ -20,7 +20,9 @@ #include #include #include +#ifndef NO_OPTIONS #include +#endif /* ! NO_OPTIONS */ #include #include "macros.h" #include "config.h" @@ -39,12 +41,14 @@ #define VERSIONSTRING \ "AnnaConnect version "XSTR(FULLVERSION)", Copyright (C) Anna Snoeijs\n" +#ifndef NO_OPTIONS // The LISENCE file // Not null-terminated so need pointers for both start and end extern char _binary_LICENSE_start[]; extern char _binary_LICENSE_end[]; +#endif /* ! NO_OPTIONS */ -int main( int argc, char *argv[] ){ +int main( [[maybe_unused]] int argc, [[maybe_unused]] char *argv[] ){ // Initialise variables board_t playboard = { .player = 0, @@ -53,9 +57,10 @@ int main( int argc, char *argv[] ){ .count0 = {0}, .count1 = {0}, }; + wins_t *wins = malloc( sizeof(wins_t) ); +#ifndef NO_OPTIONS FILE *outputfile = NULL; char *filename = NULL; - wins_t *wins = malloc( sizeof(wins_t) ); bool randomMoves = 0; // Parse options for(;;){ @@ -158,12 +163,18 @@ int main( int argc, char *argv[] ){ return -1; } #undef ROWOVERFLOW +#endif /* ! NO_OPTIONS */ // Start the actual program printf( VERSIONSTRING "AnnaConnect comes with ABSOLUTELY NO WARRANTY\n" "This is free software, and you are welcome to redistribute it\n" - "under certain condtions. See `%s --license`\n", argv[0] + "under certain condtions." +#ifndef NO_OPTIONS + " See `%s --license`\n", argv[0] +#else /* NO_OPTIONS */ + "\n" +#endif /* NO_OPTIONS */ ); // board, innit? // Allocate the board @@ -185,11 +196,10 @@ int main( int argc, char *argv[] ){ wins->same.horizontal4 = calloc( playboard.columns, sizeof(column_t) ); wins->same.diagonalUp4 = calloc( playboard.columns, sizeof(column_t) ); wins->same.diagonalDown4 = calloc( playboard.columns, sizeof(column_t) ); - goto init_ui; } - init_ui: initBoard( playboard ); // Begin loopin +#ifndef NO_OPTIONS if( outputfile != NULL ){ fprintf( outputfile, @@ -203,21 +213,29 @@ int main( int argc, char *argv[] ){ playboard.columns ); } +#endif /* ! NO_OPTIONS */ for(;; playboard.player = !playboard.player ){ columnsint_t column; +#ifndef NO_OPTIONS if( randomMoves ){ column = randomColumn( playboard ); }else{ column = askColumn( playboard ); }; +#else /* NO_OPTIONS */ + column = askColumn( playboard ); +#endif /* NO_OPTIONS */ if( column == QUITCOLUMN ) break; playMove( &playboard, column ); calcWins( wins, &playboard, column ); updateBoard( playboard, column ); +#ifndef NO_OPTIONS if( outputfile != NULL ){ fprintf( outputfile, "%d\n", column ); } +#endif /* ! NO_OPTIONS */ } +#ifndef NO_OPTIONS if( outputfile != NULL ){ fprintf( outputfile, "# Wins\n" @@ -237,5 +255,6 @@ int main( int argc, char *argv[] ){ fclose( outputfile ); printf( "Output is written to %s\n", filename ); } +#endif /* ! NO_OPTIONS */ exit_ui(); }