annotate osdep/getch2-win.c @ 33073:334e19411421

Improve handling of the comment character. The comment character is safe now between (double) quotation marks. This simplifies handling in the font description file and allows it to be used in label texts.
author ib
date Wed, 30 Mar 2011 14:24:11 +0000
parents 25090c2eb0e2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28744
5cfef41a1771 Add standard license headers to files.
diego
parents: 28232
diff changeset
1 /* Windows TermIO
5cfef41a1771 Add standard license headers to files.
diego
parents: 28232
diff changeset
2 *
5cfef41a1771 Add standard license headers to files.
diego
parents: 28232
diff changeset
3 * copyright (C) 2003 Sascha Sommer
5cfef41a1771 Add standard license headers to files.
diego
parents: 28232
diff changeset
4 *
5cfef41a1771 Add standard license headers to files.
diego
parents: 28232
diff changeset
5 * This file is part of MPlayer.
5cfef41a1771 Add standard license headers to files.
diego
parents: 28232
diff changeset
6 *
5cfef41a1771 Add standard license headers to files.
diego
parents: 28232
diff changeset
7 * MPlayer is free software; you can redistribute it and/or modify
5cfef41a1771 Add standard license headers to files.
diego
parents: 28232
diff changeset
8 * it under the terms of the GNU General Public License as published by
5cfef41a1771 Add standard license headers to files.
diego
parents: 28232
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
5cfef41a1771 Add standard license headers to files.
diego
parents: 28232
diff changeset
10 * (at your option) any later version.
5cfef41a1771 Add standard license headers to files.
diego
parents: 28232
diff changeset
11 *
5cfef41a1771 Add standard license headers to files.
diego
parents: 28232
diff changeset
12 * MPlayer is distributed in the hope that it will be useful,
5cfef41a1771 Add standard license headers to files.
diego
parents: 28232
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5cfef41a1771 Add standard license headers to files.
diego
parents: 28232
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5cfef41a1771 Add standard license headers to files.
diego
parents: 28232
diff changeset
15 * GNU General Public License for more details.
5cfef41a1771 Add standard license headers to files.
diego
parents: 28232
diff changeset
16 *
5cfef41a1771 Add standard license headers to files.
diego
parents: 28232
diff changeset
17 * You should have received a copy of the GNU General Public License along
5cfef41a1771 Add standard license headers to files.
diego
parents: 28232
diff changeset
18 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
5cfef41a1771 Add standard license headers to files.
diego
parents: 28232
diff changeset
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
5cfef41a1771 Add standard license headers to files.
diego
parents: 28232
diff changeset
20 */
9766
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
21
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
22 // See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/UserInput/VirtualKeyCodes.asp
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
23 // for additional virtual keycodes
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
24
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
25
22442
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22441
diff changeset
26 #include "config.h"
22441
6f183c95aafc Include stdio.h for printf
reimar
parents: 18107
diff changeset
27 #include <stdio.h>
30742
25090c2eb0e2 Add support for reading key events from MinGW xterm.
reimar
parents: 30738
diff changeset
28 #include <stdint.h>
29290
ef46d5a66bb2 Use a malloced string for the get_term_charset return value.
reimar
parents: 29263
diff changeset
29 #include <string.h>
9766
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
30 #include <windows.h>
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
31 #include "keycodes.h"
16985
08cac43f1e38 Unify include paths, -I.. is in CFLAGS.
diego
parents: 13015
diff changeset
32 #include "input/input.h"
24129
50e1e79056b6 Make terminal input work more like VO key input
uau
parents: 22886
diff changeset
33 #include "mp_fifo.h"
30734
749c87b2c3e2 Include getch2.h to get rid of some warnings.
reimar
parents: 29290
diff changeset
34 #include "getch2.h"
10928
f2313bd91594 add a read function for slave mode on mingw
faust3
parents: 10230
diff changeset
35
26015
f222f84f2072 Rename mp_input_win32_slave_cmd_func to mp_input_slave_cmd_func.
diego
parents: 24129
diff changeset
36 int mp_input_slave_cmd_func(int fd,char* dest,int size){
13015
00a4cf87e2ff fix slave mode for mingw, patch by Anton Ragnarsson <anton.ragnarsson.1093 at student.uu.se> some cleanup by be
faust3
parents: 10928
diff changeset
37 DWORD retval;
30735
783071763328 Do not misuse the stdin name.
reimar
parents: 30734
diff changeset
38 HANDLE in = GetStdHandle(STD_INPUT_HANDLE);
30738
25622198a15a Make -slave also work with the normal console on Windows.
reimar
parents: 30735
diff changeset
39 if(PeekNamedPipe(in, NULL, size, &retval, NULL, NULL)){
25622198a15a Make -slave also work with the normal console on Windows.
reimar
parents: 30735
diff changeset
40 if (size > retval) size = retval;
25622198a15a Make -slave also work with the normal console on Windows.
reimar
parents: 30735
diff changeset
41 } else {
25622198a15a Make -slave also work with the normal console on Windows.
reimar
parents: 30735
diff changeset
42 if (WaitForSingleObject(in, 0))
25622198a15a Make -slave also work with the normal console on Windows.
reimar
parents: 30735
diff changeset
43 size = 0;
25622198a15a Make -slave also work with the normal console on Windows.
reimar
parents: 30735
diff changeset
44 }
25622198a15a Make -slave also work with the normal console on Windows.
reimar
parents: 30735
diff changeset
45 if(!size){
13015
00a4cf87e2ff fix slave mode for mingw, patch by Anton Ragnarsson <anton.ragnarsson.1093 at student.uu.se> some cleanup by be
faust3
parents: 10928
diff changeset
46 return MP_INPUT_NOTHING;
10928
f2313bd91594 add a read function for slave mode on mingw
faust3
parents: 10230
diff changeset
47 }
30738
25622198a15a Make -slave also work with the normal console on Windows.
reimar
parents: 30735
diff changeset
48 ReadFile(in, dest, size, &retval, NULL);
13015
00a4cf87e2ff fix slave mode for mingw, patch by Anton Ragnarsson <anton.ragnarsson.1093 at student.uu.se> some cleanup by be
faust3
parents: 10928
diff changeset
49 if(retval)return retval;
10928
f2313bd91594 add a read function for slave mode on mingw
faust3
parents: 10230
diff changeset
50 return MP_INPUT_NOTHING;
f2313bd91594 add a read function for slave mode on mingw
faust3
parents: 10230
diff changeset
51 }
9766
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
52
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
53 int screen_width=80;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
54 int screen_height=24;
17258
3d02f6e2a432 change erase to end of line, fall back to old behavior if no termcap found
ods15
parents: 17251
diff changeset
55 char * erase_to_end_of_line = NULL;
9766
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
56
28232
8df85ad26746 Add missing 'void' keyword to parameterless function declarations.
diego
parents: 27393
diff changeset
57 void get_screen_size(void){
9766
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
58 }
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
59
30735
783071763328 Do not misuse the stdin name.
reimar
parents: 30734
diff changeset
60 static HANDLE in;
9936
6d9531a5d95b disable getch2 on windows when we can't read stdin (msys)
faust3
parents: 9766
diff changeset
61 static int getch2_status=0;
9766
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
62
24129
50e1e79056b6 Make terminal input work more like VO key input
uau
parents: 22886
diff changeset
63 static int getch2_internal(void)
50e1e79056b6 Make terminal input work more like VO key input
uau
parents: 22886
diff changeset
64 {
9766
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
65 INPUT_RECORD eventbuffer[128];
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
66 DWORD retval;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
67 int i=0;
30742
25090c2eb0e2 Add support for reading key events from MinGW xterm.
reimar
parents: 30738
diff changeset
68 if(!getch2_status){
25090c2eb0e2 Add support for reading key events from MinGW xterm.
reimar
parents: 30738
diff changeset
69 // supports e.g. MinGW xterm, unfortunately keys are only received after
25090c2eb0e2 Add support for reading key events from MinGW xterm.
reimar
parents: 30738
diff changeset
70 // enter was pressed.
25090c2eb0e2 Add support for reading key events from MinGW xterm.
reimar
parents: 30738
diff changeset
71 uint8_t c;
25090c2eb0e2 Add support for reading key events from MinGW xterm.
reimar
parents: 30738
diff changeset
72 if (!PeekNamedPipe(in, NULL, 1, &retval, NULL, NULL) || !retval)
25090c2eb0e2 Add support for reading key events from MinGW xterm.
reimar
parents: 30738
diff changeset
73 return -1;
25090c2eb0e2 Add support for reading key events from MinGW xterm.
reimar
parents: 30738
diff changeset
74 ReadFile(in, &c, 1, &retval, NULL);
25090c2eb0e2 Add support for reading key events from MinGW xterm.
reimar
parents: 30738
diff changeset
75 return retval == 1 ? c : -1;
25090c2eb0e2 Add support for reading key events from MinGW xterm.
reimar
parents: 30738
diff changeset
76 }
9766
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
77 /*check if there are input events*/
30735
783071763328 Do not misuse the stdin name.
reimar
parents: 30734
diff changeset
78 if(!GetNumberOfConsoleInputEvents(in,&retval))
9766
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
79 {
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
80 printf("getch2: can't get number of input events: %i\n",GetLastError());
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
81 return -1;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
82 }
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
83 if(retval<=0)return -1;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28744
diff changeset
84
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28744
diff changeset
85 /*read all events*/
30735
783071763328 Do not misuse the stdin name.
reimar
parents: 30734
diff changeset
86 if(!ReadConsoleInput(in,eventbuffer,128,&retval))
9766
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
87 {
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
88 printf("getch: can't read input events\n");
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
89 return -1;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
90 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28744
diff changeset
91
9766
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
92 /*filter out keyevents*/
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28744
diff changeset
93 for (i = 0; i < retval; i++)
9766
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
94 {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28744
diff changeset
95 switch(eventbuffer[i].EventType)
9766
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
96 {
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
97 case KEY_EVENT:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
98 /*only a pressed key is interresting for us*/
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
99 if(eventbuffer[i].Event.KeyEvent.bKeyDown == TRUE)
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
100 {
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
101 /*check for special keys*/
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
102 switch(eventbuffer[i].Event.KeyEvent.wVirtualKeyCode)
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
103 {
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
104 case VK_HOME:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
105 return KEY_HOME;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
106 case VK_END:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
107 return KEY_END;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
108 case VK_DELETE:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
109 return KEY_DEL;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
110 case VK_INSERT:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
111 return KEY_INS;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
112 case VK_BACK:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
113 return KEY_BS;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
114 case VK_PRIOR:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
115 return KEY_PGUP;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
116 case VK_NEXT:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
117 return KEY_PGDWN;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
118 case VK_RETURN:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
119 return KEY_ENTER;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
120 case VK_ESCAPE:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
121 return KEY_ESC;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
122 case VK_LEFT:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
123 return KEY_LEFT;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
124 case VK_UP:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
125 return KEY_UP;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
126 case VK_RIGHT:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
127 return KEY_RIGHT;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
128 case VK_DOWN:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
129 return KEY_DOWN;
10230
3d33d5a19c21 fix volume increasing
faust3
parents: 9983
diff changeset
130 case VK_SHIFT:
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28744
diff changeset
131 continue;
9766
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
132 }
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
133 /*check for function keys*/
18107
24003616a623 10l, fix broken if (X >= Y >= Z) comparison, probably stopped F-keys from working
reimar
parents: 18070
diff changeset
134 if(0x87 >= eventbuffer[i].Event.KeyEvent.wVirtualKeyCode && eventbuffer[i].Event.KeyEvent.wVirtualKeyCode >= 0x70)
26759
8eff880f638c cosmetics: Remove useless parentheses from return statements.
diego
parents: 26015
diff changeset
135 return KEY_F + 1 + eventbuffer[i].Event.KeyEvent.wVirtualKeyCode - 0x70;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28744
diff changeset
136
9766
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
137 /*only characters should be remaining*/
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28744
diff changeset
138 //printf("getch2: YOU PRESSED \"%c\" \n",eventbuffer[i].Event.KeyEvent.uChar.AsciiChar);
9766
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
139 return eventbuffer[i].Event.KeyEvent.uChar.AsciiChar;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
140 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28744
diff changeset
141 break;
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28744
diff changeset
142
9766
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
143 case MOUSE_EVENT:
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28744
diff changeset
144 case WINDOW_BUFFER_SIZE_EVENT:
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28744
diff changeset
145 case FOCUS_EVENT:
9766
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
146 case MENU_EVENT:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
147 default:
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28744
diff changeset
148 //printf("getch2: unsupported event type");
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28744
diff changeset
149 break;
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28744
diff changeset
150 }
9766
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
151 }
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
152 return -1;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
153 }
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
154
24129
50e1e79056b6 Make terminal input work more like VO key input
uau
parents: 22886
diff changeset
155 void getch2(void)
50e1e79056b6 Make terminal input work more like VO key input
uau
parents: 22886
diff changeset
156 {
50e1e79056b6 Make terminal input work more like VO key input
uau
parents: 22886
diff changeset
157 int r = getch2_internal();
50e1e79056b6 Make terminal input work more like VO key input
uau
parents: 22886
diff changeset
158 if (r >= 0)
50e1e79056b6 Make terminal input work more like VO key input
uau
parents: 22886
diff changeset
159 mplayer_put_key(r);
50e1e79056b6 Make terminal input work more like VO key input
uau
parents: 22886
diff changeset
160 }
9766
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
161
28232
8df85ad26746 Add missing 'void' keyword to parameterless function declarations.
diego
parents: 27393
diff changeset
162 void getch2_enable(void)
8df85ad26746 Add missing 'void' keyword to parameterless function declarations.
diego
parents: 27393
diff changeset
163 {
9983
14c92818ab75 alternative timer and glob emulation code for mingw32 port
faust3
parents: 9936
diff changeset
164 DWORD retval;
30735
783071763328 Do not misuse the stdin name.
reimar
parents: 30734
diff changeset
165 in = GetStdHandle(STD_INPUT_HANDLE);
783071763328 Do not misuse the stdin name.
reimar
parents: 30734
diff changeset
166 if(!GetNumberOfConsoleInputEvents(in,&retval))
9936
6d9531a5d95b disable getch2 on windows when we can't read stdin (msys)
faust3
parents: 9766
diff changeset
167 {
6d9531a5d95b disable getch2 on windows when we can't read stdin (msys)
faust3
parents: 9766
diff changeset
168 printf("getch2: %i can't get number of input events [disabling console input]\n",GetLastError());
6d9531a5d95b disable getch2 on windows when we can't read stdin (msys)
faust3
parents: 9766
diff changeset
169 getch2_status = 0;
6d9531a5d95b disable getch2 on windows when we can't read stdin (msys)
faust3
parents: 9766
diff changeset
170 }
6d9531a5d95b disable getch2 on windows when we can't read stdin (msys)
faust3
parents: 9766
diff changeset
171 else getch2_status=1;
9766
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
172 }
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
173
28232
8df85ad26746 Add missing 'void' keyword to parameterless function declarations.
diego
parents: 27393
diff changeset
174 void getch2_disable(void)
8df85ad26746 Add missing 'void' keyword to parameterless function declarations.
diego
parents: 27393
diff changeset
175 {
9766
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
176 if(!getch2_status) return; // already disabled / never enabled
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
177 getch2_status=0;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
178 }
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
179
27393
4876c89bafdd Rename font-related preprocessor directives.
diego
parents: 27359
diff changeset
180 #ifdef CONFIG_ICONV
22442
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22441
diff changeset
181 static const struct {
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22441
diff changeset
182 unsigned cp;
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22441
diff changeset
183 char* alias;
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22441
diff changeset
184 } cp_alias[] = {
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22441
diff changeset
185 { 20127, "ASCII" },
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22441
diff changeset
186 { 20866, "KOI8-R" },
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22441
diff changeset
187 { 21866, "KOI8-RU" },
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22441
diff changeset
188 { 28591, "ISO-8859-1" },
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22441
diff changeset
189 { 28592, "ISO-8859-2" },
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22441
diff changeset
190 { 28593, "ISO-8859-3" },
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22441
diff changeset
191 { 28594, "ISO-8859-4" },
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22441
diff changeset
192 { 28595, "ISO-8859-5" },
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22441
diff changeset
193 { 28596, "ISO-8859-6" },
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22441
diff changeset
194 { 28597, "ISO-8859-7" },
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22441
diff changeset
195 { 28598, "ISO-8859-8" },
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22441
diff changeset
196 { 28599, "ISO-8859-9" },
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22441
diff changeset
197 { 28605, "ISO-8859-15" },
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22441
diff changeset
198 { 65001, "UTF-8" },
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22441
diff changeset
199 { 0, NULL }
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22441
diff changeset
200 };
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28744
diff changeset
201
22886
71b3e04d0555 "()" to "(void)" function param list fixes
uau
parents: 22442
diff changeset
202 char* get_term_charset(void)
22442
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22441
diff changeset
203 {
29290
ef46d5a66bb2 Use a malloced string for the get_term_charset return value.
reimar
parents: 29263
diff changeset
204 char codepage[10];
22442
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22441
diff changeset
205 unsigned i, cpno = GetConsoleOutputCP();
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22441
diff changeset
206 if (!cpno)
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22441
diff changeset
207 cpno = GetACP();
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22441
diff changeset
208 if (!cpno)
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22441
diff changeset
209 return NULL;
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22441
diff changeset
210
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22441
diff changeset
211 for (i = 0; cp_alias[i].cp; i++)
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22441
diff changeset
212 if (cpno == cp_alias[i].cp)
29290
ef46d5a66bb2 Use a malloced string for the get_term_charset return value.
reimar
parents: 29263
diff changeset
213 return strdup(cp_alias[i].alias);
22442
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22441
diff changeset
214
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22441
diff changeset
215 snprintf(codepage, sizeof(codepage), "CP%u", cpno);
29290
ef46d5a66bb2 Use a malloced string for the get_term_charset return value.
reimar
parents: 29263
diff changeset
216 return strdup(codepage);
22442
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22441
diff changeset
217 }
56a0b0f8a66e Add code to detect and convert to console codepage on Windows.
reimar
parents: 22441
diff changeset
218 #endif