comparison src/highlight.c @ 20007:aadd1cae2ff5 v8.2.0559

patch 8.2.0559: clearing a struct is verbose Commit: https://github.com/vim/vim/commit/a80faa8930ed5a554beeb2727762538873135e83 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Apr 12 19:37:17 2020 +0200 patch 8.2.0559: clearing a struct is verbose Problem: Clearing a struct is verbose. Solution: Define and use CLEAR_FIELD() and CLEAR_POINTER().
author Bram Moolenaar <Bram@vim.org>
date Sun, 12 Apr 2020 19:45:05 +0200
parents 5feb426d2ea1
children 2c23053c654a
comparison
equal deleted inserted replaced
20006:aee3c9266968 20007:aadd1cae2ff5
2139 */ 2139 */
2140 if (ga_grow(table, 1) == FAIL) 2140 if (ga_grow(table, 1) == FAIL)
2141 return 0; 2141 return 0;
2142 2142
2143 taep = &(((attrentry_T *)table->ga_data)[table->ga_len]); 2143 taep = &(((attrentry_T *)table->ga_data)[table->ga_len]);
2144 vim_memset(taep, 0, sizeof(attrentry_T)); 2144 CLEAR_POINTER(taep);
2145 taep->ae_attr = aep->ae_attr; 2145 taep->ae_attr = aep->ae_attr;
2146 #ifdef FEAT_GUI 2146 #ifdef FEAT_GUI
2147 if (table == &gui_attr_table) 2147 if (table == &gui_attr_table)
2148 { 2148 {
2149 taep->ae_u.gui.fg_color = aep->ae_u.gui.fg_color; 2149 taep->ae_u.gui.fg_color = aep->ae_u.gui.fg_color;
2187 int 2187 int
2188 get_cterm_attr_idx(int attr, int fg, int bg) 2188 get_cterm_attr_idx(int attr, int fg, int bg)
2189 { 2189 {
2190 attrentry_T at_en; 2190 attrentry_T at_en;
2191 2191
2192 vim_memset(&at_en, 0, sizeof(attrentry_T)); 2192 CLEAR_FIELD(at_en);
2193 #ifdef FEAT_TERMGUICOLORS 2193 #ifdef FEAT_TERMGUICOLORS
2194 at_en.ae_u.cterm.fg_rgb = INVALCOLOR; 2194 at_en.ae_u.cterm.fg_rgb = INVALCOLOR;
2195 at_en.ae_u.cterm.bg_rgb = INVALCOLOR; 2195 at_en.ae_u.cterm.bg_rgb = INVALCOLOR;
2196 #endif 2196 #endif
2197 at_en.ae_attr = attr; 2197 at_en.ae_attr = attr;
2209 int 2209 int
2210 get_tgc_attr_idx(int attr, guicolor_T fg, guicolor_T bg) 2210 get_tgc_attr_idx(int attr, guicolor_T fg, guicolor_T bg)
2211 { 2211 {
2212 attrentry_T at_en; 2212 attrentry_T at_en;
2213 2213
2214 vim_memset(&at_en, 0, sizeof(attrentry_T)); 2214 CLEAR_FIELD(at_en);
2215 at_en.ae_attr = attr; 2215 at_en.ae_attr = attr;
2216 if (fg == INVALCOLOR && bg == INVALCOLOR) 2216 if (fg == INVALCOLOR && bg == INVALCOLOR)
2217 { 2217 {
2218 // If both GUI colors are not set fall back to the cterm colors. Helps 2218 // If both GUI colors are not set fall back to the cterm colors. Helps
2219 // if the GUI only has an attribute, such as undercurl. 2219 // if the GUI only has an attribute, such as undercurl.
2237 int 2237 int
2238 get_gui_attr_idx(int attr, guicolor_T fg, guicolor_T bg) 2238 get_gui_attr_idx(int attr, guicolor_T fg, guicolor_T bg)
2239 { 2239 {
2240 attrentry_T at_en; 2240 attrentry_T at_en;
2241 2241
2242 vim_memset(&at_en, 0, sizeof(attrentry_T)); 2242 CLEAR_FIELD(at_en);
2243 at_en.ae_attr = attr; 2243 at_en.ae_attr = attr;
2244 at_en.ae_u.gui.fg_color = fg; 2244 at_en.ae_u.gui.fg_color = fg;
2245 at_en.ae_u.gui.bg_color = bg; 2245 at_en.ae_u.gui.bg_color = bg;
2246 return get_attr_entry(&gui_attr_table, &at_en); 2246 return get_attr_entry(&gui_attr_table, &at_en);
2247 } 2247 }
2296 char_aep = syn_gui_attr2entry(char_attr); 2296 char_aep = syn_gui_attr2entry(char_attr);
2297 if (char_aep != NULL) 2297 if (char_aep != NULL)
2298 new_en = *char_aep; 2298 new_en = *char_aep;
2299 else 2299 else
2300 { 2300 {
2301 vim_memset(&new_en, 0, sizeof(new_en)); 2301 CLEAR_FIELD(new_en);
2302 new_en.ae_u.gui.fg_color = INVALCOLOR; 2302 new_en.ae_u.gui.fg_color = INVALCOLOR;
2303 new_en.ae_u.gui.bg_color = INVALCOLOR; 2303 new_en.ae_u.gui.bg_color = INVALCOLOR;
2304 new_en.ae_u.gui.sp_color = INVALCOLOR; 2304 new_en.ae_u.gui.sp_color = INVALCOLOR;
2305 if (char_attr <= HL_ALL) 2305 if (char_attr <= HL_ALL)
2306 new_en.ae_attr = char_attr; 2306 new_en.ae_attr = char_attr;
2339 char_aep = syn_cterm_attr2entry(char_attr); 2339 char_aep = syn_cterm_attr2entry(char_attr);
2340 if (char_aep != NULL) 2340 if (char_aep != NULL)
2341 new_en = *char_aep; 2341 new_en = *char_aep;
2342 else 2342 else
2343 { 2343 {
2344 vim_memset(&new_en, 0, sizeof(new_en)); 2344 CLEAR_FIELD(new_en);
2345 #ifdef FEAT_TERMGUICOLORS 2345 #ifdef FEAT_TERMGUICOLORS
2346 new_en.ae_u.cterm.bg_rgb = INVALCOLOR; 2346 new_en.ae_u.cterm.bg_rgb = INVALCOLOR;
2347 new_en.ae_u.cterm.fg_rgb = INVALCOLOR; 2347 new_en.ae_u.cterm.fg_rgb = INVALCOLOR;
2348 #endif 2348 #endif
2349 if (char_attr <= HL_ALL) 2349 if (char_attr <= HL_ALL)
2391 char_aep = syn_term_attr2entry(char_attr); 2391 char_aep = syn_term_attr2entry(char_attr);
2392 if (char_aep != NULL) 2392 if (char_aep != NULL)
2393 new_en = *char_aep; 2393 new_en = *char_aep;
2394 else 2394 else
2395 { 2395 {
2396 vim_memset(&new_en, 0, sizeof(new_en)); 2396 CLEAR_FIELD(new_en);
2397 if (char_attr <= HL_ALL) 2397 if (char_attr <= HL_ALL)
2398 new_en.ae_attr = char_attr; 2398 new_en.ae_attr = char_attr;
2399 } 2399 }
2400 2400
2401 if (prim_attr <= HL_ALL) 2401 if (prim_attr <= HL_ALL)
3060 { 3060 {
3061 vim_free(name); 3061 vim_free(name);
3062 return 0; 3062 return 0;
3063 } 3063 }
3064 3064
3065 vim_memset(&(HL_TABLE()[highlight_ga.ga_len]), 0, sizeof(hl_group_T)); 3065 CLEAR_POINTER(&(HL_TABLE()[highlight_ga.ga_len]));
3066 HL_TABLE()[highlight_ga.ga_len].sg_name = name; 3066 HL_TABLE()[highlight_ga.ga_len].sg_name = name;
3067 HL_TABLE()[highlight_ga.ga_len].sg_name_u = name_up; 3067 HL_TABLE()[highlight_ga.ga_len].sg_name_u = name_up;
3068 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) 3068 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
3069 HL_TABLE()[highlight_ga.ga_len].sg_gui_bg = INVALCOLOR; 3069 HL_TABLE()[highlight_ga.ga_len].sg_gui_bg = INVALCOLOR;
3070 HL_TABLE()[highlight_ga.ga_len].sg_gui_fg = INVALCOLOR; 3070 HL_TABLE()[highlight_ga.ga_len].sg_gui_fg = INVALCOLOR;
3260 { 3260 {
3261 hl_group_T *hlt = HL_TABLE(); 3261 hl_group_T *hlt = HL_TABLE();
3262 3262
3263 if (id_alt == 0) 3263 if (id_alt == 0)
3264 { 3264 {
3265 vim_memset(&hlt[hlcnt + i], 0, sizeof(hl_group_T)); 3265 CLEAR_POINTER(&hlt[hlcnt + i]);
3266 hlt[hlcnt + i].sg_term = highlight_attr[hlf]; 3266 hlt[hlcnt + i].sg_term = highlight_attr[hlf];
3267 hlt[hlcnt + i].sg_cterm = highlight_attr[hlf]; 3267 hlt[hlcnt + i].sg_cterm = highlight_attr[hlf];
3268 # if defined(FEAT_GUI) || defined(FEAT_EVAL) 3268 # if defined(FEAT_GUI) || defined(FEAT_EVAL)
3269 hlt[hlcnt + i].sg_gui = highlight_attr[hlf]; 3269 hlt[hlcnt + i].sg_gui = highlight_attr[hlf];
3270 # endif 3270 # endif
3455 hlcnt = highlight_ga.ga_len; 3455 hlcnt = highlight_ga.ga_len;
3456 if (id_S == -1) 3456 if (id_S == -1)
3457 { 3457 {
3458 // Make sure id_S is always valid to simplify code below. Use the last 3458 // Make sure id_S is always valid to simplify code below. Use the last
3459 // entry. 3459 // entry.
3460 vim_memset(&HL_TABLE()[hlcnt + 27], 0, sizeof(hl_group_T)); 3460 CLEAR_POINTER(&HL_TABLE()[hlcnt + 27]);
3461 HL_TABLE()[hlcnt + 18].sg_term = highlight_attr[HLF_S]; 3461 HL_TABLE()[hlcnt + 18].sg_term = highlight_attr[HLF_S];
3462 id_S = hlcnt + 19; 3462 id_S = hlcnt + 19;
3463 } 3463 }
3464 # endif 3464 # endif
3465 for (i = 0; i < 9; i++) 3465 for (i = 0; i < 9; i++)