summaryrefslogtreecommitdiff
path: root/support/dktools/dk4uc2l.h
blob: 501acc8072151ad288f82b0c4113355850880bf4 (plain)
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
/*
	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-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.
*/

#ifndef DK4UC2L_H_INCLUDED
/** Avoid multiple inclusions. */
#define DK4UC2L_H_INCLUDED 1


#line 10 "dk4uc2l.ctr"

/**	@file	dk4uc2l.h	Text to LaTeX conversion.

LaTeX sequences to represent a 32 bit character are found in lookup tables
in the ${datarootdir}/dktools/charmap directory. The functions in this
module read those lookup tables needed, cache the contents and provide
LaTeX sequences.

After finishing output you can write recommendations (i.e. LaTeX packages
to include, font encoding to use) as comments to the file.
*/

#ifndef DK4ERROR_H_INCLUDED
#include "dk4app.h"
#endif

#ifndef DK4STO_H_INCLUDED
#include "dk4sto.h"
#endif

/**	Information about a package.
*/
typedef struct {
  char			*pn;		/**< Package name. */
  unsigned char		 used;		/**< Flag: Package used. */
} dk4_uc2l_pkg_t;

/**	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. */
} 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_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. */
} 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
  )
};



/**	Errors from this module
*/
enum {

			/**	Memory allocation failed.
			*/
  DK4_UC2L_ERROR_MEMORY	=	1 ,

			/**	Syntax error in configuration file.
			*/
  DK4_UC2L_ERROR_SYNTAX	=	2 ,

			/**	Decoding error in configuration file.
			*/
  DK4_UC2L_ERROR_DECODING =	4 ,

			/**	Other processing errors while reading data.
			*/
  DK4_UC2L_ERROR_PROCESSING =	8 ,

			/**	Failed to open one of the data files.
			*/
  DK4_UC2L_ERROR_FOPEN	=	16 ,
};



#ifdef __cplusplus
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.
*/
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);

/**	Close conversion structure, release memory.
	@param	ulptr	Conversion structure to close.
*/
void
dk4uc2l_close(dk4_uc2l_t *ulptr);

/**	Enable or disable direct UTF-8 output.
	If you use usepackage[utf-8]{inputenc} you might want to
	enable UTF-8 output.
	@param	ulptr	Conversion structure to set up.
	@param	enabled	Flag: Enable UTF-8 output.
*/
void
dk4uc2l_allow_utf8(dk4_uc2l_t *ulptr, int enabled);

/**	Reset information about used packages and allowed and denied
	font encodings.
	Typically you want to use this function only after finishing
	one output file and starting a new one.
	@param	ulptr	Conversion structure to reset.
*/
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.
*/
unsigned char
dk4uc2l_retrieve_allowed_fe(dk4_uc2l_t *ulptr);

/**	Check whether a character can be written to a LaTeX file directly.
	@param	c32	Character to check.
	@return	1 for yes, 0 for no.
*/
int
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.
*/
void
dk4uc2l_recommendations(dk4_uc2l_t *ulptr, FILE *fipo);

/**	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.
*/
int
dk4uc2l_retrieve_errors(dk4_uc2l_t *ulptr);

#ifdef __cplusplus
}
#endif




#endif