| 1 | /* |
| 2 | Simple DirectMedia Layer |
| 3 | Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> |
| 4 | |
| 5 | This software is provided 'as-is', without any express or implied |
| 6 | warranty. In no event will the authors be held liable for any damages |
| 7 | arising from the use of this software. |
| 8 | |
| 9 | Permission is granted to anyone to use this software for any purpose, |
| 10 | including commercial applications, and to alter it and redistribute it |
| 11 | freely, subject to the following restrictions: |
| 12 | |
| 13 | 1. The origin of this software must not be misrepresented; you must not |
| 14 | claim that you wrote the original software. If you use this software |
| 15 | in a product, an acknowledgment in the product documentation would be |
| 16 | appreciated but is not required. |
| 17 | 2. Altered source versions must be plainly marked as such, and must not be |
| 18 | misrepresented as being the original software. |
| 19 | 3. This notice may not be removed or altered from any source distribution. |
| 20 | */ |
| 21 | #include "SDL_internal.h" |
| 22 | |
| 23 | /* The following are utility functions to help implementations. |
| 24 | They are ordered by scope largeness, decreasing. All implementations |
| 25 | should use them, as they check for invalid filters. Where they are unused, |
| 26 | the validate_* function further down below should be used. */ |
| 27 | |
| 28 | /* Transform the name given in argument into something viable for the engine. |
| 29 | Useful if there are special characters to avoid on certain platforms (such |
| 30 | as "|" with Zenity). */ |
| 31 | typedef char *(NameTransform)(const char * name); |
| 32 | |
| 33 | // Converts all the filters into a single string. |
| 34 | // <prefix>[filter]{<separator>[filter]...}<suffix> |
| 35 | char *convert_filters(const SDL_DialogFileFilter *filters, int nfilters, |
| 36 | NameTransform ntf, const char *prefix, |
| 37 | const char *separator, const char *suffix, |
| 38 | const char *filt_prefix, const char *filt_separator, |
| 39 | const char *filt_suffix, const char *ext_prefix, |
| 40 | const char *ext_separator, const char *ext_suffix); |
| 41 | |
| 42 | // Converts one filter into a single string. |
| 43 | // <prefix>[filter name]<separator>[filter extension list]<suffix> |
| 44 | char *convert_filter(SDL_DialogFileFilter filter, NameTransform ntf, |
| 45 | const char *prefix, const char *separator, |
| 46 | const char *suffix, const char *ext_prefix, |
| 47 | const char *ext_separator, const char *ext_suffix); |
| 48 | |
| 49 | // Converts the extension list of a filter into a single string. |
| 50 | // <prefix>[extension]{<separator>[extension]...}<suffix> |
| 51 | char *convert_ext_list(const char *list, const char *prefix, |
| 52 | const char *separator, const char *suffix); |
| 53 | |
| 54 | /* Must be used if convert_* functions aren't used */ |
| 55 | // Returns an error message if there's a problem, NULL otherwise |
| 56 | const char *validate_filters(const SDL_DialogFileFilter *filters, |
| 57 | int nfilters); |
| 58 | |
| 59 | const char *validate_list(const char *list); |
| 60 | |