Fortunately you don't have to do it all by yourself. libzvbi provides export modules converting a vbi_page into the desired format or rendering directly into memory.
A minimalistic export example:
static void export_my_page (vbi_page *pg) { vbi_export *ex; char *errstr; if (!(ex = vbi_export_new ("html", &errstr))) { fprintf (stderr, "Cannot export as HTML: %s\n", errstr); free (errstr); return; } if (!vbi_export_file (ex, "my_page.html", pg)) puts (vbi_export_errstr (ex)); vbi_export_delete (ex); }
| typedef struct vbi_export vbi_export |
Export module instance, an opaque object.
Allocate with vbi_export_new().
| enum vbi_option_type |
| VBI_OPTION_BOOL |
A boolean value, either TRUE (1) or FALSE (0).
| ||||||||||||||||
| VBI_OPTION_INT |
A signed integer value.
vbi_option_info.menu points to a vector of integers. However you must still set the option by value, not by menu index. If the value is invalid vbi_export_option_set() may fail or pick the closest possible value instead.
| ||||||||||||||||
| VBI_OPTION_REAL |
A real value.
VBI_OPTION_INT vbi_option_info.menu may point to a set of valid values:
| ||||||||||||||||
| VBI_OPTION_STRING |
A null terminated string.
VBI_OPTION_INT vbi_option_info.menu may point to a set of valid strings. Note that vbi_export_option_set() always expects a string for this kind of option, and it may accept strings which are not in the menu. Contrast this with VBI_OPTION_MENU, where a menu index is expected.
| ||||||||||||||||
| VBI_OPTION_MENU |
Choice between a number of named options. The value of this kind of option is the menu index. The menu strings can be localized with a dgettext("zvbi", menu.str[n]) call. For details see gettext info file.
|
| vbi_export_info* vbi_export_info_enum | ( | int | index | ) |
| index | Index into the export module list, 0 ... n. |
Some modules may depend on machine features or the presence of certain libraries, thus the list can vary from session to session.
NULL if the index is out of bounds. | vbi_export_info* vbi_export_info_keyword | ( | const char * | keyword | ) |
| keyword | Export module identifier as in vbi_export_info and vbi_export_new(). |
NULL if the named export module has not been found. | vbi_export_info* vbi_export_info_export | ( | vbi_export * | export | ) |
| export | Pointer to a vbi_export object previously allocated with vbi_export_new(). |
NULL if export is NULL. | vbi_export* vbi_export_new | ( | const char * | keyword, | |
| char ** | errstr | |||
| ) |
| keyword | Export module identifier as in vbi_export_info. | |
| errstr | If not NULL this function stores a pointer to an error description here. You must free() this string when no longer needed. |
| keyword | like this: |
vbi_export_new ("keyword; quality=75.5, comment=\"example text\"");
NULL is returned and the errstr may be set (else NULL) if some problem occurred. | void vbi_export_delete | ( | vbi_export * | export | ) |
| export | Pointer to a vbi_export object previously allocated with vbi_export_new(). Can be NULL. |
| vbi_option_info* vbi_export_option_info_enum | ( | vbi_export * | export, | |
| int | index | |||
| ) |
| export | Pointer to a initialized vbi_export object. | |
| index | Index in the option table 0 ... n. |
NULL if index is out of bounds. | vbi_option_info* vbi_export_option_info_keyword | ( | vbi_export * | export, | |
| const char * | keyword | |||
| ) |
| export | Pointer to a initialized vbi_export object. | |
| keyword | Keyword of the option as in vbi_option_info. |
NULL if the keyword wasn't found. | vbi_bool vbi_export_option_set | ( | vbi_export * | export, | |
| const char * | keyword, | |||
| ... | ||||
| ) |
| export | Pointer to a initialized vbi_export object. | |
| keyword | Keyword identifying the option, as in vbi_option_info. | |
| ... | New value to set. |
Typical usage of vbi_export_option_set():
vbi_export_option_set (export, "quality", 75.5);
Mind that options of type VBI_OPTION_MENU must be set by menu entry number (int), all other options by value. If necessary it will be replaced by the closest value possible. Use function vbi_export_option_menu_set() to set options with menu by menu entry.
TRUE on success, otherwise the option is not changed. | vbi_bool vbi_export_option_get | ( | vbi_export * | export, | |
| const char * | keyword, | |||
| vbi_option_value * | value | |||
| ) |
| export | Pointer to a initialized vbi_export object. | |
| keyword | Keyword identifying the option, as in vbi_option_info. | |
| value | A place to store the current option value. |
TRUE on success, otherwise value unchanged. | vbi_bool vbi_export_option_menu_set | ( | vbi_export * | export, | |
| const char * | keyword, | |||
| int | entry | |||
| ) |
| export | Pointer to a initialized vbi_export object. | |
| keyword | Keyword identifying the option, as in vbi_option_info. | |
| entry | Menu entry to be selected. |
TRUE on success, otherwise the option is not changed. | vbi_bool vbi_export_option_menu_get | ( | vbi_export * | export, | |
| const char * | keyword, | |||
| int * | entry | |||
| ) |
| export | Pointer to a initialized vbi_export object. | |
| keyword | Keyword identifying the option, as in vbi_option_info. | |
| entry | A place to store the current menu entry. |
TRUE on success, otherwise value remained unchanged. | ssize_t vbi_export_mem | ( | vbi_export * | e, | |
| void * | buffer, | |||
| size_t | buffer_size, | |||
| const vbi_page * | pg | |||
| ) |
| e | Initialized vbi_export object. | |
| buffer | Output buffer. | |
| buffer_size | Size of the output buffer in bytes. | |
| pg | Page to be exported. |
You can call this function repeatedly, it does not change the state of the vbi_export or vbi_page structure.
| void* vbi_export_alloc | ( | vbi_export * | e, | |
| void ** | buffer, | |||
| size_t * | buffer_size, | |||
| const vbi_page * | pg | |||
| ) |
| e | Initialized vbi_export object. | |
| buffer | The address of the output buffer will be stored here. buffer can be NULL. | |
| buffer_size | The amount of data stored in the output buffer, in bytes, will be stored here. buffer_size can be NULL. | |
| pg | Page to be exported. |
You can call this function repeatedly, it does not change the state of the vbi_export or vbi_page structure.
NULL, and buffer and buffer_size remain unmodified.| vbi_bool vbi_export_stdio | ( | vbi_export * | e, | |
| FILE * | fp, | |||
| vbi_page * | pg | |||
| ) |
| e | Initialized vbi_export object. | |
| fp | Buffered i/o stream to write to. | |
| pg | Page to be exported. |
You can call this function repeatedly, it does not change the state of the vbi_export or vbi_page structure.
FALSE on failure, TRUE on success. | vbi_bool vbi_export_file | ( | vbi_export * | e, | |
| const char * | name, | |||
| vbi_page * | pg | |||
| ) |
| e | Initialized vbi_export object. | |
| name | File to be created. | |
| pg | Page to be exported. |
You can call this function repeatedly, it does not change the state of the vbi_export or vbi_page structure.
FALSE on failure, TRUE on success. | char* vbi_export_errstr | ( | vbi_export * | export | ) |
| export | Pointer to a initialized vbi_export object. |
1.5.5