replace string strip functions with glib equivalent
This commit is contained in:
		
							parent
							
								
									70231fe231
								
							
						
					
					
						commit
						78ed4d77c5
					
				| @ -25,7 +25,7 @@ ifeq (${PKG_CONFIG}, ${EMPTY}) | ||||
|     $(error "Failed to find pkg-config, please make sure it is installed)
 | ||||
| endif | ||||
| 
 | ||||
| pkg_config_packs:="dbus-1 libxdg-basedir x11 freetype2 xext xft xscrnsaver" | ||||
| pkg_config_packs:="dbus-1 libxdg-basedir x11 freetype2 xext xft xscrnsaver glib-2.0" | ||||
| 
 | ||||
| # includes and libs
 | ||||
| INCS := $(shell ${PKG_CONFIG} --cflags ${pkg_config_packs}) | ||||
|  | ||||
							
								
								
									
										16
									
								
								dunst.c
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								dunst.c
									
									
									
									
									
								
							| @ -16,6 +16,7 @@ | ||||
| #include <errno.h> | ||||
| #include <signal.h> | ||||
| #include <sys/wait.h> | ||||
| #include <glib.h> | ||||
| #include <X11/Xlib.h> | ||||
| #include <X11/XKBlib.h> | ||||
| #include <X11/Xatom.h> | ||||
| @ -38,8 +39,6 @@ | ||||
| 
 | ||||
| #define INRECT(x,y,rx,ry,rw,rh) ((x) >= (rx) && (x) < (rx)+(rw) && (y) >= (ry) && (y) < (ry)+(rh)) | ||||
| #define LENGTH(X)               (sizeof X / sizeof X[0]) | ||||
| #define MIN(a,b)                ((a) < (b) ? (a) : (b)) | ||||
| #define MAX(a,b)                ((a) > (b) ? (a) : (b)) | ||||
| #define BUTTONMASK              (ButtonPressMask|ButtonReleaseMask) | ||||
| #define FONT_HEIGHT_BORDER 2 | ||||
| 
 | ||||
| @ -522,7 +521,7 @@ void r_line_cache_reset(r_line_cache *c) | ||||
| int do_word_wrap(char *source, int max_width) | ||||
| { | ||||
| 
 | ||||
|         rstrip(source); | ||||
|         g_strstrip(source); | ||||
| 
 | ||||
|         if (!source || strlen(source) == 0) | ||||
|                 return 0; | ||||
| @ -562,10 +561,7 @@ int do_word_wrap(char *source, int max_width) | ||||
| 
 | ||||
| void add_notification_to_line_cache(notification *n, int max_width) | ||||
| { | ||||
|         rstrip(n->msg); | ||||
|         char *msg = n->msg; | ||||
|         while (isspace(*msg)) | ||||
|                 msg++; | ||||
|         char *msg = g_strstrip(n->msg); | ||||
| 
 | ||||
|         char *buf; | ||||
| 
 | ||||
| @ -1086,7 +1082,7 @@ int init_notification(notification * n, int id) | ||||
|                 while (strstr(n->msg, "\n") != NULL) | ||||
|                         n->msg = string_replace("\n", " ", n->msg); | ||||
| 
 | ||||
|         n->msg = rstrip(n->msg); | ||||
|         n->msg = g_strstrip(n->msg); | ||||
| 
 | ||||
| 
 | ||||
|         n->dup_count = 0; | ||||
| @ -1253,10 +1249,10 @@ void init_shortcut(keyboard_shortcut * ks) | ||||
|                         str++; | ||||
|                 *str = '\0'; | ||||
|                 str++; | ||||
|                 rstrip(mod); | ||||
|                 g_strchomp(mod); | ||||
|                 ks->mask = ks->mask | string_to_mask(mod); | ||||
|         } | ||||
|         rstrip(str); | ||||
|         g_strstrip(str); | ||||
| 
 | ||||
|         ks->sym = XStringToKeysym(str); | ||||
|         /* find matching keycode for ks->sym */ | ||||
|  | ||||
| @ -6,6 +6,7 @@ | ||||
| #include <unistd.h> | ||||
| #include <stdbool.h> | ||||
| #include <stdio.h> | ||||
| #include <glib.h> | ||||
| 
 | ||||
| #include "options.h" | ||||
| #include "utils.h" | ||||
| @ -200,7 +201,7 @@ int load_ini_file(FILE * fp) | ||||
|         while (fgets(line, sizeof(line), fp) != NULL) { | ||||
|                 line_num++; | ||||
| 
 | ||||
|                 char *start = lskip(rstrip(line)); | ||||
|                 char *start = g_strstrip(line); | ||||
| 
 | ||||
|                 if (*start == ';' || *start == '#' || strlen(start) == 0) | ||||
|                         continue; | ||||
| @ -233,8 +234,8 @@ int load_ini_file(FILE * fp) | ||||
|                 } | ||||
| 
 | ||||
|                 *equal = '\0'; | ||||
|                 char *key = rstrip(start); | ||||
|                 char *value = lskip(equal + 1); | ||||
|                 char *key = g_strstrip(start); | ||||
|                 char *value = g_strstrip(equal + 1); | ||||
| 
 | ||||
|                 char *quote = strstr(value, "\""); | ||||
|                 if (quote) { | ||||
| @ -255,7 +256,7 @@ int load_ini_file(FILE * fp) | ||||
|                         if (comment) | ||||
|                                 comment = '\0'; | ||||
|                 } | ||||
|                 value = rstrip(value); | ||||
|                 value = g_strstrip(value); | ||||
| 
 | ||||
|                 if (!current_section) { | ||||
|                         printf("Warning: invalid config file at line: %d\n", | ||||
|  | ||||
							
								
								
									
										17
									
								
								utils.c
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								utils.c
									
									
									
									
									
								
							| @ -8,23 +8,6 @@ | ||||
| #include "utils.h" | ||||
| #include "dunst.h" | ||||
| 
 | ||||
| char *rstrip(char *str) | ||||
| { | ||||
|         char *end; | ||||
|         end = str + strlen(str) - 1; | ||||
|         while (isspace(*end)) { | ||||
|                 *end = '\0'; | ||||
|                 end--; | ||||
|         } | ||||
|         return str; | ||||
| } | ||||
| 
 | ||||
| char *lskip(char *s) | ||||
| { | ||||
|         for (; *s && isspace(*s); s++) ; | ||||
|         return s; | ||||
| } | ||||
| 
 | ||||
| char *string_replace_all(const char *needle, const char *replacement, | ||||
|                          char *haystack) | ||||
| { | ||||
|  | ||||
							
								
								
									
										4
									
								
								utils.h
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								utils.h
									
									
									
									
									
								
							| @ -1,9 +1,5 @@ | ||||
| #ifndef UTIL_H | ||||
| #define UTIL_H | ||||
| /* remove spaces before and after str */ | ||||
| char *rstrip(char *str); | ||||
| char *lskip(char *str); | ||||
| 
 | ||||
| /* replace all occurrences of needle with replacement in haystack */ | ||||
| char *string_replace_all(const char *needle, const char *replacement, | ||||
|                          char *haystack); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Sascha Kruse
						Sascha Kruse