1 /*
2  * MOC - music on console
3  * Copyright (C) 2005,2011 Damian Pietras <daper@daper.net>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  */
11 
12 #ifdef HAVE_CONFIG_H
13 # include "config.h"
14 #endif
15 
16 #include <stdlib.h>
17 
18 #ifdef HAVE_RCC
19 # include <librcc.h>
20 #endif
21 
22 #include <assert.h>
23 
24 #include "rcc.h"
25 
rcc_reencode(char * str)26 char *rcc_reencode (char *str)
27 {
28 	char *result = str;
29 
30 	assert (str != NULL);
31 
32 #ifdef HAVE_RCC
33 	rcc_string rccstring;
34 
35 	rccstring = rccFrom (NULL, 0, str);
36 	if (rccstring) {
37 		if (*rccstring) {
38 			char *reencoded;
39 
40 			reencoded = rccToCharset (NULL, "UTF-8", rccstring);
41 			if (reencoded) {
42 		    	free (result);
43 		    	result = reencoded;
44 			}
45 		}
46 
47 		free (rccstring);
48 	}
49 #endif /* HAVE_RCC */
50 
51 	return result;
52 }
53 
rcc_init()54 void rcc_init ()
55 {
56 #ifdef HAVE_RCC
57 	rcc_class classes[] = {
58 		{"input", RCC_CLASS_STANDARD, NULL, NULL, "Input Encoding", 0},
59 		{"output", RCC_CLASS_KNOWN, NULL, NULL, "Output Encoding", 0},
60 		{NULL, 0, NULL, NULL, NULL, 0}
61 	};
62 
63 	rccInit ();
64 	rccInitDefaultContext (NULL, 0, 0, classes, 0);
65 	rccLoad (NULL, "moc");
66 	rccSetOption (NULL, RCC_OPTION_TRANSLATE,
67 	                    RCC_OPTION_TRANSLATE_SKIP_PARRENT);
68 	rccSetOption (NULL, RCC_OPTION_AUTODETECT_LANGUAGE, 1);
69 #endif /* HAVE_RCC */
70 }
71 
rcc_cleanup()72 void rcc_cleanup ()
73 {
74 #ifdef HAVE_RCC
75 	rccFree ();
76 #endif /* HAVE_RCC */
77 }
78