charset2html.c
上传用户:romrleung
上传日期:2022-05-23
资源大小:18897k
文件大小:4k
源码类别:

MySQL数据库

开发平台:

Visual C++

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