1%%	options
2
3copyright owner	=	Dirk Krause
4copyright year	=	2011-xxxx
5SPDX-License-Identifier:	BSD-3-Clause
6
7
8%%	header
9
10#ifdef	DK3_USE_WX
11#undef	DK3_USE_WX
12#endif
13/**	Use wxWidgets libraries to build GUI programs.
14*/
15#define	DK3_USE_WX	1
16
17
18#if 0
19#include <libdk3c/dk3all.h>
20#else
21#include "dk3conf.h"
22#include <libdk3c/dk3types.h>
23#include <libdk3c/dk3const.h>
24#endif
25
26
27#ifndef	WX_WXPREC_H_INCLUDED
28#include <wx/wxprec.h>
29#define	WX_WXPREC_H_INCLUDED 1
30#endif
31#ifdef __BORLANDC__
32#pragma hdrstop
33#endif
34#ifndef WX_PRECOMP
35#if	DK4_HAVE_WX_CHARTYPE_H
36#if	DK4_HAVE_WX_DEFS_H
37#ifndef	WX_DEFS_H_INCLUDED
38#include <wx/defs.h>
39#define	WX_DEFS_H_INCLUDED
40#endif
41#endif
42#ifndef	WX_CHARTYPE_H_INCLUDED
43#include <wx/chartype.h>
44#define	WX_CHARTYPE_H_INCLUDED 1
45#endif
46#else
47#if	DK4_HAVE_WX_WXCHAR_H
48#if	DK4_HAVE_WX_DEFS_H
49#ifndef	WX_DEFS_H_INCLUDED
50#include <wx/defs.h>
51#define	WX_DEFS_H_INCLUDED
52#endif
53#endif
54#ifndef	WX_WXCHAR_H_INCLUDED
55#include <wx/wxchar.h>
56#define	WX_WXCHAR_H_INCLUDED 1
57#endif
58#else
59#ifndef	WX_WX_H_INCLUDED
60#include <wx/wx.h>
61#define	WX_WX_H_INCLUDED
62#endif
63#endif
64#endif
65#endif
66
67
68/**	Pointer to wxChar string.
69*/
70typedef	wxChar		*DK3_PWXCHAR;
71
72/**	Pointer to constant wxChar string.
73*/
74typedef wxChar const	*DK3_PCWXCHAR;
75
76
77#if DK3_ON_WINDOWS || DK3_HAVE_BACKSLASH
78/**	File name separator.
79*/
80#define	DK3_WX_CHAR_SEP	wxT('\\')
81#else
82/**	File name separator.
83*/
84#define DK3_WX_CHAR_SEP wxT('/')
85#endif
86
87#ifdef __cplusplus
88extern "C" {
89#endif
90
91/**	Copy string.
92 * 	@param	d	Destination pointer.
93 * 	@param	s	Source pointer.
94 */
95void
96dk3wxs_cpy(wxChar *d, wxChar const *s);
97
98/**	Copy string, cut to buffer size if necessary.
99 * 	@param	d	Destination pointer.
100 * 	@param	s	Source pointer.
101 * 	@param	n	Size of \a d (number of characters).
102 */
103void
104dk3wxs_ncpy(wxChar *d, wxChar const *s, size_t n);
105
106/**	Concatenate two strings.
107 * 	@param	d	Destination pointer.
108 * 	@param	s	Source pointer.
109 */
110void
111dk3wxs_cat(wxChar *d, wxChar const *s);
112
113/**	Convert to lower-case character.
114 * 	@param	c	Character to convert.
115 * 	@return	Conversion result.
116 */
117wxChar
118dk3wxs_tolower(wxChar c);
119
120/**	Convert to upper-case character.
121 * 	@param	c	Character to convert.
122 * 	@return	Conversion result.
123 */
124wxChar
125dk3wxs_toupper(wxChar c);
126
127/**	Find left-most orrucance of character in string.
128 * 	@param	s	String probably containing the character.
129 * 	@param	c	Character to search for.
130 * 	@return	Pointer to character position on success, NULL on error.
131 */
132wxChar *
133dk3wxs_chr(wxChar const *s, wxChar c);
134
135/**	Find right-most orrucance of character in string.
136 * 	@param	s	String probably containing the character.
137 * 	@param	c	Character to search for.
138 * 	@return	Pointer to character position on success, NULL on error.
139 */
140wxChar *
141dk3wxs_rchr(wxChar const *s, wxChar c);
142
143/**	Calculate string length.
144 * 	@param	s	String to process.
145 * 	@return	String length (number of characters).
146 */
147size_t
148dk3wxs_len(wxChar const *s);
149
150/**	Duplicate string into dynamically allocated memory.
151 *	Use dk3_delete() to release the memory when done.
152 * 	@param	s	String to duplicate.
153 * 	@return	Pointer to new string on success, NULL on error.
154 */
155wxChar *
156dk3wxs_dup(wxChar const *s);
157
158/**	Duplicate string into dynamically allocated memory.
159 *	Use dk3_delete() to release the memory when done.
160 * 	@param	s	String to duplicate.
161 * 	@param	app	Application structure for diagnostics, may be NULL.
162 * 	@return	Pointer to new string on success, NULL on error.
163 */
164wxChar *
165dk3wxs_dup_app(wxChar const *s, dk3_app_t *app);
166
167/**	Compare two strings, use only the first \a n characters.
168 * 	@param	l	Left side string.
169 * 	@param	r	Right side string.
170 * 	@param	n	Number of characters to use in comparison.
171 * 	@return	1 for l>r, 0 for l=r, -1 for l<r.
172 */
173int
174dk3wxs_ncmp(wxChar const *l, wxChar const *r, size_t n);
175
176/**	Compare two strings.
177 * 	@param	l	Left side string.
178 * 	@param	r	Right side string.
179 * 	@return	1 for l>r, 0 for l=r, -1 for l<r.
180 */
181int
182dk3wxs_cmp(wxChar const *l, wxChar const *r);
183
184/**	Case-insensitve string comparison.
185 * 	@param	l	Left side string.
186 * 	@param	r	Right side string.
187 * 	@return 1 for l>r, 0 for l=r, -1 for l<r.
188 */
189int
190dk3wxs_casecmp(wxChar const *l, wxChar const *r);
191
192/**	Find index of a string in an array of patterns.
193 * 	@param	a	Patterns array.
194 * 	@param	s	String to find.
195 * 	@param	c	Flag: Case-sensitive (1) or not (0).
196 * 	@return	Index of \a s in \a a on success, -1 on error (not found).
197 */
198int
199dk3wxs_array_index(wxChar const * const *a, wxChar const *s, int c);
200
201/**	Find file name suffix.
202	@param	s	File name.
203	@return	Pointer to suffix (pointer to the dot) or NULL.
204*/
205wxChar *
206dk3wxs_get_suffix(wxChar const *s);
207
208/**	Find start of string (first non-whitespace).
209 * 	@param	s	String to process.
210 * 	@param	whsp	Whitespaces set (use NULL for default whitespace set).
211 * 	@return	Pointer to first non-whitespace on success, NULL on error.
212 */
213wxChar *
214dk3wxs_start(wxChar *s, wxChar const *whsp);
215
216/**	Find start of second text
217 * 	@param	s	String to process.
218 * 	@param	whsp	Whitespaces set (use NULL for default whitespace set).
219 * 	@return	Pointer to second non-whitespace sequence on success, or NULL.
220 */
221wxChar *
222dk3wxs_next(wxChar *s, wxChar const *whsp);
223
224/**	Check whether the text represents a boolean value.
225 * 	@param	s	Text to process.
226 * 	@return	1 on success, 0 on error.
227 */
228int
229dk3wxs_is_bool(wxChar const *s);
230
231/**	Check whether the text represents the boolean value "true".
232 * 	@param	s	Text to process.
233 * 	@return	1 on success, 0 on error.
234 */
235int
236dk3wxs_is_on(wxChar const *s);
237
238/**	Explode a string (split string into array of text words).
239	@param	array	Destination pointers array.
240	@param	sz	Size of \a array (number of elements).
241	@param	s	String to process.
242	@param	whsp	Whitespaces set (may be NULL).
243	@return	Number of elements set in \a array, 0 on error.
244*/
245size_t
246dk3wxs_explode(wxChar **array, size_t sz, wxChar *s, wxChar const *whsp);
247
248/**	Normalize text line.
249	@param	l	Text line to modify.
250	@param	w	Whitespaces set (may be NULL).
251	@param	c	Separator character.
252*/
253void
254dk3wxs_normalize(wxChar *l, wxChar const *w, wxChar c);
255
256/**	Check whether a file/directory name is an absolute path.
257 * 	@param	n	Name to check.
258 * 	@return	1 for absolute path, 0 otherwise.
259 */
260int
261dk3wxs_is_abs_path(wxChar const *n);
262
263/**	Append path to a given directory.
264 * 	@param	d	In: directory, out: modified path.
265 * 	@param	sz	Destination buffer size (number of characters).
266 * 	@param	n	Path name to append.
267 * 	@return	1 on success, 0 on errors.
268 */
269int
270dk3wxs_append_path(wxChar *d, size_t sz, wxChar const *n);
271
272/**	Correct file name.
273 * 	@param	n	File name to correct.
274 */
275void
276dk3wxs_correct_filename(wxChar *n);
277
278/**	Convert UTF-8 string to wxChar string.
279 * 	@param	d	Destination buffer.
280 * 	@param	sz	Size of \a d (number of wxChar).
281 * 	@param	s	Source string.
282 * 	@return	1 on success, 0 on error.
283 */
284int
285dk3wxs_from_utf8(wxChar *d, size_t sz, char const *s);
286
287/**	Convert ASCII string to wxChar string.
288 * 	@param	d	Destination buffer.
289 * 	@param	sz	Size of \a d (number of wxChar).
290 * 	@param	s	Source string.
291 * 	@return	1 on success, 0 on error.
292 */
293int
294dk3wxs_from_plain(wxChar *d, size_t sz, char const *s);
295
296/**	Convert UTF-16 string to wxChar string.
297 * 	@param	d	Destination buffer.
298 * 	@param	sz	Size of \a d (number of wxChar).
299 * 	@param	s	Source string.
300 * 	@return	1 on success, 0 on error.
301 */
302int
303dk3wxs_from_utf16(wxChar *d, size_t sz, dk3_c16_t const *s);
304
305/**	Convert dkChar string to wxChar string.
306 * 	@param	dp	Destination buffer pointer.
307 * 	@param	sz	Size of \a dp (number of wxChar).
308 * 	@param	wxe	Encoding for wxChar string (for 8-bit wxChar only).
309 * 	@param	src	Source string.
310 * 	@param	dke	Encoding for dkChar string (for 8-bit dkChar only).
311 * 	@return	1 on success, 0 on error.
312 */
313int
314dk3wxs_from_dkstr(wxChar *dp, size_t sz, int wxe, dkChar const *src, int dke);
315
316/**	Convert wxChar string to dkChar string.
317 * 	@param	dp	Destination buffer pointer.
318 * 	@param	sz	Size of \a dp (number of dkChar).
319 * 	@param	dke	Encoding for dkChar string (used for 8-bit dkChar only).
320 * 	@param	src	Source string.
321 * 	@param	wxe	Encoding for wxChar string (used for 8-bit wxChar only).
322 * 	@return	1 on success, 0 on error.
323 */
324int
325dk3wxs_to_dkstr(dkChar *dp, size_t sz, int dke, wxChar const *src, int wxe);
326
327/**	Convert wxChar string to 8-bit char string.
328 * 	@param	dp	Destination buffer pointer.
329 * 	@param	sz	Size of \a dp.
330 * 	@param	c8e	Encoding for char string.
331 * 	@param	src	Source string.
332 * 	@param	wxe	Encoding for wxChar string (used for 8-bit wxChar only).
333 * 	@return	1 on success, 0 on error.
334 */
335int
336dk3wxs_to_c8(char *dp, size_t sz, int c8e, wxChar const *src, int wxe);
337
338#ifdef __cplusplus
339}
340#endif
341
342
343
344%%	module
345
346#ifdef	DK3_USE_WX
347#undef	DK3_USE_WX
348#endif
349/**	Use wxWidgets libraries to build GUI programs.
350*/
351#define	DK3_USE_WX	1
352
353#include <libdk3c/dk3all.h>
354#include <libdk3wx/dk3wxs.h>
355#include "dk3wxcs.h"
356
357
358
359$!trace-include
360
361
362void
363dk3wxs_cpy(wxChar *d, wxChar const *s)
364{
365#if DK3_SIZEOF_WXCHAR > 1
366#if DK3_SIZEOF_WXCHAR > 2
367  dk3str_c32_cpy((dk3_c32_t *)d, (const dk3_c32_t *)s);
368#else
369  dk3str_c16_cpy((dk3_c16_t *)d, (const dk3_c16_t *)s);
370#endif
371#else
372  dk3str_c8_cpy((char *)d, (const char *)s);
373#endif
374}
375
376wxChar *
377dk3wxs_get_suffix(wxChar const *s)
378{
379  wxChar	*back	= NULL;
380#if DK3_SIZEOF_WXCHAR > 1
381#if DK3_SIZEOF_WXCHAR > 2
382  back = (wxChar *)dk3str_c32_get_suffix((const dk3_c32_t *)s);
383#else
384  back = (wxChar *)dk3str_c16_get_suffix((const dk3_c16_t *)s);
385#endif
386#else
387  back = (wxChar *)dk3str_c8_get_suffix((const char *)s);
388#endif
389  return back;
390}
391
392void
393dk3wxs_ncpy(wxChar *d, wxChar const *s, size_t n)
394{
395#if DK3_SIZEOF_WXCHAR > 1
396#if DK3_SIZEOF_WXCHAR > 2
397  dk3str_c32_ncpy((dk3_c32_t *)d, (const dk3_c32_t *)s, n);
398#else
399  dk3str_c16_ncpy((dk3_c16_t *)d, (const dk3_c16_t *)s, n);
400#endif
401#else
402  dk3str_c8_ncpy((char *)d, (const char *)s, n);
403#endif
404}
405
406void
407dk3wxs_cat(wxChar *d, wxChar const *s)
408{
409#if DK3_SIZEOF_WXCHAR > 1
410#if DK3_SIZEOF_WXCHAR > 2
411  dk3str_c32_cat((dk3_c32_t *)d, (const dk3_c32_t *)s);
412#else
413  dk3str_c16_cat((dk3_c16_t *)d, (const dk3_c16_t *)s);
414#endif
415#else
416  dk3str_c8_cat((char *)d, (const char *)s);
417#endif
418}
419
420wxChar
421dk3wxs_tolower(wxChar c)
422{
423  wxChar back;
424#if DK3_SIZEOF_WXCHAR > 1
425#if DK3_SIZEOF_WXCHAR > 2
426  back = dk3str_c32_tolower((dk3_c32_t)c);
427#else
428  back = dk3str_c16_tolower((dk3_c16_t)c);
429#endif
430#else
431  back = dk3str_c8_tolower((char)c);
432#endif
433  return back;
434}
435
436wxChar
437dk3wxs_toupper(wxChar c)
438{
439  wxChar back;
440#if DK3_SIZEOF_WXCHAR > 1
441#if DK3_SIZEOF_WXCHAR > 2
442  back = dk3str_c32_toupper((dk3_c32_t)c);
443#else
444  back = dk3str_c16_toupper((dk3_c16_t)c);
445#endif
446#else
447  back = dk3str_c8_toupper((char)c);
448#endif
449  return back;
450}
451
452wxChar *
453dk3wxs_chr(wxChar const *s, wxChar c)
454{
455  wxChar *back = NULL;
456  if(s) {
457#if DK3_SIZEOF_WXCHAR > 1
458#if DK3_SIZEOF_WXCHAR > 2
459    back = (wxChar *)dk3str_c32_chr((const dk3_c32_t *)s, (dk3_c32_t)c);
460#else
461    back = (wxChar *)dk3str_c16_chr((const dk3_c16_t *)s, (dk3_c16_t)c);
462#endif
463#else
464    back = (wxChar *)dk3str_c8_chr((const char *)s, (char)c);
465#endif
466  }
467  return back;
468}
469
470wxChar *
471dk3wxs_rchr(wxChar const *s, wxChar c)
472{
473  wxChar *back = NULL;
474  if(s) {
475#if DK3_SIZEOF_WXCHAR > 1
476#if DK3_SIZEOF_WXCHAR > 2
477    back = (wxChar *)dk3str_c32_rchr((const dk3_c32_t *)s, (dk3_c32_t)c);
478#else
479    back = (wxChar *)dk3str_c16_rchr((const dk3_c16_t *)s, (dk3_c16_t)c);
480#endif
481#else
482    back = (wxChar *)dk3str_c8_rchr((const char *)s, (char)c);
483#endif
484  }
485  return back;
486}
487
488size_t
489dk3wxs_len(wxChar const *s)
490{
491  size_t back = 0;
492  if(s) {
493#if DK3_SIZEOF_WXCHAR > 1
494#if DK3_SIZEOF_WXCHAR > 2
495    back = dk3str_c32_len((const dk3_c32_t *)s);
496#else
497    back = dk3str_c16_len((const dk3_c16_t *)s);
498#endif
499#else
500    back = dk3str_c8_len((const char *)s);
501#endif
502  }
503  return back;
504}
505
506wxChar *
507dk3wxs_dup_app(wxChar const *s, dk3_app_t *app)
508{
509  wxChar *back = NULL;
510  if(s) {
511#if DK3_SIZEOF_WXCHAR > 1
512#if DK3_SIZEOF_WXCHAR > 2
513    back = (wxChar *)dk3str_c32_dup_app((const dk3_c32_t *)s, app);
514#else
515    back = (wxChar *)dk3str_c16_dup_app((const dk3_c16_t *)s, app);
516#endif
517#else
518    back = (wxChar *)dk3str_c8_dup_app((const char *)s, app);
519#endif
520  }
521  return back;
522}
523
524wxChar *
525dk3wxs_dup(wxChar const *s)
526{
527  wxChar *back = NULL;
528  if(s) {
529#if DK3_SIZEOF_WXCHAR > 1
530#if DK3_SIZEOF_WXCHAR > 2
531    back = (wxChar *)dk3str_c32_dup_app((const dk3_c32_t *)s, NULL);
532#else
533    back = (wxChar *)dk3str_c16_dup_app((const dk3_c16_t *)s, NULL);
534#endif
535#else
536    back = (wxChar *)dk3str_c8_dup_app((const char *)s, NULL);
537#endif
538  }
539  return back;
540}
541
542int
543dk3wxs_ncmp(wxChar const *l, wxChar const *r, size_t n)
544{
545  int back = 0;
546#if DK3_SIZEOF_WXCHAR > 1
547#if DK3_SIZEOF_WXCHAR > 2
548  back = dk3str_c32_ncmp((const dk3_c32_t *)l, (const dk3_c32_t *)r, n);
549#else
550  back = dk3str_c16_ncmp((const dk3_c16_t *)l, (const dk3_c16_t *)r, n);
551#endif
552#else
553  back = dk3str_c8_ncmp((const char *)l, (const char *)r, n);
554#endif
555  return back;
556}
557
558int
559dk3wxs_cmp(wxChar const *l, wxChar const *r)
560{
561  int back = 0;
562#if DK3_SIZEOF_WXCHAR > 1
563#if DK3_SIZEOF_WXCHAR > 2
564  back = dk3str_c32_cmp((const dk3_c32_t *)l, (const dk3_c32_t *)r);
565#else
566  back = dk3str_c16_cmp((const dk3_c16_t *)l, (const dk3_c16_t *)r);
567#endif
568#else
569  back = dk3str_c8_cmp((const char *)l, (const char *)r);
570#endif
571  return back;
572}
573
574int
575dk3wxs_casecmp(wxChar const *l, wxChar const *r)
576{
577  int back = 0;
578#if DK3_SIZEOF_WXCHAR > 1
579#if DK3_SIZEOF_WXCHAR > 2
580  back = dk3str_c32_casecmp((const dk3_c32_t *)l, (const dk3_c32_t *)r);
581#else
582  back = dk3str_c16_casecmp((const dk3_c16_t *)l, (const dk3_c16_t *)r);
583#endif
584#else
585  back = dk3str_c8_casecmp((const char *)l, (const char *)r);
586#endif
587  return back;
588}
589
590int
591dk3wxs_array_index(wxChar const * const *a, wxChar const *s, int c)
592{
593  int back = -1;
594#if DK3_SIZEOF_WXCHAR > 1
595#if DK3_SIZEOF_WXCHAR > 2
596  back = dk3str_c32_array_index(
597    (const dk3_c32_t * const *)a, (const dk3_c32_t *)s, c
598  );
599#else
600  back = dk3str_c16_array_index(
601    (const dk3_c16_t * const *)a, (const dk3_c16_t *)s, c
602  );
603#endif
604#else
605  back = dk3str_c8_array_index((const char * const *)a, (const char *)s, c);
606#endif
607  return back;
608}
609
610wxChar *
611dk3wxs_start(wxChar *s, wxChar const *whsp)
612{
613  wxChar *back = NULL;
614#if DK3_SIZEOF_WXCHAR > 1
615#if DK3_SIZEOF_WXCHAR > 2
616  back = (wxChar *)dk3str_c32_start((dk3_c32_t *)s, (const dk3_c32_t *)whsp);
617#else
618  back = (wxChar *)dk3str_c16_start((dk3_c16_t *)s, (const dk3_c16_t *)whsp);
619#endif
620#else
621  back = (wxChar *)dk3str_c8_start((char *)s, (const char *)whsp);
622#endif
623  return back;
624}
625
626wxChar *
627dk3wxs_next(wxChar *s, wxChar const *whsp)
628{
629  wxChar *back = NULL;
630#if DK3_SIZEOF_WXCHAR > 1
631#if DK3_SIZEOF_WXCHAR > 2
632  back = (wxChar *)dk3str_c32_next((dk3_c32_t *)s, (const dk3_c32_t *)whsp);
633#else
634  back = (wxChar *)dk3str_c16_next((dk3_c16_t *)s, (const dk3_c16_t *)whsp);
635#endif
636#else
637  back = (wxChar *)dk3str_c8_next((char *)s, (const char *)whsp);
638#endif
639  return back;
640}
641
642int
643dk3wxs_is_bool(wxChar const *s)
644{
645  int back = 0;
646#if DK3_SIZEOF_WXCHAR > 1
647#if DK3_SIZEOF_WXCHAR > 2
648  back = dk3str_c32_is_bool((const dk3_c32_t *)s);
649#else
650  back = dk3str_c16_is_bool((const dk3_c16_t *)s);
651#endif
652#else
653  back = dk3str_c8_is_bool((const char *)s);
654#endif
655  return back;
656}
657
658int
659dk3wxs_is_on(wxChar const *s)
660{
661  int back = 0;
662#if DK3_SIZEOF_WXCHAR > 1
663#if DK3_SIZEOF_WXCHAR > 2
664  back = dk3str_c32_is_on((const dk3_c32_t *)s);
665#else
666  back = dk3str_c16_is_on((const dk3_c16_t *)s);
667#endif
668#else
669  back = dk3str_c8_is_on((const char *)s);
670#endif
671  return back;
672}
673
674size_t
675dk3wxs_explode(wxChar **array, size_t sz, wxChar *s, wxChar const *whsp)
676{
677  size_t back;
678#if DK3_SIZEOF_WXCHAR > 1
679#if DK3_SIZEOF_WXCHAR > 2
680  back = dk3str_c32_explode(
681    (dk3_c32_t **)array, sz, (dk3_c32_t *)s, (const dk3_c32_t *)whsp
682  );
683#else
684  back = dk3str_c16_explode(
685    (dk3_c16_t **)array, sz, (dk3_c16_t *)s, (const dk3_c16_t *)whsp
686  );
687#endif
688#else
689  back = dk3str_c8_explode(
690    (char **)array, sz, (char *)s, (const char *)whsp
691  );
692#endif
693  return back;
694}
695
696void
697dk3wxs_normalize(wxChar *l, wxChar const *w, wxChar c)
698{
699#if DK3_SIZEOF_WXCHAR > 1
700#if DK3_SIZEOF_WXCHAR > 2
701  dk3str_c32_normalize((dk3_c32_t *)l, (const dk3_c32_t *)w, (dk3_c32_t)c);
702#else
703  dk3str_c16_normalize((dk3_c16_t *)l, (const dk3_c16_t *)w, (dk3_c16_t)c);
704#endif
705#else
706  dk3str_c8_normalize((char *)l, (const char *)w, (char)c);
707#endif
708}
709
710
711int
712dk3wxs_is_abs_path(wxChar const *n)
713{
714  int back = 0;
715#if DK3_SIZEOF_WXCHAR > 1
716#if DK3_SIZEOF_WXCHAR > 2
717  back = dk3str_c32_is_abs_path((const dk3_c32_t *)n);
718#else
719  back = dk3str_c16_is_abs_path((const dk3_c16_t *)n);
720#endif
721#else
722  back = dk3str_c8_is_abs_path((const char *)n);
723#endif
724  return back;
725}
726
727int
728dk3wxs_append_path(wxChar *d, size_t sz, wxChar const *n)
729{
730  int back = 0;
731#if DK3_SIZEOF_WXCHAR > 1
732#if DK3_SIZEOF_WXCHAR > 2
733  back = dk3str_c32_append_path_app(
734    (dk3_c32_t *)d, sz, (const dk3_c32_t *)n, NULL
735  );
736#else
737  back = dk3str_c16_append_path_app(
738    (dk3_c16_t *)d, sz, (const dk3_c16_t *)n, NULL
739  );
740#endif
741#else
742  back = dk3str_c8_append_path_app((char *)d, sz, (const char *)n, NULL);
743#endif
744  return back;
745}
746
747void
748dk3wxs_correct_filename(wxChar *n)
749{
750#if DK3_SIZEOF_WXCHAR > 1
751#if DK3_SIZEOF_WXCHAR > 2
752  dk3str_c32_correct_filename((dk3_c32_t *)n);
753#else
754  dk3str_c16_correct_filename((dk3_c16_t *)n);
755#endif
756#else
757  dk3str_c8_correct_filename((char *)n);
758#endif
759}
760
761
762int
763dk3wxs_from_utf8(wxChar *d, size_t sz, char const *s)
764{
765  int back = 0;
766  $? "+ dk3wxs_from_utf8 %u \"%!8s\"", (unsigned)sz, s
767  if((d) && (sz) && (s)) {
768#if DK3_SIZEOF_WXCHAR > 1
769#if DK3_SIZEOF_WXCHAR > 2
770    $? ". 32 bit"
771    if(sz >= dk3str_cnvsz_c8u_to_c32_app(s, NULL)) {
772      $? ". size ok"
773      back = dk3str_cnv_c8u_to_c32_app( (dk3_c32_t *)d, sz, s, NULL);
774    }
775#else
776    $? ". 16 bit"
777    if(sz >= dk3str_cnvsz_c8u_to_c16_app(s, NULL)) {
778      $? ". size ok"
779      back = dk3str_cnv_c8u_to_c16_app( (dk3_c16_t *)d, sz, s, NULL);
780    }
781#endif
782#else
783    $? ". 8 bit"
784    if(sz >= dk3str_cnvsz_c8u_to_c8p_app(s, NULL)) {
785      $? ". size ok"
786      back = dk3str_cnv_c8u_to_c8p_app((char *)d, sz, s, NULL);
787    }
788#endif
789  } $? "- dk3wxs_from_utf8 %d", back
790  return back;
791}
792
793
794int
795dk3wxs_from_plain(wxChar *d, size_t sz, char const *s)
796{
797  int back = 0;
798  if((d) && (sz) && (s)) {
799#if DK3_SIZEOF_WXCHAR > 1
800#if DK3_SIZEOF_WXCHAR > 2
801    if(sz >= dk3str_cnvsz_c8p_to_c32_app(s, NULL)) {
802      back = dk3str_cnv_c8p_to_c32_app((dk3_c32_t *)d, sz, s, NULL);
803    }
804#else
805    if(sz >= dk3str_cnvsz_c8p_to_c16_app(s, NULL)) {
806      back = dk3str_cnv_c8p_to_c16_app((dk3_c16_t *)d, sz, s, NULL);
807    }
808#endif
809#else
810    if(sz >= dk3str_c8_len(s)) {
811      dk3str_c8_cpy((char *)d, s);
812      back = 1;
813    }
814#endif
815  }
816  return back;
817}
818
819
820
821
822int
823dk3wxs_from_utf16(wxChar *d, size_t sz, dk3_c16_t const *s)
824{
825  int back = 0;
826  if((d) && (sz) && (s)) {
827#if DK3_SIZEOF_WXCHAR > 1
828#if DK3_SIZEOF_WXCHAR > 2
829    if(sz >= dk3str_cnvsz_c16_to_c32_app(s, NULL)) {
830      back = dk3str_cnv_c16_to_c32_app((dk3_c32_t *)d, sz, s, NULL);
831    }
832#else
833    if(sz >= dk3str_c16_len(s)) {
834      dk3str_c16_cpy((dk3_c16_t *)d, s);
835      back = 1;
836    }
837#endif
838#else
839    if(sz >= dk3str_cnvsz_c16_to_c8p_app(s, NULL)) {
840      back = dk3str_cnv_c16_to_c8p_app((char *)d, sz, s, NULL);
841    }
842#endif
843  }
844  return back;
845}
846
847
848
849int
850dk3wxs_from_dkstr(
851  wxChar	*dp,
852  size_t	 sz,
853#if DK3_SIZEOF_WXCHAR == 1
854  int		 wxe,
855#else
856  int		 WXUNUSED(wxe),
857#endif
858  dkChar const	*src,
859#if DK3_CHAR_SIZE == 1
860  int		 dke
861#else
862  int		 WXUNUSED(dke)
863#endif
864)
865{
866  int back = 0;
867  if((dp) && (sz) && (src)) {
868#if DK3_SIZEOF_WXCHAR > 1
869#if DK3_SIZEOF_WXCHAR > 2
870  /* + wxChar 4 */
871#if DK3_CHAR_SIZE > 1
872#if DK3_CHAR_SIZE > 2
873  /* + dkChar 4 */
874  if(dk3str_c32_len((const dk3_c32_t *)src) < sz) {
875    dk3str_c32_cpy((dk3_c32_t *)dp, (const dk3_c32_t *)src);
876    back = 1;
877  }
878  /* - dkChar 4 */
879#else
880  /* + dkChar 2 */
881  if(sz >= dk3str_cnvsz_c16_to_c32_app((const dk3_c16_t *)src, NULL)) {
882    back = dk3str_cnv_c16_to_c32_app(
883      (dk3_c32_t *)dp, sz, (const dk3_c16_t *)src, NULL
884    );
885  }
886  /* - dkChar 2 */
887#endif
888#else
889  /* + dkChar 1 */
890  if(dke == DK3_ENCODING_PLAIN) {
891    if(sz >= dk3str_cnvsz_c8p_to_c32_app((const char *)src, NULL)) {
892      back = dk3str_cnv_c8p_to_c32_app(
893        (dk3_c32_t *)dp, sz, (const char *)src, NULL
894      );
895    }
896  } else {
897    if(sz >= dk3str_cnvsz_c8u_to_c32_app(src, NULL)) {
898      back = dk3str_cnv_c8u_to_c32_app(dp, sz, src, NULL);
899    }
900  }
901  /* - dkChar 1 */
902#endif
903  /* - wxChar 4 */
904#else
905  /* + wxChar 2 */
906#if DK3_CHAR_SIZE > 1
907#if DK3_CHAR_SIZE > 2
908  /* + dkChar 4 */
909  if(sz >= dk3str_cnvsz_c32_to_c16_app((const dk3_c32_t *)src, NULL)) {
910    back = dk3str_cnv_c32_to_c16_app(
911      (dk3_c16_t *)dp, sz, (const dk3_c32_t *)src, NULL
912    );
913  }
914  /* - dkChar 4 */
915#else
916  /* + dkChar 2 */
917  if(dk3str_c16_len((const dk3_c16_t *)src) < sz) {
918    dk3str_c16_cpy((dk3_c16_t *)dp, (const dk3_c16_t *)src);
919    back = 1;
920  }
921  /* - dkChar 2 */
922#endif
923#else
924  /* + dkChar 1 */
925  if(dke == DK3_ENCODING_PLAIN) {
926    if(sz >= dk3str_cnvsz_c8p_to_c16_app((const char *)src, NULL)) {
927      back = dk3str_cnv_c8p_to_c16_app(
928        (dk3_c16_t *)dp, sz, (const char *)src, NULL
929      );
930    }
931  } else {
932    if(sz >= dk3str_cnvsz_c8u_to_c16_app((const char *)src, NULL)) {
933      back = dk3str_cnv_c8u_to_c16_app(
934        (dk3_c16_t *)dp, sz, (const char *)src, NULL
935      );
936    }
937  }
938  /* - dkChar 1 */
939#endif
940  /* - wxChar 2 */
941#endif
942#else
943  /* + wxChar 1 */
944#if DK3_CHAR_SIZE > 1
945#if DK3_CHAR_SIZE > 2
946  /* + dkChar 4 */
947  if(wxe == DK3_ENCODING_PLAIN) {
948    if(sz >= dk3str_cnvsz_c8p_to_c32_app((const dk3_c32_t *)src, NULL)) {
949      back = dk3str_cnv_c8p_to_c32_app(
950        (char *)dp, sz, (const dk3_c32_t *)src, NULL
951      );
952    }
953  } else {
954    if(sz >= dk3str_cnvsz_c8u_to_c32_app((const dk3_c32_t *)src, NULL)) {
955      back = dk3str_cnv_c8u_to_c32_app(
956        (char *)dp, sz, (const dk3_c32_t *)src, NULL
957      );
958    }
959  }
960  /* - dkChar 4 */
961#else
962  /* + dkChar 2 */
963  if(wxe == DK3_ENCODING_PLAIN) {
964    if(sz >= dk3str_cnvsz_c8p_to_c16_app((const dk3_c16_t *)src, NULL)) {
965      back =dk3str_cnv_c8p_to_c16_app(
966        (char *)dp, sz, (const dk3_c16_t *)src, NULL
967      );
968    }
969  } else {
970    if(sz >= dk3str_cnvsz_c8u_to_c16_app((const dk3_c16_t *)src, NULL)) {
971      back =dk3str_cnv_c8u_to_c16_app(
972        (char *)dp, sz, (const dk3_c16_t *)src, NULL
973      );
974    }
975  }
976  /* - dkChar 2 */
977#endif
978#else
979  /* + dkChar 1 */
980  if(wxe == dke) {
981    if(dk3str_c8_len((const char *)src) < sz) {
982      dk3str_c8_cpy((char *)dp, (const char *)src);
983      back = 1;
984    }
985  } else {
986    if(wxe == DK3_ENCODING_PLAIN) {
987      if(sz >= dk3str_cnvsz_c8u_to_c8p_app((const char *)src, NULL)) {
988        back = dk3str_cnv_c8u_to_c8p_app(
989	  (char *)dp, sz, (const char *)src, NULL
990	);
991      }
992    } else {
993      if(sz >= dk3str_cnvsz_c8p_to_c8u_app((const char *)src, NULL)) {
994        back = dk3str_cnv_c8p_to_c8u_app(
995	  (char *)dp, sz, (const char *)src, NULL
996	);
997      }
998    }
999  }
1000  /* - dkChar 1 */
1001#endif
1002  /* - wxChar 1 */
1003#endif
1004  }
1005  return back;
1006}
1007
1008
1009
1010int
1011dk3wxs_to_dkstr(
1012  dkChar	*dp,
1013  size_t	 sz,
1014#if DK3_CHAR_SIZE == 1
1015  int		 dke,
1016#else
1017  int		 WXUNUSED(dke),
1018#endif
1019  wxChar const	*src,
1020#if DK3_SIZEOF_WXCHAR == 1
1021  int		 wxe
1022#else
1023  int		 WXUNUSED(wxe)
1024#endif
1025)
1026{
1027  int back = 0;
1028  if((dp) && (sz) && (src)) {
1029#if DK3_CHAR_SIZE > 1
1030#if DK3_CHAR_SIZE > 2
1031  /* + dkChar 4 */
1032#if DK3_SIZEOF_WXCHAR > 1
1033#if DK3_SIZEOF_WXCHAR > 2
1034  /* + wxChar 4 */
1035  if(dk3str_c32_len((const dk3_c32_t *)src) < sz) {
1036    dk3str_c32_cpy((dk3_c32_t *)dp, (const dk3_c32_t *)src);
1037    back = 1;
1038  }
1039  /* - wxChar 4 */
1040#else
1041  /* + wxChar 2 */
1042  if(sz >= dk3str_cnvsz_c16_to_c32_app((const dk3_c16_t *)src, NULL)) {
1043    back = dk3str_cnv_c16_to_c32_app(
1044      (dk3_c32_t *)dp, sz, (const dk3_c16_t *)src, NULL
1045    );
1046  }
1047  /* - wxChar 2 */
1048#endif
1049#else
1050  /* + wxChar 1 */
1051  if(wxe == DK3_ENCODING_PLAIN) {
1052    if(sz >= dk3str_cnvsz_c8p_to_c32_app((const char *)src, NULL)) {
1053      back = dk3str_cnv_c8p_to_c32_app(
1054        (dk3_c32_t *)dp, sz, (const char *)src, NULL
1055      );
1056    }
1057  } else {
1058    if(sz >= dk3str_cnvsz_c8u_to_c32_app((const char *)src, NULL)) {
1059      back = dk3str_cnv_c8u_to_c32_app(
1060        (dk3_c32_t *)dp, sz, (const char *)src, NULL
1061      );
1062    }
1063  }
1064  /* - wxChar 1 */
1065#endif
1066  /* - dkChar 4 */
1067#else
1068  /* + dkChar 2 */
1069#if DK3_SIZEOF_WXCHAR > 1
1070#if DK3_SIZEOF_WXCHAR > 2
1071  /* + wxChar 4 */
1072  if(sz >= dk3str_cnvsz_c32_to_c16_app((const dk3_c32_t *)src, NULL)) {
1073    back = dk3str_cnv_c32_to_c16_app(
1074      (dk3_c16_t *)dp, sz, (const dk3_c32_t *)src, NULL
1075    );
1076  }
1077  /* - wxChar 4 */
1078#else
1079  /* + wxChar 2 */
1080  if(sz > dk3str_c16_len((const dk3_c16_t *)src)) {
1081    dk3str_c16_cpy((dk3_c16_t *)dp, (const dk3_c16_t *)src);
1082    back = 1;
1083  }
1084  /* - wxChar 2 */
1085#endif
1086#else
1087  /* + wxChar 1 */
1088  if(wxe == DK3_ENCODING_PLAIN) {
1089    if(sz >= dk3str_cnvsz_c8p_to_c16_app((const char *)src, NULL)) {
1090      back = dk3str_cnv_c8p_to_c16_app(
1091        (dk3_c16_t *)dp, sz, (const char *)src, NULL
1092      );
1093    }
1094  } else {
1095    if(sz >= dk3str_cnvsz_c8u_to_c16_app((const char *)src, NULL)) {
1096      back = dk3str_cnv_c8u_to_c16_app(
1097        (dk3_c16_t *)dp, sz, (const char *)src, NULL
1098      );
1099    }
1100  }
1101  /* - wxChar 1 */
1102#endif
1103  /* - dkChar 2 */
1104#endif
1105#else
1106  /* + dkChar 1 */
1107#if DK3_SIZEOF_WXCHAR > 1
1108#if DK3_SIZEOF_WXCHAR > 2
1109  /* + wxChar 4 */
1110  if(dke == DK3_ENCODING_PLAIN) {
1111    if(sz >= dk3str_cnvsz_c32_to_c8p_app((const dk3_c32_t *)src, NULL)) {
1112      back = dk3str_cnv_c32_to_c8p_app(
1113        (char *)dp, sz, (const dk3_c32_t *)src, NULL
1114      );
1115    }
1116  } else {
1117    if(sz >= dk3str_cnvsz_c32_to_c8u_app((const dk3_c32_t *)src, NULL)) {
1118      back = dk3str_cnv_c32_to_c8u_app(
1119        (char *)dp, sz, (const dk3_c32_t *)src, NULL
1120      );
1121    }
1122  }
1123  /* - wxChar 4 */
1124#else
1125  /* + wxChar 2 */
1126  if(dke == DK3_ENCODING_PLAIN) {
1127    if(sz >= dk3str_cnvsz_c16_to_c8p_app((const dk3_c16_t *)src, NULL)) {
1128      back = dk3str_cnv_c16_to_c8p_app(
1129        (char *)dp, sz, (const dk3_c16_t *)src, NULL
1130      );
1131    }
1132  } else {
1133    if(sz >= dk3str_cnvsz_c16_to_c8u_app((const dk3_c16_t *)src, NULL)) {
1134      back = dk3str_cnv_c16_to_c8u_app(
1135        (char *)dp, sz, (const dk3_c16_t *)src, NULL
1136      );
1137    }
1138  }
1139  /* - wxChar 2 */
1140#endif
1141#else
1142  /* + wxChar 1 */
1143  if(dke == wxe) {
1144    if(sz > dk3str_c8_len((const char *)src)) {
1145      dk3str_c8_cpy((char *)dp, (const char *)src);
1146      back = 1;
1147    }
1148  } else {
1149    if(dke == DK3_ENCODING_PLAIN) {
1150      if(sz >= dk3str_cnvsz_c8u_to_c8p_app((const char *)src, NULL)) {
1151        back = dk3str_cnv_c8u_to_c8p_app(
1152	  (char *)dp, sz, (const char *)src, NULL
1153	);
1154      }
1155    } else {
1156      if(sz >= dk3str_cnvsz_c8p_to_c8u_app((const char *)src, NULL)) {
1157        back = dk3str_cnv_c8p_to_c8u_app(
1158	  (char *)dp, sz, (const char *)src, NULL
1159	);
1160      }
1161    }
1162  }
1163  /* - wxChar 1 */
1164#endif
1165  /* - dkChar 1 */
1166#endif
1167  }
1168  return back;
1169}
1170
1171
1172int
1173dk3wxs_to_c8(
1174  char		*dp,
1175  size_t	 sz,
1176  int		 c8e,
1177  wxChar const	*src,
1178#if DK3_SIZEOF_WXCHAR == 1
1179  int		 wxe
1180#else
1181  int		 WXUNUSED(wxe)
1182#endif
1183)
1184{
1185  int			 back = 0;
1186  $? "+ dk3wxs_to_c8str"
1187  if((dp) && (sz) && (src)) {
1188#if DK3_SIZEOF_WXCHAR	> 1
1189#if DK3_SIZEOF_WXCHAR	> 2
1190    if(DK3_ENCODING_UTF8 == c8e) {	$? ". 32 bit to UTF-8"
1191      if(sz >= dk3str_cnvsz_c32_to_c8u_app((const dk3_c32_t *)src, NULL)) {
1192        back = dk3str_cnv_c32_to_c8u_app(
1193	  dp, sz, (const dk3_c32_t *)src, NULL
1194	);
1195      }
1196    } else {				$? ". 32 bit to plain"
1197      if(sz >= dk3str_cnvsz_c32_to_c8p_app((const dk3_c32_t *)src, NULL)) {
1198        back = dk3str_cnv_c32_to_c8p_app(
1199	  dp, sz, (const dk3_c32_t *)src, NULL
1200	);
1201      }
1202    }
1203#else
1204    if(DK3_ENCODING_UTF8 == c8e) {	$? ". 16 bit to UTF-8"
1205      if(sz >= dk3str_cnvsz_c16_to_c8u_app((const dk3_c16_t *)src, NULL)) {
1206        back = dk3str_cnv_c16_to_c8u_app(
1207	  dp, sz, (const dk3_c16_t *)src, NULL
1208	);
1209      }
1210    } else {				$? ". 16 bit to plain"
1211      if(sz >= dk3str_cnvsz_c16_to_c8p_app((const dk3_c16_t *)src, NULL)) {
1212        back = dk3str_cnv_c16_to_c8p_app(
1213	  dp, sz, (const dk3_c16_t *)src, NULL
1214	);
1215      }
1216    }
1217#endif
1218#else
1219    if(c8e == wxe) {			$? ". 8 bit copy"
1220      if(sz > strlen((const char *)src)) {
1221        strcpy(dp, (const char *)src);
1222      }
1223    } else {
1224      if(DK3_ENCODING_UTF8 == c8e) {	$? ". 8 bit to UTF-8"
1225        if(sz >= dk3str_cnvsz_c8p_to_c8u_app((const char *)src, NULL)) {
1226	  back = dk3str_cnv_c8p_to_c8u_app(dp, sz, (const char *)src, NULL);
1227	}
1228      } else {				$? ". 8 bit to plain"
1229        if(sz >= dk3str_cnvsz_c8u_to_c8p_app((const char *)src, NULL)) {
1230	  back = dk3str_cnv_c8u_to_c8p_app(dp, sz, (const char *)src, NULL);
1231	}
1232      }
1233    }
1234#endif
1235  } $? "- dk3wxs_to_c8str %d", back
1236  return back;
1237}
1238
1239
1240
1241