… | |
… | |
23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
24 | *----------------------------------------------------------------------*/ |
24 | *----------------------------------------------------------------------*/ |
25 | |
25 | |
26 | #include "../config.h" /* NECESSARY */ |
26 | #include "../config.h" /* NECESSARY */ |
27 | #include "rxvt.h" /* NECESSARY */ |
27 | #include "rxvt.h" /* NECESSARY */ |
28 | #include "misc.intpro" /* PROTOS for internal routines */ |
|
|
29 | |
28 | |
30 | char * |
29 | char * |
31 | rxvt_wcstombs (const wchar_t *str, int len) |
30 | rxvt_wcstombs (const wchar_t *str, int len) |
32 | { |
31 | { |
33 | if (len < 0) len = wcslen (str); |
32 | if (len < 0) len = wcslen (str); |
… | |
… | |
36 | char *r = (char *)rxvt_malloc (len * MB_CUR_MAX + 1); |
35 | char *r = (char *)rxvt_malloc (len * MB_CUR_MAX + 1); |
37 | |
36 | |
38 | char *dst = r; |
37 | char *dst = r; |
39 | while (len--) |
38 | while (len--) |
40 | { |
39 | { |
41 | int l = wcrtomb (dst, *str++, mbs); |
40 | ssize_t l = wcrtomb (dst, *str++, mbs); |
|
|
41 | |
42 | if (l < 0) |
42 | if (l < 0) |
43 | *dst++ = '?'; |
43 | *dst++ = '?'; |
44 | else |
44 | else |
45 | dst += l; |
45 | dst += l; |
46 | } |
46 | } |
47 | |
47 | |
48 | *dst++ = 0; |
48 | *dst++ = 0; |
49 | |
49 | |
50 | return r; |
50 | return (char *)rxvt_realloc (r, dst - r); |
51 | } |
51 | } |
52 | |
52 | |
53 | wchar_t * |
53 | wchar_t * |
54 | rxvt_mbstowcs (const char *str, int len) |
54 | rxvt_mbstowcs (const char *str, int len) |
55 | { |
55 | { |
56 | if (len < 0) len = strlen (str); |
56 | if (len < 0) len = strlen (str); |
57 | |
57 | |
58 | wchar_t *r = (wchar_t *)rxvt_malloc ((len + 1) * sizeof (wchar_t)); |
58 | wchar_t *r = (wchar_t *)rxvt_malloc ((len + 1) * sizeof (wchar_t)); |
59 | |
59 | |
60 | if (mbstowcs (r, str, len + 1) < 0) |
60 | if ((ssize_t)mbstowcs (r, str, len + 1) < 0) |
61 | *r = 0; |
61 | *r = 0; |
62 | |
62 | |
63 | return r; |
63 | return r; |
64 | } |
64 | } |
65 | |
65 | |
… | |
… | |
71 | char *r = (char *)rxvt_malloc (len * 4 + 1); |
71 | char *r = (char *)rxvt_malloc (len * 4 + 1); |
72 | char *p = r; |
72 | char *p = r; |
73 | |
73 | |
74 | while (len--) |
74 | while (len--) |
75 | { |
75 | { |
76 | unicode_t w = *str++; |
76 | unicode_t w = *str++ & UNICODE_MASK; |
77 | |
77 | |
78 | if (w < 0x000080) |
78 | if (w < 0x000080) |
79 | *p++ = w; |
79 | *p++ = w; |
80 | else if (w < 0x000800) |
80 | else if (w < 0x000800) |
81 | *p++ = 0xc0 | ( w >> 6), |
81 | *p++ = 0xc0 | ( w >> 6), |
… | |
… | |
91 | *p++ = 0x80 | ( w & 0x3f); |
91 | *p++ = 0x80 | ( w & 0x3f); |
92 | else |
92 | else |
93 | *p++ = '?'; |
93 | *p++ = '?'; |
94 | } |
94 | } |
95 | |
95 | |
96 | *p = 0; |
96 | *p++ = 0; |
97 | |
97 | |
98 | return r; |
98 | return (char *)rxvt_realloc (r, p - r); |
99 | } |
99 | } |
100 | |
100 | |
101 | wchar_t * |
101 | wchar_t * |
102 | rxvt_utf8towcs (const char *str, int len) |
102 | rxvt_utf8towcs (const char *str, int len) |
103 | { |
103 | { |
104 | if (len < 0) len = strlen (str); |
104 | if (len < 0) len = strlen (str); |
105 | |
105 | |
106 | wchar_t *r = (wchar_t *)rxvt_malloc ((len + 1) * sizeof (wchar_t)); |
106 | wchar_t *r = (wchar_t *)rxvt_malloc ((len + 1) * sizeof (wchar_t)), |
107 | wchar_t *p = r; |
107 | *p = r; |
108 | |
108 | |
109 | unsigned char *s = (unsigned char *)str; |
109 | unsigned char *s = (unsigned char *)str, |
|
|
110 | *e = s + len; |
110 | |
111 | |
111 | while (len) |
112 | for (;;) |
112 | { |
113 | { |
|
|
114 | len = e - s; |
|
|
115 | |
|
|
116 | if (len == 0) |
|
|
117 | break; |
113 | if (s[0] < 0x80) |
118 | else if (s[0] < 0x80) |
114 | { |
|
|
115 | *p++ = *s++; len--; |
119 | *p++ = *s++; |
116 | } |
|
|
117 | else if (len > 0 |
120 | else if (len >= 2 |
118 | && s[0] >= 0xc2 && s[0] <= 0xdf |
121 | && s[0] >= 0xc2 && s[0] <= 0xdf |
119 | && (s[1] & 0xc0) == 0x80) |
122 | && (s[1] & 0xc0) == 0x80) |
120 | { |
123 | { |
121 | *p++ = ((s[0] & 0x1f) << 6) |
124 | *p++ = ((s[0] & 0x1f) << 6) |
122 | | (s[1] & 0x3f); |
125 | | (s[1] & 0x3f); |
123 | s += 2; len -= 2; |
126 | s += 2; |
124 | } |
127 | } |
125 | else if (len > 1 |
128 | else if (len >= 3 |
126 | && ( (s[0] == 0xe0 && s[1] >= 0xa0 && s[1] <= 0xbf) |
129 | && ( (s[0] == 0xe0 && s[1] >= 0xa0 && s[1] <= 0xbf) |
127 | || (s[0] >= 0xe1 && s[0] <= 0xec && s[1] >= 0x80 && s[1] <= 0xbf) |
130 | || (s[0] >= 0xe1 && s[0] <= 0xec && s[1] >= 0x80 && s[1] <= 0xbf) |
128 | || (s[0] == 0xed && s[1] >= 0x80 && s[1] <= 0x9f) |
131 | || (s[0] == 0xed && s[1] >= 0x80 && s[1] <= 0x9f) |
129 | || (s[0] >= 0xee && s[0] <= 0xef && s[1] >= 0x80 && s[1] <= 0xbf) |
132 | || (s[0] >= 0xee && s[0] <= 0xef && s[1] >= 0x80 && s[1] <= 0xbf) |
130 | ) |
133 | ) |
131 | && (s[2] & 0xc0) == 0x80) |
134 | && (s[2] & 0xc0) == 0x80) |
132 | { |
135 | { |
133 | *p++ = ((s[0] & 0x0f) << 12) |
136 | *p++ = ((s[0] & 0x0f) << 12) |
134 | | ((s[1] & 0x3f) << 6) |
137 | | ((s[1] & 0x3f) << 6) |
135 | | (s[2] & 0x3f); |
138 | | (s[2] & 0x3f); |
136 | s += 3; len -= 3; |
139 | s += 3; |
137 | } |
140 | } |
138 | else if (len > 2 |
141 | else if (len >= 4 |
139 | && ( (s[0] == 0xf0 && s[1] >= 0x90 && s[1] <= 0xbf) |
142 | && ( (s[0] == 0xf0 && s[1] >= 0x90 && s[1] <= 0xbf) |
140 | || (s[0] >= 0xf1 && s[0] <= 0xf3 && s[1] >= 0x80 && s[1] <= 0xbf) |
143 | || (s[0] >= 0xf1 && s[0] <= 0xf3 && s[1] >= 0x80 && s[1] <= 0xbf) |
141 | || (s[0] == 0xf4 && s[1] >= 0x80 && s[1] <= 0x8f) |
144 | || (s[0] == 0xf4 && s[1] >= 0x80 && s[1] <= 0x8f) |
142 | ) |
145 | ) |
143 | && (s[2] & 0xc0) == 0x80 |
146 | && (s[2] & 0xc0) == 0x80 |
… | |
… | |
145 | { |
148 | { |
146 | *p++ = ((s[0] & 0x07) << 18) |
149 | *p++ = ((s[0] & 0x07) << 18) |
147 | | ((s[1] & 0x3f) << 12) |
150 | | ((s[1] & 0x3f) << 12) |
148 | | ((s[2] & 0x3f) << 6) |
151 | | ((s[2] & 0x3f) << 6) |
149 | | (s[3] & 0x3f); |
152 | | (s[3] & 0x3f); |
150 | s += 4; len -= 4; |
153 | s += 4; |
151 | } |
154 | } |
152 | else |
155 | else |
153 | { |
156 | { |
154 | *p++ = 0xfffd; |
157 | *p++ = 0xfffd; |
155 | s++; len--; |
158 | s++; |
156 | } |
159 | } |
157 | } |
160 | } |
158 | |
161 | |
159 | *p = 0; |
162 | *p = 0; |
160 | |
163 | |
… | |
… | |
165 | rxvt_strdup (const char *str) |
168 | rxvt_strdup (const char *str) |
166 | { |
169 | { |
167 | return str ? strdup (str) : 0; |
170 | return str ? strdup (str) : 0; |
168 | } |
171 | } |
169 | |
172 | |
170 | /* INTPROTO */ |
|
|
171 | char * |
173 | char * |
172 | rxvt_r_basename (const char *str) |
174 | rxvt_r_basename (const char *str) |
173 | { |
175 | { |
174 | char *base = strrchr (str, '/'); |
176 | char *base = strrchr (str, '/'); |
175 | |
177 | |
… | |
… | |
177 | } |
179 | } |
178 | |
180 | |
179 | /* |
181 | /* |
180 | * Print an error message |
182 | * Print an error message |
181 | */ |
183 | */ |
182 | /* INTPROTO */ |
|
|
183 | void |
184 | void |
184 | rxvt_vlog (const char *fmt, va_list arg_ptr) |
185 | rxvt_vlog (const char *fmt, va_list arg_ptr) |
185 | { |
186 | { |
186 | char msg[1024]; |
187 | char msg[1024]; |
187 | |
188 | |
… | |
… | |
191 | (*GET_R->log_hook) (msg); |
192 | (*GET_R->log_hook) (msg); |
192 | else |
193 | else |
193 | write (STDOUT_FILENO, msg, strlen (msg)); |
194 | write (STDOUT_FILENO, msg, strlen (msg)); |
194 | } |
195 | } |
195 | |
196 | |
196 | /* INTPROTO */ |
|
|
197 | void |
197 | void |
198 | rxvt_log (const char *fmt,...) |
198 | rxvt_log (const char *fmt,...) |
199 | { |
199 | { |
200 | va_list arg_ptr; |
200 | va_list arg_ptr; |
201 | |
201 | |
… | |
… | |
205 | } |
205 | } |
206 | |
206 | |
207 | /* |
207 | /* |
208 | * Print an error message |
208 | * Print an error message |
209 | */ |
209 | */ |
210 | /* INTPROTO */ |
|
|
211 | void |
210 | void |
212 | rxvt_warn (const char *fmt,...) |
211 | rxvt_warn (const char *fmt,...) |
213 | { |
212 | { |
214 | va_list arg_ptr; |
213 | va_list arg_ptr; |
215 | |
214 | |
… | |
… | |
218 | va_start (arg_ptr, fmt); |
217 | va_start (arg_ptr, fmt); |
219 | rxvt_vlog (fmt, arg_ptr); |
218 | rxvt_vlog (fmt, arg_ptr); |
220 | va_end (arg_ptr); |
219 | va_end (arg_ptr); |
221 | } |
220 | } |
222 | |
221 | |
223 | /* INTPROTO */ |
|
|
224 | void |
222 | void |
225 | rxvt_fatal (const char *fmt,...) |
223 | rxvt_fatal (const char *fmt,...) |
226 | { |
224 | { |
227 | va_list arg_ptr; |
225 | va_list arg_ptr; |
228 | |
226 | |
… | |
… | |
235 | rxvt_exit_failure (); |
233 | rxvt_exit_failure (); |
236 | } |
234 | } |
237 | |
235 | |
238 | class rxvt_failure_exception rxvt_failure_exception; |
236 | class rxvt_failure_exception rxvt_failure_exception; |
239 | |
237 | |
240 | /* INTPROTO */ |
|
|
241 | void |
238 | void |
242 | rxvt_exit_failure () |
239 | rxvt_exit_failure () |
243 | { |
240 | { |
244 | throw (rxvt_failure_exception); |
241 | throw (rxvt_failure_exception); |
245 | } |
242 | } |
… | |
… | |
250 | * No Match |
247 | * No Match |
251 | * return: 0 |
248 | * return: 0 |
252 | * Match |
249 | * Match |
253 | * return: strlen (S2) |
250 | * return: strlen (S2) |
254 | */ |
251 | */ |
255 | /* INTPROTO */ |
|
|
256 | int |
252 | int |
257 | rxvt_Str_match (const char *s1, const char *s2) |
253 | rxvt_Str_match (const char *s1, const char *s2) |
258 | { |
254 | { |
259 | int n = strlen (s2); |
255 | int n = strlen (s2); |
260 | |
256 | |
261 | return ((strncmp (s1, s2, n) == 0) ? n : 0); |
257 | return ((strncmp (s1, s2, n) == 0) ? n : 0); |
262 | } |
258 | } |
263 | |
259 | |
264 | /* INTPROTO */ |
|
|
265 | const char * |
260 | const char * |
266 | rxvt_Str_skip_space (const char *str) |
261 | rxvt_Str_skip_space (const char *str) |
267 | { |
262 | { |
268 | if (str) |
263 | if (str) |
269 | while (*str && isspace (*str)) |
264 | while (*str && isspace (*str)) |
… | |
… | |
274 | |
269 | |
275 | /* |
270 | /* |
276 | * remove leading/trailing space and strip-off leading/trailing quotes. |
271 | * remove leading/trailing space and strip-off leading/trailing quotes. |
277 | * in place. |
272 | * in place. |
278 | */ |
273 | */ |
279 | /* INTPROTO */ |
|
|
280 | char * |
274 | char * |
281 | rxvt_Str_trim (char *str) |
275 | rxvt_Str_trim (char *str) |
282 | { |
276 | { |
283 | char *r, *s; |
277 | char *r, *s; |
284 | int n; |
|
|
285 | |
278 | |
286 | if (!str || !*str) /* shortcut */ |
279 | if (!str || !*str) /* shortcut */ |
287 | return str; |
280 | return str; |
288 | |
281 | |
289 | /* skip leading spaces */ |
282 | /* skip leading spaces */ |
290 | for (s = str; *s && isspace (*s); s++) ; |
283 | for (s = str; *s && isspace (*s); s++) ; |
|
|
284 | |
291 | /* goto end of string */ |
285 | /* goto end of string */ |
292 | for (n = 0, r = s; *r++; n++) ; |
286 | r = s + strlen (s) - 1; |
293 | r -= 2; |
287 | |
294 | /* dump return */ |
288 | /* dump return and other trailing whitespace */ |
295 | if (n > 0 && *r == '\n') |
289 | while (r > s && isspace (*r)) |
296 | n--, r--; |
290 | r--; |
297 | /* backtrack along trailing spaces */ |
291 | |
298 | for (; n > 0 && isspace (*r); r--, n--) ; |
292 | #if 0 |
299 | /* skip matching leading/trailing quotes */ |
293 | /* skip matching leading/trailing quotes */ |
300 | if (*s == '"' && *r == '"' && n > 1) |
294 | if (*s == '"' && *r == '"' && n > 1) |
301 | { |
295 | { |
302 | s++; |
296 | s++; |
303 | n -= 2; |
297 | n -= 2; |
304 | } |
298 | } |
|
|
299 | #endif |
305 | |
300 | |
306 | /* copy back over: forwards copy */ |
301 | memmove (str, s, r + 1 - s); |
307 | for (r = str; n; n--) |
302 | str[r + 1 - s] = 0; |
308 | *r++ = *s++; |
|
|
309 | *r = '\0'; |
|
|
310 | |
303 | |
311 | return str; |
304 | return str; |
312 | } |
305 | } |
313 | |
306 | |
314 | /* |
307 | /* |
… | |
… | |
323 | * "M-x" prefixed strings, append "\r" if needed |
316 | * "M-x" prefixed strings, append "\r" if needed |
324 | * "\E]" prefixed strings (XTerm escape sequence) append ST if needed |
317 | * "\E]" prefixed strings (XTerm escape sequence) append ST if needed |
325 | * |
318 | * |
326 | * returns the converted string length |
319 | * returns the converted string length |
327 | */ |
320 | */ |
328 | /* INTPROTO */ |
|
|
329 | int |
321 | int |
330 | rxvt_Str_escaped (char *str) |
322 | rxvt_Str_escaped (char *str) |
331 | { |
323 | { |
332 | char ch, *s, *d; |
324 | char ch, *s, *d; |
333 | int i, num, append = 0; |
325 | int i, num, append = 0; |
… | |
… | |
397 | return (d - str); |
389 | return (d - str); |
398 | } |
390 | } |
399 | |
391 | |
400 | /* |
392 | /* |
401 | * Split a comma-separated string into an array, stripping leading and |
393 | * Split a comma-separated string into an array, stripping leading and |
402 | * trailing spaces (and paired quotes) from each entry. Empty strings |
394 | * trailing spaces from each entry. Empty strings are properly returned |
403 | * are properly returned |
|
|
404 | * Caller should free each entry and array when done |
395 | * Caller should free each entry and array when done |
405 | */ |
396 | */ |
406 | /* INTPROTO */ |
|
|
407 | char ** |
397 | char ** |
408 | rxvt_splitcommastring (const char *cs) |
398 | rxvt_splitcommastring (const char *cs) |
409 | { |
399 | { |
410 | int l, n, p; |
400 | int l, n, p; |
411 | const char *s, *t; |
401 | const char *s, *t; |
… | |
… | |
415 | s = ""; |
405 | s = ""; |
416 | |
406 | |
417 | for (n = 1, t = s; *t; t++) |
407 | for (n = 1, t = s; *t; t++) |
418 | if (*t == ',') |
408 | if (*t == ',') |
419 | n++; |
409 | n++; |
|
|
410 | |
420 | ret = (char **)malloc ((n + 1) * sizeof (char *)); |
411 | ret = (char **)malloc ((n + 1) * sizeof (char *)); |
421 | ret[n] = NULL; |
412 | ret[n] = NULL; |
422 | |
413 | |
423 | for (l = 0, t = s; l < n; l++) |
414 | for (l = 0, t = s; l < n; l++) |
424 | { |
415 | { |
… | |
… | |
428 | strncpy (ret[l], s, p); |
419 | strncpy (ret[l], s, p); |
429 | ret[l][p] = '\0'; |
420 | ret[l][p] = '\0'; |
430 | rxvt_Str_trim (ret[l]); |
421 | rxvt_Str_trim (ret[l]); |
431 | s = ++t; |
422 | s = ++t; |
432 | } |
423 | } |
|
|
424 | |
433 | return ret; |
425 | return ret; |
434 | } |
426 | } |
435 | |
427 | |
436 | void |
428 | void |
437 | rxvt_freecommastring (char **cs) |
429 | rxvt_freecommastring (char **cs) |
… | |
… | |
453 | * search for FILE in the current working directory, and within the |
445 | * search for FILE in the current working directory, and within the |
454 | * colon-delimited PATHLIST, adding the file extension EXT if required. |
446 | * colon-delimited PATHLIST, adding the file extension EXT if required. |
455 | * |
447 | * |
456 | * FILE is either semi-colon or zero terminated |
448 | * FILE is either semi-colon or zero terminated |
457 | */ |
449 | */ |
458 | /* INTPROTO */ |
|
|
459 | char * |
450 | char * |
460 | rxvt_File_search_path (const char *pathlist, const char *file, const char *ext) |
451 | rxvt_File_search_path (const char *pathlist, const char *file, const char *ext) |
461 | { |
452 | { |
462 | int maxpath, len; |
453 | int maxpath, len; |
463 | const char *p, *path; |
454 | const char *p, *path; |
… | |
… | |
526 | } |
517 | } |
527 | } |
518 | } |
528 | return NULL; |
519 | return NULL; |
529 | } |
520 | } |
530 | |
521 | |
531 | /* INTPROTO */ |
|
|
532 | char * |
522 | char * |
533 | rxvt_File_find (const char *file, const char *ext, const char *path) |
523 | rxvt_File_find (const char *file, const char *ext, const char *path) |
534 | { |
524 | { |
535 | char *f; |
525 | char *f; |
536 | |
526 | |
537 | if (file == NULL || *file == '\0') |
527 | if (file == NULL || *file == '\0') |
538 | return NULL; |
528 | return NULL; |
539 | |
529 | |
540 | /* search environment variables here too */ |
|
|
541 | if ((f = rxvt_File_search_path (path, file, ext)) == NULL) |
530 | f = rxvt_File_search_path (path, file, ext); |
542 | #ifdef PATH_ENV |
|
|
543 | if ((f = rxvt_File_search_path (getenv (PATH_ENV), file, ext)) == NULL) |
|
|
544 | #endif |
|
|
545 | f = rxvt_File_search_path (getenv ("PATH"), file, ext); |
|
|
546 | |
531 | |
547 | #ifdef DEBUG_SEARCH_PATH |
532 | #ifdef DEBUG_SEARCH_PATH |
548 | if (f) |
533 | if (f) |
549 | fprintf (stderr, "found: \"%s\"\n", f); |
534 | fprintf (stderr, "found: \"%s\"\n", f); |
550 | #endif |
535 | #endif |
… | |
… | |
559 | |
544 | |
560 | /* |
545 | /* |
561 | * Draw top/left and bottom/right border shadows around windows |
546 | * Draw top/left and bottom/right border shadows around windows |
562 | */ |
547 | */ |
563 | #if defined(RXVT_SCROLLBAR) || defined(MENUBAR) |
548 | #if defined(RXVT_SCROLLBAR) || defined(MENUBAR) |
564 | /* INTPROTO */ |
|
|
565 | void |
549 | void |
566 | rxvt_Draw_Shadow (Display *display, Window win, GC topShadow, GC botShadow, int x, int y, int w, int h) |
550 | rxvt_Draw_Shadow (Display *display, Window win, GC topShadow, GC botShadow, int x, int y, int w, int h) |
567 | { |
551 | { |
568 | int shadow; |
552 | int shadow; |
569 | |
553 | |
570 | shadow = (w == 0 || h == 0) ? 1 : SHADOW; |
554 | shadow = (w == 0 || h == 0) ? 1 : MENU_SHADOW; |
571 | w += x - 1; |
555 | w += x - 1; |
572 | h += y - 1; |
556 | h += y - 1; |
573 | for (; shadow-- > 0; x++, y++, w--, h--) |
557 | for (; shadow-- > 0; x++, y++, w--, h--) |
574 | { |
558 | { |
575 | XDrawLine (display, win, topShadow, x, y, w, y); |
559 | XDrawLine (display, win, topShadow, x, y, w, y); |
… | |
… | |
580 | } |
564 | } |
581 | #endif |
565 | #endif |
582 | |
566 | |
583 | /* button shapes */ |
567 | /* button shapes */ |
584 | #ifdef MENUBAR |
568 | #ifdef MENUBAR |
585 | /* INTPROTO */ |
|
|
586 | void |
569 | void |
587 | rxvt_Draw_Triangle (Display *display, Window win, GC topShadow, GC botShadow, int x, int y, int w, int type) |
570 | rxvt_Draw_Triangle (Display *display, Window win, GC topShadow, GC botShadow, int x, int y, int w, int type) |
588 | { |
571 | { |
589 | switch (type) |
572 | switch (type) |
590 | { |
573 | { |
… | |
… | |
621 | #endif |
604 | #endif |
622 | |
605 | |
623 | } |
606 | } |
624 | } |
607 | } |
625 | #endif |
608 | #endif |
|
|
609 | |
|
|
610 | // should not be used in interactive programs, for obvious reasons |
|
|
611 | void rxvt_usleep (int usecs) |
|
|
612 | { |
|
|
613 | #if HAVE_NANOSLEEP |
|
|
614 | struct timespec ts; |
|
|
615 | |
|
|
616 | ts.tv_sec = 0; |
|
|
617 | ts.tv_nsec = usecs * 1000; |
|
|
618 | nanosleep (&ts, NULL); |
|
|
619 | #else |
|
|
620 | /* use select for timing */ |
|
|
621 | struct timeval tv; |
|
|
622 | |
|
|
623 | tv.tv_sec = 0; |
|
|
624 | tv.tv_usec = usecs; |
|
|
625 | select (0, NULL, NULL, NULL, &tv); |
|
|
626 | #endif |
|
|
627 | } |
|
|
628 | |
626 | /*----------------------- end-of-file (C source) -----------------------*/ |
629 | /*----------------------- end-of-file (C source) -----------------------*/ |
|
|
630 | |