]>
git.gir.st - ttxd.git/blob - src/vtx2ascii-src/main.c
10 unsigned char buffer
[65536];
19 export_ansi_ascii(FILE *file
, const vtxpage_t
*page
, int show_hidden
)
22 int bg
,fg
,lbg
,lfg
,hidden
;
25 for (pos
= 0; pos
< VTX_PAGESIZE
; pos
++) {
26 fg
= page
->attrib
[pos
] & VTX_COLMASK
;
27 bg
= (page
->attrib
[pos
] & VTX_BGMASK
) >> 3;
28 hidden
= (page
->attrib
[pos
] & VTX_HIDDEN
) && !show_hidden
;
29 if (fg
!= lfg
|| bg
!= lbg
) {
30 fprintf(file
,"\033[%d;%dm",fg
+30,bg
+40);
34 fputc(hidden
? ' ' : vtx2iso_table
[page
->chr
[pos
]], file
);
37 fprintf(file
,"\033[0m\n");
43 export_html(FILE *file
, const vtxpage_t
*page
, int show_hidden
)
45 static const char *color
[] = {
46 "black", "red", "green", "yellow",
47 "blue", "magenta", "cyan", "white"
51 int bg
,fg
,lbg
,lfg
,hidden
;
54 /* scan for used colors */
55 memset(used
,0,sizeof(used
));
56 for (pos
= 0; pos
< VTX_PAGESIZE
; pos
++) {
57 fg
= page
->attrib
[pos
] & VTX_COLMASK
;
58 bg
= (page
->attrib
[pos
] & VTX_BGMASK
) >> 3;
63 fprintf(file
,"<style type=\"text/css\"> <!--\n");
64 for (bg
= 0; bg
< 8; bg
++) {
65 for (fg
= 0; fg
< 8; fg
++) {
67 fprintf(file
,"font.c%d { color: %s; background-color: %s }\n",
68 fg
*8+bg
,color
[fg
],color
[bg
]);
72 fprintf(file
,"//--> </style>\n");
75 fprintf(file
,"<pre>\n");
77 for (pos
= 0; pos
< VTX_PAGESIZE
; pos
++) {
78 fg
= page
->attrib
[pos
] & VTX_COLMASK
;
79 bg
= (page
->attrib
[pos
] & VTX_BGMASK
) >> 3;
80 hidden
= (page
->attrib
[pos
] & VTX_HIDDEN
) && !show_hidden
;
81 if (fg
!= lfg
|| bg
!= lbg
) {
82 if (lfg
!= -1 || lbg
!= -1)
83 fprintf(file
,"</font>");
84 fprintf(file
,"<font class=c%d>",fg
*8+bg
);
88 fputc(hidden
? ' ' : vtx2iso_table
[page
->chr
[pos
]], file
);
91 fprintf(file
,"</font>\n");
94 fprintf(file
,"</pre>\n");
100 fprintf(stderr
,"usage: %s [ options ] vtx-file\n",prog
);
103 " -a dump plain ascii (default)\n"
104 " -c dump colored ascii (using ansi control sequences).\n"
110 main(int argc
, char *argv
[])
114 int c
,output
=OUT_ASCII
;
116 if (NULL
!= (prog
= strrchr(argv
[0],'/')))
122 if (-1 == (c
= getopt(argc
, argv
, "ach")))
138 if (optind
+1 != argc
)
141 if (NULL
== (fp
= fopen(argv
[optind
],"r"))) {
142 fprintf(stderr
,"%s: %s: %s\n",prog
,argv
[optind
],strerror(errno
));
146 load_vtx(fp
, buffer
, &page
.info
, &virtual);
147 decode_page(buffer
, &page
, 0, 23);
150 export_ascii(stdout
, &page
, 0);
153 export_ansi_ascii(stdout
, &page
, 0);
156 export_html(stdout
, &page
, 0);