fltk 1.3.0rc3
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X. Release candidate.
  SfR Fresh Dox: fltk-1.3.0rc3-source.tar.gz ("inofficial" and yet experimental doxygen-generated source code documentation)  

convert_map.c

Go to the documentation of this file.
00001 /* "$Id: $"
00002  *
00003  * Author: Jean-Marc Lienher ( http://oksid.ch )
00004  * Copyright 2000-2003 by O'ksi'D.
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00019  * USA.
00020  *
00021  * Please report all bugs and problems on the following page:
00022  *
00023  *     http://www.fltk.org/str.php
00024  */
00025 
00026 /*
00027  *    read the http://www.unicode.org/Public/MAPPINGS/ and create something
00028  *    usable in C.
00029  */
00030 
00031 #include <wchar.h>
00032 #include <stdio.h>
00033 
00034 char buffer[1000000];
00035 
00036 int JIS0208(unsigned char * ptr) {
00037   int i = 0;
00038   unsigned int fmap;
00039   unsigned int ucs;
00040   while(*ptr != '\t') { ptr++; i++; }
00041   ptr++; i++; *(ptr+6) = '\0';
00042   fmap = (unsigned int)strtoul(ptr, NULL, 16);
00043   while(*ptr != '\0') { ptr++; i++; }
00044   i++; ptr++; *(ptr+6) = '\0';
00045   ucs = (unsigned int)strtoul(ptr, NULL, 16);
00046   if (ucs) 
00047     printf("/* U+%04X */ 0x%02X, 0x%02X,\n", ucs, 
00048           (fmap & 0xFF00) >> 8, fmap & 0xFF);
00049   while(*ptr != '\0') { ptr++; i++; }
00050   i++; ptr++;
00051   while(*ptr != '\n') { ptr++; i++; }
00052   i++;
00053   return i;
00054 }
00055 
00056 int JIS0201(unsigned char * ptr) {
00057   int i = 0;
00058   unsigned int fmap;
00059   unsigned int ucs;
00060   *(ptr+4) = '\0';
00061   fmap = (unsigned int)strtoul(ptr, NULL, 16);
00062   while(*ptr != '\0') { ptr++; i++; }
00063   i++; ptr++; *(ptr+6) = '\0';
00064   ucs = (unsigned int)strtoul(ptr, NULL, 16);
00065   if (*(ptr + 1) != 'x') {
00066     printf("/* EOF */\n");
00067     abort();
00068   }
00069   if (ucs) printf("/* U+%04X */ 0x%02X,\n", ucs, (unsigned char)fmap);
00070   while(*ptr != '\0') { ptr++; i++; }
00071   i++; ptr++;
00072   while(*ptr != '\n') { ptr++; i++; }
00073   i++;
00074   return i;
00075 }
00076 
00077 int ADOBE(unsigned char * ptr) {
00078   int i = 0;
00079   unsigned int fmap;
00080   unsigned int ucs;
00081   *(ptr+4) = '\0';
00082   ucs = (unsigned int)strtoul(ptr, NULL, 16);
00083   while(*ptr != '\0') { ptr++; i++; }
00084   i++; ptr++; *(ptr+2) = '\0';
00085   fmap = (unsigned int)strtoul(ptr, NULL, 16);
00086   if (fmap < 1) {
00087     printf("/* EOF */\n");
00088     abort();
00089   }
00090   if (ucs) printf("/* U+%04X */ 0x%02X,\n", ucs, (unsigned char)fmap);
00091   while(*ptr != '\0') { ptr++; i++; }
00092   i++; ptr++;
00093   while(*ptr != '\n') { ptr++; i++; }
00094   i++;
00095   return i;
00096 }
00097 
00098 
00099 int JIS0212(unsigned char * ptr) {
00100   int i = 0;
00101   unsigned int fmap;
00102   unsigned int ucs;
00103   *(ptr+6) = '\0';
00104   fmap = (unsigned int)strtoul(ptr, NULL, 16);
00105   ptr += 7;
00106   i += 7;
00107   while(*ptr == ' ') { ptr++; i++; }
00108   //i++; ptr++; 
00109   *(ptr+6) = '\0';
00110   ucs = (unsigned int)strtoul(ptr, NULL, 16);
00111   if (*(ptr + 1) != 'x') {
00112     printf("/* EOF */\n");
00113     abort();
00114   }
00115   if (ucs)
00116     printf("/* U+%04X */ 0x%02X, 0x%02X,\n", ucs, 
00117           (fmap & 0xFF00) >> 8, fmap & 0xFF);
00118   while(*ptr != '\0') { ptr++; i++; }
00119   i++; ptr++;
00120   while(*ptr != '\n') { ptr++; i++; }
00121   i++;
00122   return i;
00123 }
00124 
00125 int main(int argc, char **argv) {
00126   char buf[80];
00127   int len;
00128   int i;
00129   unsigned char *ptr;
00130   size_t nb;
00131   len = fread(buffer, 1, 1000000, stdin);
00132 
00133   buffer[len] = '\0';
00134   ptr = (unsigned char *)buffer;
00135   while (*ptr !='\n') {ptr++; len--;};
00136   ptr++; len--;
00137   while (*ptr == '#') {
00138     while (*ptr !='\n') {
00139       ptr++;
00140       len--;
00141     }
00142     ptr++;
00143     len--;
00144   }
00145 
00146   while (len > 0) {
00147     nb = 0;
00148     if (!strcmp("jisx0208.1983-0", argv[1])) {
00149       nb = JIS0208(ptr);
00150     } else if (!strcmp("jisx0201.1976-0", argv[1])) {
00151       nb = JIS0201(ptr);
00152     } else if (!strcmp("jisx0212.1990-0", argv[1])) {
00153       nb = JIS0212(ptr);
00154     } else if (!strcmp("gb2312.1980-0", argv[1])) {
00155       nb = JIS0212(ptr);
00156     } else if (!strcmp("ksc5601.1987-0", argv[1])) {
00157       nb = JIS0212(ptr);
00158     } else if (!strcmp("big5-0", argv[1])) {
00159       nb = JIS0212(ptr);
00160     } else if (!strncmp("iso8859", argv[1], 7)) {
00161       nb = JIS0201(ptr);
00162     } else if (!strcmp("koi8-1", argv[1])) {
00163       nb = JIS0201(ptr);
00164     } else if (!strcmp("dingbats", argv[1]) ||
00165                !strcmp("symbol", argv[1])) 
00166     {
00167       nb = ADOBE(ptr);
00168     } else {
00169       len = 0;
00170     }
00171     ptr += nb;
00172     len = len - nb;
00173   }
00174   return 0;
00175 }
00176 
00177 /*
00178  * End of "$Id$".
00179  */