Use STR_(EMPTY|FULL) for string emptyness checks
This commit is contained in:
		
							parent
							
								
									da846d8442
								
							
						
					
					
						commit
						1f4cd4bd15
					
				| @ -76,7 +76,7 @@ GdkPixbuf *get_pixbuf_from_file(const char *filename) | ||||
| 
 | ||||
| GdkPixbuf *get_pixbuf_from_icon(const char *iconname) | ||||
| { | ||||
|         if (!iconname || iconname[0] == '\0') | ||||
|         if (STR_EMPTY(iconname)) | ||||
|                 return NULL; | ||||
| 
 | ||||
|         const char *suffixes[] = { ".svg", ".png", ".xpm", NULL }; | ||||
| @ -117,7 +117,7 @@ GdkPixbuf *get_pixbuf_from_icon(const char *iconname) | ||||
|                                 break; | ||||
| 
 | ||||
|                         start = end + 1; | ||||
|                 } while (*(end) != '\0'); | ||||
|                 } while (STR_FULL(end)); | ||||
|                 if (!pixbuf) | ||||
|                         LOG_W("No icon found in path: '%s'", iconname); | ||||
|         } | ||||
|  | ||||
| @ -89,7 +89,7 @@ void notification_print(const struct notification *n) | ||||
| /* see notification.h */ | ||||
| void notification_run_script(struct notification *n) | ||||
| { | ||||
|         if (!n->script || strlen(n->script) < 1) | ||||
|         if (STR_EMPTY(n->script)) | ||||
|                 return; | ||||
| 
 | ||||
|         if (n->script_run && !settings.always_run_script) | ||||
| @ -300,7 +300,7 @@ void notification_init(struct notification *n) | ||||
|                 n->timeout = settings.timeouts[n->urgency]; | ||||
| 
 | ||||
|         /* Icon handling */ | ||||
|         if (n->icon && strlen(n->icon) <= 0) | ||||
|         if (STR_EMPTY(n->icon)) | ||||
|                 g_clear_pointer(&n->icon, g_free); | ||||
|         if (!n->raw_icon && !n->icon) | ||||
|                 n->icon = g_strdup(settings.icons[n->urgency]); | ||||
|  | ||||
| @ -231,7 +231,7 @@ int load_ini_file(FILE *fp) | ||||
| 
 | ||||
|                 char *start = g_strstrip(line); | ||||
| 
 | ||||
|                 if (*start == ';' || *start == '#' || strlen(start) == 0) | ||||
|                 if (*start == ';' || *start == '#' || STR_EMPTY(start)) | ||||
|                         continue; | ||||
| 
 | ||||
|                 if (*start == '[') { | ||||
| @ -521,7 +521,7 @@ int option_get_bool(const char *ini_section, | ||||
| void cmdline_usage_append(const char *key, const char *type, const char *description) | ||||
| { | ||||
|         char *key_type; | ||||
|         if (type && strlen(type) > 0) | ||||
|         if (STR_FULL(type)) | ||||
|                 key_type = g_strdup_printf("%s (%s)", key, type); | ||||
|         else | ||||
|                 key_type = g_strdup(key); | ||||
|  | ||||
| @ -125,7 +125,7 @@ int queues_notification_insert(struct notification *n) | ||||
| { | ||||
| 
 | ||||
|         /* do not display the message, if the message is empty */ | ||||
|         if (strlen(n->msg) == 0) { | ||||
|         if (STR_EMPTY(n->msg)) { | ||||
|                 if (settings.always_run_script) { | ||||
|                         notification_run_script(n); | ||||
|                 } | ||||
|  | ||||
| @ -80,7 +80,7 @@ static enum urgency ini_get_urgency(const char *section, const char *key, const | ||||
|         int ret = def; | ||||
|         char *urg = ini_get_string(section, key, ""); | ||||
| 
 | ||||
|         if (strlen(urg) > 0) { | ||||
|         if (STR_FULL(urg)) { | ||||
|                 if (strcmp(urg, "low") == 0) | ||||
|                         ret = URG_LOW; | ||||
|                 else if (strcmp(urg, "normal") == 0) | ||||
| @ -247,7 +247,7 @@ void load_settings(char *cmdline_config_path) | ||||
|                         "Ellipsize truncated lines on the start/middle/end" | ||||
|                 ); | ||||
| 
 | ||||
|                 if (strlen(c) == 0) { | ||||
|                 if (STR_EMPTY(c)) { | ||||
|                         settings.ellipsize = defaults.ellipsize; | ||||
|                 } else if (strcmp(c, "start") == 0) { | ||||
|                         settings.ellipsize = ELLIPSE_START; | ||||
| @ -346,8 +346,7 @@ void load_settings(char *cmdline_config_path) | ||||
|                         "alignment", "-align/-alignment", "", | ||||
|                         "Text alignment left/center/right" | ||||
|                 ); | ||||
| 
 | ||||
|                 if (strlen(c) > 0) { | ||||
|                 if (STR_FULL(c)) { | ||||
|                         if (strcmp(c, "left") == 0) | ||||
|                                 settings.align = ALIGN_LEFT; | ||||
|                         else if (strcmp(c, "center") == 0) | ||||
| @ -427,7 +426,7 @@ void load_settings(char *cmdline_config_path) | ||||
|                         "Color of the separator line (or 'auto')" | ||||
|                 ); | ||||
| 
 | ||||
|                 if (strlen(c) > 0) { | ||||
|                 if (STR_FULL(c)) { | ||||
|                         if (strcmp(c, "auto") == 0) | ||||
|                                 settings.sep_color = SEP_AUTO; | ||||
|                         else if (strcmp(c, "foreground") == 0) | ||||
| @ -484,7 +483,7 @@ void load_settings(char *cmdline_config_path) | ||||
|                         "Align icons left/right/off" | ||||
|                 ); | ||||
| 
 | ||||
|                 if (strlen(c) > 0) { | ||||
|                 if (STR_FULL(c)) { | ||||
|                         if (strcmp(c, "left") == 0) | ||||
|                                 settings.icon_position = ICON_LEFT; | ||||
|                         else if (strcmp(c, "right") == 0) | ||||
|  | ||||
| @ -79,11 +79,11 @@ char *string_replace_all(const char *needle, const char *replacement, char *hays | ||||
| 
 | ||||
| char *string_append(char *a, const char *b, const char *sep) | ||||
| { | ||||
|         if (!a || *a == '\0') { | ||||
|         if (STR_EMPTY(a)) { | ||||
|                 g_free(a); | ||||
|                 return g_strdup(b); | ||||
|         } | ||||
|         if (!b || *b == '\0') | ||||
|         if (STR_EMPTY(b)) | ||||
|                 return a; | ||||
| 
 | ||||
|         char *new; | ||||
|  | ||||
| @ -4,6 +4,9 @@ | ||||
| 
 | ||||
| #include <glib.h> | ||||
| 
 | ||||
| #define STR_EMPTY(s) (!s || (*s == '\0')) | ||||
| #define STR_FULL(s) !(STR_EMPTY(s)) | ||||
| 
 | ||||
| /* replace all occurrences of the character needle with the character replacement in haystack */ | ||||
| char *string_replace_char(char needle, char replacement, char *haystack); | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Benedikt Heine
						Benedikt Heine