Skip to content

Commit

Permalink
Merge pull request #71 from McModknower/master
Browse files Browse the repository at this point in the history
Feature: save to stream
  • Loading branch information
jubalh authored Sep 10, 2024
2 parents 5650984 + 6b42ee7 commit e83e9cd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions man/nudoku.6
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ Display version information.
.BR \-c
Do not use colors. Black and white mode. Some terminals don't support colors, use this option in this case.

.BR \-o
Output stream.
Print a single sudoku onto standard output. Notation is in stream format like used by -s.

.BR \-d
Choose difficulty.
Available options are: easy, normal, hard
Expand Down
21 changes: 20 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ typedef struct move
static bool g_useColor = true;
static bool g_playing = false;
static bool g_useHighlights = false;
static bool g_output_stream = false; /* is the -o flag set */
static char* g_provided_stream = NULL; /* in case of -s flag the user provides the sudoku stream */
static bool g_resume_game = false; /* in case of -r flag and saved game state */
static int g_resume_level; /* store difficulty of the resume game */
Expand Down Expand Up @@ -109,6 +110,7 @@ static void print_usage(void)
printf(_("-h help:\t\tPrint this help\n"));
printf(_("-v version:\t\tPrint version\n"));
printf(_("-c nocolor:\t\tDo not use colors\n"));
printf(_("-o output:\t\tOutput stream (inverse of -s)\n"));
printf(_("-d difficulty:\t\tChoose between: easy, normal, hard\n"));
printf(_("-s stream:\t\tUser provided sudoku stream\n"));
printf(_("-r resume:\t\tResume the last saved game\n"));
Expand Down Expand Up @@ -273,10 +275,18 @@ bool save_stream(char user_board[], char plain_board[], int n)
return true;
}

void generate_stream_output(int difficulty) {
char* stream = generate_puzzle(difficulty);

printf("%s\n", stream);

free(stream);
}

static void parse_arguments(int argc, char *argv[])
{
int opt;
while ((opt = getopt(argc, argv, "hvcrs:d:p:i:n:")) != -1)
while ((opt = getopt(argc, argv, "hvcors:d:p:i:n:")) != -1)
{
switch (opt)
{
Expand All @@ -289,6 +299,9 @@ static void parse_arguments(int argc, char *argv[])
case 'c':
g_useColor = false;
break;
case 'o':
g_output_stream = true;
break;
case 's':
if (!is_valid_stream(optarg))
exit(EXIT_FAILURE);
Expand Down Expand Up @@ -643,6 +656,12 @@ int main(int argc, char *argv[])
parse_arguments(argc, argv);
srand(time(NULL));

if (g_output_stream)
{
generate_stream_output(g_level);
return EXIT_SUCCESS;
}

if (g_outputFilename)
{
#ifdef ENABLE_CAIRO
Expand Down

0 comments on commit e83e9cd

Please sign in to comment.