Mercurial > vim
annotate src/message.c @ 18293:1c5974759bcd v8.1.2141
patch 8.1.2141: :tselect has an extra hit-enter prompt
Commit: https://github.com/vim/vim/commit/e8070987c6ca9b1e14c5305707c6d29c8e58e7c4
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Oct 12 17:07:06 2019 +0200
patch 8.1.2141: :tselect has an extra hit-enter prompt
Problem: :tselect has an extra hit-enter prompt.
Solution: Do not set need_wait_return when only moving the cursor.
(closes #5040)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 12 Oct 2019 17:15:04 +0200 |
parents | dfe9db84e326 |
children | 2047cb93eb0c |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
10040
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * message.c: functions for displaying messages on the command line | |
12 */ | |
13 | |
14 #define MESSAGE_FILE /* don't include prototype for smsg() */ | |
9988
cafe247c949a
commit https://github.com/vim/vim/commit/44ca54aeb9a0eca41aea203786e33d82e69d0615
Christian Brabandt <cb@256bit.org>
parents:
9986
diff
changeset
|
15 #define USING_FLOAT_STUFF |
7 | 16 |
17 #include "vim.h" | |
18 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
19 static void add_msg_hist(char_u *s, int len, int attr); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
20 static void hit_return_msg(void); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
21 static void msg_home_replace_attr(char_u *fname, int attr); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
22 static void msg_puts_attr_len(char *str, int maxlen, int attr); |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
23 static void msg_puts_display(char_u *str, int maxlen, int attr, int recurse); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
24 static void msg_scroll_up(void); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
25 static void inc_msg_scrolled(void); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
26 static void store_sb_text(char_u **sb_str, char_u *s, int attr, int *sb_col, int finish); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
27 static void t_puts(int *t_col, char_u *t_s, char_u *s, int attr); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
28 static void msg_puts_printf(char_u *str, int maxlen); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
29 static int do_more_prompt(int typed_char); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
30 static void msg_screen_putchar(int c, int attr); |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
31 static void msg_moremsg(int full); |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
32 static int msg_check_screen(void); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
33 static void redir_write(char_u *s, int maxlen); |
7 | 34 #ifdef FEAT_CON_DIALOG |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
35 static char_u *msg_show_console_dialog(char_u *message, char_u *buttons, int dfltbutton); |
7 | 36 static int confirm_msg_used = FALSE; /* displaying confirm_msg */ |
37 static char_u *confirm_msg = NULL; /* ":confirm" message */ | |
38 static char_u *confirm_msg_tail; /* tail of confirm_msg */ | |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
39 static void display_confirm_msg(void); |
7 | 40 #endif |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
41 #ifdef FEAT_JOB_CHANNEL |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
42 static int emsg_to_channel_log = FALSE; |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
43 #endif |
7 | 44 |
45 struct msg_hist | |
46 { | |
47 struct msg_hist *next; | |
48 char_u *msg; | |
49 int attr; | |
50 }; | |
51 | |
52 static struct msg_hist *first_msg_hist = NULL; | |
53 static struct msg_hist *last_msg_hist = NULL; | |
54 static int msg_hist_len = 0; | |
55 | |
3072 | 56 static FILE *verbose_fd = NULL; |
57 static int verbose_did_open = FALSE; | |
58 | |
7 | 59 /* |
60 * When writing messages to the screen, there are many different situations. | |
61 * A number of variables is used to remember the current state: | |
62 * msg_didany TRUE when messages were written since the last time the | |
63 * user reacted to a prompt. | |
64 * Reset: After hitting a key for the hit-return prompt, | |
65 * hitting <CR> for the command line or input(). | |
66 * Set: When any message is written to the screen. | |
67 * msg_didout TRUE when something was written to the current line. | |
68 * Reset: When advancing to the next line, when the current | |
69 * text can be overwritten. | |
70 * Set: When any message is written to the screen. | |
71 * msg_nowait No extra delay for the last drawn message. | |
72 * Used in normal_cmd() before the mode message is drawn. | |
73 * emsg_on_display There was an error message recently. Indicates that there | |
74 * should be a delay before redrawing. | |
75 * msg_scroll The next message should not overwrite the current one. | |
76 * msg_scrolled How many lines the screen has been scrolled (because of | |
77 * messages). Used in update_screen() to scroll the screen | |
78 * back. Incremented each time the screen scrolls a line. | |
79 * msg_scrolled_ign TRUE when msg_scrolled is non-zero and msg_puts_attr() | |
80 * writes something without scrolling should not make | |
81 * need_wait_return to be set. This is a hack to make ":ts" | |
82 * work without an extra prompt. | |
83 * lines_left Number of lines available for messages before the | |
3240 | 84 * more-prompt is to be given. -1 when not set. |
7 | 85 * need_wait_return TRUE when the hit-return prompt is needed. |
86 * Reset: After giving the hit-return prompt, when the user | |
87 * has answered some other prompt. | |
88 * Set: When the ruler or typeahead display is overwritten, | |
89 * scrolling the screen for some message. | |
90 * keep_msg Message to be displayed after redrawing the screen, in | |
91 * main_loop(). | |
92 * This is an allocated string or NULL when not used. | |
93 */ | |
94 | |
95 /* | |
96 * msg(s) - displays the string 's' on the status line | |
97 * When terminal not initialized (yet) mch_errmsg(..) is used. | |
98 * return TRUE if wait_return not called | |
99 */ | |
100 int | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
101 msg(char *s) |
7 | 102 { |
103 return msg_attr_keep(s, 0, FALSE); | |
104 } | |
105 | |
291 | 106 /* |
107 * Like msg() but keep it silent when 'verbosefile' is set. | |
108 */ | |
109 int | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
110 verb_msg(char *s) |
291 | 111 { |
112 int n; | |
113 | |
114 verbose_enter(); | |
115 n = msg_attr_keep(s, 0, FALSE); | |
116 verbose_leave(); | |
117 | |
118 return n; | |
119 } | |
120 | |
7 | 121 int |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
122 msg_attr(char *s, int attr) |
7 | 123 { |
124 return msg_attr_keep(s, attr, FALSE); | |
125 } | |
126 | |
127 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
128 msg_attr_keep( |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
129 char *s, |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
130 int attr, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
131 int keep) /* TRUE: set keep_msg if it doesn't scroll */ |
7 | 132 { |
133 static int entered = 0; | |
134 int retval; | |
135 char_u *buf = NULL; | |
136 | |
9941
e975914c17e9
commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
9894
diff
changeset
|
137 /* Skip messages not matching ":filter pattern". |
e975914c17e9
commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
9894
diff
changeset
|
138 * Don't filter when there is an error. */ |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
139 if (!emsg_on_display && message_filtered((char_u *)s)) |
9941
e975914c17e9
commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
9894
diff
changeset
|
140 return TRUE; |
e975914c17e9
commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
9894
diff
changeset
|
141 |
7 | 142 #ifdef FEAT_EVAL |
143 if (attr == 0) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
144 set_vim_var_string(VV_STATUSMSG, (char_u *)s, -1); |
7 | 145 #endif |
146 | |
147 /* | |
148 * It is possible that displaying a messages causes a problem (e.g., | |
149 * when redrawing the window), which causes another message, etc.. To | |
150 * break this loop, limit the recursiveness to 3 levels. | |
151 */ | |
152 if (entered >= 3) | |
153 return TRUE; | |
154 ++entered; | |
155 | |
156 /* Add message to history (unless it's a repeated kept message or a | |
157 * truncated message) */ | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
158 if ((char_u *)s != keep_msg |
7 | 159 || (*s != '<' |
160 && last_msg_hist != NULL | |
161 && last_msg_hist->msg != NULL | |
162 && STRCMP(s, last_msg_hist->msg))) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
163 add_msg_hist((char_u *)s, -1, attr); |
7 | 164 |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
165 #ifdef FEAT_JOB_CHANNEL |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
166 if (emsg_to_channel_log) |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
167 /* Write message in the channel log. */ |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11653
diff
changeset
|
168 ch_log(NULL, "ERROR: %s", (char *)s); |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
169 #endif |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
170 |
7 | 171 /* Truncate the message if needed. */ |
513 | 172 msg_start(); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
173 buf = msg_strtrunc((char_u *)s, FALSE); |
7 | 174 if (buf != NULL) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
175 s = (char *)buf; |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
176 |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
177 msg_outtrans_attr((char_u *)s, attr); |
7 | 178 msg_clr_eos(); |
179 retval = msg_end(); | |
180 | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
181 if (keep && retval && vim_strsize((char_u *)s) |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
182 < (int)(Rows - cmdline_row - 1) * Columns + sc_col) |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
183 set_keep_msg((char_u *)s, 0); |
7 | 184 |
185 vim_free(buf); | |
186 --entered; | |
187 return retval; | |
188 } | |
189 | |
190 /* | |
191 * Truncate a string such that it can be printed without causing a scroll. | |
192 * Returns an allocated string or NULL when no truncating is done. | |
193 */ | |
194 char_u * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
195 msg_strtrunc( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
196 char_u *s, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
197 int force) /* always truncate */ |
7 | 198 { |
199 char_u *buf = NULL; | |
200 int len; | |
201 int room; | |
202 | |
203 /* May truncate message to avoid a hit-return prompt */ | |
513 | 204 if ((!msg_scroll && !need_wait_return && shortmess(SHM_TRUNCALL) |
205 && !exmode_active && msg_silent == 0) || force) | |
7 | 206 { |
207 len = vim_strsize(s); | |
539 | 208 if (msg_scrolled != 0) |
513 | 209 /* Use all the columns. */ |
210 room = (int)(Rows - msg_row) * Columns - 1; | |
211 else | |
212 /* Use up to 'showcmd' column. */ | |
213 room = (int)(Rows - msg_row - 1) * Columns + sc_col - 1; | |
7 | 214 if (len > room && room > 0) |
215 { | |
216 if (enc_utf8) | |
217 /* may have up to 18 bytes per cell (6 per char, up to two | |
218 * composing chars) */ | |
3277 | 219 len = (room + 2) * 18; |
7 | 220 else if (enc_dbcs == DBCS_JPNU) |
221 /* may have up to 2 bytes per cell for euc-jp */ | |
3277 | 222 len = (room + 2) * 2; |
7 | 223 else |
3277 | 224 len = room + 2; |
225 buf = alloc(len); | |
7 | 226 if (buf != NULL) |
3277 | 227 trunc_string(s, buf, room, len); |
7 | 228 } |
229 } | |
230 return buf; | |
231 } | |
232 | |
233 /* | |
234 * Truncate a string "s" to "buf" with cell width "room". | |
235 * "s" and "buf" may be equal. | |
236 */ | |
237 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
238 trunc_string( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
239 char_u *s, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
240 char_u *buf, |
9640
bc0a6d9a9a07
commit https://github.com/vim/vim/commit/d4f31dc45482e8db527ca044b9c3436b1e750006
Christian Brabandt <cb@256bit.org>
parents:
9605
diff
changeset
|
241 int room_in, |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
242 int buflen) |
7 | 243 { |
9640
bc0a6d9a9a07
commit https://github.com/vim/vim/commit/d4f31dc45482e8db527ca044b9c3436b1e750006
Christian Brabandt <cb@256bit.org>
parents:
9605
diff
changeset
|
244 size_t room = room_in - 3; /* "..." takes 3 chars */ |
bc0a6d9a9a07
commit https://github.com/vim/vim/commit/d4f31dc45482e8db527ca044b9c3436b1e750006
Christian Brabandt <cb@256bit.org>
parents:
9605
diff
changeset
|
245 size_t half; |
bc0a6d9a9a07
commit https://github.com/vim/vim/commit/d4f31dc45482e8db527ca044b9c3436b1e750006
Christian Brabandt <cb@256bit.org>
parents:
9605
diff
changeset
|
246 size_t len = 0; |
7 | 247 int e; |
248 int i; | |
249 int n; | |
250 | |
9640
bc0a6d9a9a07
commit https://github.com/vim/vim/commit/d4f31dc45482e8db527ca044b9c3436b1e750006
Christian Brabandt <cb@256bit.org>
parents:
9605
diff
changeset
|
251 if (room_in < 3) |
bc0a6d9a9a07
commit https://github.com/vim/vim/commit/d4f31dc45482e8db527ca044b9c3436b1e750006
Christian Brabandt <cb@256bit.org>
parents:
9605
diff
changeset
|
252 room = 0; |
7 | 253 half = room / 2; |
254 | |
255 /* First part: Start of the string. */ | |
3277 | 256 for (e = 0; len < half && e < buflen; ++e) |
7 | 257 { |
258 if (s[e] == NUL) | |
259 { | |
260 /* text fits without truncating! */ | |
261 buf[e] = NUL; | |
262 return; | |
263 } | |
264 n = ptr2cells(s + e); | |
9542
00ee8d8c2e0c
commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
9538
diff
changeset
|
265 if (len + n > half) |
7 | 266 break; |
267 len += n; | |
268 buf[e] = s[e]; | |
269 if (has_mbyte) | |
474 | 270 for (n = (*mb_ptr2len)(s + e); --n > 0; ) |
7 | 271 { |
3277 | 272 if (++e == buflen) |
273 break; | |
7 | 274 buf[e] = s[e]; |
275 } | |
276 } | |
277 | |
278 /* Last part: End of the string. */ | |
279 i = e; | |
280 if (enc_dbcs != 0) | |
281 { | |
282 /* For DBCS going backwards in a string is slow, but | |
283 * computing the cell width isn't too slow: go forward | |
284 * until the rest fits. */ | |
285 n = vim_strsize(s + i); | |
286 while (len + n > room) | |
287 { | |
288 n -= ptr2cells(s + i); | |
474 | 289 i += (*mb_ptr2len)(s + i); |
7 | 290 } |
291 } | |
292 else if (enc_utf8) | |
293 { | |
294 /* For UTF-8 we can go backwards easily. */ | |
714 | 295 half = i = (int)STRLEN(s); |
7 | 296 for (;;) |
297 { | |
714 | 298 do |
11269
121d29004998
patch 8.0.0520: using a function pointer while the function is known
Christian Brabandt <cb@256bit.org>
parents:
11163
diff
changeset
|
299 half = half - utf_head_off(s, s + half - 1) - 1; |
9581
716382aaa0c0
commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents:
9542
diff
changeset
|
300 while (half > 0 && utf_iscomposing(utf_ptr2char(s + half))); |
7 | 301 n = ptr2cells(s + half); |
9581
716382aaa0c0
commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents:
9542
diff
changeset
|
302 if (len + n > room || half == 0) |
7 | 303 break; |
304 len += n; | |
9698
a1b1405a33ca
commit https://github.com/vim/vim/commit/a5c0cc11330157c721748e317e8ff54b649610ca
Christian Brabandt <cb@256bit.org>
parents:
9640
diff
changeset
|
305 i = (int)half; |
7 | 306 } |
307 } | |
308 else | |
309 { | |
310 for (i = (int)STRLEN(s); len + (n = ptr2cells(s + i - 1)) <= room; --i) | |
311 len += n; | |
312 } | |
313 | |
9538
26da1efa9e46
commit https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954
Christian Brabandt <cb@256bit.org>
parents:
9497
diff
changeset
|
314 |
26da1efa9e46
commit https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954
Christian Brabandt <cb@256bit.org>
parents:
9497
diff
changeset
|
315 if (i <= e + 3) |
3277 | 316 { |
9538
26da1efa9e46
commit https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954
Christian Brabandt <cb@256bit.org>
parents:
9497
diff
changeset
|
317 /* text fits without truncating */ |
26da1efa9e46
commit https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954
Christian Brabandt <cb@256bit.org>
parents:
9497
diff
changeset
|
318 if (s != buf) |
26da1efa9e46
commit https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954
Christian Brabandt <cb@256bit.org>
parents:
9497
diff
changeset
|
319 { |
26da1efa9e46
commit https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954
Christian Brabandt <cb@256bit.org>
parents:
9497
diff
changeset
|
320 len = STRLEN(s); |
9640
bc0a6d9a9a07
commit https://github.com/vim/vim/commit/d4f31dc45482e8db527ca044b9c3436b1e750006
Christian Brabandt <cb@256bit.org>
parents:
9605
diff
changeset
|
321 if (len >= (size_t)buflen) |
9538
26da1efa9e46
commit https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954
Christian Brabandt <cb@256bit.org>
parents:
9497
diff
changeset
|
322 len = buflen - 1; |
26da1efa9e46
commit https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954
Christian Brabandt <cb@256bit.org>
parents:
9497
diff
changeset
|
323 len = len - e + 1; |
26da1efa9e46
commit https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954
Christian Brabandt <cb@256bit.org>
parents:
9497
diff
changeset
|
324 if (len < 1) |
26da1efa9e46
commit https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954
Christian Brabandt <cb@256bit.org>
parents:
9497
diff
changeset
|
325 buf[e - 1] = NUL; |
26da1efa9e46
commit https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954
Christian Brabandt <cb@256bit.org>
parents:
9497
diff
changeset
|
326 else |
26da1efa9e46
commit https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954
Christian Brabandt <cb@256bit.org>
parents:
9497
diff
changeset
|
327 mch_memmove(buf + e, s + e, len); |
26da1efa9e46
commit https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954
Christian Brabandt <cb@256bit.org>
parents:
9497
diff
changeset
|
328 } |
26da1efa9e46
commit https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954
Christian Brabandt <cb@256bit.org>
parents:
9497
diff
changeset
|
329 } |
26da1efa9e46
commit https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954
Christian Brabandt <cb@256bit.org>
parents:
9497
diff
changeset
|
330 else if (e + 3 < buflen) |
26da1efa9e46
commit https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954
Christian Brabandt <cb@256bit.org>
parents:
9497
diff
changeset
|
331 { |
26da1efa9e46
commit https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954
Christian Brabandt <cb@256bit.org>
parents:
9497
diff
changeset
|
332 /* set the middle and copy the last part */ |
3277 | 333 mch_memmove(buf + e, "...", (size_t)3); |
9640
bc0a6d9a9a07
commit https://github.com/vim/vim/commit/d4f31dc45482e8db527ca044b9c3436b1e750006
Christian Brabandt <cb@256bit.org>
parents:
9605
diff
changeset
|
334 len = STRLEN(s + i) + 1; |
bc0a6d9a9a07
commit https://github.com/vim/vim/commit/d4f31dc45482e8db527ca044b9c3436b1e750006
Christian Brabandt <cb@256bit.org>
parents:
9605
diff
changeset
|
335 if (len >= (size_t)buflen - e - 3) |
3277 | 336 len = buflen - e - 3 - 1; |
337 mch_memmove(buf + e + 3, s + i, len); | |
338 buf[e + 3 + len - 1] = NUL; | |
339 } | |
340 else | |
341 { | |
9538
26da1efa9e46
commit https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954
Christian Brabandt <cb@256bit.org>
parents:
9497
diff
changeset
|
342 /* can't fit in the "...", just truncate it */ |
26da1efa9e46
commit https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954
Christian Brabandt <cb@256bit.org>
parents:
9497
diff
changeset
|
343 buf[e - 1] = NUL; |
3277 | 344 } |
7 | 345 } |
346 | |
347 /* | |
348 * Automatic prototype generation does not understand this function. | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
349 * Note: Caller of smsg() and smsg_attr() must check the resulting string is |
7 | 350 * shorter than IOSIZE!!! |
351 */ | |
352 #ifndef PROTO | |
353 | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
354 int vim_snprintf(char *str, size_t str_m, const char *fmt, ...); |
272 | 355 |
7 | 356 int |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
357 smsg(const char *s, ...) |
7 | 358 { |
359 va_list arglist; | |
360 | |
361 va_start(arglist, s); | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
362 vim_vsnprintf((char *)IObuff, IOSIZE, s, arglist); |
7 | 363 va_end(arglist); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
364 return msg((char *)IObuff); |
7 | 365 } |
366 | |
367 int | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
368 smsg_attr(int attr, const char *s, ...) |
7 | 369 { |
370 va_list arglist; | |
371 | |
372 va_start(arglist, s); | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
373 vim_vsnprintf((char *)IObuff, IOSIZE, s, arglist); |
7 | 374 va_end(arglist); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
375 return msg_attr((char *)IObuff, attr); |
7 | 376 } |
377 | |
14237
487d7bda80ea
patch 8.1.0135: undo message delays screen update for CTRL-O u
Christian Brabandt <cb@256bit.org>
parents:
14210
diff
changeset
|
378 int |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
379 smsg_attr_keep(int attr, const char *s, ...) |
14237
487d7bda80ea
patch 8.1.0135: undo message delays screen update for CTRL-O u
Christian Brabandt <cb@256bit.org>
parents:
14210
diff
changeset
|
380 { |
487d7bda80ea
patch 8.1.0135: undo message delays screen update for CTRL-O u
Christian Brabandt <cb@256bit.org>
parents:
14210
diff
changeset
|
381 va_list arglist; |
487d7bda80ea
patch 8.1.0135: undo message delays screen update for CTRL-O u
Christian Brabandt <cb@256bit.org>
parents:
14210
diff
changeset
|
382 |
487d7bda80ea
patch 8.1.0135: undo message delays screen update for CTRL-O u
Christian Brabandt <cb@256bit.org>
parents:
14210
diff
changeset
|
383 va_start(arglist, s); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
384 vim_vsnprintf((char *)IObuff, IOSIZE, s, arglist); |
14237
487d7bda80ea
patch 8.1.0135: undo message delays screen update for CTRL-O u
Christian Brabandt <cb@256bit.org>
parents:
14210
diff
changeset
|
385 va_end(arglist); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
386 return msg_attr_keep((char *)IObuff, attr, TRUE); |
14237
487d7bda80ea
patch 8.1.0135: undo message delays screen update for CTRL-O u
Christian Brabandt <cb@256bit.org>
parents:
14210
diff
changeset
|
387 } |
487d7bda80ea
patch 8.1.0135: undo message delays screen update for CTRL-O u
Christian Brabandt <cb@256bit.org>
parents:
14210
diff
changeset
|
388 |
7 | 389 #endif |
390 | |
391 /* | |
392 * Remember the last sourcing name/lnum used in an error message, so that it | |
393 * isn't printed each time when it didn't change. | |
394 */ | |
395 static int last_sourcing_lnum = 0; | |
396 static char_u *last_sourcing_name = NULL; | |
397 | |
398 /* | |
399 * Reset the last used sourcing name/lnum. Makes sure it is displayed again | |
400 * for the next error message; | |
401 */ | |
360 | 402 void |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
403 reset_last_sourcing(void) |
7 | 404 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13188
diff
changeset
|
405 VIM_CLEAR(last_sourcing_name); |
7 | 406 last_sourcing_lnum = 0; |
407 } | |
408 | |
409 /* | |
16 | 410 * Return TRUE if "sourcing_name" differs from "last_sourcing_name". |
411 */ | |
412 static int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
413 other_sourcing_name(void) |
16 | 414 { |
415 if (sourcing_name != NULL) | |
416 { | |
417 if (last_sourcing_name != NULL) | |
418 return STRCMP(sourcing_name, last_sourcing_name) != 0; | |
419 return TRUE; | |
420 } | |
421 return FALSE; | |
422 } | |
423 | |
424 /* | |
7 | 425 * Get the message about the source, as used for an error message. |
426 * Returns an allocated string with room for one more character. | |
427 * Returns NULL when no message is to be given. | |
428 */ | |
429 static char_u * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
430 get_emsg_source(void) |
7 | 431 { |
432 char_u *Buf, *p; | |
433 | |
16 | 434 if (sourcing_name != NULL && other_sourcing_name()) |
7 | 435 { |
436 p = (char_u *)_("Error detected while processing %s:"); | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
437 Buf = alloc(STRLEN(sourcing_name) + STRLEN(p)); |
7 | 438 if (Buf != NULL) |
439 sprintf((char *)Buf, (char *)p, sourcing_name); | |
440 return Buf; | |
441 } | |
442 return NULL; | |
443 } | |
444 | |
445 /* | |
446 * Get the message about the source lnum, as used for an error message. | |
447 * Returns an allocated string with room for one more character. | |
448 * Returns NULL when no message is to be given. | |
449 */ | |
450 static char_u * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
451 get_emsg_lnum(void) |
7 | 452 { |
453 char_u *Buf, *p; | |
454 | |
455 /* lnum is 0 when executing a command from the command line | |
456 * argument, we don't want a line number then */ | |
457 if (sourcing_name != NULL | |
16 | 458 && (other_sourcing_name() || sourcing_lnum != last_sourcing_lnum) |
7 | 459 && sourcing_lnum != 0) |
460 { | |
461 p = (char_u *)_("line %4ld:"); | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
462 Buf = alloc(STRLEN(p) + 20); |
7 | 463 if (Buf != NULL) |
464 sprintf((char *)Buf, (char *)p, (long)sourcing_lnum); | |
465 return Buf; | |
466 } | |
467 return NULL; | |
468 } | |
469 | |
470 /* | |
16 | 471 * Display name and line number for the source of an error. |
472 * Remember the file name and line number, so that for the next error the info | |
473 * is only displayed if it changed. | |
474 */ | |
475 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
476 msg_source(int attr) |
16 | 477 { |
478 char_u *p; | |
479 | |
480 ++no_wait_return; | |
481 p = get_emsg_source(); | |
482 if (p != NULL) | |
483 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
484 msg_attr((char *)p, attr); |
16 | 485 vim_free(p); |
486 } | |
487 p = get_emsg_lnum(); | |
488 if (p != NULL) | |
489 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
490 msg_attr((char *)p, HL_ATTR(HLF_N)); |
16 | 491 vim_free(p); |
492 last_sourcing_lnum = sourcing_lnum; /* only once for each line */ | |
493 } | |
494 | |
495 /* remember the last sourcing name printed, also when it's empty */ | |
36 | 496 if (sourcing_name == NULL || other_sourcing_name()) |
16 | 497 { |
498 vim_free(last_sourcing_name); | |
499 if (sourcing_name == NULL) | |
500 last_sourcing_name = NULL; | |
501 else | |
502 last_sourcing_name = vim_strsave(sourcing_name); | |
503 } | |
504 --no_wait_return; | |
505 } | |
506 | |
507 /* | |
840 | 508 * Return TRUE if not giving error messages right now: |
509 * If "emsg_off" is set: no error messages at the moment. | |
510 * If "msg" is in 'debug': do error message but without side effects. | |
511 * If "emsg_skip" is set: never do error messages. | |
512 */ | |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
513 static int |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
514 emsg_not_now(void) |
840 | 515 { |
516 if ((emsg_off > 0 && vim_strchr(p_debug, 'm') == NULL | |
517 && vim_strchr(p_debug, 't') == NULL) | |
518 #ifdef FEAT_EVAL | |
519 || emsg_skip > 0 | |
520 #endif | |
521 ) | |
522 return TRUE; | |
523 return FALSE; | |
524 } | |
525 | |
11016
4e7308525fe7
patch 8.0.0397: can't build with +viminfo but without +eval
Christian Brabandt <cb@256bit.org>
parents:
11012
diff
changeset
|
526 #if defined(FEAT_EVAL) || defined(PROTO) |
11006
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
527 static garray_T ignore_error_list = GA_EMPTY; |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
528 |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
529 void |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
530 ignore_error_for_testing(char_u *error) |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
531 { |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
532 if (ignore_error_list.ga_itemsize == 0) |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
533 ga_init2(&ignore_error_list, sizeof(char_u *), 1); |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
534 |
15219
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
535 if (STRCMP("RESET", error) == 0) |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
536 ga_clear_strings(&ignore_error_list); |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
537 else |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
538 ga_add_string(&ignore_error_list, error); |
11006
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
539 } |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
540 |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
541 static int |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
542 ignore_error(char_u *msg) |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
543 { |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
544 int i; |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
545 |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
546 for (i = 0; i < ignore_error_list.ga_len; ++i) |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
547 if (strstr((char *)msg, |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
548 (char *)((char_u **)(ignore_error_list.ga_data))[i]) != NULL) |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
549 return TRUE; |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
550 return FALSE; |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
551 } |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
552 #endif |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
553 |
9605
846d4bad2df7
commit https://github.com/vim/vim/commit/b869c0da31716ff14bbfd63346d140d0a1d68af7
Christian Brabandt <cb@256bit.org>
parents:
9581
diff
changeset
|
554 #if !defined(HAVE_STRERROR) || defined(PROTO) |
846d4bad2df7
commit https://github.com/vim/vim/commit/b869c0da31716ff14bbfd63346d140d0a1d68af7
Christian Brabandt <cb@256bit.org>
parents:
9581
diff
changeset
|
555 /* |
846d4bad2df7
commit https://github.com/vim/vim/commit/b869c0da31716ff14bbfd63346d140d0a1d68af7
Christian Brabandt <cb@256bit.org>
parents:
9581
diff
changeset
|
556 * Replacement for perror() that behaves more or less like emsg() was called. |
846d4bad2df7
commit https://github.com/vim/vim/commit/b869c0da31716ff14bbfd63346d140d0a1d68af7
Christian Brabandt <cb@256bit.org>
parents:
9581
diff
changeset
|
557 * v:errmsg will be set and called_emsg will be set. |
846d4bad2df7
commit https://github.com/vim/vim/commit/b869c0da31716ff14bbfd63346d140d0a1d68af7
Christian Brabandt <cb@256bit.org>
parents:
9581
diff
changeset
|
558 */ |
846d4bad2df7
commit https://github.com/vim/vim/commit/b869c0da31716ff14bbfd63346d140d0a1d68af7
Christian Brabandt <cb@256bit.org>
parents:
9581
diff
changeset
|
559 void |
846d4bad2df7
commit https://github.com/vim/vim/commit/b869c0da31716ff14bbfd63346d140d0a1d68af7
Christian Brabandt <cb@256bit.org>
parents:
9581
diff
changeset
|
560 do_perror(char *msg) |
846d4bad2df7
commit https://github.com/vim/vim/commit/b869c0da31716ff14bbfd63346d140d0a1d68af7
Christian Brabandt <cb@256bit.org>
parents:
9581
diff
changeset
|
561 { |
846d4bad2df7
commit https://github.com/vim/vim/commit/b869c0da31716ff14bbfd63346d140d0a1d68af7
Christian Brabandt <cb@256bit.org>
parents:
9581
diff
changeset
|
562 perror(msg); |
846d4bad2df7
commit https://github.com/vim/vim/commit/b869c0da31716ff14bbfd63346d140d0a1d68af7
Christian Brabandt <cb@256bit.org>
parents:
9581
diff
changeset
|
563 ++emsg_silent; |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
564 emsg(msg); |
9605
846d4bad2df7
commit https://github.com/vim/vim/commit/b869c0da31716ff14bbfd63346d140d0a1d68af7
Christian Brabandt <cb@256bit.org>
parents:
9581
diff
changeset
|
565 --emsg_silent; |
846d4bad2df7
commit https://github.com/vim/vim/commit/b869c0da31716ff14bbfd63346d140d0a1d68af7
Christian Brabandt <cb@256bit.org>
parents:
9581
diff
changeset
|
566 } |
846d4bad2df7
commit https://github.com/vim/vim/commit/b869c0da31716ff14bbfd63346d140d0a1d68af7
Christian Brabandt <cb@256bit.org>
parents:
9581
diff
changeset
|
567 #endif |
846d4bad2df7
commit https://github.com/vim/vim/commit/b869c0da31716ff14bbfd63346d140d0a1d68af7
Christian Brabandt <cb@256bit.org>
parents:
9581
diff
changeset
|
568 |
840 | 569 /* |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
570 * emsg_core() - display an error message |
7 | 571 * |
572 * Rings the bell, if appropriate, and calls message() to do the real work | |
573 * When terminal not initialized (yet) mch_errmsg(..) is used. | |
574 * | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
575 * Return TRUE if wait_return not called. |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
576 * Note: caller must check 'emsg_not_now()' before calling this. |
7 | 577 */ |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
578 static int |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
579 emsg_core(char_u *s) |
7 | 580 { |
581 int attr; | |
582 char_u *p; | |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
583 int r; |
7 | 584 #ifdef FEAT_EVAL |
585 int ignore = FALSE; | |
586 int severe; | |
587 #endif | |
588 | |
11006
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
589 #ifdef FEAT_EVAL |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
590 /* When testing some errors are turned into a normal message. */ |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
591 if (ignore_error(s)) |
11012
ae2de10e8398
patch 8.0.0395: testing the + register fails with Motif
Christian Brabandt <cb@256bit.org>
parents:
11006
diff
changeset
|
592 /* don't call msg() if it results in a dialog */ |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
593 return msg_use_printf() ? FALSE : msg((char *)s); |
11006
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
594 #endif |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
595 |
7 | 596 called_emsg = TRUE; |
597 | |
598 #ifdef FEAT_EVAL | |
12375
ab0d827151a1
patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents:
12152
diff
changeset
|
599 /* If "emsg_severe" is TRUE: When an error exception is to be thrown, |
ab0d827151a1
patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents:
12152
diff
changeset
|
600 * prefer this message over previous messages for the same command. */ |
7 | 601 severe = emsg_severe; |
602 emsg_severe = FALSE; | |
603 #endif | |
604 | |
839 | 605 if (!emsg_off || vim_strchr(p_debug, 't') != NULL) |
7 | 606 { |
607 #ifdef FEAT_EVAL | |
608 /* | |
609 * Cause a throw of an error exception if appropriate. Don't display | |
610 * the error message in this case. (If no matching catch clause will | |
611 * be found, the message will be displayed later on.) "ignore" is set | |
612 * when the message should be ignored completely (used for the | |
613 * interrupt message). | |
614 */ | |
615 if (cause_errthrow(s, severe, &ignore) == TRUE) | |
616 { | |
617 if (!ignore) | |
15079
a527110d5f56
patch 8.1.0550: expression evaluation may repeat an error message
Bram Moolenaar <Bram@vim.org>
parents:
14909
diff
changeset
|
618 ++did_emsg; |
7 | 619 return TRUE; |
620 } | |
621 | |
622 /* set "v:errmsg", also when using ":silent! cmd" */ | |
623 set_vim_var_string(VV_ERRMSG, s, -1); | |
624 #endif | |
625 | |
626 /* | |
1619 | 627 * When using ":silent! cmd" ignore error messages. |
7 | 628 * But do write it to the redirection file. |
629 */ | |
630 if (emsg_silent != 0) | |
631 { | |
9454
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
632 if (emsg_noredir == 0) |
7 | 633 { |
9454
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
634 msg_start(); |
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
635 p = get_emsg_source(); |
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
636 if (p != NULL) |
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
637 { |
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
638 STRCAT(p, "\n"); |
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
639 redir_write(p, -1); |
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
640 vim_free(p); |
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
641 } |
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
642 p = get_emsg_lnum(); |
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
643 if (p != NULL) |
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
644 { |
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
645 STRCAT(p, "\n"); |
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
646 redir_write(p, -1); |
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
647 vim_free(p); |
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
648 } |
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
649 redir_write(s, -1); |
7 | 650 } |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
651 #ifdef FEAT_JOB_CHANNEL |
17262
041156ce1d22
patch 8.1.1630: various small problems
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
652 ch_log(NULL, "ERROR silent: %s", (char *)s); |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
653 #endif |
7 | 654 return TRUE; |
655 } | |
656 | |
10589
b0c9c1a05054
patch 8.0.0184: when an error is caught Vim still exits with non-zero result
Christian Brabandt <cb@256bit.org>
parents:
10426
diff
changeset
|
657 ex_exitval = 1; |
b0c9c1a05054
patch 8.0.0184: when an error is caught Vim still exits with non-zero result
Christian Brabandt <cb@256bit.org>
parents:
10426
diff
changeset
|
658 |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12375
diff
changeset
|
659 /* Reset msg_silent, an error causes messages to be switched back on. |
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12375
diff
changeset
|
660 */ |
7 | 661 msg_silent = 0; |
662 cmd_silent = FALSE; | |
663 | |
664 if (global_busy) /* break :global command */ | |
665 ++global_busy; | |
666 | |
667 if (p_eb) | |
668 beep_flush(); /* also includes flush_buffers() */ | |
669 else | |
14909
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
670 flush_buffers(FLUSH_MINIMAL); // flush internal buffers |
15079
a527110d5f56
patch 8.1.0550: expression evaluation may repeat an error message
Bram Moolenaar <Bram@vim.org>
parents:
14909
diff
changeset
|
671 ++did_emsg; // flag for DoOneCmd() |
12375
ab0d827151a1
patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents:
12152
diff
changeset
|
672 #ifdef FEAT_EVAL |
ab0d827151a1
patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents:
12152
diff
changeset
|
673 did_uncaught_emsg = TRUE; |
ab0d827151a1
patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents:
12152
diff
changeset
|
674 #endif |
7 | 675 } |
676 | |
677 emsg_on_display = TRUE; /* remember there is an error message */ | |
678 ++msg_scroll; /* don't overwrite a previous message */ | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
679 attr = HL_ATTR(HLF_E); /* set highlight mode for error messages */ |
539 | 680 if (msg_scrolled != 0) |
7 | 681 need_wait_return = TRUE; /* needed in case emsg() is called after |
682 * wait_return has reset need_wait_return | |
683 * and a redraw is expected because | |
684 * msg_scrolled is non-zero */ | |
685 | |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
686 #ifdef FEAT_JOB_CHANNEL |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
687 emsg_to_channel_log = TRUE; |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
688 #endif |
7 | 689 /* |
690 * Display name and line number for the source of the error. | |
691 */ | |
16 | 692 msg_source(attr); |
7 | 693 |
694 /* | |
695 * Display the error message itself. | |
696 */ | |
16 | 697 msg_nowait = FALSE; /* wait for this msg */ |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
698 r = msg_attr((char *)s, attr); |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
699 |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
700 #ifdef FEAT_JOB_CHANNEL |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
701 emsg_to_channel_log = FALSE; |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
702 #endif |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
703 return r; |
7 | 704 } |
705 | |
706 /* | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
707 * Print an error message. |
7 | 708 */ |
709 int | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
710 emsg(char *s) |
7 | 711 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
712 /* Skip this if not giving error messages at the moment. */ |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
713 if (!emsg_not_now()) |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
714 return emsg_core((char_u *)s); |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
715 return TRUE; /* no error messages at the moment */ |
7 | 716 } |
717 | |
15896
ac080f6a4db8
patch 8.1.0954: arguments of semsg() and siemsg() are not checked
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
718 #ifndef PROTO // manual proto with __attribute__ |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
719 /* |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
720 * Print an error message with format string and variable arguments. |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
721 * Note: caller must not pass 'IObuff' as 1st argument. |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
722 */ |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
723 int |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
724 semsg(const char *s, ...) |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
725 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
726 /* Skip this if not giving error messages at the moment. */ |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
727 if (!emsg_not_now()) |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
728 { |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
729 va_list ap; |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
730 |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
731 va_start(ap, s); |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
732 vim_vsnprintf((char *)IObuff, IOSIZE, s, ap); |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
733 va_end(ap); |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
734 return emsg_core(IObuff); |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
735 } |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
736 return TRUE; /* no error messages at the moment */ |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
737 } |
15896
ac080f6a4db8
patch 8.1.0954: arguments of semsg() and siemsg() are not checked
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
738 #endif |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
739 |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
740 /* |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
741 * Same as emsg(...), but abort on error when ABORT_ON_INTERNAL_ERROR is |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
742 * defined. It is used for internal errors only, so that they can be |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
743 * detected when fuzzing vim. |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
744 */ |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
745 void |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
746 iemsg(char *s) |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
747 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
748 if (!emsg_not_now()) |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
749 emsg_core((char_u *)s); |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
750 #ifdef ABORT_ON_INTERNAL_ERROR |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
751 abort(); |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
752 #endif |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
753 } |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
754 |
15896
ac080f6a4db8
patch 8.1.0954: arguments of semsg() and siemsg() are not checked
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
755 #ifndef PROTO // manual proto with __attribute__ |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
756 /* |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
757 * Same as semsg(...) but abort on error when ABORT_ON_INTERNAL_ERROR is |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
758 * defined. It is used for internal errors only, so that they can be |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
759 * detected when fuzzing vim. |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
760 * Note: caller must not pass 'IObuff' as 1st argument. |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
761 */ |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
762 void |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
763 siemsg(const char *s, ...) |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
764 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
765 if (!emsg_not_now()) |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
766 { |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
767 va_list ap; |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
768 |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
769 va_start(ap, s); |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
770 vim_vsnprintf((char *)IObuff, IOSIZE, s, ap); |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
771 va_end(ap); |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
772 emsg_core(IObuff); |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
773 } |
15896
ac080f6a4db8
patch 8.1.0954: arguments of semsg() and siemsg() are not checked
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
774 # ifdef ABORT_ON_INTERNAL_ERROR |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
775 abort(); |
15896
ac080f6a4db8
patch 8.1.0954: arguments of semsg() and siemsg() are not checked
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
776 # endif |
ac080f6a4db8
patch 8.1.0954: arguments of semsg() and siemsg() are not checked
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
777 } |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
778 #endif |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
779 |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
780 /* |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
781 * Give an "Internal error" message. |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
782 */ |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
783 void |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
784 internal_error(char *where) |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
785 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
786 siemsg(_(e_intern2), where); |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
787 } |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
788 |
330 | 789 /* emsg3() and emsgn() are in misc2.c to avoid warnings for the prototypes. */ |
7 | 790 |
167 | 791 void |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
792 emsg_invreg(int name) |
167 | 793 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
794 semsg(_("E354: Invalid register name: '%s'"), transchar(name)); |
167 | 795 } |
796 | |
7 | 797 /* |
798 * Like msg(), but truncate to a single line if p_shm contains 't', or when | |
799 * "force" is TRUE. This truncates in another way as for normal messages. | |
800 * Careful: The string may be changed by msg_may_trunc()! | |
801 * Returns a pointer to the printed message, if wait_return() not called. | |
802 */ | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
803 char * |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
804 msg_trunc_attr(char *s, int force, int attr) |
7 | 805 { |
806 int n; | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
807 char *ts; |
7 | 808 |
809 /* Add message to history before truncating */ | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
810 add_msg_hist((char_u *)s, -1, attr); |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
811 |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
812 ts = (char *)msg_may_trunc(force, (char_u *)s); |
7 | 813 |
814 msg_hist_off = TRUE; | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
815 n = msg_attr(ts, attr); |
7 | 816 msg_hist_off = FALSE; |
817 | |
818 if (n) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
819 return ts; |
7 | 820 return NULL; |
821 } | |
822 | |
823 /* | |
824 * Check if message "s" should be truncated at the start (for filenames). | |
825 * Return a pointer to where the truncated message starts. | |
826 * Note: May change the message by replacing a character with '<'. | |
827 */ | |
828 char_u * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
829 msg_may_trunc(int force, char_u *s) |
7 | 830 { |
831 int n; | |
832 int room; | |
833 | |
834 room = (int)(Rows - cmdline_row - 1) * Columns + sc_col - 1; | |
835 if ((force || (shortmess(SHM_TRUNC) && !exmode_active)) | |
836 && (n = (int)STRLEN(s) - room) > 0) | |
837 { | |
838 if (has_mbyte) | |
839 { | |
840 int size = vim_strsize(s); | |
841 | |
615 | 842 /* There may be room anyway when there are multibyte chars. */ |
843 if (size <= room) | |
844 return s; | |
845 | |
7 | 846 for (n = 0; size >= room; ) |
847 { | |
848 size -= (*mb_ptr2cells)(s + n); | |
474 | 849 n += (*mb_ptr2len)(s + n); |
7 | 850 } |
851 --n; | |
852 } | |
853 s += n; | |
854 *s = '<'; | |
855 } | |
856 return s; | |
857 } | |
858 | |
859 static void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
860 add_msg_hist( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
861 char_u *s, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
862 int len, /* -1 for undetermined length */ |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
863 int attr) |
7 | 864 { |
865 struct msg_hist *p; | |
866 | |
867 if (msg_hist_off || msg_silent != 0) | |
868 return; | |
869 | |
870 /* Don't let the message history get too big */ | |
625 | 871 while (msg_hist_len > MAX_MSG_HIST_LEN) |
355 | 872 (void)delete_first_msg(); |
873 | |
7 | 874 /* allocate an entry and add the message at the end of the history */ |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
875 p = ALLOC_ONE(struct msg_hist); |
7 | 876 if (p != NULL) |
877 { | |
878 if (len < 0) | |
879 len = (int)STRLEN(s); | |
880 /* remove leading and trailing newlines */ | |
881 while (len > 0 && *s == '\n') | |
882 { | |
883 ++s; | |
884 --len; | |
885 } | |
886 while (len > 0 && s[len - 1] == '\n') | |
887 --len; | |
888 p->msg = vim_strnsave(s, len); | |
889 p->next = NULL; | |
890 p->attr = attr; | |
891 if (last_msg_hist != NULL) | |
892 last_msg_hist->next = p; | |
893 last_msg_hist = p; | |
894 if (first_msg_hist == NULL) | |
895 first_msg_hist = last_msg_hist; | |
896 ++msg_hist_len; | |
897 } | |
898 } | |
899 | |
900 /* | |
355 | 901 * Delete the first (oldest) message from the history. |
902 * Returns FAIL if there are no messages. | |
903 */ | |
904 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
905 delete_first_msg(void) |
355 | 906 { |
907 struct msg_hist *p; | |
908 | |
909 if (msg_hist_len <= 0) | |
910 return FAIL; | |
911 p = first_msg_hist; | |
912 first_msg_hist = p->next; | |
1619 | 913 if (first_msg_hist == NULL) |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
914 last_msg_hist = NULL; /* history is empty */ |
355 | 915 vim_free(p->msg); |
916 vim_free(p); | |
917 --msg_hist_len; | |
918 return OK; | |
919 } | |
920 | |
921 /* | |
7 | 922 * ":messages" command. |
923 */ | |
924 void | |
8901
b4dad96ade29
commit https://github.com/vim/vim/commit/52196b2dbe3b64b5054e1df3d3aa8fc65e30addc
Christian Brabandt <cb@256bit.org>
parents:
8897
diff
changeset
|
925 ex_messages(exarg_T *eap) |
7 | 926 { |
927 struct msg_hist *p; | |
928 char_u *s; | |
8897
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
929 int c = 0; |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
930 |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
931 if (STRCMP(eap->arg, "clear") == 0) |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
932 { |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
933 int keep = eap->addr_count == 0 ? 0 : eap->line2; |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
934 |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
935 while (msg_hist_len > keep) |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
936 (void)delete_first_msg(); |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
937 return; |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
938 } |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
939 |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
940 if (*eap->arg != NUL) |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
941 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
942 emsg(_(e_invarg)); |
8897
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
943 return; |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
944 } |
7 | 945 |
946 msg_hist_off = TRUE; | |
947 | |
8897
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
948 p = first_msg_hist; |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
949 if (eap->addr_count != 0) |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
950 { |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
951 /* Count total messages */ |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
952 for (; p != NULL && !got_int; p = p->next) |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
953 c++; |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
954 |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
955 c -= eap->line2; |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
956 |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
957 /* Skip without number of messages specified */ |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
958 for (p = first_msg_hist; p != NULL && !got_int && c > 0; |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
959 p = p->next, c--); |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
960 } |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
961 |
8905
9200836eee15
commit https://github.com/vim/vim/commit/bea1ede1c59a11ca5bf9d91cd30b7b2937b9fb41
Christian Brabandt <cb@256bit.org>
parents:
8901
diff
changeset
|
962 if (p == first_msg_hist) |
9200836eee15
commit https://github.com/vim/vim/commit/bea1ede1c59a11ca5bf9d91cd30b7b2937b9fb41
Christian Brabandt <cb@256bit.org>
parents:
8901
diff
changeset
|
963 { |
9200836eee15
commit https://github.com/vim/vim/commit/bea1ede1c59a11ca5bf9d91cd30b7b2937b9fb41
Christian Brabandt <cb@256bit.org>
parents:
8901
diff
changeset
|
964 s = mch_getenv((char_u *)"LANG"); |
9200836eee15
commit https://github.com/vim/vim/commit/bea1ede1c59a11ca5bf9d91cd30b7b2937b9fb41
Christian Brabandt <cb@256bit.org>
parents:
8901
diff
changeset
|
965 if (s != NULL && *s != NUL) |
14210
1681178c4434
patch 8.1.0122: translators don't always understand the maintainer message
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
966 // The next comment is extracted by xgettext and put in po file for |
1681178c4434
patch 8.1.0122: translators don't always understand the maintainer message
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
967 // translators to read. |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
968 msg_attr( |
14210
1681178c4434
patch 8.1.0122: translators don't always understand the maintainer message
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
969 // Translator: Please replace the name and email address |
1681178c4434
patch 8.1.0122: translators don't always understand the maintainer message
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
970 // with the appropriate text for your translation. |
8905
9200836eee15
commit https://github.com/vim/vim/commit/bea1ede1c59a11ca5bf9d91cd30b7b2937b9fb41
Christian Brabandt <cb@256bit.org>
parents:
8901
diff
changeset
|
971 _("Messages maintainer: Bram Moolenaar <Bram@vim.org>"), |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
972 HL_ATTR(HLF_T)); |
8905
9200836eee15
commit https://github.com/vim/vim/commit/bea1ede1c59a11ca5bf9d91cd30b7b2937b9fb41
Christian Brabandt <cb@256bit.org>
parents:
8901
diff
changeset
|
973 } |
9200836eee15
commit https://github.com/vim/vim/commit/bea1ede1c59a11ca5bf9d91cd30b7b2937b9fb41
Christian Brabandt <cb@256bit.org>
parents:
8901
diff
changeset
|
974 |
8897
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
975 /* Display what was not skipped. */ |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
976 for (; p != NULL && !got_int; p = p->next) |
7 | 977 if (p->msg != NULL) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
978 msg_attr((char *)p->msg, p->attr); |
7 | 979 |
980 msg_hist_off = FALSE; | |
981 } | |
982 | |
28 | 983 #if defined(FEAT_CON_DIALOG) || defined(FIND_REPLACE_DIALOG) || defined(PROTO) |
7 | 984 /* |
985 * Call this after prompting the user. This will avoid a hit-return message | |
986 * and a delay. | |
987 */ | |
28 | 988 void |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
989 msg_end_prompt(void) |
7 | 990 { |
991 need_wait_return = FALSE; | |
992 emsg_on_display = FALSE; | |
993 cmdline_row = msg_row; | |
994 msg_col = 0; | |
995 msg_clr_eos(); | |
3240 | 996 lines_left = -1; |
7 | 997 } |
998 #endif | |
999 | |
1000 /* | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1001 * Wait for the user to hit a key (normally Enter). |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1002 * If "redraw" is TRUE, clear and redraw the screen. |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1003 * If "redraw" is FALSE, just redraw the screen. |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1004 * If "redraw" is -1, don't redraw at all. |
7 | 1005 */ |
1006 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1007 wait_return(int redraw) |
7 | 1008 { |
1009 int c; | |
1010 int oldState; | |
1011 int tmpState; | |
1012 int had_got_int; | |
14004
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13802
diff
changeset
|
1013 int save_reg_recording; |
5430 | 1014 FILE *save_scriptout; |
7 | 1015 |
1016 if (redraw == TRUE) | |
1017 must_redraw = CLEAR; | |
1018 | |
1019 /* If using ":silent cmd", don't wait for a return. Also don't set | |
1020 * need_wait_return to do it later. */ | |
1021 if (msg_silent != 0) | |
1022 return; | |
1023 | |
2723 | 1024 /* |
1025 * When inside vgetc(), we can't wait for a typed character at all. | |
1026 * With the global command (and some others) we only need one return at | |
1027 * the end. Adjust cmdline_row to avoid the next message overwriting the | |
1028 * last one. | |
1029 */ | |
822 | 1030 if (vgetc_busy > 0) |
7 | 1031 return; |
2723 | 1032 need_wait_return = TRUE; |
7 | 1033 if (no_wait_return) |
1034 { | |
1035 if (!exmode_active) | |
1036 cmdline_row = msg_row; | |
1037 return; | |
1038 } | |
1039 | |
1040 redir_off = TRUE; /* don't redirect this message */ | |
1041 oldState = State; | |
1042 if (quit_more) | |
1043 { | |
1044 c = CAR; /* just pretend CR was hit */ | |
1045 quit_more = FALSE; | |
1046 got_int = FALSE; | |
1047 } | |
1048 else if (exmode_active) | |
1049 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1050 msg_puts(" "); /* make sure the cursor is on the right line */ |
7 | 1051 c = CAR; /* no need for a return in ex mode */ |
1052 got_int = FALSE; | |
1053 } | |
1054 else | |
1055 { | |
1056 /* Make sure the hit-return prompt is on screen when 'guioptions' was | |
1057 * just changed. */ | |
1058 screenalloc(FALSE); | |
1059 | |
1060 State = HITRETURN; | |
1061 setmouse(); | |
1062 #ifdef USE_ON_FLY_SCROLL | |
1063 dont_scroll = TRUE; /* disallow scrolling here */ | |
1064 #endif | |
8627
7c98c5d0298c
commit https://github.com/vim/vim/commit/bfb96c047b79b2aab5fd57a2472871508819f3ef
Christian Brabandt <cb@256bit.org>
parents:
8289
diff
changeset
|
1065 cmdline_row = msg_row; |
7c98c5d0298c
commit https://github.com/vim/vim/commit/bfb96c047b79b2aab5fd57a2472871508819f3ef
Christian Brabandt <cb@256bit.org>
parents:
8289
diff
changeset
|
1066 |
4325 | 1067 /* Avoid the sequence that the user types ":" at the hit-return prompt |
1068 * to start an Ex command, but the file-changed dialog gets in the | |
1069 * way. */ | |
1070 if (need_check_timestamps) | |
1071 check_timestamps(FALSE); | |
1072 | |
7 | 1073 hit_return_msg(); |
1074 | |
1075 do | |
1076 { | |
1077 /* Remember "got_int", if it is set vgetc() probably returns a | |
1078 * CTRL-C, but we need to loop then. */ | |
1079 had_got_int = got_int; | |
280 | 1080 |
1081 /* Don't do mappings here, we put the character back in the | |
1082 * typeahead buffer. */ | |
1083 ++no_mapping; | |
1084 ++allow_keys; | |
5430 | 1085 |
1086 /* Temporarily disable Recording. If Recording is active, the | |
1087 * character will be recorded later, since it will be added to the | |
1088 * typebuf after the loop */ | |
14004
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13802
diff
changeset
|
1089 save_reg_recording = reg_recording; |
5430 | 1090 save_scriptout = scriptout; |
14004
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13802
diff
changeset
|
1091 reg_recording = 0; |
5430 | 1092 scriptout = NULL; |
7 | 1093 c = safe_vgetc(); |
216 | 1094 if (had_got_int && !global_busy) |
7 | 1095 got_int = FALSE; |
280 | 1096 --no_mapping; |
1097 --allow_keys; | |
14004
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13802
diff
changeset
|
1098 reg_recording = save_reg_recording; |
5430 | 1099 scriptout = save_scriptout; |
280 | 1100 |
7 | 1101 #ifdef FEAT_CLIPBOARD |
1102 /* Strange way to allow copying (yanking) a modeless selection at | |
1103 * the hit-enter prompt. Use CTRL-Y, because the same is used in | |
1104 * Cmdline-mode and it's harmless when there is no selection. */ | |
1105 if (c == Ctrl_Y && clip_star.state == SELECT_DONE) | |
1106 { | |
1107 clip_copy_modeless_selection(TRUE); | |
1108 c = K_IGNORE; | |
1109 } | |
1110 #endif | |
1381 | 1111 |
698 | 1112 /* |
1113 * Allow scrolling back in the messages. | |
1114 * Also accept scroll-down commands when messages fill the screen, | |
1115 * to avoid that typing one 'j' too many makes the messages | |
1116 * disappear. | |
1117 */ | |
1118 if (p_more && !p_cp) | |
446 | 1119 { |
4234 | 1120 if (c == 'b' || c == 'k' || c == 'u' || c == 'g' |
1121 || c == K_UP || c == K_PAGEUP) | |
446 | 1122 { |
4234 | 1123 if (msg_scrolled > Rows) |
1124 /* scroll back to show older messages */ | |
1125 do_more_prompt(c); | |
1126 else | |
1127 { | |
1128 msg_didout = FALSE; | |
1129 c = K_IGNORE; | |
1130 msg_col = | |
1131 #ifdef FEAT_RIGHTLEFT | |
1132 cmdmsg_rl ? Columns - 1 : | |
1133 #endif | |
1134 0; | |
1135 } | |
698 | 1136 if (quit_more) |
1137 { | |
1138 c = CAR; /* just pretend CR was hit */ | |
1139 quit_more = FALSE; | |
1140 got_int = FALSE; | |
1141 } | |
5290
059c8a4b103f
updated for version 7.4b.021
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
1142 else if (c != K_IGNORE) |
698 | 1143 { |
1144 c = K_IGNORE; | |
1145 hit_return_msg(); | |
1146 } | |
446 | 1147 } |
698 | 1148 else if (msg_scrolled > Rows - 2 |
4234 | 1149 && (c == 'j' || c == 'd' || c == 'f' |
1150 || c == K_DOWN || c == K_PAGEDOWN)) | |
446 | 1151 c = K_IGNORE; |
1152 } | |
7 | 1153 } while ((had_got_int && c == Ctrl_C) |
1154 || c == K_IGNORE | |
1155 #ifdef FEAT_GUI | |
1156 || c == K_VER_SCROLLBAR || c == K_HOR_SCROLLBAR | |
1157 #endif | |
1158 #ifdef FEAT_MOUSE | |
1159 || c == K_LEFTDRAG || c == K_LEFTRELEASE | |
1160 || c == K_MIDDLEDRAG || c == K_MIDDLERELEASE | |
1161 || c == K_RIGHTDRAG || c == K_RIGHTRELEASE | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1162 || c == K_MOUSELEFT || c == K_MOUSERIGHT |
7 | 1163 || c == K_MOUSEDOWN || c == K_MOUSEUP |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
1164 || c == K_MOUSEMOVE |
7 | 1165 || (!mouse_has(MOUSE_RETURN) |
1166 && mouse_row < msg_row | |
1167 && (c == K_LEFTMOUSE | |
1168 || c == K_MIDDLEMOUSE | |
1169 || c == K_RIGHTMOUSE | |
1170 || c == K_X1MOUSE | |
1171 || c == K_X2MOUSE)) | |
1172 #endif | |
1173 ); | |
1174 ui_breakcheck(); | |
1175 #ifdef FEAT_MOUSE | |
1176 /* | |
1177 * Avoid that the mouse-up event causes visual mode to start. | |
1178 */ | |
1179 if (c == K_LEFTMOUSE || c == K_MIDDLEMOUSE || c == K_RIGHTMOUSE | |
1180 || c == K_X1MOUSE || c == K_X2MOUSE) | |
1181 (void)jump_to_mouse(MOUSE_SETPOS, NULL, 0); | |
1182 else | |
1183 #endif | |
1184 if (vim_strchr((char_u *)"\r\n ", c) == NULL && c != Ctrl_C) | |
1185 { | |
280 | 1186 /* Put the character back in the typeahead buffer. Don't use the |
1187 * stuff buffer, because lmaps wouldn't work. */ | |
852 | 1188 ins_char_typebuf(c); |
7 | 1189 do_redraw = TRUE; /* need a redraw even though there is |
280 | 1190 typeahead */ |
7 | 1191 } |
1192 } | |
1193 redir_off = FALSE; | |
1194 | |
1195 /* | |
1196 * If the user hits ':', '?' or '/' we get a command line from the next | |
1197 * line. | |
1198 */ | |
1199 if (c == ':' || c == '?' || c == '/') | |
1200 { | |
1201 if (!exmode_active) | |
1202 cmdline_row = msg_row; | |
1203 skip_redraw = TRUE; /* skip redraw once */ | |
1204 do_redraw = FALSE; | |
14129
cb731d098241
patch 8.1.0082: in terminal window, typing : at more prompt, inserts ':'
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1205 #ifdef FEAT_TERMINAL |
cb731d098241
patch 8.1.0082: in terminal window, typing : at more prompt, inserts ':'
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1206 skip_term_loop = TRUE; |
cb731d098241
patch 8.1.0082: in terminal window, typing : at more prompt, inserts ':'
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1207 #endif |
7 | 1208 } |
1209 | |
1210 /* | |
1211 * If the window size changed set_shellsize() will redraw the screen. | |
1212 * Otherwise the screen is only redrawn if 'redraw' is set and no ':' | |
1213 * typed. | |
1214 */ | |
1215 tmpState = State; | |
1216 State = oldState; /* restore State before set_shellsize */ | |
1217 setmouse(); | |
1218 msg_check(); | |
1219 | |
1220 #if defined(UNIX) || defined(VMS) | |
1221 /* | |
1222 * When switching screens, we need to output an extra newline on exit. | |
1223 */ | |
1224 if (swapping_screen() && !termcap_active) | |
1225 newline_on_exit = TRUE; | |
1226 #endif | |
1227 | |
1228 need_wait_return = FALSE; | |
1229 did_wait_return = TRUE; | |
1230 emsg_on_display = FALSE; /* can delete error message now */ | |
1231 lines_left = -1; /* reset lines_left at next msg_start() */ | |
1232 reset_last_sourcing(); | |
1233 if (keep_msg != NULL && vim_strsize(keep_msg) >= | |
1234 (Rows - cmdline_row - 1) * Columns + sc_col) | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13188
diff
changeset
|
1235 VIM_CLEAR(keep_msg); /* don't redisplay message, it's too long */ |
7 | 1236 |
1237 if (tmpState == SETWSIZE) /* got resize event while in vgetc() */ | |
1238 { | |
1239 starttermcap(); /* start termcap before redrawing */ | |
1240 shell_resized(); | |
1241 } | |
1242 else if (!skip_redraw | |
1243 && (redraw == TRUE || (msg_scrolled != 0 && redraw != -1))) | |
1244 { | |
1245 starttermcap(); /* start termcap before redrawing */ | |
1246 redraw_later(VALID); | |
1247 } | |
1248 } | |
1249 | |
1250 /* | |
1251 * Write the hit-return prompt. | |
1252 */ | |
1253 static void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1254 hit_return_msg(void) |
7 | 1255 { |
446 | 1256 int save_p_more = p_more; |
1257 | |
1258 p_more = FALSE; /* don't want see this message when scrolling back */ | |
1259 if (msg_didout) /* start on a new line */ | |
7 | 1260 msg_putchar('\n'); |
1261 if (got_int) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1262 msg_puts(_("Interrupt: ")); |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1263 |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1264 msg_puts_attr(_("Press ENTER or type command to continue"), HL_ATTR(HLF_R)); |
7 | 1265 if (!msg_use_printf()) |
1266 msg_clr_eos(); | |
446 | 1267 p_more = save_p_more; |
7 | 1268 } |
1269 | |
1270 /* | |
1271 * Set "keep_msg" to "s". Free the old value and check for NULL pointer. | |
1272 */ | |
1273 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1274 set_keep_msg(char_u *s, int attr) |
7 | 1275 { |
1276 vim_free(keep_msg); | |
1277 if (s != NULL && msg_silent == 0) | |
1278 keep_msg = vim_strsave(s); | |
1279 else | |
1280 keep_msg = NULL; | |
127 | 1281 keep_msg_more = FALSE; |
678 | 1282 keep_msg_attr = attr; |
7 | 1283 } |
1284 | |
678 | 1285 #if defined(FEAT_TERMRESPONSE) || defined(PROTO) |
1286 /* | |
1287 * If there currently is a message being displayed, set "keep_msg" to it, so | |
1288 * that it will be displayed again after redraw. | |
1289 */ | |
1290 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1291 set_keep_msg_from_hist(void) |
678 | 1292 { |
1293 if (keep_msg == NULL && last_msg_hist != NULL && msg_scrolled == 0 | |
1294 && (State & NORMAL)) | |
1295 set_keep_msg(last_msg_hist->msg, last_msg_hist->attr); | |
1296 } | |
1297 #endif | |
1298 | |
7 | 1299 /* |
1300 * Prepare for outputting characters in the command line. | |
1301 */ | |
1302 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1303 msg_start(void) |
7 | 1304 { |
1305 int did_return = FALSE; | |
1306 | |
2491
904cd1c26a1e
After entering a crypt key would need to hit return to continue.
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
1307 if (!msg_silent) |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13188
diff
changeset
|
1308 VIM_CLEAR(keep_msg); |
1619 | 1309 |
1310 #ifdef FEAT_EVAL | |
1311 if (need_clr_eos) | |
1312 { | |
1313 /* Halfway an ":echo" command and getting an (error) message: clear | |
1314 * any text from the command. */ | |
1315 need_clr_eos = FALSE; | |
1316 msg_clr_eos(); | |
1317 } | |
1318 #endif | |
1319 | |
7 | 1320 if (!msg_scroll && full_screen) /* overwrite last message */ |
1321 { | |
1322 msg_row = cmdline_row; | |
1323 msg_col = | |
1324 #ifdef FEAT_RIGHTLEFT | |
1325 cmdmsg_rl ? Columns - 1 : | |
1326 #endif | |
1327 0; | |
1328 } | |
1329 else if (msg_didout) /* start message on next line */ | |
1330 { | |
1331 msg_putchar('\n'); | |
1332 did_return = TRUE; | |
1333 if (exmode_active != EXMODE_NORMAL) | |
1334 cmdline_row = msg_row; | |
1335 } | |
1336 if (!msg_didany || lines_left < 0) | |
1337 msg_starthere(); | |
1338 if (msg_silent == 0) | |
1339 { | |
1340 msg_didout = FALSE; /* no output on current line yet */ | |
1341 cursor_off(); | |
1342 } | |
1343 | |
1344 /* when redirecting, may need to start a new line. */ | |
1345 if (!did_return) | |
1346 redir_write((char_u *)"\n", -1); | |
1347 } | |
1348 | |
1349 /* | |
1350 * Note that the current msg position is where messages start. | |
1351 */ | |
1352 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1353 msg_starthere(void) |
7 | 1354 { |
1355 lines_left = cmdline_row; | |
1356 msg_didany = FALSE; | |
1357 } | |
1358 | |
1359 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1360 msg_putchar(int c) |
7 | 1361 { |
1362 msg_putchar_attr(c, 0); | |
1363 } | |
1364 | |
1365 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1366 msg_putchar_attr(int c, int attr) |
7 | 1367 { |
15551
b069a878bbeb
patch 8.1.0783: compiler warning for signed/unsigned
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1368 char_u buf[MB_MAXBYTES + 1]; |
7 | 1369 |
1370 if (IS_SPECIAL(c)) | |
1371 { | |
1372 buf[0] = K_SPECIAL; | |
1373 buf[1] = K_SECOND(c); | |
1374 buf[2] = K_THIRD(c); | |
1375 buf[3] = NUL; | |
1376 } | |
1377 else | |
15551
b069a878bbeb
patch 8.1.0783: compiler warning for signed/unsigned
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1378 buf[(*mb_char2bytes)(c, buf)] = NUL; |
b069a878bbeb
patch 8.1.0783: compiler warning for signed/unsigned
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1379 msg_puts_attr((char *)buf, attr); |
7 | 1380 } |
1381 | |
1382 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1383 msg_outnum(long n) |
7 | 1384 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1385 char buf[20]; |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1386 |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1387 sprintf(buf, "%ld", n); |
7 | 1388 msg_puts(buf); |
1389 } | |
1390 | |
1391 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1392 msg_home_replace(char_u *fname) |
7 | 1393 { |
1394 msg_home_replace_attr(fname, 0); | |
1395 } | |
1396 | |
1397 #if defined(FEAT_FIND_ID) || defined(PROTO) | |
1398 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1399 msg_home_replace_hl(char_u *fname) |
7 | 1400 { |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
1401 msg_home_replace_attr(fname, HL_ATTR(HLF_D)); |
7 | 1402 } |
1403 #endif | |
1404 | |
1405 static void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1406 msg_home_replace_attr(char_u *fname, int attr) |
7 | 1407 { |
1408 char_u *name; | |
1409 | |
1410 name = home_replace_save(NULL, fname); | |
1411 if (name != NULL) | |
1412 msg_outtrans_attr(name, attr); | |
1413 vim_free(name); | |
1414 } | |
1415 | |
1416 /* | |
1417 * Output 'len' characters in 'str' (including NULs) with translation | |
1418 * if 'len' is -1, output upto a NUL character. | |
1419 * Use attributes 'attr'. | |
1420 * Return the number of characters it takes on the screen. | |
1421 */ | |
1422 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1423 msg_outtrans(char_u *str) |
7 | 1424 { |
1425 return msg_outtrans_attr(str, 0); | |
1426 } | |
1427 | |
1428 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1429 msg_outtrans_attr(char_u *str, int attr) |
7 | 1430 { |
1431 return msg_outtrans_len_attr(str, (int)STRLEN(str), attr); | |
1432 } | |
1433 | |
1434 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1435 msg_outtrans_len(char_u *str, int len) |
7 | 1436 { |
1437 return msg_outtrans_len_attr(str, len, 0); | |
1438 } | |
1439 | |
1440 /* | |
1441 * Output one character at "p". Return pointer to the next character. | |
1442 * Handles multi-byte characters. | |
1443 */ | |
1444 char_u * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1445 msg_outtrans_one(char_u *p, int attr) |
7 | 1446 { |
1447 int l; | |
1448 | |
474 | 1449 if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) |
7 | 1450 { |
1451 msg_outtrans_len_attr(p, l, attr); | |
1452 return p + l; | |
1453 } | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1454 msg_puts_attr((char *)transchar_byte(*p), attr); |
7 | 1455 return p + 1; |
1456 } | |
1457 | |
1458 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1459 msg_outtrans_len_attr(char_u *msgstr, int len, int attr) |
7 | 1460 { |
1461 int retval = 0; | |
1462 char_u *str = msgstr; | |
1463 char_u *plain_start = msgstr; | |
1464 char_u *s; | |
1465 int mb_l; | |
1466 int c; | |
1467 | |
1468 /* if MSG_HIST flag set, add message to history */ | |
1469 if (attr & MSG_HIST) | |
1470 { | |
1471 add_msg_hist(str, len, attr); | |
1472 attr &= ~MSG_HIST; | |
1473 } | |
1474 | |
1475 /* If the string starts with a composing character first draw a space on | |
1476 * which the composing char can be drawn. */ | |
1477 if (enc_utf8 && utf_iscomposing(utf_ptr2char(msgstr))) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1478 msg_puts_attr(" ", attr); |
7 | 1479 |
1480 /* | |
1481 * Go over the string. Special characters are translated and printed. | |
1482 * Normal characters are printed several at a time. | |
1483 */ | |
1484 while (--len >= 0) | |
1485 { | |
1486 if (enc_utf8) | |
1487 /* Don't include composing chars after the end. */ | |
474 | 1488 mb_l = utfc_ptr2len_len(str, len + 1); |
7 | 1489 else if (has_mbyte) |
474 | 1490 mb_l = (*mb_ptr2len)(str); |
7 | 1491 else |
1492 mb_l = 1; | |
1493 if (has_mbyte && mb_l > 1) | |
1494 { | |
1495 c = (*mb_ptr2char)(str); | |
1496 if (vim_isprintc(c)) | |
1497 /* printable multi-byte char: count the cells. */ | |
1498 retval += (*mb_ptr2cells)(str); | |
1499 else | |
1500 { | |
1501 /* unprintable multi-byte char: print the printable chars so | |
1502 * far and the translation of the unprintable char. */ | |
1503 if (str > plain_start) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1504 msg_puts_attr_len((char *)plain_start, |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1505 (int)(str - plain_start), attr); |
7 | 1506 plain_start = str + mb_l; |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1507 msg_puts_attr((char *)transchar(c), |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1508 attr == 0 ? HL_ATTR(HLF_8) : attr); |
7 | 1509 retval += char2cells(c); |
1510 } | |
1511 len -= mb_l - 1; | |
1512 str += mb_l; | |
1513 } | |
1514 else | |
1515 { | |
1516 s = transchar_byte(*str); | |
1517 if (s[1] != NUL) | |
1518 { | |
1519 /* unprintable char: print the printable chars so far and the | |
1520 * translation of the unprintable char. */ | |
1521 if (str > plain_start) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1522 msg_puts_attr_len((char *)plain_start, |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1523 (int)(str - plain_start), attr); |
7 | 1524 plain_start = str + 1; |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1525 msg_puts_attr((char *)s, attr == 0 ? HL_ATTR(HLF_8) : attr); |
1668 | 1526 retval += (int)STRLEN(s); |
7 | 1527 } |
1663 | 1528 else |
1529 ++retval; | |
7 | 1530 ++str; |
1531 } | |
1532 } | |
1533 | |
1534 if (str > plain_start) | |
1535 /* print the printable chars at the end */ | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1536 msg_puts_attr_len((char *)plain_start, (int)(str - plain_start), attr); |
7 | 1537 |
1538 return retval; | |
1539 } | |
1540 | |
1541 #if defined(FEAT_QUICKFIX) || defined(PROTO) | |
1542 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1543 msg_make(char_u *arg) |
7 | 1544 { |
1545 int i; | |
1546 static char_u *str = (char_u *)"eeffoc", *rs = (char_u *)"Plon#dqg#vxjduB"; | |
1547 | |
1548 arg = skipwhite(arg); | |
1549 for (i = 5; *arg && i >= 0; --i) | |
1550 if (*arg++ != str[i]) | |
1551 break; | |
1552 if (i < 0) | |
1553 { | |
1554 msg_putchar('\n'); | |
1555 for (i = 0; rs[i]; ++i) | |
1556 msg_putchar(rs[i] - 3); | |
1557 } | |
1558 } | |
1559 #endif | |
1560 | |
1561 /* | |
1562 * Output the string 'str' upto a NUL character. | |
1563 * Return the number of characters it takes on the screen. | |
1564 * | |
1565 * If K_SPECIAL is encountered, then it is taken in conjunction with the | |
1566 * following character and shown as <F1>, <S-Up> etc. Any other character | |
1567 * which is not printable shown in <> form. | |
1568 * If 'from' is TRUE (lhs of a mapping), a space is shown as <Space>. | |
1569 * If a character is displayed in one of these special ways, is also | |
1570 * highlighted (its highlight name is '8' in the p_hl variable). | |
1571 * Otherwise characters are not highlighted. | |
1572 * This function is used to show mappings, where we want to see how to type | |
1573 * the character/string -- webb | |
1574 */ | |
1575 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1576 msg_outtrans_special( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1577 char_u *strstart, |
16393
c1c25e2523a6
patch 8.1.1201: output of :command is hard to read
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
1578 int from, // TRUE for lhs of a mapping |
c1c25e2523a6
patch 8.1.1201: output of :command is hard to read
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
1579 int maxlen) // screen columns, 0 for unlimeted |
7 | 1580 { |
1581 char_u *str = strstart; | |
1582 int retval = 0; | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1583 char *text; |
7 | 1584 int attr; |
1585 int len; | |
1586 | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
1587 attr = HL_ATTR(HLF_8); |
7 | 1588 while (*str != NUL) |
1589 { | |
1590 /* Leading and trailing spaces need to be displayed in <> form. */ | |
1591 if ((str == strstart || str[1] == NUL) && *str == ' ') | |
1592 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1593 text = "<Space>"; |
7 | 1594 ++str; |
1595 } | |
1596 else | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1597 text = (char *)str2special(&str, from); |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1598 len = vim_strsize((char_u *)text); |
16393
c1c25e2523a6
patch 8.1.1201: output of :command is hard to read
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
1599 if (maxlen > 0 && retval + len >= maxlen) |
c1c25e2523a6
patch 8.1.1201: output of :command is hard to read
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
1600 break; |
7 | 1601 /* Highlight special keys */ |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1602 msg_puts_attr(text, len > 1 |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1603 && (*mb_ptr2len)((char_u *)text) <= 1 ? attr : 0); |
7 | 1604 retval += len; |
1605 } | |
1606 return retval; | |
1607 } | |
1608 | |
2610 | 1609 #if defined(FEAT_EVAL) || defined(PROTO) |
1610 /* | |
1611 * Return the lhs or rhs of a mapping, with the key codes turned into printable | |
1612 * strings, in an allocated string. | |
1613 */ | |
1614 char_u * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1615 str2special_save( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1616 char_u *str, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1617 int is_lhs) /* TRUE for lhs, FALSE for rhs */ |
2610 | 1618 { |
1619 garray_T ga; | |
1620 char_u *p = str; | |
1621 | |
1622 ga_init2(&ga, 1, 40); | |
1623 while (*p != NUL) | |
1624 ga_concat(&ga, str2special(&p, is_lhs)); | |
1625 ga_append(&ga, NUL); | |
1626 return (char_u *)ga.ga_data; | |
1627 } | |
1628 #endif | |
1629 | |
7 | 1630 /* |
1631 * Return the printable string for the key codes at "*sp". | |
1632 * Used for translating the lhs or rhs of a mapping to printable chars. | |
1633 * Advances "sp" to the next code. | |
1634 */ | |
1635 char_u * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1636 str2special( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1637 char_u **sp, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1638 int from) /* TRUE for lhs of mapping */ |
7 | 1639 { |
1640 int c; | |
1641 static char_u buf[7]; | |
1642 char_u *str = *sp; | |
1643 int modifiers = 0; | |
1644 int special = FALSE; | |
1645 | |
1646 if (has_mbyte) | |
1647 { | |
1648 char_u *p; | |
1649 | |
1650 /* Try to un-escape a multi-byte character. Return the un-escaped | |
1651 * string if it is a multi-byte character. */ | |
1652 p = mb_unescape(sp); | |
1653 if (p != NULL) | |
1654 return p; | |
1655 } | |
1656 | |
1657 c = *str; | |
1658 if (c == K_SPECIAL && str[1] != NUL && str[2] != NUL) | |
1659 { | |
1660 if (str[1] == KS_MODIFIER) | |
1661 { | |
1662 modifiers = str[2]; | |
1663 str += 3; | |
1664 c = *str; | |
1665 } | |
1666 if (c == K_SPECIAL && str[1] != NUL && str[2] != NUL) | |
1667 { | |
1668 c = TO_SPECIAL(str[1], str[2]); | |
1669 str += 2; | |
1670 } | |
1671 if (IS_SPECIAL(c) || modifiers) /* special key */ | |
1672 special = TRUE; | |
1673 } | |
1674 | |
3024 | 1675 if (has_mbyte && !IS_SPECIAL(c)) |
7 | 1676 { |
3072 | 1677 int len = (*mb_ptr2len)(str); |
3024 | 1678 |
1679 /* For multi-byte characters check for an illegal byte. */ | |
1680 if (has_mbyte && MB_BYTE2LEN(*str) > len) | |
1681 { | |
1682 transchar_nonprint(buf, c); | |
1683 *sp = str + 1; | |
1684 return buf; | |
1685 } | |
3072 | 1686 /* Since 'special' is TRUE the multi-byte character 'c' will be |
1687 * processed by get_special_key_name() */ | |
1688 c = (*mb_ptr2char)(str); | |
1689 *sp = str + len; | |
7 | 1690 } |
3024 | 1691 else |
1692 *sp = str + 1; | |
7 | 1693 |
1694 /* Make unprintable characters in <> form, also <M-Space> and <Tab>. | |
1695 * Use <Space> only for lhs of a mapping. */ | |
1696 if (special || char2cells(c) > 1 || (from && c == ' ')) | |
1697 return get_special_key_name(c, modifiers); | |
1698 buf[0] = c; | |
1699 buf[1] = NUL; | |
1700 return buf; | |
1701 } | |
1702 | |
1703 /* | |
1704 * Translate a key sequence into special key names. | |
1705 */ | |
1706 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1707 str2specialbuf(char_u *sp, char_u *buf, int len) |
7 | 1708 { |
1709 char_u *s; | |
1710 | |
1711 *buf = NUL; | |
1712 while (*sp) | |
1713 { | |
1714 s = str2special(&sp, FALSE); | |
1715 if ((int)(STRLEN(s) + STRLEN(buf)) < len) | |
1716 STRCAT(buf, s); | |
1717 } | |
1718 } | |
1719 | |
1720 /* | |
1721 * print line for :print or :list command | |
1722 */ | |
1723 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1724 msg_prt_line(char_u *s, int list) |
7 | 1725 { |
1726 int c; | |
1727 int col = 0; | |
1728 int n_extra = 0; | |
1729 int c_extra = 0; | |
15502
bc17a9d37810
patch 8.1.0759: showing two characters for tab is limited
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1730 int c_final = 0; |
7 | 1731 char_u *p_extra = NULL; /* init to make SASC shut up */ |
1732 int n; | |
1059 | 1733 int attr = 0; |
7 | 1734 char_u *trail = NULL; |
1735 int l; | |
1736 char_u buf[MB_MAXBYTES + 1]; | |
1737 | |
167 | 1738 if (curwin->w_p_list) |
1739 list = TRUE; | |
1740 | |
7 | 1741 /* find start of trailing whitespace */ |
167 | 1742 if (list && lcs_trail) |
7 | 1743 { |
1744 trail = s + STRLEN(s); | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
1745 while (trail > s && VIM_ISWHITE(trail[-1])) |
7 | 1746 --trail; |
1747 } | |
1748 | |
1749 /* output a space for an empty line, otherwise the line will be | |
1750 * overwritten */ | |
167 | 1751 if (*s == NUL && !(list && lcs_eol != NUL)) |
7 | 1752 msg_putchar(' '); |
1753 | |
446 | 1754 while (!got_int) |
7 | 1755 { |
1059 | 1756 if (n_extra > 0) |
7 | 1757 { |
1758 --n_extra; | |
15502
bc17a9d37810
patch 8.1.0759: showing two characters for tab is limited
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1759 if (n_extra == 0 && c_final) |
bc17a9d37810
patch 8.1.0759: showing two characters for tab is limited
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1760 c = c_final; |
bc17a9d37810
patch 8.1.0759: showing two characters for tab is limited
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1761 else if (c_extra) |
7 | 1762 c = c_extra; |
1763 else | |
1764 c = *p_extra++; | |
1765 } | |
474 | 1766 else if (has_mbyte && (l = (*mb_ptr2len)(s)) > 1) |
7 | 1767 { |
1768 col += (*mb_ptr2cells)(s); | |
6801 | 1769 if (lcs_nbsp != NUL && list |
1770 && (mb_ptr2char(s) == 160 | |
1771 || mb_ptr2char(s) == 0x202f)) | |
2692 | 1772 { |
1773 mb_char2bytes(lcs_nbsp, buf); | |
1774 buf[(*mb_ptr2len)(buf)] = NUL; | |
1775 } | |
1776 else | |
1777 { | |
1778 mch_memmove(buf, s, (size_t)l); | |
1779 buf[l] = NUL; | |
1780 } | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1781 msg_puts((char *)buf); |
7 | 1782 s += l; |
1783 continue; | |
1784 } | |
1785 else | |
1786 { | |
1787 attr = 0; | |
1788 c = *s++; | |
167 | 1789 if (c == TAB && (!list || lcs_tab1)) |
7 | 1790 { |
1791 /* tab amount depends on current column */ | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14129
diff
changeset
|
1792 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14129
diff
changeset
|
1793 n_extra = tabstop_padding(col, curbuf->b_p_ts, |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14129
diff
changeset
|
1794 curbuf->b_p_vts_array) - 1; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14129
diff
changeset
|
1795 #else |
7 | 1796 n_extra = curbuf->b_p_ts - col % curbuf->b_p_ts - 1; |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14129
diff
changeset
|
1797 #endif |
167 | 1798 if (!list) |
7 | 1799 { |
1800 c = ' '; | |
1801 c_extra = ' '; | |
15502
bc17a9d37810
patch 8.1.0759: showing two characters for tab is limited
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1802 c_final = NUL; |
7 | 1803 } |
1804 else | |
1805 { | |
15502
bc17a9d37810
patch 8.1.0759: showing two characters for tab is limited
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1806 c = (n_extra == 0 && lcs_tab3) ? lcs_tab3 : lcs_tab1; |
7 | 1807 c_extra = lcs_tab2; |
15502
bc17a9d37810
patch 8.1.0759: showing two characters for tab is limited
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1808 c_final = lcs_tab3; |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
1809 attr = HL_ATTR(HLF_8); |
7 | 1810 } |
1811 } | |
2692 | 1812 else if (c == 160 && list && lcs_nbsp != NUL) |
1813 { | |
1814 c = lcs_nbsp; | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
1815 attr = HL_ATTR(HLF_8); |
2692 | 1816 } |
167 | 1817 else if (c == NUL && list && lcs_eol != NUL) |
7 | 1818 { |
1819 p_extra = (char_u *)""; | |
1820 c_extra = NUL; | |
15502
bc17a9d37810
patch 8.1.0759: showing two characters for tab is limited
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1821 c_final = NUL; |
7 | 1822 n_extra = 1; |
1823 c = lcs_eol; | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
1824 attr = HL_ATTR(HLF_AT); |
7 | 1825 --s; |
1826 } | |
1827 else if (c != NUL && (n = byte2cells(c)) > 1) | |
1828 { | |
1829 n_extra = n - 1; | |
1830 p_extra = transchar_byte(c); | |
1831 c_extra = NUL; | |
15502
bc17a9d37810
patch 8.1.0759: showing two characters for tab is limited
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1832 c_final = NUL; |
7 | 1833 c = *p_extra++; |
1059 | 1834 /* Use special coloring to be able to distinguish <hex> from |
1835 * the same in plain text. */ | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
1836 attr = HL_ATTR(HLF_8); |
7 | 1837 } |
1838 else if (c == ' ' && trail != NULL && s > trail) | |
1839 { | |
1840 c = lcs_trail; | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
1841 attr = HL_ATTR(HLF_8); |
7 | 1842 } |
6781 | 1843 else if (c == ' ' && list && lcs_space != NUL) |
1844 { | |
1845 c = lcs_space; | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
1846 attr = HL_ATTR(HLF_8); |
6781 | 1847 } |
7 | 1848 } |
1849 | |
1850 if (c == NUL) | |
1851 break; | |
1852 | |
1853 msg_putchar_attr(c, attr); | |
1854 col++; | |
1855 } | |
1856 msg_clr_eos(); | |
1857 } | |
1858 | |
1859 /* | |
1860 * Use screen_puts() to output one multi-byte character. | |
1861 * Return the pointer "s" advanced to the next character. | |
1862 */ | |
1863 static char_u * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1864 screen_puts_mbyte(char_u *s, int l, int attr) |
7 | 1865 { |
1866 int cw; | |
1867 | |
1868 msg_didout = TRUE; /* remember that line is not empty */ | |
1869 cw = (*mb_ptr2cells)(s); | |
1870 if (cw > 1 && ( | |
1871 #ifdef FEAT_RIGHTLEFT | |
1872 cmdmsg_rl ? msg_col <= 1 : | |
1873 #endif | |
1874 msg_col == Columns - 1)) | |
1875 { | |
1876 /* Doesn't fit, print a highlighted '>' to fill it up. */ | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
1877 msg_screen_putchar('>', HL_ATTR(HLF_AT)); |
7 | 1878 return s; |
1879 } | |
1880 | |
1881 screen_puts_len(s, l, msg_row, msg_col, attr); | |
1882 #ifdef FEAT_RIGHTLEFT | |
1883 if (cmdmsg_rl) | |
1884 { | |
1885 msg_col -= cw; | |
1886 if (msg_col == 0) | |
1887 { | |
1888 msg_col = Columns; | |
1889 ++msg_row; | |
1890 } | |
1891 } | |
1892 else | |
1893 #endif | |
1894 { | |
1895 msg_col += cw; | |
1896 if (msg_col >= Columns) | |
1897 { | |
1898 msg_col = 0; | |
1899 ++msg_row; | |
1900 } | |
1901 } | |
1902 return s + l; | |
1903 } | |
1904 | |
1905 /* | |
1906 * Output a string to the screen at position msg_row, msg_col. | |
1907 * Update msg_row and msg_col for the next message. | |
1908 */ | |
1909 void | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1910 msg_puts(char *s) |
7 | 1911 { |
10141
b67088aae933
commit https://github.com/vim/vim/commit/aeac9006d5d14910f214f09df52c026a5936e737
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1912 msg_puts_attr(s, 0); |
7 | 1913 } |
1914 | |
1915 void | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1916 msg_puts_title(char *s) |
7 | 1917 { |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
1918 msg_puts_attr(s, HL_ATTR(HLF_T)); |
7 | 1919 } |
1920 | |
1921 /* | |
1922 * Show a message in such a way that it always fits in the line. Cut out a | |
1923 * part in the middle and replace it with "..." when necessary. | |
1924 * Does not handle multi-byte characters! | |
1925 */ | |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1926 static void |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1927 msg_outtrans_long_len_attr(char_u *longstr, int len, int attr) |
7 | 1928 { |
1929 int slen = len; | |
1930 int room; | |
1931 | |
1932 room = Columns - msg_col; | |
1933 if (len > room && room >= 20) | |
1934 { | |
1935 slen = (room - 3) / 2; | |
1936 msg_outtrans_len_attr(longstr, slen, attr); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1937 msg_puts_attr("...", HL_ATTR(HLF_8)); |
7 | 1938 } |
1939 msg_outtrans_len_attr(longstr + len - slen, slen, attr); | |
1940 } | |
1941 | |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1942 void |
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1943 msg_outtrans_long_attr(char_u *longstr, int attr) |
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1944 { |
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1945 msg_outtrans_long_len_attr(longstr, (int)STRLEN(longstr), attr); |
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1946 } |
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1947 |
7 | 1948 /* |
1949 * Basic function for writing a message with highlight attributes. | |
1950 */ | |
1951 void | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1952 msg_puts_attr(char *s, int attr) |
7 | 1953 { |
1954 msg_puts_attr_len(s, -1, attr); | |
1955 } | |
1956 | |
1957 /* | |
1958 * Like msg_puts_attr(), but with a maximum length "maxlen" (in bytes). | |
1959 * When "maxlen" is -1 there is no maximum length. | |
1960 * When "maxlen" is >= 0 the message is not put in the history. | |
1961 */ | |
1962 static void | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1963 msg_puts_attr_len(char *str, int maxlen, int attr) |
7 | 1964 { |
1965 /* | |
1966 * If redirection is on, also write to the redirection file. | |
1967 */ | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1968 redir_write((char_u *)str, maxlen); |
7 | 1969 |
1970 /* | |
1971 * Don't print anything when using ":silent cmd". | |
1972 */ | |
1973 if (msg_silent != 0) | |
1974 return; | |
1975 | |
1976 /* if MSG_HIST flag set, add message to history */ | |
1977 if ((attr & MSG_HIST) && maxlen < 0) | |
1978 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1979 add_msg_hist((char_u *)str, -1, attr); |
7 | 1980 attr &= ~MSG_HIST; |
1981 } | |
1982 | |
18293
1c5974759bcd
patch 8.1.2141: :tselect has an extra hit-enter prompt
Bram Moolenaar <Bram@vim.org>
parents:
18176
diff
changeset
|
1983 // When writing something to the screen after it has scrolled, requires a |
1c5974759bcd
patch 8.1.2141: :tselect has an extra hit-enter prompt
Bram Moolenaar <Bram@vim.org>
parents:
18176
diff
changeset
|
1984 // wait-return prompt later. Needed when scrolling, resetting |
1c5974759bcd
patch 8.1.2141: :tselect has an extra hit-enter prompt
Bram Moolenaar <Bram@vim.org>
parents:
18176
diff
changeset
|
1985 // need_wait_return after some prompt, and then outputting something |
1c5974759bcd
patch 8.1.2141: :tselect has an extra hit-enter prompt
Bram Moolenaar <Bram@vim.org>
parents:
18176
diff
changeset
|
1986 // without scrolling |
1c5974759bcd
patch 8.1.2141: :tselect has an extra hit-enter prompt
Bram Moolenaar <Bram@vim.org>
parents:
18176
diff
changeset
|
1987 // Not needed when only using CR to move the cursor. |
1c5974759bcd
patch 8.1.2141: :tselect has an extra hit-enter prompt
Bram Moolenaar <Bram@vim.org>
parents:
18176
diff
changeset
|
1988 if (msg_scrolled != 0 && !msg_scrolled_ign && STRCMP(str, "\r") != 0) |
7 | 1989 need_wait_return = TRUE; |
18293
1c5974759bcd
patch 8.1.2141: :tselect has an extra hit-enter prompt
Bram Moolenaar <Bram@vim.org>
parents:
18176
diff
changeset
|
1990 msg_didany = TRUE; // remember that something was outputted |
7 | 1991 |
1992 /* | |
1993 * If there is no valid screen, use fprintf so we can see error messages. | |
1994 * If termcap is not active, we may be writing in an alternate console | |
1995 * window, cursor positioning may not work correctly (window size may be | |
1996 * different, e.g. for Win32 console) or we just don't know where the | |
1997 * cursor is. | |
1998 */ | |
1999 if (msg_use_printf()) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
2000 msg_puts_printf((char_u *)str, maxlen); |
446 | 2001 else |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
2002 msg_puts_display((char_u *)str, maxlen, attr, FALSE); |
446 | 2003 } |
2004 | |
2005 /* | |
2006 * The display part of msg_puts_attr_len(). | |
2007 * May be called recursively to display scroll-back text. | |
2008 */ | |
2009 static void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2010 msg_puts_display( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2011 char_u *str, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2012 int maxlen, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2013 int attr, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2014 int recurse) |
446 | 2015 { |
2016 char_u *s = str; | |
2017 char_u *t_s = str; /* string from "t_s" to "s" is still todo */ | |
2018 int t_col = 0; /* screen cells todo, 0 when "t_s" not used */ | |
2019 int l; | |
2020 int cw; | |
2021 char_u *sb_str = str; | |
2022 int sb_col = msg_col; | |
2023 int wrap; | |
1381 | 2024 int did_last_char; |
7 | 2025 |
2026 did_wait_return = FALSE; | |
1339 | 2027 while ((maxlen < 0 || (int)(s - str) < maxlen) && *s != NUL) |
7 | 2028 { |
2029 /* | |
446 | 2030 * We are at the end of the screen line when: |
2031 * - When outputting a newline. | |
2032 * - When outputting a character in the last column. | |
7 | 2033 */ |
446 | 2034 if (!recurse && msg_row >= Rows - 1 && (*s == '\n' || ( |
7 | 2035 #ifdef FEAT_RIGHTLEFT |
2036 cmdmsg_rl | |
2037 ? ( | |
2038 msg_col <= 1 | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2039 || (*s == TAB && msg_col <= 7) |
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2040 || (has_mbyte && (*mb_ptr2cells)(s) > 1 && msg_col <= 2)) |
7 | 2041 : |
2042 #endif | |
2043 (msg_col + t_col >= Columns - 1 | |
2044 || (*s == TAB && msg_col + t_col >= ((Columns - 1) & ~7)) | |
2045 || (has_mbyte && (*mb_ptr2cells)(s) > 1 | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2046 && msg_col + t_col >= Columns - 2))))) |
7 | 2047 { |
446 | 2048 /* |
2049 * The screen is scrolled up when at the last row (some terminals | |
2050 * scroll automatically, some don't. To avoid problems we scroll | |
2051 * ourselves). | |
2052 */ | |
7 | 2053 if (t_col > 0) |
2054 /* output postponed text */ | |
446 | 2055 t_puts(&t_col, t_s, s, attr); |
7 | 2056 |
1342 | 2057 /* When no more prompt and no more room, truncate here */ |
7 | 2058 if (msg_no_more && lines_left == 0) |
2059 break; | |
446 | 2060 |
2061 /* Scroll the screen up one line. */ | |
2062 msg_scroll_up(); | |
7 | 2063 |
2064 msg_row = Rows - 2; | |
2065 if (msg_col >= Columns) /* can happen after screen resize */ | |
2066 msg_col = Columns - 1; | |
2067 | |
446 | 2068 /* Display char in last column before showing more-prompt. */ |
2069 if (*s >= ' ' | |
2070 #ifdef FEAT_RIGHTLEFT | |
2071 && !cmdmsg_rl | |
2072 #endif | |
2073 ) | |
2074 { | |
2075 if (has_mbyte) | |
2076 { | |
2077 if (enc_utf8 && maxlen >= 0) | |
2078 /* avoid including composing chars after the end */ | |
474 | 2079 l = utfc_ptr2len_len(s, (int)((str + maxlen) - s)); |
446 | 2080 else |
474 | 2081 l = (*mb_ptr2len)(s); |
446 | 2082 s = screen_puts_mbyte(s, l, attr); |
2083 } | |
2084 else | |
2085 msg_screen_putchar(*s++, attr); | |
1381 | 2086 did_last_char = TRUE; |
446 | 2087 } |
1381 | 2088 else |
2089 did_last_char = FALSE; | |
446 | 2090 |
2091 if (p_more) | |
2092 /* store text for scrolling back */ | |
2093 store_sb_text(&sb_str, s, attr, &sb_col, TRUE); | |
2094 | |
539 | 2095 inc_msg_scrolled(); |
446 | 2096 need_wait_return = TRUE; /* may need wait_return in main() */ |
7 | 2097 redraw_cmdline = TRUE; |
2098 if (cmdline_row > 0 && !exmode_active) | |
2099 --cmdline_row; | |
2100 | |
2101 /* | |
446 | 2102 * If screen is completely filled and 'more' is set then wait |
2103 * for a character. | |
7 | 2104 */ |
1342 | 2105 if (lines_left > 0) |
2106 --lines_left; | |
957 | 2107 if (p_more && lines_left == 0 && State != HITRETURN |
7 | 2108 && !msg_no_more && !exmode_active) |
2109 { | |
2110 #ifdef FEAT_CON_DIALOG | |
446 | 2111 if (do_more_prompt(NUL)) |
2112 s = confirm_msg_tail; | |
2113 #else | |
2114 (void)do_more_prompt(NUL); | |
7 | 2115 #endif |
2116 if (quit_more) | |
446 | 2117 return; |
7 | 2118 } |
539 | 2119 |
2120 /* When we displayed a char in last column need to check if there | |
2121 * is still more. */ | |
1381 | 2122 if (did_last_char) |
539 | 2123 continue; |
7 | 2124 } |
2125 | |
446 | 2126 wrap = *s == '\n' |
7 | 2127 || msg_col + t_col >= Columns |
2128 || (has_mbyte && (*mb_ptr2cells)(s) > 1 | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2129 && msg_col + t_col >= Columns - 1); |
446 | 2130 if (t_col > 0 && (wrap || *s == '\r' || *s == '\b' |
2131 || *s == '\t' || *s == BELL)) | |
7 | 2132 /* output any postponed text */ |
446 | 2133 t_puts(&t_col, t_s, s, attr); |
2134 | |
2135 if (wrap && p_more && !recurse) | |
2136 /* store text for scrolling back */ | |
2137 store_sb_text(&sb_str, s, attr, &sb_col, TRUE); | |
7 | 2138 |
2139 if (*s == '\n') /* go to next line */ | |
2140 { | |
2141 msg_didout = FALSE; /* remember that line is empty */ | |
474 | 2142 #ifdef FEAT_RIGHTLEFT |
2143 if (cmdmsg_rl) | |
2144 msg_col = Columns - 1; | |
2145 else | |
2146 #endif | |
2147 msg_col = 0; | |
7 | 2148 if (++msg_row >= Rows) /* safety check */ |
2149 msg_row = Rows - 1; | |
2150 } | |
2151 else if (*s == '\r') /* go to column 0 */ | |
2152 { | |
2153 msg_col = 0; | |
2154 } | |
2155 else if (*s == '\b') /* go to previous char */ | |
2156 { | |
2157 if (msg_col) | |
2158 --msg_col; | |
2159 } | |
446 | 2160 else if (*s == TAB) /* translate Tab into spaces */ |
7 | 2161 { |
2162 do | |
2163 msg_screen_putchar(' ', attr); | |
2164 while (msg_col & 7); | |
2165 } | |
6949 | 2166 else if (*s == BELL) /* beep (from ":sh") */ |
2167 vim_beep(BO_SH); | |
7 | 2168 else |
2169 { | |
2170 if (has_mbyte) | |
2171 { | |
2172 cw = (*mb_ptr2cells)(s); | |
2173 if (enc_utf8 && maxlen >= 0) | |
2174 /* avoid including composing chars after the end */ | |
474 | 2175 l = utfc_ptr2len_len(s, (int)((str + maxlen) - s)); |
7 | 2176 else |
474 | 2177 l = (*mb_ptr2len)(s); |
7 | 2178 } |
2179 else | |
2180 { | |
2181 cw = 1; | |
2182 l = 1; | |
2183 } | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2184 |
7 | 2185 /* When drawing from right to left or when a double-wide character |
2186 * doesn't fit, draw a single character here. Otherwise collect | |
2187 * characters and draw them all at once later. */ | |
2188 if ( | |
2189 # ifdef FEAT_RIGHTLEFT | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2190 cmdmsg_rl || |
7 | 2191 # endif |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2192 (cw > 1 && msg_col + t_col >= Columns - 1)) |
7 | 2193 { |
2194 if (l > 1) | |
2195 s = screen_puts_mbyte(s, l, attr) - 1; | |
2196 else | |
2197 msg_screen_putchar(*s, attr); | |
2198 } | |
2199 else | |
2200 { | |
2201 /* postpone this character until later */ | |
2202 if (t_col == 0) | |
2203 t_s = s; | |
2204 t_col += cw; | |
2205 s += l - 1; | |
2206 } | |
2207 } | |
2208 ++s; | |
2209 } | |
2210 | |
2211 /* output any postponed text */ | |
2212 if (t_col > 0) | |
446 | 2213 t_puts(&t_col, t_s, s, attr); |
2214 if (p_more && !recurse) | |
2215 store_sb_text(&sb_str, s, attr, &sb_col, FALSE); | |
7 | 2216 |
2217 msg_check(); | |
2218 } | |
2219 | |
2220 /* | |
9941
e975914c17e9
commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
9894
diff
changeset
|
2221 * Return TRUE when ":filter pattern" was used and "msg" does not match |
e975914c17e9
commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
9894
diff
changeset
|
2222 * "pattern". |
e975914c17e9
commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
9894
diff
changeset
|
2223 */ |
e975914c17e9
commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
9894
diff
changeset
|
2224 int |
e975914c17e9
commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
9894
diff
changeset
|
2225 message_filtered(char_u *msg) |
e975914c17e9
commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
9894
diff
changeset
|
2226 { |
9980
b222552cf0c4
commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents:
9941
diff
changeset
|
2227 int match; |
b222552cf0c4
commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents:
9941
diff
changeset
|
2228 |
b222552cf0c4
commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents:
9941
diff
changeset
|
2229 if (cmdmod.filter_regmatch.regprog == NULL) |
b222552cf0c4
commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents:
9941
diff
changeset
|
2230 return FALSE; |
b222552cf0c4
commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents:
9941
diff
changeset
|
2231 match = vim_regexec(&cmdmod.filter_regmatch, msg, (colnr_T)0); |
b222552cf0c4
commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents:
9941
diff
changeset
|
2232 return cmdmod.filter_force ? match : !match; |
9941
e975914c17e9
commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
9894
diff
changeset
|
2233 } |
e975914c17e9
commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
9894
diff
changeset
|
2234 |
e975914c17e9
commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
9894
diff
changeset
|
2235 /* |
446 | 2236 * Scroll the screen up one line for displaying the next message line. |
2237 */ | |
2238 static void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2239 msg_scroll_up(void) |
446 | 2240 { |
2241 #ifdef FEAT_GUI | |
2242 /* Remove the cursor before scrolling, ScreenLines[] is going | |
2243 * to become invalid. */ | |
2244 if (gui.in_use) | |
2245 gui_undraw_cursor(); | |
2246 #endif | |
2247 /* scrolling up always works */ | |
13150
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
2248 mch_disable_flush(); |
12152
69af108df70e
patch 8.0.0956: scrolling in a terminal window has flicker
Christian Brabandt <cb@256bit.org>
parents:
12015
diff
changeset
|
2249 screen_del_lines(0, 0, 1, (int)Rows, TRUE, 0, NULL); |
13150
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
2250 mch_enable_flush(); |
446 | 2251 |
2252 if (!can_clear((char_u *)" ")) | |
2253 { | |
2254 /* Scrolling up doesn't result in the right background. Set the | |
2255 * background here. It's not efficient, but avoids that we have to do | |
2256 * it all over the code. */ | |
2257 screen_fill((int)Rows - 1, (int)Rows, 0, (int)Columns, ' ', ' ', 0); | |
2258 | |
2259 /* Also clear the last char of the last but one line if it was not | |
2260 * cleared before to avoid a scroll-up. */ | |
2261 if (ScreenAttrs[LineOffset[Rows - 2] + Columns - 1] == (sattr_T)-1) | |
2262 screen_fill((int)Rows - 2, (int)Rows - 1, | |
2263 (int)Columns - 1, (int)Columns, ' ', ' ', 0); | |
2264 } | |
2265 } | |
2266 | |
2267 /* | |
539 | 2268 * Increment "msg_scrolled". |
2269 */ | |
2270 static void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2271 inc_msg_scrolled(void) |
539 | 2272 { |
2273 #ifdef FEAT_EVAL | |
2274 if (*get_vim_var_str(VV_SCROLLSTART) == NUL) | |
2275 { | |
2276 char_u *p = sourcing_name; | |
2277 char_u *tofree = NULL; | |
2278 int len; | |
2279 | |
2280 /* v:scrollstart is empty, set it to the script/function name and line | |
2281 * number */ | |
2282 if (p == NULL) | |
2283 p = (char_u *)_("Unknown"); | |
2284 else | |
2285 { | |
835 | 2286 len = (int)STRLEN(p) + 40; |
539 | 2287 tofree = alloc(len); |
2288 if (tofree != NULL) | |
2289 { | |
2290 vim_snprintf((char *)tofree, len, _("%s line %ld"), | |
2291 p, (long)sourcing_lnum); | |
2292 p = tofree; | |
2293 } | |
2294 } | |
2295 set_vim_var_string(VV_SCROLLSTART, p, -1); | |
2296 vim_free(tofree); | |
2297 } | |
2298 #endif | |
2299 ++msg_scrolled; | |
11163
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2300 if (must_redraw < VALID) |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2301 must_redraw = VALID; |
539 | 2302 } |
2303 | |
2304 /* | |
446 | 2305 * To be able to scroll back at the "more" and "hit-enter" prompts we need to |
2306 * store the displayed text and remember where screen lines start. | |
2307 */ | |
2308 typedef struct msgchunk_S msgchunk_T; | |
2309 struct msgchunk_S | |
2310 { | |
2311 msgchunk_T *sb_next; | |
2312 msgchunk_T *sb_prev; | |
2313 char sb_eol; /* TRUE when line ends after this text */ | |
2314 int sb_msg_col; /* column in which text starts */ | |
2315 int sb_attr; /* text attributes */ | |
2316 char_u sb_text[1]; /* text to be displayed, actually longer */ | |
2317 }; | |
2318 | |
2319 static msgchunk_T *last_msgchunk = NULL; /* last displayed text */ | |
2320 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
2321 static msgchunk_T *msg_sb_start(msgchunk_T *mps); |
446 | 2322 |
11163
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2323 typedef enum { |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2324 SB_CLEAR_NONE = 0, |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2325 SB_CLEAR_ALL, |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2326 SB_CLEAR_CMDLINE_BUSY, |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2327 SB_CLEAR_CMDLINE_DONE |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2328 } sb_clear_T; |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2329 |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2330 /* When to clear text on next msg. */ |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2331 static sb_clear_T do_clear_sb_text = SB_CLEAR_NONE; |
447 | 2332 |
446 | 2333 /* |
2334 * Store part of a printed message for displaying when scrolling back. | |
2335 */ | |
2336 static void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2337 store_sb_text( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2338 char_u **sb_str, /* start of string */ |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2339 char_u *s, /* just after string */ |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2340 int attr, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2341 int *sb_col, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2342 int finish) /* line ends */ |
446 | 2343 { |
2344 msgchunk_T *mp; | |
2345 | |
11163
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2346 if (do_clear_sb_text == SB_CLEAR_ALL |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2347 || do_clear_sb_text == SB_CLEAR_CMDLINE_DONE) |
447 | 2348 { |
11163
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2349 clear_sb_text(do_clear_sb_text == SB_CLEAR_ALL); |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2350 do_clear_sb_text = SB_CLEAR_NONE; |
447 | 2351 } |
2352 | |
446 | 2353 if (s > *sb_str) |
2354 { | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
2355 mp = alloc(sizeof(msgchunk_T) + (s - *sb_str)); |
446 | 2356 if (mp != NULL) |
2357 { | |
2358 mp->sb_eol = finish; | |
2359 mp->sb_msg_col = *sb_col; | |
2360 mp->sb_attr = attr; | |
2361 vim_strncpy(mp->sb_text, *sb_str, s - *sb_str); | |
2362 | |
2363 if (last_msgchunk == NULL) | |
2364 { | |
2365 last_msgchunk = mp; | |
2366 mp->sb_prev = NULL; | |
2367 } | |
2368 else | |
2369 { | |
2370 mp->sb_prev = last_msgchunk; | |
2371 last_msgchunk->sb_next = mp; | |
2372 last_msgchunk = mp; | |
2373 } | |
2374 mp->sb_next = NULL; | |
2375 } | |
2376 } | |
2377 else if (finish && last_msgchunk != NULL) | |
2378 last_msgchunk->sb_eol = TRUE; | |
2379 | |
2380 *sb_str = s; | |
2381 *sb_col = 0; | |
2382 } | |
2383 | |
2384 /* | |
447 | 2385 * Finished showing messages, clear the scroll-back text on the next message. |
2386 */ | |
2387 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2388 may_clear_sb_text(void) |
447 | 2389 { |
11163
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2390 do_clear_sb_text = SB_CLEAR_ALL; |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2391 } |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2392 |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2393 /* |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2394 * Starting to edit the command line, do not clear messages now. |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2395 */ |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2396 void |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2397 sb_text_start_cmdline(void) |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2398 { |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2399 do_clear_sb_text = SB_CLEAR_CMDLINE_BUSY; |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2400 msg_sb_eol(); |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2401 } |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2402 |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2403 /* |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2404 * Ending to edit the command line. Clear old lines but the last one later. |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2405 */ |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2406 void |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2407 sb_text_end_cmdline(void) |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2408 { |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2409 do_clear_sb_text = SB_CLEAR_CMDLINE_DONE; |
447 | 2410 } |
2411 | |
2412 /* | |
446 | 2413 * Clear any text remembered for scrolling back. |
11163
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2414 * When "all" is FALSE keep the last line. |
446 | 2415 * Called when redrawing the screen. |
2416 */ | |
2417 void | |
11163
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2418 clear_sb_text(int all) |
446 | 2419 { |
2420 msgchunk_T *mp; | |
11163
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2421 msgchunk_T **lastp; |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2422 |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2423 if (all) |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2424 lastp = &last_msgchunk; |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2425 else |
446 | 2426 { |
11163
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2427 if (last_msgchunk == NULL) |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2428 return; |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2429 lastp = &last_msgchunk->sb_prev; |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2430 } |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2431 |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2432 while (*lastp != NULL) |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2433 { |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2434 mp = (*lastp)->sb_prev; |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2435 vim_free(*lastp); |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2436 *lastp = mp; |
446 | 2437 } |
2438 } | |
2439 | |
2440 /* | |
447 | 2441 * "g<" command. |
2442 */ | |
2443 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2444 show_sb_text(void) |
447 | 2445 { |
2446 msgchunk_T *mp; | |
2447 | |
1342 | 2448 /* Only show something if there is more than one line, otherwise it looks |
447 | 2449 * weird, typing a command without output results in one line. */ |
2450 mp = msg_sb_start(last_msgchunk); | |
2451 if (mp == NULL || mp->sb_prev == NULL) | |
6949 | 2452 vim_beep(BO_MESS); |
447 | 2453 else |
2454 { | |
2455 do_more_prompt('G'); | |
2456 wait_return(FALSE); | |
2457 } | |
2458 } | |
2459 | |
2460 /* | |
446 | 2461 * Move to the start of screen line in already displayed text. |
2462 */ | |
2463 static msgchunk_T * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2464 msg_sb_start(msgchunk_T *mps) |
446 | 2465 { |
2466 msgchunk_T *mp = mps; | |
2467 | |
2468 while (mp != NULL && mp->sb_prev != NULL && !mp->sb_prev->sb_eol) | |
2469 mp = mp->sb_prev; | |
2470 return mp; | |
2471 } | |
2472 | |
2473 /* | |
3435 | 2474 * Mark the last message chunk as finishing the line. |
2475 */ | |
2476 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2477 msg_sb_eol(void) |
3435 | 2478 { |
2479 if (last_msgchunk != NULL) | |
2480 last_msgchunk->sb_eol = TRUE; | |
2481 } | |
2482 | |
2483 /* | |
446 | 2484 * Display a screen line from previously displayed text at row "row". |
2485 * Returns a pointer to the text for the next line (can be NULL). | |
2486 */ | |
2487 static msgchunk_T * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2488 disp_sb_line(int row, msgchunk_T *smp) |
446 | 2489 { |
2490 msgchunk_T *mp = smp; | |
2491 char_u *p; | |
2492 | |
2493 for (;;) | |
2494 { | |
2495 msg_row = row; | |
2496 msg_col = mp->sb_msg_col; | |
2497 p = mp->sb_text; | |
2498 if (*p == '\n') /* don't display the line break */ | |
2499 ++p; | |
2500 msg_puts_display(p, -1, mp->sb_attr, TRUE); | |
2501 if (mp->sb_eol || mp->sb_next == NULL) | |
2502 break; | |
2503 mp = mp->sb_next; | |
2504 } | |
2505 return mp->sb_next; | |
2506 } | |
2507 | |
2508 /* | |
7 | 2509 * Output any postponed text for msg_puts_attr_len(). |
2510 */ | |
2511 static void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2512 t_puts( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2513 int *t_col, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2514 char_u *t_s, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2515 char_u *s, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2516 int attr) |
7 | 2517 { |
2518 /* output postponed text */ | |
2519 msg_didout = TRUE; /* remember that line is not empty */ | |
2520 screen_puts_len(t_s, (int)(s - t_s), msg_row, msg_col, attr); | |
446 | 2521 msg_col += *t_col; |
2522 *t_col = 0; | |
7 | 2523 /* If the string starts with a composing character don't increment the |
2524 * column position for it. */ | |
2525 if (enc_utf8 && utf_iscomposing(utf_ptr2char(t_s))) | |
2526 --msg_col; | |
2527 if (msg_col >= Columns) | |
2528 { | |
2529 msg_col = 0; | |
2530 ++msg_row; | |
2531 } | |
2532 } | |
2533 | |
2534 /* | |
2535 * Returns TRUE when messages should be printed with mch_errmsg(). | |
2536 * This is used when there is no valid screen, so we can see error messages. | |
2537 * If termcap is not active, we may be writing in an alternate console | |
2538 * window, cursor positioning may not work correctly (window size may be | |
2539 * different, e.g. for Win32 console) or we just don't know where the | |
2540 * cursor is. | |
2541 */ | |
2542 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2543 msg_use_printf(void) |
7 | 2544 { |
2545 return (!msg_check_screen() | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2546 #if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL)) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2547 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2548 || (!gui.in_use && !termcap_active) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2549 # else |
7 | 2550 || !termcap_active |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2551 # endif |
7 | 2552 #endif |
2553 || (swapping_screen() && !termcap_active) | |
2554 ); | |
2555 } | |
2556 | |
446 | 2557 /* |
2558 * Print a message when there is no valid screen. | |
2559 */ | |
2560 static void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2561 msg_puts_printf(char_u *str, int maxlen) |
446 | 2562 { |
2563 char_u *s = str; | |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2564 char_u *buf = NULL; |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2565 char_u *p = s; |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2566 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15840
diff
changeset
|
2567 #ifdef MSWIN |
446 | 2568 if (!(silent_mode && p_verbose == 0)) |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2569 mch_settmode(TMODE_COOK); /* handle CR and NL correctly */ |
446 | 2570 #endif |
10158
dd0531938cb6
commit https://github.com/vim/vim/commit/2321ca2a78286bc026fa7f407281ddbeb04114bb
Christian Brabandt <cb@256bit.org>
parents:
10141
diff
changeset
|
2571 while ((maxlen < 0 || (int)(s - str) < maxlen) && *s != NUL) |
446 | 2572 { |
2573 if (!(silent_mode && p_verbose == 0)) | |
2574 { | |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2575 // NL --> CR NL translation (for Unix, not for "--version") |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2576 if (*s == NL) |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2577 { |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2578 int n = (int)(s - p); |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2579 |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2580 buf = alloc(n + 3); |
17797
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2581 if (buf != NULL) |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2582 { |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2583 memcpy(buf, p, n); |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2584 if (!info_message) |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2585 buf[n++] = CAR; |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2586 buf[n++] = NL; |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2587 buf[n++] = NUL; |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2588 if (info_message) // informative message, not an error |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2589 mch_msg((char *)buf); |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2590 else |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2591 mch_errmsg((char *)buf); |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2592 vim_free(buf); |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2593 } |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2594 p = s + 1; |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2595 } |
446 | 2596 } |
2597 | |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2598 // primitive way to compute the current column |
446 | 2599 #ifdef FEAT_RIGHTLEFT |
2600 if (cmdmsg_rl) | |
2601 { | |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2602 if (*s == CAR || *s == NL) |
446 | 2603 msg_col = Columns - 1; |
2604 else | |
2605 --msg_col; | |
2606 } | |
2607 else | |
2608 #endif | |
2609 { | |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2610 if (*s == CAR || *s == NL) |
446 | 2611 msg_col = 0; |
2612 else | |
2613 ++msg_col; | |
2614 } | |
2615 ++s; | |
2616 } | |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2617 |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2618 if (*p != NUL && !(silent_mode && p_verbose == 0)) |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2619 { |
15926
ca0a0b64809c
patch 8.1.0969: message written during startup is truncated
Bram Moolenaar <Bram@vim.org>
parents:
15896
diff
changeset
|
2620 int c = -1; |
ca0a0b64809c
patch 8.1.0969: message written during startup is truncated
Bram Moolenaar <Bram@vim.org>
parents:
15896
diff
changeset
|
2621 |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2622 if (maxlen > 0 && STRLEN(p) > (size_t)maxlen) |
15926
ca0a0b64809c
patch 8.1.0969: message written during startup is truncated
Bram Moolenaar <Bram@vim.org>
parents:
15896
diff
changeset
|
2623 { |
ca0a0b64809c
patch 8.1.0969: message written during startup is truncated
Bram Moolenaar <Bram@vim.org>
parents:
15896
diff
changeset
|
2624 c = p[maxlen]; |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2625 p[maxlen] = 0; |
15926
ca0a0b64809c
patch 8.1.0969: message written during startup is truncated
Bram Moolenaar <Bram@vim.org>
parents:
15896
diff
changeset
|
2626 } |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2627 if (info_message) |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2628 mch_msg((char *)p); |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2629 else |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2630 mch_errmsg((char *)p); |
15926
ca0a0b64809c
patch 8.1.0969: message written during startup is truncated
Bram Moolenaar <Bram@vim.org>
parents:
15896
diff
changeset
|
2631 if (c != -1) |
ca0a0b64809c
patch 8.1.0969: message written during startup is truncated
Bram Moolenaar <Bram@vim.org>
parents:
15896
diff
changeset
|
2632 p[maxlen] = c; |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2633 } |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2634 |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2635 msg_didout = TRUE; // assume that line is not empty |
446 | 2636 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15840
diff
changeset
|
2637 #ifdef MSWIN |
446 | 2638 if (!(silent_mode && p_verbose == 0)) |
2639 mch_settmode(TMODE_RAW); | |
2640 #endif | |
2641 } | |
2642 | |
2643 /* | |
2644 * Show the more-prompt and handle the user response. | |
2645 * This takes care of scrolling back and displaying previously displayed text. | |
447 | 2646 * When at hit-enter prompt "typed_char" is the already typed character, |
2647 * otherwise it's NUL. | |
446 | 2648 * Returns TRUE when jumping ahead to "confirm_msg_tail". |
2649 */ | |
2650 static int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2651 do_more_prompt(int typed_char) |
446 | 2652 { |
8627
7c98c5d0298c
commit https://github.com/vim/vim/commit/bfb96c047b79b2aab5fd57a2472871508819f3ef
Christian Brabandt <cb@256bit.org>
parents:
8289
diff
changeset
|
2653 static int entered = FALSE; |
446 | 2654 int used_typed_char = typed_char; |
2655 int oldState = State; | |
2656 int c; | |
2657 #ifdef FEAT_CON_DIALOG | |
2658 int retval = FALSE; | |
2659 #endif | |
3263 | 2660 int toscroll; |
446 | 2661 msgchunk_T *mp_last = NULL; |
2662 msgchunk_T *mp; | |
2663 int i; | |
2664 | |
8627
7c98c5d0298c
commit https://github.com/vim/vim/commit/bfb96c047b79b2aab5fd57a2472871508819f3ef
Christian Brabandt <cb@256bit.org>
parents:
8289
diff
changeset
|
2665 /* We get called recursively when a timer callback outputs a message. In |
9185
70d3337ff173
commit https://github.com/vim/vim/commit/a0055ad3a789b8eeb0c983d8a18d4bcaeaf456b8
Christian Brabandt <cb@256bit.org>
parents:
8905
diff
changeset
|
2666 * that case don't show another prompt. Also when at the hit-Enter prompt |
70d3337ff173
commit https://github.com/vim/vim/commit/a0055ad3a789b8eeb0c983d8a18d4bcaeaf456b8
Christian Brabandt <cb@256bit.org>
parents:
8905
diff
changeset
|
2667 * and nothing was typed. */ |
70d3337ff173
commit https://github.com/vim/vim/commit/a0055ad3a789b8eeb0c983d8a18d4bcaeaf456b8
Christian Brabandt <cb@256bit.org>
parents:
8905
diff
changeset
|
2668 if (entered || (State == HITRETURN && typed_char == 0)) |
8627
7c98c5d0298c
commit https://github.com/vim/vim/commit/bfb96c047b79b2aab5fd57a2472871508819f3ef
Christian Brabandt <cb@256bit.org>
parents:
8289
diff
changeset
|
2669 return FALSE; |
7c98c5d0298c
commit https://github.com/vim/vim/commit/bfb96c047b79b2aab5fd57a2472871508819f3ef
Christian Brabandt <cb@256bit.org>
parents:
8289
diff
changeset
|
2670 entered = TRUE; |
7c98c5d0298c
commit https://github.com/vim/vim/commit/bfb96c047b79b2aab5fd57a2472871508819f3ef
Christian Brabandt <cb@256bit.org>
parents:
8289
diff
changeset
|
2671 |
447 | 2672 if (typed_char == 'G') |
2673 { | |
2674 /* "g<": Find first line on the last page. */ | |
2675 mp_last = msg_sb_start(last_msgchunk); | |
2676 for (i = 0; i < Rows - 2 && mp_last != NULL | |
2677 && mp_last->sb_prev != NULL; ++i) | |
2678 mp_last = msg_sb_start(mp_last->sb_prev); | |
2679 } | |
2680 | |
446 | 2681 State = ASKMORE; |
2682 setmouse(); | |
447 | 2683 if (typed_char == NUL) |
2684 msg_moremsg(FALSE); | |
446 | 2685 for (;;) |
2686 { | |
2687 /* | |
2688 * Get a typed character directly from the user. | |
2689 */ | |
2690 if (used_typed_char != NUL) | |
2691 { | |
2692 c = used_typed_char; /* was typed at hit-enter prompt */ | |
2693 used_typed_char = NUL; | |
2694 } | |
2695 else | |
2696 c = get_keystroke(); | |
2697 | |
2698 #if defined(FEAT_MENU) && defined(FEAT_GUI) | |
2699 if (c == K_MENU) | |
2700 { | |
2701 int idx = get_menu_index(current_menu, ASKMORE); | |
2702 | |
2703 /* Used a menu. If it starts with CTRL-Y, it must | |
2704 * be a "Copy" for the clipboard. Otherwise | |
2705 * assume that we end */ | |
2706 if (idx == MENU_INDEX_INVALID) | |
2707 continue; | |
2708 c = *current_menu->strings[idx]; | |
2709 if (c != NUL && current_menu->strings[idx][1] != NUL) | |
2710 ins_typebuf(current_menu->strings[idx] + 1, | |
2711 current_menu->noremap[idx], 0, TRUE, | |
2712 current_menu->silent[idx]); | |
2713 } | |
2714 #endif | |
2715 | |
3263 | 2716 toscroll = 0; |
446 | 2717 switch (c) |
2718 { | |
2719 case BS: /* scroll one line back */ | |
2720 case K_BS: | |
2721 case 'k': | |
2722 case K_UP: | |
3263 | 2723 toscroll = -1; |
446 | 2724 break; |
2725 | |
2726 case CAR: /* one extra line */ | |
2727 case NL: | |
2728 case 'j': | |
2729 case K_DOWN: | |
3263 | 2730 toscroll = 1; |
446 | 2731 break; |
2732 | |
2733 case 'u': /* Up half a page */ | |
3263 | 2734 toscroll = -(Rows / 2); |
446 | 2735 break; |
2736 | |
2737 case 'd': /* Down half a page */ | |
3263 | 2738 toscroll = Rows / 2; |
446 | 2739 break; |
2740 | |
2741 case 'b': /* one page back */ | |
1820 | 2742 case K_PAGEUP: |
3263 | 2743 toscroll = -(Rows - 1); |
446 | 2744 break; |
2745 | |
2746 case ' ': /* one extra page */ | |
1820 | 2747 case 'f': |
446 | 2748 case K_PAGEDOWN: |
2749 case K_LEFTMOUSE: | |
3263 | 2750 toscroll = Rows - 1; |
446 | 2751 break; |
2752 | |
447 | 2753 case 'g': /* all the way back to the start */ |
3263 | 2754 toscroll = -999999; |
447 | 2755 break; |
2756 | |
2757 case 'G': /* all the way to the end */ | |
3263 | 2758 toscroll = 999999; |
447 | 2759 lines_left = 999999; |
2760 break; | |
2761 | |
446 | 2762 case ':': /* start new command line */ |
2763 #ifdef FEAT_CON_DIALOG | |
2764 if (!confirm_msg_used) | |
2765 #endif | |
2766 { | |
2767 /* Since got_int is set all typeahead will be flushed, but we | |
2768 * want to keep this ':', remember that in a special way. */ | |
2769 typeahead_noflush(':'); | |
14129
cb731d098241
patch 8.1.0082: in terminal window, typing : at more prompt, inserts ':'
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
2770 #ifdef FEAT_TERMINAL |
cb731d098241
patch 8.1.0082: in terminal window, typing : at more prompt, inserts ':'
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
2771 skip_term_loop = TRUE; |
cb731d098241
patch 8.1.0082: in terminal window, typing : at more prompt, inserts ':'
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
2772 #endif |
446 | 2773 cmdline_row = Rows - 1; /* put ':' on this line */ |
2774 skip_redraw = TRUE; /* skip redraw once */ | |
2775 need_wait_return = FALSE; /* don't wait in main() */ | |
2776 } | |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12375
diff
changeset
|
2777 /* FALLTHROUGH */ |
446 | 2778 case 'q': /* quit */ |
2779 case Ctrl_C: | |
2780 case ESC: | |
2781 #ifdef FEAT_CON_DIALOG | |
2782 if (confirm_msg_used) | |
2783 { | |
2784 /* Jump to the choices of the dialog. */ | |
2785 retval = TRUE; | |
2786 } | |
2787 else | |
2788 #endif | |
2789 { | |
2790 got_int = TRUE; | |
2791 quit_more = TRUE; | |
2792 } | |
1829 | 2793 /* When there is some more output (wrapping line) display that |
2794 * without another prompt. */ | |
2795 lines_left = Rows - 1; | |
446 | 2796 break; |
2797 | |
2798 #ifdef FEAT_CLIPBOARD | |
2799 case Ctrl_Y: | |
2800 /* Strange way to allow copying (yanking) a modeless | |
2801 * selection at the more prompt. Use CTRL-Y, | |
2802 * because the same is used in Cmdline-mode and at the | |
2803 * hit-enter prompt. However, scrolling one line up | |
2804 * might be expected... */ | |
2805 if (clip_star.state == SELECT_DONE) | |
2806 clip_copy_modeless_selection(TRUE); | |
2807 continue; | |
2808 #endif | |
2809 default: /* no valid response */ | |
2810 msg_moremsg(TRUE); | |
2811 continue; | |
2812 } | |
2813 | |
3263 | 2814 if (toscroll != 0) |
446 | 2815 { |
3263 | 2816 if (toscroll < 0) |
446 | 2817 { |
2818 /* go to start of last line */ | |
2819 if (mp_last == NULL) | |
2820 mp = msg_sb_start(last_msgchunk); | |
2821 else if (mp_last->sb_prev != NULL) | |
2822 mp = msg_sb_start(mp_last->sb_prev); | |
2823 else | |
2824 mp = NULL; | |
2825 | |
2826 /* go to start of line at top of the screen */ | |
2827 for (i = 0; i < Rows - 2 && mp != NULL && mp->sb_prev != NULL; | |
2828 ++i) | |
2829 mp = msg_sb_start(mp->sb_prev); | |
2830 | |
2831 if (mp != NULL && mp->sb_prev != NULL) | |
2832 { | |
2833 /* Find line to be displayed at top. */ | |
3263 | 2834 for (i = 0; i > toscroll; --i) |
446 | 2835 { |
2836 if (mp == NULL || mp->sb_prev == NULL) | |
2837 break; | |
2838 mp = msg_sb_start(mp->sb_prev); | |
2839 if (mp_last == NULL) | |
2840 mp_last = msg_sb_start(last_msgchunk); | |
2841 else | |
2842 mp_last = msg_sb_start(mp_last->sb_prev); | |
2843 } | |
2844 | |
3263 | 2845 if (toscroll == -1 && screen_ins_lines(0, 0, 1, |
12152
69af108df70e
patch 8.0.0956: scrolling in a terminal window has flicker
Christian Brabandt <cb@256bit.org>
parents:
12015
diff
changeset
|
2846 (int)Rows, 0, NULL) == OK) |
446 | 2847 { |
447 | 2848 /* display line at top */ |
446 | 2849 (void)disp_sb_line(0, mp); |
2850 } | |
2851 else | |
2852 { | |
447 | 2853 /* redisplay all lines */ |
446 | 2854 screenclear(); |
870 | 2855 for (i = 0; mp != NULL && i < Rows - 1; ++i) |
2856 { | |
446 | 2857 mp = disp_sb_line(i, mp); |
870 | 2858 ++msg_scrolled; |
2859 } | |
446 | 2860 } |
3263 | 2861 toscroll = 0; |
446 | 2862 } |
2863 } | |
2864 else | |
2865 { | |
2866 /* First display any text that we scrolled back. */ | |
3263 | 2867 while (toscroll > 0 && mp_last != NULL) |
446 | 2868 { |
2869 /* scroll up, display line at bottom */ | |
2870 msg_scroll_up(); | |
539 | 2871 inc_msg_scrolled(); |
446 | 2872 screen_fill((int)Rows - 2, (int)Rows - 1, 0, |
2873 (int)Columns, ' ', ' ', 0); | |
2874 mp_last = disp_sb_line((int)Rows - 2, mp_last); | |
3263 | 2875 --toscroll; |
446 | 2876 } |
2877 } | |
2878 | |
3263 | 2879 if (toscroll <= 0) |
446 | 2880 { |
2881 /* displayed the requested text, more prompt again */ | |
447 | 2882 screen_fill((int)Rows - 1, (int)Rows, 0, |
2883 (int)Columns, ' ', ' ', 0); | |
446 | 2884 msg_moremsg(FALSE); |
2885 continue; | |
2886 } | |
2887 | |
2888 /* display more text, return to caller */ | |
3263 | 2889 lines_left = toscroll; |
446 | 2890 } |
2891 | |
2892 break; | |
2893 } | |
2894 | |
2895 /* clear the --more-- message */ | |
2896 screen_fill((int)Rows - 1, (int)Rows, 0, (int)Columns, ' ', ' ', 0); | |
2897 State = oldState; | |
2898 setmouse(); | |
2899 if (quit_more) | |
2900 { | |
2901 msg_row = Rows - 1; | |
2902 msg_col = 0; | |
2903 } | |
2904 #ifdef FEAT_RIGHTLEFT | |
2905 else if (cmdmsg_rl) | |
2906 msg_col = Columns - 1; | |
2907 #endif | |
2908 | |
8627
7c98c5d0298c
commit https://github.com/vim/vim/commit/bfb96c047b79b2aab5fd57a2472871508819f3ef
Christian Brabandt <cb@256bit.org>
parents:
8289
diff
changeset
|
2909 entered = FALSE; |
446 | 2910 #ifdef FEAT_CON_DIALOG |
2911 return retval; | |
2912 #else | |
2913 return FALSE; | |
2914 #endif | |
2915 } | |
2916 | |
7 | 2917 #if defined(USE_MCH_ERRMSG) || defined(PROTO) |
2918 | |
2919 #ifdef mch_errmsg | |
2920 # undef mch_errmsg | |
2921 #endif | |
2922 #ifdef mch_msg | |
2923 # undef mch_msg | |
2924 #endif | |
2925 | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2926 #if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL)) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2927 static void |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2928 mch_errmsg_c(char *str) |
7 | 2929 { |
15824
6733b8b1caf3
patch 8.1.0919: compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
15822
diff
changeset
|
2930 int len = (int)STRLEN(str); |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2931 DWORD nwrite = 0; |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2932 DWORD mode = 0; |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2933 HANDLE h = GetStdHandle(STD_ERROR_HANDLE); |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2934 |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2935 if (GetConsoleMode(h, &mode) && enc_codepage >= 0 |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2936 && (int)GetConsoleCP() != enc_codepage) |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2937 { |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2938 WCHAR *w = enc_to_utf16((char_u *)str, &len); |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2939 |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2940 WriteConsoleW(h, w, len, &nwrite, NULL); |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2941 vim_free(w); |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2942 } |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2943 else |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2944 { |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2945 fprintf(stderr, "%s", str); |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2946 } |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2947 } |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2948 #endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2949 |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2950 /* |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2951 * Give an error message. To be used when the screen hasn't been initialized |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2952 * yet. When stderr can't be used, collect error messages until the GUI has |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2953 * started and they can be displayed in a message box. |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2954 */ |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2955 void |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2956 mch_errmsg(char *str) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2957 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2958 #if !defined(MSWIN) || defined(FEAT_GUI_MSWIN) |
7 | 2959 int len; |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2960 #endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2961 |
16596
2f86ca0c1e6b
patch 8.1.1301: when compiled with VIMDLL some messages are not shown
Bram Moolenaar <Bram@vim.org>
parents:
16457
diff
changeset
|
2962 #if (defined(UNIX) || defined(FEAT_GUI)) && !defined(ALWAYS_USE_GUI) && !defined(VIMDLL) |
7 | 2963 /* On Unix use stderr if it's a tty. |
2964 * When not going to start the GUI also use stderr. | |
2965 * On Mac, when started from Finder, stderr is the console. */ | |
2966 if ( | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2967 # ifdef UNIX |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2968 # ifdef MACOS_X |
7 | 2969 (isatty(2) && strcmp("/dev/console", ttyname(2)) != 0) |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2970 # else |
7 | 2971 isatty(2) |
2972 # endif | |
2973 # ifdef FEAT_GUI | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2974 || |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2975 # endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2976 # endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2977 # ifdef FEAT_GUI |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2978 !(gui.in_use || gui.starting) |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2979 # endif |
7 | 2980 ) |
2981 { | |
2982 fprintf(stderr, "%s", str); | |
2983 return; | |
2984 } | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2985 #endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2986 |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2987 #if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL)) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2988 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2989 if (!(gui.in_use || gui.starting)) |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2990 # endif |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2991 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2992 mch_errmsg_c(str); |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2993 return; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2994 } |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2995 #endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2996 |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2997 #if !defined(MSWIN) || defined(FEAT_GUI_MSWIN) |
7 | 2998 /* avoid a delay for a message that isn't there */ |
2999 emsg_on_display = FALSE; | |
3000 | |
3001 len = (int)STRLEN(str) + 1; | |
3002 if (error_ga.ga_growsize == 0) | |
3003 { | |
3004 error_ga.ga_growsize = 80; | |
3005 error_ga.ga_itemsize = 1; | |
3006 } | |
3007 if (ga_grow(&error_ga, len) == OK) | |
3008 { | |
3009 mch_memmove((char_u *)error_ga.ga_data + error_ga.ga_len, | |
3010 (char_u *)str, len); | |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3011 # ifdef UNIX |
7 | 3012 /* remove CR characters, they are displayed */ |
3013 { | |
3014 char_u *p; | |
3015 | |
3016 p = (char_u *)error_ga.ga_data + error_ga.ga_len; | |
3017 for (;;) | |
3018 { | |
3019 p = vim_strchr(p, '\r'); | |
3020 if (p == NULL) | |
3021 break; | |
3022 *p = ' '; | |
3023 } | |
3024 } | |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3025 # endif |
7 | 3026 --len; /* don't count the NUL at the end */ |
3027 error_ga.ga_len += len; | |
3028 } | |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3029 #endif |
7 | 3030 } |
3031 | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3032 #if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL)) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3033 static void |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3034 mch_msg_c(char *str) |
7 | 3035 { |
15824
6733b8b1caf3
patch 8.1.0919: compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
15822
diff
changeset
|
3036 int len = (int)STRLEN(str); |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3037 DWORD nwrite = 0; |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3038 DWORD mode; |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3039 HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3040 |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3041 |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3042 if (GetConsoleMode(h, &mode) && enc_codepage >= 0 |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3043 && (int)GetConsoleCP() != enc_codepage) |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3044 { |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3045 WCHAR *w = enc_to_utf16((char_u *)str, &len); |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3046 |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3047 WriteConsoleW(h, w, len, &nwrite, NULL); |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3048 vim_free(w); |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3049 } |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3050 else |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3051 { |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3052 printf("%s", str); |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3053 } |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3054 } |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3055 #endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3056 |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3057 /* |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3058 * Give a message. To be used when the screen hasn't been initialized yet. |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3059 * When there is no tty, collect messages until the GUI has started and they |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3060 * can be displayed in a message box. |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3061 */ |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3062 void |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3063 mch_msg(char *str) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3064 { |
16596
2f86ca0c1e6b
patch 8.1.1301: when compiled with VIMDLL some messages are not shown
Bram Moolenaar <Bram@vim.org>
parents:
16457
diff
changeset
|
3065 #if (defined(UNIX) || defined(FEAT_GUI)) && !defined(ALWAYS_USE_GUI) && !defined(VIMDLL) |
7 | 3066 /* On Unix use stdout if we have a tty. This allows "vim -h | more" and |
3067 * uses mch_errmsg() when started from the desktop. | |
3068 * When not going to start the GUI also use stdout. | |
3069 * On Mac, when started from Finder, stderr is the console. */ | |
3070 if ( | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3071 # ifdef UNIX |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3072 # ifdef MACOS_X |
7 | 3073 (isatty(2) && strcmp("/dev/console", ttyname(2)) != 0) |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3074 # else |
7 | 3075 isatty(2) |
16606
7e733046db1d
patch 8.1.1306: Borland support is outdated and doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
16596
diff
changeset
|
3076 # endif |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3077 # ifdef FEAT_GUI |
7 | 3078 || |
3079 # endif | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3080 # endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3081 # ifdef FEAT_GUI |
7 | 3082 !(gui.in_use || gui.starting) |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3083 # endif |
7 | 3084 ) |
3085 { | |
3086 printf("%s", str); | |
3087 return; | |
3088 } | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3089 #endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3090 |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3091 #if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL)) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3092 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3093 if (!(gui.in_use || gui.starting)) |
7 | 3094 # endif |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3095 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3096 mch_msg_c(str); |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3097 return; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3098 } |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3099 #endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3100 #if !defined(MSWIN) || defined(FEAT_GUI_MSWIN) |
7 | 3101 mch_errmsg(str); |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3102 #endif |
7 | 3103 } |
3104 #endif /* USE_MCH_ERRMSG */ | |
3105 | |
3106 /* | |
3107 * Put a character on the screen at the current message position and advance | |
3108 * to the next position. Only for printable ASCII! | |
3109 */ | |
3110 static void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3111 msg_screen_putchar(int c, int attr) |
7 | 3112 { |
3113 msg_didout = TRUE; /* remember that line is not empty */ | |
3114 screen_putchar(c, msg_row, msg_col, attr); | |
3115 #ifdef FEAT_RIGHTLEFT | |
3116 if (cmdmsg_rl) | |
3117 { | |
3118 if (--msg_col == 0) | |
3119 { | |
3120 msg_col = Columns; | |
3121 ++msg_row; | |
3122 } | |
3123 } | |
3124 else | |
3125 #endif | |
3126 { | |
3127 if (++msg_col >= Columns) | |
3128 { | |
3129 msg_col = 0; | |
3130 ++msg_row; | |
3131 } | |
3132 } | |
3133 } | |
3134 | |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
3135 static void |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3136 msg_moremsg(int full) |
7 | 3137 { |
446 | 3138 int attr; |
3139 char_u *s = (char_u *)_("-- More --"); | |
7 | 3140 |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
3141 attr = HL_ATTR(HLF_M); |
446 | 3142 screen_puts(s, (int)Rows - 1, 0, attr); |
7 | 3143 if (full) |
446 | 3144 screen_puts((char_u *) |
3145 _(" SPACE/d/j: screen/page/line down, b/u/k: up, q: quit "), | |
3146 (int)Rows - 1, vim_strsize(s), attr); | |
7 | 3147 } |
3148 | |
3149 /* | |
3150 * Repeat the message for the current mode: ASKMORE, EXTERNCMD, CONFIRM or | |
3151 * exmode_active. | |
3152 */ | |
3153 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3154 repeat_message(void) |
7 | 3155 { |
3156 if (State == ASKMORE) | |
3157 { | |
3158 msg_moremsg(TRUE); /* display --more-- message again */ | |
3159 msg_row = Rows - 1; | |
3160 } | |
3161 #ifdef FEAT_CON_DIALOG | |
3162 else if (State == CONFIRM) | |
3163 { | |
3164 display_confirm_msg(); /* display ":confirm" message again */ | |
3165 msg_row = Rows - 1; | |
3166 } | |
3167 #endif | |
3168 else if (State == EXTERNCMD) | |
3169 { | |
3170 windgoto(msg_row, msg_col); /* put cursor back */ | |
3171 } | |
3172 else if (State == HITRETURN || State == SETWSIZE) | |
3173 { | |
1445 | 3174 if (msg_row == Rows - 1) |
3175 { | |
3176 /* Avoid drawing the "hit-enter" prompt below the previous one, | |
3177 * overwrite it. Esp. useful when regaining focus and a | |
3178 * FocusGained autocmd exists but didn't draw anything. */ | |
3179 msg_didout = FALSE; | |
3180 msg_col = 0; | |
3181 msg_clr_eos(); | |
3182 } | |
7 | 3183 hit_return_msg(); |
3184 msg_row = Rows - 1; | |
3185 } | |
3186 } | |
3187 | |
3188 /* | |
3189 * msg_check_screen - check if the screen is initialized. | |
3190 * Also check msg_row and msg_col, if they are too big it may cause a crash. | |
3191 * While starting the GUI the terminal codes will be set for the GUI, but the | |
3192 * output goes to the terminal. Don't use the terminal codes then. | |
3193 */ | |
3194 static int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3195 msg_check_screen(void) |
7 | 3196 { |
3197 if (!full_screen || !screen_valid(FALSE)) | |
3198 return FALSE; | |
3199 | |
3200 if (msg_row >= Rows) | |
3201 msg_row = Rows - 1; | |
3202 if (msg_col >= Columns) | |
3203 msg_col = Columns - 1; | |
3204 return TRUE; | |
3205 } | |
3206 | |
3207 /* | |
3208 * Clear from current message position to end of screen. | |
3209 * Skip this when ":silent" was used, no need to clear for redirection. | |
3210 */ | |
3211 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3212 msg_clr_eos(void) |
7 | 3213 { |
3214 if (msg_silent == 0) | |
3215 msg_clr_eos_force(); | |
3216 } | |
3217 | |
3218 /* | |
3219 * Clear from current message position to end of screen. | |
3220 * Note: msg_col is not updated, so we remember the end of the message | |
3221 * for msg_check(). | |
3222 */ | |
3223 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3224 msg_clr_eos_force(void) |
7 | 3225 { |
3226 if (msg_use_printf()) | |
3227 { | |
3228 if (full_screen) /* only when termcap codes are valid */ | |
3229 { | |
3230 if (*T_CD) | |
3231 out_str(T_CD); /* clear to end of display */ | |
3232 else if (*T_CE) | |
3233 out_str(T_CE); /* clear to end of line */ | |
3234 } | |
3235 } | |
3236 else | |
3237 { | |
3238 #ifdef FEAT_RIGHTLEFT | |
3239 if (cmdmsg_rl) | |
3240 { | |
3241 screen_fill(msg_row, msg_row + 1, 0, msg_col + 1, ' ', ' ', 0); | |
3242 screen_fill(msg_row + 1, (int)Rows, 0, (int)Columns, ' ', ' ', 0); | |
3243 } | |
3244 else | |
3245 #endif | |
3246 { | |
3247 screen_fill(msg_row, msg_row + 1, msg_col, (int)Columns, | |
3248 ' ', ' ', 0); | |
3249 screen_fill(msg_row + 1, (int)Rows, 0, (int)Columns, ' ', ' ', 0); | |
3250 } | |
3251 } | |
3252 } | |
3253 | |
3254 /* | |
3255 * Clear the command line. | |
3256 */ | |
3257 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3258 msg_clr_cmdline(void) |
7 | 3259 { |
3260 msg_row = cmdline_row; | |
3261 msg_col = 0; | |
3262 msg_clr_eos_force(); | |
3263 } | |
3264 | |
3265 /* | |
3266 * end putting a message on the screen | |
3267 * call wait_return if the message does not fit in the available space | |
3268 * return TRUE if wait_return not called. | |
3269 */ | |
3270 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3271 msg_end(void) |
7 | 3272 { |
3273 /* | |
5245
8c6615a30951
updated for version 7.4a.047
Bram Moolenaar <bram@vim.org>
parents:
4793
diff
changeset
|
3274 * If the string is larger than the window, |
7 | 3275 * or the ruler option is set and we run into it, |
3276 * we have to redraw the window. | |
3277 * Do not do this if we are abandoning the file or editing the command line. | |
3278 */ | |
3279 if (!exiting && need_wait_return && !(State & CMDLINE)) | |
3280 { | |
3281 wait_return(FALSE); | |
3282 return FALSE; | |
3283 } | |
3284 out_flush(); | |
3285 return TRUE; | |
3286 } | |
3287 | |
3288 /* | |
3289 * If the written message runs into the shown command or ruler, we have to | |
3290 * wait for hit-return and redraw the window later. | |
3291 */ | |
3292 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3293 msg_check(void) |
7 | 3294 { |
3295 if (msg_row == Rows - 1 && msg_col >= sc_col) | |
3296 { | |
3297 need_wait_return = TRUE; | |
3298 redraw_cmdline = TRUE; | |
3299 } | |
3300 } | |
3301 | |
3302 /* | |
3303 * May write a string to the redirection file. | |
3304 * When "maxlen" is -1 write the whole string, otherwise up to "maxlen" bytes. | |
3305 */ | |
3306 static void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3307 redir_write(char_u *str, int maxlen) |
7 | 3308 { |
3309 char_u *s = str; | |
3310 static int cur_col = 0; | |
3311 | |
291 | 3312 /* Don't do anything for displaying prompts and the like. */ |
3313 if (redir_off) | |
3314 return; | |
3315 | |
3072 | 3316 /* If 'verbosefile' is set prepare for writing in that file. */ |
3317 if (*p_vfile != NUL && verbose_fd == NULL) | |
3318 verbose_open(); | |
291 | 3319 |
1854 | 3320 if (redirecting()) |
7 | 3321 { |
3322 /* If the string doesn't start with CR or NL, go to msg_col */ | |
3323 if (*s != '\n' && *s != '\r') | |
3324 { | |
3325 while (cur_col < msg_col) | |
3326 { | |
3327 #ifdef FEAT_EVAL | |
9454
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
3328 if (redir_execute) |
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
3329 execute_redir_str((char_u *)" ", -1); |
9436
f048e5a27253
commit https://github.com/vim/vim/commit/bc5d6dd1dd1dc3a06e4e655fc9479529db288365
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
3330 else if (redir_reg) |
7 | 3331 write_reg_contents(redir_reg, (char_u *)" ", -1, TRUE); |
167 | 3332 else if (redir_vname) |
3333 var_redir_str((char_u *)" ", -1); | |
3072 | 3334 else |
7 | 3335 #endif |
3072 | 3336 if (redir_fd != NULL) |
7 | 3337 fputs(" ", redir_fd); |
3072 | 3338 if (verbose_fd != NULL) |
3339 fputs(" ", verbose_fd); | |
7 | 3340 ++cur_col; |
3341 } | |
3342 } | |
3343 | |
3344 #ifdef FEAT_EVAL | |
9454
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
3345 if (redir_execute) |
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
3346 execute_redir_str(s, maxlen); |
9436
f048e5a27253
commit https://github.com/vim/vim/commit/bc5d6dd1dd1dc3a06e4e655fc9479529db288365
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
3347 else if (redir_reg) |
7 | 3348 write_reg_contents(redir_reg, s, maxlen, TRUE); |
9436
f048e5a27253
commit https://github.com/vim/vim/commit/bc5d6dd1dd1dc3a06e4e655fc9479529db288365
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
3349 else if (redir_vname) |
167 | 3350 var_redir_str(s, maxlen); |
7 | 3351 #endif |
3352 | |
3072 | 3353 /* Write and adjust the current column. */ |
7 | 3354 while (*s != NUL && (maxlen < 0 || (int)(s - str) < maxlen)) |
3355 { | |
3356 #ifdef FEAT_EVAL | |
9454
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
3357 if (!redir_reg && !redir_vname && !redir_execute) |
7 | 3358 #endif |
3072 | 3359 if (redir_fd != NULL) |
3360 putc(*s, redir_fd); | |
3361 if (verbose_fd != NULL) | |
3362 putc(*s, verbose_fd); | |
7 | 3363 if (*s == '\r' || *s == '\n') |
3364 cur_col = 0; | |
3365 else if (*s == '\t') | |
3366 cur_col += (8 - cur_col % 8); | |
3367 else | |
3368 ++cur_col; | |
3369 ++s; | |
3370 } | |
3371 | |
3372 if (msg_silent != 0) /* should update msg_col */ | |
3373 msg_col = cur_col; | |
3374 } | |
3375 } | |
3376 | |
1854 | 3377 int |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3378 redirecting(void) |
1854 | 3379 { |
3072 | 3380 return redir_fd != NULL || *p_vfile != NUL |
1854 | 3381 #ifdef FEAT_EVAL |
9454
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
3382 || redir_reg || redir_vname || redir_execute |
1854 | 3383 #endif |
3384 ; | |
3385 } | |
3386 | |
7 | 3387 /* |
1189 | 3388 * Before giving verbose message. |
291 | 3389 * Must always be called paired with verbose_leave()! |
3390 */ | |
3391 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3392 verbose_enter(void) |
291 | 3393 { |
3394 if (*p_vfile != NUL) | |
3395 ++msg_silent; | |
3396 } | |
3397 | |
3398 /* | |
3399 * After giving verbose message. | |
3400 * Must always be called paired with verbose_enter()! | |
3401 */ | |
3402 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3403 verbose_leave(void) |
291 | 3404 { |
3405 if (*p_vfile != NUL) | |
3406 if (--msg_silent < 0) | |
3407 msg_silent = 0; | |
3408 } | |
3409 | |
3410 /* | |
3411 * Like verbose_enter() and set msg_scroll when displaying the message. | |
3412 */ | |
3413 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3414 verbose_enter_scroll(void) |
291 | 3415 { |
3416 if (*p_vfile != NUL) | |
3417 ++msg_silent; | |
3418 else | |
3419 /* always scroll up, don't overwrite */ | |
3420 msg_scroll = TRUE; | |
3421 } | |
3422 | |
3423 /* | |
3424 * Like verbose_leave() and set cmdline_row when displaying the message. | |
3425 */ | |
3426 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3427 verbose_leave_scroll(void) |
291 | 3428 { |
3429 if (*p_vfile != NUL) | |
3430 { | |
3431 if (--msg_silent < 0) | |
3432 msg_silent = 0; | |
3433 } | |
3434 else | |
3435 cmdline_row = msg_row; | |
3436 } | |
3437 | |
3438 /* | |
3439 * Called when 'verbosefile' is set: stop writing to the file. | |
3440 */ | |
3441 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3442 verbose_stop(void) |
291 | 3443 { |
3444 if (verbose_fd != NULL) | |
3445 { | |
3446 fclose(verbose_fd); | |
3447 verbose_fd = NULL; | |
3448 } | |
3449 verbose_did_open = FALSE; | |
3450 } | |
3451 | |
3452 /* | |
3453 * Open the file 'verbosefile'. | |
3454 * Return FAIL or OK. | |
3455 */ | |
3456 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3457 verbose_open(void) |
291 | 3458 { |
3459 if (verbose_fd == NULL && !verbose_did_open) | |
3460 { | |
3461 /* Only give the error message once. */ | |
3462 verbose_did_open = TRUE; | |
3463 | |
531 | 3464 verbose_fd = mch_fopen((char *)p_vfile, "a"); |
291 | 3465 if (verbose_fd == NULL) |
3466 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3467 semsg(_(e_notopen), p_vfile); |
291 | 3468 return FAIL; |
3469 } | |
3470 } | |
3471 return OK; | |
3472 } | |
3473 | |
3474 /* | |
7 | 3475 * Give a warning message (for searching). |
3476 * Use 'w' highlighting and may repeat the message after redrawing | |
3477 */ | |
3478 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3479 give_warning(char_u *message, int hl) |
7 | 3480 { |
3481 /* Don't do this for ":silent". */ | |
3482 if (msg_silent != 0) | |
3483 return; | |
3484 | |
3485 /* Don't want a hit-enter prompt here. */ | |
3486 ++no_wait_return; | |
8 | 3487 |
7 | 3488 #ifdef FEAT_EVAL |
3489 set_vim_var_string(VV_WARNINGMSG, message, -1); | |
3490 #endif | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13188
diff
changeset
|
3491 VIM_CLEAR(keep_msg); |
7 | 3492 if (hl) |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
3493 keep_msg_attr = HL_ATTR(HLF_W); |
7 | 3494 else |
3495 keep_msg_attr = 0; | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
3496 if (msg_attr((char *)message, keep_msg_attr) && msg_scrolled == 0) |
678 | 3497 set_keep_msg(message, keep_msg_attr); |
7 | 3498 msg_didout = FALSE; /* overwrite this message */ |
3499 msg_nowait = TRUE; /* don't wait for this message */ | |
3500 msg_col = 0; | |
8 | 3501 |
7 | 3502 --no_wait_return; |
3503 } | |
3504 | |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15551
diff
changeset
|
3505 #if defined(FEAT_EVAL) || defined(PROTO) |
11561
7ad79766365a
patch 8.0.0663: unexpected error message only when 'verbose' is set
Christian Brabandt <cb@256bit.org>
parents:
11269
diff
changeset
|
3506 void |
7ad79766365a
patch 8.0.0663: unexpected error message only when 'verbose' is set
Christian Brabandt <cb@256bit.org>
parents:
11269
diff
changeset
|
3507 give_warning2(char_u *message, char_u *a1, int hl) |
7ad79766365a
patch 8.0.0663: unexpected error message only when 'verbose' is set
Christian Brabandt <cb@256bit.org>
parents:
11269
diff
changeset
|
3508 { |
7ad79766365a
patch 8.0.0663: unexpected error message only when 'verbose' is set
Christian Brabandt <cb@256bit.org>
parents:
11269
diff
changeset
|
3509 vim_snprintf((char *)IObuff, IOSIZE, (char *)message, a1); |
7ad79766365a
patch 8.0.0663: unexpected error message only when 'verbose' is set
Christian Brabandt <cb@256bit.org>
parents:
11269
diff
changeset
|
3510 give_warning(IObuff, hl); |
7ad79766365a
patch 8.0.0663: unexpected error message only when 'verbose' is set
Christian Brabandt <cb@256bit.org>
parents:
11269
diff
changeset
|
3511 } |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15551
diff
changeset
|
3512 #endif |
11561
7ad79766365a
patch 8.0.0663: unexpected error message only when 'verbose' is set
Christian Brabandt <cb@256bit.org>
parents:
11269
diff
changeset
|
3513 |
7 | 3514 /* |
3515 * Advance msg cursor to column "col". | |
3516 */ | |
3517 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3518 msg_advance(int col) |
7 | 3519 { |
3520 if (msg_silent != 0) /* nothing to advance to */ | |
3521 { | |
3522 msg_col = col; /* for redirection, may fill it up later */ | |
3523 return; | |
3524 } | |
3525 if (col >= Columns) /* not enough room */ | |
3526 col = Columns - 1; | |
474 | 3527 #ifdef FEAT_RIGHTLEFT |
3528 if (cmdmsg_rl) | |
3529 while (msg_col > Columns - col) | |
3530 msg_putchar(' '); | |
3531 else | |
3532 #endif | |
3533 while (msg_col < col) | |
3534 msg_putchar(' '); | |
7 | 3535 } |
3536 | |
3537 #if defined(FEAT_CON_DIALOG) || defined(PROTO) | |
3538 /* | |
3539 * Used for "confirm()" function, and the :confirm command prefix. | |
3540 * Versions which haven't got flexible dialogs yet, and console | |
3541 * versions, get this generic handler which uses the command line. | |
3542 * | |
3543 * type = one of: | |
3544 * VIM_QUESTION, VIM_INFO, VIM_WARNING, VIM_ERROR or VIM_GENERIC | |
3545 * title = title string (can be NULL for default) | |
3546 * (neither used in console dialogs at the moment) | |
3547 * | |
3548 * Format of the "buttons" string: | |
3549 * "Button1Name\nButton2Name\nButton3Name" | |
3550 * The first button should normally be the default/accept | |
3551 * The second button should be the 'Cancel' button | |
3552 * Other buttons- use your imagination! | |
3553 * A '&' in a button name becomes a shortcut, so each '&' should be before a | |
3554 * different letter. | |
3555 */ | |
3556 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3557 do_dialog( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3558 int type UNUSED, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3559 char_u *title UNUSED, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3560 char_u *message, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3561 char_u *buttons, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3562 int dfltbutton, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3563 char_u *textfield UNUSED, /* IObuff for inputdialog(), NULL |
1883 | 3564 otherwise */ |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3565 int ex_cmd) /* when TRUE pressing : accepts default and starts |
2684 | 3566 Ex command */ |
7 | 3567 { |
3568 int oldState; | |
3569 int retval = 0; | |
3570 char_u *hotkeys; | |
3571 int c; | |
3572 int i; | |
3573 | |
3574 #ifndef NO_CONSOLE | |
3575 /* Don't output anything in silent mode ("ex -s") */ | |
3576 if (silent_mode) | |
3577 return dfltbutton; /* return default option */ | |
3578 #endif | |
3579 | |
3580 #ifdef FEAT_GUI_DIALOG | |
3581 /* When GUI is running and 'c' not in 'guioptions', use the GUI dialog */ | |
3582 if (gui.in_use && vim_strchr(p_go, GO_CONDIALOG) == NULL) | |
3583 { | |
3584 c = gui_mch_dialog(type, title, message, buttons, dfltbutton, | |
2684 | 3585 textfield, ex_cmd); |
1809 | 3586 /* avoid a hit-enter prompt without clearing the cmdline */ |
3587 need_wait_return = FALSE; | |
3588 emsg_on_display = FALSE; | |
3589 cmdline_row = msg_row; | |
7 | 3590 |
3591 /* Flush output to avoid that further messages and redrawing is done | |
3592 * in the wrong order. */ | |
3593 out_flush(); | |
3594 gui_mch_update(); | |
3595 | |
3596 return c; | |
3597 } | |
3598 #endif | |
3599 | |
3600 oldState = State; | |
3601 State = CONFIRM; | |
3602 setmouse(); | |
3603 | |
3604 /* | |
3605 * Since we wait for a keypress, don't make the | |
3606 * user press RETURN as well afterwards. | |
3607 */ | |
3608 ++no_wait_return; | |
3609 hotkeys = msg_show_console_dialog(message, buttons, dfltbutton); | |
3610 | |
3611 if (hotkeys != NULL) | |
3612 { | |
3613 for (;;) | |
3614 { | |
3615 /* Get a typed character directly from the user. */ | |
3616 c = get_keystroke(); | |
3617 switch (c) | |
3618 { | |
3619 case CAR: /* User accepts default option */ | |
3620 case NL: | |
3621 retval = dfltbutton; | |
3622 break; | |
3623 case Ctrl_C: /* User aborts/cancels */ | |
3624 case ESC: | |
3625 retval = 0; | |
3626 break; | |
3627 default: /* Could be a hotkey? */ | |
3628 if (c < 0) /* special keys are ignored here */ | |
3629 continue; | |
2684 | 3630 if (c == ':' && ex_cmd) |
3631 { | |
3632 retval = dfltbutton; | |
3633 ins_char_typebuf(':'); | |
3634 break; | |
3635 } | |
3636 | |
7 | 3637 /* Make the character lowercase, as chars in "hotkeys" are. */ |
3638 c = MB_TOLOWER(c); | |
3639 retval = 1; | |
3640 for (i = 0; hotkeys[i]; ++i) | |
3641 { | |
3642 if (has_mbyte) | |
3643 { | |
3644 if ((*mb_ptr2char)(hotkeys + i) == c) | |
3645 break; | |
474 | 3646 i += (*mb_ptr2len)(hotkeys + i) - 1; |
7 | 3647 } |
3648 else | |
3649 if (hotkeys[i] == c) | |
3650 break; | |
3651 ++retval; | |
3652 } | |
3653 if (hotkeys[i]) | |
3654 break; | |
3655 /* No hotkey match, so keep waiting */ | |
3656 continue; | |
3657 } | |
3658 break; | |
3659 } | |
3660 | |
3661 vim_free(hotkeys); | |
3662 } | |
3663 | |
3664 State = oldState; | |
3665 setmouse(); | |
3666 --no_wait_return; | |
3667 msg_end_prompt(); | |
3668 | |
3669 return retval; | |
3670 } | |
3671 | |
3672 /* | |
3673 * Copy one character from "*from" to "*to", taking care of multi-byte | |
3674 * characters. Return the length of the character in bytes. | |
3675 */ | |
3676 static int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3677 copy_char( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3678 char_u *from, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3679 char_u *to, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3680 int lowercase) /* make character lower case */ |
7 | 3681 { |
3682 int len; | |
3683 int c; | |
3684 | |
3685 if (has_mbyte) | |
3686 { | |
3687 if (lowercase) | |
3688 { | |
3689 c = MB_TOLOWER((*mb_ptr2char)(from)); | |
3690 return (*mb_char2bytes)(c, to); | |
3691 } | |
3692 else | |
3693 { | |
474 | 3694 len = (*mb_ptr2len)(from); |
7 | 3695 mch_memmove(to, from, (size_t)len); |
3696 return len; | |
3697 } | |
3698 } | |
3699 else | |
3700 { | |
3701 if (lowercase) | |
3702 *to = (char_u)TOLOWER_LOC(*from); | |
3703 else | |
3704 *to = *from; | |
3705 return 1; | |
3706 } | |
3707 } | |
3708 | |
3709 /* | |
3710 * Format the dialog string, and display it at the bottom of | |
3711 * the screen. Return a string of hotkey chars (if defined) for | |
3712 * each 'button'. If a button has no hotkey defined, the first character of | |
3713 * the button is used. | |
3714 * The hotkeys can be multi-byte characters, but without combining chars. | |
3715 * | |
3716 * Returns an allocated string with hotkeys, or NULL for error. | |
3717 */ | |
3718 static char_u * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3719 msg_show_console_dialog( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3720 char_u *message, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3721 char_u *buttons, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3722 int dfltbutton) |
7 | 3723 { |
3724 int len = 0; | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
3725 #define HOTK_LEN (has_mbyte ? MB_MAXBYTES : 1) |
7 | 3726 int lenhotkey = HOTK_LEN; /* count first button */ |
3727 char_u *hotk = NULL; | |
3728 char_u *msgp = NULL; | |
3729 char_u *hotkp = NULL; | |
3730 char_u *r; | |
3731 int copy; | |
3732 #define HAS_HOTKEY_LEN 30 | |
3733 char_u has_hotkey[HAS_HOTKEY_LEN]; | |
3734 int first_hotkey = FALSE; /* first char of button is hotkey */ | |
3735 int idx; | |
3736 | |
3737 has_hotkey[0] = FALSE; | |
3738 | |
3739 /* | |
3740 * First loop: compute the size of memory to allocate. | |
3741 * Second loop: copy to the allocated memory. | |
3742 */ | |
3743 for (copy = 0; copy <= 1; ++copy) | |
3744 { | |
3745 r = buttons; | |
3746 idx = 0; | |
3747 while (*r) | |
3748 { | |
3749 if (*r == DLG_BUTTON_SEP) | |
3750 { | |
3751 if (copy) | |
3752 { | |
3753 *msgp++ = ','; | |
3754 *msgp++ = ' '; /* '\n' -> ', ' */ | |
3755 | |
3756 /* advance to next hotkey and set default hotkey */ | |
3757 if (has_mbyte) | |
1306 | 3758 hotkp += STRLEN(hotkp); |
7 | 3759 else |
3760 ++hotkp; | |
1306 | 3761 hotkp[copy_char(r + 1, hotkp, TRUE)] = NUL; |
7 | 3762 if (dfltbutton) |
3763 --dfltbutton; | |
3764 | |
3765 /* If no hotkey is specified first char is used. */ | |
3766 if (idx < HAS_HOTKEY_LEN - 1 && !has_hotkey[++idx]) | |
3767 first_hotkey = TRUE; | |
3768 } | |
3769 else | |
3770 { | |
3771 len += 3; /* '\n' -> ', '; 'x' -> '(x)' */ | |
3772 lenhotkey += HOTK_LEN; /* each button needs a hotkey */ | |
3773 if (idx < HAS_HOTKEY_LEN - 1) | |
3774 has_hotkey[++idx] = FALSE; | |
3775 } | |
3776 } | |
3777 else if (*r == DLG_HOTKEY_CHAR || first_hotkey) | |
3778 { | |
3779 if (*r == DLG_HOTKEY_CHAR) | |
3780 ++r; | |
3781 first_hotkey = FALSE; | |
3782 if (copy) | |
3783 { | |
3784 if (*r == DLG_HOTKEY_CHAR) /* '&&a' -> '&a' */ | |
3785 *msgp++ = *r; | |
3786 else | |
3787 { | |
3788 /* '&a' -> '[a]' */ | |
3789 *msgp++ = (dfltbutton == 1) ? '[' : '('; | |
3790 msgp += copy_char(r, msgp, FALSE); | |
3791 *msgp++ = (dfltbutton == 1) ? ']' : ')'; | |
3792 | |
3793 /* redefine hotkey */ | |
1306 | 3794 hotkp[copy_char(r, hotkp, TRUE)] = NUL; |
7 | 3795 } |
3796 } | |
3797 else | |
3798 { | |
3799 ++len; /* '&a' -> '[a]' */ | |
3800 if (idx < HAS_HOTKEY_LEN - 1) | |
3801 has_hotkey[idx] = TRUE; | |
3802 } | |
3803 } | |
3804 else | |
3805 { | |
3806 /* everything else copy literally */ | |
3807 if (copy) | |
3808 msgp += copy_char(r, msgp, FALSE); | |
3809 } | |
3810 | |
3811 /* advance to the next character */ | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11016
diff
changeset
|
3812 MB_PTR_ADV(r); |
7 | 3813 } |
3814 | |
3815 if (copy) | |
3816 { | |
3817 *msgp++ = ':'; | |
3818 *msgp++ = ' '; | |
3819 *msgp = NUL; | |
3820 } | |
3821 else | |
3822 { | |
835 | 3823 len += (int)(STRLEN(message) |
856 | 3824 + 2 /* for the NL's */ |
3825 + STRLEN(buttons) | |
3826 + 3); /* for the ": " and NUL */ | |
835 | 3827 lenhotkey++; /* for the NUL */ |
7 | 3828 |
3829 /* If no hotkey is specified first char is used. */ | |
3830 if (!has_hotkey[0]) | |
3831 { | |
3832 first_hotkey = TRUE; | |
3833 len += 2; /* "x" -> "[x]" */ | |
3834 } | |
3835 | |
3836 /* | |
3837 * Now allocate and load the strings | |
3838 */ | |
3839 vim_free(confirm_msg); | |
3840 confirm_msg = alloc(len); | |
3841 if (confirm_msg == NULL) | |
3842 return NULL; | |
3843 *confirm_msg = NUL; | |
3844 hotk = alloc(lenhotkey); | |
3845 if (hotk == NULL) | |
3846 return NULL; | |
3847 | |
3848 *confirm_msg = '\n'; | |
3849 STRCPY(confirm_msg + 1, message); | |
3850 | |
3851 msgp = confirm_msg + 1 + STRLEN(message); | |
3852 hotkp = hotk; | |
3853 | |
1306 | 3854 /* Define first default hotkey. Keep the hotkey string NUL |
3855 * terminated to avoid reading past the end. */ | |
3856 hotkp[copy_char(buttons, hotkp, TRUE)] = NUL; | |
7 | 3857 |
3858 /* Remember where the choices start, displaying starts here when | |
3859 * "hotkp" typed at the more prompt. */ | |
3860 confirm_msg_tail = msgp; | |
3861 *msgp++ = '\n'; | |
3862 } | |
3863 } | |
3864 | |
3865 display_confirm_msg(); | |
3866 return hotk; | |
3867 } | |
3868 | |
3869 /* | |
3870 * Display the ":confirm" message. Also called when screen resized. | |
3871 */ | |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
3872 static void |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3873 display_confirm_msg(void) |
7 | 3874 { |
3875 /* avoid that 'q' at the more prompt truncates the message here */ | |
3876 ++confirm_msg_used; | |
3877 if (confirm_msg != NULL) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
3878 msg_puts_attr((char *)confirm_msg, HL_ATTR(HLF_M)); |
7 | 3879 --confirm_msg_used; |
3880 } | |
3881 | |
3882 #endif /* FEAT_CON_DIALOG */ | |
3883 | |
3884 #if defined(FEAT_CON_DIALOG) || defined(FEAT_GUI_DIALOG) | |
3885 | |
3886 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3887 vim_dialog_yesno( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3888 int type, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3889 char_u *title, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3890 char_u *message, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3891 int dflt) |
7 | 3892 { |
3893 if (do_dialog(type, | |
3894 title == NULL ? (char_u *)_("Question") : title, | |
3895 message, | |
2684 | 3896 (char_u *)_("&Yes\n&No"), dflt, NULL, FALSE) == 1) |
7 | 3897 return VIM_YES; |
3898 return VIM_NO; | |
3899 } | |
3900 | |
3901 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3902 vim_dialog_yesnocancel( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3903 int type, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3904 char_u *title, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3905 char_u *message, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3906 int dflt) |
7 | 3907 { |
3908 switch (do_dialog(type, | |
3909 title == NULL ? (char_u *)_("Question") : title, | |
3910 message, | |
2684 | 3911 (char_u *)_("&Yes\n&No\n&Cancel"), dflt, NULL, FALSE)) |
7 | 3912 { |
3913 case 1: return VIM_YES; | |
3914 case 2: return VIM_NO; | |
3915 } | |
3916 return VIM_CANCEL; | |
3917 } | |
3918 | |
3919 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3920 vim_dialog_yesnoallcancel( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3921 int type, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3922 char_u *title, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3923 char_u *message, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3924 int dflt) |
7 | 3925 { |
3926 switch (do_dialog(type, | |
3927 title == NULL ? (char_u *)"Question" : title, | |
3928 message, | |
3929 (char_u *)_("&Yes\n&No\nSave &All\n&Discard All\n&Cancel"), | |
2684 | 3930 dflt, NULL, FALSE)) |
7 | 3931 { |
3932 case 1: return VIM_YES; | |
3933 case 2: return VIM_NO; | |
3934 case 3: return VIM_ALL; | |
3935 case 4: return VIM_DISCARDALL; | |
3936 } | |
3937 return VIM_CANCEL; | |
3938 } | |
3939 | |
3940 #endif /* FEAT_GUI_DIALOG || FEAT_CON_DIALOG */ | |
3941 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
3942 #if defined(FEAT_EVAL) |
449 | 3943 static char *e_printf = N_("E766: Insufficient arguments for printf()"); |
3944 | |
3945 /* | |
3946 * Get number argument from "idxp" entry in "tvs". First entry is 1. | |
3947 */ | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
3948 static varnumber_T |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3949 tv_nr(typval_T *tvs, int *idxp) |
449 | 3950 { |
3951 int idx = *idxp - 1; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
3952 varnumber_T n = 0; |
449 | 3953 int err = FALSE; |
3954 | |
3955 if (tvs[idx].v_type == VAR_UNKNOWN) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3956 emsg(_(e_printf)); |
449 | 3957 else |
3958 { | |
3959 ++*idxp; | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15079
diff
changeset
|
3960 n = tv_get_number_chk(&tvs[idx], &err); |
449 | 3961 if (err) |
3962 n = 0; | |
3963 } | |
3964 return n; | |
3965 } | |
3966 | |
3967 /* | |
3968 * Get string argument from "idxp" entry in "tvs". First entry is 1. | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15079
diff
changeset
|
3969 * If "tofree" is NULL tv_get_string_chk() is used. Some types (e.g. List) |
9892
41c5d59e7e10
commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents:
9698
diff
changeset
|
3970 * are not converted to a string. |
41c5d59e7e10
commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents:
9698
diff
changeset
|
3971 * If "tofree" is not NULL echo_string() is used. All types are converted to |
41c5d59e7e10
commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents:
9698
diff
changeset
|
3972 * a string with the same format as ":echo". The caller must free "*tofree". |
532 | 3973 * Returns NULL for an error. |
449 | 3974 */ |
3975 static char * | |
9892
41c5d59e7e10
commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents:
9698
diff
changeset
|
3976 tv_str(typval_T *tvs, int *idxp, char_u **tofree) |
449 | 3977 { |
9892
41c5d59e7e10
commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents:
9698
diff
changeset
|
3978 int idx = *idxp - 1; |
41c5d59e7e10
commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents:
9698
diff
changeset
|
3979 char *s = NULL; |
41c5d59e7e10
commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents:
9698
diff
changeset
|
3980 static char_u numbuf[NUMBUFLEN]; |
449 | 3981 |
3982 if (tvs[idx].v_type == VAR_UNKNOWN) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3983 emsg(_(e_printf)); |
449 | 3984 else |
3985 { | |
3986 ++*idxp; | |
9892
41c5d59e7e10
commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents:
9698
diff
changeset
|
3987 if (tofree != NULL) |
41c5d59e7e10
commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents:
9698
diff
changeset
|
3988 s = (char *)echo_string(&tvs[idx], tofree, numbuf, get_copyID()); |
41c5d59e7e10
commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents:
9698
diff
changeset
|
3989 else |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15079
diff
changeset
|
3990 s = (char *)tv_get_string_chk(&tvs[idx]); |
449 | 3991 } |
3992 return s; | |
3993 } | |
1619 | 3994 |
3995 # ifdef FEAT_FLOAT | |
3996 /* | |
3997 * Get float argument from "idxp" entry in "tvs". First entry is 1. | |
3998 */ | |
3999 static double | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4000 tv_float(typval_T *tvs, int *idxp) |
1619 | 4001 { |
4002 int idx = *idxp - 1; | |
4003 double f = 0; | |
4004 | |
4005 if (tvs[idx].v_type == VAR_UNKNOWN) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
4006 emsg(_(e_printf)); |
1619 | 4007 else |
4008 { | |
4009 ++*idxp; | |
4010 if (tvs[idx].v_type == VAR_FLOAT) | |
4011 f = tvs[idx].vval.v_float; | |
1656 | 4012 else if (tvs[idx].v_type == VAR_NUMBER) |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4013 f = (double)tvs[idx].vval.v_number; |
1619 | 4014 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
4015 emsg(_("E807: Expected Float argument for printf()")); |
1619 | 4016 } |
4017 return f; | |
4018 } | |
4019 # endif | |
449 | 4020 #endif |
4021 | |
10036
ab6320d74331
commit https://github.com/vim/vim/commit/7f7bd297d6d989254f71c694f1c72d07cbc5c306
Christian Brabandt <cb@256bit.org>
parents:
10015
diff
changeset
|
4022 #ifdef FEAT_FLOAT |
272 | 4023 /* |
10015
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4024 * Return the representation of infinity for printf() function: |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4025 * "-inf", "inf", "+inf", " inf", "-INF", "INF", "+INF" or " INF". |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4026 */ |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4027 static const char * |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4028 infinity_str(int positive, |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4029 char fmt_spec, |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4030 int force_sign, |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4031 int space_for_positive) |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4032 { |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4033 static const char *table[] = |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4034 { |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4035 "-inf", "inf", "+inf", " inf", |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4036 "-INF", "INF", "+INF", " INF" |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4037 }; |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4038 int idx = positive * (1 + force_sign + force_sign * space_for_positive); |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4039 |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4040 if (ASCII_ISUPPER(fmt_spec)) |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4041 idx += 4; |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4042 return table[idx]; |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4043 } |
10036
ab6320d74331
commit https://github.com/vim/vim/commit/7f7bd297d6d989254f71c694f1c72d07cbc5c306
Christian Brabandt <cb@256bit.org>
parents:
10015
diff
changeset
|
4044 #endif |
10015
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4045 |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4046 /* |
272 | 4047 * This code was included to provide a portable vsnprintf() and snprintf(). |
715 | 4048 * Some systems may provide their own, but we always use this one for |
272 | 4049 * consistency. |
4050 * | |
4051 * This code is based on snprintf.c - a portable implementation of snprintf | |
4052 * by Mark Martinec <mark.martinec@ijs.si>, Version 2.2, 2000-10-06. | |
1189 | 4053 * Included with permission. It was heavily modified to fit in Vim. |
272 | 4054 * The original code, including useful comments, can be found here: |
4055 * http://www.ijs.si/software/snprintf/ | |
4056 * | |
4057 * This snprintf() only supports the following conversion specifiers: | |
4058 * s, c, d, u, o, x, X, p (and synonyms: i, D, U, O - see below) | |
4059 * with flags: '-', '+', ' ', '0' and '#'. | |
4060 * An asterisk is supported for field width as well as precision. | |
4061 * | |
10038
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4062 * Limited support for floating point was added: 'f', 'F', 'e', 'E', 'g', 'G'. |
1619 | 4063 * |
10015
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4064 * Length modifiers 'h' (short int) and 'l' (long int) and 'll' (long long int) |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4065 * are supported. |
272 | 4066 * |
437 | 4067 * The locale is not used, the string is used as a byte string. This is only |
4068 * relevant for double-byte encodings where the second byte may be '%'. | |
4069 * | |
715 | 4070 * It is permitted for "str_m" to be zero, and it is permitted to specify NULL |
4071 * pointer for resulting string argument if "str_m" is zero (as per ISO C99). | |
272 | 4072 * |
4073 * The return value is the number of characters which would be generated | |
6448 | 4074 * for the given input, excluding the trailing NUL. If this value |
715 | 4075 * is greater or equal to "str_m", not all characters from the result |
4076 * have been stored in str, output bytes beyond the ("str_m"-1) -th character | |
4077 * are discarded. If "str_m" is greater than zero it is guaranteed | |
6448 | 4078 * the resulting string will be NUL-terminated. |
272 | 4079 */ |
4080 | |
4081 /* | |
4082 * When va_list is not supported we only define vim_snprintf(). | |
449 | 4083 * |
11653
67cf0d45b006
patch 8.0.0709: libvterm cannot use vsnprintf()
Christian Brabandt <cb@256bit.org>
parents:
11561
diff
changeset
|
4084 * vim_vsnprintf_typval() can be invoked with either "va_list" or a list of |
482 | 4085 * "typval_T". When the latter is not used it must be NULL. |
272 | 4086 */ |
4087 | |
4088 /* When generating prototypes all of this is skipped, cproto doesn't | |
4089 * understand this. */ | |
4090 #ifndef PROTO | |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
4091 |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
4092 /* Like vim_vsnprintf() but append to the string. */ |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
4093 int |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
4094 vim_snprintf_add(char *str, size_t str_m, const char *fmt, ...) |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
4095 { |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
4096 va_list ap; |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
4097 int str_l; |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
4098 size_t len = STRLEN(str); |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
4099 size_t space; |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
4100 |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
4101 if (str_m <= len) |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
4102 space = 0; |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
4103 else |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
4104 space = str_m - len; |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
4105 va_start(ap, fmt); |
11653
67cf0d45b006
patch 8.0.0709: libvterm cannot use vsnprintf()
Christian Brabandt <cb@256bit.org>
parents:
11561
diff
changeset
|
4106 str_l = vim_vsnprintf(str + len, space, fmt, ap); |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
4107 va_end(ap); |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
4108 return str_l; |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
4109 } |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
4110 |
272 | 4111 int |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
4112 vim_snprintf(char *str, size_t str_m, const char *fmt, ...) |
272 | 4113 { |
4114 va_list ap; | |
4115 int str_l; | |
4116 | |
4117 va_start(ap, fmt); | |
11653
67cf0d45b006
patch 8.0.0709: libvterm cannot use vsnprintf()
Christian Brabandt <cb@256bit.org>
parents:
11561
diff
changeset
|
4118 str_l = vim_vsnprintf(str, str_m, fmt, ap); |
272 | 4119 va_end(ap); |
4120 return str_l; | |
4121 } | |
4122 | |
449 | 4123 int |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4124 vim_vsnprintf( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4125 char *str, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4126 size_t str_m, |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
4127 const char *fmt, |
11653
67cf0d45b006
patch 8.0.0709: libvterm cannot use vsnprintf()
Christian Brabandt <cb@256bit.org>
parents:
11561
diff
changeset
|
4128 va_list ap) |
67cf0d45b006
patch 8.0.0709: libvterm cannot use vsnprintf()
Christian Brabandt <cb@256bit.org>
parents:
11561
diff
changeset
|
4129 { |
67cf0d45b006
patch 8.0.0709: libvterm cannot use vsnprintf()
Christian Brabandt <cb@256bit.org>
parents:
11561
diff
changeset
|
4130 return vim_vsnprintf_typval(str, str_m, fmt, ap, NULL); |
67cf0d45b006
patch 8.0.0709: libvterm cannot use vsnprintf()
Christian Brabandt <cb@256bit.org>
parents:
11561
diff
changeset
|
4131 } |
67cf0d45b006
patch 8.0.0709: libvterm cannot use vsnprintf()
Christian Brabandt <cb@256bit.org>
parents:
11561
diff
changeset
|
4132 |
67cf0d45b006
patch 8.0.0709: libvterm cannot use vsnprintf()
Christian Brabandt <cb@256bit.org>
parents:
11561
diff
changeset
|
4133 int |
67cf0d45b006
patch 8.0.0709: libvterm cannot use vsnprintf()
Christian Brabandt <cb@256bit.org>
parents:
11561
diff
changeset
|
4134 vim_vsnprintf_typval( |
67cf0d45b006
patch 8.0.0709: libvterm cannot use vsnprintf()
Christian Brabandt <cb@256bit.org>
parents:
11561
diff
changeset
|
4135 char *str, |
67cf0d45b006
patch 8.0.0709: libvterm cannot use vsnprintf()
Christian Brabandt <cb@256bit.org>
parents:
11561
diff
changeset
|
4136 size_t str_m, |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
4137 const char *fmt, |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4138 va_list ap, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4139 typval_T *tvs) |
272 | 4140 { |
4141 size_t str_l = 0; | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
4142 const char *p = fmt; |
272 | 4143 int arg_idx = 1; |
4144 | |
4145 if (p == NULL) | |
4146 p = ""; | |
4147 while (*p != NUL) | |
4148 { | |
4149 if (*p != '%') | |
4150 { | |
4151 char *q = strchr(p + 1, '%'); | |
1883 | 4152 size_t n = (q == NULL) ? STRLEN(p) : (size_t)(q - p); |
272 | 4153 |
437 | 4154 /* Copy up to the next '%' or NUL without any changes. */ |
272 | 4155 if (str_l < str_m) |
4156 { | |
4157 size_t avail = str_m - str_l; | |
4158 | |
4159 mch_memmove(str + str_l, p, n > avail ? avail : n); | |
4160 } | |
4161 p += n; | |
4162 str_l += n; | |
4163 } | |
4164 else | |
4165 { | |
4166 size_t min_field_width = 0, precision = 0; | |
4167 int zero_padding = 0, precision_specified = 0, justify_left = 0; | |
4168 int alternate_form = 0, force_sign = 0; | |
4169 | |
4170 /* If both the ' ' and '+' flags appear, the ' ' flag should be | |
4171 * ignored. */ | |
4172 int space_for_positive = 1; | |
4173 | |
4174 /* allowed values: \0, h, l, L */ | |
4175 char length_modifier = '\0'; | |
4176 | |
4177 /* temporary buffer for simple numeric->string conversion */ | |
9894
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4178 # if defined(FEAT_FLOAT) |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
4179 # define TMP_LEN 350 /* On my system 1e308 is the biggest number possible. |
1619 | 4180 * That sounds reasonable to use as the maximum |
4181 * printable. */ | |
9894
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4182 # elif defined(FEAT_NUM64) |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4183 # define TMP_LEN 66 |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
4184 # else |
9894
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4185 # define TMP_LEN 34 |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
4186 # endif |
1619 | 4187 char tmp[TMP_LEN]; |
272 | 4188 |
4189 /* string address in case of string argument */ | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
4190 const char *str_arg = NULL; |
272 | 4191 |
4192 /* natural field width of arg without padding and sign */ | |
4193 size_t str_arg_l; | |
4194 | |
4195 /* unsigned char argument value - only defined for c conversion. | |
4196 * N.B. standard explicitly states the char argument for the c | |
4197 * conversion is unsigned */ | |
4198 unsigned char uchar_arg; | |
4199 | |
4200 /* number of zeros to be inserted for numeric conversions as | |
4201 * required by the precision or minimal field width */ | |
4202 size_t number_of_zeros_to_pad = 0; | |
4203 | |
4204 /* index into tmp where zero padding is to be inserted */ | |
4205 size_t zero_padding_insertion_ind = 0; | |
4206 | |
4207 /* current conversion specifier character */ | |
4208 char fmt_spec = '\0'; | |
4209 | |
9892
41c5d59e7e10
commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents:
9698
diff
changeset
|
4210 /* buffer for 's' and 'S' specs */ |
41c5d59e7e10
commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents:
9698
diff
changeset
|
4211 char_u *tofree = NULL; |
41c5d59e7e10
commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents:
9698
diff
changeset
|
4212 |
41c5d59e7e10
commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents:
9698
diff
changeset
|
4213 |
272 | 4214 p++; /* skip '%' */ |
4215 | |
4216 /* parse flags */ | |
4217 while (*p == '0' || *p == '-' || *p == '+' || *p == ' ' | |
4218 || *p == '#' || *p == '\'') | |
4219 { | |
4220 switch (*p) | |
4221 { | |
4222 case '0': zero_padding = 1; break; | |
4223 case '-': justify_left = 1; break; | |
4224 case '+': force_sign = 1; space_for_positive = 0; break; | |
4225 case ' ': force_sign = 1; | |
4226 /* If both the ' ' and '+' flags appear, the ' ' | |
4227 * flag should be ignored */ | |
4228 break; | |
4229 case '#': alternate_form = 1; break; | |
4230 case '\'': break; | |
4231 } | |
4232 p++; | |
4233 } | |
4234 /* If the '0' and '-' flags both appear, the '0' flag should be | |
4235 * ignored. */ | |
4236 | |
4237 /* parse field width */ | |
4238 if (*p == '*') | |
4239 { | |
4240 int j; | |
4241 | |
4242 p++; | |
449 | 4243 j = |
4244 # if defined(FEAT_EVAL) | |
482 | 4245 tvs != NULL ? tv_nr(tvs, &arg_idx) : |
449 | 4246 # endif |
4247 va_arg(ap, int); | |
272 | 4248 if (j >= 0) |
4249 min_field_width = j; | |
4250 else | |
4251 { | |
4252 min_field_width = -j; | |
4253 justify_left = 1; | |
4254 } | |
4255 } | |
4256 else if (VIM_ISDIGIT((int)(*p))) | |
4257 { | |
4258 /* size_t could be wider than unsigned int; make sure we treat | |
4259 * argument like common implementations do */ | |
4260 unsigned int uj = *p++ - '0'; | |
4261 | |
4262 while (VIM_ISDIGIT((int)(*p))) | |
4263 uj = 10 * uj + (unsigned int)(*p++ - '0'); | |
4264 min_field_width = uj; | |
4265 } | |
4266 | |
4267 /* parse precision */ | |
4268 if (*p == '.') | |
4269 { | |
4270 p++; | |
4271 precision_specified = 1; | |
4272 if (*p == '*') | |
4273 { | |
4274 int j; | |
4275 | |
449 | 4276 j = |
4277 # if defined(FEAT_EVAL) | |
482 | 4278 tvs != NULL ? tv_nr(tvs, &arg_idx) : |
449 | 4279 # endif |
4280 va_arg(ap, int); | |
272 | 4281 p++; |
4282 if (j >= 0) | |
4283 precision = j; | |
4284 else | |
4285 { | |
4286 precision_specified = 0; | |
4287 precision = 0; | |
4288 } | |
4289 } | |
4290 else if (VIM_ISDIGIT((int)(*p))) | |
4291 { | |
4292 /* size_t could be wider than unsigned int; make sure we | |
4293 * treat argument like common implementations do */ | |
4294 unsigned int uj = *p++ - '0'; | |
4295 | |
4296 while (VIM_ISDIGIT((int)(*p))) | |
4297 uj = 10 * uj + (unsigned int)(*p++ - '0'); | |
4298 precision = uj; | |
4299 } | |
4300 } | |
4301 | |
4302 /* parse 'h', 'l' and 'll' length modifiers */ | |
4303 if (*p == 'h' || *p == 'l') | |
4304 { | |
4305 length_modifier = *p; | |
4306 p++; | |
4307 if (length_modifier == 'l' && *p == 'l') | |
4308 { | |
4309 /* double l = long long */ | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4310 # ifdef FEAT_NUM64 |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4311 length_modifier = 'L'; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4312 # else |
272 | 4313 length_modifier = 'l'; /* treat it as a single 'l' */ |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4314 # endif |
272 | 4315 p++; |
4316 } | |
4317 } | |
4318 fmt_spec = *p; | |
4319 | |
4320 /* common synonyms: */ | |
4321 switch (fmt_spec) | |
4322 { | |
4323 case 'i': fmt_spec = 'd'; break; | |
4324 case 'D': fmt_spec = 'd'; length_modifier = 'l'; break; | |
4325 case 'U': fmt_spec = 'u'; length_modifier = 'l'; break; | |
4326 case 'O': fmt_spec = 'o'; length_modifier = 'l'; break; | |
4327 default: break; | |
4328 } | |
4329 | |
9497
d18d71ae21e5
commit https://github.com/vim/vim/commit/38ee6b041e73ad31c3b6b99d56d20833b59b2b57
Christian Brabandt <cb@256bit.org>
parents:
9454
diff
changeset
|
4330 # if defined(FEAT_EVAL) && defined(FEAT_NUM64) |
d18d71ae21e5
commit https://github.com/vim/vim/commit/38ee6b041e73ad31c3b6b99d56d20833b59b2b57
Christian Brabandt <cb@256bit.org>
parents:
9454
diff
changeset
|
4331 switch (fmt_spec) |
d18d71ae21e5
commit https://github.com/vim/vim/commit/38ee6b041e73ad31c3b6b99d56d20833b59b2b57
Christian Brabandt <cb@256bit.org>
parents:
9454
diff
changeset
|
4332 { |
d18d71ae21e5
commit https://github.com/vim/vim/commit/38ee6b041e73ad31c3b6b99d56d20833b59b2b57
Christian Brabandt <cb@256bit.org>
parents:
9454
diff
changeset
|
4333 case 'd': case 'u': case 'o': case 'x': case 'X': |
d18d71ae21e5
commit https://github.com/vim/vim/commit/38ee6b041e73ad31c3b6b99d56d20833b59b2b57
Christian Brabandt <cb@256bit.org>
parents:
9454
diff
changeset
|
4334 if (tvs != NULL && length_modifier == '\0') |
d18d71ae21e5
commit https://github.com/vim/vim/commit/38ee6b041e73ad31c3b6b99d56d20833b59b2b57
Christian Brabandt <cb@256bit.org>
parents:
9454
diff
changeset
|
4335 length_modifier = 'L'; |
d18d71ae21e5
commit https://github.com/vim/vim/commit/38ee6b041e73ad31c3b6b99d56d20833b59b2b57
Christian Brabandt <cb@256bit.org>
parents:
9454
diff
changeset
|
4336 } |
d18d71ae21e5
commit https://github.com/vim/vim/commit/38ee6b041e73ad31c3b6b99d56d20833b59b2b57
Christian Brabandt <cb@256bit.org>
parents:
9454
diff
changeset
|
4337 # endif |
d18d71ae21e5
commit https://github.com/vim/vim/commit/38ee6b041e73ad31c3b6b99d56d20833b59b2b57
Christian Brabandt <cb@256bit.org>
parents:
9454
diff
changeset
|
4338 |
272 | 4339 /* get parameter value, do initial processing */ |
4340 switch (fmt_spec) | |
4341 { | |
4342 /* '%' and 'c' behave similar to 's' regarding flags and field | |
4343 * widths */ | |
4344 case '%': | |
4345 case 'c': | |
4346 case 's': | |
3914 | 4347 case 'S': |
272 | 4348 str_arg_l = 1; |
4349 switch (fmt_spec) | |
4350 { | |
4351 case '%': | |
4352 str_arg = p; | |
4353 break; | |
4354 | |
4355 case 'c': | |
4356 { | |
4357 int j; | |
449 | 4358 |
4359 j = | |
4360 # if defined(FEAT_EVAL) | |
482 | 4361 tvs != NULL ? tv_nr(tvs, &arg_idx) : |
449 | 4362 # endif |
4363 va_arg(ap, int); | |
272 | 4364 /* standard demands unsigned char */ |
4365 uchar_arg = (unsigned char)j; | |
4366 str_arg = (char *)&uchar_arg; | |
4367 break; | |
4368 } | |
4369 | |
4370 case 's': | |
3914 | 4371 case 'S': |
449 | 4372 str_arg = |
4373 # if defined(FEAT_EVAL) | |
9892
41c5d59e7e10
commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents:
9698
diff
changeset
|
4374 tvs != NULL ? tv_str(tvs, &arg_idx, &tofree) : |
449 | 4375 # endif |
4376 va_arg(ap, char *); | |
272 | 4377 if (str_arg == NULL) |
4378 { | |
4379 str_arg = "[NULL]"; | |
4380 str_arg_l = 6; | |
4381 } | |
4382 /* make sure not to address string beyond the specified | |
4383 * precision !!! */ | |
4384 else if (!precision_specified) | |
4385 str_arg_l = strlen(str_arg); | |
4386 /* truncate string if necessary as requested by precision */ | |
4387 else if (precision == 0) | |
4388 str_arg_l = 0; | |
4389 else | |
4390 { | |
881 | 4391 /* Don't put the #if inside memchr(), it can be a |
4392 * macro. */ | |
272 | 4393 /* memchr on HP does not like n > 2^31 !!! */ |
4394 char *q = memchr(str_arg, '\0', | |
881 | 4395 precision <= (size_t)0x7fffffffL ? precision |
4396 : (size_t)0x7fffffffL); | |
1883 | 4397 str_arg_l = (q == NULL) ? precision |
4398 : (size_t)(q - str_arg); | |
272 | 4399 } |
3914 | 4400 if (fmt_spec == 'S') |
4401 { | |
4402 if (min_field_width != 0) | |
4403 min_field_width += STRLEN(str_arg) | |
4404 - mb_string2cells((char_u *)str_arg, -1); | |
4405 if (precision) | |
4406 { | |
18176
dfe9db84e326
patch 8.1.2083: multi-byte chars do not work properly with "%.*S" in printf()
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
4407 char_u *p1; |
dfe9db84e326
patch 8.1.2083: multi-byte chars do not work properly with "%.*S" in printf()
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
4408 size_t i = 0; |
dfe9db84e326
patch 8.1.2083: multi-byte chars do not work properly with "%.*S" in printf()
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
4409 |
dfe9db84e326
patch 8.1.2083: multi-byte chars do not work properly with "%.*S" in printf()
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
4410 for (p1 = (char_u *)str_arg; *p1; |
dfe9db84e326
patch 8.1.2083: multi-byte chars do not work properly with "%.*S" in printf()
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
4411 p1 += mb_ptr2len(p1)) |
dfe9db84e326
patch 8.1.2083: multi-byte chars do not work properly with "%.*S" in printf()
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
4412 { |
dfe9db84e326
patch 8.1.2083: multi-byte chars do not work properly with "%.*S" in printf()
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
4413 i += (size_t)mb_ptr2cells(p1); |
dfe9db84e326
patch 8.1.2083: multi-byte chars do not work properly with "%.*S" in printf()
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
4414 if (i > precision) |
dfe9db84e326
patch 8.1.2083: multi-byte chars do not work properly with "%.*S" in printf()
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
4415 break; |
dfe9db84e326
patch 8.1.2083: multi-byte chars do not work properly with "%.*S" in printf()
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
4416 } |
3914 | 4417 str_arg_l = precision = p1 - (char_u *)str_arg; |
4418 } | |
4419 } | |
272 | 4420 break; |
4421 | |
4422 default: | |
4423 break; | |
4424 } | |
4425 break; | |
4426 | |
9894
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4427 case 'd': case 'u': |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4428 case 'b': case 'B': |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4429 case 'o': |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4430 case 'x': case 'X': |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4431 case 'p': |
272 | 4432 { |
9894
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4433 /* NOTE: the u, b, o, x, X and p conversion specifiers |
272 | 4434 * imply the value is unsigned; d implies a signed |
4435 * value */ | |
4436 | |
4437 /* 0 if numeric argument is zero (or if pointer is | |
4438 * NULL for 'p'), +1 if greater than zero (or nonzero | |
4439 * for unsigned arguments), -1 if negative (unsigned | |
4440 * argument is never negative) */ | |
4441 int arg_sign = 0; | |
4442 | |
4443 /* only defined for length modifier h, or for no | |
4444 * length modifiers */ | |
4445 int int_arg = 0; | |
4446 unsigned int uint_arg = 0; | |
4447 | |
4448 /* only defined for length modifier l */ | |
4449 long int long_arg = 0; | |
4450 unsigned long int ulong_arg = 0; | |
4451 | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4452 # ifdef FEAT_NUM64 |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4453 /* only defined for length modifier ll */ |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4454 varnumber_T llong_arg = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4455 uvarnumber_T ullong_arg = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4456 # endif |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4457 |
10015
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4458 /* only defined for b conversion */ |
9894
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4459 uvarnumber_T bin_arg = 0; |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4460 |
272 | 4461 /* pointer argument value -only defined for p |
4462 * conversion */ | |
4463 void *ptr_arg = NULL; | |
4464 | |
4465 if (fmt_spec == 'p') | |
4466 { | |
4467 length_modifier = '\0'; | |
449 | 4468 ptr_arg = |
4469 # if defined(FEAT_EVAL) | |
9892
41c5d59e7e10
commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents:
9698
diff
changeset
|
4470 tvs != NULL ? (void *)tv_str(tvs, &arg_idx, |
41c5d59e7e10
commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents:
9698
diff
changeset
|
4471 NULL) : |
449 | 4472 # endif |
4473 va_arg(ap, void *); | |
272 | 4474 if (ptr_arg != NULL) |
4475 arg_sign = 1; | |
4476 } | |
9894
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4477 else if (fmt_spec == 'b' || fmt_spec == 'B') |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4478 { |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4479 bin_arg = |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4480 # if defined(FEAT_EVAL) |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4481 tvs != NULL ? |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4482 (uvarnumber_T)tv_nr(tvs, &arg_idx) : |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4483 # endif |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4484 va_arg(ap, uvarnumber_T); |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4485 if (bin_arg != 0) |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4486 arg_sign = 1; |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4487 } |
272 | 4488 else if (fmt_spec == 'd') |
4489 { | |
4490 /* signed */ | |
4491 switch (length_modifier) | |
4492 { | |
4493 case '\0': | |
4494 case 'h': | |
449 | 4495 /* char and short arguments are passed as int. */ |
4496 int_arg = | |
4497 # if defined(FEAT_EVAL) | |
482 | 4498 tvs != NULL ? tv_nr(tvs, &arg_idx) : |
449 | 4499 # endif |
4500 va_arg(ap, int); | |
272 | 4501 if (int_arg > 0) |
4502 arg_sign = 1; | |
4503 else if (int_arg < 0) | |
4504 arg_sign = -1; | |
4505 break; | |
4506 case 'l': | |
449 | 4507 long_arg = |
4508 # if defined(FEAT_EVAL) | |
482 | 4509 tvs != NULL ? tv_nr(tvs, &arg_idx) : |
449 | 4510 # endif |
4511 va_arg(ap, long int); | |
272 | 4512 if (long_arg > 0) |
4513 arg_sign = 1; | |
4514 else if (long_arg < 0) | |
4515 arg_sign = -1; | |
4516 break; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4517 # ifdef FEAT_NUM64 |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4518 case 'L': |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4519 llong_arg = |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4520 # if defined(FEAT_EVAL) |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4521 tvs != NULL ? tv_nr(tvs, &arg_idx) : |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4522 # endif |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4523 va_arg(ap, varnumber_T); |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4524 if (llong_arg > 0) |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4525 arg_sign = 1; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4526 else if (llong_arg < 0) |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4527 arg_sign = -1; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4528 break; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4529 # endif |
272 | 4530 } |
4531 } | |
4532 else | |
4533 { | |
4534 /* unsigned */ | |
4535 switch (length_modifier) | |
4536 { | |
4537 case '\0': | |
4538 case 'h': | |
449 | 4539 uint_arg = |
4540 # if defined(FEAT_EVAL) | |
1883 | 4541 tvs != NULL ? (unsigned) |
4542 tv_nr(tvs, &arg_idx) : | |
449 | 4543 # endif |
4544 va_arg(ap, unsigned int); | |
272 | 4545 if (uint_arg != 0) |
4546 arg_sign = 1; | |
4547 break; | |
4548 case 'l': | |
449 | 4549 ulong_arg = |
4550 # if defined(FEAT_EVAL) | |
1883 | 4551 tvs != NULL ? (unsigned long) |
4552 tv_nr(tvs, &arg_idx) : | |
449 | 4553 # endif |
4554 va_arg(ap, unsigned long int); | |
272 | 4555 if (ulong_arg != 0) |
4556 arg_sign = 1; | |
4557 break; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4558 # ifdef FEAT_NUM64 |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4559 case 'L': |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4560 ullong_arg = |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4561 # if defined(FEAT_EVAL) |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4562 tvs != NULL ? (uvarnumber_T) |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4563 tv_nr(tvs, &arg_idx) : |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4564 # endif |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4565 va_arg(ap, uvarnumber_T); |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4566 if (ullong_arg != 0) |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4567 arg_sign = 1; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4568 break; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4569 # endif |
272 | 4570 } |
4571 } | |
4572 | |
4573 str_arg = tmp; | |
4574 str_arg_l = 0; | |
4575 | |
4576 /* NOTE: | |
4577 * For d, i, u, o, x, and X conversions, if precision is | |
4578 * specified, the '0' flag should be ignored. This is so | |
4579 * with Solaris 2.6, Digital UNIX 4.0, HPUX 10, Linux, | |
4580 * FreeBSD, NetBSD; but not with Perl. | |
4581 */ | |
4582 if (precision_specified) | |
4583 zero_padding = 0; | |
4584 if (fmt_spec == 'd') | |
4585 { | |
4586 if (force_sign && arg_sign >= 0) | |
4587 tmp[str_arg_l++] = space_for_positive ? ' ' : '+'; | |
4588 /* leave negative numbers for sprintf to handle, to | |
4589 * avoid handling tricky cases like (short int)-32768 */ | |
4590 } | |
4591 else if (alternate_form) | |
4592 { | |
4593 if (arg_sign != 0 | |
9894
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4594 && (fmt_spec == 'b' || fmt_spec == 'B' |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4595 || fmt_spec == 'x' || fmt_spec == 'X') ) |
272 | 4596 { |
4597 tmp[str_arg_l++] = '0'; | |
4598 tmp[str_arg_l++] = fmt_spec; | |
4599 } | |
4600 /* alternate form should have no effect for p | |
4601 * conversion, but ... */ | |
4602 } | |
4603 | |
4604 zero_padding_insertion_ind = str_arg_l; | |
4605 if (!precision_specified) | |
4606 precision = 1; /* default precision is 1 */ | |
4607 if (precision == 0 && arg_sign == 0) | |
4608 { | |
4609 /* When zero value is formatted with an explicit | |
4610 * precision 0, the resulting formatted string is | |
9894
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4611 * empty (d, i, u, b, B, o, x, X, p). */ |
272 | 4612 } |
4613 else | |
4614 { | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4615 char f[6]; |
272 | 4616 int f_l = 0; |
4617 | |
4618 /* construct a simple format string for sprintf */ | |
4619 f[f_l++] = '%'; | |
4620 if (!length_modifier) | |
4621 ; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4622 else if (length_modifier == 'L') |
272 | 4623 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4624 # ifdef FEAT_NUM64 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15840
diff
changeset
|
4625 # ifdef MSWIN |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4626 f[f_l++] = 'I'; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4627 f[f_l++] = '6'; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4628 f[f_l++] = '4'; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4629 # else |
272 | 4630 f[f_l++] = 'l'; |
4631 f[f_l++] = 'l'; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4632 # endif |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4633 # else |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4634 f[f_l++] = 'l'; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4635 # endif |
272 | 4636 } |
4637 else | |
4638 f[f_l++] = length_modifier; | |
4639 f[f_l++] = fmt_spec; | |
4640 f[f_l++] = '\0'; | |
4641 | |
4642 if (fmt_spec == 'p') | |
4643 str_arg_l += sprintf(tmp + str_arg_l, f, ptr_arg); | |
9894
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4644 else if (fmt_spec == 'b' || fmt_spec == 'B') |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4645 { |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4646 char b[8 * sizeof(uvarnumber_T)]; |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4647 size_t b_l = 0; |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4648 uvarnumber_T bn = bin_arg; |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4649 |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4650 do |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4651 { |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4652 b[sizeof(b) - ++b_l] = '0' + (bn & 0x1); |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4653 bn >>= 1; |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4654 } |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4655 while (bn != 0); |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4656 |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4657 memcpy(tmp + str_arg_l, b + sizeof(b) - b_l, b_l); |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4658 str_arg_l += b_l; |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4659 } |
272 | 4660 else if (fmt_spec == 'd') |
4661 { | |
4662 /* signed */ | |
4663 switch (length_modifier) | |
4664 { | |
4665 case '\0': | |
4666 case 'h': str_arg_l += sprintf( | |
4667 tmp + str_arg_l, f, int_arg); | |
4668 break; | |
4669 case 'l': str_arg_l += sprintf( | |
4670 tmp + str_arg_l, f, long_arg); | |
4671 break; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4672 # ifdef FEAT_NUM64 |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4673 case 'L': str_arg_l += sprintf( |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4674 tmp + str_arg_l, f, llong_arg); |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4675 break; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4676 # endif |
272 | 4677 } |
4678 } | |
4679 else | |
4680 { | |
4681 /* unsigned */ | |
4682 switch (length_modifier) | |
4683 { | |
4684 case '\0': | |
4685 case 'h': str_arg_l += sprintf( | |
4686 tmp + str_arg_l, f, uint_arg); | |
4687 break; | |
4688 case 'l': str_arg_l += sprintf( | |
4689 tmp + str_arg_l, f, ulong_arg); | |
4690 break; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4691 # ifdef FEAT_NUM64 |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4692 case 'L': str_arg_l += sprintf( |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4693 tmp + str_arg_l, f, ullong_arg); |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4694 break; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4695 # endif |
272 | 4696 } |
4697 } | |
4698 | |
4699 /* include the optional minus sign and possible | |
4700 * "0x" in the region before the zero padding | |
4701 * insertion point */ | |
4702 if (zero_padding_insertion_ind < str_arg_l | |
4703 && tmp[zero_padding_insertion_ind] == '-') | |
4704 zero_padding_insertion_ind++; | |
4705 if (zero_padding_insertion_ind + 1 < str_arg_l | |
4706 && tmp[zero_padding_insertion_ind] == '0' | |
4707 && (tmp[zero_padding_insertion_ind + 1] == 'x' | |
4708 || tmp[zero_padding_insertion_ind + 1] == 'X')) | |
4709 zero_padding_insertion_ind += 2; | |
4710 } | |
4711 | |
4712 { | |
4713 size_t num_of_digits = str_arg_l | |
4714 - zero_padding_insertion_ind; | |
4715 | |
4716 if (alternate_form && fmt_spec == 'o' | |
4717 /* unless zero is already the first | |
4718 * character */ | |
4719 && !(zero_padding_insertion_ind < str_arg_l | |
4720 && tmp[zero_padding_insertion_ind] == '0')) | |
4721 { | |
4722 /* assure leading zero for alternate-form | |
4723 * octal numbers */ | |
4724 if (!precision_specified | |
4725 || precision < num_of_digits + 1) | |
4726 { | |
4727 /* precision is increased to force the | |
4728 * first character to be zero, except if a | |
4729 * zero value is formatted with an | |
4730 * explicit precision of zero */ | |
4731 precision = num_of_digits + 1; | |
4732 } | |
4733 } | |
4734 /* zero padding to specified precision? */ | |
4735 if (num_of_digits < precision) | |
4736 number_of_zeros_to_pad = precision - num_of_digits; | |
4737 } | |
4738 /* zero padding to specified minimal field width? */ | |
4739 if (!justify_left && zero_padding) | |
4740 { | |
835 | 4741 int n = (int)(min_field_width - (str_arg_l |
4742 + number_of_zeros_to_pad)); | |
272 | 4743 if (n > 0) |
4744 number_of_zeros_to_pad += n; | |
4745 } | |
4746 break; | |
4747 } | |
4748 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
4749 # ifdef FEAT_FLOAT |
1619 | 4750 case 'f': |
10038
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4751 case 'F': |
1619 | 4752 case 'e': |
4753 case 'E': | |
4754 case 'g': | |
4755 case 'G': | |
4756 { | |
4757 /* Floating point. */ | |
4758 double f; | |
4759 double abs_f; | |
4760 char format[40]; | |
4761 int l; | |
4762 int remove_trailing_zeroes = FALSE; | |
4763 | |
4764 f = | |
4765 # if defined(FEAT_EVAL) | |
4766 tvs != NULL ? tv_float(tvs, &arg_idx) : | |
4767 # endif | |
4768 va_arg(ap, double); | |
4769 abs_f = f < 0 ? -f : f; | |
4770 | |
4771 if (fmt_spec == 'g' || fmt_spec == 'G') | |
4772 { | |
4773 /* Would be nice to use %g directly, but it prints | |
4774 * "1.0" as "1", we don't want that. */ | |
4775 if ((abs_f >= 0.001 && abs_f < 10000000.0) | |
4776 || abs_f == 0.0) | |
10038
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4777 fmt_spec = ASCII_ISUPPER(fmt_spec) ? 'F' : 'f'; |
1619 | 4778 else |
4779 fmt_spec = fmt_spec == 'g' ? 'e' : 'E'; | |
4780 remove_trailing_zeroes = TRUE; | |
4781 } | |
4782 | |
10038
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4783 if ((fmt_spec == 'f' || fmt_spec == 'F') && |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
4784 # ifdef VAX |
1783 | 4785 abs_f > 1.0e38 |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
4786 # else |
1783 | 4787 abs_f > 1.0e307 |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
4788 # endif |
1783 | 4789 ) |
1619 | 4790 { |
4791 /* Avoid a buffer overflow */ | |
10015
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4792 STRCPY(tmp, infinity_str(f > 0.0, fmt_spec, |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4793 force_sign, space_for_positive)); |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4794 str_arg_l = STRLEN(tmp); |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4795 zero_padding = 0; |
1619 | 4796 } |
4797 else | |
4798 { | |
10015
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4799 if (isnan(f)) |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4800 { |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4801 /* Not a number: nan or NAN */ |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4802 STRCPY(tmp, ASCII_ISUPPER(fmt_spec) ? "NAN" |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4803 : "nan"); |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4804 str_arg_l = 3; |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4805 zero_padding = 0; |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4806 } |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4807 else if (isinf(f)) |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4808 { |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4809 STRCPY(tmp, infinity_str(f > 0.0, fmt_spec, |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4810 force_sign, space_for_positive)); |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4811 str_arg_l = STRLEN(tmp); |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4812 zero_padding = 0; |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4813 } |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4814 else |
13188
a49a5419a83f
patch 8.0.1468: illegal memory access in del_bytes()
Christian Brabandt <cb@256bit.org>
parents:
13150
diff
changeset
|
4815 { |
10015
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4816 /* Regular float number */ |
10038
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4817 format[0] = '%'; |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4818 l = 1; |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4819 if (force_sign) |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4820 format[l++] = space_for_positive ? ' ' : '+'; |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4821 if (precision_specified) |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4822 { |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4823 size_t max_prec = TMP_LEN - 10; |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4824 |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4825 /* Make sure we don't get more digits than we |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4826 * have room for. */ |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4827 if ((fmt_spec == 'f' || fmt_spec == 'F') |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4828 && abs_f > 1.0) |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4829 max_prec -= (size_t)log10(abs_f); |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4830 if (precision > max_prec) |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4831 precision = max_prec; |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4832 l += sprintf(format + l, ".%d", (int)precision); |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4833 } |
10040
48f70e0c696a
commit https://github.com/vim/vim/commit/965ed14973fd3f1b2aace7bae4d4722b71ca04f9
Christian Brabandt <cb@256bit.org>
parents:
10038
diff
changeset
|
4834 format[l] = fmt_spec == 'F' ? 'f' : fmt_spec; |
10038
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4835 format[l + 1] = NUL; |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4836 |
10015
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4837 str_arg_l = sprintf(tmp, format, f); |
13188
a49a5419a83f
patch 8.0.1468: illegal memory access in del_bytes()
Christian Brabandt <cb@256bit.org>
parents:
13150
diff
changeset
|
4838 } |
9986
9bef7b5d02cb
commit https://github.com/vim/vim/commit/9992237a3e791fbc0c1ebf743ece1b75e1488410
Christian Brabandt <cb@256bit.org>
parents:
9980
diff
changeset
|
4839 |
1619 | 4840 if (remove_trailing_zeroes) |
4841 { | |
4842 int i; | |
1757 | 4843 char *tp; |
1619 | 4844 |
4845 /* Using %g or %G: remove superfluous zeroes. */ | |
10038
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4846 if (fmt_spec == 'f' || fmt_spec == 'F') |
1757 | 4847 tp = tmp + str_arg_l - 1; |
1619 | 4848 else |
4849 { | |
1757 | 4850 tp = (char *)vim_strchr((char_u *)tmp, |
1619 | 4851 fmt_spec == 'e' ? 'e' : 'E'); |
1757 | 4852 if (tp != NULL) |
1619 | 4853 { |
4854 /* Remove superfluous '+' and leading | |
4855 * zeroes from the exponent. */ | |
1757 | 4856 if (tp[1] == '+') |
1619 | 4857 { |
4858 /* Change "1.0e+07" to "1.0e07" */ | |
1757 | 4859 STRMOVE(tp + 1, tp + 2); |
1619 | 4860 --str_arg_l; |
4861 } | |
1757 | 4862 i = (tp[1] == '-') ? 2 : 1; |
4863 while (tp[i] == '0') | |
1619 | 4864 { |
4865 /* Change "1.0e07" to "1.0e7" */ | |
1757 | 4866 STRMOVE(tp + i, tp + i + 1); |
1619 | 4867 --str_arg_l; |
4868 } | |
1757 | 4869 --tp; |
1619 | 4870 } |
4871 } | |
4872 | |
1757 | 4873 if (tp != NULL && !precision_specified) |
1619 | 4874 /* Remove trailing zeroes, but keep the one |
4875 * just after a dot. */ | |
1757 | 4876 while (tp > tmp + 2 && *tp == '0' |
4877 && tp[-1] != '.') | |
1619 | 4878 { |
1757 | 4879 STRMOVE(tp, tp + 1); |
4880 --tp; | |
1619 | 4881 --str_arg_l; |
4882 } | |
4883 } | |
4884 else | |
4885 { | |
1757 | 4886 char *tp; |
1619 | 4887 |
4888 /* Be consistent: some printf("%e") use 1.0e+12 | |
4889 * and some 1.0e+012. Remove one zero in the last | |
4890 * case. */ | |
1757 | 4891 tp = (char *)vim_strchr((char_u *)tmp, |
1619 | 4892 fmt_spec == 'e' ? 'e' : 'E'); |
1757 | 4893 if (tp != NULL && (tp[1] == '+' || tp[1] == '-') |
4894 && tp[2] == '0' | |
4895 && vim_isdigit(tp[3]) | |
4896 && vim_isdigit(tp[4])) | |
1619 | 4897 { |
1757 | 4898 STRMOVE(tp + 2, tp + 3); |
1619 | 4899 --str_arg_l; |
4900 } | |
4901 } | |
4902 } | |
10038
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4903 if (zero_padding && min_field_width > str_arg_l |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4904 && (tmp[0] == '-' || force_sign)) |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4905 { |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4906 /* padding 0's should be inserted after the sign */ |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4907 number_of_zeros_to_pad = min_field_width - str_arg_l; |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4908 zero_padding_insertion_ind = 1; |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4909 } |
1619 | 4910 str_arg = tmp; |
4911 break; | |
4912 } | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
4913 # endif |
1619 | 4914 |
272 | 4915 default: |
4916 /* unrecognized conversion specifier, keep format string | |
4917 * as-is */ | |
4918 zero_padding = 0; /* turn zero padding off for non-numeric | |
1189 | 4919 conversion */ |
272 | 4920 justify_left = 1; |
856 | 4921 min_field_width = 0; /* reset flags */ |
272 | 4922 |
4923 /* discard the unrecognized conversion, just keep * | |
856 | 4924 * the unrecognized conversion character */ |
272 | 4925 str_arg = p; |
4926 str_arg_l = 0; | |
4927 if (*p != NUL) | |
4928 str_arg_l++; /* include invalid conversion specifier | |
4929 unchanged if not at end-of-string */ | |
4930 break; | |
4931 } | |
4932 | |
4933 if (*p != NUL) | |
4934 p++; /* step over the just processed conversion specifier */ | |
4935 | |
4936 /* insert padding to the left as requested by min_field_width; | |
4937 * this does not include the zero padding in case of numerical | |
4938 * conversions*/ | |
4939 if (!justify_left) | |
4940 { | |
4941 /* left padding with blank or zero */ | |
835 | 4942 int pn = (int)(min_field_width - (str_arg_l + number_of_zeros_to_pad)); |
275 | 4943 |
4944 if (pn > 0) | |
272 | 4945 { |
4946 if (str_l < str_m) | |
4947 { | |
4948 size_t avail = str_m - str_l; | |
4949 | |
4950 vim_memset(str + str_l, zero_padding ? '0' : ' ', | |
1883 | 4951 (size_t)pn > avail ? avail |
4952 : (size_t)pn); | |
272 | 4953 } |
275 | 4954 str_l += pn; |
272 | 4955 } |
4956 } | |
4957 | |
4958 /* zero padding as requested by the precision or by the minimal | |
4959 * field width for numeric conversions required? */ | |
330 | 4960 if (number_of_zeros_to_pad == 0) |
272 | 4961 { |
4962 /* will not copy first part of numeric right now, * | |
4963 * force it to be copied later in its entirety */ | |
4964 zero_padding_insertion_ind = 0; | |
4965 } | |
4966 else | |
4967 { | |
4968 /* insert first part of numerics (sign or '0x') before zero | |
4969 * padding */ | |
835 | 4970 int zn = (int)zero_padding_insertion_ind; |
275 | 4971 |
4972 if (zn > 0) | |
272 | 4973 { |
4974 if (str_l < str_m) | |
4975 { | |
4976 size_t avail = str_m - str_l; | |
4977 | |
4978 mch_memmove(str + str_l, str_arg, | |
1883 | 4979 (size_t)zn > avail ? avail |
4980 : (size_t)zn); | |
272 | 4981 } |
275 | 4982 str_l += zn; |
272 | 4983 } |
4984 | |
4985 /* insert zero padding as requested by the precision or min | |
4986 * field width */ | |
835 | 4987 zn = (int)number_of_zeros_to_pad; |
275 | 4988 if (zn > 0) |
272 | 4989 { |
4990 if (str_l < str_m) | |
4991 { | |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11653
diff
changeset
|
4992 size_t avail = str_m - str_l; |
272 | 4993 |
275 | 4994 vim_memset(str + str_l, '0', |
1883 | 4995 (size_t)zn > avail ? avail |
4996 : (size_t)zn); | |
272 | 4997 } |
275 | 4998 str_l += zn; |
272 | 4999 } |
5000 } | |
5001 | |
5002 /* insert formatted string | |
5003 * (or as-is conversion specifier for unknown conversions) */ | |
5004 { | |
835 | 5005 int sn = (int)(str_arg_l - zero_padding_insertion_ind); |
275 | 5006 |
5007 if (sn > 0) | |
272 | 5008 { |
5009 if (str_l < str_m) | |
5010 { | |
5011 size_t avail = str_m - str_l; | |
5012 | |
5013 mch_memmove(str + str_l, | |
5014 str_arg + zero_padding_insertion_ind, | |
1883 | 5015 (size_t)sn > avail ? avail : (size_t)sn); |
272 | 5016 } |
275 | 5017 str_l += sn; |
272 | 5018 } |
5019 } | |
5020 | |
5021 /* insert right padding */ | |
5022 if (justify_left) | |
5023 { | |
5024 /* right blank padding to the field width */ | |
1619 | 5025 int pn = (int)(min_field_width |
5026 - (str_arg_l + number_of_zeros_to_pad)); | |
275 | 5027 |
5028 if (pn > 0) | |
272 | 5029 { |
5030 if (str_l < str_m) | |
5031 { | |
5032 size_t avail = str_m - str_l; | |
5033 | |
275 | 5034 vim_memset(str + str_l, ' ', |
1883 | 5035 (size_t)pn > avail ? avail |
5036 : (size_t)pn); | |
272 | 5037 } |
275 | 5038 str_l += pn; |
272 | 5039 } |
5040 } | |
9892
41c5d59e7e10
commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents:
9698
diff
changeset
|
5041 vim_free(tofree); |
272 | 5042 } |
5043 } | |
5044 | |
5045 if (str_m > 0) | |
5046 { | |
437 | 5047 /* make sure the string is nul-terminated even at the expense of |
272 | 5048 * overwriting the last character (shouldn't happen, but just in case) |
5049 * */ | |
5050 str[str_l <= str_m - 1 ? str_l : str_m - 1] = '\0'; | |
5051 } | |
5052 | |
482 | 5053 if (tvs != NULL && tvs[arg_idx - 1].v_type != VAR_UNKNOWN) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5054 emsg(_("E767: Too many arguments to printf()")); |
449 | 5055 |
437 | 5056 /* Return the number of characters formatted (excluding trailing nul |
272 | 5057 * character), that is, the number of characters that would have been |
5058 * written to the buffer if it were large enough. */ | |
5059 return (int)str_l; | |
5060 } | |
5061 | |
5062 #endif /* PROTO */ |