Added option to disable command-line options

This commit is contained in:
AnnaSnoeijs 2025-08-14 22:49:04 +02:00
parent cbe9d25f11
commit f59be8398d

View file

@ -20,7 +20,9 @@
#include <stdlib.h>
#include <stdint.h>
#include <limits.h>
#ifndef NO_OPTIONS
#include <getopt.h>
#endif /* ! NO_OPTIONS */
#include <string.h>
#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();
}