SDL  2.0
test.c
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2020 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 
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <string.h>
25 #include "geniconv.h"
26 
27 int main(void)
28 {
29  char acBuf[128];
30  char *inbuf = "Тест - проверка"; /* KOI8-R string */
31  size_t inbytesleft = strlen(inbuf);
32  char *outbuf = acBuf;
33  size_t outbytesleft = sizeof(acBuf);
34  iconv_t ic;
35 
36  /* KOI8 -> system cp */
37  ic = iconv_open("", "KOI8-R");
38  if (ic == (iconv_t)(-1)) {
39  puts("iconv_open() fail");
40  return 1;
41  }
42 
43  iconv(ic, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
44  printf("KOI8-R to system cp: %s\n", acBuf);
45 
46  iconv_close(ic);
47 
48  /* System cp -> UTF-8 -> system cp: */
49 
50  /* System cp -> UTF-8 by StrUTF8New() */
51  inbuf = StrUTF8New(1, acBuf, strlen(acBuf));
52 
53  /* UTF-8 -> system cp. by StrUTF8() */
54  if (StrUTF8(0, acBuf, sizeof(acBuf), inbuf, strlen(inbuf)) == -1) {
55  puts("StrUTF8() failed");
56  } else {
57  printf("system cp. -> UTF-8 -> system cp.: %s\n", acBuf);
58  }
59 
60  free(inbuf);
61 
62  /* Unload used DLL */
63  iconv_clean();
64 
65  puts("Done.");
66  return 0;
67 }
68 
69 /* vi: set ts=4 sw=4 expandtab: */
SDL_EventEntry * free
Definition: SDL_events.c:89
#define iconv_clean
Definition: geniconv.h:48
char * StrUTF8New(int fToUTF8, char *pcStr, int cbStr)
Definition: sys2utf8.c:83
int StrUTF8(int fToUTF8, char *pcDst, int cbDst, char *pcSrc, int cbSrc)
Definition: sys2utf8.c:25
void * iconv_t
Definition: iconv.h:7
int iconv_close(iconv_t)
iconv_t iconv_open(const char *, const char *)
size_t iconv(iconv_t, char **, size_t *, char **, size_t *)
int main(void)
Definition: test.c:27