annotate src/os_beos.c @ 4301:b53fa3b43193 v7.3.900

updated for version 7.3.900 Problem: Not obvious that some mouse features are mutual-exclusive. Solution: Add a comment.
author Bram Moolenaar <bram@vim.org>
date Mon, 15 Apr 2013 15:40:33 +0200
parents e6d8b44065bc
children 4aead6a9b7a9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 * BeBox port Copyright 1997 by Olaf Seibert.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 * Do ":help uganda" in Vim to read copying and usage conditions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 * Do ":help credits" in Vim to see a list of people who contributed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 * See README.txt for an overview of the Vim source code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 * os_beos.c Additional stuff for BeOS (rest is in os_unix.c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 #include <float.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 #include <termios.h>
3927
e6d8b44065bc updated for version 7.3.719
Bram Moolenaar <bram@vim.org>
parents: 62
diff changeset
16 #ifndef PROTO
e6d8b44065bc updated for version 7.3.719
Bram Moolenaar <bram@vim.org>
parents: 62
diff changeset
17 # include <kernel/OS.h>
e6d8b44065bc updated for version 7.3.719
Bram Moolenaar <bram@vim.org>
parents: 62
diff changeset
18 #endif
e6d8b44065bc updated for version 7.3.719
Bram Moolenaar <bram@vim.org>
parents: 62
diff changeset
19
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 #include "vim.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 #if USE_THREAD_FOR_INPUT_WITH_TIMEOUT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 #ifdef PROTO /* making prototypes on Unix */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 #define sem_id int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 #define thread_id int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 char_u charbuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 signed char charcount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 sem_id character_present;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 sem_id character_wanted;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 thread_id read_thread_id;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 #define TRY_ABORT 0 /* This code does not work so turn it off. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 #if TRY_ABORT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 mostly_ignore(int sig)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 static long
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 read_thread(void *dummy)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 signal(SIGINT, SIG_IGN);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 signal(SIGQUIT, SIG_IGN);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 #if TRY_ABORT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 signal(SIGUSR1, mostly_ignore);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 for (;;) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 if (acquire_sem(character_wanted) != B_NO_ERROR)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 charcount = read(read_cmd_fd, &charbuf, 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 release_sem(character_present);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 beos_cleanup_read_thread(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 if (character_present > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 delete_sem(character_present);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 character_present = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 if (read_thread_id > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 kill_thread(read_thread_id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 read_thread_id = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 * select() emulation. Hopefully, in DR9 there will be something
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 * useful supplied by the system. ... Alas, not. Not in AAPR, nor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 * in PR or even PR2... R3 then maybe? I don't think so!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 beos_select(int nbits,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 struct fd_set *rbits,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 struct fd_set *wbits,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 struct fd_set *ebits,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 struct timeval *timeout)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 bigtime_t tmo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 if (nbits == 0) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 /* select is purely being used for delay */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 snooze(timeout->tv_sec * 1e6 + timeout->tv_usec);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 #if 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 * This does not seem to work either. Reads here are not supposed to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 * block indefinitely, yet they do. This is most annoying.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 if (FD_ISSET(0, rbits)) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 char cbuf[1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 int count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 struct termios told;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 struct termios tnew;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 tcgetattr(0, &told);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 tnew = told;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 tnew.c_lflag &= ~ICANON;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 tnew.c_cc[VMIN] = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 tnew.c_cc[VTIME] = timeout->tv_sec * 10 + timeout->tv_usec / 100000;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 tcsetattr(0, TCSANOW, &tnew);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 count = read(0, &cbuf, sizeof(cbuf));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 tcsetattr(0, TCSANOW, &told);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 if (count > 0) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 add_to_input_buf(&cbuf[0], count);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 return 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 #if USE_THREAD_FOR_INPUT_WITH_TIMEOUT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 * Check if the operation is really on stdin...
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 if (FD_ISSET(read_cmd_fd, rbits))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 int acquired;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 * Is this the first time through?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 * Then start up the thread and initialise the semaphores.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 if (character_present == 0) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 character_present = create_sem(0, "vim character_present");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 character_wanted = create_sem(1, "vim character_wanted");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 read_thread_id = spawn_thread(read_thread, "vim async read",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 B_NORMAL_PRIORITY, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 atexit(beos_cleanup_read_thread);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 resume_thread(read_thread_id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 /* timeout == NULL means "indefinitely" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 if (timeout) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 tmo = timeout->tv_sec * 1e6 + timeout->tv_usec;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 /* 0 means "don't wait, which is impossible to do exactly. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 if (tmo == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 tmo = 1.0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150 #if TRY_ABORT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 release_sem(character_wanted);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 if (timeout)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 acquired = acquire_sem_etc(character_present, 1, B_TIMEOUT, tmo);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 acquired = acquire_sem(character_present);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 if (acquired == B_NO_ERROR) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 if (charcount > 0) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 add_to_input_buf(&charbuf, 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 #if !TRY_ABORT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 release_sem(character_wanted);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 return 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 } else {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 #if !TRY_ABORT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 release_sem(character_wanted);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 #if TRY_ABORT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 else {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 * Timeout occurred. Break the read() call by sending
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 * a signal. Problem: it may be just read()ing it now.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 * Therefore we still have to finish the handshake with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 * the thread and maybe remember the character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 kill(read_thread_id, SIGUSR1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 * If some other error occurred, don't hang now.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 * (We will most likely hang later anyway...)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186 if (acquired == B_TIMED_OUT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 acquire_sem(character_present);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 if (charcount > 0) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189 add_to_input_buf(&charbuf, 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 return 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200