int main(int argc,char*argv[]) /* Main .. */ { VIOFONTINFO font; UCHAR b[1<<17]; UCHAR *buf = b; UCHAR *fname; UCHAR *tail; UCHAR *dir = NULL; UCHAR fnamebuf[MAXPATHLEN]; UCHAR tailbuf[MAXPATHLEN]; UCHAR dirbuf[MAXPATHLEN]; FILE*file; APIRET rc; int c; printf("tFont v1.2 by Tomas ™gren <*****@*****.**>, Ilya Zakharevich\n\n"); fflush(stdout); if (((ULONG)buf) & 0xFFFF) buf += 0x10000 - (((ULONG)buf) & 0xFFFF); opterr = 0; while ((c = getopt (argc, argv, "dfws")) != EOF) switch (c) { case 'd': opt_displayonly = 1; break; case 'w': opt_write = 1; break; case 'f': opt_force = 1; break; case 's': opt_autosize = 1; break; default: usage (); } if (!opt_displayonly) if (argc - optind != 1 && (!opt_autosize || argc - optind != 2)) usage (); font.cb=sizeof(font); /* How large is this structure */ font.type=0; /* Dunno, If you know what it is, mail me! */ font.cbData=65535; /* How large is my buffer? */ font.pbData=_emx_32to16(buf); /* Wants an 16:16 pointer, converting */ rc=VioGetFont (&font,0); /* Retrieve data for current font */ if (rc) { PrintError(rc); return 2; } fname = argv[optind]; if (opt_autosize) { if (optind >= argc - 1) { unsigned long lst[3]; unsigned long len; if (DosQueryCp(sizeof(lst), lst, &len) == 0 && len >= 1) { sprintf(tailbuf, "cp%lu.fnt", lst[0]); tail = tailbuf; } else { printf("Failure to query codepage!\n"); return 1; } } else tail = argv[optind+1]; sprintf(dirbuf, "%s/%dx%d", fname, font.cyCell, font.cxCell); dir = dirbuf; sprintf(fnamebuf, "%s/%dx%d/%s", fname, font.cyCell, font.cxCell, tail); fname = fnamebuf; } if (opt_write) { if (dir) { rc = mkdir(argv[optind], 0777); /* Ignore the error, dir may exists. */ rc = mkdir(dir, 0777); /* Ignore the error, dir may exists. */ } if ((file=fopen(fname,"wb"))==NULL) { printf("Error opening file '%s'!\n", fname); return 1; } if (fwrite(buf, font.cbData, 1, file) != 1) { printf("Error writing to file '%s'!\n", fname); return 1; } if (fclose(file) != 0) { printf("Error closing file '%s'!\n", fname); return 1; } return 0; } if (!opt_displayonly) if ((file=fopen(fname,"rb"))==NULL) { printf("Error opening file '%s'!\n", fname); return 1; } printf("Fontsize: %lux%lu\nTotal bytes needed for font: %lu",font.cxCell, font.cyCell, font.cbData); if (opt_displayonly) exit(0); if (filesize(file)!=font.cbData) { printf(", size of %s is %u",fname,filesize(file)); if (!opt_force) { if (RUSure("\nFilesize differs from size needed for the font..\nInstall anyway?")==0) { printf("Aborting...\n"); exit(1); } } } printf("\n"); fread(buf,1,font.cbData,file); fclose(file); rc=VioSetFont(&font,0); /* Put it all back.. */ if (rc) { PrintError(rc); return 1; } printf("All Ok, font '%s' installed successfully.\n",fname); }
STATIC #endif const char * locale_charset (void) { const char *codeset; const char *aliases; #if !(defined WINDOWS_NATIVE || defined OS2) # if HAVE_LANGINFO_CODESET /* Most systems support nl_langinfo (CODESET) nowadays. */ codeset = nl_langinfo (CODESET); # ifdef __CYGWIN__ /* Cygwin < 1.7 does not have locales. nl_langinfo (CODESET) always returns "US-ASCII". Return the suffix of the locale name from the environment variables (if present) or the codepage as a number. */ if (codeset != NULL && strcmp (codeset, "US-ASCII") == 0) { const char *locale; static char buf[2 + 10 + 1]; locale = getenv ("LC_ALL"); if (locale == NULL || locale[0] == '\0') { locale = getenv ("LC_CTYPE"); if (locale == NULL || locale[0] == '\0') locale = getenv ("LANG"); } if (locale != NULL && locale[0] != '\0') { /* If the locale name contains an encoding after the dot, return it. */ const char *dot = strchr (locale, '.'); if (dot != NULL) { const char *modifier; dot++; /* Look for the possible @... trailer and remove it, if any. */ modifier = strchr (dot, '@'); if (modifier == NULL) return dot; if (modifier - dot < sizeof (buf)) { memcpy (buf, dot, modifier - dot); buf [modifier - dot] = '\0'; return buf; } } } /* Woe32 has a function returning the locale's codepage as a number: GetACP(). This encoding is used by Cygwin, unless the user has set the environment variable CYGWIN=codepage:oem (which very few people do). Output directed to console windows needs to be converted (to GetOEMCP() if the console is using a raster font, or to GetConsoleOutputCP() if it is using a TrueType font). Cygwin does this conversion transparently (see winsup/cygwin/fhandler_console.cc), converting to GetConsoleOutputCP(). This leads to correct results, except when SetConsoleOutputCP has been called and a raster font is in use. */ sprintf (buf, "CP%u", GetACP ()); codeset = buf; } # endif # else /* On old systems which lack it, use setlocale or getenv. */ const char *locale = NULL; /* But most old systems don't have a complete set of locales. Some (like SunOS 4 or DJGPP) have only the C locale. Therefore we don't use setlocale here; it would return "C" when it doesn't support the locale name the user has set. */ # if 0 locale = setlocale (LC_CTYPE, NULL); # endif if (locale == NULL || locale[0] == '\0') { locale = getenv ("LC_ALL"); if (locale == NULL || locale[0] == '\0') { locale = getenv ("LC_CTYPE"); if (locale == NULL || locale[0] == '\0') locale = getenv ("LANG"); } } /* On some old systems, one used to set locale = "iso8859_1". On others, you set it to "language_COUNTRY.charset". In any case, we resolve it through the charset.alias file. */ codeset = locale; # endif #elif defined WINDOWS_NATIVE static char buf[2 + 10 + 1]; /* Woe32 has a function returning the locale's codepage as a number: GetACP(). When the output goes to a console window, it needs to be provided in GetOEMCP() encoding if the console is using a raster font, or in GetConsoleOutputCP() encoding if it is using a TrueType font. But in GUI programs and for output sent to files and pipes, GetACP() encoding is the best bet. */ sprintf (buf, "CP%u", GetACP ()); codeset = buf; #elif defined OS2 const char *locale; static char buf[2 + 10 + 1]; ULONG cp[3]; ULONG cplen; /* Allow user to override the codeset, as set in the operating system, with standard language environment variables. */ locale = getenv ("LC_ALL"); if (locale == NULL || locale[0] == '\0') { locale = getenv ("LC_CTYPE"); if (locale == NULL || locale[0] == '\0') locale = getenv ("LANG"); } if (locale != NULL && locale[0] != '\0') { /* If the locale name contains an encoding after the dot, return it. */ const char *dot = strchr (locale, '.'); if (dot != NULL) { const char *modifier; dot++; /* Look for the possible @... trailer and remove it, if any. */ modifier = strchr (dot, '@'); if (modifier == NULL) return dot; if (modifier - dot < sizeof (buf)) { memcpy (buf, dot, modifier - dot); buf [modifier - dot] = '\0'; return buf; } } /* Resolve through the charset.alias file. */ codeset = locale; } else { /* OS/2 has a function returning the locale's codepage as a number. */ if (DosQueryCp (sizeof (cp), cp, &cplen)) codeset = ""; else { sprintf (buf, "CP%u", cp[0]); codeset = buf; } } #endif if (codeset == NULL) /* The canonical name cannot be determined. */ codeset = ""; /* Resolve alias. */ for (aliases = get_charset_aliases (); *aliases != '\0'; aliases += strlen (aliases) + 1, aliases += strlen (aliases) + 1) if (strcmp (codeset, aliases) == 0 || (aliases[0] == '*' && aliases[1] == '\0')) { codeset = aliases + strlen (aliases) + 1; break; } /* Don't return an empty string. GNU libc and GNU libiconv interpret the empty string as denoting "the locale's character encoding", thus GNU libiconv would call this function a second time. */ if (codeset[0] == '\0') codeset = "ASCII"; return codeset; }
const char * _g_locale_charset_raw (void) { const char *codeset; #if !(defined WIN32 || defined OS2) # if HAVE_LANGINFO_CODESET /* Most systems support nl_langinfo (CODESET) nowadays. */ codeset = nl_langinfo (CODESET); # else /* On old systems which lack it, use setlocale or getenv. */ const char *locale = NULL; /* But most old systems don't have a complete set of locales. Some (like SunOS 4 or DJGPP) have only the C locale. Therefore we don't use setlocale here; it would return "C" when it doesn't support the locale name the user has set. */ # if HAVE_SETLOCALE && 0 locale = setlocale (LC_CTYPE, NULL); # endif if (locale == NULL || locale[0] == '\0') { locale = getenv ("LC_ALL"); if (locale == NULL || locale[0] == '\0') { locale = getenv ("LC_CTYPE"); if (locale == NULL || locale[0] == '\0') locale = getenv ("LANG"); } } /* On some old systems, one used to set locale = "iso8859_1". On others, you set it to "language_COUNTRY.charset". In any case, we resolve it through the charset.alias file. */ codeset = locale; # endif #elif defined WIN32 static char buf[2 + 10 + 1]; /* Woe32 has a function returning the locale's codepage as a number. */ sprintf (buf, "CP%u", GetACP ()); codeset = buf; #elif defined OS2 const char *locale; static char buf[2 + 10 + 1]; ULONG cp[3]; ULONG cplen; /* Allow user to override the codeset, as set in the operating system, with standard language environment variables. */ locale = getenv ("LC_ALL"); if (locale == NULL || locale[0] == '\0') { locale = getenv ("LC_CTYPE"); if (locale == NULL || locale[0] == '\0') locale = getenv ("LANG"); } if (locale != NULL && locale[0] != '\0') { /* If the locale name contains an encoding after the dot, return it. */ const char *dot = strchr (locale, '.'); if (dot != NULL) { const char *modifier; dot++; /* Look for the possible @... trailer and remove it, if any. */ modifier = strchr (dot, '@'); if (modifier == NULL) return dot; if (modifier - dot < sizeof (buf)) { memcpy (buf, dot, modifier - dot); buf [modifier - dot] = '\0'; return buf; } } /* Resolve through the charset.alias file. */ codeset = locale; } else { /* OS/2 has a function returning the locale's codepage as a number. */ if (DosQueryCp (sizeof (cp), cp, &cplen)) codeset = ""; else { sprintf (buf, "CP%u", cp[0]); codeset = buf; } } #endif return codeset; }
STATIC #endif const char * locale_charset (void) { const char *codeset; const char *aliases; /* Force output encoding, particularly useful for redirected output on win32 where charset detection fails when no actual console is attached. */ const char *forced_encoding = getenv("GETTEXTIOENCODING"); if (forced_encoding) return forced_encoding; #if !(defined WINDOWS_NATIVE || defined OS2) # if HAVE_LANGINFO_CODESET /* Most systems support nl_langinfo (CODESET) nowadays. */ codeset = nl_langinfo (CODESET); # ifdef __CYGWIN__ /* Cygwin < 1.7 does not have locales. nl_langinfo (CODESET) always returns "US-ASCII". Return the suffix of the locale name from the environment variables (if present) or the codepage as a number. */ if (codeset != NULL && strcmp (codeset, "US-ASCII") == 0) { const char *locale; static char buf[2 + 10 + 1]; locale = getenv ("LC_ALL"); if (locale == NULL || locale[0] == '\0') { locale = getenv ("LC_CTYPE"); if (locale == NULL || locale[0] == '\0') locale = getenv ("LANG"); } if (locale != NULL && locale[0] != '\0') { /* If the locale name contains an encoding after the dot, return it. */ const char *dot = strchr (locale, '.'); if (dot != NULL) { const char *modifier; dot++; /* Look for the possible @... trailer and remove it, if any. */ modifier = strchr (dot, '@'); if (modifier == NULL) return dot; if (modifier - dot < sizeof (buf)) { memcpy (buf, dot, modifier - dot); buf [modifier - dot] = '\0'; return buf; } } } /* The Windows API has a function returning the locale's codepage as a number: GetACP(). This encoding is used by Cygwin, unless the user has set the environment variable CYGWIN=codepage:oem (which very few people do). Output directed to console windows needs to be converted (to GetOEMCP() if the console is using a raster font, or to GetConsoleOutputCP() if it is using a TrueType font). Cygwin does this conversion transparently (see winsup/cygwin/fhandler_console.cc), converting to GetConsoleOutputCP(). This leads to correct results, except when SetConsoleOutputCP has been called and a raster font is in use. */ sprintf (buf, "CP%u", GetACP ()); codeset = buf; } # endif # else /* On old systems which lack it, use setlocale or getenv. */ const char *locale = NULL; /* But most old systems don't have a complete set of locales. Some (like SunOS 4 or DJGPP) have only the C locale. Therefore we don't use setlocale here; it would return "C" when it doesn't support the locale name the user has set. */ # if 0 locale = setlocale (LC_CTYPE, NULL); # endif if (locale == NULL || locale[0] == '\0') { locale = getenv ("LC_ALL"); if (locale == NULL || locale[0] == '\0') { locale = getenv ("LC_CTYPE"); if (locale == NULL || locale[0] == '\0') locale = getenv ("LANG"); } } /* On some old systems, one used to set locale = "iso8859_1". On others, you set it to "language_COUNTRY.charset". In any case, we resolve it through the charset.alias file. */ codeset = locale; # endif #elif defined WINDOWS_NATIVE static char buf[2 + 10 + 1]; /* The Windows API has a function returning the locale's codepage as a number, but the value doesn't change according to what the 'setlocale' call specified. So we use it as a last resort, in case the string returned by 'setlocale' doesn't specify the codepage. */ char *current_locale = setlocale (LC_ALL, NULL); char *pdot; /* If they set different locales for different categories, 'setlocale' will return a semi-colon separated list of locale values. To make sure we use the correct one, we choose LC_CTYPE. */ if (strchr (current_locale, ';')) current_locale = setlocale (LC_CTYPE, NULL); pdot = strrchr (current_locale, '.'); if (pdot) sprintf (buf, "CP%s", pdot + 1); else { /* The Windows API has a function returning the locale's codepage as a number: GetACP(). When the output goes to a console window, it needs to be provided in GetOEMCP() encoding if the console is using a raster font, or in GetConsoleOutputCP() encoding if it is using a TrueType font. But in GUI programs and for output sent to files and pipes, GetACP() encoding is the best bet. */ sprintf (buf, "CP%u", GetACP ()); } codeset = buf; #elif defined OS2 const char *locale; static char buf[2 + 10 + 1]; ULONG cp[3]; ULONG cplen; codeset = NULL; /* Allow user to override the codeset, as set in the operating system, with standard language environment variables. */ locale = getenv ("LC_ALL"); if (locale == NULL || locale[0] == '\0') { locale = getenv ("LC_CTYPE"); if (locale == NULL || locale[0] == '\0') locale = getenv ("LANG"); } if (locale != NULL && locale[0] != '\0') { /* If the locale name contains an encoding after the dot, return it. */ const char *dot = strchr (locale, '.'); if (dot != NULL) { const char *modifier; dot++; /* Look for the possible @... trailer and remove it, if any. */ modifier = strchr (dot, '@'); if (modifier == NULL) return dot; if (modifier - dot < sizeof (buf)) { memcpy (buf, dot, modifier - dot); buf [modifier - dot] = '\0'; return buf; } } /* For the POSIX locale, don't use the system's codepage. */ if (strcmp (locale, "C") == 0 || strcmp (locale, "POSIX") == 0) codeset = ""; } if (codeset == NULL) { /* OS/2 has a function returning the locale's codepage as a number. */ if (DosQueryCp (sizeof (cp), cp, &cplen)) codeset = ""; else { sprintf (buf, "CP%u", cp[0]); codeset = buf; } } #endif if (codeset == NULL) /* The canonical name cannot be determined. */ codeset = ""; /* Resolve alias. */ for (aliases = get_charset_aliases (); *aliases != '\0'; aliases += strlen (aliases) + 1, aliases += strlen (aliases) + 1) if (strcmp (codeset, aliases) == 0 || (aliases[0] == '*' && aliases[1] == '\0')) { codeset = aliases + strlen (aliases) + 1; break; } /* Don't return an empty string. GNU libc and GNU libiconv interpret the empty string as denoting "the locale's character encoding", thus GNU libiconv would call this function a second time. */ if (codeset[0] == '\0') codeset = "ASCII"; #ifdef DARWIN7 /* Mac OS X sets MB_CUR_MAX to 1 when LC_ALL=C, and "UTF-8" (the default codeset) does not work when MB_CUR_MAX is 1. */ if (strcmp (codeset, "UTF-8") == 0 && MB_CUR_MAX_L (uselocale (NULL)) <= 1) codeset = "ASCII"; #endif return codeset; }
STATIC #endif const char * locale_charset (void) { const char *codeset; const char *aliases; #if !(defined WIN32_NATIVE || defined OS2) # if HAVE_LANGINFO_CODESET /* Most systems support nl_langinfo (CODESET) nowadays. */ codeset = nl_langinfo (CODESET); # ifdef __CYGWIN__ /* Cygwin 2006 does not have locales. nl_langinfo (CODESET) always returns "US-ASCII". As long as this is not fixed, return the suffix of the locale name from the environment variables (if present) or the codepage as a number. */ if (codeset != NULL && strcmp (codeset, "US-ASCII") == 0) { const char *locale; static char buf[2 + 10 + 1]; locale = getenv ("LC_ALL"); if (locale == NULL || locale[0] == '\0') { locale = getenv ("LC_CTYPE"); if (locale == NULL || locale[0] == '\0') locale = getenv ("LANG"); } if (locale != NULL && locale[0] != '\0') { /* If the locale name contains an encoding after the dot, return it. */ const char *dot = strchr (locale, '.'); if (dot != NULL) { const char *modifier; dot++; /* Look for the possible @... trailer and remove it, if any. */ modifier = strchr (dot, '@'); if (modifier == NULL) return dot; if (modifier - dot < sizeof (buf)) { memcpy (buf, dot, modifier - dot); buf [modifier - dot] = '\0'; return buf; } } } /* Woe32 has a function returning the locale's codepage as a number. */ sprintf (buf, "CP%u", GetACP ()); codeset = buf; } # endif # else /* On old systems which lack it, use setlocale or getenv. */ const char *locale = NULL; /* But most old systems don't have a complete set of locales. Some (like SunOS 4 or DJGPP) have only the C locale. Therefore we don't use setlocale here; it would return "C" when it doesn't support the locale name the user has set. */ # if 0 locale = setlocale (LC_CTYPE, NULL); # endif if (locale == NULL || locale[0] == '\0') { locale = getenv ("LC_ALL"); if (locale == NULL || locale[0] == '\0') { locale = getenv ("LC_CTYPE"); if (locale == NULL || locale[0] == '\0') locale = getenv ("LANG"); } } /* On some old systems, one used to set locale = "iso8859_1". On others, you set it to "language_COUNTRY.charset". In any case, we resolve it through the charset.alias file. */ codeset = locale; # endif #elif defined WIN32_NATIVE //static char buf[2 + 10 + 1]; /* Woe32 has a function returning the locale's codepage as a number. */ //sprintf (buf, "CP%u", GetACP ()); codeset = "CP20127"; #elif defined OS2 const char *locale; static char buf[2 + 10 + 1]; ULONG cp[3]; ULONG cplen; /* Allow user to override the codeset, as set in the operating system, with standard language environment variables. */ locale = getenv ("LC_ALL"); if (locale == NULL || locale[0] == '\0') { locale = getenv ("LC_CTYPE"); if (locale == NULL || locale[0] == '\0') locale = getenv ("LANG"); } if (locale != NULL && locale[0] != '\0') { /* If the locale name contains an encoding after the dot, return it. */ const char *dot = strchr (locale, '.'); if (dot != NULL) { const char *modifier; dot++; /* Look for the possible @... trailer and remove it, if any. */ modifier = strchr (dot, '@'); if (modifier == NULL) return dot; if (modifier - dot < sizeof (buf)) { memcpy (buf, dot, modifier - dot); buf [modifier - dot] = '\0'; return buf; } } /* Resolve through the charset.alias file. */ codeset = locale; } else { /* OS/2 has a function returning the locale's codepage as a number. */ if (DosQueryCp (sizeof (cp), cp, &cplen)) codeset = ""; else { sprintf (buf, "CP%u", cp[0]); codeset = buf; } } #endif if (codeset == NULL) /* The canonical name cannot be determined. */ codeset = ""; /* Resolve alias. */ for (aliases = get_charset_aliases (); *aliases != '\0'; aliases += strlen (aliases) + 1, aliases += strlen (aliases) + 1) if (strcmp (codeset, aliases) == 0 || (aliases[0] == '*' && aliases[1] == '\0')) { codeset = aliases + strlen (aliases) + 1; break; } /* Don't return an empty string. GNU libc and GNU libiconv interpret the empty string as denoting "the locale's character encoding", thus GNU libiconv would call this function a second time. */ if (codeset[0] == '\0') codeset = "ASCII"; return codeset; }
enum set_encoding_id encoding_from_locale(void) { char *l = NULL; enum set_encoding_id encoding = S_ENC_INVALID; #if defined(_WIN32) || defined(MSDOS) || defined(OS2) #ifdef HAVE_LOCALE_H char * cp_str; l = setlocale(LC_CTYPE, ""); /* preserve locale string, skip language information */ if ((l != NULL) && (cp_str = strchr(l, '.')) != NULL) { unsigned cp; cp_str++; /* Step past the dot in, e.g., German_Germany.1252 */ cp = strtoul(cp_str, NULL, 10); if (cp != 0) encoding = map_codepage_to_encoding(cp); } #endif #ifdef _WIN32 /* get encoding from currently active codepage */ if (encoding == S_ENC_INVALID) { #ifndef WGP_CONSOLE encoding = map_codepage_to_encoding(GetACP()); #else encoding = map_codepage_to_encoding(GetConsoleCP()); #endif } #endif #ifdef OS2 if (encoding == S_ENC_INVALID) { ULONG cplist[4]; ULONG listsize = sizeof(cplist); ULONG count; APIRET rc; rc = DosQueryCp(listsize, cplist, &count); if (rc == 0 && count > 0) encoding = map_codepage_to_encoding(cplist[0]); } #endif #elif defined(HAVE_LOCALE_H) if (encoding == S_ENC_INVALID) { l = setlocale(LC_CTYPE, ""); if (l && (strstr(l, "utf") || strstr(l, "UTF"))) encoding = S_ENC_UTF8; if (l && (strstr(l, "sjis") || strstr(l, "SJIS") || strstr(l, "932"))) encoding = S_ENC_SJIS; if (l && (strstr(l, "850") || strstr(l, "858"))) encoding = S_ENC_CP850; if (l && (strstr(l, "437"))) encoding = S_ENC_CP437; if (l && (strstr(l, "852"))) encoding = S_ENC_CP852; if (l && (strstr(l, "1250"))) encoding = S_ENC_CP1250; if (l && (strstr(l, "1251"))) encoding = S_ENC_CP1251; if (l && (strstr(l, "1252"))) encoding = S_ENC_CP1252; if (l && (strstr(l, "1254"))) encoding = S_ENC_CP1254; if (l && (strstr(l, "950"))) encoding = S_ENC_CP950; /* FIXME: "set encoding locale" has only limited support on non-Windows systems */ } #endif return encoding; }
int __mbinit( int codepage ) { #ifdef __NT__ CPINFO cpInfo; BOOL rc; #elif defined __OS2__ COUNTRYCODE countryInfo; unsigned short leadBytes[6]; APIRET rc; OS_UINT buf[8]; OS_UINT bytes; #elif defined __OSI__ #elif defined __DOS__ unsigned short __far *leadBytes; #elif defined __WINDOWS__ DWORD version; #elif defined __LINUX__ #elif defined __RDOS__ #endif clear_dbcs_table(); /*** Handle values from _setmbcp ***/ if( codepage == _MBINIT_CP_ANSI ) { #ifdef __NT__ codepage = GetACP(); #else codepage = 0; #endif } else if( codepage == _MBINIT_CP_OEM ) { #ifdef __NT__ codepage = GetOEMCP(); #else codepage = 0; #endif } else if( codepage == _MBINIT_CP_SBCS ) { return( 0 ); } else if( codepage == _MBINIT_CP_932 ) { _set_dbcs_table( 0x81, 0x9F ); _set_dbcs_table( 0xE0, 0xFC ); __IsDBCS = 1; __MBCodePage = 932; return( 0 ); } #ifdef __NT__ /*** Initialize the __MBCSIsTable values ***/ if( codepage == 0 ) codepage = CP_OEMCP; rc = GetCPInfo( codepage, &cpInfo ); /* get code page info */ if( rc == FALSE ) return( 1 ); set_dbcs_table( (unsigned short *)cpInfo.LeadByte ); /*** Update __MBCodePage ***/ if( codepage == CP_OEMCP ) { __MBCodePage = GetOEMCP(); } else { __MBCodePage = codepage; } #elif defined __OS2__ /*** Initialize the __MBCSIsTable values ***/ countryInfo.country = 0; /* default country */ countryInfo.codepage = codepage; /* specified code page */ #if defined(__WARP__) rc = DosQueryDBCSEnv( sizeof( leadBytes ), &countryInfo, (PCHAR)leadBytes ); #else rc = DosGetDBCSEv( sizeof( leadBytes ), &countryInfo, (PCHAR)leadBytes ); #endif if( rc != 0 ) return( 1 ); set_dbcs_table( leadBytes ); /*** Update __MBCodePage ***/ if( codepage == 0 ) { #if defined(__386__) || defined(__PPC__) rc = DosQueryCp( sizeof( buf ), &buf, &bytes ); #else rc = DosGetCp( sizeof( buf ), &buf, &bytes ); #endif if( rc != 0 ) { __MBCodePage = 0; } else { __MBCodePage = (unsigned int)buf[0]; } } else { __MBCodePage = codepage; } #elif defined __OSI__ #elif defined __DOS__ /*** Initialize the __MBCSIsTable values ***/ if( codepage != 0 ) return( 1 ); /* can only handle default */ leadBytes = dos_get_dbcs_lead_table(); if( leadBytes == NULL ) return( 0 ); set_dbcs_table( leadBytes ); __MBCodePage = dos_get_code_page(); #elif defined __WINDOWS__ /*** Initialize the __MBCSIsTable values ***/ if( codepage != 0 ) return( 1 ); /* can only handle default */ version = GetVersion(); if( LOWORD(version) < 0x0A03 ) return( 1 ); /* 3.1+ needed */ set_dbcs_table(); __MBCodePage = GetKBCodePage(); #elif defined __LINUX__ #elif defined __RDOS__ #endif return( 0 ); /* return success code */ }
vlc_bool_t vlc_current_charset( char **psz_charset ) { const char *psz_codeset; #if !(defined WIN32 || defined OS2) # if HAVE_LANGINFO_CODESET /* Most systems support nl_langinfo( CODESET ) nowadays. */ psz_codeset = nl_langinfo( CODESET ); # else /* On old systems which lack it, use setlocale or getenv. */ const char *psz_locale = NULL; /* But most old systems don't have a complete set of locales. Some * (like SunOS 4 or DJGPP) have only the C locale. Therefore we don't * use setlocale here; it would return "C" when it doesn't support the * locale name the user has set. Darwin's setlocale is broken. */ # if HAVE_SETLOCALE && !SYS_DARWIN psz_locale = setlocale( LC_ALL, NULL ); # endif if( psz_locale == NULL || psz_locale[0] == '\0' ) { psz_locale = getenv( "LC_ALL" ); if( psz_locale == NULL || psz_locale[0] == '\0' ) { psz_locale = getenv( "LC_CTYPE" ); if( psz_locale == NULL || psz_locale[0] == '\0') psz_locale = getenv( "LANG" ); } } /* On some old systems, one used to set locale = "iso8859_1". On others, * you set it to "language_COUNTRY.charset". Darwin only has LANG :( */ psz_codeset = vlc_encoding_from_locale( (char *)psz_locale ); # endif /* HAVE_LANGINFO_CODESET */ #elif defined WIN32 static char buf[2 + 10 + 1]; /* Woe32 has a function returning the locale's codepage as a number. */ sprintf( buf, "CP%u", GetACP() ); psz_codeset = buf; #elif defined OS2 const char *psz_locale; static char buf[2 + 10 + 1]; ULONG cp[3]; ULONG cplen; /* Allow user to override the codeset, as set in the operating system, * with standard language environment variables. */ psz_locale = getenv( "LC_ALL" ); if( psz_locale == NULL || psz_locale[0] == '\0' ) { psz+locale = getenv( "LC_CTYPE" ); if( psz_locale == NULL || locale[0] == '\0' ) locale = getenv( "LANG" ); } if( psz_locale != NULL && psz_locale[0] != '\0' ) psz_codeset = vlc_encoding_from_locale( psz_locale ); else { /* OS/2 has a function returning the locale's codepage as a number. */ if( DosQueryCp( sizeof( cp ), cp, &cplen ) ) psz_codeset = ""; else { sprintf( buf, "CP%u", cp[0] ); psz_codeset = buf; } } #endif if( psz_codeset == NULL ) /* The canonical name cannot be determined. */ psz_codeset = ""; else psz_codeset = vlc_charset_aliases( psz_codeset ); /* Don't return an empty string. GNU libc and GNU libiconv interpret * the empty string as denoting "the locale's character encoding", * thus GNU libiconv would call this function a second time. */ if( psz_codeset[0] == '\0' ) { /* Last possibility is 'CHARSET' enviroment variable */ if( !( psz_codeset = getenv( "CHARSET" ) ) ) psz_codeset = "ISO-8859-1"; } if( psz_charset ) *psz_charset = strdup((char *)psz_codeset); if( !strcasecmp(psz_codeset, "UTF8") || !strcasecmp(psz_codeset, "UTF-8") ) return VLC_TRUE; return VLC_FALSE; }
MRESULT EXPENTRY miscMainWinProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { static HPS hpsMain; static ULONG lCodePage; static LONG lFontHeight, lAveWidth; static LONG desk_cx, desk_cy; RECTL rectl; HWND hwndEditorWin, hwndEditorClient; ULONG flCreate; FONTDLG fontDlg; char szFamilyname[FACESIZE]; char szExmpl[128]; ULONG stringID[NUM_MAINTEXT] = {IDS_MAINTEXT1, IDS_MAINTEXT2, IDS_MAINTEXT3 }; static char* sText=NULL; static char* sTextEnjoy; void setFont( HWND hwnd, HPS hps, PFATTRS pAttrs ); switch(msg) { case WM_CREATE: { int i; SIZEL sizl; HDC hdc; HWND hwndFrame; ULONG dataLength; char buf[BUFSIZ]; LONG x,y,cx,cy; /* Read message text */ for (i = 0; i < NUM_MAINTEXT; i++) { WinLoadString( hab, NULLHANDLE, stringID[i], sizeof(buf), buf ); if( sText == NULL ) { sText = malloc(strlen(buf)+1); *sText = '\0'; } else sText = realloc( sText, strlen(sText)+strlen(buf)+1 ); strcat( sText, buf ); } WinLoadString( hab, NULLHANDLE, IDS_TEXTENJOY, sizeof(buf), buf ); sTextEnjoy = malloc( strlen(buf)+1 ); strcpy( sTextEnjoy, buf ); sizl.cx = 0L; sizl.cy = 0L; hdc = WinOpenWindowDC( hwnd ); hpsMain = GpiCreatePS( hab, hdc, (PSIZEL)&sizl, (ULONG)PU_PELS | GPIT_MICRO | GPIA_ASSOC ); /* Query the environment */ DosQueryCp( sizeof(lCodePage), &lCodePage, &dataLength ); GetFontSize( hpsMain, &lAveWidth, &lFontHeight ); hwndFrame = WinQueryWindow(hwnd, QW_PARENT); desk_cx = WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN ); desk_cy = WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN ); /* set window width to show maximum 40 SBCS characters */ cx = (lAveWidth*MAIN_WIN_WIDTH>desk_cx) ? desk_cx : lAveWidth*MAIN_WIN_WIDTH; /* set window height large enough to show a string pointed to by sText.*/ cy = (((strlen(sText)/MAIN_WIN_WIDTH)+10)*lFontHeight>desk_cy) ? desk_cy : ((strlen(sText)/40) + 10)*lFontHeight; x = (cx<desk_cx) ? (desk_cx-cx)/2 : 0; y = (cy<desk_cy) ? (desk_cy-cy)/2 : 0; WinSetWindowPos(hwndFrame, HWND_BOTTOM, x, y, cx, cy, SWP_MOVE | SWP_SIZE | SWP_ACTIVATE); return(MRESULT)(FALSE); } case WM_COMMAND: switch (SHORT1FROMMP(mp1)) { case MID_CONV: /* CPCONV */ { WinDlgBox(HWND_DESKTOP, hwnd, (PFNWP) cpConvDlgProc, NULLHANDLE, DID_CONV, &lCodePage); break; } case MID_EDITOR: /* Simple Editor */ flCreate= FCF_SIZEBORDER | FCF_MENU | FCF_MAXBUTTON | FCF_MINBUTTON | FCF_SYSMENU | FCF_TITLEBAR | FCF_DBE_APPSTAT; hwndEditorWin = WinCreateStdWindow(HWND_DESKTOP, WS_VISIBLE, &flCreate, "editorWindow", "Simple Editor", 0L, NULLHANDLE, WID_EDITOR, (PHWND) & hwndEditorClient); WinSetWindowPos(hwndEditorWin, HWND_BOTTOM, 190, 130, 500, 300, SWP_MOVE | SWP_SIZE | SWP_ACTIVATE); break; case MID_WORD: /* Word Break */ { WinDlgBox(HWND_DESKTOP, hwnd, (PFNWP) wordDlgProc, NULLHANDLE, DID_WORD, &lCodePage); break; } case MID_EXIT: /* Exit */ WinSendMsg (hwnd, WM_CLOSE,mp1,mp2); break; } break; case WM_PAINT: { int i; LONG lTotLen, lWrittenLen, lDrawn; SWP swp; WinBeginPaint( hwnd, hpsMain, (PRECTL)&rectl ); /* Always update whole window - CS_SIZEREDRAW? */ WinQueryWindowPos( hwnd, &swp ); rectl.xLeft = rectl.yBottom = 0; rectl.xRight = swp.cx; rectl.yTop = swp.cy; WinFillRect( hpsMain, (PRECTL) &rectl, CLR_BACKGROUND ); lTotLen = (LONG)strlen(sText); /* make some space between the text and the frame window */ rectl.xLeft+=lAveWidth; rectl.xRight-=lAveWidth; rectl.yTop-=lFontHeight; for (lWrittenLen = 0; lWrittenLen != lTotLen; rectl.yTop -= lFontHeight) { lDrawn = WinDrawText( hpsMain, lTotLen - lWrittenLen, sText+lWrittenLen, &rectl, 0L, 0L, DT_WORDBREAK | DT_TOP | DT_LEFT | DT_TEXTATTRS); if( lDrawn != 0 ) lWrittenLen += lDrawn; else break; } rectl.yTop -= lFontHeight; WinDrawText( hpsMain, strlen(sTextEnjoy), sTextEnjoy, &rectl, CLR_RED, CLR_BACKGROUND, DT_TOP | DT_CENTER ); WinEndPaint( hpsMain ); break; } case WM_DESTROY: GpiDestroyPS( hpsMain ); break; default: return(WinDefWindowProc(hwnd,msg,mp1,mp2)); } return(MRFROMLONG(NULL)); }
STATIC #endif const char * locale_charset () { const char *codeset; const char *aliases; #if !(defined WIN32 || defined OS2) # if HAVE_LANGINFO_CODESET codeset = nl_langinfo (CODESET); # else const char *locale = NULL; # if HAVE_SETLOCALE && 0 locale = setlocale (LC_CTYPE, NULL); # endif if (locale == NULL || locale[0] == '\0') { locale = getenv ("LC_ALL"); if (locale == NULL || locale[0] == '\0') { locale = getenv ("LC_CTYPE"); if (locale == NULL || locale[0] == '\0') locale = getenv ("LANG"); } } codeset = locale; # endif #elif defined WIN32 static char buf[2 + 10 + 1]; sprintf (buf, "CP%u", GetACP ()); codeset = buf; #elif defined OS2 const char *locale; static char buf[2 + 10 + 1]; ULONG cp[3]; ULONG cplen; locale = getenv ("LC_ALL"); if (locale == NULL || locale[0] == '\0') { locale = getenv ("LC_CTYPE"); if (locale == NULL || locale[0] == '\0') locale = getenv ("LANG"); } if (locale != NULL && locale[0] != '\0') { const char *dot = strchr (locale, '.'); if (dot != NULL) { const char *modifier; dot++; modifier = strchr (dot, '@'); if (modifier == NULL) return dot; if (modifier - dot < sizeof (buf)) { memcpy (buf, dot, modifier - dot); buf [modifier - dot] = '\0'; return buf; } } codeset = locale; } else { if (DosQueryCp (sizeof (cp), cp, &cplen)) codeset = ""; else { sprintf (buf, "CP%u", cp[0]); codeset = buf; } } #endif if (codeset == NULL) codeset = ""; for (aliases = get_charset_aliases (); *aliases != '\0'; aliases += strlen (aliases) + 1, aliases += strlen (aliases) + 1) if (strcmp (codeset, aliases) == 0 || (aliases[0] == '*' && aliases[1] == '\0')) { codeset = aliases + strlen (aliases) + 1; break; } if (codeset[0] == '\0') codeset = "ASCII"; return codeset; }
/* * Map from process codepage to default charset */ int16 INTL_MenuFontCSID(void) { ULONG codepage, xxx; DosQueryCp(4, &codepage, &xxx); return INTL_MapCpToCsNum(codepage); }
STATIC #endif /* STATIC */ const char * locale_charset(void) { const char *codeset; const char *aliases; #if !(defined WINDOWS_NATIVE || defined OS2) # if HAVE_LANGINFO_CODESET && defined(HAVE_NL_LANGINFO) /* Most systems support nl_langinfo(CODESET) nowadays. */ codeset = nl_langinfo(CODESET); # ifdef __CYGWIN__ /* Cygwin < 1.7 does not have locales. nl_langinfo(CODESET) always * returns "US-ASCII". Return the suffix of the locale name from the * environment variables (if present) or the codepage as a number. */ if ((codeset != NULL) && strcmp(codeset, "US-ASCII") == 0) { const char *locale; static char buf[(2 + 10 + 1)]; /* why not just 13? */ locale = getenv("LC_ALL"); if ((locale == NULL) || (locale[0] == '\0')) { locale = getenv("LC_CTYPE"); if ((locale == NULL) || (locale[0] == '\0')) { locale = getenv("LANG"); } } if ((locale != NULL) && (locale[0] != '\0')) { /* If the locale name contains an encoding after the dot, then return * it. */ const char *dot = strchr(locale, '.'); if (dot != NULL) { const char *modifier; dot++; /* Look for the possible @... trailer and remove it, if any. */ modifier = strchr(dot, '@'); if (modifier == NULL) { return dot; } if ((modifier - dot) < sizeof(buf)) { memcpy(buf, dot, (modifier - dot)); buf[(modifier - dot)] = '\0'; return buf; } } } /* The Windows API has a function returning the locale's codepage as a * number: GetACP(). This encoding is used by Cygwin, unless the user * has set the environment variable CYGWIN=codepage:oem (which very few * people do). * Output directed to console windows needs to be converted (to * GetOEMCP() if the console is using a raster font, or to * GetConsoleOutputCP() if it is using a TrueType font). Cygwin does * this conversion transparently (see winsup/cygwin/fhandler_console.cc), * converting to GetConsoleOutputCP(). This leads to correct results, * except when SetConsoleOutputCP has been called and a raster font is * in use. */ sprintf(buf, "CP%u", GetACP()); codeset = buf; } # endif /* __CYGWIN__ */ # else /* !HAVE_LANGINFO_CODESET || !HAVE_NL_LANGINFO: */ /* On old systems which lack it, use setlocale or getenv. */ const char *locale = NULL; /* But most old systems do NOT have a complete set of locales. Some * (like SunOS 4 or DJGPP) have only the C locale. Therefore we do NOT * use setlocale here; it would return "C" when it does NOT support the * locale name the user has set. */ /* (I tried to make the ifdef here more closely follow the comment; to return * to the original behavior, change the "|| 0" to "&& 0") */ # if (defined(LC_CTYPE) && defined(HAVE_SETLOCALE) && !defined(__DJGPP__) && !defined(__sun)) || 0 # if defined(__GNUC__) && !defined(__STRICT_ANSI__) # warning "using setlocale() in an instance where it may still be incomplete" # endif /* __GNUC__ && !__STRICT_ANSI__ */ locale = setlocale(LC_CTYPE, NULL); # endif /* (LC_CTYPE && HAVE_SETLOCALE && !__DJGPP__ && !__sun) || 0 */ if ((locale == NULL) || (locale[0] == '\0')) { locale = getenv("LC_ALL"); if ((locale == NULL) || (locale[0] == '\0')) { locale = getenv("LC_CTYPE"); if ((locale == NULL) || (locale[0] == '\0')) { locale = getenv("LANG"); } } } /* On some old systems, one used to set locale = "iso8859_1". On others, * you set it to "language_COUNTRY.charset". In any case, we resolve it * through the charset.alias file. */ codeset = locale; # endif /* HAVE_LANGINFO_CODESET && HAVE_NL_LANGINFO */ #elif defined WINDOWS_NATIVE static char buf[(2 + 10 + 1)]; /* The Windows API has a function returning the locale's codepage as a * number: GetACP(). * When the output goes to a console window, it needs to be provided in * GetOEMCP() encoding if the console is using a raster font, or in * GetConsoleOutputCP() encoding if it is using a TrueType font. * But in GUI programs and for output sent to files and pipes, GetACP() * encoding is the best bet. */ sprintf(buf, "CP%u", GetACP()); codeset = buf; /* ...and that should be all we need on Windows! */ #elif defined OS2 /* things are a little more complicated on OS2... */ const char *locale; static char buf[(2 + 10 + 1)]; ULONG cp[3]; ULONG cplen; /* Allow user to override the codeset, as set in the operating system, * with standard language environment variables. */ locale = getenv("LC_ALL"); if ((locale == NULL) || (locale[0] == '\0')) { locale = getenv("LC_CTYPE"); if ((locale == NULL) || (locale[0] == '\0')) { locale = getenv("LANG"); } } if ((locale != NULL) && (locale[0] != '\0')) { /* If the locale name contains an encoding after the dot, return it: */ const char *dot = strchr(locale, '.'); if (dot != NULL) { const char *modifier; dot++; /* Look for the possible @... trailer and remove it, if any: */ modifier = strchr(dot, '@'); if (modifier == NULL) { return dot; } if ((modifier - dot) < sizeof(buf)) { memcpy(buf, dot, (modifier - dot)); buf[(modifier - dot)] = '\0'; return buf; } } /* Resolve through the charset.alias file: */ codeset = locale; } else { /* OS/2 has a function returning the locale's codepage as a number, so * use it here: */ if (DosQueryCp(sizeof(cp), cp, &cplen)) { codeset = ""; } else { sprintf(buf, "CP%u", cp[0]); codeset = buf; } } /* end OS2-specific code */ #endif /* !(WINDOWS_NATIVE || OS2) */ /* back to code generic to all platforms: */ if (codeset == NULL) { /* If we are here, then the canonical name cannot be determined. */ codeset = ""; } /* Resolve alias: */ for ((aliases = get_charset_aliases()); (*aliases != '\0'); (aliases += (strlen(aliases) + 1)), (aliases += (strlen(aliases) + 1))) { if ((strcmp(codeset, aliases) == 0) || ((aliases[0] == '*') && (aliases[1] == '\0'))) { codeset = (aliases + strlen(aliases) + 1); break; } } /* Do NOT return an empty string. GNU libc and GNU libiconv interpret * the empty string as denoting "the locale's character encoding", * thus GNU libiconv would call this function a second time. */ if (codeset[0] == '\0') { codeset = "ASCII"; } return codeset; }
BOOL LoadTranslateTable(VOID) { APIRET rc; ULONG ulParmSize; BYTE rgData[256]; PBYTE pIn; USHORT rgTranslate[256]; PUSHORT pOut; UconvObject uconv_object = NULL; INT iIndex; size_t in_bytes_left; size_t uni_chars_left; size_t num_subs; ULONG rgCP[3]; ULONG cbCP; rc = DosLoadModule(rgData, sizeof rgData, "UCONV.DLL", &hModLang); if (rc) { printf("No NLS support found (%s does not load).\n", rgData); printf("No UNICODE translate table loaded!\n"); return TRUE; } rc = DosQueryProcAddr(hModLang, 0L, "UniCreateUconvObject", (PFN *)&pUniCreateUconvObject); if (rc) { printf("ERROR: Could not find address of UniCreateUconvObject.\n"); return FALSE; } rc = DosQueryProcAddr(hModLang, 0L, "UniUconvToUcs", (PFN *)&pUniUconvToUcs); if (rc) { printf("ERROR: Could not find address of UniUconvToUcs.\n"); return FALSE; } rc = DosQueryCp(sizeof rgCP, rgCP, &cbCP); if (f32Parms.ulCurCP == rgCP[0]) return FALSE; if (f32Parms.ulCurCP) { BYTE chChar; printf("Loaded unicode translate table is for CP %lu\n", f32Parms.ulCurCP); printf("Current CP is %lu\n", rgCP[0]); printf("Would you like to reload the translate table for this CP [Y/N]? "); fflush(stdout); for (;;) { chChar = getch(); switch (chChar) { case 'y': case 'Y': chChar = 'Y'; break; case 'n': case 'N': chChar = 'N'; break; default : DosBeep(660, 10); continue; } printf("%c\n", chChar); break; } if (chChar == 'N') return FALSE; } for (iIndex = 0; iIndex < 256; iIndex++) rgData[iIndex] = iIndex; rc = pUniCreateUconvObject((UniChar *)L"", &uconv_object); if (rc != ULS_SUCCESS) { printf("UniCreateUconvObject error: return code = %u\n", rc); return FALSE; } pIn = rgData; in_bytes_left = sizeof rgData; pOut = rgTranslate; uni_chars_left = sizeof rgTranslate / sizeof (USHORT); rc = pUniUconvToUcs(uconv_object, (PVOID *)&pIn, &in_bytes_left, &pOut, &uni_chars_left, &num_subs); if (rc != ULS_SUCCESS) { printf("UniUconvToUcs failed, rc = %u\n", rc); return FALSE; } ulParmSize = sizeof rgTranslate; rc = DosFSCtl(NULL, 0, NULL, rgTranslate, ulParmSize, &ulParmSize, FAT32_SETTRANSTABLE, "FAT32", -1, FSCTL_FSDNAME); if (rc) { printf("Unable to set translate table for current Codepage.\n"); return FALSE; } f32Parms.ulCurCP = rgCP[0]; printf("Unicode translate table for CP %lu loaded.\n", rgCP[0]); DosFreeModule(hModLang); return TRUE; }
static APIRET attachVolume(ServerData * pServerData, struct attach * pattach) { VolData * pVolData; IFS_ATTACH * parms = (IFS_ATTACH *) pServerData->pData; int rc; struct iso_primary_descriptor jpd; struct hs_primary_descriptor *hpd; struct iso_directory_record *idr = 0; /* For codepage */ ULONG ulCp[4]; ULONG ulInfoLen=0; char *ptr; pattach->pVolData = 0; if ((pattach->cbParm != sizeof(IFS_ATTACH)) || VERIFYFIXED(parms->szBasePath) ) return ERROR_INVALID_PARAMETER; for (ptr = parms->szBasePath; *ptr; ptr++) if (*ptr == '/') *ptr = '\\'; logMsg(L_DBG, "attaching drive, isopath=%s, offset: %d, charset: %s", parms->szBasePath, parms->iOffset, parms->szCharSet); if ((strncmp(parms->szBasePath, "\\\\", 2) != 0) && /* UNC */ (strncmp(parms->szBasePath, "////", 2) != 0) && /* UNC */ ((strlen(parms->szBasePath) < 3) || (!isalpha((unsigned char) parms->szBasePath[0])) || (parms->szBasePath[1] != ':') || ((parms->szBasePath[2] != '\\') && (parms->szBasePath[2] != '/')))) return ERROR_INVALID_PARAMETER; /* Max sector not tested, yet */ if(parms->iOffset<0) return ERROR_ISOFS_INVALIDOFFSET; /* Allocate a VolData structure. */ pVolData = malloc(sizeof(VolData)); if (!pVolData) { logMsg(L_EVIL, "out of memory"); return ERROR_NOT_ENOUGH_MEMORY; } memset(pVolData,0,sizeof(VolData)); pVolData->pServerData = pServerData; pVolData->chDrive = toupper(pattach->szDev[0]); pVolData->cOpenFiles = 0; pVolData->cSearches = 0; strncpy(pVolData->fileName,parms->szBasePath,sizeof(pVolData->fileName)); pVolData->iSectorOffset=parms->iOffset; strncpy(pVolData->szCharSet,parms->szCharSet,sizeof(pVolData->szCharSet)); /* Load translation table */ if(strlen(pVolData->szCharSet)) { pVolData->nls = load_nls(pVolData->szCharSet); if(!pVolData->nls) logMsg(L_EVIL, "Can't load table for charset %s",pVolData->szCharSet); } else { /* Use default system codepage */ if(DosQueryCp(sizeof(ulCp),ulCp,&ulInfoLen)==NO_ERROR) { /* Check if mkisofs supports our CP */ if(checkCpSupport((int)ulCp[0])) { sprintf(pVolData->szCharSet,"cp%d",(int)ulCp[0]); pVolData->nls = load_nls(pVolData->szCharSet); if(!pVolData->nls) logMsg(L_EVIL, "Can't load table for system codepage %s",pVolData->szCharSet); } } } /* ISO file */ pVolData->isoFile=sysOpenFile(pVolData->fileName, SOF_FAIL_IF_NEW | SOF_OPEN_IF_EXISTS | SOF_DENYWRITE | SOF_READONLY, 0); if(!pVolData->isoFile) { logMsg(L_EVIL, "Can't open ISO file"); /* Unload translation table */ if(pVolData->nls) unload_nls(pVolData->nls); free(pVolData); return ERROR_ISOFS_FILEOPEN; } /* Get info from ISO file */ lseek(pVolData->isoFile->h, ((off_t)(16 + pVolData->iSectorOffset)) <<11, 0); rc=read(pVolData->isoFile->h, &pVolData->ipd, sizeof(pVolData->ipd)); logMsg(L_DBG, "ISO primary descriptor read from ISO file (%d Bytes)",rc); /****************************************/ hpd = (struct hs_primary_descriptor *) &pVolData->ipd; if ((hpd->type[0] == ISO_VD_PRIMARY) && (strncmp(hpd->id, HIGH_SIERRA_ID, sizeof(hpd->id)) == 0) && (hpd->version[0] == 1)) { pVolData->high_sierra = 1; idr = (struct iso_directory_record *) hpd->root_directory_record; memcpy(&pVolData->chrCDName,&hpd->volume_id,32); } else if ((pVolData->ipd.type[0] != ISO_VD_PRIMARY) || (strncmp(pVolData->ipd.id, ISO_STANDARD_ID, sizeof(pVolData->ipd.id)) != 0) || (pVolData->ipd.version[0] != 1)) { logMsg(L_EVIL, "Unable to find PVD"); /* Unload translation table */ if(pVolData->nls) unload_nls(pVolData->nls); sysCloseFile(pVolData->isoFile); free(pVolData); return ERROR_ISOFS_NOTISO; } if (!pVolData->high_sierra) { int block = 16; memcpy(&pVolData->chrCDName,&pVolData->ipd.volume_id,32); memcpy(&jpd, &pVolData->ipd, sizeof(pVolData->ipd)); while (((unsigned char) jpd.type[0] != ISO_VD_END) && (strncmp(jpd.id, ISO_STANDARD_ID, sizeof(jpd.id)) == 0) && (jpd.version[0] == 1)) { if( (unsigned char) jpd.type[0] == ISO_VD_SUPPLEMENTARY ) /* * Find the UCS escape sequence. */ if( jpd.escape_sequences[0] == '%' && jpd.escape_sequences[1] == '/' && (jpd.escape_sequences[3] == '\0' || jpd.escape_sequences[3] == ' ') && (jpd.escape_sequences[2] == '@' || jpd.escape_sequences[2] == 'C' || jpd.escape_sequences[2] == 'E') ) { pVolData->got_joliet = 1; break; } block++; lseek(pVolData->isoFile->h, ((off_t)(block + pVolData->iSectorOffset)) <<11, 0); read(pVolData->isoFile->h, &jpd, sizeof(jpd)); } if(pVolData->got_joliet) switch(jpd.escape_sequences[2]) { case '@': pVolData->ucs_level = 1; break; case 'C': pVolData->ucs_level = 2; break; case 'E': pVolData->ucs_level = 3; break; } if (pVolData->got_joliet) memcpy(&pVolData->ipd, &jpd, sizeof(pVolData->ipd)); idr = (struct iso_directory_record *) pVolData->ipd.root_directory_record; } /****************************************/ /* Fill in extent of root */ pVolData->root_directory_record = idr; pVolData->idRoot = isonum_733((unsigned char *)idr->extent);/* 733 */ pVolData->iRootExtent = pVolData->idRoot; pVolData->iRootSize=isonum_733((unsigned char *)idr->size); logMsg(L_DBG, "Extent of root is: %d ",pVolData->idRoot); pattach->pVolData = pVolData; pVolData->pNext = pServerData->pFirstVolume; pVolData->pPrev = 0; if (pVolData->pNext) pVolData->pNext->pPrev = pVolData; pServerData->pFirstVolume = pVolData; return NO_ERROR; }
/* * Charsets provided by Kyosuke Tokoro ([email protected]) */ const char *getcharset(void) { #ifndef __EMX__ return getenv("TREE_CHARSET"); #else static char buffer[13]; ULONG aulCpList[3],ulListSize,codepage=0; char*charset=getenv("TREE_CHARSET"); if(charset) return charset; if(!getenv("WINDOWID")) if(!DosQueryCp(sizeof aulCpList,aulCpList,&ulListSize)) if(ulListSize>=sizeof*aulCpList) codepage=*aulCpList; switch(codepage){ case 437: case 775: case 850: case 851: case 852: case 855: case 857: case 860: case 861: case 862: case 863: case 864: case 865: case 866: case 868: case 869: case 891: case 903: case 904: sprintf(buffer,"IBM%03lu",codepage); break; case 367: return"US-ASCII"; case 813: return"ISO-8859-7"; case 819: return"ISO-8859-1"; case 881: case 882: case 883: case 884: case 885: sprintf(buffer,"ISO-8859-%lu",codepage-880); break; case 858: case 924: sprintf(buffer,"IBM%05lu",codepage); break; case 874: return"TIS-620"; case 897: case 932: case 942: case 943: return"Shift_JIS"; case 912: return"ISO-8859-2"; case 915: return"ISO-8859-5"; case 916: return"ISO-8859-8"; case 949: case 970: return"EUC-KR"; case 950: return"Big5"; case 954: return"EUC-JP"; case 1051: return"hp-roman8"; case 1089: return"ISO-8859-6"; case 1250: case 1251: case 1253: case 1254: case 1255: case 1256: case 1257: case 1258: sprintf(buffer,"windows-%lu",codepage); break; case 1252: return"ISO-8859-1-Windows-3.1-Latin-1"; default: return NULL; } #endif }