File: exp-vtx.c

package info (click to toggle)
zapping 0.10~cvs6-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 9,856 kB
  • ctags: 11,841
  • sloc: ansic: 111,154; asm: 11,770; sh: 9,812; xml: 2,742; makefile: 1,283; perl: 488
file content (151 lines) | stat: -rw-r--r-- 3,837 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
 *  libzvbi - VTX export function
 *
 *  Copyright (C) 2001, 2002, 2003, 2004 Michael H. Schimek
 *
 *  Based on code from AleVT 1.5.1
 *  Copyright (C) 1998, 1999 Edgar Toernig <froese@gmx.de>
 *  Copyright (C) 1999 Paul Ortyl <ortylp@from.pl>
 *
 *  Based on code from VideoteXt 0.6
 *  Copyright (C) 1995, 1996, 1997 Martin Buck
 *    <martin-2.buck@student.uni-ulm.de>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/* $Id: exp-vtx.c,v 1.15 2005/09/01 01:40:52 mschimek Exp $ */

/* VTX is the file format used by the VideoteXt application. It stores
   Teletext pages in raw level 1.0 format. Level 1.5 additional characters
   (e.g. accents), the FLOF and TOP navigation bars and the level 2.5
   chrome will be lost.
 
   Since restoring the raw page from a fmt_page is complicated if not
   impossible, we violate encapsulation by fetching a raw copy from
   the cache. :-( */

#ifdef HAVE_CONFIG_H
#  include "config.h"
#endif

#include <assert.h>
#include <inttypes.h>

#include "hamm.h"		/* vbi3_rev8() */
#include "cache-priv.h"		/* cache_page */
#include "page-priv.h"		/* vbi3_page_priv */
#ifdef ZAPPING8
#  include "common/intl-priv.h"
#else
#  include "intl-priv.h"
#endif
#include "export-priv.h"

struct header {
	uint8_t			signature[5];
	uint8_t			pagenum_l;
	uint8_t			pagenum_h;
	uint8_t			hour;
	uint8_t			minute;
	uint8_t			charset;
	uint8_t			wst_flags;
	uint8_t			vtx_flags;
};

/*
 *  VTX - VideoteXt File (VTXV4)
 */

static vbi3_bool
export				(vbi3_export *		e,
				 const vbi3_page *	pg)
{
	const vbi3_page_priv *pgp;
	const cache_page *cp;
	struct header h;

	if (pg->pgno < 0x100 || pg->pgno > 0x8FF) {
		_vbi3_export_error_printf
			(e, _("Can only export Teletext pages."));
		return FALSE;
	}

	pgp = CONST_PARENT (pg, vbi3_page_priv, pg);

	if (pg->priv != pgp || !pgp->cp) {
		_vbi3_export_error_printf (e, _("Page is not cached."));
		return FALSE;
	}

	cp = pgp->cp;

	if (cp->function != PAGE_FUNCTION_UNKNOWN
	    && cp->function != PAGE_FUNCTION_LOP) {
		_vbi3_export_error_printf
			(e, _("Cannot export this page, is not displayable."));
		goto error;
	}

	memcpy (h.signature, "VTXV4", 5);

	h.pagenum_l = cp->pgno & 0xFF;
	h.pagenum_h = (cp->pgno >> 8) & 15;

	h.hour = 0;
	h.minute = 0;

	h.charset = cp->national & 7;

	h.wst_flags = cp->flags & C4_ERASE_PAGE;
	h.wst_flags |= vbi3_rev8 (cp->flags >> 12);
	h.vtx_flags = (0 << 7) | (0 << 6) | (0 << 5) | (0 << 4) | (0 << 3);
	/* notfound, pblf (?), hamming error, virtual, seven bits */

	if (fwrite (&h, sizeof (h), 1, e->fp) != 1)
		goto write_error;

	if (fwrite (cp->data.lop.raw, 40 * 24, 1, e->fp) != 1)
		goto write_error;

	return TRUE;

 write_error:
	_vbi3_export_write_error (e);

 error:
	return FALSE;
}

static const vbi3_export_info
export_info = {
	.keyword		= "vtx",
	.label			= N_("VTX"),
	.tooltip		= N_("Export this page as VTX file, the "
				     "format used by VideoteXt and vbidecode"),

	/* From VideoteXt examples/mime.types */
	.mime_type		= "application/videotext",
	.extension		= "vtx",
};

const _vbi3_export_module
_vbi3_export_module_vtx = {
	.export_info		= &export_info,

	/* no private data, no options */

	.export			= export
};