summaryrefslogtreecommitdiff
path: root/data/vim/patches/8.1.0772
blob: c2dee756c345667ccfa615ed62f719492c721410 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
To: vim_dev@googlegroups.com
Subject: Patch 8.1.0772
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

Patch 8.1.0772
Problem:    The sign_define_by_name() function is too long.
Solution:   Split it into smaller functions. (Yegappan Lakshmanan,
            closes #3819)
Files:	    src/sign.c


*** ../vim-8.1.0771/src/sign.c	2019-01-17 17:36:42.495509219 +0100
--- src/sign.c	2019-01-18 22:00:14.645875627 +0100
***************
*** 727,732 ****
--- 727,866 ----
  }
  
  /*
+  * Allocate a new sign
+  */
+     static sign_T *
+ alloc_new_sign(char_u *name)
+ {
+     sign_T	*sp;
+     sign_T	*lp;
+     int	start = next_sign_typenr;
+ 
+     // Allocate a new sign.
+     sp = (sign_T *)alloc_clear_id((unsigned)sizeof(sign_T),
+ 	    aid_sign_define_by_name);
+     if (sp == NULL)
+ 	return NULL;
+ 
+     // Check that next_sign_typenr is not already being used.
+     // This only happens after wrapping around.  Hopefully
+     // another one got deleted and we can use its number.
+     for (lp = first_sign; lp != NULL; )
+     {
+ 	if (lp->sn_typenr == next_sign_typenr)
+ 	{
+ 	    ++next_sign_typenr;
+ 	    if (next_sign_typenr == MAX_TYPENR)
+ 		next_sign_typenr = 1;
+ 	    if (next_sign_typenr == start)
+ 	    {
+ 		vim_free(sp);
+ 		emsg(_("E612: Too many signs defined"));
+ 		return NULL;
+ 	    }
+ 	    lp = first_sign;  // start all over
+ 	    continue;
+ 	}
+ 	lp = lp->sn_next;
+     }
+ 
+     sp->sn_typenr = next_sign_typenr;
+     if (++next_sign_typenr == MAX_TYPENR)
+ 	next_sign_typenr = 1; // wrap around
+ 
+     sp->sn_name = vim_strsave(name);
+     if (sp->sn_name == NULL)  // out of memory
+     {
+ 	vim_free(sp);
+ 	return NULL;
+     }
+ 
+     return sp;
+ }
+ 
+ /*
+  * Initialize the icon information for a new sign
+  */
+     static void
+ sign_define_init_icon(sign_T *sp, char_u *icon)
+ {
+     vim_free(sp->sn_icon);
+     sp->sn_icon = vim_strsave(icon);
+     backslash_halve(sp->sn_icon);
+ # ifdef FEAT_SIGN_ICONS
+     if (gui.in_use)
+     {
+ 	out_flush();
+ 	if (sp->sn_image != NULL)
+ 	    gui_mch_destroy_sign(sp->sn_image);
+ 	sp->sn_image = gui_mch_register_sign(sp->sn_icon);
+     }
+ # endif
+ }
+ 
+ /*
+  * Initialize the text for a new sign
+  */
+     static int
+ sign_define_init_text(sign_T *sp, char_u *text)
+ {
+     char_u	*s;
+     char_u	*endp;
+     int		cells;
+     int		len;
+ 
+     endp = text + (int)STRLEN(text);
+ 
+     // Remove backslashes so that it is possible to use a space.
+     for (s = text; s + 1 < endp; ++s)
+ 	if (*s == '\\')
+ 	{
+ 	    STRMOVE(s, s + 1);
+ 	    --endp;
+ 	}
+ 
+     // Count cells and check for non-printable chars
+ # ifdef FEAT_MBYTE
+     if (has_mbyte)
+     {
+ 	cells = 0;
+ 	for (s = text; s < endp; s += (*mb_ptr2len)(s))
+ 	{
+ 	    if (!vim_isprintc((*mb_ptr2char)(s)))
+ 		break;
+ 	    cells += (*mb_ptr2cells)(s);
+ 	}
+     }
+     else
+ # endif
+     {
+ 	for (s = text; s < endp; ++s)
+ 	    if (!vim_isprintc(*s))
+ 		break;
+ 	cells = (int)(s - text);
+     }
+ 
+     // Currently sign text must be one or two display cells
+     if (s != endp || cells < 1 || cells > 2)
+     {
+ 	semsg(_("E239: Invalid sign text: %s"), text);
+ 	return FAIL;
+     }
+ 
+     vim_free(sp->sn_text);
+     // Allocate one byte more if we need to pad up
+     // with a space.
+     len = (int)(endp - text + ((cells == 1) ? 1 : 0));
+     sp->sn_text = vim_strnsave(text, len);
+ 
+     // For single character sign text, pad with a space.
+     if (sp->sn_text != NULL && cells == 1)
+ 	STRCPY(sp->sn_text + len - 1, " ");
+ 
+     return OK;
+ }
+ 
+ /*
   * Define a new sign or update an existing sign
   */
      int
***************
*** 743,790 ****
      sp = sign_find(name, &sp_prev);
      if (sp == NULL)
      {
! 	sign_T	*lp;
! 	int	start = next_sign_typenr;
! 
! 	// Allocate a new sign.
! 	sp = (sign_T *)alloc_clear_id((unsigned)sizeof(sign_T),
! 						aid_sign_define_by_name);
  	if (sp == NULL)
  	    return FAIL;
  
- 	// Check that next_sign_typenr is not already being used.
- 	// This only happens after wrapping around.  Hopefully
- 	// another one got deleted and we can use its number.
- 	for (lp = first_sign; lp != NULL; )
- 	{
- 	    if (lp->sn_typenr == next_sign_typenr)
- 	    {
- 		++next_sign_typenr;
- 		if (next_sign_typenr == MAX_TYPENR)
- 		    next_sign_typenr = 1;
- 		if (next_sign_typenr == start)
- 		{
- 		    vim_free(sp);
- 		    emsg(_("E612: Too many signs defined"));
- 		    return FAIL;
- 		}
- 		lp = first_sign;  // start all over
- 		continue;
- 	    }
- 	    lp = lp->sn_next;
- 	}
- 
- 	sp->sn_typenr = next_sign_typenr;
- 	if (++next_sign_typenr == MAX_TYPENR)
- 	    next_sign_typenr = 1; // wrap around
- 
- 	sp->sn_name = vim_strsave(name);
- 	if (sp->sn_name == NULL)  // out of memory
- 	{
- 	    vim_free(sp);
- 	    return FAIL;
- 	}
- 
  	// add the new sign to the list of signs
  	if (sp_prev == NULL)
  	    first_sign = sp;
--- 877,886 ----
      sp = sign_find(name, &sp_prev);
      if (sp == NULL)
      {
! 	sp = alloc_new_sign(name);
  	if (sp == NULL)
  	    return FAIL;
  
  	// add the new sign to the list of signs
  	if (sp_prev == NULL)
  	    first_sign = sp;
***************
*** 794,866 ****
  
      // set values for a defined sign.
      if (icon != NULL)
!     {
! 	vim_free(sp->sn_icon);
! 	sp->sn_icon = vim_strsave(icon);
! 	backslash_halve(sp->sn_icon);
! # ifdef FEAT_SIGN_ICONS
! 	if (gui.in_use)
! 	{
! 	    out_flush();
! 	    if (sp->sn_image != NULL)
! 		gui_mch_destroy_sign(sp->sn_image);
! 	    sp->sn_image = gui_mch_register_sign(sp->sn_icon);
! 	}
! # endif
!     }
  
!     if (text != NULL)
!     {
! 	char_u	*s;
! 	char_u	*endp;
! 	int	cells;
! 	int	len;
! 
! 	endp = text + (int)STRLEN(text);
! 	for (s = text; s + 1 < endp; ++s)
! 	    if (*s == '\\')
! 	    {
! 		// Remove a backslash, so that it is possible
! 		// to use a space.
! 		STRMOVE(s, s + 1);
! 		--endp;
! 	    }
! # ifdef FEAT_MBYTE
! 	// Count cells and check for non-printable chars
! 	if (has_mbyte)
! 	{
! 	    cells = 0;
! 	    for (s = text; s < endp; s += (*mb_ptr2len)(s))
! 	    {
! 		if (!vim_isprintc((*mb_ptr2char)(s)))
! 		    break;
! 		cells += (*mb_ptr2cells)(s);
! 	    }
! 	}
! 	else
! # endif
! 	{
! 	    for (s = text; s < endp; ++s)
! 		if (!vim_isprintc(*s))
! 		    break;
! 	    cells = (int)(s - text);
! 	}
! 	// Currently must be one or two display cells
! 	if (s != endp || cells < 1 || cells > 2)
! 	{
! 	    semsg(_("E239: Invalid sign text: %s"), text);
! 	    return FAIL;
! 	}
! 
! 	vim_free(sp->sn_text);
! 	// Allocate one byte more if we need to pad up
! 	// with a space.
! 	len = (int)(endp - text + ((cells == 1) ? 1 : 0));
! 	sp->sn_text = vim_strnsave(text, len);
! 
! 	if (sp->sn_text != NULL && cells == 1)
! 	    STRCPY(sp->sn_text + len - 1, " ");
!     }
  
      if (linehl != NULL)
  	sp->sn_line_hl = syn_check_group(linehl, (int)STRLEN(linehl));
--- 890,899 ----
  
      // set values for a defined sign.
      if (icon != NULL)
! 	sign_define_init_icon(sp, icon);
  
!     if (text != NULL && (sign_define_init_text(sp, text) == FAIL))
! 	return FAIL;
  
      if (linehl != NULL)
  	sp->sn_line_hl = syn_check_group(linehl, (int)STRLEN(linehl));
*** ../vim-8.1.0771/src/version.c	2019-01-18 21:45:14.593232311 +0100
--- src/version.c	2019-01-18 21:59:53.034047592 +0100
***************
*** 793,794 ****
--- 793,796 ----
  {   /* Add new patch number below this line */
+ /**/
+     772,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
246. You use up your free 1 Gbyte in two days.

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///