home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 15 / AACD15.ISO / AACD / Programming / Python2 / Python20_source / Modules / amigaunicodedatabase.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-10-25  |  4.8 KB  |  192 lines

  1. /* ------------------------------------------------------------------------
  2.  
  3.    unicodedatabase -- The Unicode 3.0 data base.
  4.  
  5.    Data was extracted from the Unicode 3.0 UnicodeData.txt file.
  6.  
  7. Written by Marc-Andre Lemburg (mal@lemburg.com).
  8.  
  9. Copyright (c) Corporation for National Research Initiatives.
  10.  
  11.    ------------------------------------------------------------------------ */
  12.  
  13. #include <exec/types.h>
  14. #include <proto/dos.h>
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <stdlib.h>
  18. #include <stat.h>
  19. #include "unicodedatabase.h"
  20.  
  21. /* --- Unicode category names --------------------------------------------- */
  22.  
  23. const char *_PyUnicode_CategoryNames[32] = {
  24.  
  25.     "Cn", /*  Not assigned (also see below) */
  26.  
  27.     /* Normative Categories */
  28.  
  29.     "Lu", /* Letter, Uppercase */
  30.     "Ll", /* Letter, Lowercase */
  31.     "Lt", /* Letter, Titlecase */
  32.     "Mn", /* Mark, Non-Spacing */
  33.     "Mc", /* Mark, Spacing Combining */
  34.     "Me", /* Mark, Enclosing */
  35.     "Nd", /* Number, Decimal Digit */
  36.     "Nl", /* Number, Letter */
  37.     "No", /* Number, Other */
  38.     "Zs", /* Separator, Space */
  39.     "Zl", /* Separator, Line */
  40.     "Zp", /* Separator, Paragraph */
  41.     "Cc", /* Other, Control */
  42.     "Cf", /* Other, Format */
  43.     "Cs", /* Other, Surrogate */
  44.     "Co", /* Other, Private Use */
  45.     "Cn", /* Other, Not Assigned (no characters in the file
  46.          have this property) */
  47.  
  48.      /* Informative Categories */
  49.  
  50.     "Lm", /* Letter, Modifier */
  51.     "Lo", /* Letter, Other */
  52.     "Pc", /* Punctuation, Connector */
  53.     "Pd", /* Punctuation, Dash */
  54.     "Ps", /* Punctuation, Open */
  55.     "Pe", /* Punctuation, Close */
  56.     "Pi", /* Punctuation, Initial quote (may behave like Ps or Pe 
  57.          depending on usage) */
  58.     "Pf", /* Punctuation, Final quote (may behave like Ps or Pe 
  59.          depending on usage) */
  60.     "Po", /* Punctuation, Other */
  61.     "Sm", /* Symbol, Math */
  62.     "Sc", /* Symbol, Currency */
  63.     "Sk", /* Symbol, Modifier */
  64.     "So", /* Symbol, Other */
  65.  
  66.     0  /* Sentinel */
  67. };
  68.  
  69. const char *_PyUnicode_BidirectionalNames[21] = {
  70.  
  71.     "",     /*  Undefined (added so that the 0 index maps to undefined) */
  72.     
  73.     "L", /* Left-to-Right */
  74.     "LRE", /* Left-to-Right Embedding */
  75.     "LRO", /* Left-to-Right Override */
  76.     "R", /* Right-to-Left */
  77.     "AL", /* Right-to-Left Arabic */
  78.     "RLE", /* Right-to-Left Embedding */
  79.     "RLO", /* Right-to-Left Override */
  80.     "PDF", /* Pop Directional Format */
  81.     "EN", /* European Number */
  82.     "ES", /* European Number Separator */
  83.     "ET", /* European Number Terminator */
  84.     "AN", /* Arabic Number */
  85.     "CS", /* Common Number Separator */
  86.     "NSM", /* Non-Spacing Mark */
  87.     "BN", /* Boundary Neutral */
  88.     "B", /* Paragraph Separator */
  89.     "S", /* Segment Separator */
  90.     "WS", /* Whitespace */
  91.     "ON", /* Other Neutrals */
  92.     
  93.     0  /* Sentinel */
  94. };
  95.  
  96.  
  97. /*** ORIGINAL:
  98. const _PyUnicode_DatabaseRecord *_PyUnicode_Database[16] = {
  99.     _PyUnicode_Database_0,
  100.     _PyUnicode_Database_1,
  101.     _PyUnicode_Database_2,
  102.     _PyUnicode_Database_3,
  103.     _PyUnicode_Database_4,
  104.     _PyUnicode_Database_5,
  105.     _PyUnicode_Database_6,
  106.     _PyUnicode_Database_7,
  107.     _PyUnicode_Database_8,
  108.     _PyUnicode_Database_9,
  109.     _PyUnicode_Database_10,
  110.     _PyUnicode_Database_11,
  111.     _PyUnicode_Database_12,
  112.     _PyUnicode_Database_13,
  113.     _PyUnicode_Database_14,
  114.     _PyUnicode_Database_15,
  115. };
  116. ***/
  117.  
  118. /*** On AMIGA: fill in later... ***/
  119. const _PyUnicode_DatabaseRecord *_PyUnicode_Database[16];
  120.  
  121. int init_Amiga_unicodedatabase(const char *path)
  122. {
  123.     static _PyUnicode_DatabaseRecord *database = NULL;
  124.     static char *strtable = NULL;
  125.  
  126.     if(database==NULL)
  127.     {
  128.         if(database = malloc(16 * 4096 * sizeof(_PyUnicode_DatabaseRecord)))
  129.         {
  130.             FILE *fh;
  131.             char file[512];
  132.             strcpy(file, path);
  133.             AddPart(file, "Unicode_DB.data", sizeof(file));
  134.  
  135.             fh = fopen(file, "rb");
  136.             if(fh)
  137.             {
  138.                 int siz = fread(database, 1, sizeof(_PyUnicode_DatabaseRecord) * 4096 * 16, fh);
  139.                 fclose(fh);
  140.                 if(siz>0)
  141.                 {
  142.                     int i;
  143.  
  144.                     for(i=0; i<16; i++)
  145.                     {
  146.                         _PyUnicode_Database[i] = 
  147.                             &database[i*4096];
  148.                     }
  149.  
  150.                     
  151.                     strcpy(file, path);
  152.                     AddPart(file, "Unicode_DB.strings", sizeof(file));
  153.                     fh = fopen(file,"rb");
  154.                     if(fh)
  155.                     {
  156.                         struct stat s;
  157.                         int siz;
  158.                         stat(file, &s);
  159.                         if(strtable = malloc(s.st_size))
  160.                         {
  161.                             siz=fread(strtable,1,s.st_size,fh);
  162.                             fclose(fh);
  163.                             if(siz==s.st_size)
  164.                             {
  165.                                 // FIXUP string pointers
  166.                                 for(i=0; i<16; i++)
  167.                                 {
  168.                                     int j;
  169.                                     for(j=0; j<4096; j++)
  170.                                     {
  171.                                         _PyUnicode_DatabaseRecord* rec = _PyUnicode_Database[i];
  172.                                         rec += j;
  173.                                         if(rec->decomposition)
  174.                                             rec->decomposition = strtable + (unsigned int)rec->decomposition;
  175.                                     }
  176.                                 }
  177.                                 return TRUE;
  178.                             }
  179.                         }
  180.                         else
  181.                             fclose(fh);
  182.                     }
  183.                 }
  184.             }
  185.             free(database);
  186.             database=NULL;
  187.         }
  188.         return FALSE;
  189.     }
  190.     return TRUE;    
  191. }
  192.