grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / codesets / developer / examples / DetectCodeset.c
blob597fb60f8b33942f7ed6dedbe1f3bae95cfbd1d0
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 #define ISO8859_1_STR "Schmöre bröd, schmöre bröd, bröd bröd bräd."
33 #define CP1251_STR "1251 êîäèðîâêà äëÿ ïðèìåðà."
34 #define ASCII_STR "latin 1 bla bla bla."
35 #define KOI8R_STR "koi îÅ×ÏÚÍÏÖÎÏ ÐÅÒÅËÏÄÉÒÏ×ÁÔØ ÉÚ ËÏÄÉÒÏ×ËÉ"
37 struct Library *CodesetsBase = NULL;
38 #if defined(__amigaos4__)
39 struct CodesetsIFace* ICodesets = NULL;
40 #endif
42 #if defined(__amigaos4__)
43 #define GETINTERFACE(iface, base) (iface = (APTR)GetInterface((struct Library *)(base), "main", 1L, NULL))
44 #define DROPINTERFACE(iface) (DropInterface((struct Interface *)iface), iface = NULL)
45 #else
46 #define GETINTERFACE(iface, base) TRUE
47 #define DROPINTERFACE(iface)
48 #endif
50 int main(void)
52 int res;
54 if((CodesetsBase = OpenLibrary(CODESETSNAME,CODESETSVER)) &&
55 GETINTERFACE(ICodesets, CodesetsBase))
57 IPTR errNum = 0;
58 struct codeset *cs;
60 if((cs = CodesetsFindBest(CSA_Source, (IPTR)ISO8859_1_STR,
61 CSA_ErrPtr, (IPTR)&errNum,
62 TAG_DONE)))
64 printf("Identified ISO8859_1_STR as %s with %d of %d errors\n", cs->name, (int)errNum, (int)strlen(ISO8859_1_STR));
66 else
67 printf("couldn't identify ISO8859_1_STR!\n");
69 if((cs = CodesetsFindBest(CSA_Source, (IPTR)CP1251_STR,
70 CSA_ErrPtr, (IPTR)&errNum,
71 CSA_CodesetFamily, CSV_CodesetFamily_Cyrillic,
72 TAG_DONE)))
74 printf("Identified CP1251_STR as %s with %d of %d errors\n", cs->name, (int)errNum, (int)strlen(CP1251_STR));
76 else
77 printf("couldn't identify CP1251_STR!\n");
79 if((cs = CodesetsFindBest(CSA_Source, (IPTR)ASCII_STR,
80 CSA_ErrPtr, (IPTR)&errNum,
81 CSA_CodesetFamily, CSV_CodesetFamily_Cyrillic,
82 TAG_DONE)))
84 printf("Identified ASCII_STR as %s with %d of %d errors\n", cs->name, (int)errNum, (int)strlen(ASCII_STR));
86 else
87 printf("couldn't identify ASCII_STR!\n");
89 if((cs = CodesetsFindBest(CSA_Source, (IPTR)KOI8R_STR,
90 CSA_ErrPtr, (IPTR)&errNum,
91 CSA_CodesetFamily, CSV_CodesetFamily_Cyrillic,
92 TAG_DONE)))
94 printf("Identified KOI8R_STR as %s with %d of %d errors\n", cs->name, (int)errNum, (int)strlen(KOI8R_STR));
96 else
97 printf("couldn't identify KOI8R_STR!\n");
99 res = 0;
101 DROPINTERFACE(ICodesets);
102 CloseLibrary(CodesetsBase);
103 CodesetsBase = NULL;
105 else
107 printf("can't open %s %d+\n",CODESETSNAME,CODESETSVER);
108 res = 20;
111 return res;