aboutsummaryrefslogtreecommitdiff
path: root/signpost.c
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2011-09-18 07:43:18 +0000
committerSimon Tatham <anakin@pobox.com>2011-09-18 07:43:18 +0000
commit7f8919952ff61e69f264082f06d4b2698cc1dedd (patch)
tree12b48e362152166382f20093093745d9680f9d7e /signpost.c
parent73daff393722196bf48244ca95dd4f64a351a473 (diff)
downloadpuzzles-7f8919952ff61e69f264082f06d4b2698cc1dedd.zip
puzzles-7f8919952ff61e69f264082f06d4b2698cc1dedd.tar.gz
puzzles-7f8919952ff61e69f264082f06d4b2698cc1dedd.tar.bz2
puzzles-7f8919952ff61e69f264082f06d4b2698cc1dedd.tar.xz
Patch from Chris Boyle to fix Signpost's labelling when you have more
than 26 separate linked chains of unnumbered squares: we now wrap from 'z' to an Excel-like 'aa', 'ab', ..., instead of falling off z into punctuation and control characters. [originally from svn r9304]
Diffstat (limited to 'signpost.c')
-rw-r--r--signpost.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/signpost.c b/signpost.c
index 3f2a645..6b16ff7 100644
--- a/signpost.c
+++ b/signpost.c
@@ -1930,19 +1930,30 @@ static void tile_redraw(drawing *dr, game_drawstate *ds, int tx, int ty,
if (!empty) {
int set = (num <= 0) ? 0 : num / (ds->n+1);
+ char *p = buf;
if (set == 0 || num <= 0) {
sprintf(buf, "%d", num);
} else {
int n = num % (ds->n+1);
+ p += sizeof(buf) - 1;
- if (n == 0)
- sprintf(buf, "%c", (int)(set+'a'-1));
- else
- sprintf(buf, "%c+%d", (int)(set+'a'-1), n);
+ if (n != 0) {
+ sprintf(buf, "+%d", n); /* Just to get the length... */
+ p -= strlen(buf);
+ sprintf(p, "+%d", n);
+ } else {
+ *p = '\0';
+ }
+ do {
+ set--;
+ p--;
+ *p = (char)((set % 26)+'a');
+ set /= 26;
+ } while (set);
}
- textsz = min(2*asz, (TILE_SIZE - 2 * cb) / (int)strlen(buf));
+ textsz = min(2*asz, (TILE_SIZE - 2 * cb) / (int)strlen(p));
draw_text(dr, tx + cb, ty + TILE_SIZE/4, FONT_VARIABLE, textsz,
- ALIGN_VCENTRE | ALIGN_HLEFT, textcol, buf);
+ ALIGN_VCENTRE | ALIGN_HLEFT, textcol, p);
}
if (print_ink < 0) {