diff options
Diffstat (limited to 'support/dktools/dk4uc2l.h')
-rw-r--r-- | support/dktools/dk4uc2l.h | 408 |
1 files changed, 279 insertions, 129 deletions
diff --git a/support/dktools/dk4uc2l.h b/support/dktools/dk4uc2l.h index 501acc8072..6e065098a5 100644 --- a/support/dktools/dk4uc2l.h +++ b/support/dktools/dk4uc2l.h @@ -1,36 +1,14 @@ /* - WARNING: This file was generated by dkct. - Changes you make here will be lost if dkct is run again! - You should modify the original source and run dkct on it. - Original source: dk4uc2l.ctr +Copyright (C) 2015-2020, Dirk Krause +SPDX-License-Identifier: BSD-3-Clause */ /* -Copyright (C) 2015-2017, Dirk Krause - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above opyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. -* Neither the name of the author nor the names of contributors may be used - to endorse or promote products derived from this software without specific - prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. -IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + WARNING: This file was generated by the dkct program (see + http://dktools.sourceforge.net/ for details). + Changes you make here will be lost if dkct is run again! + You should modify the original source and run dkct on it. + Original source: dk4uc2l.ctr */ #ifndef DK4UC2L_H_INCLUDED @@ -49,93 +27,141 @@ LaTeX sequences. After finishing output you can write recommendations (i.e. LaTeX packages to include, font encoding to use) as comments to the file. + +The functions in this module use a dk4_er_t structure to report errors +to the calling function as good as possible. +The functions from the dk4uc2la module use a dk4_app_t structure to +report errors immediately. + +Functions from the dk4uc2la and dk4uc2l module can be used combined. +A typical scenario is to use the dk4uc2l_open_app_ex1() function with la +set to 1 to open a conversion structure. This will read all the data files +and store all contained LaTeX encodings in memory when opening the structure. +Errors - i.e. failed memory allocations or syntax error in data files - are +reported immediately. +Later the dk4uc2l_find() function can be used. As problematic errors like +failed memory allocations are already reported, a NULL return value can +only indicate a missing encoding. */ -#ifndef DK4ERROR_H_INCLUDED -#include "dk4app.h" +#ifndef DK4CONF_H_INCLUDED +#if DK4_BUILDING_DKTOOLS4 +#include "dk4conf.h" +#else +#include <dktools-4/dk4conf.h> +#endif +#endif + +#ifndef DK4ERROR_H_INCLUDED +#if DK4_BUILDING_DKTOOLS4 +#include "dk4error.h" +#else +#include <dktools-4/dk4error.h> +#endif #endif #ifndef DK4STO_H_INCLUDED +#if DK4_BUILDING_DKTOOLS4 #include "dk4sto.h" +#else +#include <dktools-4/dk4sto.h> +#endif +#endif + +#ifndef DK4STRM_H_INCLUDED +#if DK4_BUILDING_DKTOOLS4 +#include "dk4strm.h" +#else +#include <dktools-4/dk4strm.h> +#endif #endif /** Information about a package. */ typedef struct { - char *pn; /**< Package name. */ - unsigned char used; /**< Flag: Package used. */ + char *pn; /**< Package name. */ + unsigned char used; /**< Flag: Package used. */ } dk4_uc2l_pkg_t; +/** Pointer to a package or an array of packages. +*/ +typedef dk4_uc2l_pkg_t *dk4_uc2l_pkg_p; + +/** Pointer to an array of package pointers. +*/ +typedef dk4_uc2l_pkg_p *dk4_uc2l_pkg_pp; + /** Data for contents of one file. The structure contains information about the character ranges covered by the file. */ typedef struct { - dkChar *fn; /**< Short file name. */ - unsigned char loaded; /**< Flag: File loaded. */ + dkChar *fn; /**< Short file name. */ + unsigned char loaded; /**< Flag: File loaded. */ } dk4_uc2l_file_t; /** Range of characters. */ typedef struct { - dk4_uc2l_file_t *file; /**< File containing data. */ - char **both; /**< LaTeX text both modes. */ - char **text; /**< LaTeX text text mode. */ - char **math; /**< LaTeX text math mode. */ - dk4_uc2l_pkg_t ***pkgs; /**< Packages for characters. */ - unsigned char *fenc; /**< Required font encodings. */ - dk4_c32_t start; /**< First character of range. */ - dk4_c32_t end; /**< Final character of range. */ - unsigned char ia; /**< Flag: Initialisation att. */ + dk4_uc2l_file_t *file; /**< File containing data. */ + char **both; /**< LaTeX text both modes. */ + char **text; /**< LaTeX text text mode. */ + char **math; /**< LaTeX text math mode. */ + dk4_uc2l_pkg_t ***pkgs; /**< Packages for characters. */ + unsigned char *fenc; /**< Required font encodings. */ + dk4_um_t *lno; /**< Line numbers. */ + dk4_c32_t start; /**< First character of range. */ + dk4_c32_t end; /**< Final character of range. */ + unsigned char ia; /**< Flag: Initialisation att. */ } dk4_uc2l_range_t; /** Text to LaTeX conversion structure. */ typedef struct { - char buf[16]; /**< Buffer for direct output. */ - const dkChar * const *msgs; /**< Localized messages */ - dkChar *dname; /**< Directory name. */ - dk4_sto_t *s_ranges; /**< Ranges container. */ - dk4_sto_it_t *i_ranges; /**< Ranges container iterator. */ - dk4_sto_t *s_files; /**< Files container. */ - dk4_sto_it_t *i_files; /**< Files container iterator. */ - dk4_sto_t *s_pkgs; /**< Package information container. */ - dk4_sto_it_t *i_pkgs; /**< Package information iterator. */ - size_t szmsgs; /**< Number of messages in msgs. */ - int had_error; /**< Flag: Errors occured. */ - unsigned char utf8allowed; /**< Flag: UTF-8 output allowed. */ - unsigned char fallowed; /**< Allowed font encodings. */ + char buf[16]; /**< Buffer for direct output. */ + dkChar *dname; /**< Directory name. */ + dk4_sto_t *s_ranges; /**< Ranges container. */ + dk4_sto_it_t *i_ranges; /**< Ranges container iterator. */ + dk4_sto_t *s_files; /**< Files container. */ + dk4_sto_it_t *i_files; /**< Files container iterator. */ + dk4_sto_t *s_pkgs; /**< Package information container. */ + dk4_sto_it_t *i_pkgs; /**< Package information iterator. */ + int had_error; /**< Flag: Errors occured. */ + unsigned char utf8allowed; /**< Flag: UTF-8 output allowed. */ + unsigned char fallowed; /**< Allowed font encodings. */ } dk4_uc2l_t; /** Font encodings */ enum { - /** OT1 font encoding. - */ - DK4_UC2L_FONT_ENCODING_OT1 = 1 , - - /** T1 font encoding. - */ - DK4_UC2L_FONT_ENCODING_T1 = 2 , - - /** T4 font encoding. - */ - DK4_UC2L_FONT_ENCODING_T4 = 4 , - - /** T5 font encoding. - */ - DK4_UC2L_FONT_ENCODING_T5 = 8 , - - DK4_UC2L_FONT_ENCODING_ALL = ( - 0 - | DK4_UC2L_FONT_ENCODING_OT1 - | DK4_UC2L_FONT_ENCODING_T1 - | DK4_UC2L_FONT_ENCODING_T4 - | DK4_UC2L_FONT_ENCODING_T5 - ) + /** OT1 font encoding. + */ + DK4_UC2L_FONT_ENCODING_OT1 = 1 , + + /** T1 font encoding. + */ + DK4_UC2L_FONT_ENCODING_T1 = 2 , + + /** T4 font encoding. + */ + DK4_UC2L_FONT_ENCODING_T4 = 4 , + + /** T5 font encoding. + */ + DK4_UC2L_FONT_ENCODING_T5 = 8 , + + /** All encodings mentioned above. + */ + DK4_UC2L_FONT_ENCODING_ALL = ( + 0 + | DK4_UC2L_FONT_ENCODING_OT1 + | DK4_UC2L_FONT_ENCODING_T1 + | DK4_UC2L_FONT_ENCODING_T4 + | DK4_UC2L_FONT_ENCODING_T5 + ) }; @@ -144,25 +170,25 @@ enum { */ enum { - /** Memory allocation failed. - */ - DK4_UC2L_ERROR_MEMORY = 1 , + /** Memory allocation failed. + */ + DK4_UC2L_ERROR_MEMORY = 1 , - /** Syntax error in configuration file. - */ - DK4_UC2L_ERROR_SYNTAX = 2 , + /** Syntax error in configuration file. + */ + DK4_UC2L_ERROR_SYNTAX = 2 , - /** Decoding error in configuration file. - */ - DK4_UC2L_ERROR_DECODING = 4 , + /** Decoding error in configuration file. + */ + DK4_UC2L_ERROR_DECODING = 4 , - /** Other processing errors while reading data. - */ - DK4_UC2L_ERROR_PROCESSING = 8 , + /** Other processing errors while reading data. + */ + DK4_UC2L_ERROR_PROCESSING = 8 , - /** Failed to open one of the data files. - */ - DK4_UC2L_ERROR_FOPEN = 16 , + /** Failed to open one of the data files. + */ + DK4_UC2L_ERROR_FOPEN = 16 , }; @@ -171,30 +197,13 @@ enum { extern "C" { #endif -/** Open conversion structure, dynamically allocate memory. - @param dn Directory name containing the data files. - @param app Application structure for diagnostics, may be NULL. - @return Pointer to conversion structure on success, NULL on error. - - Use dk4uc2l_close() to close the conversion structure when done - with it. +/** Open conversion structure. + @param dn Directory containing the data files. + @param erp Error report, may be NULL. + @return Valid pointer on success, NULL on error. */ dk4_uc2l_t * -dk4uc2l_open(const dkChar *dn, dk4_app_t *app); - - -/** Open conversion structure, dynamically allocate memory. - The directory containing the data files is obtained from - the application (if not NULL), ${datarootdir}/dktools/charmap - is used by default. - @param app Application structure for diagnostics, may be NULL. - @return Pointer to conversion structure on success, NULL on error. - - Use dk4uc2l_close() to close the conversion structure when done - with it. -*/ -dk4_uc2l_t * -dk4uc2l_open_from_app(dk4_app_t *app); +dk4uc2l_open(const dkChar *dn, dk4_er_t *erp); /** Close conversion structure, release memory. @param ulptr Conversion structure to close. @@ -202,6 +211,16 @@ dk4uc2l_open_from_app(dk4_app_t *app); void dk4uc2l_close(dk4_uc2l_t *ulptr); +/** Find LaTeX encoding for one 32 bit character. + @param ulptr Conversion structure. + @param c Character to search encoding for. + @param mm Flag: Math mode (1) or text mode (0). + @param erp Error report, may be NULL. + @return Pointer to encoding string on success, NULL on error. +*/ +const char * +dk4uc2l_find(dk4_uc2l_t *ulptr, dk4_c32_t c, int mm, dk4_er_t *erp); + /** Enable or disable direct UTF-8 output. If you use usepackage[utf-8]{inputenc} you might want to enable UTF-8 output. @@ -220,16 +239,6 @@ dk4uc2l_allow_utf8(dk4_uc2l_t *ulptr, int enabled); void dk4uc2l_clean_packages_and_fonts(dk4_uc2l_t *ulptr); -/** Find LaTeX encoding for one 32 bit character. - @param ulptr Conversion structure. - @param c Character to search encoding for. - @param mm Flag: Math mode (1) or text mode (0). - @param app Application structure for diagnostics, may be NULL. - @return Pointer to encoding string on success, NULL on error. -*/ -const char * -dk4uc2l_find(dk4_uc2l_t *ulptr, dk4_c32_t c, int mm, dk4_app_t *app); - /** Retrieve or-combination of all allowed font encodings. You should use this function after processing all characters. */ @@ -246,10 +255,11 @@ dk4uc2lat_direct(dk4_c32_t c32); /** Issue recommendations about font encodings and packages. Use this function after processing all characters. @param ulptr Conversion structure. - @param fipo File to write to. + @param wstrm Destination stream to write to. + @param erp Error report, may be NULL. */ void -dk4uc2l_recommendations(dk4_uc2l_t *ulptr, FILE *fipo); +dk4uc2l_recommendations(dk4_uc2l_t *ulptr, dk4_stream_t *wstrm, dk4_er_t *erp); /** Retrieve internal error status from conversion structure. @param ulptr Conversion structure. @@ -260,6 +270,146 @@ dk4uc2l_recommendations(dk4_uc2l_t *ulptr, FILE *fipo); int dk4uc2l_retrieve_errors(dk4_uc2l_t *ulptr); +/** Retrieve internal error status from conversion structure. + @param ulptr Conversion structure. + @return Error status, 0 or combination of DK4_UC2L_ERROR_MEMORY, + DK4_UC2L_ERROR_SYNTAX, DK4_UC2L_ERROR_DECODING, + DK4_UC2L_ERROR_PROCESSING, and DK4_UC2L_ERROR_FOPEN. +*/ +void +dk4uc2l_reset_errors(dk4_uc2l_t *ulptr); + +/** Write dkChar string LaTeX encoded to stream. + The method is primarily selected by DK4_CHAR_SIZE. + Use this function if you want to output a dkChar string. + @param wstrm Stream to write to. + @param ulptr Conversion structure. + @param str String. + @param ie Input encoding, only used if dkChar is char. + @param erp Error report, may be NULL. + @return 1 on success, 0 on error. +*/ +int +dk4uc2l_string_dk( + dk4_stream_t *wstrm, + dk4_uc2l_t *ulptr, + const dkChar *str, + int ie, + dk4_er_t *erp +); + +/** Write encoded string LaTeX encoded to stream. + The method is selected by the ie parameter. + Use this function if your string is not necessarily a dkChar string + but you know the encoding. + @param wstrm Stream to write to. + @param ulptr Conversion structure. + @param str String. + @param ie Input encoding, only used if dkChar is char. + @param erp Error report, may be NULL. + @return 1 on success, 0 on error. +*/ +int +dk4uc2l_string_encoded( + dk4_stream_t *wstrm, + dk4_uc2l_t *ulptr, + const void *str, + int ie, + dk4_er_t *erp +); + +/** Write dk4_c32_t string LaTeX encoded to stream. + @param wstrm Stream to write to. + @param ulptr Conversion structure. + @param str String to write. + @param erp Error report, may be NULL. + @return 1 on success, 0 on error. +*/ +int +dk4uc2l_string_c32( + dk4_stream_t *wstrm, + dk4_uc2l_t *ulptr, + const dk4_c32_t *str, + dk4_er_t *erp +); + +/** Write UTF-16 encoded dk_c32_t string LaTeX encoded to stream. + @param wstrm Stream to write to. + @param ulptr Conversion structure. + @param str String to write. + @param erp Error report, may be NULL. + @return 1 on success, 0 on error. +*/ +int +dk4uc2l_string_c16( + dk4_stream_t *wstrm, + dk4_uc2l_t *ulptr, + const dk4_c16_t *str, + dk4_er_t *erp +); + +/** Write UTF-8 encoded char string LaTeX encoded to stream. + @param wstrm Stream to write to. + @param ulptr Conversion structure. + @param str String to write. + @param erp Error report, may be NULL. + @return 1 on success, 0 on error. +*/ +int +dk4uc2l_string_utf8( + dk4_stream_t *wstrm, + dk4_uc2l_t *ulptr, + const char *str, + dk4_er_t *erp +); + +/** Write ANSI encoded char string LaTeX encoded to stream. + @param wstrm Stream to write to. + @param ulptr Conversion structure. + @param str String to write. + @param erp Error report, may be NULL. + @return 1 on success, 0 on error. +*/ +int +dk4uc2l_string_ansi( + dk4_stream_t *wstrm, + dk4_uc2l_t *ulptr, + const char *str, + dk4_er_t *erp +); + +/** Write ASCII encoded char string LaTeX encoded to stream. + @param wstrm Stream to write to. + @param ulptr Conversion structure. + @param str String to write. + @param erp Error report, may be NULL. + @return 1 on success, 0 on error. +*/ +int +dk4uc2l_string_ascii( + dk4_stream_t *wstrm, + dk4_uc2l_t *ulptr, + const char *str, + dk4_er_t *erp +); + +/** Write char string LaTeX encoded to stream. + @param wstrm Stream to write to. + @param ulptr Conversion structure. + @param str String to write. + @param ie Input encoding. + @param erp Error report, may be NULL. + @return 1 on success, 0 on error. +*/ +int +dk4uc2l_string_c8( + dk4_stream_t *wstrm, + dk4_uc2l_t *ulptr, + const char *str, + int ie, + dk4_er_t *erp +); + #ifdef __cplusplus } #endif |