File: rcc.c

package info (click to toggle)
moc 1%3A2.6.0~svn-r3005-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,656 kB
  • sloc: ansic: 31,749; sh: 929; cpp: 487; makefile: 240
file content (77 lines) | stat: -rw-r--r-- 1,494 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
 * MOC - music on console
 * Copyright (C) 2005,2011 Damian Pietras <daper@daper.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <stdlib.h>

#ifdef HAVE_RCC
# include <librcc.h>
#endif

#include <assert.h>

#include "rcc.h"

char *rcc_reencode (char *str)
{
	char *result = str;

	assert (str != NULL);

#ifdef HAVE_RCC
	rcc_string rccstring;

	rccstring = rccFrom (NULL, 0, str);
	if (rccstring) {
		if (*rccstring) {
			char *reencoded;

			reencoded = rccToCharset (NULL, "UTF-8", rccstring);
			if (reencoded) {
		    	free (result);
		    	result = reencoded;
			}
		}

		free (rccstring);
	}
#endif /* HAVE_RCC */

	return result;
}

void rcc_init ()
{
#ifdef HAVE_RCC
	rcc_class classes[] = {
		{"input", RCC_CLASS_STANDARD, NULL, NULL, "Input Encoding", 0},
		{"output", RCC_CLASS_KNOWN, NULL, NULL, "Output Encoding", 0},
		{NULL, 0, NULL, NULL, NULL, 0}
	};

	rccInit ();
	rccInitDefaultContext (NULL, 0, 0, classes, 0);
	rccLoad (NULL, "moc");
	rccSetOption (NULL, RCC_OPTION_TRANSLATE,
	                    RCC_OPTION_TRANSLATE_SKIP_PARRENT);
	rccSetOption (NULL, RCC_OPTION_AUTODETECT_LANGUAGE, 1);
#endif /* HAVE_RCC */
}

void rcc_cleanup ()
{
#ifdef HAVE_RCC
	rccFree ();
#endif /* HAVE_RCC */
}