SDL  2.0
testiconv.c File Reference
#include <stdio.h>
#include "SDL.h"
+ Include dependency graph for testiconv.c:

Go to the source code of this file.

Functions

static size_t widelen (char *data)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 29 of file testiconv.c.

References i, SDL_arraysize, SDL_free, SDL_iconv_string, SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, SDL_LogError, SDL_LogSetPriority, SDL_memcmp, SDL_strlen, and widelen().

30 {
31  const char *formats[] = {
32  "UTF8",
33  "UTF-8",
34  "UTF16BE",
35  "UTF-16BE",
36  "UTF16LE",
37  "UTF-16LE",
38  "UTF32BE",
39  "UTF-32BE",
40  "UTF32LE",
41  "UTF-32LE",
42  "UCS4",
43  "UCS-4",
44  };
45  char buffer[BUFSIZ];
46  char *ucs4;
47  char *test[2];
48  int i;
49  FILE *file;
50  int errors = 0;
51 
52  /* Enable standard application logging */
54 
55  if (!argv[1]) {
56  argv[1] = "utf8.txt";
57  }
58  file = fopen(argv[1], "rb");
59  if (!file) {
60  SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to open %s\n", argv[1]);
61  return (1);
62  }
63 
64  while (fgets(buffer, sizeof(buffer), file)) {
65  /* Convert to UCS-4 */
66  size_t len;
67  ucs4 =
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]);
76  ++errors;
77  }
78  SDL_free(test[0]);
79  SDL_free(test[1]);
80  }
81  test[0] = SDL_iconv_string("UTF-8", "UCS-4", ucs4, len);
82  SDL_free(ucs4);
83  fputs(test[0], stdout);
84  SDL_free(test[0]);
85  }
86  fclose(file);
87  return (errors ? errors + 1 : 0);
88 }
static size_t widelen(char *data)
Definition: testiconv.c:18
GLenum GLsizei len
#define SDL_LogError
#define SDL_free
#define SDL_memcmp
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define SDL_LogSetPriority
GLuint buffer
EGLint EGLint * formats
Definition: eglext.h:718
#define SDL_strlen
#define SDL_iconv_string
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:93

◆ widelen()

static size_t widelen ( char *  data)
static

Definition at line 18 of file testiconv.c.

Referenced by main().

19 {
20  size_t len = 0;
21  Uint32 *p = (Uint32 *) data;
22  while (*p++) {
23  ++len;
24  }
25  return len;
26 }
GLfloat GLfloat p
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
uint32_t Uint32
Definition: SDL_stdinc.h:181
GLenum GLsizei len