X-Git-Url: https://harishankar.org/repos/?p=wordblah.git;a=blobdiff_plain;f=wordblox.h;h=bd286e3b2ba5207c20f030db7b1a18f78df18adc;hp=53c522b848ea505391742d373a75c935bedc33f6;hb=762979409c32bd4902716911101a1d1071f11038;hpb=57adeb73762dac7590dcac1b2d1e462d50e8565d diff --git a/wordblox.h b/wordblox.h index 53c522b..bd286e3 100644 --- a/wordblox.h +++ b/wordblox.h @@ -53,6 +53,40 @@ int get_num () return n; } +/* Output the clues to text file */ +void export_clues (Puzzle *p, const char *filename) +{ + FILE *outfile = fopen (filename, "w"); + if (outfile == NULL) + { + fprintf (stderr, "%s\n", ERROR_WRITING_FILE); + exit (1); + } + /* first the across clues */ + fprintf (outfile, "ACROSS CLUES\n"); + for (int i = 0; i < p->grid_size; i ++) + { + for (int j = 0; j < p->grid_size; j ++) + { + if (p->start_across_word[i][j] != -1) + fprintf (outfile, "%d - %s\n", p->start_across_word[i][j], + p->clue_across[i][j]); + } + } + /* now the down clues */ + fprintf (outfile, "DOWN CLUES\n"); + for (int i = 0; i < p->grid_size; i ++) + { + for (int j = 0; j < p->grid_size; j ++) + { + if (p->start_down_word[i][j] != -1) + fprintf (outfile, "%d - %s\n", p->start_down_word[i][j], + p->clue_down[i][j]); + } + } + fclose (outfile); +} + /* Output the grid to image - if answerkey is true export filled grid */ void export_grid_image (Puzzle *p, const char *filename, bool answerkey) { @@ -341,13 +375,15 @@ void print_puzzle (Puzzle *p) } /* function to check if a word is valid or not */ -bool is_valid_word (const char *word) +char* is_valid_word (char *word) { - for (int i = 0; i < strlen (word); i ++) + if (word == NULL || strlen(word) == 0) + return NULL; + for (int i = 0; i < strlen (word) - 1; i ++) if (! isalpha (word[i])) - return false; + return NULL; - return true; + return strtok (word, "\n"); } @@ -391,8 +427,12 @@ void print_menu (enum COLOR fg, enum COLOR bg, const char* title, printf ("\u2550"); printf ("\u2557"); reset_color (); printf ("\n"); + printf ("\u2551"); set_color (fg, bg, BOLD); - printf ("\u2551%-*s\u2551", padding, title); + printf ("%-*s", padding, title); + reset_color (); + set_color (fg, bg, NORMAL); + printf ("\u2551"); reset_color (); printf ("\n"); set_color (fg, bg, NORMAL); printf ("\u2560");