grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / codesets / developer / examples / UTF8ToStrHook.c
blob7541beafe8dbd6c6ac766edd2d46acad22539a1c
1 /***************************************************************************
3 codesets.library - Amiga shared library for handling different codesets
4 Copyright (C) 2001-2005 by Alfonso [alfie] Ranieri <alforan@tin.it>.
5 Copyright (C) 2005-2014 codesets.library Open Source Team
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 codesets.library project: http://sourceforge.net/projects/codesetslib/
19 Most of the code included in this file was relicensed from GPL to LGPL
20 from the source code of SimpleMail (http://www.sf.net/projects/simplemail)
21 with full permissions by its authors.
23 $Id$
25 ***************************************************************************/
27 #include <proto/exec.h>
28 #include <proto/codesets.h>
29 #include <stdio.h>
30 #include <string.h>
32 // plain: "öäüÖÄÜß"
33 #define STR "öäüÖÄÜß" \
34 "öäüÖÄÜß" \
35 "öäüÖÄÜß" \
36 "öäüÖÄÜß" \
37 "öäüÖÄÜß" \
38 "öäüÖÄÜß"
40 #include "SDI_hook.h"
42 struct Library *CodesetsBase = NULL;
43 #if defined(__amigaos4__)
44 struct CodesetsIFace* ICodesets = NULL;
45 #endif
47 #if defined(__amigaos4__)
48 #define GETINTERFACE(iface, base) (iface = (APTR)GetInterface((struct Library *)(base), "main", 1L, NULL))
49 #define DROPINTERFACE(iface) (DropInterface((struct Interface *)iface), iface = NULL)
50 #else
51 #define GETINTERFACE(iface, base) TRUE
52 #define DROPINTERFACE(iface)
53 #endif
55 HOOKPROTONH(destFunc, ULONG, struct convertMsg* msg, STRPTR buf)
57 printf("[%3d] [%s]\n",(int)msg->len,buf);
59 if(msg->state == CSV_End)
60 printf("\n");
62 return 0;
64 MakeStaticHook(destHook, destFunc);
66 int main(int argc,char **argv)
68 int res;
70 if((CodesetsBase = OpenLibrary(CODESETSNAME,CODESETSVER)) &&
71 GETINTERFACE(ICodesets, CodesetsBase))
73 char *str;
75 if(argc>1)
76 str = argv[1];
77 else
78 str = STR;
80 // check that the string only contains UTF8
81 // sequences.
82 if(CodesetsIsValidUTF8(str))
84 CodesetsUTF8ToStr(CSA_Source, (IPTR)str,
85 CSA_DestLen, 32,
86 CSA_DestHook, (IPTR)&destHook,
87 TAG_DONE);
89 else
90 printf("Error: example string wasn't recognized as UTF8!\n");
92 res = 0;
94 DROPINTERFACE(ICodesets);
95 CloseLibrary(CodesetsBase);
96 CodesetsBase = NULL;
98 else
100 printf("can't open %s %d+\n",CODESETSNAME,CODESETSVER);
101 res = 20;
104 return res;