/* unicode-to-iscii.c * * Authors : Sandeep Patnaik (patnaik@students.iiit.net) * Sunil Mohan Adapa (sunilmohanadapa@postmark.net) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ #include #define uint16 unsigned short unsigned char iscii [] = { 0x20, 0xa1, 0xa2, 0xa3, 0x20, 0xa4, 0xa5, 0xa6, // 0x0900 0xa7, 0xa8, 0xa9, 0xaa, 0x20, 0xae, 0xab, 0xac, // 0x0908 0xad, 0xb2, 0xaf, 0xb0, 0xb1, 0xb3, 0xb4, 0xb5, // 0x0910 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, // 0x0918 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, // 0x0920 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, // 0x0928 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, // 0x0930 0xd7, 0xd8, 0x20, 0x20, 0xe9, 0x20, 0xda, 0xdb, // 0x0938 0xdc, 0xdd, 0xde, 0xdf, 0x20, 0xe3, 0xe0, 0xe1, // 0x0940 0xe2, 0xe7, 0xe4, 0xe5, 0xe6, 0xe8, 0x20, 0x20, // 0x0948 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, // 0x0950 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0xce, // 0x0958 0x20, 0x20, 0x20, 0x20, 0xea, 0x20, 0xf1, 0xf2, // 0x0960 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, // 0x0968 }; // 0x0970 int nukta[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0900 0x00, 0x00, 0x00, 0x00, 0xa6, 0x00, 0x00, 0x00, // 0x0908 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0910 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0918 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0920 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0928 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0930 0x00, 0x00, 0x00, 0x00, 0x00, 0xea, 0x00, 0x00, // 0x0938 0x00, 0x00, 0x00, 0x00, 0xdf, 0x00, 0x00, 0x00, // 0x0940 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0948 0xa1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0950 0xb3, 0xb4, 0xb5, 0xba, 0xbf, 0xc0, 0xc9, 0x00, // 0x0958 0xaa, 0xa7, 0xda, 0xdc, 0x00, 0x00, 0x00, 0x00, // 0x0960 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0968 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0970 }; unsigned char * unicode_to_iscii (uint16 * unicode_string) { uint16 unichar; int pos=0; static unsigned char * iscii_string = NULL; int length=0; while (unicode_string[length]) length++; if (iscii_string) free (iscii_string); iscii_string = (unsigned char *) malloc (sizeof(unsigned char) * (length+1)); while (length--) { unichar = *(unicode_string++); if (unichar >= 0x0900 & unichar <= 0x0970) { if (nukta [unichar & 0xff]) { iscii_string[pos++] = nukta[unichar & 0xff]; iscii_string[pos++] = 0xe9; // nukta } else { iscii_string[pos++] = iscii [unichar & 0xff]; } continue; } if (unichar <= 0xa0) // the ascii range iscii_string [pos++] = (unsigned char) unichar; } iscii_string[pos] = 0; return iscii_string; }