summaryrefslogtreecommitdiff
path: root/mysys/charset2html.c
blob: 0d6450a81160c4ac69e1077485c7e8b2902ed26c (plain)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* Copyright (C) 2000 MySQL AB

   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.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 */

/*
  Written by Alexander Barkov to check what 
  a charset is in your favorite web browser
*/

#include <my_global.h>
#include <m_ctype.h>
#include <my_sys.h>
#include <mysql_version.h>

#include <stdio.h>

typedef struct char_info_st 
{
  int cod;
  int srt;
  int uni;
  int low;
  int upp;
  int ctp;
} MY_CH;

static int chcmp(const void *vf, const void *vs)
{
  const MY_CH *f=vf;
  const MY_CH *s=vs;
  
  return f->srt-s->srt ? f->srt-s->srt : f->uni-s->uni;
}

static void print_cs(CHARSET_INFO *cs)
{
  uint  i;
  int   srt;
  int   clr=0;
  MY_CH ch[256];
    
  printf("<HTML>\n");
  printf("<HEAD>\n");
  printf("</HEAD>\n");
  printf("<BODY><PRE>\n");
  printf("Charset %s\n",cs->name);

  printf("<TABLE>\n");
  printf("<TR><TH>Code<TH>Uni<TH>Sort<TH>Ctype<TH>Ch<TH>Lo<TH>Up</TR>");
  
  for (i=0; i<256; i++)
  {
    ch[i].cod=i;
    ch[i].srt=cs->sort_order[i];
    ch[i].uni=cs->tab_to_uni[i];
    ch[i].low=cs->tab_to_uni[cs->to_lower[i]];
    ch[i].upp=cs->tab_to_uni[cs->to_upper[i]];
    ch[i].ctp=cs->ctype[i+1];
  }
  
  qsort(ch,256,sizeof(MY_CH),&chcmp);
  srt=ch[0].srt;
  
  for (i=0; i<256; i++)
  {
    clr = (srt!=ch[i].srt) ? !clr : clr;
    
    printf("<TR bgcolor=#%s>",clr ? "DDDDDD" : "EEEE99");
    printf("<TD>%02X",ch[i].cod);
    printf("<TD>%04X",ch[i].uni);
    printf("<TD>%d",ch[i].srt);
    
    printf("<TD>%s%s%s%s%s%s%s%s",
    		ch[i].ctp & _U ? "U" : "",
    		ch[i].ctp & _L ? "L" : "",
    		ch[i].ctp & _NMR ? "N" : "",
    		ch[i].ctp & _SPC ? "S" : "",
    		ch[i].ctp & _PNT ? "P" : "",
    		ch[i].ctp & _CTR ? "C" : "",
    		ch[i].ctp & _B ? "B" : "",
    		ch[i].ctp & _X ? "X" : "");
    
    printf("<TD>&#%d;",ch[i].uni);
    printf("<TD>&#%d;",ch[i].low);
    printf("<TD>&#%d;",ch[i].upp);
    printf("</TR>\n");
    srt=ch[i].srt;
  }
  printf("</TABLE>\n");
  printf("</PRE></BODY>\n");
  printf("</HTML>\n");
}


int main(int argc, char **argv) {
  const char *the_set = MYSQL_CHARSET;
  int argcnt = 1;

  my_init();

  if (argc > argcnt && argv[argcnt][0] == '-' && argv[argcnt][1] == '#')
    DBUG_PUSH(argv[argcnt++]+2);

  if (argc > argcnt)
    the_set = argv[argcnt++];

  if (argc > argcnt)
    charsets_dir = argv[argcnt++];

  if (set_default_charset_by_name(the_set, MYF(MY_WME)))
    return 1;

  print_cs(default_charset_info);

  return 0;
}