File: ui_selection_encoding.c

package info (click to toggle)
mlterm 3.9.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 25,340 kB
  • sloc: ansic: 154,713; sh: 5,302; cpp: 2,953; objc: 2,776; java: 2,472; makefile: 2,445; perl: 1,674; xml: 44
file content (100 lines) | stat: -rw-r--r-- 1,798 bytes parent folder | download | duplicates (2)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* -*- c-basic-offset:2; tab-width:2; indent-tabs-mode:nil -*- */

#include "../ui_selection_encoding.h"

#include <stdio.h> /* NULL */
#include <vt_char_encoding.h>
#include <mef/ef_xct_parser.h>
#include <mef/ef_xct_conv.h>

/* --- static varaiables --- */

static ef_parser_t *utf_parser; /* leaked */
static ef_parser_t *parser; /* leaked */
static ef_conv_t *utf_conv; /* leaked */
static ef_conv_t *conv; /* leaked */

#ifdef USE_XLIB
static int big5_buggy;
#endif

/* --- global functions --- */

#ifdef USE_XLIB
void ui_set_big5_selection_buggy(int buggy) {
  big5_buggy = buggy;
}
#endif

ef_parser_t *ui_get_selection_parser(int utf) {
  if (utf) {
    if (!utf_parser) {
      if (!(utf_parser = vt_char_encoding_parser_new(VT_UTF8))) {
        return NULL;
      }
    }

    return utf_parser;
  } else {
    if (!parser) {
      if (!(parser = ef_xct_parser_new())) {
        return NULL;
      }
    }

    return parser;
  }
}

ef_conv_t *ui_get_selection_conv(int utf) {
  if (utf) {
    if (!utf_conv) {
      if (!(utf_conv = vt_char_encoding_conv_new(VT_UTF8))) {
        return NULL;
      }
    }

    return utf_conv;
  } else {
    if (!conv) {
#ifdef USE_XLIB
      if (big5_buggy) {
        if (!(conv = ef_xct_big5_buggy_conv_new())) {
          return NULL;
        }
      } else
#endif
      {
        if (!(conv = ef_xct_conv_new())) {
          return NULL;
        }
      }
    }

    return conv;
  }
}

#if 0
void ui_selection_encoding_final(void) {
  if (utf_parser) {
    (*utf_parser->destroy)(utf_parser);
    utf_parser = NULL;
  }

  if (parser) {
    (*parser->destroy)(parser);
    parser = NULL;
  }

  if (utf_conv) {
    (*utf_conv->destroy)(utf_conv);
    utf_conv = NULL;
  }

  if (conv) {
    (*conv->destroy)(conv);
    conv = NULL;
  }
}
#endif