Index: apps/plugins/sudoku/sudoku.h =================================================================== --- apps/plugins/sudoku/sudoku.h (revision 18118) +++ apps/plugins/sudoku/sudoku.h (working copy) @@ -226,6 +226,7 @@ int editmode; /* We are editing the start board */ #ifdef SUDOKU_BUTTON_POSSIBLE short possiblevals[9][9]; /* possible values a cell could be, user sets them */ + short savedpossible[9][9]; /* cached copy of possible cell values */ #endif }; Index: apps/plugins/sudoku/sudoku.c =================================================================== --- apps/plugins/sudoku/sudoku.c (revision 18118) +++ apps/plugins/sudoku/sudoku.c (working copy) @@ -638,10 +638,10 @@ { int fd; size_t n; - int r = 0, c = 0; + int r = 0, c = 0, d = 0; unsigned int i; int valid=0; - char buf[300]; /* A buffer to read a sudoku board from */ + char buf[500]; /* A buffer to read a sudoku board from */ fd=rb->open(filename, O_RDONLY); if (fd < 0) { @@ -650,15 +650,15 @@ } rb->strncpy(state->filename,filename,MAX_PATH); - n=rb->read(fd,buf,300); + n=rb->read(fd,buf,500); if (n <= 0) { return(false); } rb->close(fd); - r=0; c=0; i=0; + d=0; while ((i < n) && (r < 9)) { switch (buf[i]){ case ' ': case '\t': @@ -676,6 +676,7 @@ valid=0; } c = 0; + d = 0; break; case '_': case '.': valid=1; @@ -703,6 +704,13 @@ } c++; } + if((buf[i]>='a' && buf[i] <= 'z') && i < (n-1) + && (buf[i+1] >= 'a' && buf[i+1] <= 'z')) { + state->possiblevals[r][d] + = (((buf[i]-'a') * 26 + buf[i+1]-'a')<<1); + i+=2; + d++; + } /* Ignore any other characters */ break; } @@ -721,6 +729,9 @@ /* Save a copy of the saved state - so we can reload without using the disk */ rb->memcpy(state->savedboard,state->currentboard,81); +#ifdef SUDOKU_BUTTON_POSSIBLE + rb->memcpy(state->savedpossible, state->possiblevals, 81); +#endif return(true); } @@ -729,11 +740,20 @@ int fd; int r,c; int i; +#ifdef SUDOKU_BUTTON_POSSIBLE + int x; + char line[41]; +#else char line[13]; +#endif char sep[13]; rb->splash(0, "Saving..."); +#ifdef SUDOKU_BUTTON_POSSIBLE + rb->memcpy(line,"...|...|... ; \r\n",41); +#else rb->memcpy(line,"...|...|...\r\n",13); +#endif rb->memcpy(sep,"-----------\r\n",13); if (state->filename[0]==0) { @@ -757,6 +777,16 @@ i++; } } +#ifdef SUDOKU_BUTTON_POSSIBLE + i+=2; + for(c=0; c<9; c++) { + x = ((state->possiblevals[r][c]>>1)/26); + line[i++] = x + 'a'; + x = ((state->possiblevals[r][c]>>1)%26); + line[i++] = x + 'a'; + i++; + } +#endif rb->write(fd,line,sizeof(line)); if ((r==2) || (r==5)) { rb->write(fd,sep,sizeof(sep)); @@ -769,6 +799,9 @@ /* Save a copy of the saved state - so we can reload without using the disk */ rb->memcpy(state->savedboard,state->currentboard,81); +#ifdef SUDOKU_BUTTON_POSSIBLE + rb->memcpy(state->savedpossible, state->possiblevals, 81); +#endif return true; } else { return false; @@ -778,6 +811,9 @@ void restore_state(struct sudoku_state_t* state) { rb->memcpy(state->currentboard,state->savedboard,81); +#ifdef SUDOKU_BUTTON_POSSIBLE + rb->memcpy(state->possiblevals, state->savedpossible, 81); +#endif } void clear_board(struct sudoku_state_t* state)