Merge pull request #13 from rdebath/patch-fixes
[congif.git] / dump.c
blob1f62b1420e79c85e28319c4befa7b8a952fd9b1a
1 #include <stdint.h>
2 #include <unistd.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
7 #include "term.h"
9 void
10 dump_txt(Term *term, const char *fname)
12 int i, j, fd;
13 uint16_t code;
14 char ch;
16 fd = creat(fname, 0666);
17 if (fd == -1)
18 return;
19 for (i = 0; i < term->rows; i++) {
20 for (j = 0; j < term->cols; j++) {
21 code = term->addr[i][j].code;
22 if (code >= 0x20 && code < 0x7F)
23 ch = (char) code;
24 else
25 ch = 0x20;
26 write(fd, &ch, 1);
28 write(fd, "\n", 1);
30 close(fd);