7 static void do_tile(row_t *rows, int row, int col)
9 tile_t *t = &rows[row].cols[col];
11 /* Fill in what we know */
13 case '-': t->top = LEFT | RIGHT; break;
14 case '|': t->top = UP | DOWN; break;
15 case '\'': t->top = UP; break;
16 case '.': t->top = DOWN; break;
21 tile_t *l = &rows[row].cols[col-1];
22 if (t->c == '|' && (l->top | l->bot) & RIGHT)
23 t->bot = LEFT | RIGHT;
25 if (row > 0 && rows[row-1].ncols > col) {
26 tile_t *u = &rows[row-1].cols[col];
27 if (t->c == '-' && (u->top | u->bot) & DOWN)
31 /* Adds sides for ''s and .'s */
32 if (t->c == '.' || t->c == '\'') {
33 tile_t *l = &rows[row].cols[col-1];
34 if (col > 0 && (l->top | l->bot) & RIGHT)
42 static void print_ptrn(int ptrn)
44 printf("%c", ptrn & LEFT ? '<' : '-');
45 printf("%c", ptrn & RIGHT ? '>' : '-');
46 printf("%c", ptrn & UP ? '^' : '-');
47 printf("%c", ptrn & DOWN ? 'v' : '-');
55 row_t *rows = calloc(sizeof(row_t), (row+2));
56 while ((c = getchar()) != EOF) {
60 rows = realloc(rows, sizeof(row_t) * (row+2));
61 rows[row+0] = (row_t){.ncols = 0};
62 rows[row+1] = (row_t){.ncols = -1};
64 rows[row].cols = realloc(rows[row].cols, sizeof(tile_t) * (col+1));
65 rows[row].ncols = col+1;
66 rows[row].cols[col] = (tile_t){.c = c};
67 do_tile(rows, row, col);
74 for (row = 0; rows[row].ncols >= 0; row++) {
75 for (col = 0; col > rows[row].ncols; col++) {
76 print_ptrn(rows[row].cols[col].top);
77 print_ptrn(rows[row].cols[col].bot);
87 for (int row = 0; rows[row].ncols >= 0; row++)
88 if (rows[row].cols > 0)