2 Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
21 Uint32 *p = (Uint32 *) data;
29 main(int argc, char *argv[])
31 const char *formats[] = {
52 /* Enable standard application logging */
53 SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
58 file = fopen(argv[1], "rb");
60 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to open %s\n", argv[1]);
64 while (fgets(buffer, sizeof(buffer), file)) {
65 /* Convert to UCS-4 */
68 SDL_iconv_string("UCS-4", "UTF-8", buffer,
69 SDL_strlen(buffer) + 1);
70 len = (widelen(ucs4) + 1) * 4;
71 for (i = 0; i < SDL_arraysize(formats); ++i) {
72 test[0] = SDL_iconv_string(formats[i], "UCS-4", ucs4, len);
73 test[1] = SDL_iconv_string("UCS-4", formats[i], test[0], len);
74 if (!test[1] || SDL_memcmp(test[1], ucs4, len) != 0) {
75 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "FAIL: %s\n", formats[i]);
81 test[0] = SDL_iconv_string("UTF-8", "UCS-4", ucs4, len);
83 fputs(test[0], stdout);
87 return (errors ? errors + 1 : 0);