Mercurial > vim
annotate src/time.c @ 30421:425b686c5244 v9.0.0546
patch 9.0.0546: supporting Ruby 1.8 makes code complicated
Commit: https://github.com/vim/vim/commit/236ccbf6f8a671a45b773de4b34558ecfdf9ac02
Author: K.Takata <kentkt@csc.jp>
Date: Thu Sep 22 16:12:06 2022 +0100
patch 9.0.0546: supporting Ruby 1.8 makes code complicated
Problem: Supporting Ruby 1.8 makes code complicated.
Solution: Drop Ruby 1.8 support, it is ancient. (Ken Takata, closes https://github.com/vim/vim/issues/11195)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 22 Sep 2022 17:15:03 +0200 |
parents | 029c59bf78f1 |
children | b9cc46461994 |
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 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
85 static char buf[50]; |
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) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
93 vim_strncpy((char_u *)buf, (char_u *)_("(Invalid)"), sizeof(buf) - 1); |
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 |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
97 (void)strftime(buf, sizeof(buf) - 1, _("%a %b %d %H:%M:%S %Y"), |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
98 curtime); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
99 # ifdef MSWIN |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
100 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
|
101 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
102 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
|
103 int len; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
104 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
105 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
|
106 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
|
107 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
108 STRCPY(buf, to_free); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
109 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
|
110 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
111 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
112 # endif |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
113 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
114 #else |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
115 STRCPY(buf, "(unknown)"); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
116 #endif |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
117 if (add_newline) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
118 STRCAT(buf, "\n"); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
119 return buf; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
120 } |
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 #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
|
123 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
124 #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
|
125 # 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
|
126 #endif |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
127 |
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 * "localtime()" function |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
130 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
131 void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
132 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
|
133 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
134 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
|
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 # 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
|
138 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
139 * 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
|
140 * 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
|
141 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
142 static int |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
143 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
|
144 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
145 long n1, n2; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
146 int error = FALSE; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
147 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
148 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
|
149 || 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
|
150 return FAIL; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
151 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
|
152 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
|
153 # ifdef MSWIN |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
154 tm->HighPart = n1; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
155 tm->LowPart = n2; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
156 # else |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
157 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
|
158 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
|
159 # endif |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
160 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
|
161 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
162 # endif // FEAT_RELTIME |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
163 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
164 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
165 * "reltime()" function |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
166 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
167 void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
168 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
|
169 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
170 # ifdef FEAT_RELTIME |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
171 proftime_T res; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
172 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
|
173 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
|
174 |
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
|
175 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
|
176 return; |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
177 |
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
|
178 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
|
179 && (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
|
180 || (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
|
181 && 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
|
182 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
|
183 |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
184 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
|
185 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
186 // 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
|
187 profile_start(&res); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
188 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
189 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
|
190 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
191 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
|
192 { |
532faf893d37
patch 8.2.3161: Vim9: no error when reltime() has invalid arguments
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
193 if (in_vim9script()) |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26476
diff
changeset
|
194 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
|
195 return; |
25250
532faf893d37
patch 8.2.3161: Vim9: no error when reltime() has invalid arguments
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
196 } |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
197 profile_end(&res); |
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 else |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
200 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
201 // 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
|
202 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
|
203 || 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
|
204 { |
532faf893d37
patch 8.2.3161: Vim9: no error when reltime() has invalid arguments
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
205 if (in_vim9script()) |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26476
diff
changeset
|
206 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
|
207 return; |
25250
532faf893d37
patch 8.2.3161: Vim9: no error when reltime() has invalid arguments
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
208 } |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
209 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
|
210 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
211 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
212 # 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
|
213 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
|
214 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
|
215 # 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
|
216 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
|
217 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
|
218 # 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
|
219 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
|
220 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
|
221 # endif |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
222 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
223 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
224 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
225 * "reltimefloat()" function |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
226 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
227 void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
228 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
|
229 { |
30310
029c59bf78f1
patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents:
30043
diff
changeset
|
230 # 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
|
231 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
|
232 # endif |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
233 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
234 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
|
235 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
|
236 # 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
|
237 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
|
238 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
|
239 |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
240 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
|
241 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
|
242 else if (in_vim9script()) |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26476
diff
changeset
|
243 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
|
244 # endif |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
245 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
246 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
247 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
248 * "reltimestr()" function |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
249 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
250 void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
251 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
|
252 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
253 # ifdef FEAT_RELTIME |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
254 proftime_T tm; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
255 # endif |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
256 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
257 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
|
258 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
|
259 # 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
|
260 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
|
261 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
|
262 |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
263 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
|
264 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
|
265 else if (in_vim9script()) |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26476
diff
changeset
|
266 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
|
267 # endif |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
268 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
269 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
270 # 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
|
271 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
272 * "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
|
273 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
274 void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
275 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
|
276 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
277 struct tm tmval; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
278 struct tm *curtime; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
279 time_t seconds; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
280 char_u *p; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
281 |
25252
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25250
diff
changeset
|
282 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
|
283 && (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
|
284 || 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
|
285 return; |
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25250
diff
changeset
|
286 |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
287 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
|
288 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
289 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
|
290 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
|
291 seconds = time(NULL); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
292 else |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
293 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
|
294 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
|
295 // 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
|
296 if (curtime == NULL) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
297 rettv->vval.v_string = vim_strsave((char_u *)_("(Invalid)")); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
298 else |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
299 { |
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
|
300 # ifdef MSWIN |
788d7e3ade7c
patch 8.2.2894: MS-Windows: using enc_locale() for strftime() might not work
Bram Moolenaar <Bram@vim.org>
parents:
23677
diff
changeset
|
301 WCHAR result_buf[256]; |
788d7e3ade7c
patch 8.2.2894: MS-Windows: using enc_locale() for strftime() might not work
Bram Moolenaar <Bram@vim.org>
parents:
23677
diff
changeset
|
302 WCHAR *wp; |
788d7e3ade7c
patch 8.2.2894: MS-Windows: using enc_locale() for strftime() might not work
Bram Moolenaar <Bram@vim.org>
parents:
23677
diff
changeset
|
303 |
788d7e3ade7c
patch 8.2.2894: MS-Windows: using enc_locale() for strftime() might not work
Bram Moolenaar <Bram@vim.org>
parents:
23677
diff
changeset
|
304 wp = enc_to_utf16(p, NULL); |
788d7e3ade7c
patch 8.2.2894: MS-Windows: using enc_locale() for strftime() might not work
Bram Moolenaar <Bram@vim.org>
parents:
23677
diff
changeset
|
305 if (wp != NULL) |
24768
7334bf933510
patch 8.2.2922: computing array length is done in various ways
Bram Moolenaar <Bram@vim.org>
parents:
24711
diff
changeset
|
306 (void)wcsftime(result_buf, ARRAY_LENGTH(result_buf), wp, curtime); |
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
|
307 else |
788d7e3ade7c
patch 8.2.2894: MS-Windows: using enc_locale() for strftime() might not work
Bram Moolenaar <Bram@vim.org>
parents:
23677
diff
changeset
|
308 result_buf[0] = NUL; |
788d7e3ade7c
patch 8.2.2894: MS-Windows: using enc_locale() for strftime() might not work
Bram Moolenaar <Bram@vim.org>
parents:
23677
diff
changeset
|
309 rettv->vval.v_string = utf16_to_enc(result_buf, NULL); |
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 vim_free(wp); |
788d7e3ade7c
patch 8.2.2894: MS-Windows: using enc_locale() for strftime() might not work
Bram Moolenaar <Bram@vim.org>
parents:
23677
diff
changeset
|
311 # else |
788d7e3ade7c
patch 8.2.2894: MS-Windows: using enc_locale() for strftime() might not work
Bram Moolenaar <Bram@vim.org>
parents:
23677
diff
changeset
|
312 char_u result_buf[256]; |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
313 vimconv_T conv; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
314 char_u *enc; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
315 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
316 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
|
317 enc = enc_locale(); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
318 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
|
319 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
|
320 p = string_convert(&conv, p, NULL); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
321 if (p != NULL) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
322 (void)strftime((char *)result_buf, sizeof(result_buf), |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
323 (char *)p, curtime); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
324 else |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
325 result_buf[0] = NUL; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
326 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
327 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
|
328 vim_free(p); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
329 convert_setup(&conv, enc, p_enc); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
330 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
|
331 rettv->vval.v_string = string_convert(&conv, result_buf, NULL); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
332 else |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
333 rettv->vval.v_string = vim_strsave(result_buf); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
334 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
335 // Release conversion descriptors |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
336 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
|
337 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
|
338 # endif |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
339 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
340 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
341 # endif |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
342 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
343 # 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
|
344 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
345 * "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
|
346 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
347 void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
348 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
|
349 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
350 struct tm tmval; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
351 char_u *fmt; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
352 char_u *str; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
353 vimconv_T conv; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
354 char_u *enc; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
355 |
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
|
356 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
|
357 && (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
|
358 || 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
|
359 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
|
360 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19934
diff
changeset
|
361 CLEAR_FIELD(tmval); |
20794
2e7acc208a1f
patch 8.2.0949: strptime() does not use DST
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
362 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
|
363 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
|
364 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
|
365 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
366 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
|
367 enc = enc_locale(); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
368 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
|
369 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
|
370 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
|
371 if (fmt == NULL |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
372 || 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
|
373 || (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
|
374 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
|
375 |
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 vim_free(fmt); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
378 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
|
379 vim_free(enc); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
380 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
381 # endif |
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 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
|
384 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
|
385 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
|
386 |
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 * 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
|
389 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
390 long |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
391 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
|
392 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
393 # ifdef MSWIN |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
394 LARGE_INTEGER fr; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
395 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
396 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
|
397 return 0; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
398 QueryPerformanceFrequency(&fr); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
399 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
|
400 / (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
|
401 # else |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
402 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
|
403 return 0; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
404 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
|
405 + (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
|
406 # endif |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
407 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
408 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
409 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
410 * 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
|
411 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
412 static void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
413 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
|
414 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
415 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
|
416 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
|
417 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
|
418 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
|
419 first_timer = timer; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
420 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
|
421 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
422 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
423 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
424 * 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
|
425 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
426 static void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
427 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
|
428 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
429 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
|
430 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
|
431 else |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
432 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
|
433 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
|
434 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
|
435 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
436 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
437 static void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
438 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
|
439 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
440 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
|
441 vim_free(timer); |
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 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
445 * 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
|
446 * 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
|
447 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
448 timer_T * |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
449 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
|
450 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
451 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
|
452 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
|
453 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
454 if (timer == NULL) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
455 return NULL; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
456 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
|
457 // 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
|
458 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
|
459 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
|
460 insert_timer(timer); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
461 if (repeat != 0) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
462 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
|
463 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
|
464 |
29900
a6721cafbc74
patch 9.0.0288: when 'cmdheight' is zero some messages are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
465 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
|
466 return timer; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
467 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
468 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
469 /* |
29900
a6721cafbc74
patch 9.0.0288: when 'cmdheight' is zero some messages are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
470 * (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
|
471 */ |
a6721cafbc74
patch 9.0.0288: when 'cmdheight' is zero some messages are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
472 void |
a6721cafbc74
patch 9.0.0288: when 'cmdheight' is zero some messages are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
473 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
|
474 { |
a6721cafbc74
patch 9.0.0288: when 'cmdheight' is zero some messages are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
475 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
|
476 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
|
477 } |
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 /* |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
480 * 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
|
481 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
482 static void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
483 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
|
484 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
485 typval_T rettv; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
486 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
|
487 |
28725
075787b91e09
patch 8.2.4887: channel log does not show invoking a timer callback
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
488 #ifdef FEAT_JOB_CHANNEL |
075787b91e09
patch 8.2.4887: channel log does not show invoking a timer callback
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
489 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
|
490 { |
075787b91e09
patch 8.2.4887: channel log does not show invoking a timer callback
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
491 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
|
492 |
075787b91e09
patch 8.2.4887: channel log does not show invoking a timer callback
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
493 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
|
494 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
|
495 } |
075787b91e09
patch 8.2.4887: channel log does not show invoking a timer callback
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
496 #endif |
075787b91e09
patch 8.2.4887: channel log does not show invoking a timer callback
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
497 |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
498 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
|
499 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
|
500 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
|
501 |
27402
898f520e798b
patch 8.2.4229: possible crash when invoking timer callback fails
Bram Moolenaar <Bram@vim.org>
parents:
27342
diff
changeset
|
502 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
|
503 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
|
504 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
|
505 |
075787b91e09
patch 8.2.4887: channel log does not show invoking a timer callback
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
506 #ifdef FEAT_JOB_CHANNEL |
075787b91e09
patch 8.2.4887: channel log does not show invoking a timer callback
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
507 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
|
508 #endif |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
509 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
510 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
511 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
512 * 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
|
513 * 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
|
514 * 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
|
515 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
516 long |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
517 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
|
518 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
519 timer_T *timer; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
520 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
|
521 long this_due; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
522 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
|
523 proftime_T now; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
524 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
|
525 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
|
526 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
|
527 |
27012
f9a9ffebe2c0
patch 8.2.4035: timer triggered at the debug prompt may cause trouble
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
528 // 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
|
529 // 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
|
530 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
|
531 return next_due; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
532 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
533 profile_start(&now); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
534 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
|
535 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
536 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
|
537 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
538 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
|
539 continue; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
540 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
|
541 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
|
542 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
543 // 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
|
544 // 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
|
545 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
|
546 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
|
547 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
|
548 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
|
549 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
|
550 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
|
551 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
|
552 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
|
553 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
|
554 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
|
555 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
|
556 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
|
557 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
|
558 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
559 // 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
|
560 // 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
|
561 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
|
562 vgetc_busy = 0; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
563 called_emsg = 0; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
564 did_emsg = FALSE; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
565 must_redraw = 0; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
566 trylevel = 0; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
567 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
|
568 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
|
569 current_exception = NULL; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
570 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
|
571 save_vimvars(&vvsave); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
572 |
22827
20ccf5f7dc6d
patch 8.2.1961: various comments can be improved
Bram Moolenaar <Bram@vim.org>
parents:
22157
diff
changeset
|
573 // 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
|
574 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
|
575 timer_callback(timer); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
576 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
|
577 |
22827
20ccf5f7dc6d
patch 8.2.1961: various comments can be improved
Bram Moolenaar <Bram@vim.org>
parents:
22157
diff
changeset
|
578 // Restore stuff. |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
579 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
|
580 did_one = TRUE; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
581 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
|
582 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
|
583 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
|
584 ++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
|
585 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
|
586 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
|
587 trylevel = save_trylevel; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
588 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
|
589 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
|
590 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
|
591 restore_vimvars(&vvsave); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
592 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
|
593 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
|
594 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
|
595 ? 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
|
596 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
|
597 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
|
598 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
599 // 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
|
600 // 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
|
601 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
|
602 && 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
|
603 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
604 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
|
605 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
|
606 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
|
607 this_due = 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) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
609 --timer->tr_repeat; |
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 else |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
612 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
613 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
|
614 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
|
615 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
|
616 else |
a6721cafbc74
patch 9.0.0288: when 'cmdheight' is zero some messages are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
617 { |
a6721cafbc74
patch 9.0.0288: when 'cmdheight' is zero some messages are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
618 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
|
619 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
|
620 } |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
621 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
622 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
623 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
|
624 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
|
625 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
626 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
627 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
|
628 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
|
629 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
630 #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
|
631 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
|
632 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
633 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
|
634 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
|
635 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
636 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
|
637 if (balloonEval == NULL) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
638 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
639 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
|
640 balloonEvalForTerm = TRUE; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
641 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
642 if (balloonEval != NULL) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
643 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
644 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
|
645 setcursor(); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
646 out_flush(); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
647 } |
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 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
|
650 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
|
651 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
652 #endif |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
653 #ifdef FEAT_TERMINAL |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
654 // 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
|
655 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
|
656 #endif |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
657 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
658 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
|
659 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
660 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
661 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
662 * 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
|
663 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
664 static timer_T * |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
665 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
|
666 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
667 timer_T *timer; |
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 if (id >= 0) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
670 { |
19934
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
19396
diff
changeset
|
671 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
|
672 if (timer->tr_id == id) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
673 return timer; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
674 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
675 return NULL; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
676 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
677 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
678 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
679 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
680 * 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
|
681 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
682 void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
683 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
|
684 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
685 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
|
686 // 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
|
687 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
|
688 else |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
689 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
690 remove_timer(timer); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
691 free_timer(timer); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
692 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
693 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
694 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
695 static void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
696 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
|
697 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
698 timer_T *timer; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
699 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
|
700 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
701 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
|
702 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
703 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
|
704 stop_timer(timer); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
705 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
706 } |
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 static void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
709 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
|
710 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
711 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
|
712 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
|
713 dictitem_T *di; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
714 long remaining; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
715 proftime_T now; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
716 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
717 if (dict == NULL) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
718 return; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
719 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
|
720 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
721 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
|
722 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
|
723 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
724 profile_start(&now); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
725 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
|
726 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
|
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, "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
|
729 (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
|
730 : 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
|
731 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
|
732 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
733 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
|
734 if (di != NULL) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
735 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
736 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
|
737 vim_free(di); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
738 else |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
739 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
|
740 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
741 } |
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 static void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
744 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
|
745 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
746 timer_T *timer; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
747 |
19934
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
19396
diff
changeset
|
748 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
|
749 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
|
750 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
|
751 } |
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 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
754 * 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
|
755 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
756 int |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
757 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
|
758 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
759 int abort = FALSE; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
760 timer_T *timer; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
761 typval_T tv; |
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 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
|
764 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
765 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
|
766 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
767 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
|
768 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
|
769 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
770 else |
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 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
|
773 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
|
774 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
775 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
|
776 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
777 return abort; |
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 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
780 # 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
|
781 void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
782 timer_free_all() |
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 timer_T *timer; |
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 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
|
787 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
788 timer = first_timer; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
789 remove_timer(timer); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
790 free_timer(timer); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
791 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
792 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
793 # endif |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
794 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
795 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
796 * "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
|
797 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
798 void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
799 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
|
800 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
801 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
|
802 |
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
|
803 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
|
804 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
|
805 |
30043
fd855ad74887
patch 9.0.0359: error message for wrong argument type is not specific
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
806 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
|
807 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
|
808 |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
809 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
|
810 { |
30043
fd855ad74887
patch 9.0.0359: error message for wrong argument type is not specific
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
811 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
|
812 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
|
813 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
|
814 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
815 else |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
816 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
|
817 } |
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 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
820 * "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
|
821 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
822 void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
823 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
|
824 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
825 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
|
826 |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
827 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
|
828 && (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
|
829 || 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
|
830 return; |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
831 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
832 if (argvars[0].v_type != VAR_NUMBER) |
25306
078edc1821bf
patch 8.2.3190: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
833 emsg(_(e_number_expected)); |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
834 else |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
835 { |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
836 int paused = (int)tv_get_bool(&argvars[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
|
837 |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
838 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
|
839 if (timer != NULL) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
840 timer->tr_paused = paused; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
841 } |
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 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
844 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
845 * "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
|
846 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
847 void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
848 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
|
849 { |
25348
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
850 long msec; |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
851 timer_T *timer; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
852 int repeat = 0; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
853 callback_T callback; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
854 dict_T *dict; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
855 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
856 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
|
857 if (check_secure()) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
858 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
|
859 |
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
860 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
|
861 && (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
|
862 || 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
|
863 return; |
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
864 |
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
865 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
|
866 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
|
867 { |
29994
86eb4aba16c3
patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents:
29900
diff
changeset
|
868 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
|
869 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
|
870 |
86eb4aba16c3
patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents:
29900
diff
changeset
|
871 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
|
872 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
|
873 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
|
874 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
875 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
876 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
|
877 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
|
878 return; |
27402
898f520e798b
patch 8.2.4229: possible crash when invoking timer callback fails
Bram Moolenaar <Bram@vim.org>
parents:
27342
diff
changeset
|
879 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
|
880 { |
898f520e798b
patch 8.2.4229: possible crash when invoking timer callback fails
Bram Moolenaar <Bram@vim.org>
parents:
27342
diff
changeset
|
881 // 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
|
882 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
|
883 free_callback(&callback); |
898f520e798b
patch 8.2.4229: possible crash when invoking timer callback fails
Bram Moolenaar <Bram@vim.org>
parents:
27342
diff
changeset
|
884 return; |
898f520e798b
patch 8.2.4229: possible crash when invoking timer callback fails
Bram Moolenaar <Bram@vim.org>
parents:
27342
diff
changeset
|
885 } |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
886 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
887 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
|
888 if (timer == NULL) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
889 free_callback(&callback); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
890 else |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
891 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
892 set_callback(&timer->tr_callback, &callback); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
893 rettv->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
|
894 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
895 } |
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 * "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
|
899 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
900 void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
901 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
|
902 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
903 timer_T *timer; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
904 |
30043
fd855ad74887
patch 9.0.0359: error message for wrong argument type is not specific
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
905 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
|
906 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
|
907 |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
908 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
|
909 if (timer != NULL) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
910 stop_timer(timer); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
911 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
912 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
913 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
914 * "timer_stopall()" function |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
915 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
916 void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
917 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
|
918 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
919 stop_all_timers(); |
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 # endif // FEAT_TIMERS |
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 # 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
|
925 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
|
926 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
927 # ifdef MSWIN |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
928 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
929 * 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
|
930 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
931 static int |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
932 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
|
933 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
934 long t = clock(); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
935 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
|
936 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
|
937 return 0; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
938 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
939 # endif |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
940 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
941 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
942 * 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
|
943 * 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
|
944 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
945 void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
946 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
|
947 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
948 *((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
|
949 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
|
950 ((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
|
951 - ((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
|
952 ((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
|
953 - ((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
|
954 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
|
955 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
956 ((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
|
957 --((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
|
958 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
959 *(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
|
960 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
961 |
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 * 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
|
964 * 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
|
965 * 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
|
966 * have struct timeval. |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
967 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
968 void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
969 time_pop( |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
970 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
|
971 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
972 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
|
973 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
|
974 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
|
975 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
976 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
|
977 --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
|
978 } |
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 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
981 static void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
982 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
|
983 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
984 long usec; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
985 long msec; |
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 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
|
988 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
|
989 usec = usec % 1000L; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
990 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
|
991 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
992 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
993 void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
994 time_msg( |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
995 char *mesg, |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
996 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
|
997 // (struct timeval *) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
998 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
999 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
|
1000 struct timeval now; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1001 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1002 if (time_fd != NULL) |
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 if (strstr(mesg, "STARTING") != NULL) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1005 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1006 gettimeofday(&start, NULL); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1007 prev_timeval = start; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1008 fprintf(time_fd, "\n\ntimes in msec\n"); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1009 fprintf(time_fd, " clock self+sourced self: sourced script\n"); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1010 fprintf(time_fd, " clock elapsed: other lines\n\n"); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1011 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1012 gettimeofday(&now, NULL); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1013 time_diff(&start, &now); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1014 if (((struct timeval *)tv_start) != NULL) |
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 fprintf(time_fd, " "); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1017 time_diff(((struct timeval *)tv_start), &now); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1018 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1019 fprintf(time_fd, " "); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1020 time_diff(&prev_timeval, &now); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1021 prev_timeval = now; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1022 fprintf(time_fd, ": %s\n", mesg); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1023 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1024 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1025 # endif // STARTUPTIME |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1026 #endif // FEAT_EVAL |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1027 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1028 #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
|
1029 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1030 * 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
|
1031 * 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
|
1032 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1033 time_T |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1034 get8ctime(FILE *fd) |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1035 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1036 int c; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1037 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
|
1038 int i; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1039 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1040 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
|
1041 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1042 c = getc(fd); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1043 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
|
1044 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
|
1045 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1046 return n; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1047 } |
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 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1050 * 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
|
1051 * 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
|
1052 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1053 int |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1054 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
|
1055 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1056 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
|
1057 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1058 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
|
1059 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
|
1060 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1061 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1062 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1063 * 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
|
1064 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1065 void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1066 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
|
1067 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1068 int c; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1069 int i; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1070 int bi = 0; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1071 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
|
1072 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1073 // 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
|
1074 // 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
|
1075 // 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
|
1076 // 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
|
1077 // 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
|
1078 // 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
|
1079 // 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
|
1080 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
|
1081 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1082 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
|
1083 // ">>" 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
|
1084 buf[bi++] = 0; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1085 else |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1086 { |
27342
41a940219183
patch 8.2.4199: MS-Windows: Support for MSVC 2003 is not useful
Bram Moolenaar <Bram@vim.org>
parents:
27253
diff
changeset
|
1087 # 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
|
1088 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
|
1089 # else |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1090 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
|
1091 # endif |
19396
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1092 buf[bi++] = c; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1093 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1094 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1095 } |
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 #endif |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1098 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1099 /* |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1100 * 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
|
1101 */ |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1102 void |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1103 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
|
1104 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1105 #ifdef HAVE_STRFTIME |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1106 struct tm tmval; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1107 struct tm *curtime; |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1108 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1109 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
|
1110 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1111 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
|
1112 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
|
1113 // within 12 hours |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1114 (void)strftime((char *)buf, buflen, "%H:%M:%S", curtime); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1115 else |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1116 // longer ago |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1117 (void)strftime((char *)buf, buflen, "%Y/%m/%d %H:%M:%S", curtime); |
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 else |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1120 #endif |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1121 { |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1122 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
|
1123 |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1124 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
|
1125 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
|
1126 seconds); |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1127 } |
a961efb326e5
patch 8.2.0256: time and timer related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1128 } |