From 8125fcc1028b0f177f5c2bac5b6bd35b44e3a1e2 Mon Sep 17 00:00:00 2001 From: girst Date: Fri, 13 Mar 2020 15:22:54 +0100 Subject: [PATCH] '.' implementation (ugly and not portable) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit uses ungetc(3) twice, which "works on my machine"™ --- README.md | 5 +++-- sol.c | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0b4b118..e12eb14 100644 --- a/README.md +++ b/README.md @@ -36,12 +36,11 @@ licensing details, see `LICENSE`. * TODO: cleanup: in `x2y()` functions there is a lot of replication and noise when calculating legal moves, top cards, etc. * TODO: clean up '/' and 'f' implementations + * TODO: change `.` implementation to use `CMD_AGAIN` ### P3 * TODO: some stuff in printed on stdout+fflush, some on stderr * TODO: visbell changes: instead of screen, flash active {cursor,card} {red,twice}? * TODO: differential drawing mode (at least for highlighting cards) - * TODO: `.` command (repeat last action) - read data fron undo-head? * TODO: `wait_mouse_up()` sometimes hangs in kde konsole (trash the `level++` and just return an error) ### P4 @@ -119,6 +118,8 @@ licensing details, see `LICENSE`. * DONE FREECELL: join() * DONE FREECELL: autodetect possible moves (card selector choice dialog) * DONE: f or / to search for rank or suit + * DONE: `.` command (repeat last action) + read data fron undo-head? ## Notes diff --git a/sol.c b/sol.c index 17b7525..88197b0 100644 --- a/sol.c +++ b/sol.c @@ -971,6 +971,7 @@ int get_cmd (int* from, int* to, int* opt) { unsigned char mouse[6] = {0}; /* must clear [3]! */ struct cursor inactive = {-1,-1}; static struct cursor active = {0,0}; + static char last_successful_action[2] = {0,0}; //TODO: dot implementation should be in main game loop (CMD_AGAIN) if (is_tableu(active.pile)) active.opt = 0; @@ -1038,6 +1039,10 @@ from_l: print_table(&active, &inactive); inactive.opt = *opt; /* prevents card selector dialog */ break; /* misc keys: */ + case '.': + ungetc(last_successful_action[1], stdin); + ungetc(last_successful_action[0], stdin); //XXX: 2nd ungetc() not portable! + goto from_l; case ':': {char buf[256]; fprintf (stderr, ":"); @@ -1124,6 +1129,8 @@ to_l: print_table(&active, &inactive); else *to = t-'1'; } + last_successful_action[0] = _f; + last_successful_action[1] = t; /***/ /* direct addressing post-processing stage: -- 2.39.3