From a175314c3e5827eb193872241446f2f8f5c9d33c Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 4 May 2024 20:07:14 +0200 Subject: Adding upstream version 1:10.5.12. Signed-off-by: Daniel Baumann --- extra/charset2html.c | 179 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 extra/charset2html.c (limited to 'extra/charset2html.c') diff --git a/extra/charset2html.c b/extra/charset2html.c new file mode 100644 index 00000000..3a2b62d7 --- /dev/null +++ b/extra/charset2html.c @@ -0,0 +1,179 @@ +/* Copyright (c) 2000, 2002-2004, 2007, 2008 MySQL AB + Use is subject to license terms + + 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; version 2 of the License. + + 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA + */ + +/* + Written by Alexander Barkov to check what + a charset is in your favorite web browser +*/ + +#include +#include +#include +#include + +#include + +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("\n"); + printf("\n"); + printf("\n"); + printf("
\n");
+  printf("Charset %s\n",cs->name);
+
+  printf("\n");
+  printf("");
+  
+  for (i=0; i<256; i++)
+  {
+    ch[i].cod=i;
+    ch[i].srt=cs->sort_order ? cs->sort_order[i] : 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("",clr ? "DDDDDD" : "EEEE99");
+    printf("\n");
+    srt=ch[i].srt;
+  }
+  printf("
CodeUniSortCtypeChLoUp
%02X",ch[i].cod); + printf("%04X",ch[i].uni); + printf("%02X",ch[i].srt); + + printf("%s%s%s%s%s%s%s%s", + ch[i].ctp & _MY_U ? "U" : "", + ch[i].ctp & _MY_L ? "L" : "", + ch[i].ctp & _MY_NMR ? "N" : "", + ch[i].ctp & _MY_SPC ? "S" : "", + ch[i].ctp & _MY_PNT ? "P" : "", + ch[i].ctp & _MY_CTR ? "C" : "", + ch[i].ctp & _MY_B ? "B" : "", + ch[i].ctp & _MY_X ? "X" : ""); + + if ((ch[i].uni >= 0x80) && (ch[i].uni <= 0x9F)) + { + /* + Control characters 0x0080..0x009F are dysplayed by some + browsers as if they were letters. Don't print them to + avoid confusion. + */ + printf("ctrlctrlctrl"); + } + else + { + printf("&#%d;",ch[i].uni); + printf("&#%d;",ch[i].low); + printf("&#%d;",ch[i].upp); + } + printf("
\n"); + printf("
\n"); + printf("\n"); +} + +static void print_index() +{ + CHARSET_INFO **cs; + int clr=0; + + get_charset_by_name("",MYF(0)); /* To execute init_available_charsets */ + + printf("All charsets\n"); + printf("\n"); + printf("
IDCharsetCollationDefBinComComment\n"); + for (cs=all_charsets ; cs < all_charsets+256; cs++) + { + if (!cs[0]) + continue; + printf("
%d%s%s%s%s%s%s\n", + (clr= !clr) ? "DDDDDD" : "EEEE99", + cs[0]->name,cs[0]->number,cs[0]->csname, + cs[0]->name, + (cs[0]->state & MY_CS_PRIMARY) ? "def " : " ", + (cs[0]->state & MY_CS_BINSORT) ? "bin " : " ", + (cs[0]->state & MY_CS_COMPILED) ? "com " : " ", + cs[0]->comment); + } + printf("
\n"); +} + +int main(int argc, char **argv) { + const char *the_set = NULL; + int argcnt = 1; + CHARSET_INFO *cs; + + if (getenv("SCRIPT_NAME")) + { + printf("Content-Type: text/html\r\n\r\n"); + } + 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 (!the_set) + { + print_index(); + return 0; + } + + if (!(cs= get_charset_by_name(the_set, MYF(MY_WME)))) + return 1; + + print_cs(cs); + + return 0; +} -- cgit v1.2.3