annotate osdep/getch2-os2.c @ 28184:0fb5551413f7

1000l, play_tree_parser_stop_keeping broke 0-termination of buffer
author reimar
date Thu, 01 Jan 2009 09:47:21 +0000
parents 4876c89bafdd
children d5d66bff938a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26016
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
1 /*
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
2 * getch2-os2.c : OS/2 TermIO for MPlayer
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>
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
29
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
30 #include "config.h"
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
31 #include "keycodes.h"
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
32 #include "input/input.h"
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
33 #include "mp_fifo.h"
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
34
27393
4876c89bafdd Rename font-related preprocessor directives.
diego
parents: 27359
diff changeset
35 #if defined(HAVE_LANGINFO) && defined(CONFIG_ICONV)
26016
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
36 #include <locale.h>
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
37 #include <langinfo.h>
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
38 #endif
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
39
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
40 int mp_input_slave_cmd_func( int fd, char *dest, int size )
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
41 {
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
42 PPIB ppib;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
43 CHAR szPipeName[ 100 ];
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
44 HFILE hpipe;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
45 ULONG ulAction;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
46 ULONG cbActual;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
47 ULONG rc;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
48
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
49 DosGetInfoBlocks( NULL, &ppib );
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
50
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
51 sprintf( szPipeName, "\\PIPE\\MPLAYER\\%lx", ppib->pib_ulpid );
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
52
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
53 rc = DosOpen( szPipeName, &hpipe, &ulAction, 0, FILE_NORMAL,
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
54 OPEN_ACTION_OPEN_IF_EXISTS,
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
55 OPEN_SHARE_DENYREADWRITE | OPEN_ACCESS_READWRITE,
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
56 NULL );
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
57 if( rc )
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
58 return MP_INPUT_NOTHING;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
59
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
60 rc = DosRead( hpipe, dest, size, &cbActual );
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
61 if( rc )
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
62 return MP_INPUT_NOTHING;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
63
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
64 rc = cbActual;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
65
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
66 // Send ACK
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
67 DosWrite( hpipe, &rc, sizeof( ULONG ), &cbActual );
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
68
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
69 DosClose( hpipe );
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
70
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
71 return rc;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
72 }
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 int screen_width = 80;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
76 int screen_height = 24;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
77 char *erase_to_end_of_line = NULL;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
78
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
79 void get_screen_size( void )
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
80 {
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
81 VIOMODEINFO vmi;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
82
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
83 vmi.cb = sizeof( VIOMODEINFO );
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
84
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
85 VioGetMode( &vmi, 0 );
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
86
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
87 screen_width = vmi.col;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
88 screen_height = vmi.row;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
89 }
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
90
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
91 static int getch2_status = 0;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
92
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
93 static int getch2_internal( void )
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
94 {
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
95 KBDKEYINFO kki;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
96
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
97 if( !getch2_status )
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
98 return -1;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
99
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
100 if( KbdCharIn( &kki, IO_NOWAIT, 0 ))
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
101 return -1;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
102
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
103 // key pressed ?
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
104 if( kki.fbStatus )
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
105 {
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
106 // extended key ?
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
107 if(( kki.chChar == 0x00 ) || ( kki.chChar == 0xE0 ))
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
108 {
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
109 switch( kki.chScan )
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
110 {
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
111 case 0x4B : // Left
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
112 return KEY_LEFT;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
113
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
114 case 0x48 : // Up
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
115 return KEY_UP;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
116
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
117 case 0x4D : // Right
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
118 return KEY_RIGHT;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
119
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
120 case 0x50 : // Down
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
121 return KEY_DOWN;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
122
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
123 case 0x53 : // Delete
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
124 return KEY_DELETE;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
125
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
126 case 0x52 : // Insert
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
127 return KEY_INSERT;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
128
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
129 case 0x47 : // Home
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
130 return KEY_HOME;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
131
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
132 case 0x4F : // End
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
133 return KEY_END;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
134
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
135 case 0x49 : // Page Up
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
136 return KEY_PAGE_UP;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
137
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
138 case 0x51 : // Page Down
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
139 return KEY_PAGE_DOWN;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
140 }
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
141 }
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
142 else
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
143 {
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
144 switch( kki.chChar )
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
145 {
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
146 case 0x08 : // Backspace
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
147 return KEY_BS;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
148
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
149 case 0x1B : // Esc
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
150 return KEY_ESC;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
151
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
152 case 0x0D : // Enter
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
153 // Keypad Enter ?
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
154 if( kki.chScan == 0xE0 )
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
155 return KEY_KPENTER;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
156 break;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
157 }
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
158
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
159 return kki.chChar;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
160 }
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 return -1;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
164 }
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
165
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
166 void getch2( void )
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
167 {
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
168 int key;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
169
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
170 key = getch2_internal();
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
171 if( key != -1 )
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
172 mplayer_put_key( key );
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
173 }
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
174
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
175 void getch2_enable( void )
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
176 {
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
177 getch2_status = 1;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
178 }
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
179
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
180 void getch2_disable( void )
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
181 {
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
182 getch2_status = 0;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
183 }
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
184
27393
4876c89bafdd Rename font-related preprocessor directives.
diego
parents: 27359
diff changeset
185 #ifdef CONFIG_ICONV
26016
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
186 char *get_term_charset( void )
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
187 {
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
188 char *charset = NULL;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
189
27359
d788e177a35e Rename some preprocessor directives from CONFIG_* to HAVE_* where appropriate;
diego
parents: 27341
diff changeset
190 #ifdef HAVE_LANGINFO
26016
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
191 setlocale( LC_CTYPE, "");
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
192 charset = nl_langinfo( CODESET );
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
193 setlocale( LC_CTYPE, "C");
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
194 #endif
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
195
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
196 return charset;
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
197 }
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
198 #endif
528bdf17dd8a OS/2 getch2() support
diego
parents:
diff changeset
199