annotate src/os_beos.c @ 1895:f637471a3607 v7.2.192

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