int main(void) { int i; char *locale[8]; const char *cas; locale[0] = getenv("LANG"); locale[1] = "POSIX"; locale[2] = "C"; locale[3] = NULL; locale[4] = "ru"; locale[5] = "ru_RU"; locale[6] = ""; locale[7] = "ru_RU.UTF8"; setlocale(LC_ALL,""); printf("FIRST current charset (nl):%s\n", natspec_get_charset ()); printf("FIRST fileenc: %s\n",natspec_get_filename_encoding ("")); printf("user locale:%s\n",locale[0]); printf("current locale:%s\n",natspec_get_current_locale ()); printf("system locale:%s\n",natspec_get_system_locale ()); printf("current charset (nl):%s\n", natspec_get_charset ()); cas = natspec_get_charset_by_charset (NATSPEC_UNIXCS,NATSPEC_UNIXCS,NULL); printf("current charset:%s\n",cas); /*assert (!strcmp(cas, natspec_get_charset()));*/ for (i=0; i<sizeof(locale)/sizeof(char*); i++) { int j; printf("locale:'%s'\n",locale[i]); for (j = NATSPEC_UNIXCS; j<=NATSPEC_MACCS; j++) { const char *e = natspec_get_charset_by_locale(j,locale[i]); printf ("\tfor %d CS: '%s' (%s)\n", j, e, natspec_get_nls_by_charset(e)); } } printf("fileenc: %s\n",natspec_get_filename_encoding ("")); test_for_iconv(); test_nls(); test_for_enrich(); printf("SECOND current charset (nl):%s\n", natspec_get_charset ()); cas = setlocale(LC_ALL, ""); printf("old locale: %s\n",cas); test_for_convert(); test_for_natspec_iconv(); compliant_test(); printf("DONE\n"); return 0; }
int main(int argc, const char** argv) { int is_utf8; #if defined HAVE_LIBPOPT int rc = 0; poptContext poptCtx; poptCtx = poptGetContext("natspec", argc, (const char **)argv, options, 0); poptSetOtherOptionHelp(poptCtx, "[OPTION...]"); while (rc >= 0) { if((rc = poptGetNextOpt(poptCtx)) < -1) { fprintf(stderr, "Error on option %s: %s.\nRun '%s --help' to see a full list of available command line options.\n", poptBadOption(poptCtx, 0), poptStrerror(rc), argv[0]); exit(1); } } /* { int flag_help=1; if (argv) { while (poptPeekArg(poptCtx)) flag_help=0; //locale = (char *)poptGetArg(poptCtx); poptFreeContext(poptCtx); } */ if(flag_help) { poptPrintHelp(poptCtx, stdout, 0); exit(0); } #else fprintf(stderr, "Compiled without popt. Exit\n"); exit(1); #endif /* Print overall information by default */ if (argc == 1) info = 1; if (version || info) { printf("%s, compiled %s\n", PACKAGE_STRING,__DATE__); if (!info) exit(0); } if (transliterate) { char *str = NULL; if (argv) { #if defined HAVE_LIBPOPT while (poptPeekArg(poptCtx)) str = (char *)poptGetArg(poptCtx); poptFreeContext(poptCtx); #else fprintf(stderr, "Compiled without popt. Exit\n"); exit(1); #endif } if ( str != NULL) { setlocale(LC_ALL,""); str = natspec_convert_with_translit(str, "", transliterate); puts(str); } exit(0); } if (info) { printf(" === Overall locale information ===\n"); verbose = 1; } locale = natspec_get_current_locale(); if (get_user_locale || info) { VERBOSE("Current user locale: "); printf("%s", locale); if (verbose && !natspec_internal_get_locale_from_env()) printf(" (got from system locale)"); puts(""); } if (get_system_locale || info) { VERBOSE("System locale: "); printf("%s\n", natspec_get_system_locale()); if (!info) exit(0); } if (fsenc || info) { const char *buf; VERBOSE("Filename encoding in iconv/nls form: "); buf = natspec_get_filename_encoding(""); printf("%s\n",buf); if (!info) exit(0); } if (country_id || info) { int id; VERBOSE("Country ID (for DOS): "); id = -1; /* natspec_get_country_id(); */ printf("%d\n", id); if (!info) exit(0); } if (fcodepage || info) { int cp; VERBOSE("Codepage of DOS: "); cp = natspec_get_codepage_by_charset( natspec_get_charset_by_locale(NATSPEC_DOSCS, locale)); printf("%d\n", cp); if (!info) exit(0); } if (info) { char *types[]={"UNIX","WIN","DOS","MAC"}; int i; for (i=0; i<sizeof(types)/sizeof(char*);i++) get_charset(types[i]); setlocale(LC_ALL,""); printf("After setlocale:\n"); #ifdef HAVE_LANGINFO_H printf("\tnl_langinfo(CODESET): %s\n",nl_langinfo(CODESET)); #endif printf("\tnatspec_get_charset: %s\n",natspec_get_charset()); } if (charset_type) get_charset(charset_type); is_utf8 = natspec_locale_is_utf8(""); if (utf8 || info) { VERBOSE("Current locale is%sin UTF8 encoding\n",(is_utf8 ? " " : " NOT ")); if (!info) return is_utf8 ? 0 : 1; } return 0; }