replace string strip functions with glib equivalent

This commit is contained in:
Sascha Kruse 2013-02-16 03:21:26 +01:00
parent 70231fe231
commit 78ed4d77c5
5 changed files with 12 additions and 36 deletions

View File

@ -25,7 +25,7 @@ ifeq (${PKG_CONFIG}, ${EMPTY})
$(error "Failed to find pkg-config, please make sure it is installed) $(error "Failed to find pkg-config, please make sure it is installed)
endif 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 # includes and libs
INCS := $(shell ${PKG_CONFIG} --cflags ${pkg_config_packs}) INCS := $(shell ${PKG_CONFIG} --cflags ${pkg_config_packs})

16
dunst.c
View File

@ -16,6 +16,7 @@
#include <errno.h> #include <errno.h>
#include <signal.h> #include <signal.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <glib.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/XKBlib.h> #include <X11/XKBlib.h>
#include <X11/Xatom.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 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 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 BUTTONMASK (ButtonPressMask|ButtonReleaseMask)
#define FONT_HEIGHT_BORDER 2 #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) int do_word_wrap(char *source, int max_width)
{ {
rstrip(source); g_strstrip(source);
if (!source || strlen(source) == 0) if (!source || strlen(source) == 0)
return 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) void add_notification_to_line_cache(notification *n, int max_width)
{ {
rstrip(n->msg); char *msg = g_strstrip(n->msg);
char *msg = n->msg;
while (isspace(*msg))
msg++;
char *buf; char *buf;
@ -1086,7 +1082,7 @@ int init_notification(notification * n, int id)
while (strstr(n->msg, "\n") != NULL) while (strstr(n->msg, "\n") != NULL)
n->msg = string_replace("\n", " ", n->msg); n->msg = string_replace("\n", " ", n->msg);
n->msg = rstrip(n->msg); n->msg = g_strstrip(n->msg);
n->dup_count = 0; n->dup_count = 0;
@ -1253,10 +1249,10 @@ void init_shortcut(keyboard_shortcut * ks)
str++; str++;
*str = '\0'; *str = '\0';
str++; str++;
rstrip(mod); g_strchomp(mod);
ks->mask = ks->mask | string_to_mask(mod); ks->mask = ks->mask | string_to_mask(mod);
} }
rstrip(str); g_strstrip(str);
ks->sym = XStringToKeysym(str); ks->sym = XStringToKeysym(str);
/* find matching keycode for ks->sym */ /* find matching keycode for ks->sym */

View File

@ -6,6 +6,7 @@
#include <unistd.h> #include <unistd.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <glib.h>
#include "options.h" #include "options.h"
#include "utils.h" #include "utils.h"
@ -200,7 +201,7 @@ int load_ini_file(FILE * fp)
while (fgets(line, sizeof(line), fp) != NULL) { while (fgets(line, sizeof(line), fp) != NULL) {
line_num++; line_num++;
char *start = lskip(rstrip(line)); char *start = g_strstrip(line);
if (*start == ';' || *start == '#' || strlen(start) == 0) if (*start == ';' || *start == '#' || strlen(start) == 0)
continue; continue;
@ -233,8 +234,8 @@ int load_ini_file(FILE * fp)
} }
*equal = '\0'; *equal = '\0';
char *key = rstrip(start); char *key = g_strstrip(start);
char *value = lskip(equal + 1); char *value = g_strstrip(equal + 1);
char *quote = strstr(value, "\""); char *quote = strstr(value, "\"");
if (quote) { if (quote) {
@ -255,7 +256,7 @@ int load_ini_file(FILE * fp)
if (comment) if (comment)
comment = '\0'; comment = '\0';
} }
value = rstrip(value); value = g_strstrip(value);
if (!current_section) { if (!current_section) {
printf("Warning: invalid config file at line: %d\n", printf("Warning: invalid config file at line: %d\n",

17
utils.c
View File

@ -8,23 +8,6 @@
#include "utils.h" #include "utils.h"
#include "dunst.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 *string_replace_all(const char *needle, const char *replacement,
char *haystack) char *haystack)
{ {

View File

@ -1,9 +1,5 @@
#ifndef UTIL_H #ifndef UTIL_H
#define 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 */ /* replace all occurrences of needle with replacement in haystack */
char *string_replace_all(const char *needle, const char *replacement, char *string_replace_all(const char *needle, const char *replacement,
char *haystack); char *haystack);