summaryrefslogtreecommitdiff
path: root/support/dktools/dk3wxs.h
blob: f1768d439820c812da032298b65f550d3a64c58e (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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
/*
	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: dk3wxs.cpt
*/

/*
Copyright (C) 2011-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.
*/

/**	@file dk3wxs.h Header file for the dk3wxs module.
*/

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


#line 9 "dk3wxs.cpt"

#ifdef	DK3_USE_WX
#undef	DK3_USE_WX
#endif
/**	Use wxWidgets libraries to build GUI programs.
*/
#define	DK3_USE_WX	1


#if 0
#include <dk3all.h>
#else
#include <dk3conf.h>
#include <dk3types.h>
#include <dk3const.h>
#endif


#ifndef	WX_WXPREC_H_INCLUDED
#include <wx/wxprec.h>
#define	WX_WXPREC_H_INCLUDED 1
#endif
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#if	DK4_HAVE_WX_CHARTYPE_H
#ifndef	WX_CHARTYPE_H_INCLUDED
#include <wx/chartype.h>
#define	WX_CHARTYPE_H_INCLUDED 1
#endif
#else
#if	DK4_HAVE_WX_WXCHAR_H
#ifndef	WX_WXCHAR_H_INCLUDED
#include <wx/wxchar.h>
#define	WX_WXCHAR_H_INCLUDED 1
#endif
#else
#ifndef	WX_WX_H_INCLUDED
#include <wx/wx.h>
#define	WX_WX_H_INCLUDED
#endif
#endif
#endif
#endif


/**	Pointer to wxChar string.
*/
typedef	wxChar		*DK3_PWXCHAR;

/**	Pointer to constant wxChar string.
*/
typedef wxChar const	*DK3_PCWXCHAR;


#if DK3_ON_WINDOWS || DK3_HAVE_BACKSLASH
/**	File name separator.
*/
#define	DK3_WX_CHAR_SEP	wxT('\\')
#else
/**	File name separator.
*/
#define DK3_WX_CHAR_SEP wxT('/')
#endif

#ifdef __cplusplus
extern "C" {
#endif

/**	Copy string.
 * 	@param	d	Destination pointer.
 * 	@param	s	Source pointer.
 */
void
dk3wxs_cpy(wxChar *d, wxChar const *s);

/**	Copy string, cut to buffer size if necessary.
 * 	@param	d	Destination pointer.
 * 	@param	s	Source pointer.
 * 	@param	n	Size of \a d (number of characters).
 */
void
dk3wxs_ncpy(wxChar *d, wxChar const *s, size_t n);

/**	Concatenate two strings.
 * 	@param	d	Destination pointer.
 * 	@param	s	Source pointer.
 */
void
dk3wxs_cat(wxChar *d, wxChar const *s);

/**	Convert to lower-case character.
 * 	@param	c	Character to convert.
 * 	@return	Conversion result.
 */
wxChar
dk3wxs_tolower(wxChar c);

/**	Convert to upper-case character.
 * 	@param	c	Character to convert.
 * 	@return	Conversion result.
 */
wxChar
dk3wxs_toupper(wxChar c);

/**	Find left-most orrucance of character in string.
 * 	@param	s	String probably containing the character.
 * 	@param	c	Character to search for.
 * 	@return	Pointer to character position on success, NULL on error.
 */
wxChar *
dk3wxs_chr(wxChar const *s, wxChar c);

/**	Find right-most orrucance of character in string.
 * 	@param	s	String probably containing the character.
 * 	@param	c	Character to search for.
 * 	@return	Pointer to character position on success, NULL on error.
 */
wxChar *
dk3wxs_rchr(wxChar const *s, wxChar c);

/**	Calculate string length.
 * 	@param	s	String to process.
 * 	@return	String length (number of characters).
 */
size_t
dk3wxs_len(wxChar const *s);

/**	Duplicate string into dynamically allocated memory.
 *	Use dk3_delete() to release the memory when done.
 * 	@param	s	String to duplicate.
 * 	@return	Pointer to new string on success, NULL on error.
 */
wxChar *
dk3wxs_dup(wxChar const *s);

/**	Duplicate string into dynamically allocated memory.
 *	Use dk3_delete() to release the memory when done.
 * 	@param	s	String to duplicate.
 * 	@param	app	Application structure for diagnostics, may be NULL.
 * 	@return	Pointer to new string on success, NULL on error.
 */
wxChar *
dk3wxs_dup_app(wxChar const *s, dk3_app_t *app);

/**	Compare two strings, use only the first \a n characters.
 * 	@param	l	Left side string.
 * 	@param	r	Right side string.
 * 	@param	n	Number of characters to use in comparison.
 * 	@return	1 for l>r, 0 for l=r, -1 for l<r.
 */
int
dk3wxs_ncmp(wxChar const *l, wxChar const *r, size_t n);

/**	Compare two strings.
 * 	@param	l	Left side string.
 * 	@param	r	Right side string.
 * 	@return	1 for l>r, 0 for l=r, -1 for l<r.
 */
int
dk3wxs_cmp(wxChar const *l, wxChar const *r);

/**	Case-insensitve string comparison.
 * 	@param	l	Left side string.
 * 	@param	r	Right side string.
 * 	@return 1 for l>r, 0 for l=r, -1 for l<r.
 */
int
dk3wxs_casecmp(wxChar const *l, wxChar const *r);

/**	Find index of a string in an array of patterns.
 * 	@param	a	Patterns array.
 * 	@param	s	String to find.
 * 	@param	c	Flag: Case-sensitive (1) or not (0).
 * 	@return	Index of \a s in \a a on success, -1 on error (not found).
 */
int
dk3wxs_array_index(wxChar const * const *a, wxChar const *s, int c);

/**	Find file name suffix.
	@param	s	File name.
	@return	Pointer to suffix (pointer to the dot) or NULL.
*/
wxChar *
dk3wxs_get_suffix(wxChar const *s);

/**	Find start of string (first non-whitespace).
 * 	@param	s	String to process.
 * 	@param	whsp	Whitespaces set (use NULL for default whitespace set).
 * 	@return	Pointer to first non-whitespace on success, NULL on error.
 */
wxChar *
dk3wxs_start(wxChar *s, wxChar const *whsp);

/**	Find start of second text
 * 	@param	s	String to process.
 * 	@param	whsp	Whitespaces set (use NULL for default whitespace set).
 * 	@return	Pointer to second non-whitespace sequence on success, or NULL.
 */
wxChar *
dk3wxs_next(wxChar *s, wxChar const *whsp);

/**	Check whether the text represents a boolean value.
 * 	@param	s	Text to process.
 * 	@return	1 on success, 0 on error.
 */
int
dk3wxs_is_bool(wxChar const *s);

/**	Check whether the text represents the boolean value "true".
 * 	@param	s	Text to process.
 * 	@return	1 on success, 0 on error.
 */
int
dk3wxs_is_on(wxChar const *s);

/**	Explode a string (split string into array of text words).
	@param	array	Destination pointers array.
	@param	sz	Size of \a array (number of elements).
	@param	s	String to process.
	@param	whsp	Whitespaces set (may be NULL).
	@return	Number of elements set in \a array, 0 on error.
*/
size_t
dk3wxs_explode(wxChar **array, size_t sz, wxChar *s, wxChar const *whsp);

/**	Normalize text line.
	@param	l	Text line to modify.
	@param	w	Whitespaces set (may be NULL).
	@param	c	Separator character.
*/
void
dk3wxs_normalize(wxChar *l, wxChar const *w, wxChar c);

/**	Check whether a file/directory name is an absolute path.
 * 	@param	n	Name to check.
 * 	@return	1 for absolute path, 0 otherwise.
 */
int
dk3wxs_is_abs_path(wxChar const *n);

/**	Append path to a given directory.
 * 	@param	d	In: directory, out: modified path.
 * 	@param	sz	Destination buffer size (number of characters).
 * 	@param	n	Path name to append.
 * 	@return	1 on success, 0 on errors.
 */
int
dk3wxs_append_path(wxChar *d, size_t sz, wxChar const *n);

/**	Correct file name.
 * 	@param	n	File name to correct.
 */
void
dk3wxs_correct_filename(wxChar *n);

/**	Convert UTF-8 string to wxChar string.
 * 	@param	d	Destination buffer.
 * 	@param	sz	Size of \a d (number of wxChar).
 * 	@param	s	Source string.
 * 	@return	1 on success, 0 on error.
 */
int
dk3wxs_from_utf8(wxChar *d, size_t sz, char const *s);

/**	Convert ASCII string to wxChar string.
 * 	@param	d	Destination buffer.
 * 	@param	sz	Size of \a d (number of wxChar).
 * 	@param	s	Source string.
 * 	@return	1 on success, 0 on error.
 */
int
dk3wxs_from_plain(wxChar *d, size_t sz, char const *s);

/**	Convert UTF-16 string to wxChar string.
 * 	@param	d	Destination buffer.
 * 	@param	sz	Size of \a d (number of wxChar).
 * 	@param	s	Source string.
 * 	@return	1 on success, 0 on error.
 */
int
dk3wxs_from_utf16(wxChar *d, size_t sz, dk3_c16_t const *s);

/**	Convert dkChar string to wxChar string.
 * 	@param	dp	Destination buffer pointer.
 * 	@param	sz	Size of \a dp (number of wxChar).
 * 	@param	wxe	Encoding for wxChar string (for 8-bit wxChar only).
 * 	@param	src	Source string.
 * 	@param	dke	Encoding for dkChar string (for 8-bit dkChar only).
 * 	@return	1 on success, 0 on error.
 */
int
dk3wxs_from_dkstr(wxChar *dp, size_t sz, int wxe, dkChar const *src, int dke);

/**	Convert wxChar string to dkChar string.
 * 	@param	dp	Destination buffer pointer.
 * 	@param	sz	Size of \a dp (number of dkChar).
 * 	@param	dke	Encoding for dkChar string (used for 8-bit dkChar only).
 * 	@param	src	Source string.
 * 	@param	wxe	Encoding for wxChar string (used for 8-bit wxChar only).
 * 	@return	1 on success, 0 on error.
 */
int
dk3wxs_to_dkstr(dkChar *dp, size_t sz, int dke, wxChar const *src, int wxe);

/**	Convert wxChar string to 8-bit char string.
 * 	@param	dp	Destination buffer pointer.
 * 	@param	sz	Size of \a dp.
 * 	@param	c8e	Encoding for char string.
 * 	@param	src	Source string.
 * 	@param	wxe	Encoding for wxChar string (used for 8-bit wxChar only).
 * 	@return	1 on success, 0 on error.
 */
int
dk3wxs_to_c8(char *dp, size_t sz, int c8e, wxChar const *src, int wxe);

#ifdef __cplusplus
}
#endif




#endif