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)  

create_table.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 #include <wchar.h>
00027 #include <stdio.h>
00028 char buffer[1000000];
00029 
00030 /*** you can try to modifie this value to have better performences **/
00031 #define MAX_DELTA 0x80
00032 
00033 int main(int argc, char **argv) {
00034   char buf[80];
00035   int len;
00036   unsigned int i = 0;
00037   unsigned char *ptr;
00038   size_t nb;
00039   int nbb = 0;
00040   len = fread(buffer, 1, 1000000, stdin);
00041 
00042   buffer[len] = '\0';
00043   ptr = (unsigned char *)buffer;
00044   while (*ptr != '\n') ptr++;
00045   ptr++;
00046   while (*ptr != '\n') {
00047     if (*ptr == ',') nbb++;
00048     ptr++;
00049   }
00050   ptr = (unsigned char *)buffer;
00051   printf("/* %s */\n", argv[1]);
00052   while (len > 0) {
00053     unsigned int ucs = 0;
00054     char *p = ptr;
00055     char pp[20];
00056     nb = 0;
00057     pp[0] = '\0';
00058     while (*p != 'U') p++;
00059     strncat(pp, p, 6);
00060     *pp = '0';
00061     *(pp+1) = 'x';
00062     ucs = (unsigned int)strtoul(pp, NULL, 16);;
00063     if (ucs < 1) {
00064       printf("ERROR %d %d\n", len, ucs);
00065       abort();
00066     }
00067     if (i != ucs - 1 || !i) {
00068       if ((ucs - i) > MAX_DELTA || !i) {
00069         if (i) {
00070           printf("};\n");
00071           fprintf(stderr, "\t/* end: U+%04X */\n", i);
00072         }
00073         if (strcmp(argv[1], "spacing")) {
00074           printf("\nstatic const char unicode_to_%s_%db_%04X[] = {\n",
00075                  argv[1], nbb, ucs);
00076           fprintf(stderr, "unicode_to_%s_%db_%04X[]; ", 
00077                   argv[1], nbb, ucs);
00078         } else {
00079           printf("\nstatic const unsigned short"
00080                  " ucs_table_%04X[]"
00081                  " = {\n", ucs);
00082           fprintf(stderr, "ucs_table_%04X[]; ", ucs);
00083         }
00084       } else {
00085         while (i < ucs - 1) {
00086           i++;
00087           if (nbb == 1) {
00088             printf("0x00,\n");
00089           } else {
00090             printf("0x00, 0x00,\n");
00091           }
00092         };
00093       }
00094     }
00095     i = ucs;
00096     while (*ptr != '\n') {
00097       printf("%c", *ptr);
00098       ptr++;
00099       len--;
00100     }
00101     printf("\n");
00102     ptr++;
00103     len--;
00104   }
00105   printf("};\n");
00106   fprintf(stderr, "\t/* end: U+%04X */\n", i);
00107   return 0;
00108 }
00109 
00110 /*
00111  * End of "$Id$".
00112  */