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)  

conv_gen.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  *    generate the "if(){} else if ..." structure of ucs2fontmap()
00028  */
00029 #include <wchar.h>
00030 #include <stdio.h>
00031 char buffer[1000000];
00032 
00033 int main(int argc, char **argv) {
00034   char buf[80];
00035   int len;
00036   char *encode[256];
00037   int encode_number = 0;
00038   unsigned int i = 0;
00039   unsigned char *ptr;
00040   unsigned char *lst = "";
00041   size_t nb;
00042   int nbb = 0;
00043   len = fread(buffer, 1, 1000000, stdin);
00044 
00045   puts("  ");
00046   puts("   /*************** conv_gen.c ************/");
00047   buffer[len] = '\0';
00048   ptr = buffer;
00049   
00050   printf("const int ucs2fontmap"
00051           "(char *s, unsigned int ucs, int enc)\n");
00052   printf("{\n");
00053   printf("  switch(enc) {\n");
00054   printf("  case 0:\n");
00055   printf("    s[0] = (char) ((ucs & 0xFF00) >> 8);\n");
00056   printf("    s[1] = (char) (ucs & 0xFF);\n");
00057   printf("    return 0;");
00058   while (len > 0) {
00059     unsigned char *p = ptr;
00060     unsigned char *f, *t;
00061     
00062     while (*p != ']') {
00063       i++;
00064       p++;
00065     }
00066     *(p - 1) = '\0';
00067     *(p - 6) = '\0';
00068     f = p - 5;
00069     while (*p != '+') { i++; p++;}
00070     p++;
00071     t = p;
00072     *(p + 4) = '\0';
00073     if (strcmp(lst, ptr)) {
00074       encode_number++;
00075       encode[encode_number] = ptr;
00076       printf("\n    break;");
00077       printf("\n  case %d:\n", encode_number);
00078       printf("    ");
00079     } else {
00080       printf(" else ");
00081     }
00082     lst = ptr;
00083     printf("if (ucs <= 0x%s) {\n", t);
00084     printf("      if (ucs >= 0x%s) {\n", f);
00085     if (*(f - 3) == '2') {
00086       printf("        int i = (ucs - 0x%s) * 2;\n", f);
00087       printf("        s[0] = %s_%s[i++];\n", ptr, f, f);
00088       printf("        s[1] = %s_%s[i];\n", ptr, f, f);
00089       printf("        if (s[0] || s[1]) return %d;\n", encode_number);
00090     } else {
00091       printf("        s[0] = 0;\n");
00092       printf("        s[1] = %s_%s[ucs - 0x%s];\n", ptr, f, f);
00093       printf("        if (s[1]) return %d;\n", encode_number);
00094     }
00095     printf("      }\n");
00096     printf("    }");
00097     while (*ptr != '\n') {
00098       ptr++;
00099       len--;
00100     } 
00101     ptr++;
00102     len--;
00103   }
00104   printf("\n    break;\n");
00105   printf("\n  default:\n");
00106   printf("    break;\n");
00107   printf("  };\n");
00108   printf("  return -1;\n");
00109   printf("};\n\n");
00110 
00111   printf("const int encoding_number(const char *enc)\n{\n");
00112   printf("  if (!enc || !strcmp(enc, \"iso10646-1\")) {\n");
00113   printf("    return 0;\n");
00114   i = 1;
00115   while (i <= encode_number) {
00116     int l;
00117     char *ptr;
00118     l = strlen(encode[i]) - 3;
00119     ptr = encode[i] + l;
00120     *(ptr) = '\0';
00121     ptr--;
00122     while (ptr != encode[i]) {
00123       if (*ptr == '_') {
00124         *ptr = '-';
00125         ptr--;
00126         break;
00127       }
00128       ptr--;
00129     }
00130     while (ptr != encode[i]) {
00131       if (*ptr == '_') {
00132         *ptr = '.';
00133       }
00134       ptr--;
00135     }
00136     printf("  } else if (!strcmp(enc, \"%s\")", encode[i] +11);
00137 
00138     if (!strcmp(encode[i] + 11, "big5-0")) { 
00139       printf(" || !strcmp(enc, \"big5.eten-0\")");
00140     } else if (!strcmp(encode[i] + 11, "dingbats")) {
00141       printf(" || !strcmp(enc, \"zapfdingbats\")");
00142       printf(" || !strcmp(enc, \"zapf dingbats\")");
00143       printf(" || !strcmp(enc, \"itc zapf dingbats\")");
00144     } else if (!strcmp(encode[i] + 11, "jisx0208.1983-0")) {
00145       printf(" || !strcmp(enc, \"jisx0208.1990-0\")");
00146     }
00147 
00148     printf(") {\n");
00149     printf("    return %d;\n", i);
00150     i++;
00151   }
00152   printf("  };\n");     
00153   printf("  return -1;\n");     
00154   printf("};\n\n");     
00155 
00156   printf("/*\n");       
00157   printf("const char *encoding_name(int num)\n{\n");
00158   printf("  switch (num) {\n");
00159   i = 1;
00160   while (i <= encode_number) {
00161     printf("  case %d:\n", i);
00162     printf("    return \"%s\";\n", encode[i] + 11);
00163     i++;
00164   }
00165   printf("  };\n");
00166   printf("  return \"iso10646-1\";\n");
00167   printf("};\n\n");
00168   printf("*/\n");       
00169   return 0;
00170 }
00171 
00172 /*
00173  * End of "$Id$".
00174  */