annotate osdep/getch2-os2.c @ 29962:fd112c1ef46e

Simplify some commands via automatic variables.
author diego
date Sun, 13 Dec 2009 22:23:34 +0000
parents ef46d5a66bb2
children 32725ca88fed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26016
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
1 /*
28924
d5d66bff938a cosmetics: Remove file names from file header, it only causes trouble.
diego
parents: 27393
diff changeset
2 * OS/2 TermIO
26016
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
3 *
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
4 * Copyright (c) 2007 KO Myung-Hun (komh@chollian.net)
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
5 *
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
6 * This file is part of MPlayer.
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
7 *
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
8 * MPlayer is free software; you can redistribute it and/or modify
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
11 * (at your option) any later version.
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
12 *
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
13 * MPlayer is distributed in the hope that it will be useful,
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
16 * GNU General Public License for more details.
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
17 *
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License along
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
21 */
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
22
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
23 #define INCL_KBD
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
24 #define INCL_VIO
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
25 #define INCL_DOS
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
26 #include <os2.h>
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
27
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
28 #include <stdio.h>
29290
ef46d5a66bb2 Use a malloced string for the get_term_charset return value.
reimar
parents: 28924
diff changeset
29 #include <string.h>
26016
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
30
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
31 #include "config.h"
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
32 #include "keycodes.h"
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
33 #include "input/input.h"
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
34 #include "mp_fifo.h"
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
35
27393
4876c89bafdd Rename font-related preprocessor directives.
diego
parents: 27359
diff changeset
36 #if defined(HAVE_LANGINFO) && defined(CONFIG_ICONV)
26016
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
37 #include <locale.h>
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
38 #include <langinfo.h>
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
39 #endif
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
40
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
41 int mp_input_slave_cmd_func( int fd, char *dest, int size )
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
42 {
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
43 PPIB ppib;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
44 CHAR szPipeName[ 100 ];
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
45 HFILE hpipe;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
46 ULONG ulAction;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
47 ULONG cbActual;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
48 ULONG rc;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
49
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
50 DosGetInfoBlocks( NULL, &ppib );
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
51
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
52 sprintf( szPipeName, "\\PIPE\\MPLAYER\\%lx", ppib->pib_ulpid );
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
53
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
54 rc = DosOpen( szPipeName, &hpipe, &ulAction, 0, FILE_NORMAL,
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
55 OPEN_ACTION_OPEN_IF_EXISTS,
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
56 OPEN_SHARE_DENYREADWRITE | OPEN_ACCESS_READWRITE,
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
57 NULL );
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
58 if( rc )
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
59 return MP_INPUT_NOTHING;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
60
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
61 rc = DosRead( hpipe, dest, size, &cbActual );
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
62 if( rc )
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
63 return MP_INPUT_NOTHING;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
64
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
65 rc = cbActual;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
66
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
67 // Send ACK
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
68 DosWrite( hpipe, &rc, sizeof( ULONG ), &cbActual );
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
69
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
70 DosClose( hpipe );
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
71
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
72 return rc;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
73 }
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
74
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
75
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
76 int screen_width = 80;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
77 int screen_height = 24;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
78 char *erase_to_end_of_line = NULL;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
79
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
80 void get_screen_size( void )
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
81 {
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
82 VIOMODEINFO vmi;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
83
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
84 vmi.cb = sizeof( VIOMODEINFO );
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
85
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
86 VioGetMode( &vmi, 0 );
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
87
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
88 screen_width = vmi.col;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
89 screen_height = vmi.row;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
90 }
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
91
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
92 static int getch2_status = 0;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
93
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
94 static int getch2_internal( void )
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
95 {
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
96 KBDKEYINFO kki;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
97
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
98 if( !getch2_status )
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
99 return -1;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
100
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
101 if( KbdCharIn( &kki, IO_NOWAIT, 0 ))
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
102 return -1;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
103
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
104 // key pressed ?
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
105 if( kki.fbStatus )
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
106 {
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
107 // extended key ?
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
108 if(( kki.chChar == 0x00 ) || ( kki.chChar == 0xE0 ))
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
109 {
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
110 switch( kki.chScan )
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
111 {
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
112 case 0x4B : // Left
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
113 return KEY_LEFT;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
114
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
115 case 0x48 : // Up
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
116 return KEY_UP;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
117
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
118 case 0x4D : // Right
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
119 return KEY_RIGHT;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
120
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
121 case 0x50 : // Down
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
122 return KEY_DOWN;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
123
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
124 case 0x53 : // Delete
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
125 return KEY_DELETE;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
126
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
127 case 0x52 : // Insert
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
128 return KEY_INSERT;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
129
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
130 case 0x47 : // Home
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
131 return KEY_HOME;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
132
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
133 case 0x4F : // End
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
134 return KEY_END;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
135
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
136 case 0x49 : // Page Up
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
137 return KEY_PAGE_UP;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
138
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
139 case 0x51 : // Page Down
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
140 return KEY_PAGE_DOWN;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
141 }
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
142 }
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
143 else
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
144 {
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
145 switch( kki.chChar )
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
146 {
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
147 case 0x08 : // Backspace
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
148 return KEY_BS;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
149
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
150 case 0x1B : // Esc
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
151 return KEY_ESC;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
152
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
153 case 0x0D : // Enter
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
154 // Keypad Enter ?
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
155 if( kki.chScan == 0xE0 )
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
156 return KEY_KPENTER;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
157 break;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
158 }
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
159
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
160 return kki.chChar;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
161 }
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
162 }
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
163
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
164 return -1;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
165 }
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
166
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
167 void getch2( void )
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
168 {
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
169 int key;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
170
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
171 key = getch2_internal();
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
172 if( key != -1 )
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
173 mplayer_put_key( key );
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
174 }
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
175
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
176 void getch2_enable( void )
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
177 {
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
178 getch2_status = 1;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
179 }
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
180
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
181 void getch2_disable( void )
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
182 {
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
183 getch2_status = 0;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
184 }
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
185
27393
4876c89bafdd Rename font-related preprocessor directives.
diego
parents: 27359
diff changeset
186 #ifdef CONFIG_ICONV
26016
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
187 char *get_term_charset( void )
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
188 {
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
189 char *charset = NULL;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
190
27359
d788e177a35e Rename some preprocessor directives from CONFIG_* to HAVE_* where appropriate;
diego
parents: 27341
diff changeset
191 #ifdef HAVE_LANGINFO
26016
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
192 setlocale( LC_CTYPE, "");
29290
ef46d5a66bb2 Use a malloced string for the get_term_charset return value.
reimar
parents: 28924
diff changeset
193 charset = strdup( nl_langinfo( CODESET ));
26016
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
194 setlocale( LC_CTYPE, "C");
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
195 #endif
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
196
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
197 return charset;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
198 }
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
199 #endif
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
200