Mercurial > vim
annotate src/strings.c @ 33740:61985d704ecc v9.0.2097
patch 9.0.2097: No support for cypher files
Commit: https://github.com/vim/vim/commit/8f0fe20ff1a13b468fdfaf85c434475f75c7a615
Author: Gerrit Meier <meistermeier@gmail.com>
Date: Sat Nov 11 08:58:26 2023 +0100
patch 9.0.2097: No support for cypher files
Problem: No support for cypher files
Solution: Add cypher filetype detection
Cypher query language support to work with (mostly) graph databases.
Already existing lsp support in Neovim's nvim-lspconfig:
https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#cypher_ls
closes: #13516
Signed-off-by: Gerrit Meier <meistermeier@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 11 Nov 2023 09:00:09 +0100 |
parents | e9c70470fe94 |
children | da670b1549b3 |
rev | line source |
---|---|
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2 * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3 * VIM - Vi IMproved by Bram Moolenaar |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4 * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
5 * Do ":help uganda" in Vim to read copying and usage conditions. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
6 * Do ":help credits" in Vim to see a list of people who contributed. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
7 * See README.txt for an overview of the Vim source code. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
8 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
9 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
10 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
11 * strings.c: string manipulation functions |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
12 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
13 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
14 #define USING_FLOAT_STUFF |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
15 #include "vim.h" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
16 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
17 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
18 * Copy "string" into newly allocated memory. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
19 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
20 char_u * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
21 vim_strsave(char_u *string) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
22 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
23 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
24 size_t len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
25 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
26 len = STRLEN(string) + 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
27 p = alloc(len); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
28 if (p != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
29 mch_memmove(p, string, len); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
30 return p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
31 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
32 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
33 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
34 * Copy up to "len" bytes of "string" into newly allocated memory and |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
35 * terminate with a NUL. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
36 * The allocated memory always has size "len + 1", also when "string" is |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
37 * shorter. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
38 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
39 char_u * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
40 vim_strnsave(char_u *string, size_t len) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
41 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
42 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
43 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
44 p = alloc(len + 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
45 if (p == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
46 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
47 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
48 STRNCPY(p, string, len); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
49 p[len] = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
50 return p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
51 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
52 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
53 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
54 * Same as vim_strsave(), but any characters found in esc_chars are preceded |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
55 * by a backslash. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
56 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
57 char_u * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
58 vim_strsave_escaped(char_u *string, char_u *esc_chars) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
59 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
60 return vim_strsave_escaped_ext(string, esc_chars, '\\', FALSE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
61 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
62 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
63 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
64 * Same as vim_strsave_escaped(), but when "bsl" is TRUE also escape |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
65 * characters where rem_backslash() would remove the backslash. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
66 * Escape the characters with "cc". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
67 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
68 char_u * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
69 vim_strsave_escaped_ext( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
70 char_u *string, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
71 char_u *esc_chars, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
72 int cc, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
73 int bsl) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
74 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
75 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
76 char_u *p2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
77 char_u *escaped_string; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
78 unsigned length; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
79 int l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
80 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
81 // First count the number of backslashes required. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
82 // Then allocate the memory and insert them. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
83 length = 1; // count the trailing NUL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
84 for (p = string; *p; p++) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
85 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
86 if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
87 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
88 length += l; // count a multibyte char |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
89 p += l - 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
90 continue; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
91 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
92 if (vim_strchr(esc_chars, *p) != NULL || (bsl && rem_backslash(p))) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
93 ++length; // count a backslash |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
94 ++length; // count an ordinary char |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
95 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
96 escaped_string = alloc(length); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
97 if (escaped_string == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
98 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
99 p2 = escaped_string; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
100 for (p = string; *p; p++) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
101 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
102 if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
103 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
104 mch_memmove(p2, p, (size_t)l); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
105 p2 += l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
106 p += l - 1; // skip multibyte char |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
107 continue; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
108 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
109 if (vim_strchr(esc_chars, *p) != NULL || (bsl && rem_backslash(p))) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
110 *p2++ = cc; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
111 *p2++ = *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
112 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
113 *p2 = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
114 return escaped_string; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
115 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
116 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
117 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
118 * Return TRUE when 'shell' has "csh" in the tail. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
119 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
120 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
121 csh_like_shell(void) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
122 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
123 return (strstr((char *)gettail(p_sh), "csh") != NULL); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
124 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
125 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
126 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
127 * Return TRUE when 'shell' has "fish" in the tail. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
128 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
129 static int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
130 fish_like_shell(void) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
131 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
132 return (strstr((char *)gettail(p_sh), "fish") != NULL); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
133 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
134 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
135 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
136 * Escape "string" for use as a shell argument with system(). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
137 * This uses single quotes, except when we know we need to use double quotes |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
138 * (MS-DOS and MS-Windows not using PowerShell and without 'shellslash' set). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
139 * PowerShell also uses a novel escaping for enclosed single quotes - double |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
140 * them up. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
141 * Escape a newline, depending on the 'shell' option. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
142 * When "do_special" is TRUE also replace "!", "%", "#" and things starting |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
143 * with "<" like "<cfile>". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
144 * When "do_newline" is FALSE do not escape newline unless it is csh shell. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
145 * Returns the result in allocated memory, NULL if we have run out. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
146 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
147 char_u * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
148 vim_strsave_shellescape(char_u *string, int do_special, int do_newline) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
149 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
150 unsigned length; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
151 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
152 char_u *d; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
153 char_u *escaped_string; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
154 int l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
155 int csh_like; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
156 int fish_like; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
157 char_u *shname; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
158 int powershell; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
159 # ifdef MSWIN |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
160 int double_quotes; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
161 # endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
162 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
163 // Only csh and similar shells expand '!' within single quotes. For sh and |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
164 // the like we must not put a backslash before it, it will be taken |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
165 // literally. If do_special is set the '!' will be escaped twice. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
166 // Csh also needs to have "\n" escaped twice when do_special is set. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
167 csh_like = csh_like_shell(); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
168 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
169 // Fish shell uses '\' as an escape character within single quotes, so '\' |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
170 // itself must be escaped to get a literal '\'. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
171 fish_like = fish_like_shell(); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
172 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
173 // PowerShell uses its own version for quoting single quotes |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
174 shname = gettail(p_sh); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
175 powershell = strstr((char *)shname, "pwsh") != NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
176 # ifdef MSWIN |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
177 powershell = powershell || strstr((char *)shname, "powershell") != NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
178 // PowerShell only accepts single quotes so override shellslash. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
179 double_quotes = !powershell && !p_ssl; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
180 # endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
181 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
182 // First count the number of extra bytes required. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
183 length = (unsigned)STRLEN(string) + 3; // two quotes and a trailing NUL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
184 for (p = string; *p != NUL; MB_PTR_ADV(p)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
185 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
186 # ifdef MSWIN |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
187 if (double_quotes) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
188 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
189 if (*p == '"') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
190 ++length; // " -> "" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
191 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
192 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
193 # endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
194 if (*p == '\'') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
195 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
196 if (powershell) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
197 length +=2; // ' => '' |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
198 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
199 length += 3; // ' => '\'' |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
200 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
201 if ((*p == '\n' && (csh_like || do_newline)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
202 || (*p == '!' && (csh_like || do_special))) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
203 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
204 ++length; // insert backslash |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
205 if (csh_like && do_special) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
206 ++length; // insert backslash |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
207 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
208 if (do_special && find_cmdline_var(p, &l) >= 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
209 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
210 ++length; // insert backslash |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
211 p += l - 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
212 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
213 if (*p == '\\' && fish_like) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
214 ++length; // insert backslash |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
215 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
216 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
217 // Allocate memory for the result and fill it. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
218 escaped_string = alloc(length); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
219 if (escaped_string != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
220 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
221 d = escaped_string; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
222 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
223 // add opening quote |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
224 # ifdef MSWIN |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
225 if (double_quotes) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
226 *d++ = '"'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
227 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
228 # endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
229 *d++ = '\''; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
230 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
231 for (p = string; *p != NUL; ) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
232 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
233 # ifdef MSWIN |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
234 if (double_quotes) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
235 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
236 if (*p == '"') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
237 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
238 *d++ = '"'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
239 *d++ = '"'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
240 ++p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
241 continue; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
242 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
243 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
244 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
245 # endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
246 if (*p == '\'') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
247 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
248 if (powershell) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
249 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
250 *d++ = '\''; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
251 *d++ = '\''; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
252 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
253 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
254 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
255 *d++ = '\''; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
256 *d++ = '\\'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
257 *d++ = '\''; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
258 *d++ = '\''; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
259 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
260 ++p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
261 continue; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
262 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
263 if ((*p == '\n' && (csh_like || do_newline)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
264 || (*p == '!' && (csh_like || do_special))) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
265 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
266 *d++ = '\\'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
267 if (csh_like && do_special) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
268 *d++ = '\\'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
269 *d++ = *p++; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
270 continue; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
271 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
272 if (do_special && find_cmdline_var(p, &l) >= 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
273 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
274 *d++ = '\\'; // insert backslash |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
275 while (--l >= 0) // copy the var |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
276 *d++ = *p++; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
277 continue; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
278 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
279 if (*p == '\\' && fish_like) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
280 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
281 *d++ = '\\'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
282 *d++ = *p++; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
283 continue; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
284 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
285 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
286 MB_COPY_CHAR(p, d); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
287 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
288 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
289 // add terminating quote and finish with a NUL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
290 # ifdef MSWIN |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
291 if (double_quotes) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
292 *d++ = '"'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
293 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
294 # endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
295 *d++ = '\''; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
296 *d = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
297 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
298 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
299 return escaped_string; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
300 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
301 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
302 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
303 * Like vim_strsave(), but make all characters uppercase. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
304 * This uses ASCII lower-to-upper case translation, language independent. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
305 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
306 char_u * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
307 vim_strsave_up(char_u *string) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
308 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
309 char_u *p1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
310 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
311 p1 = vim_strsave(string); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
312 vim_strup(p1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
313 return p1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
314 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
315 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
316 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
317 * Like vim_strnsave(), but make all characters uppercase. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
318 * This uses ASCII lower-to-upper case translation, language independent. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
319 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
320 char_u * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
321 vim_strnsave_up(char_u *string, size_t len) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
322 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
323 char_u *p1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
324 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
325 p1 = vim_strnsave(string, len); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
326 vim_strup(p1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
327 return p1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
328 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
329 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
330 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
331 * ASCII lower-to-upper case translation, language independent. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
332 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
333 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
334 vim_strup( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
335 char_u *p) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
336 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
337 char_u *p2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
338 int c; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
339 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
340 if (p == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
341 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
342 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
343 p2 = p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
344 while ((c = *p2) != NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
345 *p2++ = (c < 'a' || c > 'z') ? c : (c - 0x20); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
346 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
347 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
348 #if defined(FEAT_EVAL) || defined(FEAT_SPELL) || defined(PROTO) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
349 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
350 * Make string "s" all upper-case and return it in allocated memory. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
351 * Handles multi-byte characters as well as possible. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
352 * Returns NULL when out of memory. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
353 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
354 static char_u * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
355 strup_save(char_u *orig) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
356 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
357 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
358 char_u *res; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
359 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
360 res = p = vim_strsave(orig); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
361 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
362 if (res != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
363 while (*p != NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
364 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
365 int l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
366 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
367 if (enc_utf8) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
368 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
369 int c, uc; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
370 int newl; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
371 char_u *s; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
372 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
373 c = utf_ptr2char(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
374 l = utf_ptr2len(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
375 if (c == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
376 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
377 // overlong sequence, use only the first byte |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
378 c = *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
379 l = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
380 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
381 uc = utf_toupper(c); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
382 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
383 // Reallocate string when byte count changes. This is rare, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
384 // thus it's OK to do another malloc()/free(). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
385 newl = utf_char2len(uc); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
386 if (newl != l) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
387 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
388 s = alloc(STRLEN(res) + 1 + newl - l); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
389 if (s == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
390 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
391 vim_free(res); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
392 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
393 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
394 mch_memmove(s, res, p - res); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
395 STRCPY(s + (p - res) + newl, p + l); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
396 p = s + (p - res); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
397 vim_free(res); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
398 res = s; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
399 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
400 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
401 utf_char2bytes(uc, p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
402 p += newl; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
403 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
404 else if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
405 p += l; // skip multi-byte character |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
406 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
407 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
408 *p = TOUPPER_LOC(*p); // note that toupper() can be a macro |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
409 p++; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
410 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
411 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
412 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
413 return res; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
414 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
415 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
416 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
417 * Make string "s" all lower-case and return it in allocated memory. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
418 * Handles multi-byte characters as well as possible. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
419 * Returns NULL when out of memory. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
420 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
421 char_u * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
422 strlow_save(char_u *orig) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
423 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
424 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
425 char_u *res; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
426 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
427 res = p = vim_strsave(orig); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
428 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
429 if (res != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
430 while (*p != NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
431 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
432 int l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
433 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
434 if (enc_utf8) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
435 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
436 int c, lc; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
437 int newl; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
438 char_u *s; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
439 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
440 c = utf_ptr2char(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
441 l = utf_ptr2len(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
442 if (c == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
443 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
444 // overlong sequence, use only the first byte |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
445 c = *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
446 l = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
447 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
448 lc = utf_tolower(c); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
449 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
450 // Reallocate string when byte count changes. This is rare, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
451 // thus it's OK to do another malloc()/free(). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
452 newl = utf_char2len(lc); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
453 if (newl != l) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
454 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
455 s = alloc(STRLEN(res) + 1 + newl - l); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
456 if (s == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
457 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
458 vim_free(res); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
459 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
460 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
461 mch_memmove(s, res, p - res); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
462 STRCPY(s + (p - res) + newl, p + l); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
463 p = s + (p - res); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
464 vim_free(res); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
465 res = s; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
466 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
467 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
468 utf_char2bytes(lc, p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
469 p += newl; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
470 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
471 else if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
472 p += l; // skip multi-byte character |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
473 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
474 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
475 *p = TOLOWER_LOC(*p); // note that tolower() can be a macro |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
476 p++; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
477 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
478 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
479 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
480 return res; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
481 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
482 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
483 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
484 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
485 * delete spaces at the end of a string |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
486 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
487 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
488 del_trailing_spaces(char_u *ptr) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
489 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
490 char_u *q; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
491 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
492 q = ptr + STRLEN(ptr); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
493 while (--q > ptr && VIM_ISWHITE(q[0]) && q[-1] != '\\' && q[-1] != Ctrl_V) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
494 *q = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
495 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
496 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
497 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
498 * Like strncpy(), but always terminate the result with one NUL. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
499 * "to" must be "len + 1" long! |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
500 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
501 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
502 vim_strncpy(char_u *to, char_u *from, size_t len) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
503 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
504 STRNCPY(to, from, len); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
505 to[len] = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
506 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
507 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
508 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
509 * Like strcat(), but make sure the result fits in "tosize" bytes and is |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
510 * always NUL terminated. "from" and "to" may overlap. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
511 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
512 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
513 vim_strcat(char_u *to, char_u *from, size_t tosize) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
514 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
515 size_t tolen = STRLEN(to); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
516 size_t fromlen = STRLEN(from); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
517 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
518 if (tolen + fromlen + 1 > tosize) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
519 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
520 mch_memmove(to + tolen, from, tosize - tolen - 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
521 to[tosize - 1] = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
522 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
523 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
524 mch_memmove(to + tolen, from, fromlen + 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
525 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
526 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
527 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
528 * A version of strlen() that has a maximum length. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
529 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
530 size_t |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
531 vim_strlen_maxlen(char *s, size_t maxlen) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
532 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
533 size_t i; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
534 for (i = 0; i < maxlen; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
535 if (s[i] == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
536 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
537 return i; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
538 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
539 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
540 #if (!defined(HAVE_STRCASECMP) && !defined(HAVE_STRICMP)) || defined(PROTO) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
541 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
542 * Compare two strings, ignoring case, using current locale. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
543 * Doesn't work for multi-byte characters. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
544 * return 0 for match, < 0 for smaller, > 0 for bigger |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
545 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
546 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
547 vim_stricmp(char *s1, char *s2) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
548 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
549 int i; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
550 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
551 for (;;) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
552 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
553 i = (int)TOLOWER_LOC(*s1) - (int)TOLOWER_LOC(*s2); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
554 if (i != 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
555 return i; // this character different |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
556 if (*s1 == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
557 break; // strings match until NUL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
558 ++s1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
559 ++s2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
560 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
561 return 0; // strings match |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
562 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
563 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
564 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
565 #if (!defined(HAVE_STRNCASECMP) && !defined(HAVE_STRNICMP)) || defined(PROTO) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
566 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
567 * Compare two strings, for length "len", ignoring case, using current locale. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
568 * Doesn't work for multi-byte characters. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
569 * return 0 for match, < 0 for smaller, > 0 for bigger |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
570 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
571 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
572 vim_strnicmp(char *s1, char *s2, size_t len) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
573 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
574 int i; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
575 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
576 while (len > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
577 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
578 i = (int)TOLOWER_LOC(*s1) - (int)TOLOWER_LOC(*s2); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
579 if (i != 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
580 return i; // this character different |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
581 if (*s1 == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
582 break; // strings match until NUL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
583 ++s1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
584 ++s2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
585 --len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
586 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
587 return 0; // strings match |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
588 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
589 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
590 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
591 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
592 * Search for first occurrence of "c" in "string". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
593 * Version of strchr() that handles unsigned char strings with characters from |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
594 * 128 to 255 correctly. It also doesn't return a pointer to the NUL at the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
595 * end of the string. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
596 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
597 char_u * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
598 vim_strchr(char_u *string, int c) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
599 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
600 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
601 int b; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
602 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
603 p = string; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
604 if (enc_utf8 && c >= 0x80) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
605 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
606 while (*p != NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
607 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
608 int l = utfc_ptr2len(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
609 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
610 // Avoid matching an illegal byte here. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
611 if (utf_ptr2char(p) == c && l > 1) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
612 return p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
613 p += l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
614 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
615 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
616 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
617 if (enc_dbcs != 0 && c > 255) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
618 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
619 int n2 = c & 0xff; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
620 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
621 c = ((unsigned)c >> 8) & 0xff; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
622 while ((b = *p) != NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
623 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
624 if (b == c && p[1] == n2) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
625 return p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
626 p += (*mb_ptr2len)(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
627 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
628 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
629 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
630 if (has_mbyte) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
631 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
632 while ((b = *p) != NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
633 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
634 if (b == c) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
635 return p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
636 p += (*mb_ptr2len)(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
637 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
638 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
639 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
640 while ((b = *p) != NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
641 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
642 if (b == c) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
643 return p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
644 ++p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
645 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
646 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
647 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
648 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
649 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
650 * Version of strchr() that only works for bytes and handles unsigned char |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
651 * strings with characters above 128 correctly. It also doesn't return a |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
652 * pointer to the NUL at the end of the string. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
653 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
654 char_u * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
655 vim_strbyte(char_u *string, int c) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
656 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
657 char_u *p = string; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
658 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
659 while (*p != NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
660 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
661 if (*p == c) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
662 return p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
663 ++p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
664 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
665 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
666 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
667 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
668 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
669 * Search for last occurrence of "c" in "string". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
670 * Version of strrchr() that handles unsigned char strings with characters from |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
671 * 128 to 255 correctly. It also doesn't return a pointer to the NUL at the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
672 * end of the string. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
673 * Return NULL if not found. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
674 * Does not handle multi-byte char for "c"! |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
675 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
676 char_u * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
677 vim_strrchr(char_u *string, int c) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
678 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
679 char_u *retval = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
680 char_u *p = string; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
681 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
682 while (*p) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
683 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
684 if (*p == c) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
685 retval = p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
686 MB_PTR_ADV(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
687 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
688 return retval; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
689 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
690 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
691 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
692 * Vim's version of strpbrk(), in case it's missing. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
693 * Don't generate a prototype for this, causes problems when it's not used. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
694 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
695 #ifndef PROTO |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
696 # ifndef HAVE_STRPBRK |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
697 # ifdef vim_strpbrk |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
698 # undef vim_strpbrk |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
699 # endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
700 char_u * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
701 vim_strpbrk(char_u *s, char_u *charset) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
702 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
703 while (*s) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
704 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
705 if (vim_strchr(charset, *s) != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
706 return s; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
707 MB_PTR_ADV(s); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
708 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
709 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
710 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
711 # endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
712 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
713 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
714 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
715 * Sort an array of strings. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
716 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
717 static int sort_compare(const void *s1, const void *s2); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
718 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
719 static int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
720 sort_compare(const void *s1, const void *s2) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
721 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
722 return STRCMP(*(char **)s1, *(char **)s2); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
723 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
724 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
725 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
726 sort_strings( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
727 char_u **files, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
728 int count) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
729 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
730 qsort((void *)files, (size_t)count, sizeof(char_u *), sort_compare); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
731 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
732 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
733 #if defined(FEAT_QUICKFIX) || defined(FEAT_SPELL) || defined(PROTO) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
734 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
735 * Return TRUE if string "s" contains a non-ASCII character (128 or higher). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
736 * When "s" is NULL FALSE is returned. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
737 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
738 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
739 has_non_ascii(char_u *s) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
740 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
741 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
742 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
743 if (s != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
744 for (p = s; *p != NUL; ++p) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
745 if (*p >= 128) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
746 return TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
747 return FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
748 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
749 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
750 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
751 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
752 * Concatenate two strings and return the result in allocated memory. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
753 * Returns NULL when out of memory. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
754 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
755 char_u * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
756 concat_str(char_u *str1, char_u *str2) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
757 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
758 char_u *dest; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
759 size_t l = str1 == NULL ? 0 : STRLEN(str1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
760 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
761 dest = alloc(l + (str2 == NULL ? 0 : STRLEN(str2)) + 1L); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
762 if (dest == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
763 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
764 if (str1 == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
765 *dest = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
766 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
767 STRCPY(dest, str1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
768 if (str2 != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
769 STRCPY(dest + l, str2); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
770 return dest; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
771 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
772 |
32856
06562c9307dd
patch 9.0.1738: Duplicate code to reverse a string
Christian Brabandt <cb@256bit.org>
parents:
32818
diff
changeset
|
773 #if defined(FEAT_EVAL) || defined(FEAT_RIGHTLEFT) || defined(PROTO) |
06562c9307dd
patch 9.0.1738: Duplicate code to reverse a string
Christian Brabandt <cb@256bit.org>
parents:
32818
diff
changeset
|
774 /* |
06562c9307dd
patch 9.0.1738: Duplicate code to reverse a string
Christian Brabandt <cb@256bit.org>
parents:
32818
diff
changeset
|
775 * Reverse text into allocated memory. |
06562c9307dd
patch 9.0.1738: Duplicate code to reverse a string
Christian Brabandt <cb@256bit.org>
parents:
32818
diff
changeset
|
776 * Returns the allocated string, NULL when out of memory. |
06562c9307dd
patch 9.0.1738: Duplicate code to reverse a string
Christian Brabandt <cb@256bit.org>
parents:
32818
diff
changeset
|
777 */ |
06562c9307dd
patch 9.0.1738: Duplicate code to reverse a string
Christian Brabandt <cb@256bit.org>
parents:
32818
diff
changeset
|
778 char_u * |
06562c9307dd
patch 9.0.1738: Duplicate code to reverse a string
Christian Brabandt <cb@256bit.org>
parents:
32818
diff
changeset
|
779 reverse_text(char_u *s) |
06562c9307dd
patch 9.0.1738: Duplicate code to reverse a string
Christian Brabandt <cb@256bit.org>
parents:
32818
diff
changeset
|
780 { |
06562c9307dd
patch 9.0.1738: Duplicate code to reverse a string
Christian Brabandt <cb@256bit.org>
parents:
32818
diff
changeset
|
781 size_t len = STRLEN(s); |
06562c9307dd
patch 9.0.1738: Duplicate code to reverse a string
Christian Brabandt <cb@256bit.org>
parents:
32818
diff
changeset
|
782 char_u *rev = alloc(len + 1); |
06562c9307dd
patch 9.0.1738: Duplicate code to reverse a string
Christian Brabandt <cb@256bit.org>
parents:
32818
diff
changeset
|
783 if (rev == NULL) |
06562c9307dd
patch 9.0.1738: Duplicate code to reverse a string
Christian Brabandt <cb@256bit.org>
parents:
32818
diff
changeset
|
784 return NULL; |
06562c9307dd
patch 9.0.1738: Duplicate code to reverse a string
Christian Brabandt <cb@256bit.org>
parents:
32818
diff
changeset
|
785 |
06562c9307dd
patch 9.0.1738: Duplicate code to reverse a string
Christian Brabandt <cb@256bit.org>
parents:
32818
diff
changeset
|
786 for (size_t s_i = 0, rev_i = len; s_i < len; ++s_i) |
06562c9307dd
patch 9.0.1738: Duplicate code to reverse a string
Christian Brabandt <cb@256bit.org>
parents:
32818
diff
changeset
|
787 { |
06562c9307dd
patch 9.0.1738: Duplicate code to reverse a string
Christian Brabandt <cb@256bit.org>
parents:
32818
diff
changeset
|
788 if (has_mbyte) |
06562c9307dd
patch 9.0.1738: Duplicate code to reverse a string
Christian Brabandt <cb@256bit.org>
parents:
32818
diff
changeset
|
789 { |
06562c9307dd
patch 9.0.1738: Duplicate code to reverse a string
Christian Brabandt <cb@256bit.org>
parents:
32818
diff
changeset
|
790 int mb_len = (*mb_ptr2len)(s + s_i); |
06562c9307dd
patch 9.0.1738: Duplicate code to reverse a string
Christian Brabandt <cb@256bit.org>
parents:
32818
diff
changeset
|
791 rev_i -= mb_len; |
06562c9307dd
patch 9.0.1738: Duplicate code to reverse a string
Christian Brabandt <cb@256bit.org>
parents:
32818
diff
changeset
|
792 mch_memmove(rev + rev_i, s + s_i, mb_len); |
06562c9307dd
patch 9.0.1738: Duplicate code to reverse a string
Christian Brabandt <cb@256bit.org>
parents:
32818
diff
changeset
|
793 s_i += mb_len - 1; |
06562c9307dd
patch 9.0.1738: Duplicate code to reverse a string
Christian Brabandt <cb@256bit.org>
parents:
32818
diff
changeset
|
794 } |
06562c9307dd
patch 9.0.1738: Duplicate code to reverse a string
Christian Brabandt <cb@256bit.org>
parents:
32818
diff
changeset
|
795 else |
06562c9307dd
patch 9.0.1738: Duplicate code to reverse a string
Christian Brabandt <cb@256bit.org>
parents:
32818
diff
changeset
|
796 rev[--rev_i] = s[s_i]; |
06562c9307dd
patch 9.0.1738: Duplicate code to reverse a string
Christian Brabandt <cb@256bit.org>
parents:
32818
diff
changeset
|
797 } |
06562c9307dd
patch 9.0.1738: Duplicate code to reverse a string
Christian Brabandt <cb@256bit.org>
parents:
32818
diff
changeset
|
798 rev[len] = NUL; |
06562c9307dd
patch 9.0.1738: Duplicate code to reverse a string
Christian Brabandt <cb@256bit.org>
parents:
32818
diff
changeset
|
799 return rev; |
06562c9307dd
patch 9.0.1738: Duplicate code to reverse a string
Christian Brabandt <cb@256bit.org>
parents:
32818
diff
changeset
|
800 } |
06562c9307dd
patch 9.0.1738: Duplicate code to reverse a string
Christian Brabandt <cb@256bit.org>
parents:
32818
diff
changeset
|
801 #endif |
06562c9307dd
patch 9.0.1738: Duplicate code to reverse a string
Christian Brabandt <cb@256bit.org>
parents:
32818
diff
changeset
|
802 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
803 #if defined(FEAT_EVAL) || defined(PROTO) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
804 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
805 * Return string "str" in ' quotes, doubling ' characters. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
806 * If "str" is NULL an empty string is assumed. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
807 * If "function" is TRUE make it function('string'). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
808 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
809 char_u * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
810 string_quote(char_u *str, int function) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
811 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
812 unsigned len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
813 char_u *p, *r, *s; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
814 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
815 len = (function ? 13 : 3); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
816 if (str != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
817 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
818 len += (unsigned)STRLEN(str); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
819 for (p = str; *p != NUL; MB_PTR_ADV(p)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
820 if (*p == '\'') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
821 ++len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
822 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
823 s = r = alloc(len); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
824 if (r == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
825 return NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
826 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
827 if (function) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
828 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
829 STRCPY(r, "function('"); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
830 r += 10; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
831 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
832 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
833 *r++ = '\''; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
834 if (str != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
835 for (p = str; *p != NUL; ) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
836 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
837 if (*p == '\'') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
838 *r++ = '\''; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
839 MB_COPY_CHAR(p, r); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
840 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
841 *r++ = '\''; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
842 if (function) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
843 *r++ = ')'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
844 *r++ = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
845 return s; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
846 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
847 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
848 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
849 * Count the number of times "needle" occurs in string "haystack". Case is |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
850 * ignored if "ic" is TRUE. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
851 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
852 long |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
853 string_count(char_u *haystack, char_u *needle, int ic) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
854 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
855 long n = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
856 char_u *p = haystack; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
857 char_u *next; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
858 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
859 if (p == NULL || needle == NULL || *needle == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
860 return 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
861 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
862 if (ic) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
863 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
864 size_t len = STRLEN(needle); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
865 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
866 while (*p != NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
867 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
868 if (MB_STRNICMP(p, needle, len) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
869 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
870 ++n; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
871 p += len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
872 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
873 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
874 MB_PTR_ADV(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
875 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
876 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
877 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
878 while ((next = (char_u *)strstr((char *)p, (char *)needle)) != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
879 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
880 ++n; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
881 p = next + STRLEN(needle); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
882 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
883 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
884 return n; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
885 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
886 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
887 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
888 * Make a typval_T of the first character of "input" and store it in "output". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
889 * Return OK or FAIL. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
890 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
891 static int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
892 copy_first_char_to_tv(char_u *input, typval_T *output) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
893 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
894 char_u buf[MB_MAXBYTES + 1]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
895 int len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
896 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
897 if (input == NULL || output == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
898 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
899 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
900 len = has_mbyte ? mb_ptr2len(input) : 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
901 STRNCPY(buf, input, len); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
902 buf[len] = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
903 output->v_type = VAR_STRING; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
904 output->vval.v_string = vim_strsave(buf); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
905 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
906 return output->vval.v_string == NULL ? FAIL : OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
907 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
908 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
909 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
910 * Implementation of map() and filter() for a String. Apply "expr" to every |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
911 * character in string "str" and return the result in "rettv". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
912 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
913 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
914 string_filter_map( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
915 char_u *str, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
916 filtermap_T filtermap, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
917 typval_T *expr, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
918 typval_T *rettv) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
919 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
920 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
921 typval_T tv; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
922 garray_T ga; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
923 int len = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
924 int idx = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
925 int rem; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
926 typval_T newtv; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
927 funccall_T *fc; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
928 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
929 rettv->v_type = VAR_STRING; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
930 rettv->vval.v_string = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
931 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
932 // set_vim_var_nr() doesn't set the type |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
933 set_vim_var_type(VV_KEY, VAR_NUMBER); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
934 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
935 // Create one funccall_T for all eval_expr_typval() calls. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
936 fc = eval_expr_get_funccal(expr, &newtv); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
937 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
938 ga_init2(&ga, sizeof(char), 80); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
939 for (p = str; *p != NUL; p += len) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
940 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
941 if (copy_first_char_to_tv(p, &tv) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
942 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
943 len = (int)STRLEN(tv.vval.v_string); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
944 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
945 newtv.v_type = VAR_UNKNOWN; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
946 set_vim_var_nr(VV_KEY, idx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
947 if (filter_map_one(&tv, expr, filtermap, fc, &newtv, &rem) == FAIL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
948 || did_emsg) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
949 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
950 clear_tv(&newtv); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
951 clear_tv(&tv); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
952 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
953 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
954 else if (filtermap != FILTERMAP_FILTER) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
955 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
956 if (newtv.v_type != VAR_STRING) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
957 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
958 clear_tv(&newtv); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
959 clear_tv(&tv); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
960 emsg(_(e_string_required)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
961 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
962 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
963 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
964 ga_concat(&ga, newtv.vval.v_string); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
965 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
966 else if (!rem) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
967 ga_concat(&ga, tv.vval.v_string); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
968 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
969 clear_tv(&newtv); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
970 clear_tv(&tv); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
971 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
972 ++idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
973 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
974 ga_append(&ga, NUL); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
975 rettv->vval.v_string = ga.ga_data; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
976 if (fc != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
977 remove_funccal(); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
978 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
979 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
980 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
981 * Implementation of reduce() for String "argvars[0]" using the function "expr" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
982 * starting with the optional initial value "argvars[2]" and return the result |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
983 * in "rettv". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
984 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
985 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
986 string_reduce( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
987 typval_T *argvars, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
988 typval_T *expr, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
989 typval_T *rettv) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
990 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
991 char_u *p = tv_get_string(&argvars[0]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
992 int len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
993 typval_T argv[3]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
994 int r; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
995 int called_emsg_start = called_emsg; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
996 funccall_T *fc; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
997 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
998 if (argvars[2].v_type == VAR_UNKNOWN) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
999 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1000 if (*p == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1001 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1002 semsg(_(e_reduce_of_an_empty_str_with_no_initial_value), "String"); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1003 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1004 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1005 if (copy_first_char_to_tv(p, rettv) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1006 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1007 p += STRLEN(rettv->vval.v_string); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1008 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1009 else if (check_for_string_arg(argvars, 2) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1010 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1011 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1012 copy_tv(&argvars[2], rettv); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1013 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1014 // Create one funccall_T for all eval_expr_typval() calls. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1015 fc = eval_expr_get_funccal(expr, rettv); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1016 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1017 for ( ; *p != NUL; p += len) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1018 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1019 argv[0] = *rettv; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1020 if (copy_first_char_to_tv(p, &argv[1]) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1021 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1022 len = (int)STRLEN(argv[1].vval.v_string); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1023 |
32818
705d0e1329a5
patch 9.0.1723: Fix regression in {func} argument of reduce()
Christian Brabandt <cb@256bit.org>
parents:
32798
diff
changeset
|
1024 r = eval_expr_typval(expr, TRUE, argv, 2, fc, rettv); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1025 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1026 clear_tv(&argv[0]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1027 clear_tv(&argv[1]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1028 if (r == FAIL || called_emsg != called_emsg_start) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1029 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1030 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1031 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1032 if (fc != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1033 remove_funccal(); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1034 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1035 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1036 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1037 * Implementation of "byteidx()" and "byteidxcomp()" functions |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1038 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1039 static void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1040 byteidx_common(typval_T *argvars, typval_T *rettv, int comp UNUSED) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1041 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1042 rettv->vval.v_number = -1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1043 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1044 if (in_vim9script() |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1045 && (check_for_string_arg(argvars, 0) == FAIL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1046 || check_for_number_arg(argvars, 1) == FAIL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1047 || check_for_opt_bool_arg(argvars, 2) == FAIL)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1048 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1049 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1050 char_u *str = tv_get_string_chk(&argvars[0]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1051 varnumber_T idx = tv_get_number_chk(&argvars[1], NULL); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1052 if (str == NULL || idx < 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1053 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1054 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1055 varnumber_T utf16idx = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1056 if (argvars[2].v_type != VAR_UNKNOWN) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1057 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1058 int error = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1059 utf16idx = tv_get_bool_chk(&argvars[2], &error); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1060 if (error) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1061 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1062 if (utf16idx < 0 || utf16idx > 1) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1063 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1064 semsg(_(e_using_number_as_bool_nr), utf16idx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1065 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1066 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1067 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1068 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1069 int (*ptr2len)(char_u *); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1070 if (enc_utf8 && comp) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1071 ptr2len = utf_ptr2len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1072 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1073 ptr2len = mb_ptr2len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1074 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1075 char_u *t = str; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1076 for ( ; idx > 0; idx--) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1077 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1078 if (*t == NUL) // EOL reached |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1079 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1080 if (utf16idx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1081 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1082 int clen = ptr2len(t); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1083 int c = (clen > 1) ? utf_ptr2char(t) : *t; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1084 if (c > 0xFFFF) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1085 idx--; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1086 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1087 if (idx > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1088 t += ptr2len(t); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1089 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1090 rettv->vval.v_number = (varnumber_T)(t - str); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1091 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1092 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1093 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1094 * "byteidx()" function |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1095 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1096 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1097 f_byteidx(typval_T *argvars, typval_T *rettv) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1098 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1099 byteidx_common(argvars, rettv, FALSE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1100 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1101 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1102 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1103 * "byteidxcomp()" function |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1104 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1105 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1106 f_byteidxcomp(typval_T *argvars, typval_T *rettv) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1107 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1108 byteidx_common(argvars, rettv, TRUE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1109 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1110 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1111 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1112 * "charidx()" function |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1113 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1114 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1115 f_charidx(typval_T *argvars, typval_T *rettv) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1116 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1117 rettv->vval.v_number = -1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1118 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1119 if (check_for_string_arg(argvars, 0) == FAIL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1120 || check_for_number_arg(argvars, 1) == FAIL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1121 || check_for_opt_bool_arg(argvars, 2) == FAIL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1122 || (argvars[2].v_type != VAR_UNKNOWN |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1123 && check_for_opt_bool_arg(argvars, 3) == FAIL)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1124 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1125 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1126 char_u *str = tv_get_string_chk(&argvars[0]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1127 varnumber_T idx = tv_get_number_chk(&argvars[1], NULL); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1128 if (str == NULL || idx < 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1129 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1130 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1131 varnumber_T countcc = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1132 varnumber_T utf16idx = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1133 if (argvars[2].v_type != VAR_UNKNOWN) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1134 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1135 countcc = tv_get_bool(&argvars[2]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1136 if (argvars[3].v_type != VAR_UNKNOWN) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1137 utf16idx = tv_get_bool(&argvars[3]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1138 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1139 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1140 int (*ptr2len)(char_u *); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1141 if (enc_utf8 && countcc) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1142 ptr2len = utf_ptr2len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1143 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1144 ptr2len = mb_ptr2len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1145 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1146 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1147 int len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1148 for (p = str, len = 0; utf16idx ? idx >= 0 : p <= str + idx; len++) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1149 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1150 if (*p == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1151 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1152 // If the index is exactly the number of bytes or utf-16 code units |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1153 // in the string then return the length of the string in |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1154 // characters. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1155 if (utf16idx ? (idx == 0) : (p == (str + idx))) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1156 rettv->vval.v_number = len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1157 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1158 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1159 if (utf16idx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1160 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1161 idx--; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1162 int clen = ptr2len(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1163 int c = (clen > 1) ? utf_ptr2char(p) : *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1164 if (c > 0xFFFF) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1165 idx--; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1166 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1167 p += ptr2len(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1168 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1169 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1170 rettv->vval.v_number = len > 0 ? len - 1 : 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1171 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1172 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1173 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1174 * "str2list()" function |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1175 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1176 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1177 f_str2list(typval_T *argvars, typval_T *rettv) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1178 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1179 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1180 int utf8 = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1181 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1182 if (rettv_list_alloc(rettv) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1183 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1184 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1185 if (in_vim9script() |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1186 && (check_for_string_arg(argvars, 0) == FAIL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1187 || check_for_opt_bool_arg(argvars, 1) == FAIL)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1188 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1189 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1190 if (argvars[1].v_type != VAR_UNKNOWN) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1191 utf8 = (int)tv_get_bool_chk(&argvars[1], NULL); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1192 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1193 p = tv_get_string(&argvars[0]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1194 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1195 if (has_mbyte || utf8) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1196 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1197 int (*ptr2len)(char_u *); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1198 int (*ptr2char)(char_u *); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1199 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1200 if (utf8 || enc_utf8) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1201 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1202 ptr2len = utf_ptr2len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1203 ptr2char = utf_ptr2char; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1204 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1205 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1206 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1207 ptr2len = mb_ptr2len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1208 ptr2char = mb_ptr2char; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1209 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1210 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1211 for ( ; *p != NUL; p += (*ptr2len)(p)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1212 list_append_number(rettv->vval.v_list, (*ptr2char)(p)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1213 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1214 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1215 for ( ; *p != NUL; ++p) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1216 list_append_number(rettv->vval.v_list, *p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1217 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1218 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1219 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1220 * "str2nr()" function |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1221 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1222 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1223 f_str2nr(typval_T *argvars, typval_T *rettv) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1224 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1225 int base = 10; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1226 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1227 varnumber_T n; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1228 int what = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1229 int isneg; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1230 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1231 if (in_vim9script() |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1232 && (check_for_string_arg(argvars, 0) == FAIL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1233 || check_for_opt_number_arg(argvars, 1) == FAIL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1234 || (argvars[1].v_type != VAR_UNKNOWN |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1235 && check_for_opt_bool_arg(argvars, 2) == FAIL))) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1236 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1237 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1238 if (argvars[1].v_type != VAR_UNKNOWN) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1239 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1240 base = (int)tv_get_number(&argvars[1]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1241 if (base != 2 && base != 8 && base != 10 && base != 16) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1242 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1243 emsg(_(e_invalid_argument)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1244 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1245 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1246 if (argvars[2].v_type != VAR_UNKNOWN && tv_get_bool(&argvars[2])) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1247 what |= STR2NR_QUOTE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1248 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1249 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1250 p = skipwhite(tv_get_string_strict(&argvars[0])); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1251 isneg = (*p == '-'); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1252 if (*p == '+' || *p == '-') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1253 p = skipwhite(p + 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1254 switch (base) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1255 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1256 case 2: what |= STR2NR_BIN + STR2NR_FORCE; break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1257 case 8: what |= STR2NR_OCT + STR2NR_OOCT + STR2NR_FORCE; break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1258 case 16: what |= STR2NR_HEX + STR2NR_FORCE; break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1259 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1260 vim_str2nr(p, NULL, NULL, what, &n, NULL, 0, FALSE, NULL); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1261 // Text after the number is silently ignored. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1262 if (isneg) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1263 rettv->vval.v_number = -n; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1264 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1265 rettv->vval.v_number = n; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1266 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1267 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1268 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1269 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1270 * "strgetchar()" function |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1271 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1272 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1273 f_strgetchar(typval_T *argvars, typval_T *rettv) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1274 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1275 char_u *str; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1276 int len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1277 int error = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1278 int charidx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1279 int byteidx = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1280 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1281 rettv->vval.v_number = -1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1282 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1283 if (in_vim9script() |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1284 && (check_for_string_arg(argvars, 0) == FAIL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1285 || check_for_number_arg(argvars, 1) == FAIL)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1286 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1287 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1288 str = tv_get_string_chk(&argvars[0]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1289 if (str == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1290 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1291 len = (int)STRLEN(str); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1292 charidx = (int)tv_get_number_chk(&argvars[1], &error); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1293 if (error) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1294 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1295 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1296 while (charidx >= 0 && byteidx < len) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1297 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1298 if (charidx == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1299 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1300 rettv->vval.v_number = mb_ptr2char(str + byteidx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1301 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1302 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1303 --charidx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1304 byteidx += MB_CPTR2LEN(str + byteidx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1305 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1306 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1307 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1308 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1309 * "stridx()" function |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1310 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1311 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1312 f_stridx(typval_T *argvars, typval_T *rettv) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1313 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1314 char_u buf[NUMBUFLEN]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1315 char_u *needle; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1316 char_u *haystack; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1317 char_u *save_haystack; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1318 char_u *pos; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1319 int start_idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1320 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1321 if (in_vim9script() |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1322 && (check_for_string_arg(argvars, 0) == FAIL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1323 || check_for_string_arg(argvars, 1) == FAIL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1324 || check_for_opt_number_arg(argvars, 2) == FAIL)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1325 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1326 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1327 needle = tv_get_string_chk(&argvars[1]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1328 save_haystack = haystack = tv_get_string_buf_chk(&argvars[0], buf); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1329 rettv->vval.v_number = -1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1330 if (needle == NULL || haystack == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1331 return; // type error; errmsg already given |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1332 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1333 if (argvars[2].v_type != VAR_UNKNOWN) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1334 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1335 int error = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1336 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1337 start_idx = (int)tv_get_number_chk(&argvars[2], &error); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1338 if (error || start_idx >= (int)STRLEN(haystack)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1339 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1340 if (start_idx >= 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1341 haystack += start_idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1342 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1343 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1344 pos = (char_u *)strstr((char *)haystack, (char *)needle); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1345 if (pos != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1346 rettv->vval.v_number = (varnumber_T)(pos - save_haystack); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1347 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1348 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1349 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1350 * "string()" function |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1351 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1352 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1353 f_string(typval_T *argvars, typval_T *rettv) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1354 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1355 char_u *tofree; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1356 char_u numbuf[NUMBUFLEN]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1357 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1358 rettv->v_type = VAR_STRING; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1359 rettv->vval.v_string = tv2string(&argvars[0], &tofree, numbuf, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1360 get_copyID()); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1361 // Make a copy if we have a value but it's not in allocated memory. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1362 if (rettv->vval.v_string != NULL && tofree == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1363 rettv->vval.v_string = vim_strsave(rettv->vval.v_string); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1364 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1365 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1366 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1367 * "strlen()" function |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1368 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1369 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1370 f_strlen(typval_T *argvars, typval_T *rettv) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1371 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1372 if (in_vim9script() |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1373 && check_for_string_or_number_arg(argvars, 0) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1374 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1375 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1376 rettv->vval.v_number = (varnumber_T)(STRLEN( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1377 tv_get_string(&argvars[0]))); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1378 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1379 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1380 static void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1381 strchar_common(typval_T *argvars, typval_T *rettv, int skipcc) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1382 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1383 char_u *s = tv_get_string(&argvars[0]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1384 varnumber_T len = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1385 int (*func_mb_ptr2char_adv)(char_u **pp); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1386 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1387 func_mb_ptr2char_adv = skipcc ? mb_ptr2char_adv : mb_cptr2char_adv; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1388 while (*s != NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1389 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1390 func_mb_ptr2char_adv(&s); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1391 ++len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1392 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1393 rettv->vval.v_number = len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1394 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1395 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1396 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1397 * "strcharlen()" function |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1398 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1399 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1400 f_strcharlen(typval_T *argvars, typval_T *rettv) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1401 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1402 if (in_vim9script() |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1403 && check_for_string_or_number_arg(argvars, 0) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1404 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1405 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1406 strchar_common(argvars, rettv, TRUE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1407 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1408 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1409 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1410 * "strchars()" function |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1411 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1412 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1413 f_strchars(typval_T *argvars, typval_T *rettv) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1414 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1415 varnumber_T skipcc = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1416 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1417 if (in_vim9script() |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1418 && (check_for_string_arg(argvars, 0) == FAIL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1419 || check_for_opt_bool_arg(argvars, 1) == FAIL)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1420 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1421 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1422 if (argvars[1].v_type != VAR_UNKNOWN) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1423 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1424 int error = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1425 skipcc = tv_get_bool_chk(&argvars[1], &error); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1426 if (error) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1427 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1428 if (skipcc < 0 || skipcc > 1) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1429 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1430 semsg(_(e_using_number_as_bool_nr), skipcc); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1431 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1432 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1433 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1434 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1435 strchar_common(argvars, rettv, skipcc); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1436 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1437 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1438 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1439 * "strutf16len()" function |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1440 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1441 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1442 f_strutf16len(typval_T *argvars, typval_T *rettv) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1443 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1444 rettv->vval.v_number = -1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1445 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1446 if (check_for_string_arg(argvars, 0) == FAIL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1447 || check_for_opt_bool_arg(argvars, 1) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1448 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1449 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1450 varnumber_T countcc = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1451 if (argvars[1].v_type != VAR_UNKNOWN) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1452 countcc = tv_get_bool(&argvars[1]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1453 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1454 char_u *s = tv_get_string(&argvars[0]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1455 varnumber_T len = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1456 int (*func_mb_ptr2char_adv)(char_u **pp); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1457 int ch; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1458 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1459 func_mb_ptr2char_adv = countcc ? mb_cptr2char_adv : mb_ptr2char_adv; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1460 while (*s != NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1461 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1462 ch = func_mb_ptr2char_adv(&s); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1463 if (ch > 0xFFFF) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1464 ++len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1465 ++len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1466 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1467 rettv->vval.v_number = len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1468 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1469 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1470 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1471 * "strdisplaywidth()" function |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1472 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1473 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1474 f_strdisplaywidth(typval_T *argvars, typval_T *rettv) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1475 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1476 char_u *s; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1477 int col = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1478 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1479 rettv->vval.v_number = -1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1480 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1481 if (in_vim9script() |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1482 && (check_for_string_arg(argvars, 0) == FAIL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1483 || check_for_opt_number_arg(argvars, 1) == FAIL)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1484 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1485 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1486 s = tv_get_string(&argvars[0]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1487 if (argvars[1].v_type != VAR_UNKNOWN) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1488 col = (int)tv_get_number(&argvars[1]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1489 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1490 rettv->vval.v_number = (varnumber_T)(linetabsize_col(col, s) - col); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1491 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1492 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1493 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1494 * "strwidth()" function |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1495 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1496 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1497 f_strwidth(typval_T *argvars, typval_T *rettv) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1498 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1499 char_u *s; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1500 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1501 if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1502 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1503 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1504 s = tv_get_string_strict(&argvars[0]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1505 rettv->vval.v_number = (varnumber_T)(mb_string2cells(s, -1)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1506 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1507 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1508 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1509 * "strcharpart()" function |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1510 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1511 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1512 f_strcharpart(typval_T *argvars, typval_T *rettv) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1513 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1514 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1515 int nchar; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1516 int nbyte = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1517 int charlen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1518 int skipcc = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1519 int len = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1520 int slen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1521 int error = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1522 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1523 if (in_vim9script() |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1524 && (check_for_string_arg(argvars, 0) == FAIL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1525 || check_for_number_arg(argvars, 1) == FAIL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1526 || check_for_opt_number_arg(argvars, 2) == FAIL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1527 || (argvars[2].v_type != VAR_UNKNOWN |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1528 && check_for_opt_bool_arg(argvars, 3) == FAIL))) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1529 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1530 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1531 p = tv_get_string(&argvars[0]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1532 slen = (int)STRLEN(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1533 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1534 nchar = (int)tv_get_number_chk(&argvars[1], &error); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1535 if (!error) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1536 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1537 if (argvars[2].v_type != VAR_UNKNOWN |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1538 && argvars[3].v_type != VAR_UNKNOWN) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1539 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1540 skipcc = tv_get_bool_chk(&argvars[3], &error); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1541 if (error) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1542 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1543 if (skipcc < 0 || skipcc > 1) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1544 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1545 semsg(_(e_using_number_as_bool_nr), skipcc); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1546 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1547 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1548 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1549 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1550 if (nchar > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1551 while (nchar > 0 && nbyte < slen) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1552 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1553 if (skipcc) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1554 nbyte += mb_ptr2len(p + nbyte); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1555 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1556 nbyte += MB_CPTR2LEN(p + nbyte); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1557 --nchar; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1558 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1559 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1560 nbyte = nchar; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1561 if (argvars[2].v_type != VAR_UNKNOWN) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1562 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1563 charlen = (int)tv_get_number(&argvars[2]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1564 while (charlen > 0 && nbyte + len < slen) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1565 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1566 int off = nbyte + len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1567 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1568 if (off < 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1569 len += 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1570 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1571 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1572 if (skipcc) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1573 len += mb_ptr2len(p + off); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1574 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1575 len += MB_CPTR2LEN(p + off); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1576 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1577 --charlen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1578 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1579 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1580 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1581 len = slen - nbyte; // default: all bytes that are available. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1582 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1583 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1584 // Only return the overlap between the specified part and the actual |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1585 // string. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1586 if (nbyte < 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1587 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1588 len += nbyte; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1589 nbyte = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1590 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1591 else if (nbyte > slen) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1592 nbyte = slen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1593 if (len < 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1594 len = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1595 else if (nbyte + len > slen) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1596 len = slen - nbyte; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1597 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1598 rettv->v_type = VAR_STRING; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1599 rettv->vval.v_string = vim_strnsave(p + nbyte, len); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1600 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1601 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1602 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1603 * "strpart()" function |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1604 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1605 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1606 f_strpart(typval_T *argvars, typval_T *rettv) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1607 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1608 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1609 int n; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1610 int len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1611 int slen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1612 int error = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1613 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1614 if (in_vim9script() |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1615 && (check_for_string_arg(argvars, 0) == FAIL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1616 || check_for_number_arg(argvars, 1) == FAIL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1617 || check_for_opt_number_arg(argvars, 2) == FAIL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1618 || (argvars[2].v_type != VAR_UNKNOWN |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1619 && check_for_opt_bool_arg(argvars, 3) == FAIL))) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1620 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1621 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1622 p = tv_get_string(&argvars[0]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1623 slen = (int)STRLEN(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1624 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1625 n = (int)tv_get_number_chk(&argvars[1], &error); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1626 if (error) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1627 len = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1628 else if (argvars[2].v_type != VAR_UNKNOWN) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1629 len = (int)tv_get_number(&argvars[2]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1630 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1631 len = slen - n; // default len: all bytes that are available. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1632 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1633 // Only return the overlap between the specified part and the actual |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1634 // string. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1635 if (n < 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1636 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1637 len += n; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1638 n = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1639 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1640 else if (n > slen) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1641 n = slen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1642 if (len < 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1643 len = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1644 else if (n + len > slen) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1645 len = slen - n; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1646 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1647 if (argvars[2].v_type != VAR_UNKNOWN && argvars[3].v_type != VAR_UNKNOWN) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1648 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1649 int off; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1650 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1651 // length in characters |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1652 for (off = n; off < slen && len > 0; --len) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1653 off += mb_ptr2len(p + off); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1654 len = off - n; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1655 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1656 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1657 rettv->v_type = VAR_STRING; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1658 rettv->vval.v_string = vim_strnsave(p + n, len); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1659 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1660 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1661 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1662 * "strridx()" function |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1663 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1664 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1665 f_strridx(typval_T *argvars, typval_T *rettv) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1666 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1667 char_u buf[NUMBUFLEN]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1668 char_u *needle; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1669 char_u *haystack; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1670 char_u *rest; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1671 char_u *lastmatch = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1672 int haystack_len, end_idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1673 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1674 if (in_vim9script() |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1675 && (check_for_string_arg(argvars, 0) == FAIL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1676 || check_for_string_arg(argvars, 1) == FAIL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1677 || check_for_opt_number_arg(argvars, 2) == FAIL)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1678 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1679 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1680 needle = tv_get_string_chk(&argvars[1]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1681 haystack = tv_get_string_buf_chk(&argvars[0], buf); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1682 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1683 rettv->vval.v_number = -1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1684 if (needle == NULL || haystack == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1685 return; // type error; errmsg already given |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1686 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1687 haystack_len = (int)STRLEN(haystack); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1688 if (argvars[2].v_type != VAR_UNKNOWN) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1689 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1690 // Third argument: upper limit for index |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1691 end_idx = (int)tv_get_number_chk(&argvars[2], NULL); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1692 if (end_idx < 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1693 return; // can never find a match |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1694 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1695 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1696 end_idx = haystack_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1697 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1698 if (*needle == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1699 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1700 // Empty string matches past the end. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1701 lastmatch = haystack + end_idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1702 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1703 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1704 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1705 for (rest = haystack; *rest != '\0'; ++rest) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1706 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1707 rest = (char_u *)strstr((char *)rest, (char *)needle); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1708 if (rest == NULL || rest > haystack + end_idx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1709 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1710 lastmatch = rest; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1711 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1712 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1713 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1714 if (lastmatch == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1715 rettv->vval.v_number = -1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1716 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1717 rettv->vval.v_number = (varnumber_T)(lastmatch - haystack); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1718 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1719 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1720 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1721 * "strtrans()" function |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1722 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1723 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1724 f_strtrans(typval_T *argvars, typval_T *rettv) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1725 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1726 if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1727 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1728 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1729 rettv->v_type = VAR_STRING; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1730 rettv->vval.v_string = transstr(tv_get_string(&argvars[0])); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1731 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1732 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1733 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1734 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1735 * "utf16idx()" function |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1736 * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1737 * Converts a byte or character offset in a string to the corresponding UTF-16 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1738 * code unit offset. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1739 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1740 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1741 f_utf16idx(typval_T *argvars, typval_T *rettv) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1742 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1743 rettv->vval.v_number = -1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1744 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1745 if (check_for_string_arg(argvars, 0) == FAIL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1746 || check_for_opt_number_arg(argvars, 1) == FAIL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1747 || check_for_opt_bool_arg(argvars, 2) == FAIL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1748 || (argvars[2].v_type != VAR_UNKNOWN |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1749 && check_for_opt_bool_arg(argvars, 3) == FAIL)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1750 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1751 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1752 char_u *str = tv_get_string_chk(&argvars[0]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1753 varnumber_T idx = tv_get_number_chk(&argvars[1], NULL); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1754 if (str == NULL || idx < 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1755 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1756 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1757 varnumber_T countcc = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1758 varnumber_T charidx = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1759 if (argvars[2].v_type != VAR_UNKNOWN) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1760 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1761 countcc = tv_get_bool(&argvars[2]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1762 if (argvars[3].v_type != VAR_UNKNOWN) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1763 charidx = tv_get_bool(&argvars[3]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1764 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1765 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1766 int (*ptr2len)(char_u *); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1767 if (enc_utf8 && countcc) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1768 ptr2len = utf_ptr2len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1769 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1770 ptr2len = mb_ptr2len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1771 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1772 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1773 int len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1774 int utf16idx = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1775 for (p = str, len = 0; charidx ? idx >= 0 : p <= str + idx; len++) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1776 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1777 if (*p == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1778 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1779 // If the index is exactly the number of bytes or characters in the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1780 // string then return the length of the string in utf-16 code |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1781 // units. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1782 if (charidx ? (idx == 0) : (p == (str + idx))) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1783 rettv->vval.v_number = len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1784 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1785 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1786 utf16idx = len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1787 int clen = ptr2len(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1788 int c = (clen > 1) ? utf_ptr2char(p) : *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1789 if (c > 0xFFFF) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1790 len++; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1791 p += ptr2len(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1792 if (charidx) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1793 idx--; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1794 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1795 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1796 rettv->vval.v_number = utf16idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1797 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1798 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1799 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1800 * "tolower(string)" function |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1801 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1802 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1803 f_tolower(typval_T *argvars, typval_T *rettv) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1804 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1805 if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1806 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1807 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1808 rettv->v_type = VAR_STRING; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1809 rettv->vval.v_string = strlow_save(tv_get_string(&argvars[0])); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1810 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1811 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1812 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1813 * "toupper(string)" function |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1814 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1815 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1816 f_toupper(typval_T *argvars, typval_T *rettv) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1817 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1818 if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1819 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1820 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1821 rettv->v_type = VAR_STRING; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1822 rettv->vval.v_string = strup_save(tv_get_string(&argvars[0])); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1823 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1824 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1825 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1826 * "tr(string, fromstr, tostr)" function |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1827 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1828 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1829 f_tr(typval_T *argvars, typval_T *rettv) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1830 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1831 char_u *in_str; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1832 char_u *fromstr; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1833 char_u *tostr; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1834 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1835 int inlen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1836 int fromlen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1837 int tolen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1838 int idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1839 char_u *cpstr; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1840 int cplen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1841 int first = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1842 char_u buf[NUMBUFLEN]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1843 char_u buf2[NUMBUFLEN]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1844 garray_T ga; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1845 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1846 if (in_vim9script() |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1847 && (check_for_string_arg(argvars, 0) == FAIL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1848 || check_for_string_arg(argvars, 1) == FAIL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1849 || check_for_string_arg(argvars, 2) == FAIL)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1850 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1851 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1852 in_str = tv_get_string(&argvars[0]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1853 fromstr = tv_get_string_buf_chk(&argvars[1], buf); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1854 tostr = tv_get_string_buf_chk(&argvars[2], buf2); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1855 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1856 // Default return value: empty string. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1857 rettv->v_type = VAR_STRING; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1858 rettv->vval.v_string = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1859 if (fromstr == NULL || tostr == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1860 return; // type error; errmsg already given |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1861 ga_init2(&ga, sizeof(char), 80); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1862 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1863 if (!has_mbyte) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1864 // not multi-byte: fromstr and tostr must be the same length |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1865 if (STRLEN(fromstr) != STRLEN(tostr)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1866 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1867 error: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1868 semsg(_(e_invalid_argument_str), fromstr); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1869 ga_clear(&ga); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1870 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1871 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1872 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1873 // fromstr and tostr have to contain the same number of chars |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1874 while (*in_str != NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1875 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1876 if (has_mbyte) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1877 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1878 inlen = (*mb_ptr2len)(in_str); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1879 cpstr = in_str; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1880 cplen = inlen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1881 idx = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1882 for (p = fromstr; *p != NUL; p += fromlen) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1883 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1884 fromlen = (*mb_ptr2len)(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1885 if (fromlen == inlen && STRNCMP(in_str, p, inlen) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1886 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1887 for (p = tostr; *p != NUL; p += tolen) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1888 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1889 tolen = (*mb_ptr2len)(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1890 if (idx-- == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1891 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1892 cplen = tolen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1893 cpstr = p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1894 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1895 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1896 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1897 if (*p == NUL) // tostr is shorter than fromstr |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1898 goto error; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1899 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1900 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1901 ++idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1902 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1903 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1904 if (first && cpstr == in_str) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1905 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1906 // Check that fromstr and tostr have the same number of |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1907 // (multi-byte) characters. Done only once when a character |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1908 // of in_str doesn't appear in fromstr. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1909 first = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1910 for (p = tostr; *p != NUL; p += tolen) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1911 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1912 tolen = (*mb_ptr2len)(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1913 --idx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1914 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1915 if (idx != 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1916 goto error; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1917 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1918 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1919 (void)ga_grow(&ga, cplen); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1920 mch_memmove((char *)ga.ga_data + ga.ga_len, cpstr, (size_t)cplen); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1921 ga.ga_len += cplen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1922 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1923 in_str += inlen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1924 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1925 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1926 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1927 // When not using multi-byte chars we can do it faster. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1928 p = vim_strchr(fromstr, *in_str); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1929 if (p != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1930 ga_append(&ga, tostr[p - fromstr]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1931 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1932 ga_append(&ga, *in_str); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1933 ++in_str; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1934 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1935 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1936 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1937 // add a terminating NUL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1938 (void)ga_grow(&ga, 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1939 ga_append(&ga, NUL); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1940 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1941 rettv->vval.v_string = ga.ga_data; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1942 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1943 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1944 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1945 * "trim({expr})" function |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1946 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1947 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1948 f_trim(typval_T *argvars, typval_T *rettv) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1949 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1950 char_u buf1[NUMBUFLEN]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1951 char_u buf2[NUMBUFLEN]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1952 char_u *head; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1953 char_u *mask = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1954 char_u *tail; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1955 char_u *prev; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1956 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1957 int c1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1958 int dir = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1959 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1960 rettv->v_type = VAR_STRING; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1961 rettv->vval.v_string = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1962 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1963 if (in_vim9script() |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1964 && (check_for_string_arg(argvars, 0) == FAIL |
33594
e9c70470fe94
patch 9.0.2041: trim(): hard to use default mask
Christian Brabandt <cb@256bit.org>
parents:
33591
diff
changeset
|
1965 || check_for_opt_string_arg(argvars, 1) == FAIL |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1966 || (argvars[1].v_type != VAR_UNKNOWN |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1967 && check_for_opt_number_arg(argvars, 2) == FAIL))) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1968 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1969 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1970 head = tv_get_string_buf_chk(&argvars[0], buf1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1971 if (head == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1972 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1973 |
33594
e9c70470fe94
patch 9.0.2041: trim(): hard to use default mask
Christian Brabandt <cb@256bit.org>
parents:
33591
diff
changeset
|
1974 if (check_for_opt_string_arg(argvars, 1) == FAIL) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1975 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1976 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1977 if (argvars[1].v_type == VAR_STRING) |
33594
e9c70470fe94
patch 9.0.2041: trim(): hard to use default mask
Christian Brabandt <cb@256bit.org>
parents:
33591
diff
changeset
|
1978 { |
33591
288da62613ba
patch 9.0.2040: trim(): hard to use default mask
Christian Brabandt <cb@256bit.org>
parents:
33494
diff
changeset
|
1979 mask = tv_get_string_buf_chk(&argvars[1], buf2); |
33594
e9c70470fe94
patch 9.0.2041: trim(): hard to use default mask
Christian Brabandt <cb@256bit.org>
parents:
33591
diff
changeset
|
1980 if (*mask == NUL) |
e9c70470fe94
patch 9.0.2041: trim(): hard to use default mask
Christian Brabandt <cb@256bit.org>
parents:
33591
diff
changeset
|
1981 mask = NULL; |
e9c70470fe94
patch 9.0.2041: trim(): hard to use default mask
Christian Brabandt <cb@256bit.org>
parents:
33591
diff
changeset
|
1982 |
e9c70470fe94
patch 9.0.2041: trim(): hard to use default mask
Christian Brabandt <cb@256bit.org>
parents:
33591
diff
changeset
|
1983 if (argvars[2].v_type != VAR_UNKNOWN) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1984 { |
33594
e9c70470fe94
patch 9.0.2041: trim(): hard to use default mask
Christian Brabandt <cb@256bit.org>
parents:
33591
diff
changeset
|
1985 int error = 0; |
e9c70470fe94
patch 9.0.2041: trim(): hard to use default mask
Christian Brabandt <cb@256bit.org>
parents:
33591
diff
changeset
|
1986 |
e9c70470fe94
patch 9.0.2041: trim(): hard to use default mask
Christian Brabandt <cb@256bit.org>
parents:
33591
diff
changeset
|
1987 // leading or trailing characters to trim |
e9c70470fe94
patch 9.0.2041: trim(): hard to use default mask
Christian Brabandt <cb@256bit.org>
parents:
33591
diff
changeset
|
1988 dir = (int)tv_get_number_chk(&argvars[2], &error); |
e9c70470fe94
patch 9.0.2041: trim(): hard to use default mask
Christian Brabandt <cb@256bit.org>
parents:
33591
diff
changeset
|
1989 if (error) |
e9c70470fe94
patch 9.0.2041: trim(): hard to use default mask
Christian Brabandt <cb@256bit.org>
parents:
33591
diff
changeset
|
1990 return; |
e9c70470fe94
patch 9.0.2041: trim(): hard to use default mask
Christian Brabandt <cb@256bit.org>
parents:
33591
diff
changeset
|
1991 if (dir < 0 || dir > 2) |
e9c70470fe94
patch 9.0.2041: trim(): hard to use default mask
Christian Brabandt <cb@256bit.org>
parents:
33591
diff
changeset
|
1992 { |
e9c70470fe94
patch 9.0.2041: trim(): hard to use default mask
Christian Brabandt <cb@256bit.org>
parents:
33591
diff
changeset
|
1993 semsg(_(e_invalid_argument_str), tv_get_string(&argvars[2])); |
e9c70470fe94
patch 9.0.2041: trim(): hard to use default mask
Christian Brabandt <cb@256bit.org>
parents:
33591
diff
changeset
|
1994 return; |
e9c70470fe94
patch 9.0.2041: trim(): hard to use default mask
Christian Brabandt <cb@256bit.org>
parents:
33591
diff
changeset
|
1995 } |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1996 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1997 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1998 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1999 if (dir == 0 || dir == 1) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2000 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2001 // Trim leading characters |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2002 while (*head != NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2003 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2004 c1 = PTR2CHAR(head); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2005 if (mask == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2006 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2007 if (c1 > ' ' && c1 != 0xa0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2008 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2009 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2010 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2011 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2012 for (p = mask; *p != NUL; MB_PTR_ADV(p)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2013 if (c1 == PTR2CHAR(p)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2014 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2015 if (*p == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2016 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2017 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2018 MB_PTR_ADV(head); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2019 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2020 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2021 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2022 tail = head + STRLEN(head); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2023 if (dir == 0 || dir == 2) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2024 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2025 // Trim trailing characters |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2026 for (; tail > head; tail = prev) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2027 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2028 prev = tail; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2029 MB_PTR_BACK(head, prev); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2030 c1 = PTR2CHAR(prev); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2031 if (mask == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2032 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2033 if (c1 > ' ' && c1 != 0xa0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2034 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2035 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2036 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2037 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2038 for (p = mask; *p != NUL; MB_PTR_ADV(p)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2039 if (c1 == PTR2CHAR(p)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2040 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2041 if (*p == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2042 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2043 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2044 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2045 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2046 rettv->vval.v_string = vim_strnsave(head, tail - head); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2047 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2048 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2049 static char *e_printf = N_(e_insufficient_arguments_for_printf); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2050 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2051 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2052 * Get number argument from "idxp" entry in "tvs". First entry is 1. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2053 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2054 static varnumber_T |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2055 tv_nr(typval_T *tvs, int *idxp) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2056 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2057 int idx = *idxp - 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2058 varnumber_T n = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2059 int err = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2060 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2061 if (tvs[idx].v_type == VAR_UNKNOWN) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2062 emsg(_(e_printf)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2063 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2064 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2065 ++*idxp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2066 n = tv_get_number_chk(&tvs[idx], &err); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2067 if (err) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2068 n = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2069 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2070 return n; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2071 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2072 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2073 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2074 * Get string argument from "idxp" entry in "tvs". First entry is 1. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2075 * If "tofree" is NULL tv_get_string_chk() is used. Some types (e.g. List) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2076 * are not converted to a string. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2077 * If "tofree" is not NULL echo_string() is used. All types are converted to |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2078 * a string with the same format as ":echo". The caller must free "*tofree". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2079 * Returns NULL for an error. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2080 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2081 static char * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2082 tv_str(typval_T *tvs, int *idxp, char_u **tofree) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2083 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2084 int idx = *idxp - 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2085 char *s = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2086 static char_u numbuf[NUMBUFLEN]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2087 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2088 if (tvs[idx].v_type == VAR_UNKNOWN) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2089 emsg(_(e_printf)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2090 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2091 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2092 ++*idxp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2093 if (tofree != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2094 s = (char *)echo_string(&tvs[idx], tofree, numbuf, get_copyID()); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2095 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2096 s = (char *)tv_get_string_chk(&tvs[idx]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2097 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2098 return s; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2099 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2100 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2101 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2102 * Get float argument from "idxp" entry in "tvs". First entry is 1. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2103 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2104 static double |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2105 tv_float(typval_T *tvs, int *idxp) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2106 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2107 int idx = *idxp - 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2108 double f = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2109 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2110 if (tvs[idx].v_type == VAR_UNKNOWN) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2111 emsg(_(e_printf)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2112 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2113 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2114 ++*idxp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2115 if (tvs[idx].v_type == VAR_FLOAT) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2116 f = tvs[idx].vval.v_float; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2117 else if (tvs[idx].v_type == VAR_NUMBER) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2118 f = (double)tvs[idx].vval.v_number; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2119 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2120 emsg(_(e_expected_float_argument_for_printf)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2121 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2122 return f; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2123 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2124 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2125 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2126 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2127 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2128 * Return the representation of infinity for printf() function: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2129 * "-inf", "inf", "+inf", " inf", "-INF", "INF", "+INF" or " INF". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2130 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2131 static const char * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2132 infinity_str(int positive, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2133 char fmt_spec, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2134 int force_sign, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2135 int space_for_positive) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2136 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2137 static const char *table[] = |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2138 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2139 "-inf", "inf", "+inf", " inf", |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2140 "-INF", "INF", "+INF", " INF" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2141 }; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2142 int idx = positive * (1 + force_sign + force_sign * space_for_positive); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2143 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2144 if (ASCII_ISUPPER(fmt_spec)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2145 idx += 4; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2146 return table[idx]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2147 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2148 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2149 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2150 * This code was included to provide a portable vsnprintf() and snprintf(). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2151 * Some systems may provide their own, but we always use this one for |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2152 * consistency. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2153 * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2154 * This code is based on snprintf.c - a portable implementation of snprintf |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2155 * by Mark Martinec <mark.martinec@ijs.si>, Version 2.2, 2000-10-06. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2156 * Included with permission. It was heavily modified to fit in Vim. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2157 * The original code, including useful comments, can be found here: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2158 * http://www.ijs.si/software/snprintf/ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2159 * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2160 * This snprintf() only supports the following conversion specifiers: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2161 * s, c, d, u, o, x, X, p (and synonyms: i, D, U, O - see below) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2162 * with flags: '-', '+', ' ', '0' and '#'. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2163 * An asterisk is supported for field width as well as precision. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2164 * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2165 * Limited support for floating point was added: 'f', 'F', 'e', 'E', 'g', 'G'. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2166 * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2167 * Length modifiers 'h' (short int) and 'l' (long int) and 'll' (long long int) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2168 * are supported. NOTE: for 'll' the argument is varnumber_T or uvarnumber_T. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2169 * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2170 * The locale is not used, the string is used as a byte string. This is only |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2171 * relevant for double-byte encodings where the second byte may be '%'. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2172 * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2173 * It is permitted for "str_m" to be zero, and it is permitted to specify NULL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2174 * pointer for resulting string argument if "str_m" is zero (as per ISO C99). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2175 * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2176 * The return value is the number of characters which would be generated |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2177 * for the given input, excluding the trailing NUL. If this value |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2178 * is greater or equal to "str_m", not all characters from the result |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2179 * have been stored in str, output bytes beyond the ("str_m"-1) -th character |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2180 * are discarded. If "str_m" is greater than zero it is guaranteed |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2181 * the resulting string will be NUL-terminated. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2182 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2183 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2184 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2185 * When va_list is not supported we only define vim_snprintf(). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2186 * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2187 * vim_vsnprintf_typval() can be invoked with either "va_list" or a list of |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2188 * "typval_T". When the latter is not used it must be NULL. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2189 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2190 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2191 // When generating prototypes all of this is skipped, cproto doesn't |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2192 // understand this. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2193 #ifndef PROTO |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2194 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2195 // Like vim_vsnprintf() but append to the string. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2196 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2197 vim_snprintf_add(char *str, size_t str_m, const char *fmt, ...) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2198 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2199 va_list ap; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2200 int str_l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2201 size_t len = STRLEN(str); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2202 size_t space; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2203 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2204 if (str_m <= len) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2205 space = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2206 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2207 space = str_m - len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2208 va_start(ap, fmt); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2209 str_l = vim_vsnprintf(str + len, space, fmt, ap); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2210 va_end(ap); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2211 return str_l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2212 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2213 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2214 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2215 vim_snprintf(char *str, size_t str_m, const char *fmt, ...) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2216 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2217 va_list ap; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2218 int str_l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2219 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2220 va_start(ap, fmt); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2221 str_l = vim_vsnprintf(str, str_m, fmt, ap); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2222 va_end(ap); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2223 return str_l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2224 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2225 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2226 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2227 vim_vsnprintf( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2228 char *str, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2229 size_t str_m, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2230 const char *fmt, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2231 va_list ap) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2232 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2233 return vim_vsnprintf_typval(str, str_m, fmt, ap, NULL); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2234 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2235 |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2236 enum |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2237 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2238 TYPE_UNKNOWN = -1, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2239 TYPE_INT, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2240 TYPE_LONGINT, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2241 TYPE_LONGLONGINT, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2242 TYPE_UNSIGNEDINT, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2243 TYPE_UNSIGNEDLONGINT, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2244 TYPE_UNSIGNEDLONGLONGINT, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2245 TYPE_POINTER, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2246 TYPE_PERCENT, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2247 TYPE_CHAR, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2248 TYPE_STRING, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2249 TYPE_FLOAT |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2250 }; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2251 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2252 /* Types that can be used in a format string |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2253 */ |
32798
f48e27f20e6b
patch 9.0.1715: duplicate test in message_test.c
Christian Brabandt <cb@256bit.org>
parents:
32775
diff
changeset
|
2254 static int |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2255 format_typeof( |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
2256 const char *type) |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2257 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2258 // allowed values: \0, h, l, L |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2259 char length_modifier = '\0'; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2260 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2261 // current conversion specifier character |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2262 char fmt_spec = '\0'; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2263 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2264 // parse 'h', 'l' and 'll' length modifiers |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2265 if (*type == 'h' || *type == 'l') |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2266 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2267 length_modifier = *type; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2268 type++; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2269 if (length_modifier == 'l' && *type == 'l') |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2270 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2271 // double l = __int64 / varnumber_T |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2272 length_modifier = 'L'; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2273 type++; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2274 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2275 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2276 fmt_spec = *type; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2277 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2278 // common synonyms: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2279 switch (fmt_spec) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2280 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2281 case 'i': fmt_spec = 'd'; break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2282 case '*': fmt_spec = 'd'; length_modifier = 'h'; break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2283 case 'D': fmt_spec = 'd'; length_modifier = 'l'; break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2284 case 'U': fmt_spec = 'u'; length_modifier = 'l'; break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2285 case 'O': fmt_spec = 'o'; length_modifier = 'l'; break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2286 default: break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2287 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2288 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2289 // get parameter value, do initial processing |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2290 switch (fmt_spec) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2291 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2292 // '%' and 'c' behave similar to 's' regarding flags and field |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2293 // widths |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2294 case '%': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2295 return TYPE_PERCENT; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2296 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2297 case 'c': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2298 return TYPE_CHAR; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2299 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2300 case 's': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2301 case 'S': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2302 return TYPE_STRING; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2303 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2304 case 'd': case 'u': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2305 case 'b': case 'B': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2306 case 'o': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2307 case 'x': case 'X': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2308 case 'p': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2309 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2310 // NOTE: the u, b, o, x, X and p conversion specifiers |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2311 // imply the value is unsigned; d implies a signed |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2312 // value |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2313 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2314 // 0 if numeric argument is zero (or if pointer is |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2315 // NULL for 'p'), +1 if greater than zero (or nonzero |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2316 // for unsigned arguments), -1 if negative (unsigned |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2317 // argument is never negative) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2318 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2319 if (fmt_spec == 'p') |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2320 return TYPE_POINTER; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2321 else if (fmt_spec == 'b' || fmt_spec == 'B') |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
2322 return TYPE_UNSIGNEDLONGLONGINT; |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2323 else if (fmt_spec == 'd') |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2324 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2325 // signed |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2326 switch (length_modifier) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2327 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2328 case '\0': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2329 case 'h': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2330 // char and short arguments are passed as int. |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2331 return TYPE_INT; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2332 case 'l': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2333 return TYPE_LONGINT; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2334 case 'L': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2335 return TYPE_LONGLONGINT; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2336 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2337 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2338 else |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2339 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2340 // unsigned |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2341 switch (length_modifier) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2342 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2343 case '\0': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2344 case 'h': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2345 return TYPE_UNSIGNEDINT; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2346 case 'l': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2347 return TYPE_UNSIGNEDLONGINT; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2348 case 'L': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2349 return TYPE_UNSIGNEDLONGLONGINT; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2350 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2351 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2352 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2353 break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2354 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2355 case 'f': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2356 case 'F': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2357 case 'e': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2358 case 'E': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2359 case 'g': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2360 case 'G': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2361 return TYPE_FLOAT; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2362 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2363 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2364 return TYPE_UNKNOWN; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2365 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2366 |
32798
f48e27f20e6b
patch 9.0.1715: duplicate test in message_test.c
Christian Brabandt <cb@256bit.org>
parents:
32775
diff
changeset
|
2367 static char * |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2368 format_typename( |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2369 const char *type) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2370 { |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
2371 switch (format_typeof(type)) |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2372 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2373 case TYPE_INT: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2374 return _(typename_int); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2375 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2376 case TYPE_LONGINT: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2377 return _(typename_longint); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2378 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2379 case TYPE_LONGLONGINT: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2380 return _(typename_longlongint); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2381 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2382 case TYPE_UNSIGNEDINT: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2383 return _(typename_unsignedint); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2384 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2385 case TYPE_UNSIGNEDLONGINT: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2386 return _(typename_unsignedlongint); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2387 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2388 case TYPE_UNSIGNEDLONGLONGINT: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2389 return _(typename_unsignedlonglongint); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2390 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2391 case TYPE_POINTER: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2392 return _(typename_pointer); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2393 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2394 case TYPE_PERCENT: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2395 return _(typename_percent); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2396 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2397 case TYPE_CHAR: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2398 return _(typename_char); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2399 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2400 case TYPE_STRING: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2401 return _(typename_string); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2402 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2403 case TYPE_FLOAT: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2404 return _(typename_float); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2405 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2406 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2407 return _(typename_unknown); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2408 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2409 |
32798
f48e27f20e6b
patch 9.0.1715: duplicate test in message_test.c
Christian Brabandt <cb@256bit.org>
parents:
32775
diff
changeset
|
2410 static int |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2411 adjust_types( |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2412 const char ***ap_types, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2413 int arg, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2414 int *num_posarg, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2415 const char *type) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2416 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2417 if (*ap_types == NULL || *num_posarg < arg) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2418 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2419 int idx; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2420 const char **new_types; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2421 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2422 if (*ap_types == NULL) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2423 new_types = ALLOC_CLEAR_MULT(const char *, arg); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2424 else |
32991
0bdb1f8a17c1
patch 9.0.1788: C4090 warnings in strings.c
Christian Brabandt <cb@256bit.org>
parents:
32856
diff
changeset
|
2425 new_types = vim_realloc((char **)*ap_types, |
0bdb1f8a17c1
patch 9.0.1788: C4090 warnings in strings.c
Christian Brabandt <cb@256bit.org>
parents:
32856
diff
changeset
|
2426 arg * sizeof(const char *)); |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2427 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2428 if (new_types == NULL) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2429 return FAIL; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2430 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2431 for (idx = *num_posarg; idx < arg; ++idx) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2432 new_types[idx] = NULL; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2433 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2434 *ap_types = new_types; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2435 *num_posarg = arg; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2436 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2437 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2438 if ((*ap_types)[arg - 1] != NULL) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2439 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2440 if ((*ap_types)[arg - 1][0] == '*' || type[0] == '*') |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2441 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2442 const char *pt = type; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2443 if (pt[0] == '*') |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2444 pt = (*ap_types)[arg - 1]; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2445 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2446 if (pt[0] != '*') |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2447 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2448 switch (pt[0]) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2449 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2450 case 'd': case 'i': break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2451 default: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2452 semsg(_(e_positional_num_field_spec_reused_str_str), arg, format_typename((*ap_types)[arg - 1]), format_typename(type)); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2453 return FAIL; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2454 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2455 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2456 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2457 else |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2458 { |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
2459 if (format_typeof(type) != format_typeof((*ap_types)[arg - 1])) |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2460 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2461 semsg(_( e_positional_arg_num_type_inconsistent_str_str), arg, format_typename(type), format_typename((*ap_types)[arg - 1])); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2462 return FAIL; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2463 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2464 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2465 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2466 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2467 (*ap_types)[arg - 1] = type; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2468 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2469 return OK; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2470 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2471 |
32798
f48e27f20e6b
patch 9.0.1715: duplicate test in message_test.c
Christian Brabandt <cb@256bit.org>
parents:
32775
diff
changeset
|
2472 static int |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2473 parse_fmt_types( |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2474 const char ***ap_types, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2475 int *num_posarg, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2476 const char *fmt, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2477 typval_T *tvs UNUSED |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2478 ) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2479 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2480 const char *p = fmt; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2481 const char *arg = NULL; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2482 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2483 int any_pos = 0; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2484 int any_arg = 0; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2485 int arg_idx; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2486 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2487 #define CHECK_POS_ARG do { \ |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2488 if (any_pos && any_arg) \ |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2489 { \ |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2490 semsg(_( e_cannot_mix_positional_and_non_positional_str), fmt); \ |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2491 goto error; \ |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2492 } \ |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2493 } while (0); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2494 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2495 if (p == NULL) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2496 return OK; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2497 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2498 while (*p != NUL) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2499 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2500 if (*p != '%') |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2501 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2502 char *q = strchr(p + 1, '%'); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2503 size_t n = (q == NULL) ? STRLEN(p) : (size_t)(q - p); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2504 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2505 p += n; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2506 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2507 else |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2508 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2509 // allowed values: \0, h, l, L |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2510 char length_modifier = '\0'; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2511 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2512 // variable for positional arg |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2513 int pos_arg = -1; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2514 const char *ptype = NULL; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2515 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2516 p++; // skip '%' |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2517 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2518 // First check to see if we find a positional |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2519 // argument specifier |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2520 ptype = p; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2521 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2522 while (VIM_ISDIGIT(*ptype)) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2523 ++ptype; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2524 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2525 if (*ptype == '$') |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2526 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2527 if (*p == '0') |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2528 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2529 // 0 flag at the wrong place |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2530 semsg(_( e_invalid_format_specifier_str), fmt); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2531 goto error; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2532 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2533 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2534 // Positional argument |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2535 unsigned int uj = *p++ - '0'; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2536 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2537 while (VIM_ISDIGIT((int)(*p))) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2538 uj = 10 * uj + (unsigned int)(*p++ - '0'); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2539 pos_arg = uj; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2540 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2541 any_pos = 1; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2542 CHECK_POS_ARG; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2543 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2544 ++p; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2545 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2546 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2547 // parse flags |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2548 while (*p == '0' || *p == '-' || *p == '+' || *p == ' ' |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2549 || *p == '#' || *p == '\'') |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2550 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2551 switch (*p) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2552 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2553 case '0': break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2554 case '-': break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2555 case '+': break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2556 case ' ': // If both the ' ' and '+' flags appear, the ' ' |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2557 // flag should be ignored |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2558 break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2559 case '#': break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2560 case '\'': break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2561 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2562 p++; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2563 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2564 // If the '0' and '-' flags both appear, the '0' flag should be |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2565 // ignored. |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2566 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2567 // parse field width |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2568 if (*(arg = p) == '*') |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2569 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2570 p++; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2571 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2572 if (VIM_ISDIGIT((int)(*p))) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2573 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2574 // Positional argument field width |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2575 unsigned int uj = *p++ - '0'; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2576 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2577 while (VIM_ISDIGIT((int)(*p))) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2578 uj = 10 * uj + (unsigned int)(*p++ - '0'); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2579 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2580 if (*p != '$') |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2581 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2582 semsg(_( e_invalid_format_specifier_str), fmt); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2583 goto error; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2584 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2585 else |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2586 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2587 ++p; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2588 any_pos = 1; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2589 CHECK_POS_ARG; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2590 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2591 if (adjust_types(ap_types, uj, num_posarg, arg) == FAIL) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2592 goto error; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2593 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2594 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2595 else |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2596 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2597 any_arg = 1; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2598 CHECK_POS_ARG; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2599 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2600 } |
33494
8b7a2ea22a86
patch 9.0.1997: Some unused code in move.c and string.c
Christian Brabandt <cb@256bit.org>
parents:
33214
diff
changeset
|
2601 else if (VIM_ISDIGIT((int)(*p))) |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2602 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2603 // size_t could be wider than unsigned int; make sure we treat |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2604 // argument like common implementations do |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2605 unsigned int uj = *p++ - '0'; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2606 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2607 while (VIM_ISDIGIT((int)(*p))) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2608 uj = 10 * uj + (unsigned int)(*p++ - '0'); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2609 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2610 if (*p == '$') |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2611 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2612 semsg(_( e_invalid_format_specifier_str), fmt); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2613 goto error; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2614 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2615 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2616 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2617 // parse precision |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2618 if (*p == '.') |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2619 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2620 p++; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2621 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2622 if (*(arg = p) == '*') |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2623 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2624 p++; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2625 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2626 if (VIM_ISDIGIT((int)(*p))) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2627 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2628 // Parse precision |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2629 unsigned int uj = *p++ - '0'; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2630 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2631 while (VIM_ISDIGIT((int)(*p))) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2632 uj = 10 * uj + (unsigned int)(*p++ - '0'); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2633 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2634 if (*p == '$') |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2635 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2636 any_pos = 1; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2637 CHECK_POS_ARG; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2638 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2639 ++p; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2640 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2641 if (adjust_types(ap_types, uj, num_posarg, arg) == FAIL) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2642 goto error; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2643 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2644 else |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2645 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2646 semsg(_( e_invalid_format_specifier_str), fmt); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2647 goto error; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2648 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2649 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2650 else |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2651 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2652 any_arg = 1; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2653 CHECK_POS_ARG; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2654 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2655 } |
33494
8b7a2ea22a86
patch 9.0.1997: Some unused code in move.c and string.c
Christian Brabandt <cb@256bit.org>
parents:
33214
diff
changeset
|
2656 else if (VIM_ISDIGIT((int)(*p))) |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2657 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2658 // size_t could be wider than unsigned int; make sure we |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2659 // treat argument like common implementations do |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2660 unsigned int uj = *p++ - '0'; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2661 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2662 while (VIM_ISDIGIT((int)(*p))) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2663 uj = 10 * uj + (unsigned int)(*p++ - '0'); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2664 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2665 if (*p == '$') |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2666 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2667 semsg(_( e_invalid_format_specifier_str), fmt); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2668 goto error; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2669 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2670 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2671 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2672 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2673 if (pos_arg != -1) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2674 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2675 any_pos = 1; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2676 CHECK_POS_ARG; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2677 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2678 ptype = p; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2679 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2680 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2681 // parse 'h', 'l' and 'll' length modifiers |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2682 if (*p == 'h' || *p == 'l') |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2683 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2684 length_modifier = *p; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2685 p++; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2686 if (length_modifier == 'l' && *p == 'l') |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2687 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2688 // double l = __int64 / varnumber_T |
33494
8b7a2ea22a86
patch 9.0.1997: Some unused code in move.c and string.c
Christian Brabandt <cb@256bit.org>
parents:
33214
diff
changeset
|
2689 // length_modifier = 'L'; |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2690 p++; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2691 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2692 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2693 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2694 switch (*p) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2695 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2696 // Check for known format specifiers. % is special! |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2697 case 'i': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2698 case '*': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2699 case 'd': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2700 case 'u': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2701 case 'o': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2702 case 'D': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2703 case 'U': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2704 case 'O': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2705 case 'x': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2706 case 'X': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2707 case 'b': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2708 case 'B': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2709 case 'c': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2710 case 's': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2711 case 'S': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2712 case 'p': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2713 case 'f': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2714 case 'F': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2715 case 'e': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2716 case 'E': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2717 case 'g': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2718 case 'G': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2719 if (pos_arg != -1) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2720 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2721 if (adjust_types(ap_types, pos_arg, num_posarg, ptype) == FAIL) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2722 goto error; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2723 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2724 else |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2725 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2726 any_arg = 1; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2727 CHECK_POS_ARG; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2728 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2729 break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2730 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2731 default: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2732 if (pos_arg != -1) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2733 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2734 semsg(_( e_cannot_mix_positional_and_non_positional_str), fmt); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2735 goto error; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2736 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2737 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2738 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2739 if (*p != NUL) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2740 p++; // step over the just processed conversion specifier |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2741 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2742 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2743 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2744 for (arg_idx = 0; arg_idx < *num_posarg; ++arg_idx) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2745 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2746 if ((*ap_types)[arg_idx] == NULL) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2747 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2748 semsg(_(e_fmt_arg_nr_unused_str), arg_idx + 1, fmt); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2749 goto error; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2750 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2751 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2752 # if defined(FEAT_EVAL) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2753 if (tvs != NULL && tvs[arg_idx].v_type == VAR_UNKNOWN) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2754 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2755 semsg(_(e_positional_nr_out_of_bounds_str), arg_idx + 1, fmt); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2756 goto error; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2757 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2758 # endif |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2759 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2760 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2761 return OK; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2762 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2763 error: |
32991
0bdb1f8a17c1
patch 9.0.1788: C4090 warnings in strings.c
Christian Brabandt <cb@256bit.org>
parents:
32856
diff
changeset
|
2764 vim_free((char**)*ap_types); |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2765 *ap_types = NULL; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2766 *num_posarg = 0; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2767 return FAIL; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2768 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2769 |
32798
f48e27f20e6b
patch 9.0.1715: duplicate test in message_test.c
Christian Brabandt <cb@256bit.org>
parents:
32775
diff
changeset
|
2770 static void |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2771 skip_to_arg( |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2772 const char **ap_types, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2773 va_list ap_start, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2774 va_list *ap, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2775 int *arg_idx, |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
2776 int *arg_cur, |
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
2777 const char *fmt) |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2778 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2779 int arg_min = 0; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2780 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2781 if (*arg_cur + 1 == *arg_idx) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2782 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2783 ++*arg_cur; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2784 ++*arg_idx; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2785 return; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2786 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2787 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2788 if (*arg_cur >= *arg_idx) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2789 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2790 // Reset ap to ap_start and skip arg_idx - 1 types |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2791 va_end(*ap); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2792 va_copy(*ap, ap_start); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2793 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2794 else |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2795 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2796 // Skip over any we should skip |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2797 arg_min = *arg_cur; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2798 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2799 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2800 for (*arg_cur = arg_min; *arg_cur < *arg_idx - 1; ++*arg_cur) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2801 { |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
2802 const char *p; |
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
2803 |
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
2804 if (ap_types == NULL || ap_types[*arg_cur] == NULL) |
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
2805 { |
33214
39bc126cc890
patch 9.0.1884: Wrong order of arguments for error messages
Christian Brabandt <cb@256bit.org>
parents:
33162
diff
changeset
|
2806 siemsg(e_aptypes_is_null_nr_str, *arg_cur, fmt); |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
2807 return; |
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
2808 } |
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
2809 |
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
2810 p = ap_types[*arg_cur]; |
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
2811 |
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
2812 int fmt_type = format_typeof(p); |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2813 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2814 // get parameter value, do initial processing |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2815 switch (fmt_type) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2816 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2817 case TYPE_PERCENT: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2818 case TYPE_UNKNOWN: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2819 break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2820 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2821 case TYPE_CHAR: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2822 va_arg(*ap, int); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2823 break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2824 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2825 case TYPE_STRING: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2826 va_arg(*ap, char *); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2827 break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2828 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2829 case TYPE_POINTER: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2830 va_arg(*ap, void *); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2831 break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2832 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2833 case TYPE_INT: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2834 va_arg(*ap, int); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2835 break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2836 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2837 case TYPE_LONGINT: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2838 va_arg(*ap, long int); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2839 break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2840 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2841 case TYPE_LONGLONGINT: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2842 va_arg(*ap, varnumber_T); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2843 break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2844 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2845 case TYPE_UNSIGNEDINT: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2846 va_arg(*ap, unsigned int); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2847 break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2848 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2849 case TYPE_UNSIGNEDLONGINT: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2850 va_arg(*ap, unsigned long int); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2851 break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2852 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2853 case TYPE_UNSIGNEDLONGLONGINT: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2854 va_arg(*ap, uvarnumber_T); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2855 break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2856 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2857 case TYPE_FLOAT: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2858 va_arg(*ap, double); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2859 break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2860 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2861 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2862 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2863 // Because we know that after we return from this call, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2864 // a va_arg() call is made, we can pre-emptively |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2865 // increment the current argument index. |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2866 ++*arg_cur; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2867 ++*arg_idx; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2868 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2869 return; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2870 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2871 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2872 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2873 vim_vsnprintf_typval( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2874 char *str, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2875 size_t str_m, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2876 const char *fmt, |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2877 va_list ap_start, |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2878 typval_T *tvs) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2879 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2880 size_t str_l = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2881 const char *p = fmt; |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2882 int arg_cur = 0; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2883 int num_posarg = 0; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2884 int arg_idx = 1; |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2885 va_list ap; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2886 const char **ap_types = NULL; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2887 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2888 if (parse_fmt_types(&ap_types, &num_posarg, fmt, tvs) == FAIL) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2889 return 0; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2890 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2891 va_copy(ap, ap_start); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2892 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2893 if (p == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2894 p = ""; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2895 while (*p != NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2896 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2897 if (*p != '%') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2898 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2899 char *q = strchr(p + 1, '%'); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2900 size_t n = (q == NULL) ? STRLEN(p) : (size_t)(q - p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2901 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2902 // Copy up to the next '%' or NUL without any changes. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2903 if (str_l < str_m) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2904 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2905 size_t avail = str_m - str_l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2906 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2907 mch_memmove(str + str_l, p, n > avail ? avail : n); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2908 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2909 p += n; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2910 str_l += n; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2911 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2912 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2913 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2914 size_t min_field_width = 0, precision = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2915 int zero_padding = 0, precision_specified = 0, justify_left = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2916 int alternate_form = 0, force_sign = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2917 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2918 // If both the ' ' and '+' flags appear, the ' ' flag should be |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2919 // ignored. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2920 int space_for_positive = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2921 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2922 // allowed values: \0, h, l, L |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2923 char length_modifier = '\0'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2924 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2925 // temporary buffer for simple numeric->string conversion |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2926 # define TMP_LEN 350 // On my system 1e308 is the biggest number possible. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2927 // That sounds reasonable to use as the maximum |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2928 // printable. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2929 char tmp[TMP_LEN]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2930 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2931 // string address in case of string argument |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2932 const char *str_arg = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2933 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2934 // natural field width of arg without padding and sign |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2935 size_t str_arg_l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2936 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2937 // unsigned char argument value - only defined for c conversion. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2938 // N.B. standard explicitly states the char argument for the c |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2939 // conversion is unsigned |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2940 unsigned char uchar_arg; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2941 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2942 // number of zeros to be inserted for numeric conversions as |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2943 // required by the precision or minimal field width |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2944 size_t number_of_zeros_to_pad = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2945 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2946 // index into tmp where zero padding is to be inserted |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2947 size_t zero_padding_insertion_ind = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2948 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2949 // current conversion specifier character |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2950 char fmt_spec = '\0'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2951 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2952 // buffer for 's' and 'S' specs |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2953 char_u *tofree = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2954 |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2955 // variables for positional arg |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2956 int pos_arg = -1; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2957 const char *ptype; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2958 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2959 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2960 p++; // skip '%' |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2961 |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2962 // First check to see if we find a positional |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2963 // argument specifier |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2964 ptype = p; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2965 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2966 while (VIM_ISDIGIT(*ptype)) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2967 ++ptype; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2968 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2969 if (*ptype == '$') |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2970 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2971 // Positional argument |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2972 unsigned int uj = *p++ - '0'; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2973 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2974 while (VIM_ISDIGIT((int)(*p))) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2975 uj = 10 * uj + (unsigned int)(*p++ - '0'); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2976 pos_arg = uj; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2977 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2978 ++p; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2979 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2980 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2981 // parse flags |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2982 while (*p == '0' || *p == '-' || *p == '+' || *p == ' ' |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2983 || *p == '#' || *p == '\'') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2984 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2985 switch (*p) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2986 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2987 case '0': zero_padding = 1; break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2988 case '-': justify_left = 1; break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2989 case '+': force_sign = 1; space_for_positive = 0; break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2990 case ' ': force_sign = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2991 // If both the ' ' and '+' flags appear, the ' ' |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2992 // flag should be ignored |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2993 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2994 case '#': alternate_form = 1; break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2995 case '\'': break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2996 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2997 p++; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2998 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2999 // If the '0' and '-' flags both appear, the '0' flag should be |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3000 // ignored. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3001 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3002 // parse field width |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3003 if (*p == '*') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3004 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3005 int j; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3006 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3007 p++; |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3008 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3009 if (VIM_ISDIGIT((int)(*p))) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3010 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3011 // Positional argument field width |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3012 unsigned int uj = *p++ - '0'; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3013 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3014 while (VIM_ISDIGIT((int)(*p))) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3015 uj = 10 * uj + (unsigned int)(*p++ - '0'); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3016 arg_idx = uj; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3017 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3018 ++p; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3019 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3020 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3021 j = |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3022 # if defined(FEAT_EVAL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3023 tvs != NULL ? tv_nr(tvs, &arg_idx) : |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3024 # endif |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3025 (skip_to_arg(ap_types, ap_start, &ap, &arg_idx, |
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3026 &arg_cur, fmt), |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3027 va_arg(ap, int)); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3028 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3029 if (j >= 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3030 min_field_width = j; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3031 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3032 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3033 min_field_width = -j; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3034 justify_left = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3035 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3036 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3037 else if (VIM_ISDIGIT((int)(*p))) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3038 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3039 // size_t could be wider than unsigned int; make sure we treat |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3040 // argument like common implementations do |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3041 unsigned int uj = *p++ - '0'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3042 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3043 while (VIM_ISDIGIT((int)(*p))) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3044 uj = 10 * uj + (unsigned int)(*p++ - '0'); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3045 min_field_width = uj; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3046 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3047 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3048 // parse precision |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3049 if (*p == '.') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3050 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3051 p++; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3052 precision_specified = 1; |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3053 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3054 if (VIM_ISDIGIT((int)(*p))) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3055 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3056 // size_t could be wider than unsigned int; make sure we |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3057 // treat argument like common implementations do |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3058 unsigned int uj = *p++ - '0'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3059 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3060 while (VIM_ISDIGIT((int)(*p))) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3061 uj = 10 * uj + (unsigned int)(*p++ - '0'); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3062 precision = uj; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3063 } |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3064 else if (*p == '*') |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3065 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3066 int j; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3067 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3068 p++; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3069 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3070 if (VIM_ISDIGIT((int)(*p))) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3071 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3072 // positional argument |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3073 unsigned int uj = *p++ - '0'; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3074 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3075 while (VIM_ISDIGIT((int)(*p))) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3076 uj = 10 * uj + (unsigned int)(*p++ - '0'); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3077 arg_idx = uj; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3078 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3079 ++p; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3080 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3081 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3082 j = |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3083 # if defined(FEAT_EVAL) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3084 tvs != NULL ? tv_nr(tvs, &arg_idx) : |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3085 # endif |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3086 (skip_to_arg(ap_types, ap_start, &ap, &arg_idx, |
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3087 &arg_cur, fmt), |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3088 va_arg(ap, int)); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3089 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3090 if (j >= 0) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3091 precision = j; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3092 else |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3093 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3094 precision_specified = 0; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3095 precision = 0; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3096 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3097 } |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3098 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3099 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3100 // parse 'h', 'l' and 'll' length modifiers |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3101 if (*p == 'h' || *p == 'l') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3102 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3103 length_modifier = *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3104 p++; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3105 if (length_modifier == 'l' && *p == 'l') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3106 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3107 // double l = __int64 / varnumber_T |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3108 length_modifier = 'L'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3109 p++; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3110 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3111 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3112 fmt_spec = *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3113 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3114 // common synonyms: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3115 switch (fmt_spec) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3116 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3117 case 'i': fmt_spec = 'd'; break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3118 case 'D': fmt_spec = 'd'; length_modifier = 'l'; break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3119 case 'U': fmt_spec = 'u'; length_modifier = 'l'; break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3120 case 'O': fmt_spec = 'o'; length_modifier = 'l'; break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3121 default: break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3122 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3123 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3124 # if defined(FEAT_EVAL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3125 switch (fmt_spec) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3126 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3127 case 'd': case 'u': case 'o': case 'x': case 'X': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3128 if (tvs != NULL && length_modifier == '\0') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3129 length_modifier = 'L'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3130 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3131 # endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3132 |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3133 if (pos_arg != -1) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3134 arg_idx = pos_arg; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3135 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3136 // get parameter value, do initial processing |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3137 switch (fmt_spec) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3138 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3139 // '%' and 'c' behave similar to 's' regarding flags and field |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3140 // widths |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3141 case '%': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3142 case 'c': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3143 case 's': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3144 case 'S': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3145 str_arg_l = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3146 switch (fmt_spec) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3147 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3148 case '%': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3149 str_arg = p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3150 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3151 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3152 case 'c': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3153 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3154 int j; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3155 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3156 j = |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3157 # if defined(FEAT_EVAL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3158 tvs != NULL ? tv_nr(tvs, &arg_idx) : |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3159 # endif |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3160 (skip_to_arg(ap_types, ap_start, &ap, &arg_idx, |
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3161 &arg_cur, fmt), |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3162 va_arg(ap, int)); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3163 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3164 // standard demands unsigned char |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3165 uchar_arg = (unsigned char)j; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3166 str_arg = (char *)&uchar_arg; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3167 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3168 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3169 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3170 case 's': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3171 case 'S': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3172 str_arg = |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3173 # if defined(FEAT_EVAL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3174 tvs != NULL ? tv_str(tvs, &arg_idx, &tofree) : |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3175 # endif |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3176 (skip_to_arg(ap_types, ap_start, &ap, &arg_idx, |
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3177 &arg_cur, fmt), |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3178 va_arg(ap, char *)); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3179 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3180 if (str_arg == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3181 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3182 str_arg = "[NULL]"; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3183 str_arg_l = 6; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3184 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3185 // make sure not to address string beyond the specified |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3186 // precision !!! |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3187 else if (!precision_specified) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3188 str_arg_l = strlen(str_arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3189 // truncate string if necessary as requested by precision |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3190 else if (precision == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3191 str_arg_l = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3192 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3193 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3194 // Don't put the #if inside memchr(), it can be a |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3195 // macro. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3196 // memchr on HP does not like n > 2^31 !!! |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3197 char *q = memchr(str_arg, '\0', |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3198 precision <= (size_t)0x7fffffffL ? precision |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3199 : (size_t)0x7fffffffL); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3200 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3201 str_arg_l = (q == NULL) ? precision |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3202 : (size_t)(q - str_arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3203 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3204 if (fmt_spec == 'S') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3205 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3206 char_u *p1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3207 size_t i; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3208 int cell; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3209 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3210 for (i = 0, p1 = (char_u *)str_arg; *p1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3211 p1 += mb_ptr2len(p1)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3212 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3213 cell = mb_ptr2cells(p1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3214 if (precision_specified && i + cell > precision) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3215 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3216 i += cell; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3217 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3218 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3219 str_arg_l = p1 - (char_u *)str_arg; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3220 if (min_field_width != 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3221 min_field_width += str_arg_l - i; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3222 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3223 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3224 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3225 default: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3226 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3227 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3228 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3229 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3230 case 'd': case 'u': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3231 case 'b': case 'B': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3232 case 'o': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3233 case 'x': case 'X': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3234 case 'p': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3235 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3236 // NOTE: the u, b, o, x, X and p conversion specifiers |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3237 // imply the value is unsigned; d implies a signed |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3238 // value |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3239 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3240 // 0 if numeric argument is zero (or if pointer is |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3241 // NULL for 'p'), +1 if greater than zero (or nonzero |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3242 // for unsigned arguments), -1 if negative (unsigned |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3243 // argument is never negative) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3244 int arg_sign = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3245 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3246 // only set for length modifier h, or for no length |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3247 // modifiers |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3248 int int_arg = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3249 unsigned int uint_arg = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3250 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3251 // only set for length modifier l |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3252 long int long_arg = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3253 unsigned long int ulong_arg = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3254 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3255 // only set for length modifier ll |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3256 varnumber_T llong_arg = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3257 uvarnumber_T ullong_arg = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3258 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3259 // only set for b conversion |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3260 uvarnumber_T bin_arg = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3261 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3262 // pointer argument value -only defined for p |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3263 // conversion |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3264 void *ptr_arg = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3265 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3266 if (fmt_spec == 'p') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3267 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3268 length_modifier = '\0'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3269 ptr_arg = |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3270 # if defined(FEAT_EVAL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3271 tvs != NULL ? (void *)tv_str(tvs, &arg_idx, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3272 NULL) : |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3273 # endif |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3274 (skip_to_arg(ap_types, ap_start, &ap, &arg_idx, |
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3275 &arg_cur, fmt), |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3276 va_arg(ap, void *)); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3277 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3278 if (ptr_arg != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3279 arg_sign = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3280 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3281 else if (fmt_spec == 'b' || fmt_spec == 'B') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3282 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3283 bin_arg = |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3284 # if defined(FEAT_EVAL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3285 tvs != NULL ? |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3286 (uvarnumber_T)tv_nr(tvs, &arg_idx) : |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3287 # endif |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3288 (skip_to_arg(ap_types, ap_start, &ap, &arg_idx, |
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3289 &arg_cur, fmt), |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3290 va_arg(ap, uvarnumber_T)); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3291 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3292 if (bin_arg != 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3293 arg_sign = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3294 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3295 else if (fmt_spec == 'd') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3296 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3297 // signed |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3298 switch (length_modifier) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3299 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3300 case '\0': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3301 case 'h': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3302 // char and short arguments are passed as int. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3303 int_arg = |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3304 # if defined(FEAT_EVAL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3305 tvs != NULL ? tv_nr(tvs, &arg_idx) : |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3306 # endif |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3307 (skip_to_arg(ap_types, ap_start, &ap, &arg_idx, |
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3308 &arg_cur, fmt), |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3309 va_arg(ap, int)); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3310 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3311 if (int_arg > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3312 arg_sign = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3313 else if (int_arg < 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3314 arg_sign = -1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3315 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3316 case 'l': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3317 long_arg = |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3318 # if defined(FEAT_EVAL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3319 tvs != NULL ? tv_nr(tvs, &arg_idx) : |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3320 # endif |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3321 (skip_to_arg(ap_types, ap_start, &ap, &arg_idx, |
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3322 &arg_cur, fmt), |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3323 va_arg(ap, long int)); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3324 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3325 if (long_arg > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3326 arg_sign = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3327 else if (long_arg < 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3328 arg_sign = -1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3329 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3330 case 'L': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3331 llong_arg = |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3332 # if defined(FEAT_EVAL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3333 tvs != NULL ? tv_nr(tvs, &arg_idx) : |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3334 # endif |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3335 (skip_to_arg(ap_types, ap_start, &ap, &arg_idx, |
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3336 &arg_cur, fmt), |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3337 va_arg(ap, varnumber_T)); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3338 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3339 if (llong_arg > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3340 arg_sign = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3341 else if (llong_arg < 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3342 arg_sign = -1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3343 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3344 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3345 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3346 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3347 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3348 // unsigned |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3349 switch (length_modifier) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3350 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3351 case '\0': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3352 case 'h': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3353 uint_arg = |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3354 # if defined(FEAT_EVAL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3355 tvs != NULL ? (unsigned) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3356 tv_nr(tvs, &arg_idx) : |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3357 # endif |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3358 (skip_to_arg(ap_types, ap_start, &ap, &arg_idx, |
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3359 &arg_cur, fmt), |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3360 va_arg(ap, unsigned int)); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3361 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3362 if (uint_arg != 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3363 arg_sign = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3364 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3365 case 'l': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3366 ulong_arg = |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3367 # if defined(FEAT_EVAL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3368 tvs != NULL ? (unsigned long) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3369 tv_nr(tvs, &arg_idx) : |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3370 # endif |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3371 (skip_to_arg(ap_types, ap_start, &ap, &arg_idx, |
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3372 &arg_cur, fmt), |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3373 va_arg(ap, unsigned long int)); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3374 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3375 if (ulong_arg != 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3376 arg_sign = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3377 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3378 case 'L': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3379 ullong_arg = |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3380 # if defined(FEAT_EVAL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3381 tvs != NULL ? (uvarnumber_T) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3382 tv_nr(tvs, &arg_idx) : |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3383 # endif |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3384 (skip_to_arg(ap_types, ap_start, &ap, &arg_idx, |
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3385 &arg_cur, fmt), |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3386 va_arg(ap, uvarnumber_T)); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3387 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3388 if (ullong_arg != 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3389 arg_sign = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3390 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3391 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3392 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3393 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3394 str_arg = tmp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3395 str_arg_l = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3396 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3397 // NOTE: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3398 // For d, i, u, o, x, and X conversions, if precision is |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3399 // specified, the '0' flag should be ignored. This is so |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3400 // with Solaris 2.6, Digital UNIX 4.0, HPUX 10, Linux, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3401 // FreeBSD, NetBSD; but not with Perl. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3402 if (precision_specified) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3403 zero_padding = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3404 if (fmt_spec == 'd') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3405 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3406 if (force_sign && arg_sign >= 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3407 tmp[str_arg_l++] = space_for_positive ? ' ' : '+'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3408 // leave negative numbers for sprintf to handle, to |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3409 // avoid handling tricky cases like (short int)-32768 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3410 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3411 else if (alternate_form) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3412 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3413 if (arg_sign != 0 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3414 && (fmt_spec == 'b' || fmt_spec == 'B' |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3415 || fmt_spec == 'x' || fmt_spec == 'X') ) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3416 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3417 tmp[str_arg_l++] = '0'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3418 tmp[str_arg_l++] = fmt_spec; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3419 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3420 // alternate form should have no effect for p |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3421 // conversion, but ... |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3422 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3423 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3424 zero_padding_insertion_ind = str_arg_l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3425 if (!precision_specified) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3426 precision = 1; // default precision is 1 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3427 if (precision == 0 && arg_sign == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3428 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3429 // When zero value is formatted with an explicit |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3430 // precision 0, the resulting formatted string is |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3431 // empty (d, i, u, b, B, o, x, X, p). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3432 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3433 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3434 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3435 char f[6]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3436 int f_l = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3437 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3438 // construct a simple format string for sprintf |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3439 f[f_l++] = '%'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3440 if (!length_modifier) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3441 ; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3442 else if (length_modifier == 'L') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3443 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3444 # ifdef MSWIN |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3445 f[f_l++] = 'I'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3446 f[f_l++] = '6'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3447 f[f_l++] = '4'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3448 # else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3449 f[f_l++] = 'l'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3450 f[f_l++] = 'l'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3451 # endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3452 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3453 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3454 f[f_l++] = length_modifier; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3455 f[f_l++] = fmt_spec; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3456 f[f_l++] = '\0'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3457 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3458 if (fmt_spec == 'p') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3459 str_arg_l += sprintf(tmp + str_arg_l, f, ptr_arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3460 else if (fmt_spec == 'b' || fmt_spec == 'B') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3461 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3462 char b[8 * sizeof(uvarnumber_T)]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3463 size_t b_l = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3464 uvarnumber_T bn = bin_arg; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3465 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3466 do |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3467 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3468 b[sizeof(b) - ++b_l] = '0' + (bn & 0x1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3469 bn >>= 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3470 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3471 while (bn != 0); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3472 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3473 memcpy(tmp + str_arg_l, b + sizeof(b) - b_l, b_l); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3474 str_arg_l += b_l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3475 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3476 else if (fmt_spec == 'd') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3477 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3478 // signed |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3479 switch (length_modifier) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3480 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3481 case '\0': str_arg_l += sprintf( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3482 tmp + str_arg_l, f, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3483 int_arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3484 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3485 case 'h': str_arg_l += sprintf( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3486 tmp + str_arg_l, f, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3487 (short)int_arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3488 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3489 case 'l': str_arg_l += sprintf( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3490 tmp + str_arg_l, f, long_arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3491 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3492 case 'L': str_arg_l += sprintf( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3493 tmp + str_arg_l, f, llong_arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3494 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3495 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3496 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3497 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3498 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3499 // unsigned |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3500 switch (length_modifier) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3501 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3502 case '\0': str_arg_l += sprintf( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3503 tmp + str_arg_l, f, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3504 uint_arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3505 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3506 case 'h': str_arg_l += sprintf( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3507 tmp + str_arg_l, f, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3508 (unsigned short)uint_arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3509 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3510 case 'l': str_arg_l += sprintf( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3511 tmp + str_arg_l, f, ulong_arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3512 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3513 case 'L': str_arg_l += sprintf( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3514 tmp + str_arg_l, f, ullong_arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3515 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3516 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3517 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3518 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3519 // include the optional minus sign and possible |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3520 // "0x" in the region before the zero padding |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3521 // insertion point |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3522 if (zero_padding_insertion_ind < str_arg_l |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3523 && tmp[zero_padding_insertion_ind] == '-') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3524 zero_padding_insertion_ind++; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3525 if (zero_padding_insertion_ind + 1 < str_arg_l |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3526 && tmp[zero_padding_insertion_ind] == '0' |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3527 && (tmp[zero_padding_insertion_ind + 1] == 'x' |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3528 || tmp[zero_padding_insertion_ind + 1] == 'X')) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3529 zero_padding_insertion_ind += 2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3530 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3531 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3532 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3533 size_t num_of_digits = str_arg_l |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3534 - zero_padding_insertion_ind; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3535 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3536 if (alternate_form && fmt_spec == 'o' |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3537 // unless zero is already the first |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3538 // character |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3539 && !(zero_padding_insertion_ind < str_arg_l |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3540 && tmp[zero_padding_insertion_ind] == '0')) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3541 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3542 // assure leading zero for alternate-form |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3543 // octal numbers |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3544 if (!precision_specified |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3545 || precision < num_of_digits + 1) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3546 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3547 // precision is increased to force the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3548 // first character to be zero, except if a |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3549 // zero value is formatted with an |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3550 // explicit precision of zero |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3551 precision = num_of_digits + 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3552 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3553 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3554 // zero padding to specified precision? |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3555 if (num_of_digits < precision) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3556 number_of_zeros_to_pad = precision - num_of_digits; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3557 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3558 // zero padding to specified minimal field width? |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3559 if (!justify_left && zero_padding) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3560 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3561 int n = (int)(min_field_width - (str_arg_l |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3562 + number_of_zeros_to_pad)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3563 if (n > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3564 number_of_zeros_to_pad += n; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3565 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3566 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3567 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3568 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3569 case 'f': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3570 case 'F': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3571 case 'e': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3572 case 'E': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3573 case 'g': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3574 case 'G': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3575 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3576 // Floating point. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3577 double f; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3578 double abs_f; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3579 char format[40]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3580 int l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3581 int remove_trailing_zeroes = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3582 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3583 f = |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3584 # if defined(FEAT_EVAL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3585 tvs != NULL ? tv_float(tvs, &arg_idx) : |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3586 # endif |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3587 (skip_to_arg(ap_types, ap_start, &ap, &arg_idx, |
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3588 &arg_cur, fmt), |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3589 va_arg(ap, double)); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3590 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3591 abs_f = f < 0 ? -f : f; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3592 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3593 if (fmt_spec == 'g' || fmt_spec == 'G') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3594 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3595 // Would be nice to use %g directly, but it prints |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3596 // "1.0" as "1", we don't want that. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3597 if ((abs_f >= 0.001 && abs_f < 10000000.0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3598 || abs_f == 0.0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3599 fmt_spec = ASCII_ISUPPER(fmt_spec) ? 'F' : 'f'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3600 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3601 fmt_spec = fmt_spec == 'g' ? 'e' : 'E'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3602 remove_trailing_zeroes = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3603 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3604 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3605 if ((fmt_spec == 'f' || fmt_spec == 'F') && |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3606 # ifdef VAX |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3607 abs_f > 1.0e38 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3608 # else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3609 abs_f > 1.0e307 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3610 # endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3611 ) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3612 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3613 // Avoid a buffer overflow |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3614 STRCPY(tmp, infinity_str(f > 0.0, fmt_spec, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3615 force_sign, space_for_positive)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3616 str_arg_l = STRLEN(tmp); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3617 zero_padding = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3618 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3619 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3620 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3621 if (isnan(f)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3622 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3623 // Not a number: nan or NAN |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3624 STRCPY(tmp, ASCII_ISUPPER(fmt_spec) ? "NAN" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3625 : "nan"); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3626 str_arg_l = 3; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3627 zero_padding = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3628 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3629 else if (isinf(f)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3630 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3631 STRCPY(tmp, infinity_str(f > 0.0, fmt_spec, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3632 force_sign, space_for_positive)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3633 str_arg_l = STRLEN(tmp); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3634 zero_padding = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3635 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3636 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3637 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3638 // Regular float number |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3639 format[0] = '%'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3640 l = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3641 if (force_sign) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3642 format[l++] = space_for_positive ? ' ' : '+'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3643 if (precision_specified) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3644 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3645 size_t max_prec = TMP_LEN - 10; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3646 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3647 // Make sure we don't get more digits than we |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3648 // have room for. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3649 if ((fmt_spec == 'f' || fmt_spec == 'F') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3650 && abs_f > 1.0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3651 max_prec -= (size_t)log10(abs_f); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3652 if (precision > max_prec) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3653 precision = max_prec; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3654 l += sprintf(format + l, ".%d", (int)precision); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3655 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3656 format[l] = fmt_spec == 'F' ? 'f' : fmt_spec; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3657 format[l + 1] = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3658 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3659 str_arg_l = sprintf(tmp, format, f); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3660 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3661 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3662 if (remove_trailing_zeroes) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3663 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3664 int i; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3665 char *tp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3666 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3667 // Using %g or %G: remove superfluous zeroes. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3668 if (fmt_spec == 'f' || fmt_spec == 'F') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3669 tp = tmp + str_arg_l - 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3670 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3671 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3672 tp = (char *)vim_strchr((char_u *)tmp, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3673 fmt_spec == 'e' ? 'e' : 'E'); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3674 if (tp != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3675 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3676 // Remove superfluous '+' and leading |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3677 // zeroes from the exponent. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3678 if (tp[1] == '+') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3679 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3680 // Change "1.0e+07" to "1.0e07" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3681 STRMOVE(tp + 1, tp + 2); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3682 --str_arg_l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3683 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3684 i = (tp[1] == '-') ? 2 : 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3685 while (tp[i] == '0') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3686 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3687 // Change "1.0e07" to "1.0e7" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3688 STRMOVE(tp + i, tp + i + 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3689 --str_arg_l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3690 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3691 --tp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3692 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3693 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3694 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3695 if (tp != NULL && !precision_specified) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3696 // Remove trailing zeroes, but keep the one |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3697 // just after a dot. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3698 while (tp > tmp + 2 && *tp == '0' |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3699 && tp[-1] != '.') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3700 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3701 STRMOVE(tp, tp + 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3702 --tp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3703 --str_arg_l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3704 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3705 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3706 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3707 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3708 char *tp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3709 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3710 // Be consistent: some printf("%e") use 1.0e+12 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3711 // and some 1.0e+012. Remove one zero in the last |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3712 // case. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3713 tp = (char *)vim_strchr((char_u *)tmp, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3714 fmt_spec == 'e' ? 'e' : 'E'); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3715 if (tp != NULL && (tp[1] == '+' || tp[1] == '-') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3716 && tp[2] == '0' |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3717 && vim_isdigit(tp[3]) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3718 && vim_isdigit(tp[4])) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3719 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3720 STRMOVE(tp + 2, tp + 3); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3721 --str_arg_l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3722 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3723 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3724 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3725 if (zero_padding && min_field_width > str_arg_l |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3726 && (tmp[0] == '-' || force_sign)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3727 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3728 // padding 0's should be inserted after the sign |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3729 number_of_zeros_to_pad = min_field_width - str_arg_l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3730 zero_padding_insertion_ind = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3731 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3732 str_arg = tmp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3733 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3734 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3735 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3736 default: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3737 // unrecognized conversion specifier, keep format string |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3738 // as-is |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3739 zero_padding = 0; // turn zero padding off for non-numeric |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3740 // conversion |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3741 justify_left = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3742 min_field_width = 0; // reset flags |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3743 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3744 // discard the unrecognized conversion, just keep * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3745 // the unrecognized conversion character |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3746 str_arg = p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3747 str_arg_l = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3748 if (*p != NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3749 str_arg_l++; // include invalid conversion specifier |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3750 // unchanged if not at end-of-string |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3751 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3752 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3753 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3754 if (*p != NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3755 p++; // step over the just processed conversion specifier |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3756 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3757 // insert padding to the left as requested by min_field_width; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3758 // this does not include the zero padding in case of numerical |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3759 // conversions |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3760 if (!justify_left) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3761 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3762 // left padding with blank or zero |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3763 int pn = (int)(min_field_width - (str_arg_l + number_of_zeros_to_pad)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3764 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3765 if (pn > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3766 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3767 if (str_l < str_m) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3768 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3769 size_t avail = str_m - str_l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3770 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3771 vim_memset(str + str_l, zero_padding ? '0' : ' ', |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3772 (size_t)pn > avail ? avail |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3773 : (size_t)pn); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3774 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3775 str_l += pn; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3776 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3777 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3778 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3779 // zero padding as requested by the precision or by the minimal |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3780 // field width for numeric conversions required? |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3781 if (number_of_zeros_to_pad == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3782 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3783 // will not copy first part of numeric right now, * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3784 // force it to be copied later in its entirety |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3785 zero_padding_insertion_ind = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3786 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3787 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3788 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3789 // insert first part of numerics (sign or '0x') before zero |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3790 // padding |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3791 int zn = (int)zero_padding_insertion_ind; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3792 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3793 if (zn > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3794 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3795 if (str_l < str_m) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3796 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3797 size_t avail = str_m - str_l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3798 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3799 mch_memmove(str + str_l, str_arg, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3800 (size_t)zn > avail ? avail |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3801 : (size_t)zn); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3802 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3803 str_l += zn; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3804 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3805 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3806 // insert zero padding as requested by the precision or min |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3807 // field width |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3808 zn = (int)number_of_zeros_to_pad; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3809 if (zn > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3810 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3811 if (str_l < str_m) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3812 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3813 size_t avail = str_m - str_l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3814 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3815 vim_memset(str + str_l, '0', |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3816 (size_t)zn > avail ? avail |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3817 : (size_t)zn); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3818 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3819 str_l += zn; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3820 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3821 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3822 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3823 // insert formatted string |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3824 // (or as-is conversion specifier for unknown conversions) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3825 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3826 int sn = (int)(str_arg_l - zero_padding_insertion_ind); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3827 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3828 if (sn > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3829 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3830 if (str_l < str_m) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3831 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3832 size_t avail = str_m - str_l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3833 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3834 mch_memmove(str + str_l, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3835 str_arg + zero_padding_insertion_ind, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3836 (size_t)sn > avail ? avail : (size_t)sn); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3837 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3838 str_l += sn; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3839 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3840 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3841 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3842 // insert right padding |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3843 if (justify_left) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3844 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3845 // right blank padding to the field width |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3846 int pn = (int)(min_field_width |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3847 - (str_arg_l + number_of_zeros_to_pad)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3848 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3849 if (pn > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3850 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3851 if (str_l < str_m) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3852 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3853 size_t avail = str_m - str_l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3854 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3855 vim_memset(str + str_l, ' ', |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3856 (size_t)pn > avail ? avail |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3857 : (size_t)pn); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3858 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3859 str_l += pn; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3860 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3861 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3862 vim_free(tofree); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3863 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3864 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3865 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3866 if (str_m > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3867 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3868 // make sure the string is nul-terminated even at the expense of |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3869 // overwriting the last character (shouldn't happen, but just in case) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3870 // |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3871 str[str_l <= str_m - 1 ? str_l : str_m - 1] = '\0'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3872 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3873 |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3874 if (tvs != NULL && tvs[num_posarg != 0 ? num_posarg : arg_idx - 1].v_type != VAR_UNKNOWN) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3875 emsg(_(e_too_many_arguments_to_printf)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3876 |
32991
0bdb1f8a17c1
patch 9.0.1788: C4090 warnings in strings.c
Christian Brabandt <cb@256bit.org>
parents:
32856
diff
changeset
|
3877 vim_free((char*)ap_types); |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3878 va_end(ap); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3879 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3880 // Return the number of characters formatted (excluding trailing nul |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3881 // character), that is, the number of characters that would have been |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3882 // written to the buffer if it were large enough. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3883 return (int)str_l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3884 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3885 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3886 #endif // PROTO |