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