Stunt: get codesetslib from its own Sourceforge repository.
[cake.git] / workbench / libs / codesetslib / developer / examples / DetectCodeset.c
blob5e17e763638ceea925e3655e6587880422ca6795
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-2007 by 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(int argc,char **argv)
52 int res;
54 if((CodesetsBase = OpenLibrary(CODESETSNAME,CODESETSVER)) &&
55 GETINTERFACE(ICodesets, CodesetsBase))
57 ULONG errNum = 0;
58 struct codeset *cs;
60 if((cs = CodesetsFindBest(CSA_Source, ISO8859_1_STR,
61 CSA_ErrPtr, &errNum,
62 TAG_DONE)))
64 printf("Identified ISO8859_1_STR as %s with %ld of %d errors\n", cs->name, errNum, strlen(ISO8859_1_STR));
66 else
67 printf("couldn't identify ISO8859_1_STR!\n");
69 if((cs = CodesetsFindBest(CSA_Source, CP1251_STR,
70 CSA_ErrPtr, &errNum,
71 CSA_CodesetFamily, CSV_CodesetFamily_Cyrillic,
72 TAG_DONE)))
74 printf("Identified CP1251_STR as %s with %ld of %d errors\n", cs->name, errNum, strlen(CP1251_STR));
76 else
77 printf("couldn't identify CP1251_STR!\n");
79 if((cs = CodesetsFindBest(CSA_Source, ASCII_STR,
80 CSA_ErrPtr, &errNum,
81 CSA_CodesetFamily, CSV_CodesetFamily_Cyrillic,
82 TAG_DONE)))
84 printf("Identified ASCII_STR as %s with %ld of %d errors\n", cs->name, errNum, strlen(ASCII_STR));
86 else
87 printf("couldn't identify ASCII_STR!\n");
89 if((cs = CodesetsFindBest(CSA_Source, KOI8R_STR,
90 CSA_ErrPtr, &errNum,
91 CSA_CodesetFamily, CSV_CodesetFamily_Cyrillic,
92 TAG_DONE)))
94 printf("Identified KOI8R_STR as %s with %ld of %d errors\n", cs->name, errNum, 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;