dict.c
changeset 8 09ec33061ff3
parent 6 bc41369f4587
child 10 188a0e3b3fb4
--- a/dict.c	Mon Aug 13 23:45:46 2007 +0200
+++ b/dict.c	Tue Aug 14 22:18:46 2007 +0200
@@ -107,13 +107,13 @@
         case '8': return 60;
         case '9': return 61;
         case '+': return 62;
-        case '-': return 63;
+        case '/': return 63;
         default:
                   return 0;
     }
 }
 
-static int str2int(const char *str)
+int str2int(const char *str)
 {
     int i = 0;
     int length;
@@ -155,3 +155,45 @@
     fread(out, length, 1, fdefs);
     return out;
 }
+
+static char num_to_ia5char(int n)
+{
+    /* From RFC 1421 */
+    if (n >= 0 && n <= 25)
+        return 'A' + n;
+    else if (n >= 26 && n <= 51)
+        return 'a' + (n - 26);
+    else if (n >= 52 && n <= 61)
+        return '0' + (n - 52);
+    else if (n == 62)
+        return '+';
+    else if (n == 63)
+        return '/';
+    else
+        return '!'; /* Error */
+}
+
+int num_to_ia5(char *dest, int n)
+{
+    char tmp[20];
+
+    int i, max;
+   
+    for(i =0; i <= 10; ++i)
+    {
+        tmp[i] = num_to_ia5char(n % 64);
+        if (n < 64)
+            break;
+        n /= 64;
+    }
+
+    max = i;
+
+    /* reverse the number */
+    for (i=0; i<=max; ++i)
+        dest[i] = tmp[max-i];
+
+    /* Ending '\0' */
+    dest[max+1] = '\0';
+    return max;
+}