#include <dk.h>
#include <dktypes.h>
Go to the source code of this file.
Functions | |
dk_le_t * | dkle_open (char *d) |
Create encoding structure. | |
int | dkle_load (dk_le_t *l, dk_udword c) |
Attempt to load table for character c from file (if not yet loaded). | |
char * | dkle_get_encoding (dk_le_t *l, dk_udword c, int m) |
Get encoding for character (LaTeX sequence). | |
int | dkle_get_error_code (dk_le_t *l, int r) |
Retrieve (and optionally reset) the error code for the last error occured in the encoding structure. | |
char * | dkle_get_filename (dk_le_t *l) |
Retrieve file name in which the last error occured. | |
unsigned long | dkle_get_error_lineno (dk_le_t *l) |
Retrieve line number in which the last error occured. | |
size_t | dkle_length_plain_to_latex (dk_le_t *l, char *s) |
Find necessary result buffer length to convert plain text string into LaTeX sequence. | |
int | dkle_put_plain_to_latex (dk_le_t *l, char *d, size_t s, char *p) |
Convert plain text string into LaTeX sequence. | |
size_t | dkle_length_utf8_to_latex (dk_le_t *l, char *u) |
Find necessary result buffer length to convert UTF-8 encoded text string into LaTeX sequence. | |
int | dkle_put_utf8_to_latex (dk_le_t *l, char *d, size_t s, char *u) |
Convert UTF-8 encoded text string into LaTeX sequence. | |
void | dkle_close (dk_le_t *l) |
Destroy encoding structure obtained from dkle_open() and release the memory. |
Encoding changes for use with LaTeX Example: Read text file (not UTF-8 encoded) and convert to LaTeX.
A dk_le_t structure is needed for the conversions, this structure can be created using dkle_open(). After usage release the memory by calling dkle_close(). Conversion tables can be loaded using the dkle_load() function. The dkle_get_encoding() function can be used to get a string containing the LaTeX sequence for a character.
Unless otherwise stated, int functions in this module return a positive number to indicate success or a true condition, 0 to indicate an error or an unfullfilled condition. Pointer functions return valid pointers on success, NULL on error.
See "dklibs - LaTeX encodings" for details about encoding table files.
#include <dk.h> #include <dkle.h> #include <dkapp.h> char ib[1024]; char dn[1024]; char ob[8192]; dk_app_t *a; dk_le_t *le; a = dkapp_open_ext1(argc, argv, "tests", "/etc", f_s, DK_APP_LOG_NO_STDOUT); if(a) { if(dkapp_transform_string_ext1(a, dn, sizeof(dn), "$(shared.dir)/uc2lat-t")) { le = dkle_open(dn); if(le) { while(fgets(ib, sizeof(ib), stdin)) { if(dkle_put_plain_to_latex(le, ob, sizeof(ob), ib)) { fputs(ob, stdout); } } dkle_close(le); } } dkapp_close(a); }
Example: Read UTF-8 encoded file, convert to LaTeX.
#include <dk.h> #include <dkle.h> #include <dkapp.h> char ib[1024]; char dn[1024]; char ob[8192]; dk_app_t *a; dk_le_t *le; a = dkapp_open_ext1(argc, argv, "tests", "/etc", f_s, DK_APP_LOG_NO_STDOUT); if(a) { if(dkapp_transform_string_ext1(a, dn, sizeof(dn), "$(shared.dir)/uc2lat-t")) { le = dkle_open(dn); if(le) { while(fgets(ib, sizeof(ib), stdin)) { if(dkle_put_utf8_to_latex(le, ob, sizeof(ob), ib)) { fputs(ob, stdout); } } dkle_close(le); } } dkapp_close(a); }
void dkle_close | ( | dk_le_t * | l | ) |
Destroy encoding structure obtained from dkle_open() and release the memory.
l | Pointer to encoding structure. |
Get encoding for character (LaTeX sequence).
l | Pointer to encoding structure. | |
c | 32 bit character to convert. | |
m | Flag to indicate math mode (1) or text mode (0). |
int dkle_get_error_code | ( | dk_le_t * | l, | |
int | r | |||
) |
Retrieve (and optionally reset) the error code for the last error occured in the encoding structure.
l | Pointer to encoding structure. | |
r | Flag to reset error code. |
unsigned long dkle_get_error_lineno | ( | dk_le_t * | l | ) |
Retrieve line number in which the last error occured.
l | Pointer to encoding structure. |
char* dkle_get_filename | ( | dk_le_t * | l | ) |
Retrieve file name in which the last error occured.
l | Pointer to encoding structure. |
size_t dkle_length_plain_to_latex | ( | dk_le_t * | l, | |
char * | s | |||
) |
Find necessary result buffer length to convert plain text string into LaTeX sequence.
l | Pointer to encoding structure. | |
s | Plain text string. |
size_t dkle_length_utf8_to_latex | ( | dk_le_t * | l, | |
char * | u | |||
) |
Find necessary result buffer length to convert UTF-8 encoded text string into LaTeX sequence.
l | Pointer to encoding structure. | |
u | UTF-8 encoded text string. |
Attempt to load table for character c from file (if not yet loaded).
l | Pointer to encoding structure. | |
c | The 32 bit character to convert. |
dk_le_t* dkle_open | ( | char * | d | ) |
Create encoding structure.
The encoding structure is created in dynamically allocated memory. Use dkle_open() to destory the structure and release the memory when the structure is no longer needed.
d | A base directory containing the data files. |
int dkle_put_plain_to_latex | ( | dk_le_t * | l, | |
char * | d, | |||
size_t | s, | |||
char * | p | |||
) |
Convert plain text string into LaTeX sequence.
l | Pointer to encoding structure. | |
d | Destination buffer to store result. | |
s | Length of d in bytes. | |
p | Plaint text string. |
int dkle_put_utf8_to_latex | ( | dk_le_t * | l, | |
char * | d, | |||
size_t | s, | |||
char * | u | |||
) |
Convert UTF-8 encoded text string into LaTeX sequence.
l | Pointer to encoding structure. | |
d | Destination buffer to store result. | |
s | Length of d in bytes. | |
u | UTF-8 encoded text string. |