From ca4af600fdad77b3c4603a62c81eee51187fafcf Mon Sep 17 00:00:00 2001 From: rodri Date: Fri, 25 Aug 2023 21:53:17 +0000 Subject: implemented most of the layout code. added a new util.c to host the cell/coordinate conversions. made the showproc a painter thread instead, to avoid problems with menuhit(2). --- util.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 util.c (limited to 'util.c') diff --git a/util.c b/util.c new file mode 100644 index 0000000..4594a9a --- /dev/null +++ b/util.c @@ -0,0 +1,42 @@ +#include +#include +#include +#include +#include +#include +#include +#include "dat.h" +#include "fns.h" + +static char rowtab[] = "abcdefghijklmnopq"; + + +char * +cell2coords(Point2 cell) +{ + static char s[3+1]; + + assert(cell.x < 17 && cell.x >= 0 + && cell.y < 17 && cell.y >= 0); + + snprint(s, sizeof s, "%c%d", rowtab[(int)cell.y], (int)cell.x); + return s; +} + +Point2 +coords2cell(char *s) +{ + Point2 cell; + char *p; + + assert(s[0] >= 'a' && s[0] <= 'q'); + + cell = Pt2(0,0,1); + p = strchr(rowtab, s[0]); + cell.y = p-rowtab; + cell.x = strtol(s+1, nil, 10); + + assert(cell.x < 17 && cell.x >= 0); + + return cell; +} -- cgit v1.2.3