write.c
changeset 8 09ec33061ff3
parent 0 7f37716d4f1e
equal deleted inserted replaced
7:c815840c5b65 8:09ec33061ff3
     3 
     3 
     4 extern struct Word words[];
     4 extern struct Word words[];
     5 extern int nwords;
     5 extern int nwords;
     6 extern struct Def defs[];
     6 extern struct Def defs[];
     7 extern int ndefs;
     7 extern int ndefs;
     8 
       
     9 static char num_to_ia5char(int n)
       
    10 {
       
    11     /* From RFC 1421 */
       
    12     if (n >= 0 && n <= 25)
       
    13         return 'A' + n;
       
    14     else if (n >= 26 && n <= 51)
       
    15         return 'a' + (n - 26);
       
    16     else if (n >= 52 && n <= 61)
       
    17         return '0' + (n - 52);
       
    18     else if (n == 62)
       
    19         return '+';
       
    20     else if (n == 63)
       
    21         return '-';
       
    22     else
       
    23         return '!'; /* Error */
       
    24 }
       
    25 
       
    26 static int num_to_ia5(char *dest, int n)
       
    27 {
       
    28     char tmp[20];
       
    29 
       
    30     int i, max;
       
    31    
       
    32     for(i =0; i <= 10; ++i)
       
    33     {
       
    34         tmp[i] = num_to_ia5char(n % 64);
       
    35         if (n < 64)
       
    36             break;
       
    37         n /= 64;
       
    38     }
       
    39 
       
    40     max = i;
       
    41 
       
    42     /* reverse the number */
       
    43     for (i=0; i<=max; ++i)
       
    44         dest[i] = tmp[max-i];
       
    45 
       
    46     /* Ending '\0' */
       
    47     dest[max+1] = '\0';
       
    48     return max;
       
    49 }
       
    50 
     8 
    51 static int write_dictionary_data(FILE *fdefs)
     9 static int write_dictionary_data(FILE *fdefs)
    52 {
    10 {
    53     int i;
    11     int i;
    54 
    12