Mercurial > vim
annotate src/time.c @ 32015:018c77663f66 v9.0.1339
patch 9.0.1339: no test for :disassemble with class function
Commit: https://github.com/vim/vim/commit/38f1ab31fa31196360dc4a31aeb388889b8bd6b8
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Feb 21 20:09:46 2023 +0000
patch 9.0.1339: no test for :disassemble with class function
Problem: No test for :disassemble with class function.
Solution: Add a test.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 21 Feb 2023 21:15:03 +0100 |
parents | 4545f58c8490 |
children | 98774a275d6d |
rev | line source |
---|---|
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2 * |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3 * VIM - Vi IMproved by Bram Moolenaar |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4 * |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5 * Do ":help uganda" in Vim to read copying and usage conditions. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6 * Do ":help credits" in Vim to see a list of people who contributed. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 * See README.txt for an overview of the Vim source code. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
9 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
10 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
11 * time.c: functions related to time and timers |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
13 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
14 #include "vim.h" |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
16 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
17 * Cache of the current timezone name as retrieved from TZ, or an empty string |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
18 * where unset, up to 64 octets long including trailing null byte. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
19 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
20 #if defined(HAVE_LOCALTIME_R) && defined(HAVE_TZSET) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
21 static char tz_cache[64]; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
22 #endif |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
23 |
19934
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
19396
diff
changeset
|
24 #define FOR_ALL_TIMERS(t) \ |
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
19396
diff
changeset
|
25 for ((t) = first_timer; (t) != NULL; (t) = (t)->tr_next) |
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
19396
diff
changeset
|
26 |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
27 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
28 * Call either localtime(3) or localtime_r(3) from POSIX libc time.h, with the |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
29 * latter version preferred for reentrancy. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
30 * |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
31 * If we use localtime_r(3) and we have tzset(3) available, check to see if the |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
32 * environment variable TZ has changed since the last run, and call tzset(3) to |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
33 * update the global timezone variables if it has. This is because the POSIX |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
34 * standard doesn't require localtime_r(3) implementations to do that as it |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
35 * does with localtime(3), and we don't want to call tzset(3) every time. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
36 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
37 static struct tm * |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
38 vim_localtime( |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
39 const time_t *timep, // timestamp for local representation |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
40 struct tm *result UNUSED) // pointer to caller return buffer |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
41 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
42 #ifdef HAVE_LOCALTIME_R |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
43 # ifdef HAVE_TZSET |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
44 char *tz; // pointer for TZ environment var |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
45 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
46 tz = (char *)mch_getenv((char_u *)"TZ"); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
47 if (tz == NULL) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
48 tz = ""; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
49 if (STRNCMP(tz_cache, tz, sizeof(tz_cache) - 1) != 0) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
50 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
51 tzset(); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
52 vim_strncpy((char_u *)tz_cache, (char_u *)tz, sizeof(tz_cache) - 1); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
53 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
54 # endif // HAVE_TZSET |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
55 return localtime_r(timep, result); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
56 #else |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
57 return localtime(timep); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
58 #endif // HAVE_LOCALTIME_R |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
59 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
60 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
61 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
62 * Return the current time in seconds. Calls time(), unless test_settime() |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
63 * was used. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
64 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
65 time_T |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
66 vim_time(void) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
67 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
68 # ifdef FEAT_EVAL |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
69 return time_for_testing == 0 ? time(NULL) : time_for_testing; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
70 # else |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
71 return time(NULL); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
72 # endif |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
73 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
74 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
75 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
76 * Replacement for ctime(), which is not safe to use. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
77 * Requires strftime(), otherwise returns "(unknown)". |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
78 * If "thetime" is invalid returns "(invalid)". Never returns NULL. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
79 * When "add_newline" is TRUE add a newline like ctime() does. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
80 * Uses a static buffer. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
81 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
82 char * |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
83 get_ctime(time_t thetime, int add_newline) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
84 { |
30797
1213e3988168
patch 9.0.0733: use of strftime() is not safe
Bram Moolenaar <Bram@vim.org>
parents:
30695
diff
changeset
|
85 static char buf[100]; // hopefully enough for every language |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
86 #ifdef HAVE_STRFTIME |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
87 struct tm tmval; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
88 struct tm *curtime; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
89 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
90 curtime = vim_localtime(&thetime, &tmval); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
91 // MSVC returns NULL for an invalid value of seconds. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
92 if (curtime == NULL) |
30797
1213e3988168
patch 9.0.0733: use of strftime() is not safe
Bram Moolenaar <Bram@vim.org>
parents:
30695
diff
changeset
|
93 vim_strncpy((char_u *)buf, (char_u *)_("(Invalid)"), sizeof(buf) - 2); |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
94 else |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
95 { |
27253
da5b8e1405c6
patch 8.2.4155: translating strftime() argument results in check error
Bram Moolenaar <Bram@vim.org>
parents:
27012
diff
changeset
|
96 // xgettext:no-c-format |
30797
1213e3988168
patch 9.0.0733: use of strftime() is not safe
Bram Moolenaar <Bram@vim.org>
parents:
30695
diff
changeset
|
97 if (strftime(buf, sizeof(buf) - 2, _("%a %b %d %H:%M:%S %Y"), curtime) |
1213e3988168
patch 9.0.0733: use of strftime() is not safe
Bram Moolenaar <Bram@vim.org>
parents:
30695
diff
changeset
|
98 == 0) |
1213e3988168
patch 9.0.0733: use of strftime() is not safe
Bram Moolenaar <Bram@vim.org>
parents:
30695
diff
changeset
|
99 { |
1213e3988168
patch 9.0.0733: use of strftime() is not safe
Bram Moolenaar <Bram@vim.org>
parents:
30695
diff
changeset
|
100 // Quoting "man strftime": |
1213e3988168
patch 9.0.0733: use of strftime() is not safe
Bram Moolenaar <Bram@vim.org>
parents:
30695
diff
changeset
|
101 // > If the length of the result string (including the terminating |
1213e3988168
patch 9.0.0733: use of strftime() is not safe
Bram Moolenaar <Bram@vim.org>
parents:
30695
diff
changeset
|
102 // > null byte) would exceed max bytes, then strftime() returns 0, |
1213e3988168
patch 9.0.0733: use of strftime() is not safe
Bram Moolenaar <Bram@vim.org>
parents:
30695
diff
changeset
|
103 // > and the contents of the array are undefined. |
1213e3988168
patch 9.0.0733: use of strftime() is not safe
Bram Moolenaar <Bram@vim.org>
parents:
30695
diff
changeset
|
104 vim_strncpy((char_u *)buf, (char_u *)_("(Invalid)"), |
1213e3988168
patch 9.0.0733: use of strftime() is not safe
Bram Moolenaar <Bram@vim.org>
parents:
30695
diff
changeset
|
105 sizeof(buf) - 2); |
1213e3988168
patch 9.0.0733: use of strftime() is not safe
Bram Moolenaar <Bram@vim.org>
parents:
30695
diff
changeset
|
106 } |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
107 # ifdef MSWIN |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
108 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
109 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
110 char_u *to_free = NULL; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
111 int len; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
112 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
113 acp_to_enc((char_u *)buf, (int)strlen(buf), &to_free, &len); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
114 if (to_free != NULL) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
115 { |
30797
1213e3988168
patch 9.0.0733: use of strftime() is not safe
Bram Moolenaar <Bram@vim.org>
parents:
30695
diff
changeset
|
116 STRNCPY(buf, to_free, sizeof(buf) - 2); |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
117 vim_free(to_free); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
118 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
119 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
120 # endif |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
121 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
122 #else |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
123 STRCPY(buf, "(unknown)"); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
124 #endif |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
125 if (add_newline) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
126 STRCAT(buf, "\n"); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
127 return buf; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
128 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
129 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
130 #if defined(FEAT_EVAL) || defined(PROTO) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
131 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
132 #if defined(MACOS_X) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
133 # include <time.h> // for time_t |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
134 #endif |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
135 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
136 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
137 * "localtime()" function |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
138 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
139 void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
140 f_localtime(typval_T *argvars UNUSED, typval_T *rettv) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
141 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
142 rettv->vval.v_number = (varnumber_T)time(NULL); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
143 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
144 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
145 # if defined(FEAT_RELTIME) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
146 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
147 * Convert a List to proftime_T. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
148 * Return FAIL when there is something wrong. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
149 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
150 static int |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
151 list2proftime(typval_T *arg, proftime_T *tm) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
152 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
153 long n1, n2; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
154 int error = FALSE; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
155 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
156 if (arg->v_type != VAR_LIST || arg->vval.v_list == NULL |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
157 || arg->vval.v_list->lv_len != 2) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
158 return FAIL; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
159 n1 = list_find_nr(arg->vval.v_list, 0L, &error); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
160 n2 = list_find_nr(arg->vval.v_list, 1L, &error); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
161 # ifdef MSWIN |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
162 tm->HighPart = n1; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
163 tm->LowPart = n2; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
164 # else |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
165 tm->tv_sec = n1; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
166 tm->tv_usec = n2; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
167 # endif |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
168 return error ? FAIL : OK; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
169 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
170 # endif // FEAT_RELTIME |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
171 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
172 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
173 * "reltime()" function |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
174 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
175 void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
176 f_reltime(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
177 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
178 # ifdef FEAT_RELTIME |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
179 proftime_T res; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
180 proftime_T start; |
25252
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25250
diff
changeset
|
181 long n1, n2; |
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25250
diff
changeset
|
182 |
29175
755ab148288b
patch 8.2.5107: some callers of rettv_list_alloc() check for not OK
Bram Moolenaar <Bram@vim.org>
parents:
28725
diff
changeset
|
183 if (rettv_list_alloc(rettv) == FAIL) |
25252
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25250
diff
changeset
|
184 return; |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
185 |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
186 if (in_vim9script() |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
187 && (check_for_opt_list_arg(argvars, 0) == FAIL |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
188 || (argvars[0].v_type != VAR_UNKNOWN |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
189 && check_for_opt_list_arg(argvars, 1) == FAIL))) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
190 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
191 |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
192 if (argvars[0].v_type == VAR_UNKNOWN) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
193 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
194 // No arguments: get current time. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
195 profile_start(&res); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
196 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
197 else if (argvars[1].v_type == VAR_UNKNOWN) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
198 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
199 if (list2proftime(&argvars[0], &res) == FAIL) |
25250
532faf893d37
patch 8.2.3161: Vim9: no error when reltime() has invalid arguments
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
200 { |
532faf893d37
patch 8.2.3161: Vim9: no error when reltime() has invalid arguments
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
201 if (in_vim9script()) |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26476
diff
changeset
|
202 emsg(_(e_invalid_argument)); |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
203 return; |
25250
532faf893d37
patch 8.2.3161: Vim9: no error when reltime() has invalid arguments
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
204 } |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
205 profile_end(&res); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
206 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
207 else |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
208 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
209 // Two arguments: compute the difference. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
210 if (list2proftime(&argvars[0], &start) == FAIL |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
211 || list2proftime(&argvars[1], &res) == FAIL) |
25250
532faf893d37
patch 8.2.3161: Vim9: no error when reltime() has invalid arguments
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
212 { |
532faf893d37
patch 8.2.3161: Vim9: no error when reltime() has invalid arguments
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
213 if (in_vim9script()) |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26476
diff
changeset
|
214 emsg(_(e_invalid_argument)); |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
215 return; |
25250
532faf893d37
patch 8.2.3161: Vim9: no error when reltime() has invalid arguments
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
216 } |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
217 profile_sub(&res, &start); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
218 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
219 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
220 # ifdef MSWIN |
25252
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25250
diff
changeset
|
221 n1 = res.HighPart; |
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25250
diff
changeset
|
222 n2 = res.LowPart; |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
223 # else |
25252
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25250
diff
changeset
|
224 n1 = res.tv_sec; |
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25250
diff
changeset
|
225 n2 = res.tv_usec; |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
226 # endif |
25252
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25250
diff
changeset
|
227 list_append_number(rettv->vval.v_list, (varnumber_T)n1); |
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25250
diff
changeset
|
228 list_append_number(rettv->vval.v_list, (varnumber_T)n2); |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
229 # endif |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
230 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
231 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
232 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
233 * "reltimefloat()" function |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
234 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
235 void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
236 f_reltimefloat(typval_T *argvars UNUSED, typval_T *rettv) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
237 { |
30310
029c59bf78f1
patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents:
30043
diff
changeset
|
238 # ifdef FEAT_RELTIME |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
239 proftime_T tm; |
30310
029c59bf78f1
patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents:
30043
diff
changeset
|
240 # endif |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
241 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
242 rettv->v_type = VAR_FLOAT; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
243 rettv->vval.v_float = 0; |
30310
029c59bf78f1
patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents:
30043
diff
changeset
|
244 # ifdef FEAT_RELTIME |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
245 if (in_vim9script() && check_for_list_arg(argvars, 0) == FAIL) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
246 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
247 |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
248 if (list2proftime(&argvars[0], &tm) == OK) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
249 rettv->vval.v_float = profile_float(&tm); |
25250
532faf893d37
patch 8.2.3161: Vim9: no error when reltime() has invalid arguments
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
250 else if (in_vim9script()) |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26476
diff
changeset
|
251 emsg(_(e_invalid_argument)); |
30310
029c59bf78f1
patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents:
30043
diff
changeset
|
252 # endif |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
253 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
254 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
255 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
256 * "reltimestr()" function |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
257 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
258 void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
259 f_reltimestr(typval_T *argvars UNUSED, typval_T *rettv) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
260 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
261 # ifdef FEAT_RELTIME |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
262 proftime_T tm; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
263 # endif |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
264 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
265 rettv->v_type = VAR_STRING; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
266 rettv->vval.v_string = NULL; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
267 # ifdef FEAT_RELTIME |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
268 if (in_vim9script() && check_for_list_arg(argvars, 0) == FAIL) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
269 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
270 |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
271 if (list2proftime(&argvars[0], &tm) == OK) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
272 rettv->vval.v_string = vim_strsave((char_u *)profile_msg(&tm)); |
25250
532faf893d37
patch 8.2.3161: Vim9: no error when reltime() has invalid arguments
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
273 else if (in_vim9script()) |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26476
diff
changeset
|
274 emsg(_(e_invalid_argument)); |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
275 # endif |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
276 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
277 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
278 # if defined(HAVE_STRFTIME) || defined(PROTO) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
279 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
280 * "strftime({format}[, {time}])" function |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
281 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
282 void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
283 f_strftime(typval_T *argvars, typval_T *rettv) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
284 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
285 struct tm tmval; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
286 struct tm *curtime; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
287 time_t seconds; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
288 char_u *p; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
289 |
25252
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25250
diff
changeset
|
290 if (in_vim9script() |
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25250
diff
changeset
|
291 && (check_for_string_arg(argvars, 0) == FAIL |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
292 || check_for_opt_number_arg(argvars, 1) == FAIL)) |
25252
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25250
diff
changeset
|
293 return; |
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25250
diff
changeset
|
294 |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
295 rettv->v_type = VAR_STRING; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
296 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
297 p = tv_get_string(&argvars[0]); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
298 if (argvars[1].v_type == VAR_UNKNOWN) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
299 seconds = time(NULL); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
300 else |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
301 seconds = (time_t)tv_get_number(&argvars[1]); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
302 curtime = vim_localtime(&seconds, &tmval); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
303 // MSVC returns NULL for an invalid value of seconds. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
304 if (curtime == NULL) |
31825
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
305 { |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
306 rettv->vval.v_string = vim_strsave((char_u *)_("(Invalid)")); |
31825
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
307 return; |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
308 } |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
309 |
24711
788d7e3ade7c
patch 8.2.2894: MS-Windows: using enc_locale() for strftime() might not work
Bram Moolenaar <Bram@vim.org>
parents:
23677
diff
changeset
|
310 # ifdef MSWIN |
31825
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
311 WCHAR result_buf[256]; |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
312 WCHAR *wp; |
24711
788d7e3ade7c
patch 8.2.2894: MS-Windows: using enc_locale() for strftime() might not work
Bram Moolenaar <Bram@vim.org>
parents:
23677
diff
changeset
|
313 |
31825
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
314 wp = enc_to_utf16(p, NULL); |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
315 if (wp != NULL) |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
316 (void)wcsftime(result_buf, ARRAY_LENGTH(result_buf), wp, curtime); |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
317 else |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
318 result_buf[0] = NUL; |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
319 rettv->vval.v_string = utf16_to_enc(result_buf, NULL); |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
320 vim_free(wp); |
24711
788d7e3ade7c
patch 8.2.2894: MS-Windows: using enc_locale() for strftime() might not work
Bram Moolenaar <Bram@vim.org>
parents:
23677
diff
changeset
|
321 # else |
31825
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
322 char_u result_buf[256]; |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
323 vimconv_T conv; |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
324 char_u *enc; |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
325 |
31825
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
326 conv.vc_type = CONV_NONE; |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
327 enc = enc_locale(); |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
328 convert_setup(&conv, p_enc, enc); |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
329 if (conv.vc_type != CONV_NONE) |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
330 p = string_convert(&conv, p, NULL); |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
331 if (p == NULL || strftime((char *)result_buf, sizeof(result_buf), |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
332 (char *)p, curtime) == 0) |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
333 result_buf[0] = NUL; |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
334 |
31825
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
335 if (conv.vc_type != CONV_NONE) |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
336 vim_free(p); |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
337 convert_setup(&conv, enc, p_enc); |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
338 if (conv.vc_type != CONV_NONE) |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
339 rettv->vval.v_string = string_convert(&conv, result_buf, NULL); |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
340 else |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
341 rettv->vval.v_string = vim_strsave(result_buf); |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
342 |
31825
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
343 // Release conversion descriptors |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
344 convert_setup(&conv, NULL, NULL); |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
345 vim_free(enc); |
24711
788d7e3ade7c
patch 8.2.2894: MS-Windows: using enc_locale() for strftime() might not work
Bram Moolenaar <Bram@vim.org>
parents:
23677
diff
changeset
|
346 # endif |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
347 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
348 # endif |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
349 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
350 # if defined(HAVE_STRPTIME) || defined(PROTO) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
351 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
352 * "strptime({format}, {timestring})" function |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
353 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
354 void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
355 f_strptime(typval_T *argvars, typval_T *rettv) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
356 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
357 struct tm tmval; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
358 char_u *fmt; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
359 char_u *str; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
360 vimconv_T conv; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
361 char_u *enc; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
362 |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
363 if (in_vim9script() |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
364 && (check_for_string_arg(argvars, 0) == FAIL |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
365 || check_for_string_arg(argvars, 1) == FAIL)) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
366 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
367 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19934
diff
changeset
|
368 CLEAR_FIELD(tmval); |
20794
2e7acc208a1f
patch 8.2.0949: strptime() does not use DST
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
369 tmval.tm_isdst = -1; |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
370 fmt = tv_get_string(&argvars[0]); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
371 str = tv_get_string(&argvars[1]); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
372 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
373 conv.vc_type = CONV_NONE; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
374 enc = enc_locale(); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
375 convert_setup(&conv, p_enc, enc); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
376 if (conv.vc_type != CONV_NONE) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
377 fmt = string_convert(&conv, fmt, NULL); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
378 if (fmt == NULL |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
379 || strptime((char *)str, (char *)fmt, &tmval) == NULL |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
380 || (rettv->vval.v_number = mktime(&tmval)) == -1) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
381 rettv->vval.v_number = 0; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
382 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
383 if (conv.vc_type != CONV_NONE) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
384 vim_free(fmt); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
385 convert_setup(&conv, NULL, NULL); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
386 vim_free(enc); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
387 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
388 # endif |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
389 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
390 # if defined(FEAT_TIMERS) || defined(PROTO) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
391 static timer_T *first_timer = NULL; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
392 static long last_timer_id = 0; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
393 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
394 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
395 * Return time left until "due". Negative if past "due". |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
396 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
397 long |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
398 proftime_time_left(proftime_T *due, proftime_T *now) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
399 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
400 # ifdef MSWIN |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
401 LARGE_INTEGER fr; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
402 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
403 if (now->QuadPart > due->QuadPart) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
404 return 0; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
405 QueryPerformanceFrequency(&fr); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
406 return (long)(((double)(due->QuadPart - now->QuadPart) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
407 / (double)fr.QuadPart) * 1000); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
408 # else |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
409 if (now->tv_sec > due->tv_sec) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
410 return 0; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
411 return (due->tv_sec - now->tv_sec) * 1000 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
412 + (due->tv_usec - now->tv_usec) / 1000; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
413 # endif |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
414 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
415 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
416 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
417 * Insert a timer in the list of timers. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
418 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
419 static void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
420 insert_timer(timer_T *timer) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
421 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
422 timer->tr_next = first_timer; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
423 timer->tr_prev = NULL; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
424 if (first_timer != NULL) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
425 first_timer->tr_prev = timer; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
426 first_timer = timer; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
427 did_add_timer = TRUE; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
428 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
429 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
430 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
431 * Take a timer out of the list of timers. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
432 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
433 static void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
434 remove_timer(timer_T *timer) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
435 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
436 if (timer->tr_prev == NULL) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
437 first_timer = timer->tr_next; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
438 else |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
439 timer->tr_prev->tr_next = timer->tr_next; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
440 if (timer->tr_next != NULL) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
441 timer->tr_next->tr_prev = timer->tr_prev; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
442 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
443 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
444 static void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
445 free_timer(timer_T *timer) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
446 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
447 free_callback(&timer->tr_callback); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
448 vim_free(timer); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
449 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
450 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
451 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
452 * Create a timer and return it. NULL if out of memory. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
453 * Caller should set the callback. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
454 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
455 timer_T * |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
456 create_timer(long msec, int repeat) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
457 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
458 timer_T *timer = ALLOC_CLEAR_ONE(timer_T); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
459 long prev_id = last_timer_id; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
460 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
461 if (timer == NULL) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
462 return NULL; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
463 if (++last_timer_id <= prev_id) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
464 // Overflow! Might cause duplicates... |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
465 last_timer_id = 0; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
466 timer->tr_id = last_timer_id; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
467 insert_timer(timer); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
468 if (repeat != 0) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
469 timer->tr_repeat = repeat - 1; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
470 timer->tr_interval = msec; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
471 |
29900
a6721cafbc74
patch 9.0.0288: when 'cmdheight' is zero some messages are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
472 timer_start(timer); |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
473 return timer; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
474 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
475 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
476 /* |
29900
a6721cafbc74
patch 9.0.0288: when 'cmdheight' is zero some messages are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
477 * (Re)start a timer. |
a6721cafbc74
patch 9.0.0288: when 'cmdheight' is zero some messages are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
478 */ |
a6721cafbc74
patch 9.0.0288: when 'cmdheight' is zero some messages are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
479 void |
a6721cafbc74
patch 9.0.0288: when 'cmdheight' is zero some messages are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
480 timer_start(timer_T *timer) |
a6721cafbc74
patch 9.0.0288: when 'cmdheight' is zero some messages are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
481 { |
a6721cafbc74
patch 9.0.0288: when 'cmdheight' is zero some messages are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
482 profile_setlimit(timer->tr_interval, &timer->tr_due); |
a6721cafbc74
patch 9.0.0288: when 'cmdheight' is zero some messages are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
483 timer->tr_paused = FALSE; |
a6721cafbc74
patch 9.0.0288: when 'cmdheight' is zero some messages are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
484 } |
a6721cafbc74
patch 9.0.0288: when 'cmdheight' is zero some messages are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
485 |
a6721cafbc74
patch 9.0.0288: when 'cmdheight' is zero some messages are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
486 /* |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
487 * Invoke the callback of "timer". |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
488 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
489 static void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
490 timer_callback(timer_T *timer) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
491 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
492 typval_T rettv; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
493 typval_T argv[2]; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
494 |
31287
fa309d9af73c
patch 9.0.0977: it is not easy to see what client-server commands are doing
Bram Moolenaar <Bram@vim.org>
parents:
30857
diff
changeset
|
495 #ifdef FEAT_EVAL |
28725
075787b91e09
patch 8.2.4887: channel log does not show invoking a timer callback
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
496 if (ch_log_active()) |
075787b91e09
patch 8.2.4887: channel log does not show invoking a timer callback
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
497 { |
075787b91e09
patch 8.2.4887: channel log does not show invoking a timer callback
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
498 callback_T *cb = &timer->tr_callback; |
075787b91e09
patch 8.2.4887: channel log does not show invoking a timer callback
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
499 |
075787b91e09
patch 8.2.4887: channel log does not show invoking a timer callback
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
500 ch_log(NULL, "invoking timer callback %s", |
075787b91e09
patch 8.2.4887: channel log does not show invoking a timer callback
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
501 cb->cb_partial != NULL ? cb->cb_partial->pt_name : cb->cb_name); |
075787b91e09
patch 8.2.4887: channel log does not show invoking a timer callback
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
502 } |
075787b91e09
patch 8.2.4887: channel log does not show invoking a timer callback
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
503 #endif |
075787b91e09
patch 8.2.4887: channel log does not show invoking a timer callback
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
504 |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
505 argv[0].v_type = VAR_NUMBER; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
506 argv[0].vval.v_number = (varnumber_T)timer->tr_id; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
507 argv[1].v_type = VAR_UNKNOWN; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
508 |
27402
898f520e798b
patch 8.2.4229: possible crash when invoking timer callback fails
Bram Moolenaar <Bram@vim.org>
parents:
27342
diff
changeset
|
509 rettv.v_type = VAR_UNKNOWN; |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
510 call_callback(&timer->tr_callback, -1, &rettv, 1, argv); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
511 clear_tv(&rettv); |
28725
075787b91e09
patch 8.2.4887: channel log does not show invoking a timer callback
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
512 |
31287
fa309d9af73c
patch 9.0.0977: it is not easy to see what client-server commands are doing
Bram Moolenaar <Bram@vim.org>
parents:
30857
diff
changeset
|
513 #ifdef FEAT_EVAL |
28725
075787b91e09
patch 8.2.4887: channel log does not show invoking a timer callback
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
514 ch_log(NULL, "timer callback finished"); |
075787b91e09
patch 8.2.4887: channel log does not show invoking a timer callback
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
515 #endif |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
516 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
517 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
518 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
519 * Call timers that are due. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
520 * Return the time in msec until the next timer is due. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
521 * Returns -1 if there are no pending timers. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
522 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
523 long |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
524 check_due_timer(void) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
525 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
526 timer_T *timer; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
527 timer_T *timer_next; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
528 long this_due; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
529 long next_due = -1; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
530 proftime_T now; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
531 int did_one = FALSE; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
532 int need_update_screen = FALSE; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
533 long current_id = last_timer_id; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
534 |
27012
f9a9ffebe2c0
patch 8.2.4035: timer triggered at the debug prompt may cause trouble
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
535 // Don't run any timers while exiting, dealing with an error or at the |
f9a9ffebe2c0
patch 8.2.4035: timer triggered at the debug prompt may cause trouble
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
536 // debug prompt. |
f9a9ffebe2c0
patch 8.2.4035: timer triggered at the debug prompt may cause trouble
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
537 if (exiting || aborting() || debug_mode) |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
538 return next_due; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
539 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
540 profile_start(&now); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
541 for (timer = first_timer; timer != NULL && !got_int; timer = timer_next) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
542 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
543 timer_next = timer->tr_next; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
544 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
545 if (timer->tr_id == -1 || timer->tr_firing || timer->tr_paused) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
546 continue; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
547 this_due = proftime_time_left(&timer->tr_due, &now); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
548 if (this_due <= 1) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
549 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
550 // Save and restore a lot of flags, because the timer fires while |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
551 // waiting for a character, which might be halfway a command. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
552 int save_timer_busy = timer_busy; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
553 int save_vgetc_busy = vgetc_busy; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
554 int save_did_emsg = did_emsg; |
25609
f8bcd21e6e24
patch 8.2.3341: Vim9: function call aborted despite try/catch
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
555 int prev_uncaught_emsg = uncaught_emsg; |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
556 int save_called_emsg = called_emsg; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
557 int save_must_redraw = must_redraw; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
558 int save_trylevel = trylevel; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
559 int save_did_throw = did_throw; |
23677
94409ebb33f1
patch 8.2.2380: Vim9: occasional crash when using try/catch and a timer
Bram Moolenaar <Bram@vim.org>
parents:
22827
diff
changeset
|
560 int save_need_rethrow = need_rethrow; |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
561 int save_ex_pressedreturn = get_pressedreturn(); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
562 int save_may_garbage_collect = may_garbage_collect; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
563 except_T *save_current_exception = current_exception; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
564 vimvars_save_T vvsave; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
565 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
566 // Create a scope for running the timer callback, ignoring most of |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
567 // the current scope, such as being inside a try/catch. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
568 timer_busy = timer_busy > 0 || vgetc_busy > 0; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
569 vgetc_busy = 0; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
570 called_emsg = 0; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
571 did_emsg = FALSE; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
572 must_redraw = 0; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
573 trylevel = 0; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
574 did_throw = FALSE; |
23677
94409ebb33f1
patch 8.2.2380: Vim9: occasional crash when using try/catch and a timer
Bram Moolenaar <Bram@vim.org>
parents:
22827
diff
changeset
|
575 need_rethrow = FALSE; |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
576 current_exception = NULL; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
577 may_garbage_collect = FALSE; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
578 save_vimvars(&vvsave); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
579 |
22827
20ccf5f7dc6d
patch 8.2.1961: various comments can be improved
Bram Moolenaar <Bram@vim.org>
parents:
22157
diff
changeset
|
580 // Invoke the callback. |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
581 timer->tr_firing = TRUE; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
582 timer_callback(timer); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
583 timer->tr_firing = FALSE; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
584 |
22827
20ccf5f7dc6d
patch 8.2.1961: various comments can be improved
Bram Moolenaar <Bram@vim.org>
parents:
22157
diff
changeset
|
585 // Restore stuff. |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
586 timer_next = timer->tr_next; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
587 did_one = TRUE; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
588 timer_busy = save_timer_busy; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
589 vgetc_busy = save_vgetc_busy; |
25609
f8bcd21e6e24
patch 8.2.3341: Vim9: function call aborted despite try/catch
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
590 if (uncaught_emsg > prev_uncaught_emsg) |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
591 ++timer->tr_emsg_count; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
592 did_emsg = save_did_emsg; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
593 called_emsg = save_called_emsg; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
594 trylevel = save_trylevel; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
595 did_throw = save_did_throw; |
23677
94409ebb33f1
patch 8.2.2380: Vim9: occasional crash when using try/catch and a timer
Bram Moolenaar <Bram@vim.org>
parents:
22827
diff
changeset
|
596 need_rethrow = save_need_rethrow; |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
597 current_exception = save_current_exception; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
598 restore_vimvars(&vvsave); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
599 if (must_redraw != 0) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
600 need_update_screen = TRUE; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
601 must_redraw = must_redraw > save_must_redraw |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
602 ? must_redraw : save_must_redraw; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
603 set_pressedreturn(save_ex_pressedreturn); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
604 may_garbage_collect = save_may_garbage_collect; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
605 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
606 // Only fire the timer again if it repeats and stop_timer() wasn't |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
607 // called while inside the callback (tr_id == -1). |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
608 if (timer->tr_repeat != 0 && timer->tr_id != -1 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
609 && timer->tr_emsg_count < 3) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
610 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
611 profile_setlimit(timer->tr_interval, &timer->tr_due); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
612 this_due = proftime_time_left(&timer->tr_due, &now); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
613 if (this_due < 1) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
614 this_due = 1; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
615 if (timer->tr_repeat > 0) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
616 --timer->tr_repeat; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
617 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
618 else |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
619 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
620 this_due = -1; |
29900
a6721cafbc74
patch 9.0.0288: when 'cmdheight' is zero some messages are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
621 if (timer->tr_keep) |
a6721cafbc74
patch 9.0.0288: when 'cmdheight' is zero some messages are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
622 timer->tr_paused = TRUE; |
a6721cafbc74
patch 9.0.0288: when 'cmdheight' is zero some messages are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
623 else |
a6721cafbc74
patch 9.0.0288: when 'cmdheight' is zero some messages are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
624 { |
a6721cafbc74
patch 9.0.0288: when 'cmdheight' is zero some messages are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
625 remove_timer(timer); |
a6721cafbc74
patch 9.0.0288: when 'cmdheight' is zero some messages are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
626 free_timer(timer); |
a6721cafbc74
patch 9.0.0288: when 'cmdheight' is zero some messages are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
627 } |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
628 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
629 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
630 if (this_due > 0 && (next_due == -1 || next_due > this_due)) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
631 next_due = this_due; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
632 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
633 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
634 if (did_one) |
26466
d413104a94c8
patch 8.2.3763: when editing the cmdline a callback may cause a scroll up
Bram Moolenaar <Bram@vim.org>
parents:
25609
diff
changeset
|
635 redraw_after_callback(need_update_screen, FALSE); |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
636 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
637 #ifdef FEAT_BEVAL_TERM |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
638 if (bevalexpr_due_set) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
639 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
640 this_due = proftime_time_left(&bevalexpr_due, &now); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
641 if (this_due <= 1) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
642 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
643 bevalexpr_due_set = FALSE; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
644 if (balloonEval == NULL) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
645 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
646 balloonEval = ALLOC_CLEAR_ONE(BalloonEval); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
647 balloonEvalForTerm = TRUE; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
648 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
649 if (balloonEval != NULL) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
650 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
651 general_beval_cb(balloonEval, 0); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
652 setcursor(); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
653 out_flush(); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
654 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
655 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
656 else if (next_due == -1 || next_due > this_due) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
657 next_due = this_due; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
658 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
659 #endif |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
660 #ifdef FEAT_TERMINAL |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
661 // Some terminal windows may need their buffer updated. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
662 next_due = term_check_timers(next_due, &now); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
663 #endif |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
664 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
665 return current_id != last_timer_id ? 1 : next_due; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
666 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
667 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
668 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
669 * Find a timer by ID. Returns NULL if not found; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
670 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
671 static timer_T * |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
672 find_timer(long id) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
673 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
674 timer_T *timer; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
675 |
31825
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
676 if (id < 0) |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
677 return NULL; |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
678 |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
679 FOR_ALL_TIMERS(timer) |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
680 if (timer->tr_id == id) |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
681 return timer; |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
682 return NULL; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
683 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
684 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
685 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
686 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
687 * Stop a timer and delete it. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
688 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
689 void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
690 stop_timer(timer_T *timer) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
691 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
692 if (timer->tr_firing) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
693 // Free the timer after the callback returns. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
694 timer->tr_id = -1; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
695 else |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
696 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
697 remove_timer(timer); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
698 free_timer(timer); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
699 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
700 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
701 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
702 static void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
703 stop_all_timers(void) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
704 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
705 timer_T *timer; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
706 timer_T *timer_next; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
707 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
708 for (timer = first_timer; timer != NULL; timer = timer_next) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
709 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
710 timer_next = timer->tr_next; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
711 stop_timer(timer); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
712 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
713 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
714 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
715 static void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
716 add_timer_info(typval_T *rettv, timer_T *timer) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
717 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
718 list_T *list = rettv->vval.v_list; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
719 dict_T *dict = dict_alloc(); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
720 dictitem_T *di; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
721 long remaining; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
722 proftime_T now; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
723 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
724 if (dict == NULL) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
725 return; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
726 list_append_dict(list, dict); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
727 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
728 dict_add_number(dict, "id", timer->tr_id); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
729 dict_add_number(dict, "time", (long)timer->tr_interval); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
730 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
731 profile_start(&now); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
732 remaining = proftime_time_left(&timer->tr_due, &now); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
733 dict_add_number(dict, "remaining", (long)remaining); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
734 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
735 dict_add_number(dict, "repeat", |
26476
7426c2657710
patch 8.2.3768: timer_info() has the wrong repeat value in a timer callback
Bram Moolenaar <Bram@vim.org>
parents:
26466
diff
changeset
|
736 (long)(timer->tr_repeat < 0 ? -1 |
7426c2657710
patch 8.2.3768: timer_info() has the wrong repeat value in a timer callback
Bram Moolenaar <Bram@vim.org>
parents:
26466
diff
changeset
|
737 : timer->tr_repeat + (timer->tr_firing ? 0 : 1))); |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
738 dict_add_number(dict, "paused", (long)(timer->tr_paused)); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
739 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
740 di = dictitem_alloc((char_u *)"callback"); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
741 if (di != NULL) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
742 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
743 if (dict_add(dict, di) == FAIL) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
744 vim_free(di); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
745 else |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
746 put_callback(&timer->tr_callback, &di->di_tv); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
747 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
748 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
749 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
750 static void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
751 add_timer_info_all(typval_T *rettv) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
752 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
753 timer_T *timer; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
754 |
19934
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
19396
diff
changeset
|
755 FOR_ALL_TIMERS(timer) |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
756 if (timer->tr_id != -1) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
757 add_timer_info(rettv, timer); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
758 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
759 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
760 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
761 * Mark references in partials of timers. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
762 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
763 int |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
764 set_ref_in_timer(int copyID) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
765 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
766 int abort = FALSE; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
767 timer_T *timer; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
768 typval_T tv; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
769 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
770 for (timer = first_timer; !abort && timer != NULL; timer = timer->tr_next) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
771 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
772 if (timer->tr_callback.cb_partial != NULL) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
773 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
774 tv.v_type = VAR_PARTIAL; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
775 tv.vval.v_partial = timer->tr_callback.cb_partial; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
776 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
777 else |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
778 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
779 tv.v_type = VAR_FUNC; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
780 tv.vval.v_string = timer->tr_callback.cb_name; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
781 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
782 abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
783 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
784 return abort; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
785 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
786 |
30695
b9cc46461994
patch 9.0.0682: crash when popup with deleted timer is closed
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
787 /* |
b9cc46461994
patch 9.0.0682: crash when popup with deleted timer is closed
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
788 * Return TRUE if "timer" exists in the list of timers. |
b9cc46461994
patch 9.0.0682: crash when popup with deleted timer is closed
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
789 */ |
b9cc46461994
patch 9.0.0682: crash when popup with deleted timer is closed
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
790 int |
b9cc46461994
patch 9.0.0682: crash when popup with deleted timer is closed
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
791 timer_valid(timer_T *timer) |
b9cc46461994
patch 9.0.0682: crash when popup with deleted timer is closed
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
792 { |
b9cc46461994
patch 9.0.0682: crash when popup with deleted timer is closed
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
793 if (timer == NULL) |
b9cc46461994
patch 9.0.0682: crash when popup with deleted timer is closed
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
794 return FALSE; |
31825
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
795 |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
796 timer_T *t; |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
797 FOR_ALL_TIMERS(t) |
30695
b9cc46461994
patch 9.0.0682: crash when popup with deleted timer is closed
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
798 if (t == timer) |
b9cc46461994
patch 9.0.0682: crash when popup with deleted timer is closed
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
799 return TRUE; |
b9cc46461994
patch 9.0.0682: crash when popup with deleted timer is closed
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
800 return FALSE; |
b9cc46461994
patch 9.0.0682: crash when popup with deleted timer is closed
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
801 } |
b9cc46461994
patch 9.0.0682: crash when popup with deleted timer is closed
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
802 |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
803 # if defined(EXITFREE) || defined(PROTO) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
804 void |
32009
4545f58c8490
patch 9.0.1336: functions without arguments are not always declared properly
Bram Moolenaar <Bram@vim.org>
parents:
31825
diff
changeset
|
805 timer_free_all(void) |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
806 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
807 while (first_timer != NULL) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
808 { |
30695
b9cc46461994
patch 9.0.0682: crash when popup with deleted timer is closed
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
809 timer_T *timer = first_timer; |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
810 remove_timer(timer); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
811 free_timer(timer); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
812 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
813 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
814 # endif |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
815 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
816 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
817 * "timer_info([timer])" function |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
818 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
819 void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
820 f_timer_info(typval_T *argvars, typval_T *rettv) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
821 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
822 timer_T *timer = NULL; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
823 |
29175
755ab148288b
patch 8.2.5107: some callers of rettv_list_alloc() check for not OK
Bram Moolenaar <Bram@vim.org>
parents:
28725
diff
changeset
|
824 if (rettv_list_alloc(rettv) == FAIL) |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
825 return; |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
826 |
30043
fd855ad74887
patch 9.0.0359: error message for wrong argument type is not specific
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
827 if (check_for_opt_number_arg(argvars, 0) == FAIL) |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
828 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
829 |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
830 if (argvars[0].v_type != VAR_UNKNOWN) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
831 { |
30043
fd855ad74887
patch 9.0.0359: error message for wrong argument type is not specific
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
832 timer = find_timer((int)tv_get_number(&argvars[0])); |
fd855ad74887
patch 9.0.0359: error message for wrong argument type is not specific
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
833 if (timer != NULL) |
fd855ad74887
patch 9.0.0359: error message for wrong argument type is not specific
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
834 add_timer_info(rettv, timer); |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
835 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
836 else |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
837 add_timer_info_all(rettv); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
838 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
839 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
840 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
841 * "timer_pause(timer, paused)" function |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
842 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
843 void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
844 f_timer_pause(typval_T *argvars, typval_T *rettv UNUSED) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
845 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
846 timer_T *timer = NULL; |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
847 |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
848 if (in_vim9script() |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
849 && (check_for_number_arg(argvars, 0) == FAIL |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
850 || check_for_bool_arg(argvars, 1) == FAIL)) |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
851 return; |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
852 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
853 if (argvars[0].v_type != VAR_NUMBER) |
31825
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
854 { |
25306
078edc1821bf
patch 8.2.3190: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
855 emsg(_(e_number_expected)); |
31825
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
856 return; |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
857 } |
29900
a6721cafbc74
patch 9.0.0288: when 'cmdheight' is zero some messages are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
858 |
31825
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
859 int paused = (int)tv_get_bool(&argvars[1]); |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
860 |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
861 timer = find_timer((int)tv_get_number(&argvars[0])); |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
862 if (timer != NULL) |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
863 timer->tr_paused = paused; |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
864 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
865 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
866 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
867 * "timer_start(time, callback [, options])" function |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
868 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
869 void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
870 f_timer_start(typval_T *argvars, typval_T *rettv) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
871 { |
25348
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
872 long msec; |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
873 timer_T *timer; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
874 int repeat = 0; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
875 callback_T callback; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
876 dict_T *dict; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
877 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
878 rettv->vval.v_number = -1; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
879 if (check_secure()) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
880 return; |
25348
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
881 |
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
882 if (in_vim9script() |
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
883 && (check_for_number_arg(argvars, 0) == FAIL |
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
884 || check_for_opt_dict_arg(argvars, 2) == FAIL)) |
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
885 return; |
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
886 |
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
887 msec = (long)tv_get_number(&argvars[0]); |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
888 if (argvars[2].v_type != VAR_UNKNOWN) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
889 { |
29994
86eb4aba16c3
patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents:
29900
diff
changeset
|
890 if (check_for_nonnull_dict_arg(argvars, 2) == FAIL) |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
891 return; |
29994
86eb4aba16c3
patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents:
29900
diff
changeset
|
892 |
86eb4aba16c3
patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents:
29900
diff
changeset
|
893 dict = argvars[2].vval.v_dict; |
28315
62cc3b60493b
patch 8.2.4683: verbose check with dict_find() to see if a key is present
Bram Moolenaar <Bram@vim.org>
parents:
27402
diff
changeset
|
894 if (dict_has_key(dict, "repeat")) |
29442
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29175
diff
changeset
|
895 repeat = dict_get_number(dict, "repeat"); |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
896 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
897 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
898 callback = get_callback(&argvars[1]); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
899 if (callback.cb_name == NULL) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
900 return; |
27402
898f520e798b
patch 8.2.4229: possible crash when invoking timer callback fails
Bram Moolenaar <Bram@vim.org>
parents:
27342
diff
changeset
|
901 if (in_vim9script() && *callback.cb_name == NUL) |
898f520e798b
patch 8.2.4229: possible crash when invoking timer callback fails
Bram Moolenaar <Bram@vim.org>
parents:
27342
diff
changeset
|
902 { |
898f520e798b
patch 8.2.4229: possible crash when invoking timer callback fails
Bram Moolenaar <Bram@vim.org>
parents:
27342
diff
changeset
|
903 // empty callback is not useful for a timer |
898f520e798b
patch 8.2.4229: possible crash when invoking timer callback fails
Bram Moolenaar <Bram@vim.org>
parents:
27342
diff
changeset
|
904 emsg(_(e_invalid_callback_argument)); |
898f520e798b
patch 8.2.4229: possible crash when invoking timer callback fails
Bram Moolenaar <Bram@vim.org>
parents:
27342
diff
changeset
|
905 free_callback(&callback); |
898f520e798b
patch 8.2.4229: possible crash when invoking timer callback fails
Bram Moolenaar <Bram@vim.org>
parents:
27342
diff
changeset
|
906 return; |
898f520e798b
patch 8.2.4229: possible crash when invoking timer callback fails
Bram Moolenaar <Bram@vim.org>
parents:
27342
diff
changeset
|
907 } |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
908 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
909 timer = create_timer(msec, repeat); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
910 if (timer == NULL) |
31825
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
911 { |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
912 free_callback(&callback); |
31825
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
913 return; |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
914 } |
31825
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
915 set_callback(&timer->tr_callback, &callback); |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
916 if (callback.cb_free_name) |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
917 vim_free(callback.cb_name); |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
918 rettv->vval.v_number = (varnumber_T)timer->tr_id; |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
919 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
920 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
921 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
922 * "timer_stop(timer)" function |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
923 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
924 void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
925 f_timer_stop(typval_T *argvars, typval_T *rettv UNUSED) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
926 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
927 timer_T *timer; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
928 |
30043
fd855ad74887
patch 9.0.0359: error message for wrong argument type is not specific
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
929 if (check_for_number_arg(argvars, 0) == FAIL) |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
930 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
931 |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
932 timer = find_timer((int)tv_get_number(&argvars[0])); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
933 if (timer != NULL) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
934 stop_timer(timer); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
935 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
936 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
937 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
938 * "timer_stopall()" function |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
939 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
940 void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
941 f_timer_stopall(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
942 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
943 stop_all_timers(); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
944 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
945 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
946 # endif // FEAT_TIMERS |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
947 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
948 # if defined(STARTUPTIME) || defined(PROTO) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
949 static struct timeval prev_timeval; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
950 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
951 # ifdef MSWIN |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
952 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
953 * Windows doesn't have gettimeofday(), although it does have struct timeval. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
954 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
955 static int |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
956 gettimeofday(struct timeval *tv, char *dummy UNUSED) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
957 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
958 long t = clock(); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
959 tv->tv_sec = t / CLOCKS_PER_SEC; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
960 tv->tv_usec = (t - tv->tv_sec * CLOCKS_PER_SEC) * 1000000 / CLOCKS_PER_SEC; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
961 return 0; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
962 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
963 # endif |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
964 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
965 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
966 * Save the previous time before doing something that could nest. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
967 * set "*tv_rel" to the time elapsed so far. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
968 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
969 void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
970 time_push(void *tv_rel, void *tv_start) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
971 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
972 *((struct timeval *)tv_rel) = prev_timeval; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
973 gettimeofday(&prev_timeval, NULL); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
974 ((struct timeval *)tv_rel)->tv_usec = prev_timeval.tv_usec |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
975 - ((struct timeval *)tv_rel)->tv_usec; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
976 ((struct timeval *)tv_rel)->tv_sec = prev_timeval.tv_sec |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
977 - ((struct timeval *)tv_rel)->tv_sec; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
978 if (((struct timeval *)tv_rel)->tv_usec < 0) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
979 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
980 ((struct timeval *)tv_rel)->tv_usec += 1000000; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
981 --((struct timeval *)tv_rel)->tv_sec; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
982 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
983 *(struct timeval *)tv_start = prev_timeval; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
984 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
985 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
986 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
987 * Compute the previous time after doing something that could nest. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
988 * Subtract "*tp" from prev_timeval; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
989 * Note: The arguments are (void *) to avoid trouble with systems that don't |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
990 * have struct timeval. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
991 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
992 void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
993 time_pop( |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
994 void *tp) // actually (struct timeval *) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
995 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
996 prev_timeval.tv_usec -= ((struct timeval *)tp)->tv_usec; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
997 prev_timeval.tv_sec -= ((struct timeval *)tp)->tv_sec; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
998 if (prev_timeval.tv_usec < 0) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
999 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1000 prev_timeval.tv_usec += 1000000; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1001 --prev_timeval.tv_sec; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1002 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1003 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1004 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1005 static void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1006 time_diff(struct timeval *then, struct timeval *now) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1007 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1008 long usec; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1009 long msec; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1010 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1011 usec = now->tv_usec - then->tv_usec; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1012 msec = (now->tv_sec - then->tv_sec) * 1000L + usec / 1000L, |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1013 usec = usec % 1000L; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1014 fprintf(time_fd, "%03ld.%03ld", msec, usec >= 0 ? usec : usec + 1000L); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1015 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1016 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1017 void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1018 time_msg( |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1019 char *mesg, |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1020 void *tv_start) // only for do_source: start time; actually |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1021 // (struct timeval *) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1022 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1023 static struct timeval start; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1024 struct timeval now; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1025 |
31825
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
1026 if (time_fd == NULL) |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
1027 return; |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
1028 |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
1029 if (strstr(mesg, "STARTING") != NULL) |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1030 { |
31825
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
1031 gettimeofday(&start, NULL); |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
1032 prev_timeval = start; |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
1033 fprintf(time_fd, "\n\ntimes in msec\n"); |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
1034 fprintf(time_fd, " clock self+sourced self: sourced script\n"); |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
1035 fprintf(time_fd, " clock elapsed: other lines\n\n"); |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
1036 } |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
1037 gettimeofday(&now, NULL); |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
1038 time_diff(&start, &now); |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
1039 if (((struct timeval *)tv_start) != NULL) |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
1040 { |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1041 fprintf(time_fd, " "); |
31825
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
1042 time_diff(((struct timeval *)tv_start), &now); |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1043 } |
31825
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
1044 fprintf(time_fd, " "); |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
1045 time_diff(&prev_timeval, &now); |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
1046 prev_timeval = now; |
0d27ddce621d
patch 9.0.1245: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
1047 fprintf(time_fd, ": %s\n", mesg); |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1048 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1049 # endif // STARTUPTIME |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1050 #endif // FEAT_EVAL |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1051 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1052 #if defined(FEAT_SPELL) || defined(FEAT_PERSISTENT_UNDO) || defined(PROTO) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1053 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1054 * Read 8 bytes from "fd" and turn them into a time_T, MSB first. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1055 * Returns -1 when encountering EOF. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1056 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1057 time_T |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1058 get8ctime(FILE *fd) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1059 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1060 int c; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1061 time_T n = 0; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1062 int i; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1063 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1064 for (i = 0; i < 8; ++i) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1065 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1066 c = getc(fd); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1067 if (c == EOF) return -1; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1068 n = (n << 8) + c; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1069 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1070 return n; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1071 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1072 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1073 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1074 * Write time_T to file "fd" in 8 bytes. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1075 * Returns FAIL when the write failed. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1076 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1077 int |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1078 put_time(FILE *fd, time_T the_time) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1079 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1080 char_u buf[8]; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1081 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1082 time_to_bytes(the_time, buf); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1083 return fwrite(buf, (size_t)8, (size_t)1, fd) == 1 ? OK : FAIL; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1084 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1085 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1086 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1087 * Write time_T to "buf[8]". |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1088 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1089 void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1090 time_to_bytes(time_T the_time, char_u *buf) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1091 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1092 int c; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1093 int i; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1094 int bi = 0; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1095 time_T wtime = the_time; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1096 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1097 // time_T can be up to 8 bytes in size, more than long_u, thus we |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1098 // can't use put_bytes() here. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1099 // Another problem is that ">>" may do an arithmetic shift that keeps the |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1100 // sign. This happens for large values of wtime. A cast to long_u may |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1101 // truncate if time_T is 8 bytes. So only use a cast when it is 4 bytes, |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1102 // it's safe to assume that long_u is 4 bytes or more and when using 8 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1103 // bytes the top bit won't be set. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1104 for (i = 7; i >= 0; --i) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1105 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1106 if (i + 1 > (int)sizeof(time_T)) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1107 // ">>" doesn't work well when shifting more bits than avail |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1108 buf[bi++] = 0; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1109 else |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1110 { |
27342
41a940219183
patch 8.2.4199: MS-Windows: Support for MSVC 2003 is not useful
Bram Moolenaar <Bram@vim.org>
parents:
27253
diff
changeset
|
1111 # if defined(SIZEOF_TIME_T) && SIZEOF_TIME_T > 4 |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1112 c = (int)(wtime >> (i * 8)); |
27342
41a940219183
patch 8.2.4199: MS-Windows: Support for MSVC 2003 is not useful
Bram Moolenaar <Bram@vim.org>
parents:
27253
diff
changeset
|
1113 # else |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1114 c = (int)((long_u)wtime >> (i * 8)); |
27342
41a940219183
patch 8.2.4199: MS-Windows: Support for MSVC 2003 is not useful
Bram Moolenaar <Bram@vim.org>
parents:
27253
diff
changeset
|
1115 # endif |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1116 buf[bi++] = c; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1117 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1118 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1119 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1120 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1121 #endif |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1122 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1123 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1124 * Put timestamp "tt" in "buf[buflen]" in a nice format. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1125 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1126 void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1127 add_time(char_u *buf, size_t buflen, time_t tt) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1128 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1129 #ifdef HAVE_STRFTIME |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1130 struct tm tmval; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1131 struct tm *curtime; |
30857
ec7cb7e68968
patch 9.0.0763: MS-Windows: warning for using int for size_t
Bram Moolenaar <Bram@vim.org>
parents:
30797
diff
changeset
|
1132 size_t n; |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1133 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1134 if (vim_time() - tt >= 100) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1135 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1136 curtime = vim_localtime(&tt, &tmval); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1137 if (vim_time() - tt < (60L * 60L * 12L)) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1138 // within 12 hours |
30797
1213e3988168
patch 9.0.0733: use of strftime() is not safe
Bram Moolenaar <Bram@vim.org>
parents:
30695
diff
changeset
|
1139 n = strftime((char *)buf, buflen, "%H:%M:%S", curtime); |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1140 else |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1141 // longer ago |
30797
1213e3988168
patch 9.0.0733: use of strftime() is not safe
Bram Moolenaar <Bram@vim.org>
parents:
30695
diff
changeset
|
1142 n = strftime((char *)buf, buflen, "%Y/%m/%d %H:%M:%S", curtime); |
1213e3988168
patch 9.0.0733: use of strftime() is not safe
Bram Moolenaar <Bram@vim.org>
parents:
30695
diff
changeset
|
1143 if (n == 0) |
1213e3988168
patch 9.0.0733: use of strftime() is not safe
Bram Moolenaar <Bram@vim.org>
parents:
30695
diff
changeset
|
1144 buf[0] = NUL; |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1145 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1146 else |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1147 #endif |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1148 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1149 long seconds = (long)(vim_time() - tt); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1150 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1151 vim_snprintf((char *)buf, buflen, |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1152 NGETTEXT("%ld second ago", "%ld seconds ago", seconds), |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1153 seconds); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1154 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1155 } |