Main Page | Compound List | File List | Compound Members | File Members

example2.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>
#include <librcc.h>

Functions

int main (int argc, char *argv[])

Function Documentation

int main int  argc,
char *  argv[]
 

00009                                  {
00010     rcc_language_id language_id, current_language_id, english_language_id;
00011     rcc_string rccstring;
00012     const char *language;
00013     char buf[255];
00014     char *recoded;
00015     
00016     rcc_class classes[] = {
00017         { "input", RCC_CLASS_STANDARD, NULL, NULL, "Input Encoding", 0 },
00018         { "output", RCC_CLASS_TRANSLATE_LOCALE, "LC_CTYPE", NULL, "Output Encoding", 0 },
00019         { NULL }
00020     };
00021 
00022     setlocale(LC_ALL, "");
00023     
00024     rccInit();
00025     rccInitDefaultContext(NULL, 0, 0, classes, 0);
00026     rccInitDb4(NULL, "example", 0);
00027     rccSetOption(NULL, RCC_OPTION_TRANSLATE, RCC_OPTION_TRANSLATE_SKIP_PARRENT);
00028 
00029     current_language_id = rccGetCurrentLanguage(NULL);
00030     english_language_id = rccGetLanguageByName(NULL, "en");
00031     if (argc>1) rccSetLanguageByName(NULL, argv[1]);
00032     else rccSetOption(NULL, RCC_OPTION_AUTODETECT_LANGUAGE, 1);
00033     language_id = rccGetCurrentLanguage(NULL);
00034 
00035     language = rccGetCurrentLanguageName(NULL);
00036     if (language) printf("Current Language: %s\n\n", language);
00037     else {
00038         printf("Unable Detect Language, using english\n\n");
00039         rccSetLanguageByName(NULL, "en");
00040     }
00041     
00042     while (fgets(buf,255,stdin)) {
00043         if (strlen(buf)<2) break;
00044         
00045         rccstring = rccFrom(NULL, 0, buf);
00046         if (rccstring) {
00047             recoded = rccTo(NULL, 1, rccstring);
00048             if (recoded) {
00049                 printf(recoded);
00050                 free(recoded);
00051             } else printf("Recoding from UTF-8 is failed\n");
00052             free(rccstring);
00053         } else printf("Recoding to UTF-8 is failed\n");
00054     }
00055 
00056     rccFree();
00057 
00058     return 0;
00059 }


Generated on Thu Aug 11 01:55:29 2005 for LibRCC by doxygen 1.3.3