Mercurial > vim
annotate src/strings.c @ 33517:921673b465a6 v9.0.2007
patch 9.0.2007: Vim9: covariant parameter types allowed
Commit: https://github.com/vim/vim/commit/e4671890220ef3f2bca43fde6ffe5d3ef3ed0e42
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Mon Oct 9 18:01:06 2023 +0200
patch 9.0.2007: Vim9: covariant parameter types allowed
Problem: Vim9: covariant parameter types allowed when assigning
functions
Solution: Enforce invariant type check for arguments and return value
when assigning a funcref
closes: #13299
closes: #13305
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Mon, 09 Oct 2023 18:15:03 +0200 |
parents | 8b7a2ea22a86 |
children | 288da62613ba |
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 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1965 || check_for_opt_string_arg(argvars, 1) == FAIL |
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 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1974 if (check_for_opt_string_arg(argvars, 1) == FAIL) |
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) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1978 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1979 mask = tv_get_string_buf_chk(&argvars[1], buf2); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1980 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1981 if (argvars[2].v_type != VAR_UNKNOWN) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1982 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1983 int error = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1984 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1985 // leading or trailing characters to trim |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1986 dir = (int)tv_get_number_chk(&argvars[2], &error); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1987 if (error) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1988 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1989 if (dir < 0 || dir > 2) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1990 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1991 semsg(_(e_invalid_argument_str), tv_get_string(&argvars[2])); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1992 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1993 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1994 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1995 } |
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 if (dir == 0 || dir == 1) |
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 // Trim leading characters |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2000 while (*head != NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2001 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2002 c1 = PTR2CHAR(head); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2003 if (mask == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2004 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2005 if (c1 > ' ' && c1 != 0xa0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2006 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2007 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2008 else |
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 for (p = mask; *p != NUL; MB_PTR_ADV(p)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2011 if (c1 == PTR2CHAR(p)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2012 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2013 if (*p == NUL) |
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 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2016 MB_PTR_ADV(head); |
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 } |
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 tail = head + STRLEN(head); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2021 if (dir == 0 || dir == 2) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2022 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2023 // Trim trailing characters |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2024 for (; tail > head; tail = prev) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2025 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2026 prev = tail; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2027 MB_PTR_BACK(head, prev); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2028 c1 = PTR2CHAR(prev); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2029 if (mask == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2030 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2031 if (c1 > ' ' && c1 != 0xa0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2032 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2033 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2034 else |
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 for (p = mask; *p != NUL; MB_PTR_ADV(p)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2037 if (c1 == PTR2CHAR(p)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2038 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2039 if (*p == NUL) |
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 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2042 } |
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 rettv->vval.v_string = vim_strnsave(head, tail - head); |
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 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2047 static char *e_printf = N_(e_insufficient_arguments_for_printf); |
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 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2050 * 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
|
2051 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2052 static varnumber_T |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2053 tv_nr(typval_T *tvs, int *idxp) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2054 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2055 int idx = *idxp - 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2056 varnumber_T n = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2057 int err = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2058 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2059 if (tvs[idx].v_type == VAR_UNKNOWN) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2060 emsg(_(e_printf)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2061 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2062 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2063 ++*idxp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2064 n = tv_get_number_chk(&tvs[idx], &err); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2065 if (err) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2066 n = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2067 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2068 return n; |
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 |
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 * 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
|
2073 * 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
|
2074 * are not converted to a string. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2075 * 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
|
2076 * 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
|
2077 * Returns NULL for an error. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2078 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2079 static char * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2080 tv_str(typval_T *tvs, int *idxp, char_u **tofree) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2081 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2082 int idx = *idxp - 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2083 char *s = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2084 static char_u numbuf[NUMBUFLEN]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2085 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2086 if (tvs[idx].v_type == VAR_UNKNOWN) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2087 emsg(_(e_printf)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2088 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2089 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2090 ++*idxp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2091 if (tofree != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2092 s = (char *)echo_string(&tvs[idx], tofree, numbuf, get_copyID()); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2093 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2094 s = (char *)tv_get_string_chk(&tvs[idx]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2095 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2096 return s; |
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 |
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 * 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
|
2101 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2102 static double |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2103 tv_float(typval_T *tvs, int *idxp) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2104 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2105 int idx = *idxp - 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2106 double f = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2107 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2108 if (tvs[idx].v_type == VAR_UNKNOWN) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2109 emsg(_(e_printf)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2110 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2111 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2112 ++*idxp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2113 if (tvs[idx].v_type == VAR_FLOAT) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2114 f = tvs[idx].vval.v_float; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2115 else if (tvs[idx].v_type == VAR_NUMBER) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2116 f = (double)tvs[idx].vval.v_number; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2117 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2118 emsg(_(e_expected_float_argument_for_printf)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2119 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2120 return f; |
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 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2123 #endif |
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 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2126 * Return the representation of infinity for printf() function: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2127 * "-inf", "inf", "+inf", " inf", "-INF", "INF", "+INF" or " INF". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2128 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2129 static const char * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2130 infinity_str(int positive, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2131 char fmt_spec, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2132 int force_sign, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2133 int space_for_positive) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2134 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2135 static const char *table[] = |
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 "-inf", "inf", "+inf", " inf", |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2138 "-INF", "INF", "+INF", " INF" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2139 }; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2140 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
|
2141 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2142 if (ASCII_ISUPPER(fmt_spec)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2143 idx += 4; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2144 return table[idx]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2145 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2146 |
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 * 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
|
2149 * 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
|
2150 * consistency. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2151 * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2152 * 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
|
2153 * 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
|
2154 * 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
|
2155 * The original code, including useful comments, can be found here: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2156 * http://www.ijs.si/software/snprintf/ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2157 * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2158 * This snprintf() only supports the following conversion specifiers: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2159 * 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
|
2160 * with flags: '-', '+', ' ', '0' and '#'. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2161 * 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
|
2162 * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2163 * 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
|
2164 * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2165 * 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
|
2166 * 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
|
2167 * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2168 * 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
|
2169 * 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
|
2170 * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2171 * 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
|
2172 * 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
|
2173 * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2174 * 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
|
2175 * 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
|
2176 * 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
|
2177 * 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
|
2178 * 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
|
2179 * the resulting string will be NUL-terminated. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2180 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2181 |
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 * 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
|
2184 * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2185 * 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
|
2186 * "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
|
2187 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2188 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2189 // 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
|
2190 // understand this. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2191 #ifndef PROTO |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2192 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2193 // Like vim_vsnprintf() but append to the string. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2194 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2195 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
|
2196 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2197 va_list ap; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2198 int str_l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2199 size_t len = STRLEN(str); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2200 size_t space; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2201 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2202 if (str_m <= len) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2203 space = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2204 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2205 space = str_m - len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2206 va_start(ap, fmt); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2207 str_l = vim_vsnprintf(str + len, space, fmt, ap); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2208 va_end(ap); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2209 return str_l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2210 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2211 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2212 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2213 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
|
2214 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2215 va_list ap; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2216 int str_l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2217 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2218 va_start(ap, fmt); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2219 str_l = vim_vsnprintf(str, str_m, fmt, ap); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2220 va_end(ap); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2221 return str_l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2222 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2223 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2224 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2225 vim_vsnprintf( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2226 char *str, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2227 size_t str_m, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2228 const char *fmt, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2229 va_list ap) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2230 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2231 return vim_vsnprintf_typval(str, str_m, fmt, ap, NULL); |
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 |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2234 enum |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2235 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2236 TYPE_UNKNOWN = -1, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2237 TYPE_INT, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2238 TYPE_LONGINT, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2239 TYPE_LONGLONGINT, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2240 TYPE_UNSIGNEDINT, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2241 TYPE_UNSIGNEDLONGINT, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2242 TYPE_UNSIGNEDLONGLONGINT, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2243 TYPE_POINTER, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2244 TYPE_PERCENT, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2245 TYPE_CHAR, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2246 TYPE_STRING, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2247 TYPE_FLOAT |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2248 }; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2249 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2250 /* 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
|
2251 */ |
32798
f48e27f20e6b
patch 9.0.1715: duplicate test in message_test.c
Christian Brabandt <cb@256bit.org>
parents:
32775
diff
changeset
|
2252 static int |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2253 format_typeof( |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
2254 const char *type) |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2255 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2256 // 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
|
2257 char length_modifier = '\0'; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2258 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2259 // current conversion specifier character |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2260 char fmt_spec = '\0'; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2261 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2262 // 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
|
2263 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
|
2264 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2265 length_modifier = *type; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2266 type++; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2267 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
|
2268 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2269 // 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
|
2270 length_modifier = 'L'; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2271 type++; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2272 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2273 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2274 fmt_spec = *type; |
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 // common synonyms: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2277 switch (fmt_spec) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2278 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2279 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
|
2280 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
|
2281 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
|
2282 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
|
2283 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
|
2284 default: break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2285 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2286 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2287 // 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
|
2288 switch (fmt_spec) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2289 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2290 // '%' 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
|
2291 // widths |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2292 case '%': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2293 return TYPE_PERCENT; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2294 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2295 case 'c': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2296 return TYPE_CHAR; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2297 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2298 case 's': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2299 case 'S': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2300 return TYPE_STRING; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2301 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2302 case 'd': case 'u': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2303 case 'b': case 'B': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2304 case 'o': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2305 case 'x': case 'X': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2306 case 'p': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2307 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2308 // 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
|
2309 // 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
|
2310 // value |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2311 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2312 // 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
|
2313 // 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
|
2314 // 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
|
2315 // argument is never negative) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2316 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2317 if (fmt_spec == 'p') |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2318 return TYPE_POINTER; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2319 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
|
2320 return TYPE_UNSIGNEDLONGLONGINT; |
32775
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 == 'd') |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2322 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2323 // signed |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2324 switch (length_modifier) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2325 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2326 case '\0': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2327 case 'h': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2328 // 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
|
2329 return TYPE_INT; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2330 case 'l': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2331 return TYPE_LONGINT; |
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_LONGLONGINT; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2334 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2335 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2336 else |
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 // unsigned |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2339 switch (length_modifier) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2340 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2341 case '\0': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2342 case 'h': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2343 return TYPE_UNSIGNEDINT; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2344 case 'l': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2345 return TYPE_UNSIGNEDLONGINT; |
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_UNSIGNEDLONGLONGINT; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2348 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2349 } |
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 break; |
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 case 'f': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2354 case 'F': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2355 case 'e': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2356 case 'E': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2357 case 'g': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2358 case 'G': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2359 return TYPE_FLOAT; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2360 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2361 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2362 return TYPE_UNKNOWN; |
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 |
32798
f48e27f20e6b
patch 9.0.1715: duplicate test in message_test.c
Christian Brabandt <cb@256bit.org>
parents:
32775
diff
changeset
|
2365 static char * |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2366 format_typename( |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2367 const char *type) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2368 { |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
2369 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
|
2370 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2371 case TYPE_INT: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2372 return _(typename_int); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2373 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2374 case TYPE_LONGINT: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2375 return _(typename_longint); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2376 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2377 case TYPE_LONGLONGINT: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2378 return _(typename_longlongint); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2379 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2380 case TYPE_UNSIGNEDINT: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2381 return _(typename_unsignedint); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2382 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2383 case TYPE_UNSIGNEDLONGINT: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2384 return _(typename_unsignedlongint); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2385 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2386 case TYPE_UNSIGNEDLONGLONGINT: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2387 return _(typename_unsignedlonglongint); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2388 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2389 case TYPE_POINTER: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2390 return _(typename_pointer); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2391 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2392 case TYPE_PERCENT: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2393 return _(typename_percent); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2394 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2395 case TYPE_CHAR: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2396 return _(typename_char); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2397 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2398 case TYPE_STRING: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2399 return _(typename_string); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2400 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2401 case TYPE_FLOAT: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2402 return _(typename_float); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2403 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2404 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2405 return _(typename_unknown); |
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 |
32798
f48e27f20e6b
patch 9.0.1715: duplicate test in message_test.c
Christian Brabandt <cb@256bit.org>
parents:
32775
diff
changeset
|
2408 static int |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2409 adjust_types( |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2410 const char ***ap_types, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2411 int arg, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2412 int *num_posarg, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2413 const char *type) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2414 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2415 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
|
2416 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2417 int idx; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2418 const char **new_types; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2419 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2420 if (*ap_types == NULL) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2421 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
|
2422 else |
32991
0bdb1f8a17c1
patch 9.0.1788: C4090 warnings in strings.c
Christian Brabandt <cb@256bit.org>
parents:
32856
diff
changeset
|
2423 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
|
2424 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
|
2425 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2426 if (new_types == NULL) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2427 return FAIL; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2428 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2429 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
|
2430 new_types[idx] = NULL; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2431 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2432 *ap_types = new_types; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2433 *num_posarg = arg; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2434 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2435 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2436 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
|
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][0] == '*' || type[0] == '*') |
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 const char *pt = type; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2441 if (pt[0] == '*') |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2442 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
|
2443 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2444 if (pt[0] != '*') |
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 switch (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 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
|
2449 default: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2450 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
|
2451 return FAIL; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2452 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2453 } |
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 else |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2456 { |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
2457 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
|
2458 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2459 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
|
2460 return FAIL; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2461 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2462 } |
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 (*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
|
2466 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2467 return OK; |
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 |
32798
f48e27f20e6b
patch 9.0.1715: duplicate test in message_test.c
Christian Brabandt <cb@256bit.org>
parents:
32775
diff
changeset
|
2470 static int |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2471 parse_fmt_types( |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2472 const char ***ap_types, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2473 int *num_posarg, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2474 const char *fmt, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2475 typval_T *tvs UNUSED |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2476 ) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2477 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2478 const char *p = fmt; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2479 const char *arg = NULL; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2480 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2481 int any_pos = 0; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2482 int any_arg = 0; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2483 int arg_idx; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2484 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2485 #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
|
2486 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
|
2487 { \ |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2488 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
|
2489 goto error; \ |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2490 } \ |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2491 } while (0); |
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 if (p == NULL) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2494 return OK; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2495 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2496 while (*p != NUL) |
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 if (*p != '%') |
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 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
|
2501 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
|
2502 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2503 p += n; |
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 else |
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 // 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
|
2508 char length_modifier = '\0'; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2509 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2510 // variable for positional arg |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2511 int pos_arg = -1; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2512 const char *ptype = NULL; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2513 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2514 p++; // skip '%' |
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 // 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
|
2517 // argument specifier |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2518 ptype = p; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2519 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2520 while (VIM_ISDIGIT(*ptype)) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2521 ++ptype; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2522 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2523 if (*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 (*p == '0') |
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 // 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
|
2528 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
|
2529 goto error; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2530 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2531 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2532 // Positional argument |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2533 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
|
2534 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2535 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
|
2536 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
|
2537 pos_arg = uj; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2538 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2539 any_pos = 1; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2540 CHECK_POS_ARG; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2541 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2542 ++p; |
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 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2545 // parse flags |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2546 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
|
2547 || *p == '#' || *p == '\'') |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2548 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2549 switch (*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 case '0': break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2552 case '-': break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2553 case '+': break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2554 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
|
2555 // flag should be ignored |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2556 break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2557 case '#': break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2558 case '\'': break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2559 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2560 p++; |
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 // 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
|
2563 // ignored. |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2564 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2565 // parse field width |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2566 if (*(arg = p) == '*') |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2567 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2568 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 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
|
2571 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2572 // Positional argument field width |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2573 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
|
2574 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2575 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
|
2576 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
|
2577 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2578 if (*p != '$') |
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 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
|
2581 goto error; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2582 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2583 else |
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 ++p; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2586 any_pos = 1; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2587 CHECK_POS_ARG; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2588 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2589 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
|
2590 goto error; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2591 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2592 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2593 else |
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 any_arg = 1; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2596 CHECK_POS_ARG; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2597 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2598 } |
33494
8b7a2ea22a86
patch 9.0.1997: Some unused code in move.c and string.c
Christian Brabandt <cb@256bit.org>
parents:
33214
diff
changeset
|
2599 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
|
2600 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2601 // 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
|
2602 // 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
|
2603 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
|
2604 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2605 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
|
2606 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
|
2607 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2608 if (*p == '$') |
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 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
|
2611 goto error; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2612 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2613 } |
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 // parse precision |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2616 if (*p == '.') |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2617 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2618 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 if (*(arg = 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 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 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
|
2625 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2626 // Parse precision |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2627 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
|
2628 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2629 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
|
2630 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
|
2631 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2632 if (*p == '$') |
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 any_pos = 1; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2635 CHECK_POS_ARG; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2636 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2637 ++p; |
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 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
|
2640 goto error; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2641 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2642 else |
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 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
|
2645 goto error; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2646 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2647 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2648 else |
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 any_arg = 1; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2651 CHECK_POS_ARG; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2652 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2653 } |
33494
8b7a2ea22a86
patch 9.0.1997: Some unused code in move.c and string.c
Christian Brabandt <cb@256bit.org>
parents:
33214
diff
changeset
|
2654 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
|
2655 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2656 // 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
|
2657 // 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
|
2658 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
|
2659 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2660 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
|
2661 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
|
2662 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2663 if (*p == '$') |
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 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
|
2666 goto error; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2667 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2668 } |
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 if (pos_arg != -1) |
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 any_pos = 1; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2674 CHECK_POS_ARG; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2675 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2676 ptype = p; |
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 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2679 // 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
|
2680 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
|
2681 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2682 length_modifier = *p; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2683 p++; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2684 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
|
2685 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2686 // 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
|
2687 // length_modifier = 'L'; |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2688 p++; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2689 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2690 } |
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 switch (*p) |
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 // 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
|
2695 case 'i': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2696 case '*': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2697 case 'd': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2698 case 'u': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2699 case 'o': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2700 case 'D': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2701 case 'U': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2702 case 'O': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2703 case 'x': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2704 case 'X': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2705 case 'b': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2706 case 'B': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2707 case 'c': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2708 case 's': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2709 case 'S': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2710 case 'p': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2711 case 'f': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2712 case 'F': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2713 case 'e': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2714 case 'E': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2715 case 'g': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2716 case 'G': |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2717 if (pos_arg != -1) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2718 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2719 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
|
2720 goto error; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2721 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2722 else |
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 any_arg = 1; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2725 CHECK_POS_ARG; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2726 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2727 break; |
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 default: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2730 if (pos_arg != -1) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2731 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2732 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
|
2733 goto error; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2734 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2735 } |
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 if (*p != NUL) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2738 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
|
2739 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2740 } |
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 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
|
2743 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2744 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
|
2745 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2746 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
|
2747 goto error; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2748 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2749 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2750 # if defined(FEAT_EVAL) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2751 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
|
2752 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2753 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
|
2754 goto error; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2755 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2756 # endif |
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 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2759 return OK; |
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 error: |
32991
0bdb1f8a17c1
patch 9.0.1788: C4090 warnings in strings.c
Christian Brabandt <cb@256bit.org>
parents:
32856
diff
changeset
|
2762 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
|
2763 *ap_types = NULL; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2764 *num_posarg = 0; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2765 return FAIL; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2766 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2767 |
32798
f48e27f20e6b
patch 9.0.1715: duplicate test in message_test.c
Christian Brabandt <cb@256bit.org>
parents:
32775
diff
changeset
|
2768 static void |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2769 skip_to_arg( |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2770 const char **ap_types, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2771 va_list ap_start, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2772 va_list *ap, |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2773 int *arg_idx, |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
2774 int *arg_cur, |
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
2775 const char *fmt) |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2776 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2777 int arg_min = 0; |
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 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
|
2780 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2781 ++*arg_cur; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2782 ++*arg_idx; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2783 return; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2784 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2785 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2786 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
|
2787 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2788 // 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
|
2789 va_end(*ap); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2790 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
|
2791 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2792 else |
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 // 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
|
2795 arg_min = *arg_cur; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2796 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2797 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2798 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
|
2799 { |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
2800 const char *p; |
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
2801 |
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
2802 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
|
2803 { |
33214
39bc126cc890
patch 9.0.1884: Wrong order of arguments for error messages
Christian Brabandt <cb@256bit.org>
parents:
33162
diff
changeset
|
2804 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
|
2805 return; |
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
2806 } |
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
2807 |
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
2808 p = ap_types[*arg_cur]; |
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 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
|
2811 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2812 // 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
|
2813 switch (fmt_type) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2814 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2815 case TYPE_PERCENT: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2816 case TYPE_UNKNOWN: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2817 break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2818 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2819 case TYPE_CHAR: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2820 va_arg(*ap, int); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2821 break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2822 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2823 case TYPE_STRING: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2824 va_arg(*ap, char *); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2825 break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2826 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2827 case TYPE_POINTER: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2828 va_arg(*ap, void *); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2829 break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2830 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2831 case TYPE_INT: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2832 va_arg(*ap, int); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2833 break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2834 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2835 case TYPE_LONGINT: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2836 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
|
2837 break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2838 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2839 case TYPE_LONGLONGINT: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2840 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
|
2841 break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2842 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2843 case TYPE_UNSIGNEDINT: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2844 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
|
2845 break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2846 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2847 case TYPE_UNSIGNEDLONGINT: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2848 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
|
2849 break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2850 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2851 case TYPE_UNSIGNEDLONGLONGINT: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2852 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
|
2853 break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2854 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2855 case TYPE_FLOAT: |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2856 va_arg(*ap, double); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2857 break; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2858 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2859 } |
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 // 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
|
2862 // 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
|
2863 // 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
|
2864 ++*arg_cur; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2865 ++*arg_idx; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2866 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2867 return; |
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 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2870 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2871 vim_vsnprintf_typval( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2872 char *str, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2873 size_t str_m, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2874 const char *fmt, |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2875 va_list ap_start, |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2876 typval_T *tvs) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2877 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2878 size_t str_l = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2879 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
|
2880 int arg_cur = 0; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2881 int num_posarg = 0; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2882 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
|
2883 va_list ap; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2884 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
|
2885 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2886 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
|
2887 return 0; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2888 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2889 va_copy(ap, ap_start); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2890 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2891 if (p == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2892 p = ""; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2893 while (*p != NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2894 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2895 if (*p != '%') |
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 char *q = strchr(p + 1, '%'); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2898 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
|
2899 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2900 // Copy up to the next '%' or NUL without any changes. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2901 if (str_l < str_m) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2902 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2903 size_t avail = str_m - str_l; |
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 mch_memmove(str + str_l, p, n > avail ? avail : n); |
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 p += n; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2908 str_l += n; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2909 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2910 else |
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 size_t min_field_width = 0, precision = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2913 int zero_padding = 0, precision_specified = 0, justify_left = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2914 int alternate_form = 0, force_sign = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2915 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2916 // If both the ' ' and '+' flags appear, the ' ' flag should be |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2917 // ignored. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2918 int space_for_positive = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2919 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2920 // allowed values: \0, h, l, L |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2921 char length_modifier = '\0'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2922 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2923 // temporary buffer for simple numeric->string conversion |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2924 # 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
|
2925 // That sounds reasonable to use as the maximum |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2926 // printable. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2927 char tmp[TMP_LEN]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2928 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2929 // string address in case of string argument |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2930 const char *str_arg = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2931 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2932 // natural field width of arg without padding and sign |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2933 size_t str_arg_l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2934 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2935 // unsigned char argument value - only defined for c conversion. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2936 // 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
|
2937 // conversion is unsigned |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2938 unsigned char uchar_arg; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2939 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2940 // number of zeros to be inserted for numeric conversions as |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2941 // required by the precision or minimal field width |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2942 size_t number_of_zeros_to_pad = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2943 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2944 // index into tmp where zero padding is to be inserted |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2945 size_t zero_padding_insertion_ind = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2946 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2947 // current conversion specifier character |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2948 char fmt_spec = '\0'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2949 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2950 // buffer for 's' and 'S' specs |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2951 char_u *tofree = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2952 |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2953 // variables for positional arg |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2954 int pos_arg = -1; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2955 const char *ptype; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2956 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2957 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2958 p++; // skip '%' |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2959 |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2960 // 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
|
2961 // argument specifier |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2962 ptype = p; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2963 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2964 while (VIM_ISDIGIT(*ptype)) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2965 ++ptype; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2966 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2967 if (*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 // Positional argument |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2970 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
|
2971 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2972 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
|
2973 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
|
2974 pos_arg = uj; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2975 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
2976 ++p; |
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 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2979 // parse flags |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2980 while (*p == '0' || *p == '-' || *p == '+' || *p == ' ' |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2981 || *p == '#' || *p == '\'') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2982 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2983 switch (*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 case '0': zero_padding = 1; break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2986 case '-': justify_left = 1; break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2987 case '+': force_sign = 1; space_for_positive = 0; break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2988 case ' ': force_sign = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2989 // If both the ' ' and '+' flags appear, the ' ' |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2990 // flag should be ignored |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2991 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2992 case '#': alternate_form = 1; break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2993 case '\'': break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2994 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2995 p++; |
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 // 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
|
2998 // ignored. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2999 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3000 // parse field width |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3001 if (*p == '*') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3002 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3003 int j; |
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 p++; |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3006 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3007 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
|
3008 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3009 // Positional argument field width |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3010 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
|
3011 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3012 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
|
3013 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
|
3014 arg_idx = uj; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3015 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3016 ++p; |
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 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3019 j = |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3020 # if defined(FEAT_EVAL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3021 tvs != NULL ? tv_nr(tvs, &arg_idx) : |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3022 # endif |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3023 (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
|
3024 &arg_cur, fmt), |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3025 va_arg(ap, int)); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3026 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3027 if (j >= 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3028 min_field_width = j; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3029 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3030 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3031 min_field_width = -j; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3032 justify_left = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3033 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3034 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3035 else if (VIM_ISDIGIT((int)(*p))) |
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 // 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
|
3038 // argument like common implementations do |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3039 unsigned int uj = *p++ - '0'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3040 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3041 while (VIM_ISDIGIT((int)(*p))) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3042 uj = 10 * uj + (unsigned int)(*p++ - '0'); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3043 min_field_width = uj; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3044 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3045 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3046 // parse precision |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3047 if (*p == '.') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3048 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3049 p++; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3050 precision_specified = 1; |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3051 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3052 if (VIM_ISDIGIT((int)(*p))) |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3053 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3054 // 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
|
3055 // treat argument like common implementations do |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3056 unsigned int uj = *p++ - '0'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3057 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3058 while (VIM_ISDIGIT((int)(*p))) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3059 uj = 10 * uj + (unsigned int)(*p++ - '0'); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3060 precision = uj; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3061 } |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3062 else if (*p == '*') |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3063 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3064 int j; |
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 p++; |
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 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
|
3069 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3070 // positional argument |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3071 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
|
3072 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3073 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
|
3074 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
|
3075 arg_idx = uj; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3076 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3077 ++p; |
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 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3080 j = |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3081 # if defined(FEAT_EVAL) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3082 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
|
3083 # endif |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3084 (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
|
3085 &arg_cur, fmt), |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3086 va_arg(ap, int)); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3087 |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3088 if (j >= 0) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3089 precision = j; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3090 else |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3091 { |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3092 precision_specified = 0; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3093 precision = 0; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3094 } |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3095 } |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3096 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3097 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3098 // parse 'h', 'l' and 'll' length modifiers |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3099 if (*p == 'h' || *p == 'l') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3100 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3101 length_modifier = *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3102 p++; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3103 if (length_modifier == 'l' && *p == 'l') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3104 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3105 // double l = __int64 / varnumber_T |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3106 length_modifier = 'L'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3107 p++; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3108 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3109 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3110 fmt_spec = *p; |
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 // common synonyms: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3113 switch (fmt_spec) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3114 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3115 case 'i': fmt_spec = 'd'; break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3116 case 'D': fmt_spec = 'd'; length_modifier = 'l'; break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3117 case 'U': fmt_spec = 'u'; length_modifier = 'l'; break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3118 case 'O': fmt_spec = 'o'; length_modifier = 'l'; break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3119 default: break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3120 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3121 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3122 # if defined(FEAT_EVAL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3123 switch (fmt_spec) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3124 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3125 case 'd': case 'u': case 'o': case 'x': case 'X': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3126 if (tvs != NULL && length_modifier == '\0') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3127 length_modifier = 'L'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3128 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3129 # endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3130 |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3131 if (pos_arg != -1) |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3132 arg_idx = pos_arg; |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3133 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3134 // get parameter value, do initial processing |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3135 switch (fmt_spec) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3136 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3137 // '%' and 'c' behave similar to 's' regarding flags and field |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3138 // widths |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3139 case '%': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3140 case 'c': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3141 case 's': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3142 case 'S': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3143 str_arg_l = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3144 switch (fmt_spec) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3145 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3146 case '%': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3147 str_arg = p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3148 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3149 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3150 case 'c': |
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 int j; |
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 j = |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3155 # if defined(FEAT_EVAL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3156 tvs != NULL ? tv_nr(tvs, &arg_idx) : |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3157 # endif |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3158 (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
|
3159 &arg_cur, fmt), |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3160 va_arg(ap, int)); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3161 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3162 // standard demands unsigned char |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3163 uchar_arg = (unsigned char)j; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3164 str_arg = (char *)&uchar_arg; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3165 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3166 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3167 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3168 case 's': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3169 case 'S': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3170 str_arg = |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3171 # if defined(FEAT_EVAL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3172 tvs != NULL ? tv_str(tvs, &arg_idx, &tofree) : |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3173 # endif |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3174 (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
|
3175 &arg_cur, fmt), |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3176 va_arg(ap, char *)); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3177 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3178 if (str_arg == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3179 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3180 str_arg = "[NULL]"; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3181 str_arg_l = 6; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3182 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3183 // make sure not to address string beyond the specified |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3184 // precision !!! |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3185 else if (!precision_specified) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3186 str_arg_l = strlen(str_arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3187 // truncate string if necessary as requested by precision |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3188 else if (precision == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3189 str_arg_l = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3190 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3191 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3192 // 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
|
3193 // macro. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3194 // memchr on HP does not like n > 2^31 !!! |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3195 char *q = memchr(str_arg, '\0', |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3196 precision <= (size_t)0x7fffffffL ? precision |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3197 : (size_t)0x7fffffffL); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3198 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3199 str_arg_l = (q == NULL) ? precision |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3200 : (size_t)(q - str_arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3201 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3202 if (fmt_spec == 'S') |
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 char_u *p1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3205 size_t i; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3206 int cell; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3207 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3208 for (i = 0, p1 = (char_u *)str_arg; *p1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3209 p1 += mb_ptr2len(p1)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3210 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3211 cell = mb_ptr2cells(p1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3212 if (precision_specified && i + cell > precision) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3213 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3214 i += cell; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3215 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3216 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3217 str_arg_l = p1 - (char_u *)str_arg; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3218 if (min_field_width != 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3219 min_field_width += str_arg_l - i; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3220 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3221 break; |
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 default: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3224 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3225 } |
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 case 'd': case 'u': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3229 case 'b': case 'B': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3230 case 'o': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3231 case 'x': case 'X': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3232 case 'p': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3233 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3234 // 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
|
3235 // imply the value is unsigned; d implies a signed |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3236 // value |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3237 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3238 // 0 if numeric argument is zero (or if pointer is |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3239 // NULL for 'p'), +1 if greater than zero (or nonzero |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3240 // for unsigned arguments), -1 if negative (unsigned |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3241 // argument is never negative) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3242 int arg_sign = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3243 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3244 // only set for length modifier h, or for no length |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3245 // modifiers |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3246 int int_arg = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3247 unsigned int uint_arg = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3248 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3249 // only set for length modifier l |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3250 long int long_arg = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3251 unsigned long int ulong_arg = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3252 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3253 // only set for length modifier ll |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3254 varnumber_T llong_arg = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3255 uvarnumber_T ullong_arg = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3256 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3257 // only set for b conversion |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3258 uvarnumber_T bin_arg = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3259 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3260 // pointer argument value -only defined for p |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3261 // conversion |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3262 void *ptr_arg = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3263 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3264 if (fmt_spec == 'p') |
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 length_modifier = '\0'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3267 ptr_arg = |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3268 # if defined(FEAT_EVAL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3269 tvs != NULL ? (void *)tv_str(tvs, &arg_idx, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3270 NULL) : |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3271 # endif |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3272 (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
|
3273 &arg_cur, fmt), |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3274 va_arg(ap, void *)); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3275 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3276 if (ptr_arg != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3277 arg_sign = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3278 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3279 else if (fmt_spec == 'b' || fmt_spec == 'B') |
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 bin_arg = |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3282 # if defined(FEAT_EVAL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3283 tvs != NULL ? |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3284 (uvarnumber_T)tv_nr(tvs, &arg_idx) : |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3285 # endif |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3286 (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
|
3287 &arg_cur, fmt), |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3288 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
|
3289 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3290 if (bin_arg != 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3291 arg_sign = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3292 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3293 else if (fmt_spec == 'd') |
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 // signed |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3296 switch (length_modifier) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3297 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3298 case '\0': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3299 case 'h': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3300 // char and short arguments are passed as int. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3301 int_arg = |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3302 # if defined(FEAT_EVAL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3303 tvs != NULL ? tv_nr(tvs, &arg_idx) : |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3304 # endif |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3305 (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
|
3306 &arg_cur, fmt), |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3307 va_arg(ap, int)); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3308 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3309 if (int_arg > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3310 arg_sign = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3311 else 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 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3314 case 'l': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3315 long_arg = |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3316 # if defined(FEAT_EVAL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3317 tvs != NULL ? tv_nr(tvs, &arg_idx) : |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3318 # endif |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3319 (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
|
3320 &arg_cur, fmt), |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3321 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
|
3322 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3323 if (long_arg > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3324 arg_sign = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3325 else 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 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3328 case 'L': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3329 llong_arg = |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3330 # if defined(FEAT_EVAL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3331 tvs != NULL ? tv_nr(tvs, &arg_idx) : |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3332 # endif |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3333 (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
|
3334 &arg_cur, fmt), |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3335 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
|
3336 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3337 if (llong_arg > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3338 arg_sign = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3339 else 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 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3342 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3343 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3344 else |
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 // unsigned |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3347 switch (length_modifier) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3348 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3349 case '\0': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3350 case 'h': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3351 uint_arg = |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3352 # if defined(FEAT_EVAL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3353 tvs != NULL ? (unsigned) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3354 tv_nr(tvs, &arg_idx) : |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3355 # endif |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3356 (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
|
3357 &arg_cur, fmt), |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3358 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
|
3359 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3360 if (uint_arg != 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3361 arg_sign = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3362 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3363 case 'l': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3364 ulong_arg = |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3365 # if defined(FEAT_EVAL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3366 tvs != NULL ? (unsigned long) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3367 tv_nr(tvs, &arg_idx) : |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3368 # endif |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3369 (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
|
3370 &arg_cur, fmt), |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3371 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
|
3372 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3373 if (ulong_arg != 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3374 arg_sign = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3375 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3376 case 'L': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3377 ullong_arg = |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3378 # if defined(FEAT_EVAL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3379 tvs != NULL ? (uvarnumber_T) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3380 tv_nr(tvs, &arg_idx) : |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3381 # endif |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3382 (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
|
3383 &arg_cur, fmt), |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3384 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
|
3385 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3386 if (ullong_arg != 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3387 arg_sign = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3388 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3389 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3390 } |
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 str_arg = tmp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3393 str_arg_l = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3394 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3395 // NOTE: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3396 // 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
|
3397 // specified, the '0' flag should be ignored. This is so |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3398 // 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
|
3399 // FreeBSD, NetBSD; but not with Perl. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3400 if (precision_specified) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3401 zero_padding = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3402 if (fmt_spec == 'd') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3403 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3404 if (force_sign && arg_sign >= 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3405 tmp[str_arg_l++] = space_for_positive ? ' ' : '+'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3406 // leave negative numbers for sprintf to handle, to |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3407 // avoid handling tricky cases like (short int)-32768 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3408 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3409 else if (alternate_form) |
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 if (arg_sign != 0 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3412 && (fmt_spec == 'b' || fmt_spec == 'B' |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3413 || fmt_spec == 'x' || fmt_spec == 'X') ) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3414 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3415 tmp[str_arg_l++] = '0'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3416 tmp[str_arg_l++] = fmt_spec; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3417 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3418 // alternate form should have no effect for p |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3419 // conversion, but ... |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3420 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3421 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3422 zero_padding_insertion_ind = str_arg_l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3423 if (!precision_specified) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3424 precision = 1; // default precision is 1 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3425 if (precision == 0 && arg_sign == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3426 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3427 // When zero value is formatted with an explicit |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3428 // precision 0, the resulting formatted string is |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3429 // empty (d, i, u, b, B, o, x, X, p). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3430 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3431 else |
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 char f[6]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3434 int f_l = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3435 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3436 // construct a simple format string for sprintf |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3437 f[f_l++] = '%'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3438 if (!length_modifier) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3439 ; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3440 else if (length_modifier == 'L') |
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 # ifdef MSWIN |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3443 f[f_l++] = 'I'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3444 f[f_l++] = '6'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3445 f[f_l++] = '4'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3446 # else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3447 f[f_l++] = 'l'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3448 f[f_l++] = 'l'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3449 # endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3450 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3451 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3452 f[f_l++] = length_modifier; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3453 f[f_l++] = fmt_spec; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3454 f[f_l++] = '\0'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3455 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3456 if (fmt_spec == 'p') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3457 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
|
3458 else if (fmt_spec == 'b' || fmt_spec == 'B') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3459 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3460 char b[8 * sizeof(uvarnumber_T)]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3461 size_t b_l = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3462 uvarnumber_T bn = bin_arg; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3463 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3464 do |
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 b[sizeof(b) - ++b_l] = '0' + (bn & 0x1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3467 bn >>= 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3468 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3469 while (bn != 0); |
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 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
|
3472 str_arg_l += b_l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3473 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3474 else if (fmt_spec == 'd') |
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 // signed |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3477 switch (length_modifier) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3478 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3479 case '\0': str_arg_l += sprintf( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3480 tmp + str_arg_l, f, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3481 int_arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3482 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3483 case 'h': str_arg_l += sprintf( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3484 tmp + str_arg_l, f, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3485 (short)int_arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3486 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3487 case 'l': str_arg_l += sprintf( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3488 tmp + str_arg_l, f, long_arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3489 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3490 case 'L': str_arg_l += sprintf( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3491 tmp + str_arg_l, f, llong_arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3492 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3493 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3494 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3495 else |
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 // unsigned |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3498 switch (length_modifier) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3499 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3500 case '\0': str_arg_l += sprintf( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3501 tmp + str_arg_l, f, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3502 uint_arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3503 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3504 case 'h': str_arg_l += sprintf( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3505 tmp + str_arg_l, f, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3506 (unsigned short)uint_arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3507 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3508 case 'l': str_arg_l += sprintf( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3509 tmp + str_arg_l, f, ulong_arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3510 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3511 case 'L': str_arg_l += sprintf( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3512 tmp + str_arg_l, f, ullong_arg); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3513 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3514 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3515 } |
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 // include the optional minus sign and possible |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3518 // "0x" in the region before the zero padding |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3519 // insertion point |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3520 if (zero_padding_insertion_ind < str_arg_l |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3521 && tmp[zero_padding_insertion_ind] == '-') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3522 zero_padding_insertion_ind++; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3523 if (zero_padding_insertion_ind + 1 < str_arg_l |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3524 && tmp[zero_padding_insertion_ind] == '0' |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3525 && (tmp[zero_padding_insertion_ind + 1] == 'x' |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3526 || tmp[zero_padding_insertion_ind + 1] == 'X')) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3527 zero_padding_insertion_ind += 2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3528 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3529 |
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 size_t num_of_digits = str_arg_l |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3532 - zero_padding_insertion_ind; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3533 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3534 if (alternate_form && fmt_spec == 'o' |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3535 // unless zero is already the first |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3536 // character |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3537 && !(zero_padding_insertion_ind < str_arg_l |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3538 && tmp[zero_padding_insertion_ind] == '0')) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3539 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3540 // assure leading zero for alternate-form |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3541 // octal numbers |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3542 if (!precision_specified |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3543 || precision < num_of_digits + 1) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3544 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3545 // precision is increased to force the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3546 // first character to be zero, except if a |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3547 // zero value is formatted with an |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3548 // explicit precision of zero |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3549 precision = num_of_digits + 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3550 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3551 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3552 // zero padding to specified precision? |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3553 if (num_of_digits < precision) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3554 number_of_zeros_to_pad = precision - num_of_digits; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3555 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3556 // zero padding to specified minimal field width? |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3557 if (!justify_left && zero_padding) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3558 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3559 int n = (int)(min_field_width - (str_arg_l |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3560 + number_of_zeros_to_pad)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3561 if (n > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3562 number_of_zeros_to_pad += n; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3563 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3564 break; |
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 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3567 case 'f': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3568 case 'F': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3569 case 'e': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3570 case 'E': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3571 case 'g': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3572 case 'G': |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3573 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3574 // Floating point. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3575 double f; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3576 double abs_f; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3577 char format[40]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3578 int l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3579 int remove_trailing_zeroes = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3580 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3581 f = |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3582 # if defined(FEAT_EVAL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3583 tvs != NULL ? tv_float(tvs, &arg_idx) : |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3584 # endif |
33148
7bc10151ce81
patch 9.0.1856: issues with formatting positional arguments
Christian Brabandt <cb@256bit.org>
parents:
32991
diff
changeset
|
3585 (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
|
3586 &arg_cur, fmt), |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3587 va_arg(ap, double)); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3588 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3589 abs_f = f < 0 ? -f : f; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3590 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3591 if (fmt_spec == 'g' || fmt_spec == 'G') |
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 // Would be nice to use %g directly, but it prints |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3594 // "1.0" as "1", we don't want that. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3595 if ((abs_f >= 0.001 && abs_f < 10000000.0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3596 || abs_f == 0.0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3597 fmt_spec = ASCII_ISUPPER(fmt_spec) ? 'F' : 'f'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3598 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3599 fmt_spec = fmt_spec == 'g' ? 'e' : 'E'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3600 remove_trailing_zeroes = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3601 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3602 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3603 if ((fmt_spec == 'f' || fmt_spec == 'F') && |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3604 # ifdef VAX |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3605 abs_f > 1.0e38 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3606 # else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3607 abs_f > 1.0e307 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3608 # endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3609 ) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3610 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3611 // Avoid a buffer overflow |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3612 STRCPY(tmp, infinity_str(f > 0.0, fmt_spec, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3613 force_sign, space_for_positive)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3614 str_arg_l = STRLEN(tmp); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3615 zero_padding = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3616 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3617 else |
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 if (isnan(f)) |
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 // Not a number: nan or NAN |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3622 STRCPY(tmp, ASCII_ISUPPER(fmt_spec) ? "NAN" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3623 : "nan"); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3624 str_arg_l = 3; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3625 zero_padding = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3626 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3627 else if (isinf(f)) |
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 STRCPY(tmp, infinity_str(f > 0.0, fmt_spec, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3630 force_sign, space_for_positive)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3631 str_arg_l = STRLEN(tmp); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3632 zero_padding = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3633 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3634 else |
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 // Regular float number |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3637 format[0] = '%'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3638 l = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3639 if (force_sign) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3640 format[l++] = space_for_positive ? ' ' : '+'; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3641 if (precision_specified) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3642 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3643 size_t max_prec = TMP_LEN - 10; |
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 // Make sure we don't get more digits than we |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3646 // have room for. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3647 if ((fmt_spec == 'f' || fmt_spec == 'F') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3648 && abs_f > 1.0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3649 max_prec -= (size_t)log10(abs_f); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3650 if (precision > max_prec) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3651 precision = max_prec; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3652 l += sprintf(format + l, ".%d", (int)precision); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3653 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3654 format[l] = fmt_spec == 'F' ? 'f' : fmt_spec; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3655 format[l + 1] = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3656 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3657 str_arg_l = sprintf(tmp, format, f); |
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 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3660 if (remove_trailing_zeroes) |
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 int i; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3663 char *tp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3664 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3665 // Using %g or %G: remove superfluous zeroes. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3666 if (fmt_spec == 'f' || fmt_spec == 'F') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3667 tp = tmp + str_arg_l - 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3668 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3669 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3670 tp = (char *)vim_strchr((char_u *)tmp, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3671 fmt_spec == 'e' ? 'e' : 'E'); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3672 if (tp != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3673 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3674 // Remove superfluous '+' and leading |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3675 // zeroes from the exponent. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3676 if (tp[1] == '+') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3677 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3678 // Change "1.0e+07" to "1.0e07" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3679 STRMOVE(tp + 1, tp + 2); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3680 --str_arg_l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3681 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3682 i = (tp[1] == '-') ? 2 : 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3683 while (tp[i] == '0') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3684 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3685 // Change "1.0e07" to "1.0e7" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3686 STRMOVE(tp + i, tp + i + 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3687 --str_arg_l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3688 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3689 --tp; |
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 } |
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 if (tp != NULL && !precision_specified) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3694 // Remove trailing zeroes, but keep the one |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3695 // just after a dot. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3696 while (tp > tmp + 2 && *tp == '0' |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3697 && tp[-1] != '.') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3698 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3699 STRMOVE(tp, tp + 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3700 --tp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3701 --str_arg_l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3702 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3703 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3704 else |
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 char *tp; |
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 // Be consistent: some printf("%e") use 1.0e+12 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3709 // 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
|
3710 // case. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3711 tp = (char *)vim_strchr((char_u *)tmp, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3712 fmt_spec == 'e' ? 'e' : 'E'); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3713 if (tp != NULL && (tp[1] == '+' || tp[1] == '-') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3714 && tp[2] == '0' |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3715 && vim_isdigit(tp[3]) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3716 && vim_isdigit(tp[4])) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3717 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3718 STRMOVE(tp + 2, tp + 3); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3719 --str_arg_l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3720 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3721 } |
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 if (zero_padding && min_field_width > str_arg_l |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3724 && (tmp[0] == '-' || force_sign)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3725 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3726 // padding 0's should be inserted after the sign |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3727 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
|
3728 zero_padding_insertion_ind = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3729 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3730 str_arg = tmp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3731 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3732 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3733 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3734 default: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3735 // unrecognized conversion specifier, keep format string |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3736 // as-is |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3737 zero_padding = 0; // turn zero padding off for non-numeric |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3738 // conversion |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3739 justify_left = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3740 min_field_width = 0; // reset flags |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3741 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3742 // discard the unrecognized conversion, just keep * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3743 // the unrecognized conversion character |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3744 str_arg = p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3745 str_arg_l = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3746 if (*p != NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3747 str_arg_l++; // include invalid conversion specifier |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3748 // unchanged if not at end-of-string |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3749 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3750 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3751 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3752 if (*p != NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3753 p++; // step over the just processed conversion specifier |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3754 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3755 // 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
|
3756 // 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
|
3757 // conversions |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3758 if (!justify_left) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3759 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3760 // left padding with blank or zero |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3761 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
|
3762 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3763 if (pn > 0) |
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 (str_l < str_m) |
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 size_t avail = str_m - str_l; |
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 vim_memset(str + str_l, zero_padding ? '0' : ' ', |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3770 (size_t)pn > avail ? avail |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3771 : (size_t)pn); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3772 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3773 str_l += 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 } |
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 // 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
|
3778 // field width for numeric conversions required? |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3779 if (number_of_zeros_to_pad == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3780 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3781 // will not copy first part of numeric right now, * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3782 // force it to be copied later in its entirety |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3783 zero_padding_insertion_ind = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3784 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3785 else |
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 // insert first part of numerics (sign or '0x') before zero |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3788 // padding |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3789 int zn = (int)zero_padding_insertion_ind; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3790 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3791 if (zn > 0) |
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 (str_l < str_m) |
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 size_t avail = str_m - str_l; |
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 mch_memmove(str + str_l, str_arg, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3798 (size_t)zn > avail ? avail |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3799 : (size_t)zn); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3800 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3801 str_l += 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 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3804 // insert zero padding as requested by the precision or min |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3805 // field width |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3806 zn = (int)number_of_zeros_to_pad; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3807 if (zn > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3808 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3809 if (str_l < str_m) |
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 size_t avail = str_m - str_l; |
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 vim_memset(str + str_l, '0', |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3814 (size_t)zn > avail ? avail |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3815 : (size_t)zn); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3816 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3817 str_l += 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 } |
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 // insert formatted string |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3822 // (or as-is conversion specifier for unknown conversions) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3823 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3824 int sn = (int)(str_arg_l - zero_padding_insertion_ind); |
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 if (sn > 0) |
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 (str_l < str_m) |
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 size_t avail = str_m - str_l; |
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 mch_memmove(str + str_l, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3833 str_arg + zero_padding_insertion_ind, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3834 (size_t)sn > avail ? avail : (size_t)sn); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3835 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3836 str_l += 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 } |
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 // insert right padding |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3841 if (justify_left) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3842 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3843 // right blank padding to the field width |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3844 int pn = (int)(min_field_width |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3845 - (str_arg_l + number_of_zeros_to_pad)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3846 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3847 if (pn > 0) |
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 (str_l < str_m) |
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 size_t avail = str_m - str_l; |
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 vim_memset(str + str_l, ' ', |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3854 (size_t)pn > avail ? avail |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3855 : (size_t)pn); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3856 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3857 str_l += 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 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3860 vim_free(tofree); |
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 } |
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 if (str_m > 0) |
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 // 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
|
3867 // 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
|
3868 // |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3869 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
|
3870 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3871 |
32775
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3872 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
|
3873 emsg(_(e_too_many_arguments_to_printf)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3874 |
32991
0bdb1f8a17c1
patch 9.0.1788: C4090 warnings in strings.c
Christian Brabandt <cb@256bit.org>
parents:
32856
diff
changeset
|
3875 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
|
3876 va_end(ap); |
2d5e8c46508b
patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
3877 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3878 // Return the number of characters formatted (excluding trailing nul |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3879 // 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
|
3880 // written to the buffer if it were large enough. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3881 return (int)str_l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3882 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3883 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3884 #endif // PROTO |