~ubuntu-branches/ubuntu/hoary/flac/hoary

« back to all changes in this revision

Viewing changes to src/share/utf8/makemap.c

  • Committer: Bazaar Package Importer
  • Author(s): Matt Zimmerman
  • Date: 2004-04-16 15:14:31 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040416151431-eyloggqxpwbwpogz
Tags: 1.1.0-11
Ensure that libFLAC is linked with -lm on all architectures, and
regardless of whether nasm is present

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2001 Edmund Grimley Evans <edmundo@rano.org>
 
3
 * 
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 2 of the License, or
 
7
 * (at your option) any later version.
 
8
 * 
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 * 
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
 */
 
18
 
 
19
#include <errno.h>
 
20
#include <iconv.h>
 
21
#include <stdio.h>
 
22
 
 
23
int main(int argc, char *argv[])
 
24
{
 
25
  iconv_t cd;
 
26
  const char *ib;
 
27
  char *ob;
 
28
  size_t ibl, obl, k;
 
29
  unsigned char c, buf[4];
 
30
  int i, wc;
 
31
 
 
32
  if (argc != 2) {
 
33
    printf("Usage: %s ENCODING\n", argv[0]);
 
34
    printf("Output a charset map for the 8-bit ENCODING.\n");
 
35
    return 1;
 
36
  }
 
37
 
 
38
  cd = iconv_open("UCS-4", argv[1]);
 
39
  if (cd == (iconv_t)(-1)) {
 
40
    perror("iconv_open");
 
41
    return 1;
 
42
  }
 
43
 
 
44
  for (i = 0; i < 256; i++) {
 
45
    c = i;
 
46
    ib = &c;
 
47
    ibl = 1;
 
48
    ob = buf;
 
49
    obl = 4;
 
50
    k = iconv(cd, &ib, &ibl, &ob, &obl);
 
51
    if (!k && !ibl && !obl) {
 
52
      wc = (buf[0] << 24) + (buf[1] << 16) + (buf[2] << 8) + buf[3];
 
53
      if (wc >= 0xffff) {
 
54
        printf("Dodgy value.\n");
 
55
        return 1;
 
56
      }
 
57
    }
 
58
    else if (k == (size_t)(-1) && errno == EILSEQ)
 
59
      wc = 0xffff;
 
60
    else {
 
61
      printf("Non-standard iconv.\n");
 
62
      return 1;
 
63
    }
 
64
 
 
65
    if (i % 8 == 0)
 
66
      printf("  ");
 
67
    printf("0x%04x", wc);
 
68
    if (i == 255)
 
69
      printf("\n");
 
70
    else if (i % 8 == 7)
 
71
      printf(",\n");
 
72
    else
 
73
      printf(", ");
 
74
  }
 
75
 
 
76
  return 0;
 
77
}