summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2010-06-06 10:59:29 +0000
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2010-06-06 10:59:29 +0000
commit3ee3b28f8a57429e33fb2215199025bc31d9dfe1 (patch)
tree4c7b06c5cf5613c60fa281e42c3add3ff1444d9b /apps
parentb2302e4e9b279a11abad118d2380d4eaa073af4c (diff)
downloadrockbox-3ee3b28f8a57429e33fb2215199025bc31d9dfe1.tar.gz
rockbox-3ee3b28f8a57429e33fb2215199025bc31d9dfe1.zip
Save the scratchpad state in Sudoku plugin (FS#5737).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26622 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r--apps/plugins/sudoku/sudoku.c46
-rw-r--r--apps/plugins/sudoku/sudoku.h1
2 files changed, 38 insertions, 9 deletions
diff --git a/apps/plugins/sudoku/sudoku.c b/apps/plugins/sudoku/sudoku.c
index 02615caac1..f3d9b1e75f 100644
--- a/apps/plugins/sudoku/sudoku.c
+++ b/apps/plugins/sudoku/sudoku.c
@@ -302,6 +302,10 @@ static void save_state(struct sudoku_state_t *state)
302{ 302{
303 rb->memcpy(state->savedboard, state->currentboard, 303 rb->memcpy(state->savedboard, state->currentboard,
304 sizeof(state->savedboard)); 304 sizeof(state->savedboard));
305#ifdef SUDOKU_BUTTON_POSSIBLE
306 rb->memcpy(state->savedpossible, state->possiblevals,
307 sizeof(state->savedpossible));
308#endif
305} 309}
306 310
307/* Copies the saved to the current board */ 311/* Copies the saved to the current board */
@@ -309,6 +313,10 @@ static void restore_state(struct sudoku_state_t *state)
309{ 313{
310 rb->memcpy(state->currentboard, state->savedboard, 314 rb->memcpy(state->currentboard, state->savedboard,
311 sizeof(state->savedboard)); 315 sizeof(state->savedboard));
316#ifdef SUDOKU_BUTTON_POSSIBLE
317 rb->memcpy(state->possiblevals, state->savedpossible,
318 sizeof(state->possiblevals));
319#endif
312} 320}
313 321
314void default_state(struct sudoku_state_t* state) 322void default_state(struct sudoku_state_t* state)
@@ -420,10 +428,10 @@ bool load_sudoku(struct sudoku_state_t* state, char* filename)
420{ 428{
421 int fd; 429 int fd;
422 size_t n; 430 size_t n;
423 int r = 0, c = 0; 431 int r = 0, c = 0, d = 0;
424 unsigned int i; 432 unsigned int i;
425 int valid=0; 433 int valid=0;
426 char buf[300]; /* A buffer to read a sudoku board from */ 434 char buf[500]; /* A buffer to read a sudoku board from */
427 435
428 fd=rb->open(filename, O_RDONLY); 436 fd=rb->open(filename, O_RDONLY);
429 if (fd < 0) { 437 if (fd < 0) {
@@ -432,15 +440,15 @@ bool load_sudoku(struct sudoku_state_t* state, char* filename)
432 } 440 }
433 441
434 rb->strlcpy(state->filename,filename,MAX_PATH); 442 rb->strlcpy(state->filename,filename,MAX_PATH);
435 n=rb->read(fd,buf,300); 443 n=rb->read(fd,buf,500);
436 if (n <= 0) { 444 if (n <= 0) {
437 return(false); 445 return(false);
438 } 446 }
439 rb->close(fd); 447 rb->close(fd);
440
441 r=0; 448 r=0;
442 c=0; 449 c=0;
443 i=0; 450 i=0;
451 d=0;
444 while ((i < n) && (r < 9)) { 452 while ((i < n) && (r < 9)) {
445 switch (buf[i]){ 453 switch (buf[i]){
446 case ' ': case '\t': 454 case ' ': case '\t':
@@ -458,6 +466,7 @@ bool load_sudoku(struct sudoku_state_t* state, char* filename)
458 valid=0; 466 valid=0;
459 } 467 }
460 c = 0; 468 c = 0;
469 d = 0;
461 break; 470 break;
462 case '_': case '.': 471 case '_': case '.':
463 valid=1; 472 valid=1;
@@ -485,6 +494,13 @@ bool load_sudoku(struct sudoku_state_t* state, char* filename)
485 } 494 }
486 c++; 495 c++;
487 } 496 }
497 if((buf[i]>='a' && buf[i] <= 'z') && i < (n-1)
498 && (buf[i+1] >= 'a' && buf[i+1] <= 'z')) {
499 state->possiblevals[r][d]
500 = (((buf[i]-'a') * 26 + buf[i+1]-'a')<<1);
501 i++;
502 d++;
503 }
488 /* Ignore any other characters */ 504 /* Ignore any other characters */
489 break; 505 break;
490 } 506 }
@@ -511,12 +527,15 @@ bool save_sudoku(struct sudoku_state_t* state)
511 int fd; 527 int fd;
512 int r,c; 528 int r,c;
513 int i; 529 int i;
514 char line[13]; 530#ifdef SUDOKU_BUTTON_POSSIBLE
515 char sep[13]; 531 int x;
532 char line[41]="...|...|... ; \r\n";
533#else
534 char line[13]="...|...|...\r\n";
535#endif
536 char sep[13]="-----------\r\n";
516 537
517 rb->splash(0, "Saving..."); 538 rb->splash(0, "Saving...");
518 rb->memcpy(line,"...|...|...\r\n",13);
519 rb->memcpy(sep,"-----------\r\n",13);
520 539
521 if (state->filename[0]==0) { 540 if (state->filename[0]==0) {
522 return false; 541 return false;
@@ -539,6 +558,15 @@ bool save_sudoku(struct sudoku_state_t* state)
539 i++; 558 i++;
540 } 559 }
541 } 560 }
561#ifdef SUDOKU_BUTTON_POSSIBLE
562 i+=2;
563 for(c=0; c<9; c++) {
564 x = ((state->possiblevals[r][c]>>1)/26);
565 line[i++] = x + 'a';
566 x = ((state->possiblevals[r][c]>>1)%26);
567 line[i++] = x + 'a';
568 }
569#endif
542 rb->write(fd,line,sizeof(line)); 570 rb->write(fd,line,sizeof(line));
543 if ((r==2) || (r==5)) { 571 if ((r==2) || (r==5)) {
544 rb->write(fd,sep,sizeof(sep)); 572 rb->write(fd,sep,sizeof(sep));
@@ -570,7 +598,7 @@ void clear_board(struct sudoku_state_t* state)
570 state->y=0; 598 state->y=0;
571} 599}
572 600
573void update_cell(struct sudoku_state_t* state, int r, int c) 601void update_cell(struct sudoku_state_t* state, int r, int c)
574{ 602{
575 /* We have four types of cell: 603 /* We have four types of cell:
576 1) User-entered number 604 1) User-entered number
diff --git a/apps/plugins/sudoku/sudoku.h b/apps/plugins/sudoku/sudoku.h
index 8974bd8768..f943a9f5fc 100644
--- a/apps/plugins/sudoku/sudoku.h
+++ b/apps/plugins/sudoku/sudoku.h
@@ -330,6 +330,7 @@ struct sudoku_state_t {
330 int editmode; /* We are editing the start board */ 330 int editmode; /* We are editing the start board */
331#ifdef SUDOKU_BUTTON_POSSIBLE 331#ifdef SUDOKU_BUTTON_POSSIBLE
332 short possiblevals[9][9]; /* possible values a cell could be, user sets them */ 332 short possiblevals[9][9]; /* possible values a cell could be, user sets them */
333 short savedpossible[9][9]; /* cached copy of possible cell values */
333#endif 334#endif
334}; 335};
335 336