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