Move set_program_name and init_nls to host_init. On windows
fix in this fuction console and argument charset as well.
This commit is contained in:
		
							parent
							
								
									4cd3c4fec7
								
							
						
					
					
						commit
						ae5540d3d4
					
				
					 24 changed files with 282 additions and 78 deletions
				
			
		
							
								
								
									
										33
									
								
								grub-core/osdep/basic/init.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								grub-core/osdep/basic/init.c
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,33 @@ | |||
| /*
 | ||||
|  *  GRUB  --  GRand Unified Bootloader | ||||
|  *  Copyright (C) 2013  Free Software Foundation, Inc. | ||||
|  * | ||||
|  *  GRUB is free software: you can redistribute it and/or modify | ||||
|  *  it under the terms of the GNU General Public License as published by | ||||
|  *  the Free Software Foundation, either version 3 of the License, or | ||||
|  *  (at your option) any later version. | ||||
|  * | ||||
|  *  GRUB 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 General Public License for more details. | ||||
|  * | ||||
|  *  You should have received a copy of the GNU General Public License | ||||
|  *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
 | ||||
|  */ | ||||
| 
 | ||||
| #include <config.h> | ||||
| #include <config-util.h> | ||||
| 
 | ||||
| #include <grub/util/misc.h> | ||||
| 
 | ||||
| #include "progname.h" | ||||
| 
 | ||||
| void | ||||
| grub_util_host_init (int *argc __attribute__ ((unused)), | ||||
| 		     char ***argv) | ||||
| { | ||||
|   set_program_name ((*argv)[0]); | ||||
| 
 | ||||
|   grub_util_init_nls (); | ||||
| } | ||||
							
								
								
									
										5
									
								
								grub-core/osdep/init.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								grub-core/osdep/init.c
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,5 @@ | |||
| #if defined (__MINGW32__) | ||||
| #include "windows/init.c" | ||||
| #else | ||||
| #include "basic/init.c" | ||||
| #endif | ||||
|  | @ -49,24 +49,6 @@ | |||
| #include <windows.h> | ||||
| #include <winioctl.h> | ||||
| 
 | ||||
| char * | ||||
| grub_util_tchar_to_utf8 (LPCTSTR in) | ||||
| { | ||||
| #if SIZEOF_TCHAR == 1 | ||||
|   return xstrdup (path); | ||||
| #elif SIZEOF_TCHAR == 2 | ||||
|   size_t ssz; | ||||
|   for (ssz = 0; in[ssz]; ssz++); | ||||
| 
 | ||||
|   size_t tsz = GRUB_MAX_UTF8_PER_UTF16 * ssz + 1; | ||||
|   grub_uint8_t *ret = xmalloc (tsz); | ||||
|   *grub_utf16_to_utf8 (ret, in, ssz) = '\0'; | ||||
|   return (char *) ret; | ||||
| #else | ||||
| #error "Unsupported TCHAR size" | ||||
| #endif | ||||
| } | ||||
| 
 | ||||
| #if SIZEOF_TCHAR == 1 | ||||
| #define tcsnicmp strncasecmp | ||||
| #define tclen strlen | ||||
|  |  | |||
|  | @ -48,6 +48,51 @@ | |||
| #include <windows.h> | ||||
| #include <winioctl.h> | ||||
| 
 | ||||
| #if SIZEOF_TCHAR == 1 | ||||
| 
 | ||||
| LPTSTR | ||||
| grub_util_utf8_to_tchar (const char *in) | ||||
| { | ||||
|   return xstrdup (in); | ||||
| } | ||||
| 
 | ||||
| char * | ||||
| grub_util_tchar_to_utf8 (LPCTSTR in) | ||||
| { | ||||
|   return xstrdup (in); | ||||
| } | ||||
| 
 | ||||
| #elif SIZEOF_TCHAR == 2 | ||||
| 
 | ||||
| LPTSTR | ||||
| grub_util_utf8_to_tchar (const char *in) | ||||
| { | ||||
|   LPTSTR ret; | ||||
|   size_t ssz = strlen (in); | ||||
|   size_t tsz = 2 * (GRUB_MAX_UTF16_PER_UTF8 * ssz + 1); | ||||
|   ret = xmalloc (tsz); | ||||
|   tsz = grub_utf8_to_utf16 (ret, tsz, | ||||
| 			    (const grub_uint8_t *) in, ssz, NULL); | ||||
|   ret[tsz] = 0; | ||||
|   return ret; | ||||
| } | ||||
| 
 | ||||
| char * | ||||
| grub_util_tchar_to_utf8 (LPCTSTR in) | ||||
| { | ||||
|   size_t ssz; | ||||
|   for (ssz = 0; in[ssz]; ssz++); | ||||
| 
 | ||||
|   size_t tsz = GRUB_MAX_UTF8_PER_UTF16 * ssz + 1; | ||||
|   grub_uint8_t *ret = xmalloc (tsz); | ||||
|   *grub_utf16_to_utf8 (ret, in, ssz) = '\0'; | ||||
|   return (char *) ret; | ||||
| } | ||||
| 
 | ||||
| #else | ||||
| #error "Unsupported TCHAR size" | ||||
| #endif | ||||
| 
 | ||||
| #ifdef __CYGWIN__ | ||||
| LPTSTR | ||||
| grub_util_get_windows_path (const char *path) | ||||
|  | @ -64,28 +109,20 @@ grub_util_get_windows_path (const char *path) | |||
| LPTSTR | ||||
| grub_util_get_windows_path (const char *path) | ||||
| { | ||||
|   char *fpa; | ||||
|   const char *fp; | ||||
|   LPTSTR ret; | ||||
|   LPTSTR fpa; | ||||
|   LPTSTR tpath; | ||||
| 
 | ||||
|   fp = fpa = xmalloc (PATH_MAX); | ||||
|   if (!_fullpath (fpa, path, PATH_MAX)) | ||||
|     fp = path; | ||||
| #if SIZEOF_TCHAR == 1 | ||||
|   ret = xstrdup (fp); | ||||
| #elif SIZEOF_TCHAR == 2 | ||||
|   size_t ssz = strlen (fp); | ||||
|   size_t tsz = 2 * (GRUB_MAX_UTF16_PER_UTF8 * ssz + 1); | ||||
|   ret = xmalloc (tsz); | ||||
|   tsz = grub_utf8_to_utf16 (ret, tsz, (const grub_uint8_t *) fp, ssz, NULL); | ||||
|   ret[tsz] = 0; | ||||
| #else | ||||
| #error SIZEOF_TCHAR | ||||
| #error "Unsupported TCHAR size" | ||||
| #endif | ||||
|   tpath = grub_util_utf8_to_tchar (path); | ||||
| 
 | ||||
|   free (fpa); | ||||
|   return ret; | ||||
|   fpa = xmalloc (PATH_MAX * sizeof (fpa[0])); | ||||
|   if (!_wfullpath (fpa, tpath, PATH_MAX)) | ||||
|     { | ||||
|       free (fpa); | ||||
|       return tpath; | ||||
|     } | ||||
| 
 | ||||
|   free (tpath); | ||||
|   return fpa; | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										143
									
								
								grub-core/osdep/windows/init.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										143
									
								
								grub-core/osdep/windows/init.c
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,143 @@ | |||
| /*
 | ||||
|  *  GRUB  --  GRand Unified Bootloader | ||||
|  *  Copyright (C) 2013  Free Software Foundation, Inc. | ||||
|  * | ||||
|  *  GRUB is free software: you can redistribute it and/or modify | ||||
|  *  it under the terms of the GNU General Public License as published by | ||||
|  *  the Free Software Foundation, either version 3 of the License, or | ||||
|  *  (at your option) any later version. | ||||
|  * | ||||
|  *  GRUB 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 General Public License for more details. | ||||
|  * | ||||
|  *  You should have received a copy of the GNU General Public License | ||||
|  *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
 | ||||
|  */ | ||||
| 
 | ||||
| #include <config.h> | ||||
| #include <config-util.h> | ||||
| #include <grub/util/misc.h> | ||||
| #include <grub/osdep/hostfile.h> | ||||
| #include <grub/util/windows.h> | ||||
| 
 | ||||
| #include <wincon.h> | ||||
| #include <windows.h> | ||||
| 
 | ||||
| #include <grub/util/misc.h> | ||||
| 
 | ||||
| #include "progname.h" | ||||
| 
 | ||||
| struct grub_windows_console_font_infoex { | ||||
|   ULONG cbSize; | ||||
|   DWORD nFont; | ||||
|   COORD dwFontSize; | ||||
|   UINT  FontFamily; | ||||
|   UINT  FontWeight; | ||||
|   WCHAR FaceName[LF_FACESIZE]; | ||||
| }; | ||||
| 
 | ||||
| static int | ||||
| check_is_raster (HMODULE kernel32, HANDLE hnd) | ||||
| { | ||||
|   CONSOLE_FONT_INFO console_font_info; | ||||
|   BOOL (WINAPI * func_GetCurrentConsoleFont) (HANDLE, BOOL, | ||||
| 					      PCONSOLE_FONT_INFO); | ||||
| 
 | ||||
|   func_GetCurrentConsoleFont = (void *) | ||||
|     GetProcAddress (kernel32, "GetCurrentConsoleFont"); | ||||
| 
 | ||||
|   if (!func_GetCurrentConsoleFont) | ||||
|     return 1; | ||||
| 
 | ||||
|   if (!func_GetCurrentConsoleFont (hnd, FALSE, &console_font_info)) | ||||
|     return 1; | ||||
|   return console_font_info.nFont < 12; | ||||
| } | ||||
| 
 | ||||
| static void | ||||
| set_console_unicode_font (void) | ||||
| { | ||||
|   BOOL (WINAPI * func_SetCurrentConsoleFontEx) (HANDLE, BOOL, | ||||
| 						struct grub_windows_console_font_infoex *); | ||||
|   BOOL (WINAPI * func_SetConsoleFont)(HANDLE, DWORD); | ||||
|   HMODULE kernel32; | ||||
|   HANDLE out_handle = GetStdHandle (STD_OUTPUT_HANDLE); | ||||
|   HANDLE err_handle = GetStdHandle (STD_ERROR_HANDLE); | ||||
|   int out_raster, err_raster; | ||||
| 
 | ||||
|   kernel32 = GetModuleHandle(TEXT("kernel32.dll")); | ||||
|   if (!kernel32) | ||||
|     return; | ||||
| 
 | ||||
|   out_raster = check_is_raster (kernel32, out_handle); | ||||
|   err_raster = check_is_raster (kernel32, err_handle); | ||||
| 
 | ||||
|   if (!out_raster && !err_raster) | ||||
|     return; | ||||
| 
 | ||||
|   func_SetCurrentConsoleFontEx = (void *) GetProcAddress (kernel32, "SetCurrentConsoleFontEx"); | ||||
| 
 | ||||
|   /* Newer windows versions.  */ | ||||
|   if (func_SetCurrentConsoleFontEx) | ||||
|     { | ||||
|       struct grub_windows_console_font_infoex new_console_font_info; | ||||
|       new_console_font_info.cbSize = sizeof (new_console_font_info); | ||||
|       new_console_font_info.nFont = 12; | ||||
|       new_console_font_info.dwFontSize.X = 7; | ||||
|       new_console_font_info.dwFontSize.Y = 12; | ||||
|       new_console_font_info.FontFamily = FF_DONTCARE; | ||||
|       new_console_font_info.FontWeight = 400; | ||||
|       memcpy (new_console_font_info.FaceName, TEXT("Lucida Console"), | ||||
| 	      sizeof (TEXT("Lucida Console"))); | ||||
|       if (out_raster) | ||||
| 	func_SetCurrentConsoleFontEx (out_handle, FALSE, | ||||
| 				      &new_console_font_info); | ||||
|       if (err_raster) | ||||
| 	func_SetCurrentConsoleFontEx (err_handle, FALSE, | ||||
| 				      &new_console_font_info); | ||||
|       return; | ||||
|     } | ||||
| 
 | ||||
|   /* Fallback for older versions.  */ | ||||
|   func_SetConsoleFont = (void *) GetProcAddress (kernel32, "SetConsoleFont"); | ||||
|   if (func_SetConsoleFont) | ||||
|     { | ||||
|       if (out_raster) | ||||
| 	func_SetConsoleFont (out_handle, 12); | ||||
|       if (err_raster) | ||||
| 	func_SetConsoleFont (err_handle, 12); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void | ||||
| grub_util_host_init (int *argc __attribute__ ((unused)), | ||||
| 		     char ***argv) | ||||
| { | ||||
|   SetConsoleOutputCP (CP_UTF8); | ||||
|   SetConsoleCP (CP_UTF8); | ||||
| 
 | ||||
|   set_console_unicode_font (); | ||||
| 
 | ||||
| #if SIZEOF_TCHAR == 1 | ||||
| 
 | ||||
| #elif SIZEOF_TCHAR == 2 | ||||
|   LPWSTR tcmdline = GetCommandLineW (); | ||||
|   int i; | ||||
|   LPWSTR *targv; | ||||
| 
 | ||||
|   targv = CommandLineToArgvW (tcmdline, argc); | ||||
|   *argv = xmalloc ((*argc + 1) * sizeof (argv[0])); | ||||
| 
 | ||||
|   for (i = 0; i < *argc; i++) | ||||
|     (*argv)[i] = grub_util_tchar_to_utf8 (targv[i]);  | ||||
|   (*argv)[i] = NULL; | ||||
| #else | ||||
| #error "Unsupported TCHAR size" | ||||
| #endif | ||||
| 
 | ||||
|   set_program_name ((*argv)[0]); | ||||
| 
 | ||||
|   grub_util_init_nls (); | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue