7 static void do_tile(row_t *rows, int row, int col)
9 tile_t *t = &rows[row ].cols[col ];
10 tile_t *l = &rows[row ].cols[col-1];
11 tile_t *u = &rows[row-1].cols[col ];
13 /* Fill in what we know */
15 case '-': t->top = LEFT | RIGHT; break;
16 case '|': t->top = UP | DOWN; break;
17 case '\'': t->top = UP; break;
18 case '.': t->top = DOWN; break;
22 if (t->c == '|' && (l->top | l->bot) & RIGHT)
23 t->bot = LEFT | RIGHT;
24 if (rows[row-1].ncols >= col)
25 if (t->c == '-' && (u->top | u->bot) & DOWN)
28 /* Adds sides for ''s and .'s */
29 if (t->c == '.' || t->c == '\'') {
30 if ((l->top | l->bot) & RIGHT)
38 static void print_ptrn(int ptrn)
40 printf("%c", ptrn & LEFT ? '<' : '-');
41 printf("%c", ptrn & RIGHT ? '>' : '-');
42 printf("%c", ptrn & UP ? '^' : '-');
43 printf("%c", ptrn & DOWN ? 'v' : '-');
51 row_t *rows = calloc(sizeof(row_t), (row+2));
52 while ((c = getchar()) != EOF) {
56 rows = realloc(rows, sizeof(row_t) * (row+2));
57 rows[row+1] = (row_t){};
59 rows[row].cols = realloc(rows[row].cols, sizeof(tile_t) * (col+1));
60 rows[row].ncols = col+1;
61 rows[row].cols[col] = (tile_t){};
62 rows[row].cols[col].c = c;
63 do_tile(rows, row, col);
69 //for (row = 1; row < 63; row++) {
70 // for (col = 1; col < 511; col++) {
71 // print_ptrn(tiles[row][col].top);
72 // print_ptrn(tiles[row][col].bot);