1 /* 2 Copyright (C) 2011-2021, Dirk Krause 3 SPDX-License-Identifier: BSD-3-Clause 4 */ 5 6 /* 7 WARNING: This file was generated by the dkct program (see 8 http://dktools.sourceforge.net/ for details). 9 Changes you make here will be lost if dkct is run again! 10 You should modify the original source and run dkct on it. 11 Original source: dk3wxs.cpt 12 */ 13 14 /** @file dk3wxs.h Header file for the dk3wxs module. 15 */ 16 17 #ifndef DK3WXS_H_INCLUDED 18 /** Avoid multiple inclusions. */ 19 #define DK3WXS_H_INCLUDED 1 20 21 22 #ifdef DK3_USE_WX 23 #undef DK3_USE_WX 24 #endif 25 /** Use wxWidgets libraries to build GUI programs. 26 */ 27 #define DK3_USE_WX 1 28 29 30 #if 0 31 #include <libdk3c/dk3all.h> 32 #else 33 #include "dk3conf.h" 34 #include <libdk3c/dk3types.h> 35 #include <libdk3c/dk3const.h> 36 #endif 37 38 39 #ifndef WX_WXPREC_H_INCLUDED 40 #include <wx/wxprec.h> 41 #define WX_WXPREC_H_INCLUDED 1 42 #endif 43 #ifdef __BORLANDC__ 44 #pragma hdrstop 45 #endif 46 #ifndef WX_PRECOMP 47 #if DK4_HAVE_WX_CHARTYPE_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_CHARTYPE_H_INCLUDED 55 #include <wx/chartype.h> 56 #define WX_CHARTYPE_H_INCLUDED 1 57 #endif 58 #else 59 #if DK4_HAVE_WX_WXCHAR_H 60 #if DK4_HAVE_WX_DEFS_H 61 #ifndef WX_DEFS_H_INCLUDED 62 #include <wx/defs.h> 63 #define WX_DEFS_H_INCLUDED 64 #endif 65 #endif 66 #ifndef WX_WXCHAR_H_INCLUDED 67 #include <wx/wxchar.h> 68 #define WX_WXCHAR_H_INCLUDED 1 69 #endif 70 #else 71 #ifndef WX_WX_H_INCLUDED 72 #include <wx/wx.h> 73 #define WX_WX_H_INCLUDED 74 #endif 75 #endif 76 #endif 77 #endif 78 79 80 /** Pointer to wxChar string. 81 */ 82 typedef wxChar *DK3_PWXCHAR; 83 84 /** Pointer to constant wxChar string. 85 */ 86 typedef wxChar const *DK3_PCWXCHAR; 87 88 89 #if DK3_ON_WINDOWS || DK3_HAVE_BACKSLASH 90 /** File name separator. 91 */ 92 #define DK3_WX_CHAR_SEP wxT('\\') 93 #else 94 /** File name separator. 95 */ 96 #define DK3_WX_CHAR_SEP wxT('/') 97 #endif 98 99 #ifdef __cplusplus 100 extern "C" { 101 #endif 102 103 /** Copy string. 104 * @param d Destination pointer. 105 * @param s Source pointer. 106 */ 107 void 108 dk3wxs_cpy(wxChar *d, wxChar const *s); 109 110 /** Copy string, cut to buffer size if necessary. 111 * @param d Destination pointer. 112 * @param s Source pointer. 113 * @param n Size of \a d (number of characters). 114 */ 115 void 116 dk3wxs_ncpy(wxChar *d, wxChar const *s, size_t n); 117 118 /** Concatenate two strings. 119 * @param d Destination pointer. 120 * @param s Source pointer. 121 */ 122 void 123 dk3wxs_cat(wxChar *d, wxChar const *s); 124 125 /** Convert to lower-case character. 126 * @param c Character to convert. 127 * @return Conversion result. 128 */ 129 wxChar 130 dk3wxs_tolower(wxChar c); 131 132 /** Convert to upper-case character. 133 * @param c Character to convert. 134 * @return Conversion result. 135 */ 136 wxChar 137 dk3wxs_toupper(wxChar c); 138 139 /** Find left-most orrucance of character in string. 140 * @param s String probably containing the character. 141 * @param c Character to search for. 142 * @return Pointer to character position on success, NULL on error. 143 */ 144 wxChar * 145 dk3wxs_chr(wxChar const *s, wxChar c); 146 147 /** Find right-most orrucance of character in string. 148 * @param s String probably containing the character. 149 * @param c Character to search for. 150 * @return Pointer to character position on success, NULL on error. 151 */ 152 wxChar * 153 dk3wxs_rchr(wxChar const *s, wxChar c); 154 155 /** Calculate string length. 156 * @param s String to process. 157 * @return String length (number of characters). 158 */ 159 size_t 160 dk3wxs_len(wxChar const *s); 161 162 /** Duplicate string into dynamically allocated memory. 163 * Use dk3_delete() to release the memory when done. 164 * @param s String to duplicate. 165 * @return Pointer to new string on success, NULL on error. 166 */ 167 wxChar * 168 dk3wxs_dup(wxChar const *s); 169 170 /** Duplicate string into dynamically allocated memory. 171 * Use dk3_delete() to release the memory when done. 172 * @param s String to duplicate. 173 * @param app Application structure for diagnostics, may be NULL. 174 * @return Pointer to new string on success, NULL on error. 175 */ 176 wxChar * 177 dk3wxs_dup_app(wxChar const *s, dk3_app_t *app); 178 179 /** Compare two strings, use only the first \a n characters. 180 * @param l Left side string. 181 * @param r Right side string. 182 * @param n Number of characters to use in comparison. 183 * @return 1 for l>r, 0 for l=r, -1 for l<r. 184 */ 185 int 186 dk3wxs_ncmp(wxChar const *l, wxChar const *r, size_t n); 187 188 /** Compare two strings. 189 * @param l Left side string. 190 * @param r Right side string. 191 * @return 1 for l>r, 0 for l=r, -1 for l<r. 192 */ 193 int 194 dk3wxs_cmp(wxChar const *l, wxChar const *r); 195 196 /** Case-insensitve string comparison. 197 * @param l Left side string. 198 * @param r Right side string. 199 * @return 1 for l>r, 0 for l=r, -1 for l<r. 200 */ 201 int 202 dk3wxs_casecmp(wxChar const *l, wxChar const *r); 203 204 /** Find index of a string in an array of patterns. 205 * @param a Patterns array. 206 * @param s String to find. 207 * @param c Flag: Case-sensitive (1) or not (0). 208 * @return Index of \a s in \a a on success, -1 on error (not found). 209 */ 210 int 211 dk3wxs_array_index(wxChar const * const *a, wxChar const *s, int c); 212 213 /** Find file name suffix. 214 @param s File name. 215 @return Pointer to suffix (pointer to the dot) or NULL. 216 */ 217 wxChar * 218 dk3wxs_get_suffix(wxChar const *s); 219 220 /** Find start of string (first non-whitespace). 221 * @param s String to process. 222 * @param whsp Whitespaces set (use NULL for default whitespace set). 223 * @return Pointer to first non-whitespace on success, NULL on error. 224 */ 225 wxChar * 226 dk3wxs_start(wxChar *s, wxChar const *whsp); 227 228 /** Find start of second text 229 * @param s String to process. 230 * @param whsp Whitespaces set (use NULL for default whitespace set). 231 * @return Pointer to second non-whitespace sequence on success, or NULL. 232 */ 233 wxChar * 234 dk3wxs_next(wxChar *s, wxChar const *whsp); 235 236 /** Check whether the text represents a boolean value. 237 * @param s Text to process. 238 * @return 1 on success, 0 on error. 239 */ 240 int 241 dk3wxs_is_bool(wxChar const *s); 242 243 /** Check whether the text represents the boolean value "true". 244 * @param s Text to process. 245 * @return 1 on success, 0 on error. 246 */ 247 int 248 dk3wxs_is_on(wxChar const *s); 249 250 /** Explode a string (split string into array of text words). 251 @param array Destination pointers array. 252 @param sz Size of \a array (number of elements). 253 @param s String to process. 254 @param whsp Whitespaces set (may be NULL). 255 @return Number of elements set in \a array, 0 on error. 256 */ 257 size_t 258 dk3wxs_explode(wxChar **array, size_t sz, wxChar *s, wxChar const *whsp); 259 260 /** Normalize text line. 261 @param l Text line to modify. 262 @param w Whitespaces set (may be NULL). 263 @param c Separator character. 264 */ 265 void 266 dk3wxs_normalize(wxChar *l, wxChar const *w, wxChar c); 267 268 /** Check whether a file/directory name is an absolute path. 269 * @param n Name to check. 270 * @return 1 for absolute path, 0 otherwise. 271 */ 272 int 273 dk3wxs_is_abs_path(wxChar const *n); 274 275 /** Append path to a given directory. 276 * @param d In: directory, out: modified path. 277 * @param sz Destination buffer size (number of characters). 278 * @param n Path name to append. 279 * @return 1 on success, 0 on errors. 280 */ 281 int 282 dk3wxs_append_path(wxChar *d, size_t sz, wxChar const *n); 283 284 /** Correct file name. 285 * @param n File name to correct. 286 */ 287 void 288 dk3wxs_correct_filename(wxChar *n); 289 290 /** Convert UTF-8 string to wxChar string. 291 * @param d Destination buffer. 292 * @param sz Size of \a d (number of wxChar). 293 * @param s Source string. 294 * @return 1 on success, 0 on error. 295 */ 296 int 297 dk3wxs_from_utf8(wxChar *d, size_t sz, char const *s); 298 299 /** Convert ASCII string to wxChar string. 300 * @param d Destination buffer. 301 * @param sz Size of \a d (number of wxChar). 302 * @param s Source string. 303 * @return 1 on success, 0 on error. 304 */ 305 int 306 dk3wxs_from_plain(wxChar *d, size_t sz, char const *s); 307 308 /** Convert UTF-16 string to wxChar string. 309 * @param d Destination buffer. 310 * @param sz Size of \a d (number of wxChar). 311 * @param s Source string. 312 * @return 1 on success, 0 on error. 313 */ 314 int 315 dk3wxs_from_utf16(wxChar *d, size_t sz, dk3_c16_t const *s); 316 317 /** Convert dkChar string to wxChar string. 318 * @param dp Destination buffer pointer. 319 * @param sz Size of \a dp (number of wxChar). 320 * @param wxe Encoding for wxChar string (for 8-bit wxChar only). 321 * @param src Source string. 322 * @param dke Encoding for dkChar string (for 8-bit dkChar only). 323 * @return 1 on success, 0 on error. 324 */ 325 int 326 dk3wxs_from_dkstr(wxChar *dp, size_t sz, int wxe, dkChar const *src, int dke); 327 328 /** Convert wxChar string to dkChar string. 329 * @param dp Destination buffer pointer. 330 * @param sz Size of \a dp (number of dkChar). 331 * @param dke Encoding for dkChar string (used for 8-bit dkChar only). 332 * @param src Source string. 333 * @param wxe Encoding for wxChar string (used for 8-bit wxChar only). 334 * @return 1 on success, 0 on error. 335 */ 336 int 337 dk3wxs_to_dkstr(dkChar *dp, size_t sz, int dke, wxChar const *src, int wxe); 338 339 /** Convert wxChar string to 8-bit char string. 340 * @param dp Destination buffer pointer. 341 * @param sz Size of \a dp. 342 * @param c8e Encoding for char string. 343 * @param src Source string. 344 * @param wxe Encoding for wxChar string (used for 8-bit wxChar only). 345 * @return 1 on success, 0 on error. 346 */ 347 int 348 dk3wxs_to_c8(char *dp, size_t sz, int c8e, wxChar const *src, int wxe); 349 350 #ifdef __cplusplus 351 } 352 #endif 353 354 355 356 357 #endif 358