]>
git.gir.st - ttxd.git/blob - src/vtx2ascii-src/fileio.c
2 * fileio.c: Read font-bitmaps, write GIF-, PPM-, ASCII- & VTX-files
4 * $Id: fileio.c,v 1.5 1997/08/14 22:59:42 mb Exp mb $
6 * Copyright (c) 1995-96 Martin Buck <martin-2.buck@student.uni-ulm.de>
7 * Read COPYING for more information
18 #include "vtx_assert.h"
19 #include "vtxdecode.h"
24 #define VTXFONT_EXT ".vtxfont"
25 typedef enum { FP_ARG
, FP_ENV
, FP_DEFAULT
} fp_src_t
;
31 static const int vtx_img_red
[8] = { 0, 255, 0, 255, 0, 255, 0, 255 };
32 static const int vtx_img_green
[8] = { 0, 0, 255, 255, 0, 0, 255, 255 };
33 static const int vtx_img_blue
[8] = { 0, 0, 0, 0, 255, 255, 255, 255 };
35 static const vtxpage_t
*vtxpage
;
36 static const vtxbmfont_t
*vtxfont
;
42 export_ascii(FILE *file
, const vtxpage_t
*page
, int show_hidden
) {
45 for (pos
= 0; pos
< VTX_PAGESIZE
; pos
++) {
46 if (!(page
->attrib
[pos
] & VTX_HIDDEN
) || show_hidden
) {
47 fputc(vtx2iso_table
[page
->chr
[pos
]], file
);
58 save_vtx(FILE *file
, const byte_t
*buffer
, const vtx_pageinfo_t
*info
, int virtual) {
60 fputc(info
->pagenum
& 0xff, file
);
61 fputc(info
->pagenum
/ 0x100, file
);
62 fputc(info
->hour
& 0xff, file
);
63 fputc(info
->minute
& 0xff, file
);
64 fputc(info
->charset
& 0xff, file
);
65 fputc(info
->delete << 7 | info
->headline
<< 6 | info
->subtitle
<< 5 | info
->supp_header
<< 4 |
66 info
->update
<< 3 | info
->inter_seq
<< 2 | info
->dis_disp
<< 1 | info
->serial
<< 0, file
);
67 fputc(info
->notfound
<< 7 | info
->pblf
<< 6 | info
->hamming
<< 5 | (!!virtual) << 4 |
69 fwrite(buffer
, 1, virtual ? VTX_VIRTUALSIZE
: VTX_PAGESIZE
, file
);
74 load_vtx(FILE *file
, byte_t
*buffer
, vtx_pageinfo_t
*info
, int *virtual) {
75 byte_t tmp_buffer
[VTX_VIRTUALSIZE
];
76 vtx_pageinfo_t tmp_inf
;
77 unsigned char tmpstr
[256];
79 int pos
, tmpbits
, is_virtual
= FALSE
, is_sevenbit
= FALSE
;
81 memset(tmp_buffer
, ' ', sizeof(tmp_buffer
));
82 if (fscanf(file
, "VTXV%c", tmpstr
) != 1) {
83 if (fstat(fileno(file
), &st
) < 0) {
85 /* The stupid INtv format doesn't use a signature, so we have to use the file-length instead */
86 } else if (st
.st_size
!= 1008) {
89 memset(&tmp_inf
, 0, sizeof(tmp_inf
)); /* Read ITV-file */
91 for (pos
= 0; pos
<= 23; pos
++) {
92 fseek(file
, 2, SEEK_CUR
);
93 fread(tmp_buffer
+ pos
* 40, 40, 1, file
);
95 /* The first 8 bytes in the INtv-format usually contain garbage (or data I don't understand) */
96 memset(tmp_buffer
, vtx_mkparity(' '), 8 * sizeof(byte_t
));
97 for (pos
= 0; pos
<= 2; pos
++) {
98 tmpstr
[pos
] = tmp_buffer
[8 + pos
];
99 vtx_chkparity(&tmpstr
[pos
]);
102 sscanf(tmpstr
, "%3x", &tmp_inf
.pagenum
);
103 if (!vtx_chkpgnum(tmp_inf
.pagenum
, TRUE
)) {
110 if (tmpstr
[0] != '2' && tmpstr
[0] != '3' && tmpstr
[0] != '4') {
113 tmp_inf
.pagenum
= fgetc(file
) + 0x100 * fgetc(file
); /* Read VTX-file */
114 tmp_inf
.hour
= fgetc(file
);
115 tmp_inf
.minute
= fgetc(file
);
116 tmp_inf
.charset
= fgetc(file
);
117 tmpbits
= fgetc(file
);
118 tmp_inf
.delete = !!(tmpbits
& 0x80);
119 tmp_inf
.headline
= !!(tmpbits
& 0x40);
120 tmp_inf
.subtitle
= !!(tmpbits
& 0x20);
121 tmp_inf
.supp_header
= !!(tmpbits
& 0x10);
122 tmp_inf
.update
= !!(tmpbits
& 8);
123 tmp_inf
.inter_seq
= !!(tmpbits
& 4);
124 tmp_inf
.dis_disp
= !!(tmpbits
& 2);
125 tmp_inf
.serial
= (tmpbits
& 1);
126 tmpbits
= fgetc(file
);
127 tmp_inf
.notfound
= !!(tmpbits
& 0x80);
128 tmp_inf
.pblf
= !!(tmpbits
& 0x40);
129 tmp_inf
.hamming
= !!(tmpbits
& 0x20);
130 if (tmpstr
[0] == '3') {
132 } else if (tmpstr
[0] == '4') {
133 is_virtual
= !!(tmpbits
& 0x10);
134 is_sevenbit
= !!(tmpbits
& 8);
136 fread(tmp_buffer
, is_virtual
? VTX_VIRTUALSIZE
: VTX_PAGESIZE
, 1, file
);
138 *virtual = is_virtual
;
148 /* If file was saved in seven-bit mode, fake parity bit.
149 * FIXME: Should we add parity to the virtual part too?
152 for (pos
= 0; pos
< VTX_PAGESIZE
; pos
++) {
153 tmp_buffer
[pos
] = vtx_mkparity(tmp_buffer
[pos
]);
156 memcpy(buffer
, tmp_buffer
, is_virtual
? VTX_VIRTUALSIZE
: VTX_PAGESIZE
);
157 memset(buffer
, vtx_mkparity(7), 8);