~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000 MySQL AB
2
3
   This program is free software; you can redistribute it and/or modify
4
   it under the terms of the GNU General Public License as published by
5
   the Free Software Foundation; version 2 of the License.
6
7
   This program is distributed in the hope that it will be useful,
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
   GNU General Public License for more details.
11
12
   You should have received a copy of the GNU General Public License
13
   along with this program; if not, write to the Free Software
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
15
 */
16
17
/*
18
  Written by Alexander Barkov to check what 
19
  a charset is in your favorite web browser
20
*/
21
22
#include <my_global.h>
23
#include <m_ctype.h>
24
#include <my_sys.h>
25
#include <mysql_version.h>
26
27
#include <stdio.h>
28
29
typedef struct char_info_st 
30
{
31
  int cod;
32
  int srt;
33
  int uni;
34
  int low;
35
  int upp;
36
  int ctp;
37
} MY_CH;
38
39
static int chcmp(const void *vf, const void *vs)
40
{
41
  const MY_CH *f=vf;
42
  const MY_CH *s=vs;
43
  
44
  return f->srt-s->srt ? f->srt-s->srt : f->uni-s->uni;
45
}
46
47
static void print_cs(CHARSET_INFO *cs)
48
{
49
  uint  i;
50
  int   srt;
51
  int   clr=0;
52
  MY_CH ch[256];
53
    
54
  printf("<HTML>\n");
55
  printf("<HEAD>\n");
56
  printf("</HEAD>\n");
57
  printf("<BODY><PRE>\n");
58
  printf("Charset %s\n",cs->name);
59
60
  printf("<TABLE>\n");
61
  printf("<TR><TH>Code<TH>Uni<TH>Sort<TH>Ctype<TH>Ch<TH>Lo<TH>Up</TR>");
62
  
63
  for (i=0; i<256; i++)
64
  {
65
    ch[i].cod=i;
66
    ch[i].srt=cs->sort_order ? cs->sort_order[i] : i;
67
    ch[i].uni=cs->tab_to_uni[i];
68
    ch[i].low=cs->tab_to_uni[cs->to_lower[i]];
69
    ch[i].upp=cs->tab_to_uni[cs->to_upper[i]];
70
    ch[i].ctp=cs->ctype[i+1];
71
  }
72
  
73
  qsort(ch,256,sizeof(MY_CH),&chcmp);
74
  srt=ch[0].srt;
75
  
76
  for (i=0; i<256; i++)
77
  {
78
    clr = (srt!=ch[i].srt) ? !clr : clr;
79
    
80
    printf("<TR bgcolor=#%s>",clr ? "DDDDDD" : "EEEE99");
81
    printf("<TD>%02X",ch[i].cod);
82
    printf("<TD>%04X",ch[i].uni);
83
    printf("<TD>%02X",ch[i].srt);
84
    
85
    printf("<TD>%s%s%s%s%s%s%s%s",
86
    		ch[i].ctp & _MY_U ? "U" : "",
87
    		ch[i].ctp & _MY_L ? "L" : "",
88
    		ch[i].ctp & _MY_NMR ? "N" : "",
89
    		ch[i].ctp & _MY_SPC ? "S" : "",
90
    		ch[i].ctp & _MY_PNT ? "P" : "",
91
    		ch[i].ctp & _MY_CTR ? "C" : "",
92
    		ch[i].ctp & _MY_B ? "B" : "",
93
    		ch[i].ctp & _MY_X ? "X" : "");
94
    
95
    if ((ch[i].uni >= 0x80) && (ch[i].uni <= 0x9F))
96
    {
97
      /* 
98
       Control characters 0x0080..0x009F are dysplayed by some
99
       browers as if they were letters. Don't print them to
100
       avoid confusion.
101
      */
102
      printf("<TD>ctrl<TD>ctrl<TD>ctrl");
103
    }
104
    else
105
    {
106
      printf("<TD>&#%d;",ch[i].uni);
107
      printf("<TD>&#%d;",ch[i].low);
108
      printf("<TD>&#%d;",ch[i].upp);
109
    }
110
    printf("</TR>\n");
111
    srt=ch[i].srt;
112
  }
113
  printf("</TABLE>\n");
114
  printf("</PRE></BODY>\n");
115
  printf("</HTML>\n");
116
}
117
118
static void print_index()
119
{
120
  CHARSET_INFO **cs;
121
  int clr=0; 
122
  
123
  get_charset_by_name("",MYF(0));	/* To execute init_available_charsets */
124
  
125
  printf("All charsets\n");
126
  printf("<table border=1>\n");
127
  printf("<tr bgcolor=EEEE99><th>ID<th>Charset<th>Collation<th>Def<th>Bin<th>Com<th>Comment\n");
128
  for (cs=all_charsets ; cs < all_charsets+256; cs++)
129
  {
130
    if (!cs[0])
131
      continue;
132
    printf("<tr bgcolor=#%s><td><a href=\"?%s\">%d</a><td>%s<td>%s<td>%s<td>%s<td>%s<td>%s\n",
133
    	   (clr= !clr) ? "DDDDDD" : "EEEE99",
134
    	   cs[0]->name,cs[0]->number,cs[0]->csname,
135
    	   cs[0]->name,
136
    	   (cs[0]->state & MY_CS_PRIMARY)  ? "def " : "&nbsp;",
137
    	   (cs[0]->state & MY_CS_BINSORT)  ? "bin " : "&nbsp;",
138
    	   (cs[0]->state & MY_CS_COMPILED) ? "com " : "&nbsp;",
139
    	   cs[0]->comment);
140
  }
141
  printf("</table>\n");
142
}
143
144
int main(int argc, char **argv) {
145
  const char *the_set = NULL;
146
  int argcnt = 1;
147
  CHARSET_INFO *cs;
148
149
  if (getenv("SCRIPT_NAME"))
150
  {
151
    printf("Content-Type: text/html\r\n\r\n");
152
  }
153
  my_init();
154
155
  if (argc > argcnt && argv[argcnt][0] == '-' && argv[argcnt][1] == '#')
156
  {
157
    DBUG_PUSH(argv[argcnt++]+2);
158
  }
159
160
  if (argc > argcnt)
161
    the_set = argv[argcnt++];
162
163
  if (argc > argcnt)
164
    charsets_dir = argv[argcnt++];
165
166
  if (!the_set)
167
  {
168
    print_index();
169
    return 0;
170
  }
171
  
172
  if (!(cs= get_charset_by_name(the_set, MYF(MY_WME))))
173
    return 1;
174
175
  print_cs(cs);
176
177
  return 0;
178
}