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.
25 ***************************************************************************/
27 #include <proto/exec.h>
28 #include <proto/codesets.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
;
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)
46 #define GETINTERFACE(iface, base) TRUE
47 #define DROPINTERFACE(iface)
54 if((CodesetsBase
= OpenLibrary(CODESETSNAME
,CODESETSVER
)) &&
55 GETINTERFACE(ICodesets
, CodesetsBase
))
60 if((cs
= CodesetsFindBest(CSA_Source
, (IPTR
)ISO8859_1_STR
,
61 CSA_ErrPtr
, (IPTR
)&errNum
,
64 printf("Identified ISO8859_1_STR as %s with %d of %d errors\n", cs
->name
, (int)errNum
, (int)strlen(ISO8859_1_STR
));
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
,
74 printf("Identified CP1251_STR as %s with %d of %d errors\n", cs
->name
, (int)errNum
, (int)strlen(CP1251_STR
));
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
,
84 printf("Identified ASCII_STR as %s with %d of %d errors\n", cs
->name
, (int)errNum
, (int)strlen(ASCII_STR
));
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
,
94 printf("Identified KOI8R_STR as %s with %d of %d errors\n", cs
->name
, (int)errNum
, (int)strlen(KOI8R_STR
));
97 printf("couldn't identify KOI8R_STR!\n");
101 DROPINTERFACE(ICodesets
);
102 CloseLibrary(CodesetsBase
);
107 printf("can't open %s %d+\n",CODESETSNAME
,CODESETSVER
);