1/*$Header: /p/tcsh/cvsroot/tcsh/win32/nt.char.c,v 1.10 2008/10/11 12:47:39 christos Exp $*/ 2/*- 3 * Copyright (c) 1980, 1991 The Regents of the University of California. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. Neither the name of the University nor the names of its contributors 15 * may be used to endorse or promote products derived from this software 16 * without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 31/* 32 * nt.char.c : Does NLS-like stuff 33 * -amol 34 * 35 */ 36#define WIN32_LEAN_AND_MEAN 37#include <windows.h> 38#include <stdlib.h> 39#include "sh.h" 40 41 42static HMODULE hlangdll; 43 44 45extern DWORD gdwPlatform; 46 47 48unsigned char oem_it(unsigned char ch) { 49 unsigned char ch1[2],ch2[2]; 50 51 ch1[0] = ch; 52 ch1[1] = 0; 53 54 OemToChar((char*)ch1,(char*)ch2); 55 56 return ch2[0]; 57} 58void nls_dll_unload(void) { 59 FreeLibrary(hlangdll); 60 hlangdll=NULL; 61} 62char * nt_cgets(int set, int msgnum, char *def) { 63 64 int rc; 65 int msg; 66 static char oembuf[256];/*FIXBUF*/ 67 WCHAR buffer[256];/*FIXBUF*/ 68 69 70 71 if (!hlangdll) 72 return def; 73 74 msg = set * 10000 + msgnum; 75 76 if (gdwPlatform == VER_PLATFORM_WIN32_WINDOWS) { 77 rc = LoadString(hlangdll,msg,oembuf,sizeof(oembuf)); 78 79 if(!rc) 80 return def; 81 return oembuf; 82 } 83 rc = LoadStringW(hlangdll,msg,buffer,ARRAYSIZE(buffer)); 84 85 if(!rc) 86 return def; 87 88 WideCharToMultiByte(CP_OEMCP, 89 0, 90 buffer, 91 -1, 92 oembuf,//winbuf, 93 256, 94 NULL,NULL); 95 96 return oembuf; 97} 98#if defined(DSPMBYTE) 99void nt_autoset_dspmbyte(void) { 100 switch (GetConsoleCP()) { 101 case 932: /* Japan */ 102 setcopy(CHECK_MBYTEVAR, STRsjis, VAR_READWRITE); 103 update_dspmbyte_vars(); 104 break; 105 } 106} 107 108// _mbmap must be copied to the child during fork() 109unsigned short _mbmap[256] = { 0 }; 110#endif 111 112#undef free 113void nls_dll_init(void) { 114 115 char *ptr; 116 size_t size = 0; 117 118 119 if (_dupenv_s(&ptr,&size,"TCSHLANG") == 0){ 120 121 if (hlangdll) 122 FreeLibrary(hlangdll); 123 hlangdll = LoadLibrary(ptr); 124 125 free(ptr); 126 } 127} 128