#include #include #include #define MAXN 80 static char map[MAXN][MAXN]; static unsigned rows, cols; #define SWAP(A, B) { unsigned t; t = A; A = B; B = t; } static void put (unsigned x, unsigned y, char c) { if (map[x][y] == ' ' || map[x][y] == c) map[x][y] = c; else if ((c == '|' || c == '-') && strchr ("-|+", map[x][y]) != NULL) map[x][y] = '+'; else if ((c == '/' || c == '\\') && strchr ("/\\x", map[x][y]) != NULL) map[x][y] = '+'; else map[x][y] = '*'; } static void out (void) { unsigned x, y; putchar ('+'); for (x = 0; x < cols; x++) putchar ('-'); puts ("+"); for (y = 0; y < rows; y++) { putchar ('|'); for (x = 0; x < cols; x++) putchar (map[x][y]); puts ("|"); } putchar ('+'); for (x = 0; x < cols; x++) putchar ('-'); puts ("+\n"); } int main (void) { for (;;) { scanf ("%u%u ", &cols, &rows); if (rows == 0 && cols == 0) break; memset (map, ' ', sizeof (map)); for (;;) { static char buf[10240], buf2[10240]; unsigned x, y, x2, y2; gets (buf); if (sscanf (buf, " POINT%u%u", &x, &y) == 2) put(x - 1, y - 1, 'o'); else if (sscanf (buf, " TEXT%u%u %s", &x, &y, buf2) == 3) { const char *p; x -= 1; y -= 1; for (p = buf2; *p != 0; p++) { put (x, y, *p); x++; if (x == cols) break; } } else if (sscanf (buf, " LINE%u%u%u%u", &x, &y, &x2, &y2) == 4) { if (x == x2) { x--; if (y > y2) SWAP (y, y2); y--; while (y < y2) { put (x, y, '|'); y++; } } else if (y == y2) { y--; if (x > x2) SWAP (x, x2); x--; while (x < x2) { put (x, y, '-'); x++; } } else if (x2 - x == y2 - y) { if (x > x2) { SWAP (x, x2); SWAP (y, y2); } x--; y--; while (x < x2) { put (x, y, '\\'); x++; y++; } } else if (x2 - x == y - y2) { if (x > x2) { SWAP (x, x2); SWAP (y, y2); } x--; y--; while (x < x2) { put (x, y, '/'); x++; y--; } } else abort (); } else if (sscanf (buf, " CLEAR%u%u%u%u", &x, &y, &x2, &y2) == 4) { if (x > x2) SWAP (x, x2); if (y > y2) SWAP (y, y2); x--; y--; while (x < x2) { unsigned i; for (i = y; i < y2; i++) map[x][i] = ' '; x++; } } else if (strstr (buf, "PRINT") != 0) break; else abort (); } out (); } return EXIT_SUCCESS; }